Jiabao-Sun commented on code in PR #1:
URL: 
https://github.com/apache/flink-connector-mongodb/pull/1#discussion_r1025564871


##########
flink-connector-mongodb/src/main/java/org/apache/flink/connector/mongodb/source/enumerator/splitter/MongoSplitters.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.flink.connector.mongodb.source.enumerator.splitter;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.connector.mongodb.common.config.MongoConnectionOptions;
+import org.apache.flink.connector.mongodb.common.utils.MongoUtils;
+import org.apache.flink.connector.mongodb.source.config.MongoReadOptions;
+import org.apache.flink.connector.mongodb.source.split.MongoScanSourceSplit;
+import org.apache.flink.connector.mongodb.source.split.MongoSourceSplit;
+
+import com.mongodb.MongoNamespace;
+import com.mongodb.client.MongoClient;
+import com.mongodb.client.MongoClients;
+import org.bson.BsonDocument;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.Collection;
+
+import static 
org.apache.flink.connector.mongodb.common.utils.MongoConstants.ERROR_MESSAGE_FIELD;
+import static 
org.apache.flink.connector.mongodb.common.utils.MongoUtils.isCommandSucceed;
+
+/** To split collections of MongoDB to {@link MongoSourceSplit}s. */
+@Internal
+public class MongoSplitters implements Serializable, Closeable {
+
+    private static final long serialVersionUID = 1L;
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(MongoSplitters.class);
+
+    private final MongoReadOptions readOptions;
+    private final boolean limitPushedDown;
+    private final MongoClient mongoClient;
+
+    public MongoSplitters(
+            MongoConnectionOptions connectionOptions,
+            MongoReadOptions readOptions,
+            boolean limitPushedDown) {
+        this.readOptions = readOptions;
+        this.limitPushedDown = limitPushedDown;
+        this.mongoClient = MongoClients.create(connectionOptions.getUri());
+    }
+
+    public Collection<MongoScanSourceSplit> split(MongoNamespace namespace) {
+        BsonDocument collStats = MongoUtils.collStats(mongoClient, namespace);
+        if (!isCommandSucceed(collStats)) {
+            LOG.error(
+                    "Execute command collStats failed: {}",
+                    collStats.getString(ERROR_MESSAGE_FIELD));
+            throw new IllegalStateException(String.format("Collection not 
found %s", namespace));
+        }
+
+        MongoSplitContext splitContext =
+                MongoSplitContext.of(readOptions, mongoClient, namespace, 
collStats);
+
+        if (limitPushedDown) {
+            LOG.info("Limit {} is applied, using single splitter", 
limitPushedDown);
+            return MongoSingleSplitter.INSTANCE.split(splitContext);
+        }

Review Comment:
   Another reason for why we don't try to split things is that it is difficult 
for us to merge the results of each chunk when reading concurrently. We need to 
cache these results to sort and limit, which may cause a lot of overhead.
   



-- 
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: issues-unsubscr...@flink.apache.org

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

Reply via email to