saths008 commented on code in PR #19122:
URL: https://github.com/apache/iceberg/pull/19122#discussion_r4811446054


##########
spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/source/SparkChangelogScan.java:
##########
@@ -18,119 +18,55 @@
  */
 package org.apache.iceberg.spark.source;
 
-import java.io.IOException;
-import java.io.UncheckedIOException;
 import java.util.Collections;
 import java.util.List;
 import java.util.Locale;
 import java.util.Objects;
-import org.apache.iceberg.ChangelogScanTask;
 import org.apache.iceberg.IncrementalChangelogScan;
-import org.apache.iceberg.ScanTaskGroup;
+import org.apache.iceberg.PartitionScanTask;
 import org.apache.iceberg.Schema;
 import org.apache.iceberg.Table;
 import org.apache.iceberg.expressions.Expression;
-import org.apache.iceberg.io.CloseableIterable;
-import org.apache.iceberg.relocated.com.google.common.collect.Lists;
-import org.apache.iceberg.spark.Spark3Util;
 import org.apache.iceberg.spark.SparkReadConf;
-import org.apache.iceberg.spark.SparkSchemaUtil;
-import org.apache.iceberg.types.Types;
-import org.apache.spark.api.java.JavaSparkContext;
 import org.apache.spark.sql.SparkSession;
-import org.apache.spark.sql.connector.read.Batch;
-import org.apache.spark.sql.connector.read.Scan;
-import org.apache.spark.sql.connector.read.Statistics;
-import org.apache.spark.sql.connector.read.SupportsReportStatistics;
-import org.apache.spark.sql.types.StructType;
 
-class SparkChangelogScan implements Scan, SupportsReportStatistics {
-
-  private static final Types.StructType EMPTY_GROUPING_KEY_TYPE = 
Types.StructType.of();
-
-  private final JavaSparkContext sparkContext;
-  private final Table table;
-  private final IncrementalChangelogScan scan;
-  private final SparkReadConf readConf;
-  private final Schema projection;
-  private final List<Expression> filters;
+class SparkChangelogScan extends SparkPartitioningAwareScan<PartitionScanTask> 
{
   private final Long startSnapshotId;
   private final Long endSnapshotId;
 
-  // lazy variables
-  private List<ScanTaskGroup<ChangelogScanTask>> taskGroups = null;
-  private StructType expectedSparkType = null;
-
   SparkChangelogScan(
       SparkSession spark,
       Table table,
       IncrementalChangelogScan scan,
       SparkReadConf readConf,
       Schema projection,
       List<Expression> filters) {
-
-    SparkSchemaUtil.validateMetadataColumnReferences(table.schema(), 
projection);
-
-    this.sparkContext = 
JavaSparkContext.fromSparkContext(spark.sparkContext());
-    this.table = table;
-    this.scan = scan;
-    this.readConf = readConf;
-    this.projection = projection;
-    this.filters = filters != null ? filters : Collections.emptyList();
-    this.startSnapshotId = readConf.startSnapshotId();
-    this.endSnapshotId = readConf.endSnapshotId();
-    if (scan == null) {
-      this.taskGroups = Collections.emptyList();
-    }
-  }
-
-  @Override
-  public Statistics estimateStatistics() {
-    long rowsCount = 
taskGroups().stream().mapToLong(ScanTaskGroup::estimatedRowsCount).sum();
-    long sizeInBytes = SparkSchemaUtil.estimateSize(readSchema(), rowsCount);
-    return new Stats(sizeInBytes, rowsCount, Collections.emptyMap());
-  }
-
-  @Override
-  public StructType readSchema() {
-    if (expectedSparkType == null) {
-      this.expectedSparkType = SparkSchemaUtil.convert(projection);
-    }
-
-    return expectedSparkType;
-  }
-
-  @Override
-  public Batch toBatch() {
-    return new SparkBatch(
-        sparkContext,
+    super(
+        spark,
         table,
-        null != scan ? scan.fileIO() : table::io,
+        table.schema(),
+        scan,
         readConf,
-        EMPTY_GROUPING_KEY_TYPE,
-        taskGroups(),
         projection,
-        hashCode());
+        filters,
+        Collections.emptyList(),
+        null);
+    this.startSnapshotId = readConf.startSnapshotId();
+    this.endSnapshotId = readConf.endSnapshotId();
+    tasks();

Review Comment:
   >  make Spark reuse an exchange across them (for example in UNION ALL or a 
full outer join), silently dropping rows
   
   I believe this is already a problem on `main` today and is fixed here: 
https://github.com/apache/iceberg/pull/19209



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

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