Repository navigation
fix(spark): return the requested field when Spark prunes nested fields - #10724
Conversation
…t fields
With spark.sql.optimizer.nestedSchemaPruning.enabled (the Spark default),
pruneColumns receives struct columns with unused fields removed. The native
scan only projects top-level columns and returns the full struct, but
readSchema() reported the pruned type, so Spark bound nested fields by the
pruned ordinals and silently returned the wrong field: selecting s.c from
s{a,b,c} returned s.a.
Keep each required column's full table type, so readSchema() matches the
data the reader returns. Nested pruning in the native scan can follow.
Signed-off-by: gitRasheed <99349713+gitRasheed@users.noreply.github.com>
Keep the table's columns that Spark requires instead of rebuilding them from the required schema, so a pruned type can't slip back in. Test struct, array, map and struct-in-struct fields, and document that pruning is top-level only. Signed-off-by: gitRasheed <99349713+gitRasheed@users.noreply.github.com>
The Java CI job runs `gradlew check`, which includes spotlessCheck. Signed-off-by: gitRasheed <99349713+gitRasheed@users.noreply.github.com>
Pin the pruneColumns contract without going through Spark's optimizer: a nested-pruned required schema yields the table's full column types, in table order, and unrequired columns are dropped. Signed-off-by: gitRasheed <99349713+gitRasheed@users.noreply.github.com>
… note Signed-off-by: gitRasheed <99349713+gitRasheed@users.noreply.github.com>
aa17508 to
a7744f2
Compare
Merging this PR will degrade performance by 17.8%3 warnings, 1 note
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
Summary
Fixes #10723
Reading one field of a nested column returned a different field, because
readSchema()described pruned structs while the native scan returns each top-level column whole.Changes
pruneColumnsnow keeps each required column with its full table type, in table order, soreadSchema()matches what the reader returns. A query that uses one field of a nested column still reads the whole column.VortexNestedSchemaPruningTestselects a non-first field from a struct, an array of structs, a map of structs and a struct inside a struct. All four fail without the fix.VortexScanBuilderTest.pruneColumnsKeepsTableTypeschecks the read schema directly.I used AI tools to help write and review this change.