Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ class SparkOptimizer(
V2ScanPartitioningAndOrdering,
V2Writes,
PruneFileSourcePartitions,
PushVariantIntoScan)
PushVariantIntoScan,
// Variant pushdown can make a reconstruction projection unnecessary. Prune again so this
// Once batch reaches the same plan on its first application as it would on a second one.
SchemaPruning)

override def preCBORules: Seq[Rule[LogicalPlan]] =
Seq(OptimizeMetadataOnlyDeleteFromTable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.apache.spark.sql.execution.adaptive.AdaptiveSparkPlanHelper
import org.apache.spark.sql.execution.datasources.SchemaPruningSuite
import org.apache.spark.sql.execution.datasources.v2.BatchScanExec
import org.apache.spark.sql.execution.datasources.v2.parquet.ParquetScan
import org.apache.spark.sql.functions.{col, udf}
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.tags.ExtendedSQLTest

Expand All @@ -42,6 +43,23 @@ class ParquetV1SchemaPruningSuite extends ParquetSchemaPruningSuite {
super
.sparkConf
.set(SQLConf.USE_V1_SOURCE_LIST, "parquet")

test("SPARK-57659: SchemaPruning is idempotent with metadata and a filtered variant") {
withTempPath { path =>
spark.range(10)
.selectExpr("parse_json(cast(id as string)) as v")
.write.parquet(path.getCanonicalPath)

val alwaysTrue = udf(() => true).asNondeterministic()
val query = spark.read.parquet(path.getCanonicalPath)
.where("v::int = 3")
.select(col("_metadata.file_path"))
.filter(alwaysTrue())
.distinct()

assert(query.collect().nonEmpty)
}
}
}

@ExtendedSQLTest
Expand Down