-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-12865][SPARK-12866][SQL] Migrate SparkSQLParser/ExtendedHiveQlParser commands to new Parser #10905
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-12865][SPARK-12866][SQL] Migrate SparkSQLParser/ExtendedHiveQlParser commands to new Parser #10905
Changes from all commits
eaee5c1
ff50b52
85eb26d
7a21ea1
3a3f32c
259027d
45d537c
7e40aae
bec8628
81fa6df
5177926
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 |
|---|---|---|
|
|
@@ -167,8 +167,8 @@ intervalLiteral | |
| ((intervalConstant KW_HOUR)=> hour=intervalConstant KW_HOUR)? | ||
| ((intervalConstant KW_MINUTE)=> minute=intervalConstant KW_MINUTE)? | ||
| ((intervalConstant KW_SECOND)=> second=intervalConstant KW_SECOND)? | ||
| (millisecond=intervalConstant KW_MILLISECOND)? | ||
| (microsecond=intervalConstant KW_MICROSECOND)? | ||
| ((intervalConstant KW_MILLISECOND)=> millisecond=intervalConstant KW_MILLISECOND)? | ||
| ((intervalConstant KW_MICROSECOND)=> microsecond=intervalConstant KW_MICROSECOND)? | ||
| -> ^(TOK_INTERVAL | ||
| ^(TOK_INTERVAL_YEAR_LITERAL $year?) | ||
| ^(TOK_INTERVAL_MONTH_LITERAL $month?) | ||
|
|
@@ -505,10 +505,8 @@ identifier | |
| functionIdentifier | ||
| @init { gParent.pushMsg("function identifier", state); } | ||
| @after { gParent.popMsg(state); } | ||
| : db=identifier DOT fn=identifier | ||
| -> Identifier[$db.text + "." + $fn.text] | ||
| | | ||
| identifier | ||
| : | ||
| identifier (DOT identifier)? -> identifier+ | ||
| ; | ||
|
|
||
| principalIdentifier | ||
|
|
@@ -553,6 +551,8 @@ nonReserved | |
| | KW_SNAPSHOT | ||
| | KW_AUTOCOMMIT | ||
| | KW_ANTI | ||
| | KW_WEEK | KW_MILLISECOND | KW_MICROSECOND | ||
|
Contributor
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. This is a leftover chore from a previous PR. |
||
| | KW_CLEAR | KW_LAZY | KW_CACHE | KW_UNCACHE | KW_DFS | ||
| ; | ||
|
|
||
| //The following SQL2011 reserved keywords are used as cast function name only, but not as identifiers. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -371,6 +371,13 @@ TOK_TXN_READ_WRITE; | |
| TOK_COMMIT; | ||
| TOK_ROLLBACK; | ||
| TOK_SET_AUTOCOMMIT; | ||
| TOK_CACHETABLE; | ||
| TOK_UNCACHETABLE; | ||
| TOK_CLEARCACHE; | ||
| TOK_SETCONFIG; | ||
| TOK_DFS; | ||
| TOK_ADDFILE; | ||
| TOK_ADDJAR; | ||
| } | ||
|
|
||
|
|
||
|
|
@@ -515,6 +522,11 @@ import java.util.HashMap; | |
| xlateMap.put("KW_WEEK", "WEEK"); | ||
| xlateMap.put("KW_MILLISECOND", "MILLISECOND"); | ||
| xlateMap.put("KW_MICROSECOND", "MICROSECOND"); | ||
| xlateMap.put("KW_CLEAR", "CLEAR"); | ||
| xlateMap.put("KW_LAZY", "LAZY"); | ||
| xlateMap.put("KW_CACHE", "CACHE"); | ||
| xlateMap.put("KW_UNCACHE", "UNCACHE"); | ||
| xlateMap.put("KW_DFS", "DFS"); | ||
|
|
||
| // Operators | ||
| xlateMap.put("DOT", "."); | ||
|
|
@@ -687,8 +699,12 @@ catch (RecognitionException e) { | |
|
|
||
| // starting rule | ||
| statement | ||
| : explainStatement EOF | ||
| | execStatement EOF | ||
| : explainStatement EOF | ||
| | execStatement EOF | ||
| | KW_ADD KW_JAR -> ^(TOK_ADDJAR) | ||
|
Contributor
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. These rules do not match until EOF. We will use the raw input after we encouter such a token. |
||
| | KW_ADD KW_FILE -> ^(TOK_ADDFILE) | ||
| | KW_DFS -> ^(TOK_DFS) | ||
| | (KW_SET)=> KW_SET -> ^(TOK_SETCONFIG) | ||
| ; | ||
|
|
||
| explainStatement | ||
|
|
@@ -717,6 +733,7 @@ execStatement | |
| | deleteStatement | ||
| | updateStatement | ||
| | sqlTransactionStatement | ||
| | cacheStatement | ||
| ; | ||
|
|
||
| loadStatement | ||
|
|
@@ -1390,7 +1407,7 @@ showStatement | |
| @init { pushMsg("show statement", state); } | ||
| @after { popMsg(state); } | ||
| : KW_SHOW (KW_DATABASES|KW_SCHEMAS) (KW_LIKE showStmtIdentifier)? -> ^(TOK_SHOWDATABASES showStmtIdentifier?) | ||
| | KW_SHOW KW_TABLES ((KW_FROM|KW_IN) db_name=identifier)? (KW_LIKE showStmtIdentifier|showStmtIdentifier)? -> ^(TOK_SHOWTABLES (TOK_FROM $db_name)? showStmtIdentifier?) | ||
| | KW_SHOW KW_TABLES ((KW_FROM|KW_IN) db_name=identifier)? (KW_LIKE showStmtIdentifier|showStmtIdentifier)? -> ^(TOK_SHOWTABLES ^(TOK_FROM $db_name)? showStmtIdentifier?) | ||
| | KW_SHOW KW_COLUMNS (KW_FROM|KW_IN) tableName ((KW_FROM|KW_IN) db_name=identifier)? | ||
| -> ^(TOK_SHOWCOLUMNS tableName $db_name?) | ||
| | KW_SHOW KW_FUNCTIONS (KW_LIKE showFunctionIdentifier|showFunctionIdentifier)? -> ^(TOK_SHOWFUNCTIONS KW_LIKE? showFunctionIdentifier?) | ||
|
|
@@ -2438,12 +2455,11 @@ BEGIN user defined transaction boundaries; follows SQL 2003 standard exactly exc | |
| sqlTransactionStatement | ||
| @init { pushMsg("transaction statement", state); } | ||
| @after { popMsg(state); } | ||
| : | ||
| startTransactionStatement | ||
| | commitStatement | ||
| | rollbackStatement | ||
| | setAutoCommitStatement | ||
| ; | ||
| : startTransactionStatement | ||
| | commitStatement | ||
| | rollbackStatement | ||
| | setAutoCommitStatement | ||
| ; | ||
|
|
||
| startTransactionStatement | ||
| : | ||
|
|
@@ -2489,3 +2505,31 @@ setAutoCommitStatement | |
| /* | ||
| END user defined transaction boundaries | ||
| */ | ||
|
|
||
| /* | ||
| Table Caching statements. | ||
| */ | ||
| cacheStatement | ||
| @init { pushMsg("cache statement", state); } | ||
| @after { popMsg(state); } | ||
| : | ||
| cacheTableStatement | ||
| | uncacheTableStatement | ||
| | clearCacheStatement | ||
| ; | ||
|
|
||
| cacheTableStatement | ||
| : | ||
| KW_CACHE (lazy=KW_LAZY)? KW_TABLE identifier (KW_AS selectStatementWithCTE)? -> ^(TOK_CACHETABLE identifier $lazy? selectStatementWithCTE?) | ||
| ; | ||
|
|
||
| uncacheTableStatement | ||
| : | ||
| KW_UNCACHE KW_TABLE identifier -> ^(TOK_UNCACHETABLE identifier) | ||
| ; | ||
|
|
||
| clearCacheStatement | ||
| : | ||
| KW_CLEAR KW_CACHE -> ^(TOK_CLEARCACHE) | ||
| ; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,10 +27,10 @@ case class ASTNode( | |
| children: List[ASTNode], | ||
| stream: TokenRewriteStream) extends TreeNode[ASTNode] { | ||
| /** Cache the number of children. */ | ||
| val numChildren = children.size | ||
| val numChildren: Int = children.size | ||
|
|
||
| /** tuple used in pattern matching. */ | ||
| val pattern = Some((token.getText, children)) | ||
| val pattern: Some[(String, List[ASTNode])] = Some((token.getText, children)) | ||
|
|
||
| /** Line in which the ASTNode starts. */ | ||
| lazy val line: Int = { | ||
|
|
@@ -55,10 +55,16 @@ case class ASTNode( | |
| } | ||
|
|
||
| /** Origin of the ASTNode. */ | ||
| override val origin = Origin(Some(line), Some(positionInLine)) | ||
| override val origin: Origin = Origin(Some(line), Some(positionInLine)) | ||
|
|
||
| /** Source text. */ | ||
|
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 comment isn't super useful - can you explain a bit more what "source text" is? |
||
| lazy val source = stream.toString(startIndex, stopIndex) | ||
| lazy val source: String = stream.toString(startIndex, stopIndex) | ||
|
|
||
| /** Get the source text that remains after this token. */ | ||
|
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. would be great to briefly mention what this is used for (set?) |
||
| lazy val remainder: String = { | ||
| stream.fill() | ||
| stream.toString(stopIndex + 1, stream.size() - 1).trim() | ||
| } | ||
|
|
||
| def text: String = token.getText | ||
|
|
||
|
|
||
This file was deleted.
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.
This is a leftover chore from a previous PR.