-
Notifications
You must be signed in to change notification settings - Fork 28.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-22937][SQL] SQL elt output binary for binary inputs
## What changes were proposed in this pull request? This pr modified `elt` to output binary for binary inputs. `elt` in the current master always output data as a string. But, in some databases (e.g., MySQL), if all inputs are binary, `elt` also outputs binary (Also, this might be a small surprise). This pr is related to #19977. ## How was this patch tested? Added tests in `SQLQueryTestSuite` and `TypeCoercionSuite`. Author: Takeshi Yamamuro <yamamuro@apache.org> Closes #20135 from maropu/SPARK-22937. (cherry picked from commit e8af7e8) Signed-off-by: gatorsmile <gatorsmile@gmail.com>
- Loading branch information
1 parent
55afac4
commit bf85301
Showing
7 changed files
with
281 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
sql/core/src/test/resources/sql-tests/inputs/typeCoercion/native/elt.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
-- Mixed inputs (output type is string) | ||
SELECT elt(2, col1, col2, col3, col4, col5) col | ||
FROM ( | ||
SELECT | ||
'prefix_' col1, | ||
id col2, | ||
string(id + 1) col3, | ||
encode(string(id + 2), 'utf-8') col4, | ||
CAST(id AS DOUBLE) col5 | ||
FROM range(10) | ||
); | ||
|
||
SELECT elt(3, col1, col2, col3, col4) col | ||
FROM ( | ||
SELECT | ||
string(id) col1, | ||
string(id + 1) col2, | ||
encode(string(id + 2), 'utf-8') col3, | ||
encode(string(id + 3), 'utf-8') col4 | ||
FROM range(10) | ||
); | ||
|
||
-- turn on eltOutputAsString | ||
set spark.sql.function.eltOutputAsString=true; | ||
|
||
SELECT elt(1, col1, col2) col | ||
FROM ( | ||
SELECT | ||
encode(string(id), 'utf-8') col1, | ||
encode(string(id + 1), 'utf-8') col2 | ||
FROM range(10) | ||
); | ||
|
||
-- turn off eltOutputAsString | ||
set spark.sql.function.eltOutputAsString=false; | ||
|
||
-- Elt binary inputs (output type is binary) | ||
SELECT elt(2, col1, col2) col | ||
FROM ( | ||
SELECT | ||
encode(string(id), 'utf-8') col1, | ||
encode(string(id + 1), 'utf-8') col2 | ||
FROM range(10) | ||
); |
Oops, something went wrong.