github-actions[bot] commented on code in PR #62183:
URL: https://github.com/apache/doris/pull/62183#discussion_r3090323477


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalConnectorTableSink.java:
##########
@@ -33,78 +33,81 @@
 import java.util.List;
 import java.util.Optional;
 
-/** physical jdbc sink */
-public class PhysicalJdbcTableSink<CHILD_TYPE extends Plan> extends 
PhysicalBaseExternalTableSink<CHILD_TYPE> {
+/**
+ * Physical table sink for plugin-driven connector catalogs.
+ */
+public class PhysicalConnectorTableSink<CHILD_TYPE extends Plan> extends 
PhysicalBaseExternalTableSink<CHILD_TYPE> {
 
     /**
      * constructor
      */
-    public PhysicalJdbcTableSink(JdbcExternalDatabase database,
-                                 JdbcExternalTable targetTable,
-                                 List<Column> cols,
-                                 List<NamedExpression> outputExprs,
-                                 Optional<GroupExpression> groupExpression,
-                                 LogicalProperties logicalProperties,
-                                 CHILD_TYPE child) {
+    public PhysicalConnectorTableSink(ExternalDatabase database,
+                                      ExternalTable targetTable,
+                                      List<Column> cols,
+                                      List<NamedExpression> outputExprs,
+                                      Optional<GroupExpression> 
groupExpression,
+                                      LogicalProperties logicalProperties,
+                                      CHILD_TYPE child) {
         this(database, targetTable, cols, outputExprs, groupExpression, 
logicalProperties,
                 PhysicalProperties.GATHER, null, child);
     }
 
     /**
      * constructor
      */
-    public PhysicalJdbcTableSink(JdbcExternalDatabase database,
-                                 JdbcExternalTable targetTable,
-                                 List<Column> cols,
-                                 List<NamedExpression> outputExprs,
-                                 Optional<GroupExpression> groupExpression,
-                                 LogicalProperties logicalProperties,
-                                 PhysicalProperties physicalProperties,
-                                 Statistics statistics,
-                                 CHILD_TYPE child) {
-        super(PlanType.PHYSICAL_JDBC_TABLE_SINK, database, targetTable, cols, 
outputExprs, groupExpression,
+    public PhysicalConnectorTableSink(ExternalDatabase database,
+                                      ExternalTable targetTable,
+                                      List<Column> cols,
+                                      List<NamedExpression> outputExprs,
+                                      Optional<GroupExpression> 
groupExpression,
+                                      LogicalProperties logicalProperties,
+                                      PhysicalProperties physicalProperties,
+                                      Statistics statistics,
+                                      CHILD_TYPE child) {
+        super(PlanType.PHYSICAL_CONNECTOR_TABLE_SINK, database, targetTable, 
cols, outputExprs, groupExpression,
                 logicalProperties, physicalProperties, statistics, child);
     }
 
     @Override
     public Plan withChildren(List<Plan> children) {
-        return AbstractPlan.copyWithSameId(this, () -> new 
PhysicalJdbcTableSink<>(
-                (JdbcExternalDatabase) database, (JdbcExternalTable) 
targetTable,
-                cols, outputExprs, groupExpression,
+        return AbstractPlan.copyWithSameId(this, () -> new 
PhysicalConnectorTableSink<>(
+                (ExternalDatabase) database, (ExternalTable) targetTable, 
cols, outputExprs, groupExpression,
                 getLogicalProperties(), physicalProperties, statistics, 
children.get(0)));
     }
 
     @Override
     public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
-        return visitor.visitPhysicalJdbcTableSink(this, context);
+        return visitor.visitPhysicalConnectorTableSink(this, context);
     }
 
     @Override
     public Plan withGroupExpression(Optional<GroupExpression> groupExpression) 
{
-        return AbstractPlan.copyWithSameId(this, () -> new 
PhysicalJdbcTableSink<>(
-                (JdbcExternalDatabase) database, (JdbcExternalTable) 
targetTable, cols, outputExprs,
+        return AbstractPlan.copyWithSameId(this, () -> new 
PhysicalConnectorTableSink<>(
+                (ExternalDatabase) database, (ExternalTable) targetTable, 
cols, outputExprs,
                 groupExpression, getLogicalProperties(), child()));
     }
 
     @Override
     public Plan withGroupExprLogicalPropChildren(Optional<GroupExpression> 
groupExpression,
-            Optional<LogicalProperties> logicalProperties, List<Plan> 
children) {
-        return AbstractPlan.copyWithSameId(this, () -> new 
PhysicalJdbcTableSink<>(
-                (JdbcExternalDatabase) database, (JdbcExternalTable) 
targetTable, cols, outputExprs,
+                                                 Optional<LogicalProperties> 
logicalProperties, List<Plan> children) {
+        return AbstractPlan.copyWithSameId(this, () -> new 
PhysicalConnectorTableSink<>(
+                (ExternalDatabase) database, (ExternalTable) targetTable, 
cols, outputExprs,
                 groupExpression, logicalProperties.get(), children.get(0)));
     }
 
     @Override
     public PhysicalPlan withPhysicalPropertiesAndStats(PhysicalProperties 
physicalProperties, Statistics statistics) {
-        return AbstractPlan.copyWithSameId(this, () -> new 
PhysicalJdbcTableSink<>(
-                (JdbcExternalDatabase) database, (JdbcExternalTable) 
targetTable, cols, outputExprs,
+        return AbstractPlan.copyWithSameId(this, () -> new 
PhysicalConnectorTableSink<>(
+                (ExternalDatabase) database, (ExternalTable) targetTable, 
cols, outputExprs,
                 groupExpression, getLogicalProperties(), physicalProperties, 
statistics, child()));
     }
 
+    /**
+     * Get output physical properties.
+     * Generic connector sink uses random partitioning (no connector-specific 
partition awareness).
+     */
     @Override
     public PhysicalProperties getRequirePhysicalProperties() {
-        // Since JDBC tables do not have partitioning, return a default 
physical property.
-        // GATHER implies that all data is gathered to a single location, 
which is a common requirement for JDBC sinks.
-        return PhysicalProperties.GATHER;

Review Comment:
   This changes the migrated JDBC sink from `GATHER` to 
`SINK_RANDOM_PARTITIONED`, and the old 
`RequestPropertyDeriver.visitPhysicalJdbcTableSink()` special-case was removed 
in the same PR. That means `INSERT INTO jdbc_catalog...SELECT ...` can now be 
planned with multiple sink instances.
   
   That is a behavior regression, not just a cost-model change. The previous 
path forced a single writer, while BE's JDBC sink still commits per writer 
(`VJdbcTableWriter::close()` commits the remote transaction when 
`use_transaction=true`). With multiple fragment instances, one writer can 
commit successfully before another fails, leaving partial remote writes where 
the old plan kept a single remote transaction/writer.



##########
fe/fe-core/src/main/java/org/apache/doris/httpv2/restv2/ESCatalogAction.java:
##########
@@ -64,12 +64,11 @@ private Object handleRequest(HttpServletRequest request, 
HttpServletResponse res
         String catalogName = request.getParameter(CATALOG);
         String tableName = request.getParameter(TABLE);
         CatalogIf catalog = env.getCatalogMgr().getCatalog(catalogName);

Review Comment:
   This type check is now too broad. `PluginDrivenExternalCatalog` currently 
includes JDBC as well as ES in production, but the endpoint still assumes an 
ES-only capability and immediately calls `Connector.executeRestRequest()`.
   
   For a JDBC catalog, the default `Connector.executeRestRequest()` throws 
`UnsupportedOperationException`, so 
`/rest/v2/api/es_catalog/...&catalog=<jdbc_catalog>` now turns into a 
server-side 500 instead of being rejected as 'unknown ES catalog'. Please keep 
the ES-specific guard here (`getType() == "es"` or an explicit capability 
check).



##########
fe/fe-core/src/main/java/org/apache/doris/datasource/PluginDrivenScanNode.java:
##########
@@ -0,0 +1,816 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.datasource;
+
+import org.apache.doris.analysis.CastExpr;
+import org.apache.doris.analysis.Expr;
+import org.apache.doris.analysis.ExprToSqlVisitor;
+import org.apache.doris.analysis.ToSqlParams;
+import org.apache.doris.analysis.TupleDescriptor;
+import org.apache.doris.catalog.TableIf;
+import org.apache.doris.common.UserException;
+import org.apache.doris.connector.api.Connector;
+import org.apache.doris.connector.api.ConnectorMetadata;
+import org.apache.doris.connector.api.ConnectorSession;
+import org.apache.doris.connector.api.handle.ConnectorColumnHandle;
+import org.apache.doris.connector.api.handle.ConnectorTableHandle;
+import org.apache.doris.connector.api.handle.PassthroughQueryTableHandle;
+import org.apache.doris.connector.api.pushdown.ConnectorExpression;
+import org.apache.doris.connector.api.pushdown.ConnectorFilterConstraint;
+import org.apache.doris.connector.api.pushdown.FilterApplicationResult;
+import org.apache.doris.connector.api.pushdown.LimitApplicationResult;
+import org.apache.doris.connector.api.pushdown.ProjectionApplicationResult;
+import org.apache.doris.connector.api.scan.ConnectorScanPlanProvider;
+import org.apache.doris.connector.api.scan.ConnectorScanRange;
+import org.apache.doris.planner.PlanNodeId;
+import org.apache.doris.planner.ScanContext;
+import org.apache.doris.qe.SessionVariable;
+import org.apache.doris.spi.Split;
+import org.apache.doris.thrift.TExplainLevel;
+import org.apache.doris.thrift.TFileAttributes;
+import org.apache.doris.thrift.TFileFormatType;
+import org.apache.doris.thrift.TFileRangeDesc;
+import org.apache.doris.thrift.TFileTextScanRangeParams;
+import org.apache.doris.thrift.TMaxComputeFileDesc;
+import org.apache.doris.thrift.TPaimonDeletionFileDesc;
+import org.apache.doris.thrift.TPaimonFileDesc;
+import org.apache.doris.thrift.TTableFormatFileDesc;
+import org.apache.doris.thrift.TTrinoConnectorFileDesc;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+/**
+ * Generic scan node that delegates scan planning to the connector SPI.
+ *
+ * <p>Replaces connector-specific ScanNode subclasses for plugin-driven 
catalogs.
+ * Extends {@link FileQueryScanNode} to reuse the existing split-to-Thrift
+ * conversion pipeline. Uses {@code FORMAT_JNI} by default, which routes
+ * to BE's JNI scanner framework.</p>
+ *
+ * <p>Scan flow:</p>
+ * <ol>
+ *   <li>{@link #getSplits} calls {@link ConnectorScanPlanProvider#planScan}
+ *       to obtain {@link ConnectorScanRange}s from the connector plugin</li>
+ *   <li>Each range is wrapped in a {@link PluginDrivenSplit}</li>
+ *   <li>{@link FileQueryScanNode#createScanRangeLocations} distributes splits
+ *       to backends</li>
+ *   <li>{@link #setScanParams} populates {@link TTableFormatFileDesc} with
+ *       connector-specific properties for each split</li>
+ * </ol>
+ */
+public class PluginDrivenScanNode extends FileQueryScanNode {
+
+    private static final Logger LOG = 
LogManager.getLogger(PluginDrivenScanNode.class);
+
+    private static final String TABLE_FORMAT_TYPE = "plugin_driven";
+
+    /** Scan node property keys (shared with connector plugins). */
+    private static final String PROP_FILE_FORMAT_TYPE = "file_format_type";
+    private static final String PROP_PATH_PARTITION_KEYS = 
"path_partition_keys";
+    private static final String PROP_LOCATION_PREFIX = "location.";
+    private static final String PROP_HIVE_TEXT_PREFIX = "hive.text.";
+
+    private final Connector connector;
+    private final ConnectorSession connectorSession;
+
+    // Set during filter pushdown; may be updated from the original table 
handle.
+    private ConnectorTableHandle currentHandle;
+
+    // Populated from ConnectorScanPlanProvider.getScanNodeProperties()
+    private Map<String, String> scanNodeProperties;
+
+    public PluginDrivenScanNode(PlanNodeId id, TupleDescriptor desc,
+            boolean needCheckColumnPriv, SessionVariable sv,
+            ScanContext scanContext, Connector connector,
+            ConnectorSession connectorSession, ConnectorTableHandle 
tableHandle) {
+        super(id, desc, "PluginDrivenScanNode", scanContext, 
needCheckColumnPriv, sv);
+        this.connector = connector;
+        this.connectorSession = connectorSession;
+        this.currentHandle = tableHandle;
+    }
+
+    /**
+     * Creates a PluginDrivenScanNode by resolving the connector, session, and 
table handle
+     * from the plugin-driven catalog and table.
+     */
+    public static PluginDrivenScanNode create(PlanNodeId id, TupleDescriptor 
desc,
+            boolean needCheckColumnPriv, SessionVariable sv,
+            ScanContext scanContext, PluginDrivenExternalCatalog catalog,
+            PluginDrivenExternalTable table) {
+        Connector connector = catalog.getConnector();

Review Comment:
   `PluginDrivenScanNode` now captures a live `Connector` object from the 
catalog and keeps using it during predicate pushdown / split planning. That 
makes catalog refresh unsafe: `ALTER CATALOG ... SET PROPERTIES` calls 
`ExternalCatalog.resetToUninitialized()` -> 
`PluginDrivenExternalCatalog.onClose()`, which closes this same connector 
before the replacement is lazily created.
   
   Concrete failure path: build a query on a JDBC catalog, then alter the 
catalog before `getSplits()` / `convertPredicate()` runs. The scan node still 
holds the old connector and `JdbcDorisConnector.getOrCreateClient()` will throw 
`JdbcDorisConnector has been closed`. The old JDBC/ES scan nodes copied the 
resolved connection state instead of keeping a closable catalog object, so 
in-flight readers survived refreshes.



##########
fe/fe-core/src/main/java/org/apache/doris/datasource/PluginDrivenExternalTable.java:
##########
@@ -0,0 +1,217 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.datasource;
+
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.Env;
+import org.apache.doris.catalog.TableIf;
+import org.apache.doris.catalog.TableIf.TableType;
+import org.apache.doris.connector.api.Connector;
+import org.apache.doris.connector.api.ConnectorColumn;
+import org.apache.doris.connector.api.ConnectorMetadata;
+import org.apache.doris.connector.api.ConnectorSession;
+import org.apache.doris.connector.api.ConnectorTableSchema;
+import org.apache.doris.connector.api.ConnectorTableStatistics;
+import org.apache.doris.connector.api.handle.ConnectorTableHandle;
+import org.apache.doris.statistics.AnalysisInfo;
+import org.apache.doris.statistics.BaseAnalysisTask;
+import org.apache.doris.statistics.ExternalAnalysisTask;
+import org.apache.doris.thrift.TTableDescriptor;
+import org.apache.doris.thrift.TTableType;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * Generic {@link ExternalTable} for plugin-driven catalogs.
+ *
+ * <p>Provides table implementation that fetches schema from the connector SPI.
+ * Connector-specific behavior is accessed through the parent catalog's
+ * {@link org.apache.doris.connector.api.Connector} using opaque handles.</p>
+ */
+public class PluginDrivenExternalTable extends ExternalTable {
+
+    private static final Logger LOG = 
LogManager.getLogger(PluginDrivenExternalTable.class);
+
+    /** No-arg constructor for GSON deserialization. */
+    public PluginDrivenExternalTable() {
+    }
+
+    public PluginDrivenExternalTable(long id, String name, String remoteName,
+            ExternalCatalog catalog, ExternalDatabase db) {
+        super(id, name, remoteName, catalog, db, 
TableType.PLUGIN_EXTERNAL_TABLE);
+    }
+
+    @Override
+    public Optional<SchemaCacheValue> initSchema() {
+        PluginDrivenExternalCatalog pluginCatalog = 
(PluginDrivenExternalCatalog) catalog;
+        Connector connector = pluginCatalog.getConnector();
+        ConnectorSession session = pluginCatalog.buildConnectorSession();
+        ConnectorMetadata metadata = connector.getMetadata(session);
+
+        String dbName = db != null ? db.getRemoteName() : "";
+        String tableName = getRemoteName();
+        Optional<ConnectorTableHandle> handleOpt = 
metadata.getTableHandle(session, dbName, tableName);
+        if (!handleOpt.isPresent()) {
+            LOG.warn("Table handle not found for plugin-driven table: {}.{}", 
dbName, tableName);
+            return Optional.empty();
+        }
+
+        ConnectorTableSchema tableSchema = metadata.getTableSchema(session, 
handleOpt.get());
+
+        // Apply identifier mapping to column names (lowercase / explicit 
mapping)
+        List<ConnectorColumn> mappedColumns = new 
ArrayList<>(tableSchema.getColumns().size());
+        for (ConnectorColumn col : tableSchema.getColumns()) {
+            String mappedName = metadata.fromRemoteColumnName(session, dbName, 
tableName, col.getName());
+            if (!mappedName.equals(col.getName())) {
+                mappedColumns.add(new ConnectorColumn(mappedName, 
col.getType(),
+                        col.getComment(), col.isNullable(), 
col.getDefaultValue(), col.isKey()));
+            } else {
+                mappedColumns.add(col);
+            }
+        }
+
+        List<Column> columns = 
ConnectorColumnConverter.convertColumns(mappedColumns);
+        return Optional.of(new SchemaCacheValue(columns));
+    }
+
+    @Override
+    protected synchronized void makeSureInitialized() {
+        super.makeSureInitialized();
+        if (!objectCreated) {
+            objectCreated = true;
+        }
+    }
+
+    @Override
+    public long getCachedRowCount() {

Review Comment:
   This regresses `getCachedRowCount()` from a cheap cache-only lookup into a 
forced remote initialization. `ExternalTable.getCachedRowCount()` intentionally 
returned `-1` for uninitialized tables so `SHOW TABLE STATUS` / 
`information_schema.tables` could stay non-blocking and avoid touching external 
systems.
   
   With the plugin migration, a freshly restarted FE or a temporarily 
unavailable ES/JDBC source will now make those metadata queries initialize the 
connector and fetch remote state just to answer a cached row-count request. 
That is a visible behavior/perf regression compared to the previous ES/JDBC 
table implementations.



##########
fe/fe-core/src/main/java/org/apache/doris/tablefunction/QueryTableValueFunction.java:
##########
@@ -71,7 +71,7 @@ public static QueryTableValueFunction 
createQueryTableValueFunction(Map<String,
         if (catalogIf == null) {
             throw new AnalysisException("Catalog not found: " + catalogName);
         }
-        if (catalogIf instanceof JdbcExternalCatalog) {

Review Comment:
   This broadens `query()` from 'JDBC catalogs only' to 'any plugin-driven 
catalog', but the rest of the path is still JDBC-only. 
`JdbcQueryTableValueFunction` immediately calls 
`ConnectorMetadata.getColumnsFromQuery()` and later builds a 
`PassthroughQueryTableHandle`; in this PR only the JDBC connector implements 
those APIs.
   
   So `select * from query('catalog'='es_catalog', 'query'='...')` now passes 
the catalog-type check and then fails inside the connector with 
`getColumnsFromQuery not supported`, whereas the previous code rejected it up 
front. This needs a capability/type check here instead of a plain `instanceof 
PluginDrivenExternalCatalog`.



-- 
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