-
Notifications
You must be signed in to change notification settings - Fork 28.5k
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
[SPARK-20412] Throw ParseException from visitNonOptionalPartitionSpec instead of returning null values. #17707
Conversation
cc @cloud-fan |
ok to test |
Could you add a unit test to the DDLCommandSuite? |
Test build #75994 has finished for PR 17707 at commit
|
Test build #75997 has finished for PR 17707 at commit
|
looks like we need to fix a test |
@@ -214,8 +214,11 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with Logging { | |||
* Create a partition specification map without optional values. | |||
*/ | |||
protected def visitNonOptionalPartitionSpec( | |||
ctx: PartitionSpecContext): Map[String, String] = withOrigin(ctx) { | |||
visitPartitionSpec(ctx).mapValues(_.orNull).map(identity) | |||
ctx: PartitionSpecContext): Map[String, String] = withOrigin(ctx) { |
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.
Nit: Indentation issues. Need to add extra two spaces
visitPartitionSpec(ctx).mapValues(_.orNull).map(identity) | ||
ctx: PartitionSpecContext): Map[String, String] = withOrigin(ctx) { | ||
visitPartitionSpec(ctx).map { | ||
case (key, None) => throw new ParseException(s"Found empty key '$key'.", ctx) |
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.
How about Found an empty partition key '$key'
?
Test build #76029 has finished for PR 17707 at commit
|
val expected5 = AlterTableSerDePropertiesCommand( | ||
tableIdent, | ||
None, | ||
Some(Map("columns" -> "foo,bar", "field.delim" -> ",")), | ||
Some(Map("test" -> null, "dt" -> "2008-08-08", "country" -> "us"))) |
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.
BTW: In AlterTableSerDePropertiesCommand that null would have caused a NullPointerExeception later, so not having this as null, but checked as ParseException is also a valid change here.
thanks, merging to master/2.2! |
… instead of returning null values. ## What changes were proposed in this pull request? If a partitionSpec is supposed to not contain optional values, a ParseException should be thrown, and not nulls returned. The nulls can later cause NullPointerExceptions in places not expecting them. ## How was this patch tested? A query like "SHOW PARTITIONS tbl PARTITION(col1='val1', col2)" used to throw a NullPointerException. Now it throws a ParseException. Author: Juliusz Sompolski <julek@databricks.com> Closes #17707 from juliuszsompolski/SPARK-20412. (cherry picked from commit c9e6035) Signed-off-by: Wenchen Fan <wenchen@databricks.com>
… instead of returning null values. ## What changes were proposed in this pull request? If a partitionSpec is supposed to not contain optional values, a ParseException should be thrown, and not nulls returned. The nulls can later cause NullPointerExceptions in places not expecting them. ## How was this patch tested? A query like "SHOW PARTITIONS tbl PARTITION(col1='val1', col2)" used to throw a NullPointerException. Now it throws a ParseException. Author: Juliusz Sompolski <julek@databricks.com> Closes apache#17707 from juliuszsompolski/SPARK-20412.
What changes were proposed in this pull request?
If a partitionSpec is supposed to not contain optional values, a ParseException should be thrown, and not nulls returned.
The nulls can later cause NullPointerExceptions in places not expecting them.
How was this patch tested?
A query like "SHOW PARTITIONS tbl PARTITION(col1='val1', col2)" used to throw a NullPointerException.
Now it throws a ParseException.