morningman commented on code in PR #70903:
URL: https://github.com/apache/doris/pull/70903#discussion_r4676075490


##########
fe/fe-core/src/main/java/org/apache/doris/tablefunction/S3TableValuedFunction.java:
##########
@@ -54,7 +54,14 @@ public S3TableValuedFunction(Map<String, String> properties, 
List<TBrokerFileSta
         String uri = storageAdapter.validateAndGetUri(props);
         filePath = storageAdapter.validateAndNormalizeUri(uri);
         this.backendConnectProperties.put(URI_KEY, filePath);
-        if (!FeConstants.runningUnitTest) {
+        if (isPluginFormat()) {
+            // The data set at the uri is read as a whole; a streaming job's 
list of files has no meaning for it.
+            if (files != null) {
+                throw new AnalysisException("Format " + 
fileFormatProperties.getFormatName()
+                        + " reads the data set at the uri as a whole, not a 
list of files");
+            }
+            readPluginFormat();

Review Comment:
   Fixed in a1a26b6d767. `readPluginFormat()` now requires an S3-compatible 
binding before it hands the location over, and refuses any other binding with 
the message `hdfs()` and `http()` already get. The check is there rather than 
on `file()`'s path because `s3()` reaches it too: an `s3.endpoint` on 
`*.blob.core.windows.net`, or `provider = azure`, binds Azure in `s3()` as well.
   
   `PluginFileFormatTableValuedFunctionTest.azureStorageNeverReachesThePlugin` 
covers both: `file()` with `wasbs://` and Azure shared-key properties, and 
`s3()` with an Azure endpoint. Before the fix it fails with `handed to the 
plugin: [s3://warehouse/test.lance with [AZURE]]`; with the fix the plugin is 
never called. `test_lance_s3_tvf` also refuses the Azure `file()` case.
   



##########
fe/fe-core/src/main/java/org/apache/doris/tablefunction/ExternalFileTableValuedFunction.java:
##########
@@ -214,6 +223,55 @@ protected void parseFile(List<TBrokerFileStatus> files) 
throws AnalysisException
     }
 
 
+    /**
+     * The endpoint white list and SSRF check of an object-storage location, 
which the FE reaches before any BE
+     * does: listing its files, or a plugin reading the data set there.
+     */
+    private static void validateEndpoint(BrokerDesc brokerDesc) throws 
UserException {
+        // "Object storage" here means an S3-compatible binding 
(S3/OSS/OBS/COS/GCS/MinIO/
+        // Ozone) — the exact implementor set of the legacy object-storage 
marker interface;
+        // Azure deliberately stays excluded, matching the legacy instanceof 
check.
+        StorageAdapter storageAdapter = brokerDesc.getStorageAdapter();
+        if (storageAdapter != null
+                && storageAdapter.getSpiProperties() instanceof 
S3CompatibleFileSystemProperties) {
+            S3Util.validateAndTestEndpoint(
+                    ((S3CompatibleFileSystemProperties) 
storageAdapter.getSpiProperties()).getEndpoint());
+        }
+    }
+
+    /** Whether a connector plugin reads this table function's format; see 
{@link #readPluginFormat}. */
+    public boolean isPluginFormat() {
+        return pluginFormat != null;
+    }
+
+    /**
+     * Hands the location to the plugin that reads this table function's 
format, after the endpoint check a listing
+     * gets, and takes the columns from what the plugin resolved. The plugin 
interprets the data set as a whole, so
+     * nothing is listed, and it pins what the statement reads.
+     */
+    protected void readPluginFormat() throws AnalysisException {
+        long startAt = System.currentTimeMillis();
+        try {
+            validateEndpoint(getBrokerDesc());
+            ConnectorFileSource source = new 
ConnectorFileSource(pluginFormat.getFormat(), filePath,
+                    
Collections.singletonList(storageAdapter.getSpiProperties()), 
backendConnectProperties);
+            ConnectorSession session = pluginFormat.buildSession();
+            ConnectorMetadata metadata = PluginDrivenMetadata.get(session, 
pluginFormat.getConnector());
+            pluginTableHandle = ((ConnectorFileSourceOps) 
metadata).getFileTableHandle(session, source);
+            columns = ConnectorColumnConverter.convertColumns(

Review Comment:
   Fixed in a1a26b6d767. `fillColumns` and the plugin path now share one check. 
It refuses a column whose name an earlier column already took, regardless of 
case, with the existing message (`Repeated lowercase column names: id`, as on 
4.2). The plugin path keeps the plugin's spelling; a file's non-JSON columns 
are still lower-cased, as before.
   
   Unit tests: `columnsWhoseNamesDifferOnlyInCaseAreRefused` fails before the 
fix and passes with it; `mixedCaseColumnKeepsThePluginsSpelling`; and 
`S3TableValuedFunctionTest.testColumnNamesThatDifferOnlyInCaseAreRefused` for 
the shared check on a file's columns.
   
   Regression: `test_lance_s3_tvf` reads two new fixtures, built by 
`lance_build_column_case.py` with the pinned pylance 7.0.0:
   - `column_case.lance` (`row_id`, `UserName`): its `DESC FUNCTION` shows 
`UserName`, and `SELECT row_id, username ... WHERE USERNAME <> 'b'` reads it.
   - `column_case_conflict.lance` (`id`, `ID`): refused.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to