zakariya-s opened a new pull request, #445:
URL: https://github.com/apache/datafusion-spark/pull/445
<!--
SPDX-License-Identifier: Apache-2.0
SPDX-FileCopyrightText: See the NOTICE file distributed with this work for
additional information regarding copyright ownership
SPDX-FileContributor: Licensed to the Apache Software Foundation (ASF) under
one or more contributor license agreements
-->
## Which issue does this PR close?
<!--
Link the issue this PR fixes, for example `Closes #123`. Most changes should
have an
issue, which also helps us write the changelog for each release.
-->
- Closes #199.
## Rationale for this change
<!--
Why is this change needed? If the issue already explains it, you can skip
this section.
Describe the problem in terms of behavior a user sees, rather than the
implementation.
For example, "`round` returns 2.0 for 2.5 where Spark returns 3.0" rather
than "the
code in `round.rs` truncates".
-->
`translate` currently resolves to DataFusion's built-in. That function
matches Spark except in two ways:
- A U+0000 in `to` is written to the output. Spark deletes the character
instead, because `StringTranslate.buildDict` uses U+0000 as its deletion
marker: `translate('abc', 'b', char(0))` returns `ac` in Spark.
- Arrays, maps and structs are accepted and cast to their display string:
`translate(array('a'), 'a', 'x')` returns `[x]`. Spark rejects them with
`DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE`.
## What changes are included in this PR?
<!--
A summary of the changes. There is no need to repeat the issue.
-->
A Spark `translate` that calls DataFusion's `translate` kernel. The U+0000
rule is handled by rewriting `from` and `to` into an equivalent pair before
calling the kernel. The rewrite only happens when a `to` value contains a NUL
byte, so other calls pass straight through and keep the kernel's scalar and
ASCII fast paths.
## Are these changes tested?
<!--
Point to the tests you added, for example the `.slt` cases in
`math/round.slt`.
Say which Spark versions you checked the expected results against, and how.
For
example with the PySpark runner in `crates/sqllogictest/scripts`, or with
the Spark
source or golden files. If this PR does not add tests, explain why.
-->
`string/translate.slt` replaces the porting stub with 64 records. Expected
values were taken from PySpark 4.2.0 and checked with `pyspark_slt_runner.py`.
Seven are marked as xfail (six are casts to string that still differ from
Spark's `CAST` (#88) and one is collations (#299)).
## Are there any user-facing changes?
<!--
For example a function that now returns Spark's result, or a new function.
A breaking change to the public Rust API waits until `main` moves to the
next DataFusion
major version. See the versioning policy in `dev/release/README.md`.
-->
`translate` deletes a character mapped to U+0000, and rejects array, map and
struct arguments, as Spark does.
--
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]