mrhard9090 opened a new pull request, #25774:
URL: https://github.com/apache/datafusion/pull/25774

   ## Which issue does this PR close?
   
   - Closes #25505.
   
   ## Rationale for this change
   
   Spark's `xxhash64` treats a NULL value by leaving the running hash 
unchanged, so `xxhash64` of a NULL struct should be the seed, `42`. When a 
struct is NULL but its child arrays still hold values, for example after 
`nullif(s, s)`, DataFusion hashed those child values anyway:
   
   ```sql
   SELECT s IS NULL, xxhash64(s), xxhash64(arrow_cast(NULL, 'Struct("a": Int64, 
"b": Utf8)'))
   FROM (SELECT nullif(s, s) AS s FROM (SELECT named_struct('a', 1, 'b', 'x') 
AS s));
   -- true  6158280145716684778  42
   ```
   
   The same NULL gets two different hashes depending on how it was produced.
   
   ## What changes are included in this PR?
   
   In the `DataType::Struct` branch of `create_hashes_internal!`, when the 
struct array has NULLs, the hashes are saved before the fields are hashed, and 
the saved value is put back for every NULL row. Without NULLs the branch works 
as before and copies nothing.
   
   ## What is the testing strategy for this PR?
   
   - New unit test `test_xxhash64_null_struct_ignores_fields`: a struct whose 
second row is NULL but whose fields still hold values. The NULL row keeps the 
seed and the valid row is hashed.
   - `spark/hash/xxhash64.slt` gets the query from the issue, which now returns 
`true 42 42`. Without the change it returns `6158280145716684778` for the 
masked NULL, so the test fails.
   - `cargo test -p datafusion-spark --lib xxhash64` passes, and so do the 
`xxhash64` sqllogictest, `cargo fmt --all` and `cargo clippy -p 
datafusion-spark --no-deps --all-targets --all-features -- -D warnings`.
   
   ## Are there any user-facing changes?
   
   `xxhash64` of a NULL struct now returns the input hash (`42` for a single 
argument), matching Spark. There are no API changes.
   
   This PR was written with help from Claude Opus 5.5. I reviewed the change 
and ran the tests above myself.
   


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