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 2022/08/10 02:39:36 UTC

[GitHub] [incubator-seatunnel] ashulin commented on a diff in pull request #2392: [Feature][Connector-V2] Support user-defined schema for source connectors

ashulin commented on code in PR #2392:
URL: https://github.com/apache/incubator-seatunnel/pull/2392#discussion_r941953978


##########
seatunnel-connectors-v2/connector-common/src/main/java/org/apache/seatunnel/connectors/seatunnel/common/schema/SeatunnelSchema.java:
##########
@@ -0,0 +1,204 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.common.schema;
+
+import org.apache.seatunnel.api.table.type.ArrayType;
+import org.apache.seatunnel.api.table.type.BasicType;
+import org.apache.seatunnel.api.table.type.DecimalType;
+import org.apache.seatunnel.api.table.type.LocalTimeType;
+import org.apache.seatunnel.api.table.type.MapType;
+import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.api.table.type.SqlType;
+import org.apache.seatunnel.common.config.CheckConfigUtil;
+import org.apache.seatunnel.common.config.CheckResult;
+
+import org.apache.seatunnel.shade.com.typesafe.config.Config;
+import org.apache.seatunnel.shade.com.typesafe.config.ConfigValue;
+
+import java.util.Map;
+
+public class SeatunnelSchema {
+    private static final String FIELD_KEY = "fields";
+    private static final String FORMAT_KEY = "format";
+    private static final String DELIMITER_KEY = "delimiter";
+    private static final String DEFAULT_DELIMITER = ",";
+    private final String format;
+    private final String delimiter;
+    private final SeaTunnelRowType seaTunnelRowType;
+
+    private SeatunnelSchema(String format, String delimiter, SeaTunnelRowType seaTunnelRowType) {
+        this.format = format;
+        this.delimiter = delimiter;
+        this.seaTunnelRowType = seaTunnelRowType;
+    }
+
+    private static SeaTunnelDataType<?> parseTypeByString(String type) {
+        // init precision (used by decimal type)
+        int precision = 0;
+        // init scale (used by decimal type)
+        int scale = 0;
+        // init generic type (used by array type)
+        String genericType = "";
+        // init key generic type (used by map type)
+        String keyGenericType = "";
+        // init value generic type (used by map type)
+        String valueGenericType = "";
+        // convert type to uppercase
+        type = type.toUpperCase();
+        if (type.contains("<") || type.contains(">")) {
+            // Map type or Array type
+            int start = type.indexOf("<");
+            int end = type.lastIndexOf(">");
+            genericType = type
+                    // get the content between '<' and '>'
+                    .substring(start + 1, end)
+                    // replace the space between key and value
+                    .replace(" ", "");
+            if (type.contains("MAP")) {

Review Comment:
   ```suggestion
               if (type.startsWith(SqlType.MAP.name());) {
   ```
   Array & Decimal type in the same way.



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