rdsr commented on a change in pull request #315: [WIP] Incremental processing 
prototype
URL: https://github.com/apache/incubator-iceberg/pull/315#discussion_r363455256
 
 

 ##########
 File path: core/src/main/java/org/apache/iceberg/IncrementalDataScan.java
 ##########
 @@ -0,0 +1,118 @@
+/*
+ * 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 com.google.common.base.Preconditions;
+import com.google.common.base.Predicate;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import java.util.Collection;
+import java.util.List;
+import org.apache.iceberg.expressions.Expression;
+import org.apache.iceberg.io.CloseableIterable;
+import org.apache.iceberg.util.SnapshotUtil;
+
+class IncrementalDataScan extends DataTableScan implements TableScan {
+  private final TableOperations ops;
+  private final Table table;
+  private boolean colStats;
+  private long fromSnapshotId;
+  private long toSnapshotId;
+
+  IncrementalDataScan(TableOperations ops, Table table, long fromSnapshotId, 
long toSnapshotId) {
+    super(ops, table);
+    this.ops = ops;
+    this.table = table;
+    this.fromSnapshotId = fromSnapshotId;
+    this.toSnapshotId = toSnapshotId;
+  }
+
+  private IncrementalDataScan(TableOperations ops, Table table, Long 
snapshotId, Schema schema,
+                              Expression rowFilter, boolean caseSensitive, 
boolean colStats,
+                              Collection<String> selectedColumns, 
ImmutableMap<String, String> options,
+                              Long fromSnapshotId, Long toSnapshotId) {
+    super(ops, table, snapshotId, schema, rowFilter, caseSensitive, colStats, 
selectedColumns, options);
+    this.ops = ops;
+    this.table = table;
+    this.colStats = colStats;
+    this.fromSnapshotId = fromSnapshotId;
+    this.toSnapshotId = toSnapshotId;
+  }
+
+  @Override
+  public TableScan asOfTime(long timestampMillis) {
+    throw new UnsupportedOperationException("asOfTime() is not supported in 
IncrementalScan");
+  }
+
+  @Override
+  public TableScan useSnapshot(long scanSnapshotId) {
+    throw new UnsupportedOperationException("useSnapshot() is not supported in 
IncrementalScan");
+  }
+
+  @Override
+  public CloseableIterable<FileScanTask> planFiles() {
+    //TODO publish an incremental appends scan event
+    List<Snapshot> snapshots = snapshotsWithin(table, fromSnapshotId, 
toSnapshotId);
+    final Iterable<CloseableIterable<FileScanTask>> files = 
Iterables.transform(snapshots, this::planFiles);
+    return CloseableIterable.concat(files);
+  }
+
+  private CloseableIterable<FileScanTask> planFiles(Snapshot snapshot) {
+    Predicate<ManifestFile> matchingManifests = manifest -> 
manifest.snapshotId() == snapshot.snapshotId();
+
+    Predicate<ManifestEntry> matchingManifestEntries =
+        manifestEntry ->
+            manifestEntry.snapshotId() == snapshot.snapshotId() &&
+            manifestEntry.status() == ManifestEntry.Status.ADDED;
+
+    return planFiles(ops, snapshot, filter(), isCaseSensitive(), colStats, 
matchingManifests, matchingManifestEntries);
 
 Review comment:
   `ManifestGroup.entries()` returns a Iterable<ManifestEntry>. We'd also need 
partition spec id, from `ManifestFile` to construct `BaseFileScanTask` in the 
planFiles method.
   
   I see two ways to solve this. 
   
   1. Pass a `(ManifestFile, ManifestEntry) -> BaseFileScanTask` transformation 
function to ManifestGroup to transform manifest entries.  Since the transform 
function also takes the corresponding ManifestFile from which the manifestEntry 
came from, it can then correctly construct the `ResidualEvaluator` to pass it 
to `BaseFileScanTask`. Downsides are I'd have to make ManifestGroup a 
parameterized class, to take in a generic transformation function like having 
the signature `(ManifestFile, ManifestEntry) -> T`
   
   2. Add another method which instead of returning Iterable<ManifestEntry> 
returns a Iterable<(ManifestFile, ManifestEntry)> . Using this I can then 
transform this result in `DataTableScan#planFiles` to construct 
`BaseFileScanTask`
   
   Do you see a cleaner way @rdblue ?

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to