You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2020/07/29 07:36:46 UTC

[GitHub] [iceberg] kbendick commented on a change in pull request #1263: Add MicroBatch support in Iceberg Core

kbendick commented on a change in pull request #1263:
URL: https://github.com/apache/iceberg/pull/1263#discussion_r461726054



##########
File path: core/src/main/java/org/apache/iceberg/MicroBatches.java
##########
@@ -0,0 +1,255 @@
+/*
+ * 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.iceberg;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.iceberg.io.CloseableIterable;
+import org.apache.iceberg.io.CloseableIterator;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.apache.iceberg.util.Pair;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MicroBatches {
+  private MicroBatches() {
+  }
+
+  public static class MicroBatch {
+    private final long snapshotId;
+    private final int startFileIndex;
+    private final int endFileIndex;
+    private final long sizeInBytes;
+    private final List<FileScanTask> tasks;
+    private final boolean lastIndexOfSnapshot;
+
+    private MicroBatch(long snapshotId, int startFileIndex, int endFileIndex, long sizeInBytes,
+               List<FileScanTask> tasks, boolean lastIndexOfSnapshot) {
+      this.snapshotId = snapshotId;
+      this.startFileIndex = startFileIndex;
+      this.endFileIndex = endFileIndex;
+      this.sizeInBytes = sizeInBytes;
+      this.tasks = tasks;
+      this.lastIndexOfSnapshot = lastIndexOfSnapshot;
+    }
+
+    public long snapshotId() {
+      return snapshotId;
+    }
+
+    public int startFileIndex() {
+      return startFileIndex;
+    }
+
+    public int endFileIndex() {
+      return endFileIndex;
+    }
+
+    public long sizeInBytes() {
+      return sizeInBytes;
+    }
+
+    public List<FileScanTask> tasks() {
+      return tasks;
+    }
+
+    public boolean lastIndexOfSnapshot() {
+      return lastIndexOfSnapshot;
+    }
+  }
+
+  public static MicroBatchBuilder from(Snapshot snapshot, FileIO io) {
+    return new MicroBatchBuilder(snapshot, io);
+  }
+
+  public static class MicroBatchBuilder {
+    private static final Logger LOG = LoggerFactory.getLogger(MicroBatchBuilder.class);
+
+    private final Snapshot snapshot;
+    private final FileIO io;
+    private boolean caseSensitive;
+    private Map<Integer, PartitionSpec> specsById;
+
+    private MicroBatchBuilder(Snapshot snapshot, FileIO io) {
+      this.snapshot = snapshot;
+      this.io = io;
+      this.caseSensitive = true;
+    }
+
+    public MicroBatchBuilder caseSensitive(boolean sensitive) {
+      this.caseSensitive = sensitive;
+      return this;
+    }
+
+    public MicroBatchBuilder specsById(Map<Integer, PartitionSpec> specs) {
+      this.specsById = specs;
+      return this;
+    }
+
+    public MicroBatch generate(int startFileIndex, long targetSizeInBytes, boolean isStarting) {
+      Preconditions.checkArgument(startFileIndex >= 0, "startFileIndex is unexpectedly smaller than 0");

Review comment:
       Nit: The language on condition failure should match the next precondition check. `startFileIndex should be greater than or equal to zero` or something would make much more sense to me. 




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

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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org