JingsongLi commented on a change in pull request #15:
URL: https://github.com/apache/flink-table-store/pull/15#discussion_r805557046



##########
File path: 
flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/source/FileStoreSourceSplitGenerator.java
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.table.store.connector.source;
+
+import org.apache.flink.table.store.file.operation.FileStoreScan;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * The {@code FileStoreSplitGenerator}'s task is to plan all files to be read 
and to split them into
+ * a set of {@link FileStoreSourceSplit}.
+ */
+public class FileStoreSourceSplitGenerator {
+
+    /**
+     * The current Id as a mutable string representation. This covers more 
values than the integer
+     * value range, so we should never overflow.
+     */
+    private final char[] currentId = "0000000000".toCharArray();
+
+    public List<FileStoreSourceSplit> createSplits(FileStoreScan scan) {
+        return createSplits(scan.plan());
+    }
+
+    public List<FileStoreSourceSplit> createSplits(FileStoreScan.Plan plan) {
+        return plan.groupByPartFiles().entrySet().stream()
+                .flatMap(
+                        pe ->
+                                pe.getValue().entrySet().stream()
+                                        .map(
+                                                be ->
+                                                        new 
FileStoreSourceSplit(
+                                                                getNextId(),
+                                                                pe.getKey(),
+                                                                be.getKey(),
+                                                                
be.getValue())))
+                .collect(Collectors.toList());
+    }
+
+    protected final String getNextId() {
+        // because we just increment numbers, we increment the char 
representation directly,
+        // rather than incrementing an integer and converting it to a string 
representation
+        // every time again (requires quite some expensive conversion logic).
+        incrementCharArrayByOne(currentId, currentId.length - 1);
+        return new String(currentId);
+    }
+
+    private static void incrementCharArrayByOne(char[] array, int pos) {
+        char c = array[pos];
+        c++;
+
+        if (c > '9') {
+            c = '0';
+            incrementCharArrayByOne(array, pos - 1);
+        }
+        array[pos] = c;
+    }

Review comment:
       Just throw exception is OK... There are to many splits...




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