This is an automated email from the ASF dual-hosted git repository.

LuciferYang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gluten.git


The following commit(s) were added to refs/heads/main by this push:
     new af0d97ccd6 [GLUTEN-13719][VL] Fix None.get in a storage-partitioned 
join whose runtime filter removes every partition (#13725)
af0d97ccd6 is described below

commit af0d97ccd6c0fd08a2a368ba861b5c20cd7bc299
Author: YangJie <[email protected]>
AuthorDate: Fri Nov 27 02:35:48 2026 -0500

    [GLUTEN-13719][VL] Fix None.get in a storage-partitioned join whose runtime 
filter removes every partition (#13725)
    
    ## What changes are proposed in this pull request?
    
    On Spark 3.4 to 4.1, `BatchScanExecShim` kept its own copy of 
`filteredPartitions` next to the one in `AbstractBatchScanExec`, Gluten's copy 
of Spark's `BatchScanExec`. The 3.4/3.5 copies missed SPARK-45652: they call 
`groupPartitions(newPartitions).get`, so a storage-partitioned join fails with 
`None.get` when a runtime filter removes every partition (see the issue).
    
    The shim now uses the `AbstractBatchScanExec` member, made `protected`, and 
its copy is removed. The two copies only differed in that line (and a blank 
line on 4.0/4.1). The Spark 4.2 shim is unchanged: it groups splits 
differently, tracked in #13139.
    
    Fixes #13719.
    
    ## How was this patch tested?
    
    Added a test to `IcebergSuite`: a bucketed join whose dynamic filter 
removes every partition of the key-grouped side, with `pushPartValues` and 
partially clustered distribution on and off. It checks the result and that the 
filtered scan is offloaded and key grouped, and fails with `None.get` without 
the fix.
    
    ## Was this patch authored or co-authored using generative AI tooling?
    
    Yes. Generated-by: Claude Opus.
    
    
    Related issue: #13719
---
 .../org/apache/gluten/execution/IcebergSuite.scala | 43 +++++++++++++
 .../datasources/v2/AbstractBatchScanExec.scala     |  2 +-
 .../datasources/v2/BatchScanExecShim.scala         | 68 +--------------------
 .../datasources/v2/AbstractBatchScanExec.scala     |  2 +-
 .../datasources/v2/BatchScanExecShim.scala         | 68 +--------------------
 .../datasources/v2/AbstractBatchScanExec.scala     |  2 +-
 .../datasources/v2/BatchScanExecShim.scala         | 71 +---------------------
 .../datasources/v2/AbstractBatchScanExec.scala     |  2 +-
 .../datasources/v2/BatchScanExecShim.scala         | 71 +---------------------
 9 files changed, 51 insertions(+), 278 deletions(-)

diff --git 
a/gluten-iceberg/src/test/scala/org/apache/gluten/execution/IcebergSuite.scala 
b/gluten-iceberg/src/test/scala/org/apache/gluten/execution/IcebergSuite.scala
index 082816b9ce..9d207aee06 100644
--- 
a/gluten-iceberg/src/test/scala/org/apache/gluten/execution/IcebergSuite.scala
+++ 
b/gluten-iceberg/src/test/scala/org/apache/gluten/execution/IcebergSuite.scala
@@ -20,6 +20,7 @@ import org.apache.gluten.config.{GlutenConfig, 
GlutenIcebergConfig}
 
 import org.apache.spark.SparkConf
 import org.apache.spark.sql.Row
+import org.apache.spark.sql.catalyst.expressions.{DynamicPruningExpression, 
Literal}
 import org.apache.spark.sql.execution.QueryExecution
 import org.apache.spark.sql.execution.datasources.v2.BatchScanExec
 import org.apache.spark.sql.util.QueryExecutionListener
@@ -289,6 +290,48 @@ abstract class IcebergSuite extends 
WholeStageTransformerSuite {
     }
   }
 
+  test("iceberg bucketed join with a runtime filter that removes every 
partition") {
+    withTable("spj_items", "spj_purchases") {
+      spark.sql("create table spj_items(id int, price double) using iceberg 
partitioned by (id)")
+      spark.sql("insert into spj_items values (1, 40.0), (1, 41.0), (2, 10.0), 
(3, 15.5)")
+      spark.sql(
+        "create table spj_purchases(item_id int, price double) using iceberg " 
+
+          "partitioned by (item_id)")
+      spark.sql("insert into spj_purchases values (1, 42.0), (1, 44.0), (2, 
11.0), (3, 19.5)")
+      for {
+        pushDownValues <- Seq("true", "false")
+        partiallyClustered <- Seq("true", "false")
+      } {
+        withSQLConf(
+          "spark.sql.sources.v2.bucketing.enabled" -> "true",
+          "spark.sql.requireAllClusterKeysForCoPartition" -> "false",
+          "spark.sql.adaptive.enabled" -> "false",
+          "spark.sql.iceberg.planning.preserve-data-grouping" -> "true",
+          "spark.sql.autoBroadcastJoinThreshold" -> "-1",
+          "spark.sql.optimizer.dynamicPartitionPruning.enabled" -> "true",
+          "spark.sql.optimizer.dynamicPartitionPruning.reuseBroadcastOnly" -> 
"false",
+          "spark.sql.optimizer.dynamicPartitionPruning.fallbackFilterRatio" -> 
"10",
+          "spark.sql.sources.v2.bucketing.pushPartValues.enabled" -> 
pushDownValues,
+          
"spark.sql.sources.v2.bucketing.partiallyClusteredDistribution.enabled" ->
+            partiallyClustered
+        ) {
+          // No item is priced over 50, so dynamic filtering removes every 
purchases partition.
+          val df = spark.sql(
+            "select p.price from spj_items i, spj_purchases p " +
+              "where i.id = p.item_id and i.price > 50.0")
+          assert(df.collect().isEmpty)
+          // The purchases scan is offloaded, key grouped and dynamically 
filtered.
+          assert(getExecutedPlan(df).exists {
+            case s: IcebergScanTransformer =>
+              s.getKeyGroupPartitioning.isDefined &&
+              s.runtimeFilters.exists(_ != 
DynamicPruningExpression(Literal.TrueLiteral))
+            case _ => false
+          })
+        }
+      }
+    }
+  }
+
   test("iceberg bucketed join with partition") {
     val leftTable = "p_str_tb"
     val rightTable = "p_int_tb"
diff --git 
a/shims/spark34/src/main/scala/org/apache/spark/sql/execution/datasources/v2/AbstractBatchScanExec.scala
 
b/shims/spark34/src/main/scala/org/apache/spark/sql/execution/datasources/v2/AbstractBatchScanExec.scala
index f084e1101b..1167c2a6be 100644
--- 
a/shims/spark34/src/main/scala/org/apache/spark/sql/execution/datasources/v2/AbstractBatchScanExec.scala
+++ 
b/shims/spark34/src/main/scala/org/apache/spark/sql/execution/datasources/v2/AbstractBatchScanExec.scala
@@ -62,7 +62,7 @@ abstract class AbstractBatchScanExec(
   @transient protected lazy val inputPartitionsShim: Seq[InputPartition] =
     batch.planInputPartitions()
 
-  @transient private lazy val filteredPartitions: Seq[Seq[InputPartition]] = {
+  @transient protected lazy val filteredPartitions: Seq[Seq[InputPartition]] = 
{
     val dataSourceFilters = runtimeFilters.flatMap {
       case DynamicPruningExpression(e) => 
DataSourceV2Strategy.translateRuntimeFilterV2(e)
       case _ => None
diff --git 
a/shims/spark34/src/main/scala/org/apache/spark/sql/execution/datasources/v2/BatchScanExecShim.scala
 
b/shims/spark34/src/main/scala/org/apache/spark/sql/execution/datasources/v2/BatchScanExecShim.scala
index 986401f8b6..a0fb75f058 100644
--- 
a/shims/spark34/src/main/scala/org/apache/spark/sql/execution/datasources/v2/BatchScanExecShim.scala
+++ 
b/shims/spark34/src/main/scala/org/apache/spark/sql/execution/datasources/v2/BatchScanExecShim.scala
@@ -16,15 +16,12 @@
  */
 package org.apache.spark.sql.execution.datasources.v2
 
-import org.apache.spark.SparkException
 import org.apache.spark.rdd.RDD
 import org.apache.spark.sql.catalyst.InternalRow
 import org.apache.spark.sql.catalyst.expressions._
-import org.apache.spark.sql.catalyst.plans.physical.KeyGroupedPartitioning
-import org.apache.spark.sql.catalyst.util.InternalRowComparableWrapper
 import org.apache.spark.sql.connector.catalog.Table
 import org.apache.spark.sql.connector.expressions.aggregate.Aggregation
-import org.apache.spark.sql.connector.read.{HasPartitionKey, InputPartition, 
Scan, SupportsRuntimeV2Filtering}
+import org.apache.spark.sql.connector.read.Scan
 import org.apache.spark.sql.execution.datasources.v2.orc.OrcScan
 import org.apache.spark.sql.execution.datasources.v2.parquet.ParquetScan
 import org.apache.spark.sql.execution.metric.SQLMetric
@@ -77,69 +74,6 @@ abstract class BatchScanExecShim(
     throw new UnsupportedOperationException("Need to implement this method")
   }
 
-  @transient protected lazy val filteredPartitions: Seq[Seq[InputPartition]] = 
{
-    val dataSourceFilters = runtimeFilters.flatMap {
-      case DynamicPruningExpression(e) => 
DataSourceV2Strategy.translateRuntimeFilterV2(e)
-      case _ => None
-    }
-
-    if (dataSourceFilters.nonEmpty) {
-      val originalPartitioning = outputPartitioning
-
-      // the cast is safe as runtime filters are only assigned if the scan can 
be filtered
-      val filterableScan = scan.asInstanceOf[SupportsRuntimeV2Filtering]
-      filterableScan.filter(dataSourceFilters.toArray)
-
-      // call toBatch again to get filtered partitions
-      val newPartitions = scan.toBatch.planInputPartitions()
-
-      originalPartitioning match {
-        case p: KeyGroupedPartitioning =>
-          if (newPartitions.exists(!_.isInstanceOf[HasPartitionKey])) {
-            throw new SparkException(
-              "Data source must have preserved the original partitioning " +
-                "during runtime filtering: not all partitions implement 
HasPartitionKey after " +
-                "filtering")
-          }
-          val newPartitionValues = newPartitions
-            .map(
-              partition =>
-                InternalRowComparableWrapper(
-                  partition.asInstanceOf[HasPartitionKey],
-                  p.expressions))
-            .toSet
-          val oldPartitionValues = p.partitionValues
-            .map(partition => InternalRowComparableWrapper(partition, 
p.expressions))
-            .toSet
-          // We require the new number of partition values to be equal or less 
than the old number
-          // of partition values here. In the case of less than, empty 
partitions will be added for
-          // those missing values that are not present in the new input 
partitions.
-          if (oldPartitionValues.size < newPartitionValues.size) {
-            throw new SparkException(
-              "During runtime filtering, data source must either report " +
-                "the same number of partition values, or a subset of partition 
values from the " +
-                s"original. Before: ${oldPartitionValues.size} partition 
values. " +
-                s"After: ${newPartitionValues.size} partition values")
-          }
-
-          if (!newPartitionValues.forall(oldPartitionValues.contains)) {
-            throw new SparkException(
-              "During runtime filtering, data source must not report new " +
-                "partition values that are not present in the original 
partitioning.")
-          }
-
-          groupPartitions(newPartitions).get.map(_._2)
-
-        case _ =>
-          // no validation is needed as the data source did not report any 
specific partitioning
-          newPartitions.map(Seq(_))
-      }
-
-    } else {
-      partitions
-    }
-  }
-
   @transient lazy val pushedAggregate: Option[Aggregation] = {
     scan match {
       case s: ParquetScan => s.pushedAggregate
diff --git 
a/shims/spark35/src/main/scala/org/apache/spark/sql/execution/datasources/v2/AbstractBatchScanExec.scala
 
b/shims/spark35/src/main/scala/org/apache/spark/sql/execution/datasources/v2/AbstractBatchScanExec.scala
index 62a5880474..49ccaa5d72 100644
--- 
a/shims/spark35/src/main/scala/org/apache/spark/sql/execution/datasources/v2/AbstractBatchScanExec.scala
+++ 
b/shims/spark35/src/main/scala/org/apache/spark/sql/execution/datasources/v2/AbstractBatchScanExec.scala
@@ -57,7 +57,7 @@ abstract class AbstractBatchScanExec(
   @transient protected lazy val inputPartitionsShim: Seq[InputPartition] =
     batch.planInputPartitions()
 
-  @transient private lazy val filteredPartitions: Seq[Seq[InputPartition]] = {
+  @transient protected lazy val filteredPartitions: Seq[Seq[InputPartition]] = 
{
     val dataSourceFilters = runtimeFilters.flatMap {
       case DynamicPruningExpression(e) => 
DataSourceV2Strategy.translateRuntimeFilterV2(e)
       case _ => None
diff --git 
a/shims/spark35/src/main/scala/org/apache/spark/sql/execution/datasources/v2/BatchScanExecShim.scala
 
b/shims/spark35/src/main/scala/org/apache/spark/sql/execution/datasources/v2/BatchScanExecShim.scala
index 7196af63ed..4c790e92c2 100644
--- 
a/shims/spark35/src/main/scala/org/apache/spark/sql/execution/datasources/v2/BatchScanExecShim.scala
+++ 
b/shims/spark35/src/main/scala/org/apache/spark/sql/execution/datasources/v2/BatchScanExecShim.scala
@@ -16,15 +16,12 @@
  */
 package org.apache.spark.sql.execution.datasources.v2
 
-import org.apache.spark.SparkException
 import org.apache.spark.rdd.RDD
 import org.apache.spark.sql.catalyst.InternalRow
 import org.apache.spark.sql.catalyst.expressions._
-import org.apache.spark.sql.catalyst.plans.physical.KeyGroupedPartitioning
-import org.apache.spark.sql.catalyst.util.InternalRowComparableWrapper
 import org.apache.spark.sql.connector.catalog.Table
 import org.apache.spark.sql.connector.expressions.aggregate.Aggregation
-import org.apache.spark.sql.connector.read.{HasPartitionKey, InputPartition, 
Scan, SupportsRuntimeV2Filtering}
+import org.apache.spark.sql.connector.read.Scan
 import org.apache.spark.sql.execution.datasources.v2.orc.OrcScan
 import org.apache.spark.sql.execution.datasources.v2.parquet.ParquetScan
 import org.apache.spark.sql.execution.metric.SQLMetric
@@ -79,69 +76,6 @@ abstract class BatchScanExecShim(
     throw new UnsupportedOperationException("Need to implement this method")
   }
 
-  @transient protected lazy val filteredPartitions: Seq[Seq[InputPartition]] = 
{
-    val dataSourceFilters = runtimeFilters.flatMap {
-      case DynamicPruningExpression(e) => 
DataSourceV2Strategy.translateRuntimeFilterV2(e)
-      case _ => None
-    }
-
-    if (dataSourceFilters.nonEmpty) {
-      val originalPartitioning = outputPartitioning
-
-      // the cast is safe as runtime filters are only assigned if the scan can 
be filtered
-      val filterableScan = scan.asInstanceOf[SupportsRuntimeV2Filtering]
-      filterableScan.filter(dataSourceFilters.toArray)
-
-      // call toBatch again to get filtered partitions
-      val newPartitions = scan.toBatch.planInputPartitions()
-
-      originalPartitioning match {
-        case p: KeyGroupedPartitioning =>
-          if (newPartitions.exists(!_.isInstanceOf[HasPartitionKey])) {
-            throw new SparkException(
-              "Data source must have preserved the original partitioning " +
-                "during runtime filtering: not all partitions implement 
HasPartitionKey after " +
-                "filtering")
-          }
-          val newPartitionValues = newPartitions
-            .map(
-              partition =>
-                InternalRowComparableWrapper(
-                  partition.asInstanceOf[HasPartitionKey],
-                  p.expressions))
-            .toSet
-          val oldPartitionValues = p.partitionValues
-            .map(partition => InternalRowComparableWrapper(partition, 
p.expressions))
-            .toSet
-          // We require the new number of partition values to be equal or less 
than the old number
-          // of partition values here. In the case of less than, empty 
partitions will be added for
-          // those missing values that are not present in the new input 
partitions.
-          if (oldPartitionValues.size < newPartitionValues.size) {
-            throw new SparkException(
-              "During runtime filtering, data source must either report " +
-                "the same number of partition values, or a subset of partition 
values from the " +
-                s"original. Before: ${oldPartitionValues.size} partition 
values. " +
-                s"After: ${newPartitionValues.size} partition values")
-          }
-
-          if (!newPartitionValues.forall(oldPartitionValues.contains)) {
-            throw new SparkException(
-              "During runtime filtering, data source must not report new " +
-                "partition values that are not present in the original 
partitioning.")
-          }
-
-          groupPartitions(newPartitions).get.map(_._2)
-
-        case _ =>
-          // no validation is needed as the data source did not report any 
specific partitioning
-          newPartitions.map(Seq(_))
-      }
-
-    } else {
-      partitions
-    }
-  }
-
   @transient lazy val pushedAggregate: Option[Aggregation] = {
     scan match {
       case s: ParquetScan => s.pushedAggregate
diff --git 
a/shims/spark40/src/main/scala/org/apache/spark/sql/execution/datasources/v2/AbstractBatchScanExec.scala
 
b/shims/spark40/src/main/scala/org/apache/spark/sql/execution/datasources/v2/AbstractBatchScanExec.scala
index 0e03fa0ffe..b910e42943 100644
--- 
a/shims/spark40/src/main/scala/org/apache/spark/sql/execution/datasources/v2/AbstractBatchScanExec.scala
+++ 
b/shims/spark40/src/main/scala/org/apache/spark/sql/execution/datasources/v2/AbstractBatchScanExec.scala
@@ -60,7 +60,7 @@ abstract class AbstractBatchScanExec(
   @transient protected lazy val inputPartitionsShim: Seq[InputPartition] =
     batch.planInputPartitions()
 
-  @transient private lazy val filteredPartitions: Seq[Seq[InputPartition]] = {
+  @transient protected lazy val filteredPartitions: Seq[Seq[InputPartition]] = 
{
     val dataSourceFilters = runtimeFilters.flatMap {
       case DynamicPruningExpression(e) => 
DataSourceV2Strategy.translateRuntimeFilterV2(e)
       case _ => None
diff --git 
a/shims/spark40/src/main/scala/org/apache/spark/sql/execution/datasources/v2/BatchScanExecShim.scala
 
b/shims/spark40/src/main/scala/org/apache/spark/sql/execution/datasources/v2/BatchScanExecShim.scala
index 8a40a8130a..d5609c13dd 100644
--- 
a/shims/spark40/src/main/scala/org/apache/spark/sql/execution/datasources/v2/BatchScanExecShim.scala
+++ 
b/shims/spark40/src/main/scala/org/apache/spark/sql/execution/datasources/v2/BatchScanExecShim.scala
@@ -16,21 +16,17 @@
  */
 package org.apache.spark.sql.execution.datasources.v2
 
-import org.apache.spark.SparkException
 import org.apache.spark.rdd.RDD
 import org.apache.spark.sql.catalyst.InternalRow
 import org.apache.spark.sql.catalyst.expressions._
-import org.apache.spark.sql.catalyst.plans.physical.KeyGroupedPartitioning
-import org.apache.spark.sql.catalyst.util.InternalRowComparableWrapper
 import org.apache.spark.sql.connector.catalog.Table
 import org.apache.spark.sql.connector.catalog.functions.Reducer
 import org.apache.spark.sql.connector.expressions.aggregate.Aggregation
-import org.apache.spark.sql.connector.read.{HasPartitionKey, InputPartition, 
Scan, SupportsRuntimeV2Filtering}
+import org.apache.spark.sql.connector.read.Scan
 import org.apache.spark.sql.execution.datasources.v2.orc.OrcScan
 import org.apache.spark.sql.execution.datasources.v2.parquet.ParquetScan
 import org.apache.spark.sql.execution.metric.SQLMetric
 import org.apache.spark.sql.vectorized.ColumnarBatch
-import org.apache.spark.util.ArrayImplicits._
 
 abstract class BatchScanExecShim(
     output: Seq[AttributeReference],
@@ -85,71 +81,6 @@ abstract class BatchScanExecShim(
     throw new UnsupportedOperationException("Need to implement this method")
   }
 
-  @transient protected lazy val filteredPartitions: Seq[Seq[InputPartition]] = 
{
-    val dataSourceFilters = runtimeFilters.flatMap {
-      case DynamicPruningExpression(e) => 
DataSourceV2Strategy.translateRuntimeFilterV2(e)
-      case _ => None
-    }
-
-    if (dataSourceFilters.nonEmpty) {
-      val originalPartitioning = outputPartitioning
-
-      // the cast is safe as runtime filters are only assigned if the scan can 
be filtered
-      val filterableScan = scan.asInstanceOf[SupportsRuntimeV2Filtering]
-      filterableScan.filter(dataSourceFilters.toArray)
-
-      // call toBatch again to get filtered partitions
-      val newPartitions = scan.toBatch.planInputPartitions()
-
-      originalPartitioning match {
-        case p: KeyGroupedPartitioning =>
-          if (newPartitions.exists(!_.isInstanceOf[HasPartitionKey])) {
-            throw new SparkException(
-              "Data source must have preserved the original partitioning " +
-                "during runtime filtering: not all partitions implement 
HasPartitionKey after " +
-                "filtering")
-          }
-          val newPartitionValues = newPartitions
-            .map(
-              partition =>
-                InternalRowComparableWrapper(
-                  partition.asInstanceOf[HasPartitionKey],
-                  p.expressions))
-            .toSet
-          val oldPartitionValues = p.partitionValues
-            .map(partition => InternalRowComparableWrapper(partition, 
p.expressions))
-            .toSet
-          // We require the new number of partition values to be equal or less 
than the old number
-          // of partition values here. In the case of less than, empty 
partitions will be added for
-          // those missing values that are not present in the new input 
partitions.
-          if (oldPartitionValues.size < newPartitionValues.size) {
-            throw new SparkException(
-              "During runtime filtering, data source must either report " +
-                "the same number of partition values, or a subset of partition 
values from the " +
-                s"original. Before: ${oldPartitionValues.size} partition 
values. " +
-                s"After: ${newPartitionValues.size} partition values")
-          }
-
-          if (!newPartitionValues.forall(oldPartitionValues.contains)) {
-            throw new SparkException(
-              "During runtime filtering, data source must not report new " +
-                "partition values that are not present in the original 
partitioning.")
-          }
-
-          groupPartitions(newPartitions.toImmutableArraySeq)
-            .map(_.groupedParts.map(_.parts))
-            .getOrElse(Seq.empty)
-
-        case _ =>
-          // no validation is needed as the data source did not report any 
specific partitioning
-          newPartitions.map(Seq(_))
-      }
-
-    } else {
-      partitions
-    }
-  }
-
   @transient lazy val pushedAggregate: Option[Aggregation] = {
     scan match {
       case s: ParquetScan => s.pushedAggregate
diff --git 
a/shims/spark41/src/main/scala/org/apache/spark/sql/execution/datasources/v2/AbstractBatchScanExec.scala
 
b/shims/spark41/src/main/scala/org/apache/spark/sql/execution/datasources/v2/AbstractBatchScanExec.scala
index a6a46b10f4..66844c3b07 100644
--- 
a/shims/spark41/src/main/scala/org/apache/spark/sql/execution/datasources/v2/AbstractBatchScanExec.scala
+++ 
b/shims/spark41/src/main/scala/org/apache/spark/sql/execution/datasources/v2/AbstractBatchScanExec.scala
@@ -61,7 +61,7 @@ abstract class AbstractBatchScanExec(
   @transient protected lazy val inputPartitionsShim: Seq[InputPartition] =
     batch.planInputPartitions()
 
-  @transient private lazy val filteredPartitions: Seq[Seq[InputPartition]] = {
+  @transient protected lazy val filteredPartitions: Seq[Seq[InputPartition]] = 
{
     val dataSourceFilters = runtimeFilters.flatMap {
       case DynamicPruningExpression(e) => 
DataSourceV2Strategy.translateRuntimeFilterV2(e)
       case _ => None
diff --git 
a/shims/spark41/src/main/scala/org/apache/spark/sql/execution/datasources/v2/BatchScanExecShim.scala
 
b/shims/spark41/src/main/scala/org/apache/spark/sql/execution/datasources/v2/BatchScanExecShim.scala
index d7ab949f47..3fbc7c023c 100644
--- 
a/shims/spark41/src/main/scala/org/apache/spark/sql/execution/datasources/v2/BatchScanExecShim.scala
+++ 
b/shims/spark41/src/main/scala/org/apache/spark/sql/execution/datasources/v2/BatchScanExecShim.scala
@@ -16,22 +16,18 @@
  */
 package org.apache.spark.sql.execution.datasources.v2
 
-import org.apache.spark.SparkException
 import org.apache.spark.rdd.RDD
 import org.apache.spark.sql.catalyst.InternalRow
 import org.apache.spark.sql.catalyst.expressions._
-import org.apache.spark.sql.catalyst.plans.physical.KeyGroupedPartitioning
-import org.apache.spark.sql.catalyst.util.InternalRowComparableWrapper
 import org.apache.spark.sql.connector.catalog.Table
 import org.apache.spark.sql.connector.catalog.functions.Reducer
 import org.apache.spark.sql.connector.expressions.aggregate.Aggregation
-import org.apache.spark.sql.connector.read.{HasPartitionKey, InputPartition, 
Scan, SupportsRuntimeV2Filtering}
+import org.apache.spark.sql.connector.read.Scan
 import org.apache.spark.sql.execution.datasources.v2.orc.OrcScan
 import org.apache.spark.sql.execution.datasources.v2.parquet.ParquetScan
 import org.apache.spark.sql.execution.joins.StoragePartitionJoinParams
 import org.apache.spark.sql.execution.metric.SQLMetric
 import org.apache.spark.sql.vectorized.ColumnarBatch
-import org.apache.spark.util.ArrayImplicits._
 
 abstract class BatchScanExecShim(
     output: Seq[AttributeReference],
@@ -86,71 +82,6 @@ abstract class BatchScanExecShim(
     throw new UnsupportedOperationException("Need to implement this method")
   }
 
-  @transient protected lazy val filteredPartitions: Seq[Seq[InputPartition]] = 
{
-    val dataSourceFilters = runtimeFilters.flatMap {
-      case DynamicPruningExpression(e) => 
DataSourceV2Strategy.translateRuntimeFilterV2(e)
-      case _ => None
-    }
-
-    if (dataSourceFilters.nonEmpty) {
-      val originalPartitioning = outputPartitioning
-
-      // the cast is safe as runtime filters are only assigned if the scan can 
be filtered
-      val filterableScan = scan.asInstanceOf[SupportsRuntimeV2Filtering]
-      filterableScan.filter(dataSourceFilters.toArray)
-
-      // call toBatch again to get filtered partitions
-      val newPartitions = scan.toBatch.planInputPartitions()
-
-      originalPartitioning match {
-        case p: KeyGroupedPartitioning =>
-          if (newPartitions.exists(!_.isInstanceOf[HasPartitionKey])) {
-            throw new SparkException(
-              "Data source must have preserved the original partitioning " +
-                "during runtime filtering: not all partitions implement 
HasPartitionKey after " +
-                "filtering")
-          }
-          val newPartitionValues = newPartitions
-            .map(
-              partition =>
-                InternalRowComparableWrapper(
-                  partition.asInstanceOf[HasPartitionKey],
-                  p.expressions))
-            .toSet
-          val oldPartitionValues = p.partitionValues
-            .map(partition => InternalRowComparableWrapper(partition, 
p.expressions))
-            .toSet
-          // We require the new number of partition values to be equal or less 
than the old number
-          // of partition values here. In the case of less than, empty 
partitions will be added for
-          // those missing values that are not present in the new input 
partitions.
-          if (oldPartitionValues.size < newPartitionValues.size) {
-            throw new SparkException(
-              "During runtime filtering, data source must either report " +
-                "the same number of partition values, or a subset of partition 
values from the " +
-                s"original. Before: ${oldPartitionValues.size} partition 
values. " +
-                s"After: ${newPartitionValues.size} partition values")
-          }
-
-          if (!newPartitionValues.forall(oldPartitionValues.contains)) {
-            throw new SparkException(
-              "During runtime filtering, data source must not report new " +
-                "partition values that are not present in the original 
partitioning.")
-          }
-
-          groupPartitions(newPartitions.toImmutableArraySeq)
-            .map(_.groupedParts.map(_.parts))
-            .getOrElse(Seq.empty)
-
-        case _ =>
-          // no validation is needed as the data source did not report any 
specific partitioning
-          newPartitions.map(Seq(_))
-      }
-
-    } else {
-      partitions
-    }
-  }
-
   @transient lazy val pushedAggregate: Option[Aggregation] = {
     scan match {
       case s: ParquetScan => s.pushedAggregate


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

Reply via email to