rdblue commented on a change in pull request #315: [WIP] Incremental processing prototype URL: https://github.com/apache/incubator-iceberg/pull/315#discussion_r361754798
########## 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: Instead of adding more parameters to `planFiles`, I think it would be cleaner to switch this over to using `ManifestGroup`. We'd need to add an entry filter to `ManifestGroup`, but that class already has most of what we need here and is a bit more flexible than the original implementation of `planFiles` in the scan. ---------------------------------------------------------------- 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]
