samarkumar4355 opened a new pull request, #7774:
URL: https://github.com/apache/datafusion-comet/pull/7774
## Which issue does this PR close?
Closes #7769
## Rationale for this change
`ListExtract`, `SparkMapExtract`, `GetStructField`, and `CreateNamedStruct`
were dropping Arrow field metadata (including Arrow extension types such as
`VariantType`) because they relied on DataFusion's default
`PhysicalExpr::return_field` / `ScalarUDFImpl::return_field_from_args` or
rebuilt `Field::new(...)` from `data_type` + `nullable`. Additionally,
`PhysicalPlanner::create_scalar_function_expr` reconstructed `arg_fields` and
the output `Field` from `DataType`s, stripping metadata for scalar UDFs like
`map_extract`.
## What changes are included in this PR?
- **`ListExtract` (`native/spark-expr/src/array_funcs/list_extract.rs`)**:
Updated `child_field` to use `return_field` and overrode
`PhysicalExpr::return_field` to preserve the inner element field's metadata.
- **`SparkMapExtract` (`native/spark-expr/src/map_funcs/map_extract.rs`)**:
Overrode `ScalarUDFImpl::return_field_from_args` to preserve the map value
field's metadata.
- **`GetStructField`
(`native/spark-expr/src/struct_funcs/get_struct_field.rs`)**: Updated
`child_field` to use `return_field` and overrode `PhysicalExpr::return_field`
to preserve the child struct field's metadata.
- **`CreateNamedStruct`
(`native/spark-expr/src/struct_funcs/create_named_struct.rs`)**: Updated
`fields()` to use `expr.return_field(schema)?` with `.with_name(name)` instead
of `Field::new(...)`.
- **`PhysicalPlanner::create_scalar_function_expr`
(`native/core/src/execution/planner.rs`)**: Propagated input `return_field`s
into `arg_fields` and preserved the `FieldRef` returned by
`return_field_from_args` on `ScalarFunctionExpr`.
*(Note: Under ANSI mode with nullable array/map operands,
`CometElementAt.needsNullGuard` wraps `ListExtract`/`map_extract` in
`CaseWhenExpr`, which still uses the default `return_field`. Leaving
`CaseWhenExpr` out of this PR to keep scope focused; happy to follow up if
desired.)*
## How are these changes tested?
Added unit tests covering all 4 expressions and end-to-end planner
integration (`map_extract_preserves_field_metadata_through_planner`).
<details>
<summary>Before fix (4 reproduction tests failing with empty metadata
<code>{}</code>)</summary>
```text
running 4 tests
test
struct_funcs::get_struct_field::tests::get_struct_field_preserves_field_metadata
... FAILED
test map_funcs::map_extract::tests::map_extract_preserves_field_metadata ...
FAILED
test
struct_funcs::create_named_struct::test::test_create_struct_preserves_field_metadata
... FAILED
test
array_funcs::list_extract::test::test_list_extract_preserves_field_metadata ...
FAILED
test result: FAILED. 0 passed; 4 failed; 0 ignored; 0 measured; 1395
filtered out
```
</details>
<details>
<summary>After fix (all unit tests, planner tests, fmt, and clippy
passing)</summary>
- `cargo test -p datafusion-comet-spark-expr --lib
preserves_field_metadata`: **4 passed; 0 failed**
- `cargo test -p datafusion-comet --lib preserves_field_metadata`: **3
passed; 0 failed**
- `cargo test -p datafusion-comet --lib execution::planner::tests`: **81
passed; 0 failed**
- `cargo fmt --check`: **passed**
- `cargo clippy -p datafusion-comet-spark-expr -p datafusion-comet --tests`:
**passed**
</details>
--
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]