You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by "odbozhou (via GitHub)" <gi...@apache.org> on 2023/02/02 11:40:58 UTC

[GitHub] [rocketmq-connect] odbozhou commented on a diff in pull request #398: [ISSUE #392] Add iotdb source connector

odbozhou commented on code in PR #398:
URL: https://github.com/apache/rocketmq-connect/pull/398#discussion_r1094401658


##########
connectors/rocketmq-connect-iotdb/src/main/java/org/apache/rocketmq/connect/iotdb/exception/IotdbRuntimeException.java:
##########
@@ -0,0 +1,25 @@
+/*
+ * 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.rocketmq.connect.iotdb.exception;
+
+public class IotdbRuntimeException extends RuntimeException {

Review Comment:
   Inheriting ConnectException may be a better choice



##########
connectors/rocketmq-connect-iotdb/src/main/java/org/apache/rocketmq/connect/iotdb/replicator/source/IotdbQuery.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * 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.rocketmq.connect.iotdb.replicator.source;
+
+import io.openmessaging.KeyValue;
+import io.openmessaging.connector.api.data.RecordOffset;
+import java.util.List;
+import org.apache.iotdb.rpc.IoTDBConnectionException;
+import org.apache.iotdb.rpc.StatementExecutionException;
+import org.apache.iotdb.session.Session;
+import org.apache.iotdb.session.SessionDataSet;
+import org.apache.rocketmq.connect.iotdb.config.IotdbConfig;
+import org.apache.rocketmq.connect.iotdb.config.IotdbConstant;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class IotdbQuery {
+
+    private static final Logger log = LoggerFactory.getLogger(IotdbQuery.class);
+
+    private IotdbReplicator replicator;
+
+    private IotdbConfig config;
+
+    private Session session;
+
+    public IotdbQuery(IotdbReplicator replicator) {
+        this.replicator = replicator;
+        this.config = replicator.getConfig();
+        session =
+            new Session.Builder()
+                .host(config.getIotdbHost())
+                .port(config.getIotdbPort())
+                .build();
+        try {
+            session.open();
+        } catch (IoTDBConnectionException e) {
+            log.error("iotdb session open failed", e);
+        }
+
+    }
+
+    public void start(RecordOffset recordOffset, KeyValue keyValue) {
+
+
+        String path = null;
+        try {
+            path = keyValue.getString(IotdbConstant.IOTDB_PATH);
+            if (path == null || path.trim().equals("")) {
+                log.warn("the path is empty,please check config");
+                return;
+            }
+            long time = 0;
+            if (recordOffset != null && recordOffset.getOffset() != null && recordOffset.getOffset().size() > 0) {
+                final Long offsetValue = (Long) recordOffset.getOffset().get(keyValue.getString(IotdbConstant.IOTDB_PARTITION) + path);
+                time = offsetValue;
+            }
+            int limit = 500;
+            long offset = 1;
+            String sql = "select * from " + path + " where time > " + time + " limit " + limit + " offset " + offset;

Review Comment:
   If you just use timestamps, is it impossible to guarantee the uniqueness of the data? It is possible that some data have exactly the same time



##########
connectors/rocketmq-connect-iotdb/src/main/java/org/apache/rocketmq/connect/iotdb/replicator/source/IotdbQuery.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * 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.rocketmq.connect.iotdb.replicator.source;
+
+import io.openmessaging.KeyValue;
+import io.openmessaging.connector.api.data.RecordOffset;
+import java.util.List;
+import org.apache.iotdb.rpc.IoTDBConnectionException;
+import org.apache.iotdb.rpc.StatementExecutionException;
+import org.apache.iotdb.session.Session;
+import org.apache.iotdb.session.SessionDataSet;
+import org.apache.rocketmq.connect.iotdb.config.IotdbConfig;
+import org.apache.rocketmq.connect.iotdb.config.IotdbConstant;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class IotdbQuery {
+
+    private static final Logger log = LoggerFactory.getLogger(IotdbQuery.class);
+
+    private IotdbReplicator replicator;
+
+    private IotdbConfig config;
+
+    private Session session;
+
+    public IotdbQuery(IotdbReplicator replicator) {
+        this.replicator = replicator;
+        this.config = replicator.getConfig();
+        session =

Review Comment:
   Is it more appropriate to open the session in start ?



##########
connectors/rocketmq-connect-iotdb/src/main/java/org/apache/rocketmq/connect/iotdb/connector/IotdbSourceConnector.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.rocketmq.connect.iotdb.connector;
+
+import io.openmessaging.KeyValue;
+import io.openmessaging.connector.api.component.task.Task;
+import io.openmessaging.connector.api.component.task.source.SourceConnector;
+import io.openmessaging.internal.DefaultKeyValue;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.rocketmq.connect.iotdb.config.IotdbConfig;
+import org.apache.rocketmq.connect.iotdb.config.IotdbConstant;
+import org.apache.rocketmq.connect.iotdb.exception.IotdbRuntimeException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class IotdbSourceConnector extends SourceConnector {
+
+    private Logger logger = LoggerFactory.getLogger(IotdbSourceConnector.class);
+
+    private KeyValue keyValue;
+
+    private IotdbConfig config;
+
+    @Override
+    public List<KeyValue> taskConfigs(int maxTasks) {

Review Comment:
   maxTasks does not take effect



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

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