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


##########
seatunnel-connectors-v2/connector-tdengine/src/main/java/org/apache/seatunnel/connectors/seatunnel/tdengine/source/TDengineSourceSplitEnumerator.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.source;
+
+import org.apache.seatunnel.api.source.SourceSplitEnumerator;
+import org.apache.seatunnel.common.config.Common;
+import 
org.apache.seatunnel.connectors.seatunnel.tdengine.config.TDengineSourceConfig;
+import 
org.apache.seatunnel.connectors.seatunnel.tdengine.state.TDengineSourceState;
+
+import com.google.common.collect.Sets;
+
+import java.time.Instant;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+public class TDengineSourceSplitEnumerator implements 
SourceSplitEnumerator<TDengineSourceSplit, TDengineSourceState> {
+
+    private static final DateTimeFormatter FORMATTER = 
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
+    private final SourceSplitEnumerator.Context<TDengineSourceSplit> context;
+    private final TDengineSourceConfig config;
+    private Set<TDengineSourceSplit> pendingSplit = 
Sets.newConcurrentHashSet();
+    private Set<TDengineSourceSplit> assignedSplit = 
Sets.newConcurrentHashSet();
+
+    public TDengineSourceSplitEnumerator(TDengineSourceConfig config, 
SourceSplitEnumerator.Context<TDengineSourceSplit> context) {
+        this.config = config;
+        this.context = context;
+    }
+
+    public TDengineSourceSplitEnumerator(TDengineSourceConfig config, 
TDengineSourceState sourceState, 
SourceSplitEnumerator.Context<TDengineSourceSplit> context) {
+        this(config, context);
+        this.assignedSplit = sourceState.getAssignedSplit();
+    }
+
+    private static int getSplitOwner(String tp, int numReaders) {
+        return tp.hashCode() % numReaders;
+    }
+
+    @Override
+    public void open() {
+    }
+
+    @Override
+    public void run() {
+        pendingSplit = getAllSplit();
+        assignSplit(context.registeredReaders());
+    }
+
+    /**
+     * split the time range into numPartitions parts if numPartitions is 1, 
use the whole time range if numPartitions < (end - start), use (start-end) 
partitions
+     * <p>
+     * eg: start = 1, end = 10, numPartitions = 2 sql = "select * from test"
+     * <p>
+     * split result
+     * <p>
+     * split 1: select * from test  where (time >= 1 and time < 6)
+     * <p>
+     * split 2: select * from test  where (time >= 6 and time < 11)
+     */
+    private Set<TDengineSourceSplit> getAllSplit() {
+        String sql = "select * from " + config.getStable();
+        Set<TDengineSourceSplit> sourceSplits = Sets.newHashSet();
+        // no need numPartitions, use one partition
+        if (config.getPartitionsNum() <= 1) {
+            sourceSplits.add(new TDengineSourceSplit("0", sql));
+            return sourceSplits;
+        }
+        long start = config.getLowerBound();
+        long end = config.getUpperBound();
+        int partitionsNum = config.getPartitionsNum();
+        if (end - start < partitionsNum) {
+            partitionsNum = (int) (end - start);
+        }
+        int size = (int) (end - start) / partitionsNum;
+        long currentStart = start;
+        int i = 0;
+        while (i < partitionsNum) {
+            //Left closed right away
+            long currentEnd = i == partitionsNum - 1 ? end + 1 : currentStart 
+ size;
+            String query = " where ts >= '" + 
Instant.ofEpochMilli(currentStart).atZone(ZoneId.systemDefault()).format(FORMATTER)
 + "' and ts < '" + 
Instant.ofEpochMilli(currentEnd).atZone(ZoneId.systemDefault()).format(FORMATTER)
 + "'";
+            String finalSQL = sql + query;
+            sourceSplits.add(new TDengineSourceSplit(String.valueOf(i + 
System.nanoTime()), finalSQL));
+            i++;
+            currentStart += size;
+        }
+        return sourceSplits;
+    }
+
+    @Override
+    public void addSplitsBack(List<TDengineSourceSplit> splits, int subtaskId) 
{
+        if (!splits.isEmpty()) {
+            pendingSplit.addAll(splits);
+            assignSplit(Collections.singletonList(subtaskId));
+        }
+    }
+
+    @Override
+    public int currentUnassignedSplitSize() {
+        return pendingSplit.size();
+    }
+
+    @Override
+    public void registerReader(int subtaskId) {
+        if (!pendingSplit.isEmpty()) {
+            assignSplit(Collections.singletonList(subtaskId));
+        }
+    }
+
+    private void assignSplit(Collection<Integer> taskIDList) {

Review Comment:
   reference to the new version code (fix some bugs)
   
   https://github.com/apache/incubator-seatunnel/pull/2917



##########
seatunnel-connectors-v2/connector-tdengine/src/main/java/org/apache/seatunnel/connectors/seatunnel/tdengine/source/TDengineSourceReader.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.source;
+
+import org.apache.seatunnel.api.source.Boundedness;
+import org.apache.seatunnel.api.source.Collector;
+import org.apache.seatunnel.api.source.SourceReader;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import 
org.apache.seatunnel.connectors.seatunnel.tdengine.config.TDengineSourceConfig;
+
+import com.google.common.collect.Sets;
+import com.taosdata.jdbc.TSDBDriver;
+import lombok.extern.slf4j.Slf4j;
+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.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.Properties;
+import java.util.Set;
+
+@Slf4j
+public class TDengineSourceReader implements SourceReader<SeaTunnelRow, 
TDengineSourceSplit> {
+
+    private static final long THREAD_WAIT_TIME = 500L;
+
+    private final TDengineSourceConfig config;
+
+    private final Set<TDengineSourceSplit> sourceSplits;
+
+    private final Context context;
+
+    private Connection conn;
+
+    public TDengineSourceReader(TDengineSourceConfig config, 
SourceReader.Context readerContext) {
+        this.config = config;
+        this.sourceSplits = Sets.newHashSet();
+        this.context = readerContext;
+    }
+
+    @Override
+    public void pollNext(Collector<SeaTunnelRow> collector) throws Exception {

Review Comment:
   reference to the new version  code (fix some bugs)
   
   https://github.com/apache/incubator-seatunnel/pull/2917



##########
seatunnel-connectors-v2/connector-tdengine/src/main/java/org/apache/seatunnel/connectors/seatunnel/tdengine/sink/TDengineSink.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.sink.SeaTunnelSink;
+import org.apache.seatunnel.api.sink.SinkWriter;
+import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import 
org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSimpleSink;
+import 
org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSinkWriter;
+
+import org.apache.seatunnel.shade.com.typesafe.config.Config;
+import org.apache.seatunnel.shade.com.typesafe.config.ConfigException;
+
+import com.google.auto.service.AutoService;
+import com.google.common.base.Throwables;
+import org.apache.commons.collections4.CollectionUtils;
+
+import java.io.IOException;
+import java.util.List;
+
+@AutoService(SeaTunnelSink.class)
+public class TDengineSink extends AbstractSimpleSink<SeaTunnelRow, Void> {
+    private static final String RULES = "rules";
+    private SeaTunnelRowType seaTunnelRowType;
+
+    @Override
+    public void setTypeInfo(SeaTunnelRowType seaTunnelRowType) {
+        this.seaTunnelRowType = seaTunnelRowType;
+    }
+
+    @Override
+    public SeaTunnelDataType<SeaTunnelRow> getConsumedType() {
+        return this.seaTunnelRowType;
+    }
+
+    @Override
+    public AbstractSinkWriter<SeaTunnelRow, Void> 
createWriter(SinkWriter.Context context) throws IOException {
+        return new TDengineSinkWriter(seaTunnelRowType);
+    }
+
+    @Override
+    public void prepare(Config pluginConfig) {
+        if (!pluginConfig.hasPath(RULES)) {
+            Throwables.propagateIfPossible(new ConfigException.Missing(RULES));
+        }
+
+        List<? extends Config> configList = pluginConfig.getConfigList(RULES);
+        if (CollectionUtils.isEmpty(configList)) {
+            Throwables.propagateIfPossible(new ConfigException.BadValue(RULES, 
"Assert rule config is empty, please add rule config."));
+        }
+    }
+
+    @Override
+    public String getPluginName() {
+        return "Assert";

Review Comment:
   rename `Assert` to `TDengine`?



##########
seatunnel-connectors-v2/connector-tdengine/src/main/java/org/apache/seatunnel/connectors/seatunnel/tdengine/source/TDengineSourceSplitEnumerator.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.source;
+
+import org.apache.seatunnel.api.source.SourceSplitEnumerator;
+import org.apache.seatunnel.common.config.Common;
+import 
org.apache.seatunnel.connectors.seatunnel.tdengine.config.TDengineSourceConfig;
+import 
org.apache.seatunnel.connectors.seatunnel.tdengine.state.TDengineSourceState;
+
+import com.google.common.collect.Sets;
+
+import java.time.Instant;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+public class TDengineSourceSplitEnumerator implements 
SourceSplitEnumerator<TDengineSourceSplit, TDengineSourceState> {
+
+    private static final DateTimeFormatter FORMATTER = 
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
+    private final SourceSplitEnumerator.Context<TDengineSourceSplit> context;
+    private final TDengineSourceConfig config;
+    private Set<TDengineSourceSplit> pendingSplit = 
Sets.newConcurrentHashSet();
+    private Set<TDengineSourceSplit> assignedSplit = 
Sets.newConcurrentHashSet();
+
+    public TDengineSourceSplitEnumerator(TDengineSourceConfig config, 
SourceSplitEnumerator.Context<TDengineSourceSplit> context) {
+        this.config = config;
+        this.context = context;
+    }
+
+    public TDengineSourceSplitEnumerator(TDengineSourceConfig config, 
TDengineSourceState sourceState, 
SourceSplitEnumerator.Context<TDengineSourceSplit> context) {
+        this(config, context);
+        this.assignedSplit = sourceState.getAssignedSplit();
+    }
+
+    private static int getSplitOwner(String tp, int numReaders) {
+        return tp.hashCode() % numReaders;
+    }
+
+    @Override
+    public void open() {
+    }
+
+    @Override
+    public void run() {
+        pendingSplit = getAllSplit();
+        assignSplit(context.registeredReaders());
+    }
+
+    /**
+     * split the time range into numPartitions parts if numPartitions is 1, 
use the whole time range if numPartitions < (end - start), use (start-end) 
partitions
+     * <p>
+     * eg: start = 1, end = 10, numPartitions = 2 sql = "select * from test"
+     * <p>
+     * split result
+     * <p>
+     * split 1: select * from test  where (time >= 1 and time < 6)
+     * <p>
+     * split 2: select * from test  where (time >= 6 and time < 11)
+     */
+    private Set<TDengineSourceSplit> getAllSplit() {

Review Comment:
   reference to the new version code (fix some bugs)
   
   https://github.com/apache/incubator-seatunnel/pull/2917



##########
seatunnel-connectors-v2/connector-tdengine/src/main/java/org/apache/seatunnel/connectors/seatunnel/tdengine/sink/TDengineSinkWriter.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * 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 java.io.IOException;
+
+public class TDengineSinkWriter extends AbstractSinkWriter<SeaTunnelRow, Void> 
{
+
+    private final SeaTunnelRowType seaTunnelRowType;
+
+    public TDengineSinkWriter(SeaTunnelRowType seaTunnelRowType) {
+        this.seaTunnelRowType = seaTunnelRowType;
+    }
+
+    @Override
+    @SuppressWarnings("checkstyle:RegexpSingleline")
+    public void write(SeaTunnelRow element) {

Review Comment:
   Is it not implemented?



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