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


##########
seatunnel-connectors-v2/connector-iotdb/src/main/java/org/apache/seatunnel/connectors/seatunnel/iotdb/source/IoTDBSourceSplitEnumerator.java:
##########
@@ -0,0 +1,174 @@
+/*
+ * 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.iotdb.source;
+
+import static 
org.apache.seatunnel.connectors.seatunnel.iotdb.config.SourceConfig.LOWER_BOUND;
+import static 
org.apache.seatunnel.connectors.seatunnel.iotdb.config.SourceConfig.NUM_PARTITIONS;
+import static 
org.apache.seatunnel.connectors.seatunnel.iotdb.config.SourceConfig.SQL;
+import static 
org.apache.seatunnel.connectors.seatunnel.iotdb.config.SourceConfig.UPPER_BOUND;
+import static 
org.apache.seatunnel.connectors.seatunnel.iotdb.constant.SourceConstants.DEFAULT_PARTITIONS;
+import static 
org.apache.seatunnel.connectors.seatunnel.iotdb.constant.SourceConstants.SQL_WHERE;
+import static 
org.apache.iotdb.tsfile.common.constant.QueryConstant.RESERVED_TIME;
+
+import org.apache.seatunnel.api.source.SourceSplitEnumerator;
+import org.apache.seatunnel.common.config.Common;
+import org.apache.seatunnel.connectors.seatunnel.iotdb.state.IoTDBSourceState;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+public class IoTDBSourceSplitEnumerator implements 
SourceSplitEnumerator<IoTDBSourceSplit, IoTDBSourceState> {
+
+    private final Context<IoTDBSourceSplit> context;
+    private Set<IoTDBSourceSplit> pendingSplit;
+    private Set<IoTDBSourceSplit> assignedSplit;
+    private Map<String, Object> conf;
+
+    public 
IoTDBSourceSplitEnumerator(SourceSplitEnumerator.Context<IoTDBSourceSplit> 
context, Map<String, Object> conf) {
+        this.context = context;
+        this.conf = conf;
+    }
+
+    public 
IoTDBSourceSplitEnumerator(SourceSplitEnumerator.Context<IoTDBSourceSplit> 
context, IoTDBSourceState sourceState, Map<String, Object> conf) {
+        this(context, conf);
+        this.assignedSplit = sourceState.getAssignedSplit();
+    }
+
+    @Override
+    public void open() {
+        this.assignedSplit = new HashSet<>();
+        this.pendingSplit = new HashSet<>();
+    }
+
+    @Override
+    public void run() {
+        pendingSplit = getIotDBSplit();
+        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 where age > 0 and age < 10"
+     * <p>
+     * split result
+     * <p>
+     * split 1: select * from test  where (time >= 1 and time < 6)  and (  age 
> 0 and age < 10 )
+     * <p>
+     * split 2: select * from test  where (time >= 6 and time < 11) and (  age 
> 0 and age < 10 )
+     */
+    private Set<IoTDBSourceSplit> getIotDBSplit() {
+        String sql = conf.get(SQL).toString();
+        Set<IoTDBSourceSplit> iotDBSourceSplits = new HashSet<>();
+        // no need numPartitions, use one partition
+        if (!conf.containsKey(NUM_PARTITIONS)) {
+            iotDBSourceSplits.add(new IoTDBSourceSplit(DEFAULT_PARTITIONS, 
sql));
+            return iotDBSourceSplits;
+        }
+        long start = Long.parseLong(conf.get(LOWER_BOUND).toString());
+        long end = Long.parseLong(conf.get(UPPER_BOUND).toString());
+        int numPartitions = 
Integer.parseInt(conf.get(NUM_PARTITIONS).toString());
+        String[] sqls = sql.split(SQL_WHERE);

Review Comment:
   If sqls.length > 2 throw exception?



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