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

   ## Which issue does this PR close?
   
   - Closes #408.
   
   ## Rationale for this change
   
   `encode('', 'utf-16')` returns `feff` (only the byte order mark), while 
Spark returns an empty binary. Spark 4.0 returns the input bytes unchanged when 
the input is empty, and Spark 3.5 goes through `String.getBytes(charset)`, 
where the JDK returns an empty array for an empty string without running the 
encoder, so no BOM is written.
   
   ## What changes are included in this PR?
   
   - In `encode_string`, the `UTF-16` / `UTF16` branch now skips the byte order 
mark when the input string is empty. Non-empty input is unchanged and still 
starts with `FE FF`.
   - Updated the `#[user_doc]` description of `encode` to say the BOM is 
omitted for an empty string, and regenerated 
`docs/functions/scalar/binary_string.md` with `dev/update_function_docs.sh`.
   
   ## Are these changes tested?
   
   Yes:
   
   - Unit test `test_utf16_empty_string_has_no_bom` in `encode.rs`. It covers 
`utf-16`, the legacy `utf16` alias, empty binary input, and that non-empty 
input still gets the BOM.
   - New cases in `string/encode.slt`, covering the queries from the issue. The 
empty result is asserted through `octet_length(...)`, because the sqllogictest 
format can't express an empty binary row.
   
   The new tests fail without the fix and pass with it. `cargo fmt --all`, 
`cargo clippy --all-targets --all-features -- -D warnings`, `cargo test -p 
datafusion-spark` and `cargo test -p datafusion-spark-sqllogictest` all pass.
   
   The expected behavior comes from reading the Spark 4.0.0 and 3.5 sources 
(see the rationale above). I did not run these cases against a live Spark.
   
   ## Are there any user-facing changes?
   
   Yes: `encode('', 'utf-16')` now returns an empty binary instead of `feff`, 
matching Spark. There are no public Rust API changes.


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