aokolnychyi commented on a change in pull request #1782:
URL: https://github.com/apache/iceberg/pull/1782#discussion_r526330028



##########
File path: 
spark3/src/main/java/org/apache/iceberg/spark/source/SparkBatchQueryScan.java
##########
@@ -0,0 +1,168 @@
+/*
+ * 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.spark.source;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Objects;
+import org.apache.iceberg.CombinedScanTask;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.TableProperties;
+import org.apache.iceberg.TableScan;
+import org.apache.iceberg.encryption.EncryptionManager;
+import org.apache.iceberg.exceptions.RuntimeIOException;
+import org.apache.iceberg.expressions.Expression;
+import org.apache.iceberg.io.CloseableIterable;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.apache.iceberg.spark.Spark3Util;
+import org.apache.spark.broadcast.Broadcast;
+import org.apache.spark.sql.connector.read.SupportsReportStatistics;
+import org.apache.spark.sql.util.CaseInsensitiveStringMap;
+
+class SparkBatchQueryScan extends SparkBatchScan implements 
SupportsReportStatistics {
+
+  private final Long snapshotId;
+  private final Long startSnapshotId;
+  private final Long endSnapshotId;
+  private final Long asOfTimestamp;
+  private final Long splitSize;
+  private final Integer splitLookback;
+  private final Long splitOpenFileCost;
+
+  private List<CombinedScanTask> tasks = null; // lazy cache of tasks
+
+  SparkBatchQueryScan(Table table, Broadcast<FileIO> io, 
Broadcast<EncryptionManager> encryption,
+                      boolean caseSensitive, Schema expectedSchema, 
List<Expression> filters,
+                      CaseInsensitiveStringMap options) {
+
+    super(table, io, encryption, caseSensitive, expectedSchema, filters, 
options);
+
+    this.snapshotId = Spark3Util.propertyAsLong(options, "snapshot-id", null);
+    this.asOfTimestamp = Spark3Util.propertyAsLong(options, "as-of-timestamp", 
null);
+
+    if (snapshotId != null && asOfTimestamp != null) {
+      throw new IllegalArgumentException(
+          "Cannot scan using both snapshot-id and as-of-timestamp to select 
the table snapshot");
+    }
+
+    this.startSnapshotId = Spark3Util.propertyAsLong(options, 
"start-snapshot-id", null);
+    this.endSnapshotId = Spark3Util.propertyAsLong(options, "end-snapshot-id", 
null);
+    if (snapshotId != null || asOfTimestamp != null) {
+      if (startSnapshotId != null || endSnapshotId != null) {
+        throw new IllegalArgumentException(
+            "Cannot specify start-snapshot-id and end-snapshot-id to do 
incremental scan when either snapshot-id or " +
+                "as-of-timestamp is specified");
+      }
+    } else if (startSnapshotId == null && endSnapshotId != null) {
+      throw new IllegalArgumentException("Cannot only specify option 
end-snapshot-id to do incremental scan");
+    }
+
+    // look for split behavior overrides in options
+    this.splitSize = Spark3Util.propertyAsLong(options, "split-size", null);
+    this.splitLookback = Spark3Util.propertyAsInt(options, "lookback", null);
+    this.splitOpenFileCost = Spark3Util.propertyAsLong(options, 
"file-open-cost", null);
+  }
+
+  @Override
+  protected List<CombinedScanTask> tasks() {
+    if (tasks == null) {
+      TableScan scan = table()
+          .newScan()
+          .caseSensitive(caseSensitive())
+          .project(expectedSchema());
+
+      if (snapshotId != null) {
+        scan = scan.useSnapshot(snapshotId);
+      }
+
+      if (asOfTimestamp != null) {
+        scan = scan.asOfTime(asOfTimestamp);
+      }
+
+      if (startSnapshotId != null) {
+        if (endSnapshotId != null) {
+          scan = scan.appendsBetween(startSnapshotId, endSnapshotId);
+        } else {
+          scan = scan.appendsAfter(startSnapshotId);
+        }
+      }
+
+      if (splitSize != null) {
+        scan = scan.option(TableProperties.SPLIT_SIZE, splitSize.toString());
+      }
+
+      if (splitLookback != null) {
+        scan = scan.option(TableProperties.SPLIT_LOOKBACK, 
splitLookback.toString());
+      }
+
+      if (splitOpenFileCost != null) {
+        scan = scan.option(TableProperties.SPLIT_OPEN_FILE_COST, 
splitOpenFileCost.toString());
+      }
+
+      for (Expression filter : filterExpressions()) {

Review comment:
       I removed the not null check as `filterExpressions()` cannot be null 
now. 




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



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

Reply via email to