Jiabao-Sun commented on code in PR #45: URL: https://github.com/apache/flink-connector-mongodb/pull/45#discussion_r1830280938
########## flink-connector-mongodb/src/main/java/org/apache/flink/connector/mongodb/source/enumerator/splitter/MongoPaginationSplitter.java: ########## @@ -0,0 +1,101 @@ +/* + * 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.source.split.MongoScanSourceSplit; +import org.apache.flink.util.Preconditions; + +import com.mongodb.MongoNamespace; +import com.mongodb.client.model.Aggregates; +import com.mongodb.client.model.Projections; +import com.mongodb.client.model.Sorts; +import org.bson.BsonDocument; +import org.bson.conversions.Bson; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import static org.apache.flink.connector.mongodb.common.utils.MongoConstants.BSON_MAX_BOUNDARY; +import static org.apache.flink.connector.mongodb.common.utils.MongoConstants.BSON_MIN_BOUNDARY; +import static org.apache.flink.connector.mongodb.common.utils.MongoConstants.ID_FIELD; +import static org.apache.flink.connector.mongodb.common.utils.MongoConstants.ID_HINT; + +/** Mongo Splitter that splits MongoDB collection evenly by record counts. */ +@Internal +public class MongoPaginationSplitter { + + private MongoPaginationSplitter() {} + + public static Collection<MongoScanSourceSplit> split(MongoSplitContext splitContext) { + int partitionRecordSize = splitContext.getReadOptions().getPartitionRecordSize(); + Preconditions.checkArgument( + partitionRecordSize > 0, + "The partition record size must be set to a positive integer."); + + int numberOfPartitions = + (int) (Math.ceil(splitContext.getCount() / (double) partitionRecordSize)); Review Comment: Thanks @yuxiqian for the great work. Looks good overall. A suggestion is that we might not need to set the default value of `scan.partition.record-size` to 0, but rather leave it without a default value. This is because having 0 as the default value can be somewhat misleading. I prefer that when the user does not explicitly set the `scan.partition.record-size` config option, the number of documents per partition should be calculated based on `scan.partition.size` and `avgObjSize`, similar to the `MongoSampleSplitter`. When the user explicitly sets the `scan.partition.record-size` config option, the number of documents per partition should be determined by this parameter. https://github.com/apache/flink-connector-mongodb/blob/e0a04d0e64e7e8cfa073ab92abbc2c6c0ae20830/flink-connector-mongodb/src/main/java/org/apache/flink/connector/mongodb/source/enumerator/splitter/MongoSampleSplitter.java#L83-L97 Additionally, it would be best for `MongoPaginationSplitter` to provide unit tests similar to `MongoPaginationSplitterTest` to verify edge cases. -- 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