ivan-kiselev opened a new pull request, #27919:
URL: https://github.com/apache/datafusion/pull/27919

   ## Which issue does this PR close?
   
   Closes #27905.
   
   Replaces #27906 in coordination with @ekkinox. This moves the contribution 
to the shared `dash0hq/datafusion` fork so we can maintain it together. 
Jonathan's original commit and authorship are preserved, followed by a separate 
lookup-policy fix and expanded benchmarks. His PR remains a draft until this 
replacement is available.
   
   ## Rationale for this change
   
   Wide struct schema adaptation can spend substantial CPU time matching field 
names before reading data. `map_struct_fields` searches the source fields for 
each target field, making name matching quadratic when both schemas are wide.
   
   Indexing removes that repeated search, but building an index for every call 
regresses small structs and wastes work when a wide source has only one target. 
This version keeps a linear path for those cases.
   
   ## What changes are included in this PR?
   
   - Use linear lookup when there are zero or one target fields, or both 
schemas have at most 32 fields. Otherwise, build one source-name index for the 
overlap check and target lookups.
   - Keep first-match behavior for duplicate names, target validation order, 
missing-field handling and errors shared between both paths.
   - Extend the struct benchmark with small aligned/reversed schemas, 
wide-source single-target cases, runtime struct casts and an unchanged 
primitive-cast control.
   
   The cutoff of 32 is a conservative measured choice, not a globally optimal 
threshold. No public API, persistent cache or dependency change is included.
   
   <details>
   <summary>Focused benchmark results</summary>
   
   Same-binary comparison against upstream main at 
`c75bc57aa1e59e50f9134d66e0e38e834f503948`, using a standalone Rust harness 
with the baseline and candidate source. Values are microseconds per call, 
median [minimum, maximum].
   
   | Case | Main | Candidate |
   | --- | ---: | ---: |
   | Sparse 5,000 source / 10,000 target | 95,779.677 [94,073.910, 102,831.664] 
| 494.950 [463.849, 542.120] |
   | Aligned 8 fields | 0.404158 [0.400654, 0.478044] | 0.164433 [0.163046, 
0.221578] |
   | Aligned 32 fields | 2.122488 [2.080018, 2.166495] | 1.062850 [1.034731, 
1.323378] |
   | Reversed 33 fields | 2.256260 [2.192860, 2.623114] | 2.129945 [2.081781, 
2.377856] |
   | 10,000 source / first target | 289.600520 [283.554948, 302.747648] | 
0.023600 [0.021923, 0.048322] |
   | 10,000 source / last target | 337.604662 [330.881906, 357.152275] | 
73.790945 [61.898323, 92.693112] |
   | Runtime reversed struct, 8 fields / 16 rows | 2.216666 [2.175612, 
2.672115] | 2.001115 [1.942818, 2.284460] |
   | Unchanged primitive cast | 0.110788 [0.108279, 0.164503] | 0.110742 
[0.107790, 0.124067] |
   
   Twenty samples per implementation, balanced 
baseline/candidate/candidate/baseline order. Each sample averages 100,000 calls 
for small validation and casts, 1,000 for single-target wide-source validation, 
and 10 for sparse wide validation. Fixtures and correctness assertions are 
outside timers. Inputs are synthetic and resident; there is no I/O or 
cold-cache claim.
   
   Measured on an 8-CPU x86-64 Linux machine with 15 GiB RAM, Rust 1.100.0 
release, DataFusion 57.0.0-dev and Arrow 60.2.0. These are function-level 
measurements, not query latency or optimized Criterion results. The 33-field 
and runtime ranges overlap. The contributed Criterion cases also passed in test 
mode.
   
   </details>
   
   ## What is the testing strategy for this PR?
   
   Existing nested-struct tests cover compatibility, missing/extra fields and 
errors. The original commit adds mapping checks for duplicate/reordered/missing 
names and a reversed 2,000-field struct. The benchmark fixtures check runtime 
values, types, order and nulls outside the timed loop.
   
   Before rebasing, all of these passed on upstream's pinned Rust 1.99.1:
   
   - `cargo fmt --all --check`
   - `cargo clippy --all-targets --all-features -- -D warnings`
   - Full `./dev/rust_lint.sh`
   - The contributor guide's extended workspace test command: 13,698 passed, 0 
failed, 8 ignored; all 310 SQL test files completed. The command excludes 
examples, benchmarks and CLI as documented.
   - All 16 nested-struct Criterion cases in test mode.
   
   The branch was then rebased onto `929fd8a948a164af05d23e57b0e4b2f979c5af1a`. 
`git range-diff` confirms both patch contents are unchanged. Formatting and the 
90 nested-struct tests were rerun after the rebase. The full workspace checks 
and performance measurements were not repeated on the new base; CI will 
validate the submitted head.
   
   ## Are there any user-facing changes?
   
   Faster struct compatibility checks. Results, validation errors and public 
APIs are unchanged.
   
   Prepared with an AI coding assistant under task-specific human supervision.
   


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