TechWizard9999 opened a new issue, #408:
URL: https://github.com/apache/datafusion-spark/issues/408
### Describe the bug
`encode('', 'utf-16')` returns `feff`, only the byte order mark. Spark
returns an empty binary.
The `UTF-16` branch always writes the byte order mark first, even for an
empty string
([encode.rs#L202-L205](https://github.com/apache/datafusion-spark/blob/2129f388277144e4549654c8250a975ccf0322d4/crates/spark/src/function/string/encode.rs#L202-L205)).
### To Reproduce
```sql
SELECT encode(''::string, 'utf-16'::string);
SELECT encode(s, 'utf-16') FROM (VALUES (''), ('a')) t(s);
```
datafusion-spark returns:
```
feff
feff
feff0061
```
`encode('a', 'utf-16')` returns `feff0061`, which matches Spark.
### Expected behavior
An empty binary for the empty string, as in Spark.
### Spark versions
Spark 4.0.0: `Encode.encode` returns the input bytes when `input.numBytes ==
0`
([stringExpressions.scala#L3193](https://github.com/apache/spark/blob/v4.0.0/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala#L3193)).
Spark 3.5 calls Java's `String.getBytes(charset)`
([stringExpressions.scala#L2691](https://github.com/apache/spark/blob/v3.5.0/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala#L2691)).
For an empty string the JDK returns an empty array without running the
encoder, so no byte order mark is written. Not run on a live Spark.
### datafusion-spark version
main at 2129f38
### Additional context
Found with the sqllogictest runner, in both simplify and evaluate modes.
cc @andygrove
--
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]