-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-27931][SQL] Accept "true", "yes", "1", "false", "no", "0", and unique prefixes as input and trim input for the boolean data type. #25458
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
7d61642
933fe86
a5aec9f
9e9aac3
dacd46b
abe9a84
2ea551c
b787483
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 |
|---|---|---|
|
|
@@ -819,20 +819,34 @@ class CastSuite extends SparkFunSuite with ExpressionEvalHelper { | |
| } | ||
|
|
||
| test("cast string to boolean") { | ||
| checkCast("t", true) | ||
| checkCast("true", true) | ||
| checkCast("tru", true) | ||
| checkCast("tr", true) | ||
| checkCast("t", true) | ||
| checkCast("tRUe", true) | ||
| checkCast("y", true) | ||
| checkCast(" tRue ", true) | ||
| checkCast(" tRu ", true) | ||
| checkCast("yes", true) | ||
| checkCast("ye", true) | ||
| checkCast("y", true) | ||
| checkCast("1", true) | ||
| checkCast("on", true) | ||
|
|
||
| checkCast("f", false) | ||
| checkCast("false", false) | ||
| checkCast("FAlsE", false) | ||
younggyuchun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| checkCast("n", false) | ||
| checkCast("fals", false) | ||
| checkCast("fal", false) | ||
| checkCast("fa", false) | ||
| checkCast("f", false) | ||
| checkCast(" fAlse ", false) | ||
| checkCast(" fAls ", false) | ||
| checkCast(" FAlsE ", false) | ||
| checkCast("no", false) | ||
| checkCast("n", false) | ||
| checkCast("0", false) | ||
| checkCast("off", false) | ||
| checkCast("of", false) | ||
|
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. @younggyuchun, just for doubly sure, did you double check the behaviours against PostgreSQL?
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. @HyukjinKwon Here it is:
Contributor
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. This is not documented: https://www.postgresql.org/docs/devel/datatype-boolean.html Postgres may support
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. @cloud-fan @dongjoon-hyun @HyukjinKwon
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. @cloud-fan . It's a documented feature in that document. We had better support it.
cc @gatorsmile
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. BTW, @younggyuchun . Please add a negative test case.
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. Seems okay to me
Contributor
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. SGTM |
||
|
|
||
| checkEvaluation(cast("o", BooleanType), null) | ||
|
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. @dongjoon-hyun |
||
| checkEvaluation(cast("abc", BooleanType), null) | ||
| checkEvaluation(cast("", BooleanType), null) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -39,7 +39,7 @@ SELECT boolean(' f ') AS `false` | |||
| -- !query 4 schema | ||||
| struct<false:boolean> | ||||
| -- !query 4 output | ||||
| NULL | ||||
| false | ||||
|
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. plz remove the comments, too:
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. I found the four places to remove.
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. done Thank you @maropu |
||||
|
|
||||
|
|
||||
| -- !query 5 | ||||
|
|
@@ -127,23 +127,23 @@ SELECT boolean('on') AS true | |||
| -- !query 15 schema | ||||
| struct<true:boolean> | ||||
| -- !query 15 output | ||||
| NULL | ||||
| true | ||||
|
|
||||
|
|
||||
| -- !query 16 | ||||
| SELECT boolean('off') AS `false` | ||||
| -- !query 16 schema | ||||
| struct<false:boolean> | ||||
| -- !query 16 output | ||||
| NULL | ||||
| false | ||||
|
|
||||
|
|
||||
| -- !query 17 | ||||
| SELECT boolean('of') AS `false` | ||||
| -- !query 17 schema | ||||
| struct<false:boolean> | ||||
| -- !query 17 output | ||||
| NULL | ||||
| false | ||||
|
|
||||
|
|
||||
| -- !query 18 | ||||
|
|
@@ -296,7 +296,7 @@ SELECT boolean(string(' true ')) AS true, | |||
| -- !query 36 schema | ||||
| struct<true:boolean,false:boolean> | ||||
| -- !query 36 output | ||||
| NULL NULL | ||||
| true false | ||||
|
|
||||
|
|
||||
| -- !query 37 | ||||
|
|
||||

Uh oh!
There was an error while loading. Please reload this page.