← Back to Pull requests

fix: preserve Arrow field metadata in element_at, GetStructField, and CreateNamedStruct #7774

Open
unknown opened this pull request with 406 lines diff across 5 files
View on GitHub
unknown unknown commented on Nov 27, 2026 19:33 UTC
Author

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 DataTypes, 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_fields 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>

    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>

    Diff: 406 lines (+304 / -102) across 5 files Reviewer: comphead Review duration: 4490m
    All Vouch review confidence checks passed
    Residual risk 0.24 = Change Risk (0.45) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 406 lines diff across 5 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.359
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #7774"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 44.8% (MEDIUM) · Higher = larger blast radius
    44.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 23.9% · Safe to merge
    23.9%