-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-12689][SQL] Migrate DDL parsing to the newly absorbed parser #10723
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
Closed
Closed
Changes from 2 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
f886f67
Migrate DDL parsing to the newly absorbed parser: describe command.
viirya c60cd9e
Migrate refreshTable command.
viirya f2d6fa6
Migrate createTable ddl command.
viirya 5a6cc4a
Merge remote-tracking branch 'upstream/master' into migrate-ddl-describe
viirya 78f1b7c
Remove quotes from option values.
viirya 1c145eb
Allow dotted provider name.
viirya d800c58
Address comments and fix bug.
viirya 838f701
Remove DDLParser.
viirya 7e0f218
Merge remote-tracking branch 'upstream/master' into migrate-ddl-describe
viirya 559083e
Fix MiMa test.
viirya 17ce6ae
Merge remote-tracking branch 'upstream/master' into migrate-ddl-describe
viirya 4fc7a60
Fix test by allowing using DOT in option key and support comment in c…
viirya 3e5a229
Fix test.
viirya 9922ccc
Fix another problem.
viirya cbd3173
Fix test.
viirya 1df2b80
For comments.
viirya 9ff32e0
For comment.
viirya 7350f07
Merge remote-tracking branch 'upstream/master' into migrate-ddl-describe
viirya 7d31844
For comments.
viirya 8b7086e
Merge remote-tracking branch 'upstream/master' into migrate-ddl-describe
viirya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ import org.apache.spark.sql.catalyst.{CatalystQl, TableIdentifier} | |
| import org.apache.spark.sql.catalyst.analysis.UnresolvedRelation | ||
| import org.apache.spark.sql.catalyst.parser.{ASTNode, ParserConf, SimpleParserConf} | ||
| import org.apache.spark.sql.catalyst.plans.logical.{LogicalPlan, OneRowRelation} | ||
| import org.apache.spark.sql.execution.datasources.RefreshTable | ||
|
|
||
| private[sql] class SparkQl(conf: ParserConf = SimpleParserConf()) extends CatalystQl(conf) { | ||
| /** Check if a command should not be explained. */ | ||
|
|
@@ -42,6 +43,10 @@ private[sql] class SparkQl(conf: ParserConf = SimpleParserConf()) extends Cataly | |
| getClauses(Seq("TOK_QUERY", "FORMATTED", "EXTENDED"), explainArgs) | ||
| ExplainCommand(nodeToPlan(query), extended = extended.isDefined) | ||
|
|
||
| case Token("TOK_REFRESHTABLE", nameParts :: Nil) => | ||
| val tableIdent = extractTableIdent(nameParts) | ||
| RefreshTable(tableIdent) | ||
|
|
||
| case Token("TOK_DESCTABLE", describeArgs) => | ||
| // Reference: https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL | ||
| val Some(tableType) :: formatted :: extended :: pretty :: Nil = | ||
|
|
@@ -52,26 +57,30 @@ private[sql] class SparkQl(conf: ParserConf = SimpleParserConf()) extends Cataly | |
| nodeToDescribeFallback(node) | ||
| } else { | ||
| tableType match { | ||
| case Token("TOK_TABTYPE", Token("TOK_TABNAME", nameParts :: Nil) :: Nil) => | ||
| case Token("TOK_TABTYPE", Token("TOK_TABNAME", nameParts) :: Nil) => | ||
| nameParts match { | ||
| case Token(".", dbName :: tableName :: Nil) => | ||
| case Token(dbName, _) :: Token(tableName, _) :: Nil => | ||
| // It is describing a table with the format like "describe db.table". | ||
| // TODO: Actually, a user may mean tableName.columnName. Need to resolve this | ||
| // issue. | ||
| val tableIdent = extractTableIdent(nameParts) | ||
| val tableIdent = TableIdentifier( | ||
| cleanIdentifier(tableName), Some(cleanIdentifier(dbName))) | ||
| datasources.DescribeCommand( | ||
| UnresolvedRelation(tableIdent, None), isExtended = extended.isDefined) | ||
| case Token(".", dbName :: tableName :: colName :: Nil) => | ||
| case Token(dbName, _) :: Token(tableName, _) :: Token(colName, _) :: Nil => | ||
| // It is describing a column with the format like "describe db.table column". | ||
| nodeToDescribeFallback(node) | ||
| case tableName => | ||
| case tableName :: Nil => | ||
| // It is describing a table with the format like "describe table". | ||
| datasources.DescribeCommand( | ||
| UnresolvedRelation(TableIdentifier(tableName.text), None), | ||
|
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. cleanIdentifier? |
||
| isExtended = extended.isDefined) | ||
| case _ => | ||
| nodeToDescribeFallback(node) | ||
| } | ||
| // All other cases. | ||
| case _ => nodeToDescribeFallback(node) | ||
| case _ => | ||
| nodeToDescribeFallback(node) | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why change this? You didn't touch the describe stuff in
SparkSqlParser.gright?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.
Yes. I think it is incorrect from beginning but not be tested it out because we don't reach here before. I've tested it locally. Once all three commands are migrated, we can see this passing tests.
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.
if we parse the following SQL using the parse driver
org.apache.spark.sql.catalyst.parser.ParseDriver.parsePlan("DESCRIBE EXTENDED tbl.a", null)We would end up with the following AST:
This change would pick this up, and old code didn't (I am sure I tested this though :S ). You can disable this in the DDL parser, to see if it works now.
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 we add a test for this? The Hive test suite apparently misses this one. I could also address in a different PR.
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.
Actually we have test for describe table command in HiveQuerySuite. Do we need another test?