-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-41205][SQL] Check that format is foldable in TryToBinary
#38727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,4 +45,8 @@ select try_to_binary(null, null); | |
| select try_to_binary(null, cast(null as string)); | ||
| -- invalid format | ||
| select try_to_binary('abc', 1); | ||
| select try_to_binary('abc', 'invalidFormat'); | ||
| select try_to_binary('abc', 'invalidFormat'); | ||
| -- format must be foldable | ||
| SELECT try_to_binary(col1, col2) from values ('abc', 'utf-8') as data(col1, col2); | ||
| -- non-foldable input string | ||
| SELECT try_to_binary(col1, 'utf-8') from values ('abc') as data(col1); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not strictly relevant to this issue, but I noticed that there were no tests for non-foldable input values, so I added one. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1597,3 +1597,20 @@ org.apache.spark.sql.AnalysisException | |
| "invalidValue" : "invalidformat" | ||
| } | ||
| } | ||
|
|
||
|
|
||
| -- !query | ||
| SELECT to_binary(col1, col2) from values ('abc', 'utf-8') as data(col1, col2) | ||
| -- !query schema | ||
| struct<> | ||
| -- !query output | ||
| org.apache.spark.sql.AnalysisException | ||
| The 'format' parameter of function 'to_binary' needs to be a string literal.; line 1 pos 7 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When you move the exception from constructor, you should see |
||
|
|
||
|
|
||
| -- !query | ||
| SELECT to_binary(col1, 'utf-8') from values ('abc') as data(col1) | ||
| -- !query schema | ||
| struct<to_binary(col1, utf-8):binary> | ||
| -- !query output | ||
| abc | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you perform the check in
checkInputDataTypes()as we do that in other expression, please.BTW, exceptions from expressions constructors are wrapped by
AnalysisExceptionadditionally which is not convenient to users.