You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by GitBox <gi...@apache.org> on 2023/01/17 07:11:33 UTC

[GitHub] [incubator-seatunnel] sunnyzhu92 commented on a diff in pull request #3896: [Improve][SourceConnector] Unified schema parameter, update IoTDB sou…

sunnyzhu92 commented on code in PR #3896:
URL: https://github.com/apache/incubator-seatunnel/pull/3896#discussion_r1071816091


##########
seatunnel-connectors-v2/connector-iotdb/src/main/java/org/apache/seatunnel/connectors/seatunnel/iotdb/source/IoTDBSource.java:
##########
@@ -65,21 +65,29 @@ public String getPluginName() {
 
     @Override
     public void prepare(Config pluginConfig) throws PrepareFailException {
-        CheckResult result = CheckConfigUtil.checkAllExists(pluginConfig, HOST.key(), PORT.key());
-        if (!result.isSuccess()) {
-            result = CheckConfigUtil.checkAllExists(pluginConfig, NODE_URLS.key());
-
-            if (!result.isSuccess()) {
-                throw new IotdbConnectorException(SeaTunnelAPIErrorCode.CONFIG_VALIDATION_FAILED,
-                    String.format("PluginName: %s, PluginType: %s, Message: %s",
-                        getPluginName(), PluginType.SOURCE,
-                        result.getMsg())
-                );
-            }
+        CheckResult urlCheckResult = CheckConfigUtil.checkAllExists(pluginConfig, HOST.key(), PORT.key());
+        if (!urlCheckResult.isSuccess()) {
+            urlCheckResult = CheckConfigUtil.checkAllExists(pluginConfig, NODE_URLS.key());
+        }
+        CheckResult schemaCheckResult = CheckConfigUtil.checkAllExists(pluginConfig, SeaTunnelSchema.SCHEMA.key());
+        CheckResult mergedConfigCheck = CheckConfigUtil.mergeCheckResults(urlCheckResult, schemaCheckResult);
+        if (!mergedConfigCheck.isSuccess()) {
+            throw new IotdbConnectorException(SeaTunnelAPIErrorCode.CONFIG_VALIDATION_FAILED,
+                String.format("PluginName: %s, PluginType: %s, Message: %s",
+                    getPluginName(), PluginType.SOURCE,
+                    mergedConfigCheck.getMsg())
+            );
+        }
+        try {
+            Config schemaConfig = pluginConfig.getConfig(SeaTunnelSchema.SCHEMA.key());
+            this.typeInfo = SeaTunnelSchema.buildWithConfig(schemaConfig).getSeaTunnelRowType();
+            pluginConfig.entrySet().forEach(entry -> configParams.put(entry.getKey(), entry.getValue().unwrapped()));
+        } catch (Exception e) {
+            throw new IotdbConnectorException(SeaTunnelAPIErrorCode.CONFIG_VALIDATION_FAILED,
+                String.format("PluginName: %s, PluginType: %s, Message: %s",
+                    getPluginName(), PluginType.SOURCE, e)
+            );
         }

Review Comment:
   @TyrantLucifer Thanks for your suggestions.I have done this.



##########
seatunnel-connectors-v2/connector-iotdb/src/main/java/org/apache/seatunnel/connectors/seatunnel/iotdb/source/IoTDBSourceFactory.java:
##########
@@ -49,7 +50,7 @@ public String factoryIdentifier() {
     @Override
     public OptionRule optionRule() {
         return OptionRule.builder()
-                .required(NODE_URLS, USERNAME, PASSWORD, SQL)
+                .required(NODE_URLS, USERNAME, PASSWORD, SQL, SeaTunnelSchema.SCHEMA)

Review Comment:
   @TyrantLucifer Thanks for your suggestions.I have done 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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org