ViktorBystrov72 opened a new pull request, #60610:
URL: https://github.com/apache/spark/pull/60610

   ### What changes were proposed in this pull request?
   
   Retain the declared default type in internal read-schema metadata when 
`SchemaPruning` narrows a column's nested type. `ResolveDefaultColumns` 
resolves the original default using that type, then projects the value to the 
requested struct/array/map shape. Preserve the source default metadata on 
repeated pruning passes.
   
   Add Catalyst tests for nested values, NULLs, empty collections, map 
keys/values, preservation of the current default, and idempotence. Add Parquet 
regressions that read old files and newly written rows through V1/V2 file 
sources, checking both results and the pruned scan schema.
   
   Projecting the resolved value also preserves distinct original map entries 
whose keys become equal in the pruned representation. Rebuilding such a 
projected value as SQL would raise `DUPLICATED_MAP_KEY` or deduplicate entries. 
The original SQL is retained.
   
   ### Why are the changes needed?
   
   [SPARK-60790](https://issues.apache.org/jira/browse/SPARK-60790): after 
adding a nested column with a nonempty default, selecting a subset of its 
fields from an older Parquet file fails with `INVALID_DEFAULT_VALUE.DATA_TYPE`.
   
   The read schema has been pruned, but its existence default still describes 
the complete value. For example, selecting `s.b` asks the reader to coerce 
`named_struct('a', 11, 'b', 22)` to `STRUCT<b: INT>`. Resolving the complete 
default against its declared type and then projecting it keeps the read schema 
and default consistent.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. Affected queries return the requested fields of the default instead of 
failing during default-value resolution. Nested schema pruning remains 
effective.
   
   ### How was this patch tested?
   
   Before the fix, six Catalyst regression cases failed and two 
empty-collection controls passed. All 16 original Parquet V1/V2 regression 
cases failed. All 27 focused cases pass with the fix, including the additional 
map-key collision regressions.
   
   The Parquet cases add columns after writing the first file, then append a 
row with stored values. The file sources use the catalog schema, including 
default metadata, so V1 and V2 scans are both exercised. Row and vectorized 
readers cover nonempty defaults; nullable complex defaults are covered by the 
row reader and Catalyst tests.
   
   All 23 Catalyst tests and 1,199 SQL tests in the scoped suites passed (1,222 
total). Catalyst production/test and SQL test ScalaStyle passed. Apache RAT 
passed with the repository exclusions plus `.git`, the local worktree metadata 
file; no additional source exclusions were used.
   
   Scoped validation:
   
   ```text
   catalyst/testOnly 
org.apache.spark.sql.catalyst.expressions.SchemaPruningSuite
   sql/testOnly org.apache.spark.sql.ResolveDefaultColumnsSuite 
*ParquetV1SchemaPruningSuite *ParquetV2SchemaPruningSuite 
*OrcV1SchemaPruningSuite *OrcV2SchemaPruningSuite
   catalyst/Compile/scalastyle
   catalyst/Test/scalastyle
   sql/Test/scalastyle
   ```
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: OpenAI Codex (GPT-6; exact model/tool build unavailable).
   


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