TyrantLucifer commented on code in PR #2832:
URL: 
https://github.com/apache/incubator-seatunnel/pull/2832#discussion_r1063191401


##########
seatunnel-connectors-v2/connector-common/src/main/java/org/apache/seatunnel/connectors/seatunnel/common/schema/SeaTunnelSchema.java:
##########
@@ -103,7 +103,7 @@ private static int[] parseDecimalPS(String type) {
         return new int[]{precision, scale};
     }
 
-    private static SeaTunnelDataType<?> parseTypeByString(String type) {
+    public static SeaTunnelDataType<?> parseTypeByString(String type) {

Review Comment:
   Revert?



##########
seatunnel-connectors-v2/connector-tdengine/src/main/java/org/apache/seatunnel/connectors/seatunnel/tdengine/sink/TDengineSinkWriter.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.tdengine.sink;
+
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import 
org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSinkWriter;
+import 
org.apache.seatunnel.connectors.seatunnel.tdengine.config.TDengineSourceConfig;
+
+import org.apache.seatunnel.shade.com.typesafe.config.Config;
+
+import com.google.common.base.Throwables;
+import com.google.common.collect.Lists;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.StringUtils;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Objects;
+
+@Slf4j
+public class TDengineSinkWriter extends AbstractSinkWriter<SeaTunnelRow, Void> 
{
+
+    private static final DateTimeFormatter FORMATTER = 
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
+    private final Connection conn;
+    private final TDengineSourceConfig config;
+    private int tagsNum;
+
+    @SneakyThrows
+    public TDengineSinkWriter(Config pluginConfig, SeaTunnelRowType 
seaTunnelRowType) {
+        config = TDengineSourceConfig.buildSourceConfig(pluginConfig);
+        String jdbcUrl = StringUtils.join(config.getUrl(), 
config.getDatabase(), "?user=", config.getUsername(), "&password=", 
config.getPassword());
+        conn = DriverManager.getConnection(jdbcUrl);
+        try (Statement statement = conn.createStatement()) {
+            final ResultSet metaResultSet = statement.executeQuery("desc " + 
config.getDatabase() + "." + config.getStable());
+            while (metaResultSet.next()) {
+                if (StringUtils.equals("TAG", 
metaResultSet.getString("note"))) {
+                    tagsNum++;
+                }
+            }
+        }
+    }
+
+    @SneakyThrows
+    @Override
+    @SuppressWarnings("checkstyle:RegexpSingleline")
+    public void write(SeaTunnelRow element) {
+        final ArrayList<Object> tags = Lists.newArrayList();
+        for (int i = element.getArity() - tagsNum; i < element.getArity(); 
i++) {
+            tags.add(element.getField(i));
+        }
+        final String tagValues = 
StringUtils.join(convertDataType(tags.toArray()), ",");
+
+        final Object[] metrics = ArrayUtils.subarray(element.getFields(), 1, 
element.getArity() - tagsNum);
+
+        try (Statement statement = 
conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY)) {
+            String sql = "INSERT INTO " + element.getField(0)

Review Comment:
   String.format is better.



-- 
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-unsubscr...@seatunnel.apache.org

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

Reply via email to