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/16 13:26:31 UTC

[GitHub] [incubator-seatunnel] TaoZex commented on a diff in pull request #3932: [Improve][Connector-V2][Fake] Improve fake connector

TaoZex commented on code in PR #3932:
URL: https://github.com/apache/incubator-seatunnel/pull/3932#discussion_r1071238365


##########
seatunnel-connectors-v2/connector-fake/src/main/java/org/apache/seatunnel/connectors/seatunnel/fake/config/FakeConfig.java:
##########
@@ -90,6 +205,174 @@ public static FakeConfig buildWithConfig(Config config) {
             }
             builder.fakeRows(rows);
         }
+        if (config.hasPath(STRING_TEMPLATE.key())) {
+            builder.stringTemplate(config.getStringList(STRING_TEMPLATE.key()));
+        }
+        if (config.hasPath(TINYINT_TEMPLATE.key())) {
+            builder.tinyintTemplate(config.getIntList(TINYINT_TEMPLATE.key()));
+        }
+        if (config.hasPath(SMALLINT_TEMPLATE.key())) {
+            builder.smallintTemplate(config.getIntList(SMALLINT_TEMPLATE.key()));
+        }
+        if (config.hasPath(INT_TEMPLATE.key())) {
+            builder.intTemplate(config.getIntList(INT_TEMPLATE.key()));
+        }
+        if (config.hasPath(BIGINT_TEMPLATE.key())) {
+            builder.bigTemplate(config.getLongList(BIGINT_TEMPLATE.key()));
+        }
+        if (config.hasPath(FLOAT_TEMPLATE.key())) {
+            builder.floatTemplate(config.getDoubleList(FLOAT_TEMPLATE.key()));
+        }
+        if (config.hasPath(DOUBLE_TEMPLATE.key())) {
+            builder.doubleTemplate(config.getDoubleList(DOUBLE_TEMPLATE.key()));
+        }
+        if (config.hasPath(DATE_YEAR_TEMPLATE.key())) {
+            builder.dateYearTemplate(config.getIntList(DATE_YEAR_TEMPLATE.key()));
+        }
+        if (config.hasPath(DATE_MONTH_TEMPLATE.key())) {
+            builder.dateMonthTemplate(config.getIntList(DATE_MONTH_TEMPLATE.key()));
+        }
+        if (config.hasPath(DATE_DAY_TEMPLATE.key())) {
+            builder.dateDayTemplate(config.getIntList(DATE_DAY_TEMPLATE.key()));
+        }
+        if (config.hasPath(TIME_HOUR_TEMPLATE.key())) {
+            builder.timeHourTemplate(config.getIntList(TIME_HOUR_TEMPLATE.key()));
+        }
+        if (config.hasPath(TIME_MINUTE_TEMPLATE.key())) {
+            builder.timeMinuteTemplate(config.getIntList(TIME_MINUTE_TEMPLATE.key()));
+        }
+        if (config.hasPath(TIME_SECOND_TEMPLATE.key())) {
+            builder.timeSecondTemplate(config.getIntList(TIME_SECOND_TEMPLATE.key()));
+        }
+        if (config.hasPath(TINYINT_MIN.key())) {
+            int tinyintMin = config.getInt(TINYINT_MIN.key());
+            if (tinyintMin < TINYINT_MIN.defaultValue() || tinyintMin > TINYINT_MAX.defaultValue()) {
+                throw new FakeConnectorException(CommonErrorCode.ILLEGAL_ARGUMENT,
+                        TINYINT_MIN.key() + " should >= " + TINYINT_MIN.defaultValue() +
+                                " and <= " + TINYINT_MAX.defaultValue());

Review Comment:
   Using String.format may be better.
   There's a lot of code duplication like this, how about wrapping it as a method to return an error message?



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