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

[GitHub] [rocketmq-connect] Oliverwqcwrw commented on a diff in pull request #410: [ISSUE #408] Add apache hive source connector

Oliverwqcwrw commented on code in PR #410:
URL: https://github.com/apache/rocketmq-connect/pull/410#discussion_r1095248097


##########
connectors/rocketmq-connect-hive/src/main/java/org/apache/rocketmq/connect/hive/connector/HiveSourceConnector.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * 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.hive.connector;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import io.openmessaging.KeyValue;
+import io.openmessaging.connector.api.component.task.Task;
+import io.openmessaging.connector.api.component.task.source.SourceConnector;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import org.apache.rocketmq.connect.hive.config.HiveJdbcDriverManager;
+import org.apache.rocketmq.connect.hive.config.HiveConfig;
+import org.apache.rocketmq.connect.hive.config.HiveConstant;
+import org.apache.rocketmq.connect.hive.replicator.source.HiveQuery;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class HiveSourceConnector extends SourceConnector {
+
+    private static final Logger log = LoggerFactory.getLogger(HiveSourceConnector.class);
+
+    private KeyValue keyValue;
+    private HiveConfig config;
+
+    private transient Statement stmt;
+
+    @Override
+    public List<KeyValue> taskConfigs(int maxTasks) {
+        List<KeyValue> configs = new ArrayList<>();
+        JSONObject jsonObject = JSON.parseObject(this.config.getTables());
+        for (Map.Entry<String, Object> entry : jsonObject.entrySet()) {
+            final String tableName = entry.getKey();
+            final JSONObject value = (JSONObject) entry.getValue();
+            final Map.Entry<String, Object> increment = value.entrySet().stream().findFirst().get();
+            final String incrementField = increment.getKey();
+            String initIncrementValue = increment.getValue().toString();
+            this.keyValue.put(HiveConstant.TABLE_NAME, tableName);
+            this.keyValue.put(HiveConstant.INCREMENT_FIELD, incrementField);
+            this.keyValue.put(HiveConstant.INCREMENT_VALUE, initIncrementValue);
+            this.keyValue.put(tableName, incrementField);
+            if (maxTasks < 2) {
+                configs.add(this.keyValue);
+                continue;
+            }
+            try {
+                final Integer count = HiveQuery.countData(stmt, tableName, incrementField, initIncrementValue);
+                if (count < 100000) {
+                    configs.add(this.keyValue);
+                    continue;
+                }
+                final int eachNum = count / maxTasks;
+                for (int i = 0; i < maxTasks; i++) {

Review Comment:
   The current scheme combines table data and table data volume to determine the number of tasks.
   
   If the number of tables and the minimum value of maxTask are used to determine the number of tasks, there are two problems.
   
    If the number of tables is small and the data volume of a table is large, the concurrency will not be improved even if maxTask is increased. 
   
   If maxTask is small, a task may process multiple tables, and the data processing will be slow



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