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


##########
fe/fe-core/src/main/java/org/apache/doris/catalog/TableIf.java:
##########
@@ -253,6 +261,8 @@ public String toEngineName() {
                     return "dictionary";
                 case DORIS_EXTERNAL_TABLE:
                     return "External_Doris";
+                case PLUGIN_EXTERNAL_TABLE:
+                    return "Plugin";

Review Comment:
   This changes the public engine name for migrated JDBC/ES tables from their 
legacy values to `Plugin`, because `ExternalTable.getEngine()` still delegates 
to `getType().toEngineName()`. `getEngineTableTypeName()` only fixes `SHOW 
CREATE TABLE`; it does not cover the other metadata surfaces that still call 
`getEngine()` (`SHOW TABLE STATUS`, `information_schema.tables`, 
`FrontendServiceImpl`/`TTableStatus`, `MetaInfoActionV2`, etc.). That is a 
user-visible compatibility regression for existing JDBC/ES catalogs after 
replay/migration.



##########
fe/fe-core/src/main/java/org/apache/doris/datasource/PluginDrivenExternalCatalog.java:
##########
@@ -0,0 +1,300 @@
+// 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.common.DdlException;
+import org.apache.doris.connector.ConnectorFactory;
+import org.apache.doris.connector.ConnectorSessionBuilder;
+import org.apache.doris.connector.DefaultConnectorContext;
+import org.apache.doris.connector.DefaultConnectorValidationContext;
+import org.apache.doris.connector.api.Connector;
+import org.apache.doris.connector.api.ConnectorSession;
+import org.apache.doris.connector.api.ConnectorTestResult;
+import org.apache.doris.datasource.property.metastore.MetastoreProperties;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.transaction.PluginDrivenTransactionManager;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+/**
+ * An {@link ExternalCatalog} backed by a Connector SPI plugin.
+ *
+ * <p>This adapter bridges the connector SPI ({@link Connector}) with the 
existing
+ * ExternalCatalog hierarchy. Metadata operations are delegated to the 
connector's
+ * {@link org.apache.doris.connector.api.ConnectorMetadata} implementation.</p>
+ *
+ * <p>When created via {@link CatalogFactory}, the Connector instance is 
provided
+ * directly. After GSON deserialization (FE restart), the Connector is 
recreated
+ * from catalog properties during {@link #initLocalObjectsImpl()}.</p>
+ */
+public class PluginDrivenExternalCatalog extends ExternalCatalog {
+
+    private static final Logger LOG = 
LogManager.getLogger(PluginDrivenExternalCatalog.class);
+
+    // Volatile for cross-thread visibility; all mutations happen under 
synchronized(this)
+    // via makeSureInitialized() → initLocalObjectsImpl(), or 
resetToUninitialized() → onClose().
+    private transient volatile Connector connector;
+
+    /** No-arg constructor for GSON deserialization. */
+    public PluginDrivenExternalCatalog() {
+    }
+
+    /**
+     * Creates a plugin-driven catalog with an already-created Connector.
+     *
+     * @param catalogId unique catalog id
+     * @param name catalog name
+     * @param resource optional resource name
+     * @param props catalog properties
+     * @param comment catalog comment
+     * @param connector the SPI connector instance
+     */
+    public PluginDrivenExternalCatalog(long catalogId, String name, String 
resource,
+            Map<String, String> props, String comment, Connector connector) {
+        super(catalogId, name, InitCatalogLog.Type.PLUGIN, comment);
+        this.catalogProperty = new CatalogProperty(resource, props);
+        this.connector = connector;
+    }
+
+    @Override
+    protected void initLocalObjectsImpl() {
+        // Always (re-)create the connector so it gets the proper engine 
context,
+        // including the catalog's execution authenticator for 
Kerberos/secured HMS.
+        // The connector created by CatalogFactory used a lightweight context
+        // without auth (the catalog didn't exist yet); we replace it now.
+        Connector newConnector = createConnectorFromProperties();
+        if (newConnector != null) {
+            connector = newConnector;
+        }
+        if (connector == null) {
+            throw new RuntimeException("No ConnectorProvider found for 
plugin-driven catalog: "
+                    + name + ", type: " + getType()
+                    + ". Ensure the connector plugin is installed.");
+        }
+        transactionManager = new PluginDrivenTransactionManager();
+        initPreExecutionAuthenticator();
+    }
+
+    @Override
+    protected synchronized void initPreExecutionAuthenticator() {
+        if (executionAuthenticator != null) {
+            return;
+        }
+        try {
+            MetastoreProperties msp = catalogProperty.getMetastoreProperties();
+            if (msp != null) {
+                executionAuthenticator = msp.getExecutionAuthenticator();
+                return;
+            }
+        } catch (Exception ignored) {
+            // Not all catalog types have metastore properties (e.g., JDBC, ES)
+        }
+        super.initPreExecutionAuthenticator();
+    }
+
+    /**
+     * Creates a new Connector from catalog properties. Extracted as a 
protected method
+     * so tests can override without depending on the static ConnectorFactory 
registry.
+     */
+    protected Connector createConnectorFromProperties() {
+        // Use getType() which falls back to logType when "type" is not in 
properties.
+        // This handles image deserialization of old resource-backed catalogs 
whose
+        // properties never contained "type" (it was derived from the Resource 
object).
+        String catalogType = getType();
+        return ConnectorFactory.createConnector(catalogType,
+                catalogProperty.getProperties(),
+                new DefaultConnectorContext(name, id, 
this::getExecutionAuthenticator));
+    }
+
+    @Override
+    public void checkProperties() throws DdlException {
+        super.checkProperties();
+        String catalogType = getType();
+        try {
+            ConnectorFactory.validateProperties(catalogType, 
catalogProperty.getProperties());

Review Comment:
   The new JDBC SPI path no longer preserves the old create-time property 
validation. `PropertyAnalyzer.checkCatalogProperties()` is effectively a no-op 
here, and `JdbcConnectorProvider.validateProperties()` only checks 
`lower_case_table_names` / `meta_names_mapping`. Under the old 
`JdbcExternalCatalog.checkProperties()` path, FE rejected missing `jdbc_url` / 
`driver_url` / `driver_class`, invalid `only_specified_database`, inconsistent 
include/exclude database lists, and invalid pool settings up front. Now those 
cases can be accepted and either fail much later on first use or silently fall 
back to defaults via `JdbcConnectorProperties.getInt()`. Please restore parity 
with the legacy validation behavior before routing JDBC catalogs through this 
SPI path.



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