-
Notifications
You must be signed in to change notification settings - Fork 28.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-38590][SQL] New SQL function: try_to_binary
### What changes were proposed in this pull request? Add a new SQL function: `try_to_binary`. It is identical to the function `to_binary`, except that it returns NULL results instead of throwing an exception on encoding errors. There is a similar function in Snowflake: https://docs.snowflake.com/en/sql-reference/functions/try_to_binary.html ### Why are the changes needed? Users can manage to finish queries without interruptions by encoding errors. ### Does this PR introduce _any_ user-facing change? Yes, adding a new SQL function: `try_to_binary`. It is identical to the function `to_binary`, except that it returns NULL results instead of throwing an exception on encoding errors. ### How was this patch tested? UT Closes #35897 from gengliangwang/try_to_binary. Authored-by: Gengliang Wang <gengliang@apache.org> Signed-off-by: Max Gekk <max.gekk@gmail.com>
- Loading branch information
1 parent
b57c93b
commit becda33
Showing
9 changed files
with
97 additions
and
13 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
21 changes: 21 additions & 0 deletions
21
sql/core/src/test/resources/sql-tests/inputs/try-string-functions.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,21 @@ | ||
-- try_to_binary | ||
select try_to_binary('abc'); | ||
select try_to_binary('abc', 'utf-8'); | ||
select try_to_binary('abc', 'base64'); | ||
select try_to_binary('abc', 'hex'); | ||
-- 'format' parameter can be any foldable string value, not just literal. | ||
select try_to_binary('abc', concat('utf', '-8')); | ||
-- 'format' parameter is case insensitive. | ||
select try_to_binary('abc', 'Hex'); | ||
-- null inputs lead to null result. | ||
select try_to_binary('abc', null); | ||
select try_to_binary(null, 'utf-8'); | ||
select try_to_binary(null, null); | ||
select try_to_binary(null, cast(null as string)); | ||
-- 'format' parameter must be string type or void type. | ||
select try_to_binary(null, cast(null as int)); | ||
select try_to_binary('abc', 1); | ||
-- invalid format | ||
select try_to_binary('abc', 'invalidFormat'); | ||
-- invalid string input | ||
select try_to_binary('a!', 'base64'); |
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
Binary file added
BIN
+1.88 KB
sql/core/src/test/resources/sql-tests/results/try-string-functions.sql.out
Binary file not shown.