ruanwenjun commented on code in PR #1850:
URL: 
https://github.com/apache/incubator-seatunnel/pull/1850#discussion_r870321348


##########
seatunnel-core/seatunnel-core-flink-sql/src/main/java/org/apache/seatunnel/core/sql/job/Executor.java:
##########
@@ -75,12 +116,65 @@ private static StatementSet handleStatements(String 
workFlowContent, StreamTable
             if (op instanceof CatalogSinkModifyOperation) {
                 statementSet.addInsertSql(stmt);
             } else {
+                if (op instanceof CreateTableOperation) {
+                    String connectorType = ((CreateTableOperation) 
op).getCatalogTable().getOptions().get(CONNECTOR_IDENTIFIER);
+                    loadConnector(connectorType, executionEnvConfiguration);
+                }
+
                 tEnv.executeSql(stmt);
             }
         }
         return statementSet;
     }
 
+    private static void loadConnector(String connectorType, Configuration 
configuration) {
+        Iterator<Factory> factories = ServiceLoader.load(Factory.class, 
CLASSLOADER).iterator();
+        while (factories.hasNext()) {
+            Factory factory = factories.next();
+
+            /**
+             * Handle for two cases:
+             * 1. Flink built-in connectors.
+             * 2. Connectors have been placed in classpath.
+             */
+            if (factory.factoryIdentifier().equals(connectorType)) {
+                return;
+            }
+        }
+
+        Common.setDeployMode(DeployMode.CLIENT.getName());
+        File connectorDir = 
Common.connectorJarDir(SQL_CONNECTOR_PREFIX).toFile();
+        if (!connectorDir.exists() || connectorDir.listFiles() == null) {
+            return;
+        }
+
+        Optional<File> connectorFile = Arrays.stream(connectorDir.listFiles())
+            .filter(file -> file.getName().startsWith(CONNECTOR_JAR_PREFIX + 
connectorType))
+            .findFirst();
+
+        if (connectorFile.isPresent()) {
+            // handleStatements need this.
+            CLASSLOADER.addJar(connectorFile.get().toPath());
+
+            List<String> jars = configuration.get(PipelineOptions.JARS);
+            jars = jars == null ? new ArrayList<>() : jars;
+
+            List<String> classpath = 
configuration.get(PipelineOptions.CLASSPATHS);
+            classpath = classpath == null ? new ArrayList<>() : classpath;
+
+            try {
+                String connectorURL = 
connectorFile.get().toPath().toUri().toURL().toString();
+                jars.add(connectorURL);
+                classpath.add(connectorURL);
+
+                configuration.set(PipelineOptions.JARS, jars);
+                configuration.set(PipelineOptions.CLASSPATHS, classpath);
+            } catch (MalformedURLException ignored) {
+                LOGGER.error("Failed to load connector {}. Connector file: 
{}", connectorType, connectorFile.get().getAbsolutePath());
+            }

Review Comment:
   Why ignore this exception, please add comment to explain this.



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

Reply via email to