Skip to content
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

Closed
wants to merge 4 commits into from

Conversation

juliuszsompolski
Copy link
Contributor

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.

@juliuszsompolski
Copy link
Contributor Author

cc @cloud-fan

@hvanhovell
Copy link
Contributor

ok to test

@hvanhovell
Copy link
Contributor

Could you add a unit test to the DDLCommandSuite?

@SparkQA
Copy link

SparkQA commented Apr 20, 2017

Test build #75994 has finished for PR 17707 at commit 59ba235.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Apr 20, 2017

Test build #75997 has finished for PR 17707 at commit ca8ac7e.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan
Copy link
Contributor

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) {
Copy link
Member

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)
Copy link
Member

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'?

@SparkQA
Copy link

SparkQA commented Apr 21, 2017

Test build #76029 has finished for PR 17707 at commit 4abfa2a.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

val expected5 = AlterTableSerDePropertiesCommand(
tableIdent,
None,
Some(Map("columns" -> "foo,bar", "field.delim" -> ",")),
Some(Map("test" -> null, "dt" -> "2008-08-08", "country" -> "us")))
Copy link
Contributor Author

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.

@cloud-fan
Copy link
Contributor

thanks, merging to master/2.2!

@asfgit asfgit closed this in c9e6035 Apr 21, 2017
asfgit pushed a commit that referenced this pull request Apr 21, 2017
… 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>
peter-toth pushed a commit to peter-toth/spark that referenced this pull request Oct 6, 2018
… 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants