-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-18106][SQL] ANALYZE TABLE should raise a ParseException for invalid option #15640
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 2 commits
4819dd1
2a7707e
ec0516b
00b4f54
465f646
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 |
|---|---|---|
|
|
@@ -98,9 +98,10 @@ class SparkSqlAstBuilder(conf: SQLConf) extends AstBuilder { | |
| * }}} | ||
| */ | ||
| override def visitAnalyze(ctx: AnalyzeContext): LogicalPlan = withOrigin(ctx) { | ||
| if (ctx.partitionSpec == null && | ||
| ctx.identifier != null && | ||
| ctx.identifier.getText.toLowerCase == "noscan") { | ||
| if (ctx.identifier != null && ctx.identifier.getText.toLowerCase != "noscan") { | ||
| throw new ParseException(s"Expected `NOSCAN` instead of `${ctx.identifier.getText}`", ctx) | ||
| } | ||
| if (ctx.partitionSpec == null && ctx.identifier != null) { | ||
|
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. What if partition spec is not null ? (Could you add a test for that ?) could be moved to the top ?
Member
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. Thank you for review and I'll handle that too.
Member
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. Test case is added. |
||
| AnalyzeTableCommand(visitTableIdentifier(ctx.tableIdentifier)) | ||
| } else if (ctx.identifierSeq() == null) { | ||
| AnalyzeTableCommand(visitTableIdentifier(ctx.tableIdentifier), noscan = false) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,8 +23,8 @@ import org.apache.spark.sql.catalyst.catalog.{BucketSpec, CatalogStorageFormat, | |
| import org.apache.spark.sql.catalyst.parser.ParseException | ||
| import org.apache.spark.sql.catalyst.plans.PlanTest | ||
| import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan | ||
| import org.apache.spark.sql.execution.command.{DescribeFunctionCommand, DescribeTableCommand, | ||
| ShowFunctionsCommand} | ||
| import org.apache.spark.sql.execution.command.{AnalyzeTableCommand, DescribeFunctionCommand, | ||
| DescribeTableCommand, ShowFunctionsCommand} | ||
| import org.apache.spark.sql.execution.datasources.{CreateTable, CreateTempViewUsing} | ||
| import org.apache.spark.sql.internal.{HiveSerDe, SQLConf} | ||
| import org.apache.spark.sql.types.{IntegerType, LongType, StringType, StructType} | ||
|
|
@@ -220,4 +220,13 @@ class SparkSqlParserSuite extends PlanTest { | |
|
|
||
| intercept("explain describe tables x", "Unsupported SQL statement") | ||
| } | ||
|
|
||
| test("SPARK-18106 analyze table") { | ||
|
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. There are also parse tests for AnalyzeTable in sql/hive/src/test/scala/org/apache/spark/sql/hive/StatisticsSuite.scala
Member
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. Sure.
Member
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. Ur, @srinathshankar . I understand the reason why you put this there, so I looked at the StatisticsSuite.scala in both How do you think about that?
Member
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. If you want, I'll remove the normal cases which raises no exceptions.
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. Then maybe you can move those parse tests here ? All I'm suggesting is that the parse tests all be together.
Member
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. Thank you. But, the parse test should be rewritten. Is it okay? Those testcase uses def assertAnalyzeCommand(analyzeCommand: String, c: Class[_]) {
val parsed = spark.sessionState.sqlParser.parsePlan(analyzeCommand)
val operators = parsed.collect {
case a: AnalyzeTableCommand => a
case o => o
}
assert(operators.size === 1)
if (operators(0).getClass() != c) {
fail(
s"""$analyzeCommand expected command: $c, but got ${operators(0)}
|parsed command:
|$parsed
""".stripMargin)
}
}
assertAnalyzeCommand(
"ANALYZE TABLE Table1 COMPUTE STATISTICS",
classOf[AnalyzeTableCommand])
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. In my opinion it's fine to rewrite and simplify. If you could do that, that would be great.
Member
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. Yep. I have no objection for that. Actually, I love to do that.
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. Lets keep the parsing unit test (this file) and the analyze table integration test separate for now.
Member
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. Thank you for the guide! |
||
| assertEqual("analyze table t compute statistics", | ||
| AnalyzeTableCommand(TableIdentifier("t"), noscan = false)) | ||
| assertEqual("analyze table t compute statistics noscan", | ||
| AnalyzeTableCommand(TableIdentifier("t"), noscan = true)) | ||
| intercept("analyze table t compute statistics xxxx", "Expected `NOSCAN` instead of `xxxx`") | ||
| intercept("analyze table t partition (a) compute statistics xxxx") | ||
|
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. Nit:
Member
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. Thank you, It's done. |
||
| } | ||
| } | ||
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.
Move this check into the first
ifstatement. There is no need to check this twice.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.
I also think that the treatment of the
partionSpecis quite funky. We scan the table as soon as a user defines a spec. Could you remove the null check; maybe it is better to just log a warning message and do what the user specified.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.
Thank you for review, @hvanhovell . I'll update the PR.