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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java:
##########
@@ -650,19 +658,45 @@ public PlanFragment 
visitPhysicalIcebergMergeSink(PhysicalIcebergMergeSink<? ext
     }
 
     @Override
-    public PlanFragment visitPhysicalJdbcTableSink(PhysicalJdbcTableSink<? 
extends Plan> jdbcTableSink,
+    public PlanFragment visitPhysicalConnectorTableSink(
+            PhysicalConnectorTableSink<? extends Plan> connectorTableSink,
             PlanTranslatorContext context) {
-        PlanFragment rootFragment = jdbcTableSink.child().accept(this, 
context);
+        PlanFragment rootFragment = connectorTableSink.child().accept(this, 
context);
         rootFragment.setOutputPartition(DataPartition.UNPARTITIONED);
-        List<Column> targetTableColumns = jdbcTableSink.getCols();
-        List<String> insertCols = targetTableColumns.stream()
-                .map(Column::getName)
-                .collect(Collectors.toList());
 
-        JdbcTableSink sink = new JdbcTableSink(
-                (JdbcExternalTable) jdbcTableSink.getTargetTable(),
-                insertCols
-        );
+        PluginDrivenExternalTable targetTable =
+                (PluginDrivenExternalTable) 
connectorTableSink.getTargetTable();
+        PluginDrivenExternalCatalog catalog =
+                (PluginDrivenExternalCatalog) targetTable.getCatalog();
+
+        // Get write config from the connector
+        Connector connector = catalog.getConnector();
+        ConnectorSession connSession = catalog.buildConnectorSession();
+        ConnectorMetadata metadata = connector.getMetadata(connSession);
+
+        // Convert sink columns to connector columns for INSERT SQL generation
+        List<ConnectorColumn> connectorColumns = 
connectorTableSink.getCols().stream()
+                .map(col -> new ConnectorColumn(col.getName(),
+                        
ConnectorType.of(col.getType().getPrimitiveType().toString()),
+                        null, col.isAllowNull(), null))
+                .collect(java.util.stream.Collectors.toList());
+
+        ConnectorWriteConfig writeConfig;
+        if (metadata.supportsInsert()) {
+            ConnectorTableHandle tableHandle = 
metadata.getTableHandle(connSession,
+                    targetTable.getRemoteDbName(), targetTable.getRemoteName())
+                    .orElseThrow(() -> new AnalysisException(
+                            "Table not found: " + targetTable.getRemoteDbName()
+                                    + "." + targetTable.getRemoteName()
+                                    + " in catalog " + catalog.getName()));

Review Comment:
   This fallback is unsafe for read-only plugin catalogs like ES. Once we 
synthesize a `FILE_WRITE` config here, the statement keeps going through 
`BuildInsertExecutorResult.build()` and `InsertIntoTableCommand.initPlan()`: FE 
constructs a `PluginDrivenInsertExecutor` (which already registers an 
`InsertLoadJob` in `AbstractInsertExecutor`), starts a plugin transaction in 
`beginTransaction()`, and only then does 
`PluginDrivenInsertExecutor.beforeExec()` reject the statement via 
`supportsInsert()`. For `INSERT INTO es_catalog.tbl ...`, that means a 
statement which used to be rejected during sink creation now leaves behind 
FE-side write state: a stale `PENDING` `SHOW LOAD` row, plus a leaked 
`PluginDrivenTransactionManager` entry because `executeSingleInsert()` calls 
`beforeExec()` before its cleanup `try/catch`. We should fail planning here (or 
earlier) instead of fabricating a write config for non-insert-capable 
connectors.



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