Pastoray opened a new pull request, #425:
URL: https://github.com/apache/datafusion-spark/pull/425

   ## Which issue does this PR close?
   
   - Closes #364.
   
   ## Rationale for this change
   
   DataFusion's `struct(...)` names its fields `c0`, `c1`, ..., while Spark 
names them `col1`, `col2`, .... With the Spark functions registered, `SELECT 
struct(1, 2, 3)` returned `{c0: 1, c1: 2, c2: 3}` where Spark returns `{col1: 
1, col2: 2, col3: 3}` (`struct<col1:int,col2:int,col3:int>`). This shows up in 
the output of any query that builds a struct, such as `map_from_arrays` and 
`map_from_entries` with struct values.
   
   ## What changes are included in this PR?
   
   - Add a Spark-compatible `struct` function (`SparkStruct`) that names fields 
`col1`, `col2`, ... (1-based). It is registered with the other Spark functions 
and exported as `expr_fn::r#struct`.
   - Route unnamed struct literals (`struct(a, b, ...)`) to it in 
`SparkFunctionPlanner::plan_struct_literal`. DataFusion plans `struct(...)` 
through the `ExprPlanner` and never looks up a registered `struct` function, so 
registering the function alone had no effect.
   - Named structs such as `struct(1 AS a)` are left to DataFusion, since they 
already use the names the user gave.
   - Add the `#[user_doc]` and regenerate `docs/functions` (new 
`scalar/struct.md` page and README entries).
   
   ## Are these changes tested?
   
   Yes.
   
   - Unit tests in `function/struct/spark_struct.rs`: field naming, the error 
for zero arguments, the non-nullable return field, and invoking with a mix of 
array and scalar arguments.
   - `struct/struct.slt`: replaces the commented-out record with active cases 
for int fields, mixed types, `NULL` fields and nested structs.
   - `map/map_from_arrays.slt`: removes the `xfail spark` marker that 
referenced this issue and updates the expected value.
   - `map/map_from_entries.slt`: the expected value of the nested `struct(1, 2, 
3)` now uses `col1..col3`.
   
   The expected results follow the Spark 3.5.5 result recorded in `struct.slt` 
(`struct<col1:int,col2:int,col3:int>`). I did not run the PySpark runner in 
`crates/sqllogictest/scripts` against these new cases.
   
   `cargo fmt --all --check`, `cargo clippy --all-targets --all-features -- -D 
warnings`, `cargo test -p datafusion-spark` and `cargo test -p 
datafusion-spark-sqllogictest` all pass.
   
   ## Are there any user-facing changes?
   
   Yes. `struct(...)` now returns Spark's field names (`col1`, `col2`, ...) 
instead of DataFusion's (`c0`, `c1`, ...) when the Spark functions are 
registered. Queries that referenced the old names, for example `get_field(s, 
'c0')`, need updating. It also adds `struct` to the function reference docs and 
a new public `expr_fn::r#struct`. There is no breaking change to the existing 
public Rust API.


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