This is an automated email from the ASF dual-hosted git repository.
ulyssesyou pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-kyuubi.git
The following commit(s) were added to refs/heads/master by this push:
new eecf074 [KYUUBI #1045] Clean up zorder .g4
eecf074 is described below
commit eecf074bf18ad75bc31a92eb74676b68b0506406
Author: ulysses-you <[email protected]>
AuthorDate: Tue Sep 7 15:36:30 2021 +0800
[KYUUBI #1045] Clean up zorder .g4
<!--
Thanks for sending a pull request!
Here are some tips for you:
1. If this is your first time, please read our contributor guidelines:
https://kyuubi.readthedocs.io/en/latest/community/contributions.html
2. If the PR is related to an issue in
https://github.com/apache/incubator-kyuubi/issues, add '[KYUUBI #XXXX]' in your
PR title, e.g., '[KYUUBI #XXXX] Your PR title ...'.
3. If the PR is unfinished, add '[WIP]' in your PR title, e.g.,
'[WIP][KYUUBI #XXXX] Your PR title ...'.
-->
### _Why are the changes needed?_
<!--
Please clarify why the changes are needed. For instance,
1. If you add a feature, you can talk about the use case of it.
2. If you fix a bug, you can clarify why it is a bug.
-->
Clean up .g4 file. Remove some grammar we donn't need
### _How was this patch tested?_
Pass CI
Closes #1045 from ulysses-you/clean-up-zorder.
Closes #1045
cf1a5cc3 [ulysses-you] eight indention
d6d7eb6e [ulysses-you] pom
8da9df92 [ulysses-you] clean up
Authored-by: ulysses-you <[email protected]>
Signed-off-by: ulysses-you <[email protected]>
---
dev/kyuubi-extension-spark-3-1/pom.xml | 2 +-
.../kyuubi/sql/zorder/ZorderSqlExtensions.g4 | 236 +++++
.../apache/kyuubi/zorder/ZorderSqlExtensions.g4 | 979 ---------------------
.../kyuubi/sql/zorder/KyuubiZorderExtension.scala | 26 -
.../zorder/ZorderSparkSqlExtensionsParser.scala | 17 +-
.../kyuubi/sql/zorder/ZorderSqlAstBuilder.scala | 53 +-
6 files changed, 260 insertions(+), 1053 deletions(-)
diff --git a/dev/kyuubi-extension-spark-3-1/pom.xml
b/dev/kyuubi-extension-spark-3-1/pom.xml
index 92a25ff..3048ec4 100644
--- a/dev/kyuubi-extension-spark-3-1/pom.xml
+++ b/dev/kyuubi-extension-spark-3-1/pom.xml
@@ -118,7 +118,7 @@
<artifactId>antlr4-maven-plugin</artifactId>
<configuration>
<visitor>true</visitor>
-
<sourceDirectory>${project.basedir}/src/main/antlr4/org/apache/kyuubi/zorder</sourceDirectory>
+
<sourceDirectory>${project.basedir}/src/main/antlr4</sourceDirectory>
</configuration>
</plugin>
</plugins>
diff --git
a/dev/kyuubi-extension-spark-3-1/src/main/antlr4/org/apache/kyuubi/sql/zorder/ZorderSqlExtensions.g4
b/dev/kyuubi-extension-spark-3-1/src/main/antlr4/org/apache/kyuubi/sql/zorder/ZorderSqlExtensions.g4
new file mode 100644
index 0000000..fbb0f5e
--- /dev/null
+++
b/dev/kyuubi-extension-spark-3-1/src/main/antlr4/org/apache/kyuubi/sql/zorder/ZorderSqlExtensions.g4
@@ -0,0 +1,236 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+grammar ZorderSqlExtensions;
+
+@members {
+ /**
+ * Verify whether current token is a valid decimal token (which contains
dot).
+ * Returns true if the character that follows the token is not a digit or
letter or underscore.
+ *
+ * For example:
+ * For char stream "2.3", "2." is not a valid decimal token, because it is
followed by digit '3'.
+ * For char stream "2.3_", "2.3" is not a valid decimal token, because it
is followed by '_'.
+ * For char stream "2.3W", "2.3" is not a valid decimal token, because it
is followed by 'W'.
+ * For char stream "12.0D 34.E2+0.12 " 12.0D is a valid decimal token
because it is followed
+ * by a space. 34.E2 is a valid decimal token because it is followed by
symbol '+'
+ * which is not a digit or letter or underscore.
+ */
+ public boolean isValidDecimal() {
+ int nextChar = _input.LA(1);
+ if (nextChar >= 'A' && nextChar <= 'Z' || nextChar >= '0' && nextChar <=
'9' ||
+ nextChar == '_') {
+ return false;
+ } else {
+ return true;
+ }
+ }
+ }
+
+tokens {
+ DELIMITER
+}
+
+singleStatement
+ : statement EOF
+ ;
+
+statement
+ : OPTIMIZE multipartIdentifier whereClause? zorderClause
#optimizeZorder
+ | .*?
#passThrough
+ ;
+
+whereClause
+ : WHERE booleanExpression
+ ;
+
+zorderClause
+ : ZORDER BY order+=multipartIdentifier (',' order+=multipartIdentifier)*
+ ;
+
+booleanExpression
+ : query
#logicalQuery
+ | left=booleanExpression operator=AND right=booleanExpression
#logicalBinary
+ | left=booleanExpression operator=OR right=booleanExpression
#logicalBinary
+ ;
+
+query
+ : '('? multipartIdentifier comparisonOperator constant ')'?
+ ;
+
+comparisonOperator
+ : EQ | NEQ | NEQJ | LT | LTE | GT | GTE | NSEQ
+ ;
+
+constant
+ : NULL #nullLiteral
+ | identifier STRING #typeConstructor
+ | number #numericLiteral
+ | booleanValue #booleanLiteral
+ | STRING+ #stringLiteral
+ ;
+
+multipartIdentifier
+ : parts+=identifier ('.' parts+=identifier)*
+ ;
+
+booleanValue
+ : TRUE | FALSE
+ ;
+
+number
+ : MINUS? DECIMAL_VALUE #decimalLiteral
+ | MINUS? INTEGER_VALUE #integerLiteral
+ | MINUS? BIGINT_LITERAL #bigIntLiteral
+ | MINUS? SMALLINT_LITERAL #smallIntLiteral
+ | MINUS? TINYINT_LITERAL #tinyIntLiteral
+ | MINUS? DOUBLE_LITERAL #doubleLiteral
+ | MINUS? BIGDECIMAL_LITERAL #bigDecimalLiteral
+ ;
+
+identifier
+ : strictIdentifier
+ ;
+
+strictIdentifier
+ : IDENTIFIER #unquotedIdentifier
+ | quotedIdentifier #quotedIdentifierAlternative
+ | nonReserved #unquotedIdentifier
+ ;
+
+quotedIdentifier
+ : BACKQUOTED_IDENTIFIER
+ ;
+
+nonReserved
+ : AND
+ | BY
+ | FALSE
+ | DATE
+ | INTERVAL
+ | OPTIMIZE
+ | OR
+ | TABLE
+ | TIMESTAMP
+ | TRUE
+ | WHERE
+ | ZORDER
+ ;
+
+AND: 'AND';
+BY: 'BY';
+FALSE: 'FALSE';
+DATE: 'DATE';
+INTERVAL: 'INTERVAL';
+NULL: 'NULL';
+OPTIMIZE: 'OPTIMIZE';
+OR: 'OR';
+TABLE: 'TABLE';
+TIMESTAMP: 'TIMESTAMP';
+TRUE: 'TRUE';
+WHERE: 'WHERE';
+ZORDER: 'ZORDER';
+
+EQ : '=' | '==';
+NSEQ: '<=>';
+NEQ : '<>';
+NEQJ: '!=';
+LT : '<';
+LTE : '<=' | '!>';
+GT : '>';
+GTE : '>=' | '!<';
+
+MINUS: '-';
+
+STRING
+ : '\'' ( ~('\''|'\\') | ('\\' .) )* '\''
+ | '"' ( ~('"'|'\\') | ('\\' .) )* '"'
+ ;
+
+BIGINT_LITERAL
+ : DIGIT+ 'L'
+ ;
+
+SMALLINT_LITERAL
+ : DIGIT+ 'S'
+ ;
+
+TINYINT_LITERAL
+ : DIGIT+ 'Y'
+ ;
+
+INTEGER_VALUE
+ : DIGIT+
+ ;
+
+DECIMAL_VALUE
+ : DIGIT+ EXPONENT
+ | DECIMAL_DIGITS EXPONENT? {isValidDecimal()}?
+ ;
+
+DOUBLE_LITERAL
+ : DIGIT+ EXPONENT? 'D'
+ | DECIMAL_DIGITS EXPONENT? 'D' {isValidDecimal()}?
+ ;
+
+BIGDECIMAL_LITERAL
+ : DIGIT+ EXPONENT? 'BD'
+ | DECIMAL_DIGITS EXPONENT? 'BD' {isValidDecimal()}?
+ ;
+
+BACKQUOTED_IDENTIFIER
+ : '`' ( ~'`' | '``' )* '`'
+ ;
+
+IDENTIFIER
+ : (LETTER | DIGIT | '_')+
+ ;
+
+fragment DECIMAL_DIGITS
+ : DIGIT+ '.' DIGIT*
+ | '.' DIGIT+
+ ;
+
+fragment EXPONENT
+ : 'E' [+-]? DIGIT+
+ ;
+
+fragment DIGIT
+ : [0-9]
+ ;
+
+fragment LETTER
+ : [A-Z]
+ ;
+
+SIMPLE_COMMENT
+ : '--' ~[\r\n]* '\r'? '\n'? -> channel(HIDDEN)
+ ;
+
+BRACKETED_COMMENT
+ : '/*' .*? '*/' -> channel(HIDDEN)
+ ;
+
+WS : [ \r\n\t]+ -> channel(HIDDEN)
+ ;
+
+// Catch-all for anything we can't recognize.
+// We use this to be able to ignore and recover all the text
+// when splitting statements with DelimiterLexer
+UNRECOGNIZED
+ : .
+ ;
diff --git
a/dev/kyuubi-extension-spark-3-1/src/main/antlr4/org/apache/kyuubi/zorder/ZorderSqlExtensions.g4
b/dev/kyuubi-extension-spark-3-1/src/main/antlr4/org/apache/kyuubi/zorder/ZorderSqlExtensions.g4
deleted file mode 100644
index 9d10522..0000000
---
a/dev/kyuubi-extension-spark-3-1/src/main/antlr4/org/apache/kyuubi/zorder/ZorderSqlExtensions.g4
+++ /dev/null
@@ -1,979 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-grammar ZorderSqlExtensions;
-
-@header { package org.apache.kyuubi.sql.zorder; }
-
-@members {
- /**
- * When false, INTERSECT is given the greater precedence over the other set
- * operations (UNION, EXCEPT and MINUS) as per the SQL standard.
- */
- public boolean legacy_setops_precedence_enbled = false;
-
- /**
- * When false, a literal with an exponent would be converted into
- * double type rather than decimal type.
- */
- public boolean legacy_exponent_literal_as_decimal_enabled = false;
-
- /**
- * Verify whether current token is a valid decimal token (which contains
dot).
- * Returns true if the character that follows the token is not a digit or
letter or underscore.
- *
- * For example:
- * For char stream "2.3", "2." is not a valid decimal token, because it is
followed by digit '3'.
- * For char stream "2.3_", "2.3" is not a valid decimal token, because it
is followed by '_'.
- * For char stream "2.3W", "2.3" is not a valid decimal token, because it
is followed by 'W'.
- * For char stream "12.0D 34.E2+0.12 " 12.0D is a valid decimal token
because it is followed
- * by a space. 34.E2 is a valid decimal token because it is followed by
symbol '+'
- * which is not a digit or letter or underscore.
- */
- public boolean isValidDecimal() {
- int nextChar = _input.LA(1);
- if (nextChar >= 'A' && nextChar <= 'Z' || nextChar >= '0' && nextChar <=
'9' ||
- nextChar == '_') {
- return false;
- } else {
- return true;
- }
- }
-
- /**
- * When true, the behavior of keywords follows ANSI SQL standard.
- */
- public boolean SQL_standard_keyword_behavior = false;
- }
-
-singleStatement
- : statement EOF
- ;
-
-statement
- : OPTIMIZE multipartIdentifier whereClause? zorderClause
#optimizeZorder
- ;
-
-whereClause
- : WHERE booleanExpression
- ;
-
-zorderClause
- : ZORDER BY order+=multipartIdentifier (',' order+=multipartIdentifier)*
- ;
-
-booleanExpression
- : query
#logicalQuery
- | left=booleanExpression operator=AND right=booleanExpression
#logicalBinary
- | left=booleanExpression operator=OR right=booleanExpression
#logicalBinary
- ;
-
-query
- : '('? multipartIdentifier comparisonOperator constant ')'?
- ;
-
-
-comparisonOperator
- : EQ | NEQ | NEQJ | LT | LTE | GT | GTE | NSEQ
- ;
-
-constant
- : NULL
#nullLiteral
- | interval
#intervalLiteral
- | identifier STRING
#typeConstructor
- | number
#numericLiteral
- | booleanValue
#booleanLiteral
- | STRING+
#stringLiteral
- ;
-
-multipartIdentifier
- : parts+=identifier ('.' parts+=identifier)*
- ;
-
-booleanValue
- : TRUE | FALSE
- ;
-
-interval
- : INTERVAL (errorCapturingMultiUnitsInterval |
errorCapturingUnitToUnitInterval)?
- ;
-
-errorCapturingMultiUnitsInterval
- : multiUnitsInterval unitToUnitInterval?
- ;
-
-multiUnitsInterval
- : (intervalValue unit+=identifier)+
- ;
-
-errorCapturingUnitToUnitInterval
- : body=unitToUnitInterval (error1=multiUnitsInterval |
error2=unitToUnitInterval)?
- ;
-
-unitToUnitInterval
- : value=intervalValue from=identifier TO to=identifier
- ;
-
-intervalValue
- : (PLUS | MINUS)? (INTEGER_VALUE | DECIMAL_VALUE)
- | STRING
- ;
-
-number
- : {!legacy_exponent_literal_as_decimal_enabled}? MINUS? EXPONENT_VALUE
#exponentLiteral
- | {!legacy_exponent_literal_as_decimal_enabled}? MINUS? DECIMAL_VALUE
#decimalLiteral
- | {legacy_exponent_literal_as_decimal_enabled}? MINUS? (EXPONENT_VALUE |
DECIMAL_VALUE) #legacyDecimalLiteral
- | MINUS? INTEGER_VALUE #integerLiteral
- | MINUS? BIGINT_LITERAL #bigIntLiteral
- | MINUS? SMALLINT_LITERAL #smallIntLiteral
- | MINUS? TINYINT_LITERAL #tinyIntLiteral
- | MINUS? DOUBLE_LITERAL #doubleLiteral
- | MINUS? BIGDECIMAL_LITERAL #bigDecimalLiteral
- ;
-
-// this rule is used for explicitly capturing wrong identifiers such as
test-table, which should actually be `test-table`
-// replace identifier with errorCapturingIdentifier where the immediate follow
symbol is not an expression, otherwise
-// valid expressions such as "a-b" can be recognized as an identifier
-errorCapturingIdentifier
- : identifier errorCapturingIdentifierExtra
- ;
-
-// extra left-factoring grammar
-errorCapturingIdentifierExtra
- : (MINUS identifier)+ #errorIdent
- | #realIdent
- ;
-
-identifier
- : strictIdentifier
- | {!SQL_standard_keyword_behavior}? strictNonReserved
- ;
-
-strictIdentifier
- : IDENTIFIER #unquotedIdentifier
- | quotedIdentifier #quotedIdentifierAlternative
- | {SQL_standard_keyword_behavior}? ansiNonReserved #unquotedIdentifier
- | {!SQL_standard_keyword_behavior}? nonReserved #unquotedIdentifier
- ;
-
-quotedIdentifier
- : BACKQUOTED_IDENTIFIER
- ;
-
-// When `SQL_standard_keyword_behavior=true`, there are 2 kinds of keywords in
Spark SQL.
-// - Reserved keywords:
-// Keywords that are reserved and can't be used as identifiers for table,
view, column,
-// function, alias, etc.
-// - Non-reserved keywords:
-// Keywords that have a special meaning only in particular contexts and
can be used as
-// identifiers in other contexts. For example, `EXPLAIN SELECT ...` is a
command, but EXPLAIN
-// can be used as identifiers in other places.
-// You can find the full keywords list by searching "Start of the keywords
list" in this file.
-// The non-reserved keywords are listed below. Keywords not in this list are
reserved keywords.
-ansiNonReserved
-//--ANSI-NON-RESERVED-START
- : ADD
- | AFTER
- | ALTER
- | ANALYZE
- | ANTI
- | ARCHIVE
- | ARRAY
- | ASC
- | AT
- | BETWEEN
- | BUCKET
- | BUCKETS
- | BY
- | CACHE
- | CASCADE
- | CHANGE
- | CLEAR
- | CLUSTER
- | CLUSTERED
- | CODEGEN
- | COLLECTION
- | COLUMNS
- | COMMENT
- | COMMIT
- | COMPACT
- | COMPACTIONS
- | COMPUTE
- | CONCATENATE
- | COST
- | CUBE
- | CURRENT
- | DATA
- | DATABASE
- | DATABASES
- | DBPROPERTIES
- | DEFINED
- | DELETE
- | DELIMITED
- | DESC
- | DESCRIBE
- | DFS
- | DIRECTORIES
- | DIRECTORY
- | DISTRIBUTE
- | DIV
- | DROP
- | ESCAPED
- | EXCHANGE
- | EXISTS
- | EXPLAIN
- | EXPORT
- | EXTENDED
- | EXTERNAL
- | EXTRACT
- | FIELDS
- | FILEFORMAT
- | FIRST
- | FOLLOWING
- | FORMAT
- | FORMATTED
- | FUNCTION
- | FUNCTIONS
- | GLOBAL
- | GROUPING
- | IF
- | IGNORE
- | IMPORT
- | INDEX
- | INDEXES
- | INPATH
- | INPUTFORMAT
- | INSERT
- | INTERVAL
- | ITEMS
- | KEYS
- | LAST
- | LATERAL
- | LAZY
- | LIKE
- | LIMIT
- | LINES
- | LIST
- | LOAD
- | LOCAL
- | LOCATION
- | LOCK
- | LOCKS
- | LOGICAL
- | MACRO
- | MAP
- | MATCHED
- | MERGE
- | MSCK
- | NAMESPACE
- | NAMESPACES
- | NO
- | NULLS
- | OF
- | OPTION
- | OPTIONS
- | OUT
- | OUTPUTFORMAT
- | OVER
- | OVERLAY
- | OVERWRITE
- | PARTITION
- | PARTITIONED
- | PARTITIONS
- | PERCENTLIT
- | PIVOT
- | PLACING
- | POSITION
- | PRECEDING
- | PRINCIPALS
- | PROPERTIES
- | PURGE
- | QUERY
- | RANGE
- | RECORDREADER
- | RECORDWRITER
- | RECOVER
- | REDUCE
- | REFRESH
- | RENAME
- | REPAIR
- | REPLACE
- | RESET
- | RESTRICT
- | REVOKE
- | RLIKE
- | ROLE
- | ROLES
- | ROLLBACK
- | ROLLUP
- | ROW
- | ROWS
- | SCHEMA
- | SEMI
- | SEPARATED
- | SERDE
- | SERDEPROPERTIES
- | SET
- | SETMINUS
- | SETS
- | SHOW
- | SKEWED
- | SORT
- | SORTED
- | START
- | STATISTICS
- | STORED
- | STRATIFY
- | STRUCT
- | SUBSTR
- | SUBSTRING
- | TABLES
- | TABLESAMPLE
- | TBLPROPERTIES
- | TEMPORARY
- | TERMINATED
- | TOUCH
- | TRANSACTION
- | TRANSACTIONS
- | TRANSFORM
- | TRIM
- | TRUE
- | TRUNCATE
- | TYPE
- | UNARCHIVE
- | UNBOUNDED
- | UNCACHE
- | UNLOCK
- | UNSET
- | UPDATE
- | USE
- | VALUES
- | VIEW
- | VIEWS
- | WINDOW
-//--ANSI-NON-RESERVED-END
- ;
-
-// When `SQL_standard_keyword_behavior=false`, there are 2 kinds of keywords
in Spark SQL.
-// - Non-reserved keywords:
-// Same definition as the one when `SQL_standard_keyword_behavior=true`.
-// - Strict-non-reserved keywords:
-// A strict version of non-reserved keywords, which can not be used as
table alias.
-// You can find the full keywords list by searching "Start of the keywords
list" in this file.
-// The strict-non-reserved keywords are listed in `strictNonReserved`.
-// The non-reserved keywords are listed in `nonReserved`.
-// These 2 together contain all the keywords.
-strictNonReserved
- : ANTI
- | CROSS
- | EXCEPT
- | FULL
- | INNER
- | INTERSECT
- | JOIN
- | LEFT
- | NATURAL
- | ON
- | RIGHT
- | SEMI
- | SETMINUS
- | UNION
- | USING
- ;
-
-nonReserved
-//--DEFAULT-NON-RESERVED-START
- : ADD
- | AFTER
- | ALL
- | ALTER
- | ANALYZE
- | AND
- | ANY
- | ARCHIVE
- | ARRAY
- | AS
- | ASC
- | AT
- | AUTHORIZATION
- | BETWEEN
- | BOTH
- | BUCKET
- | BUCKETS
- | BY
- | CACHE
- | CASCADE
- | CASE
- | CAST
- | CHANGE
- | CHECK
- | CLEAR
- | CLUSTER
- | CLUSTERED
- | CODEGEN
- | COLLATE
- | COLLECTION
- | COLUMN
- | COLUMNS
- | COMMENT
- | COMMIT
- | COMPACT
- | COMPACTIONS
- | COMPUTE
- | CONCATENATE
- | CONSTRAINT
- | COST
- | CREATE
- | CUBE
- | CURRENT
- | CURRENT_DATE
- | CURRENT_TIME
- | CURRENT_TIMESTAMP
- | CURRENT_USER
- | DATA
- | DATABASE
- | DATABASES
- | DBPROPERTIES
- | DEFINED
- | DELETE
- | DELIMITED
- | DESC
- | DESCRIBE
- | DFS
- | DIRECTORIES
- | DIRECTORY
- | DISTINCT
- | DISTRIBUTE
- | DIV
- | DROP
- | ELSE
- | END
- | ESCAPE
- | ESCAPED
- | EXCHANGE
- | EXISTS
- | EXPLAIN
- | EXPORT
- | EXTENDED
- | EXTERNAL
- | EXTRACT
- | FALSE
- | FETCH
- | FILTER
- | FIELDS
- | FILEFORMAT
- | FIRST
- | FOLLOWING
- | FOR
- | FOREIGN
- | FORMAT
- | FORMATTED
- | FROM
- | FUNCTION
- | FUNCTIONS
- | GLOBAL
- | GRANT
- | GROUP
- | GROUPING
- | HAVING
- | IF
- | IGNORE
- | IMPORT
- | IN
- | INDEX
- | INDEXES
- | INPATH
- | INPUTFORMAT
- | INSERT
- | INTERVAL
- | INTO
- | IS
- | ITEMS
- | KEYS
- | LAST
- | LATERAL
- | LAZY
- | LEADING
- | LIKE
- | LIMIT
- | LINES
- | LIST
- | LOAD
- | LOCAL
- | LOCATION
- | LOCK
- | LOCKS
- | LOGICAL
- | MACRO
- | MAP
- | MATCHED
- | MERGE
- | MSCK
- | NAMESPACE
- | NAMESPACES
- | NO
- | NOT
- | NULL
- | NULLS
- | OF
- | ONLY
- | OPTION
- | OPTIONS
- | OR
- | ORDER
- | OUT
- | OUTER
- | OUTPUTFORMAT
- | OVER
- | OVERLAPS
- | OVERLAY
- | OVERWRITE
- | PARTITION
- | PARTITIONED
- | PARTITIONS
- | PERCENTLIT
- | PIVOT
- | PLACING
- | POSITION
- | PRECEDING
- | PRIMARY
- | PRINCIPALS
- | PROPERTIES
- | PURGE
- | QUERY
- | RANGE
- | RECORDREADER
- | RECORDWRITER
- | RECOVER
- | REDUCE
- | REFERENCES
- | REFRESH
- | RENAME
- | REPAIR
- | REPLACE
- | RESET
- | RESTRICT
- | REVOKE
- | RLIKE
- | ROLE
- | ROLES
- | ROLLBACK
- | ROLLUP
- | ROW
- | ROWS
- | SCHEMA
- | SELECT
- | SEPARATED
- | SERDE
- | SERDEPROPERTIES
- | SESSION_USER
- | SET
- | SETS
- | SHOW
- | SKEWED
- | SOME
- | SORT
- | SORTED
- | START
- | STATISTICS
- | STORED
- | STRATIFY
- | STRUCT
- | SUBSTR
- | SUBSTRING
- | TABLE
- | TABLES
- | TABLESAMPLE
- | TBLPROPERTIES
- | TEMPORARY
- | TERMINATED
- | THEN
- | TO
- | TOUCH
- | TRAILING
- | TRANSACTION
- | TRANSACTIONS
- | TRANSFORM
- | TRIM
- | TRUE
- | TRUNCATE
- | TYPE
- | UNARCHIVE
- | UNBOUNDED
- | UNCACHE
- | UNIQUE
- | UNKNOWN
- | UNLOCK
- | UNSET
- | UPDATE
- | USE
- | USER
- | VALUES
- | VIEW
- | VIEWS
- | WHEN
- | WHERE
- | WINDOW
- | WITH
-//--DEFAULT-NON-RESERVED-END
- ;
-
-
-// NOTE: If you add a new token in the list below, you should update the list
of keywords
-// and reserved tag in `docs/sql-ref-ansi-compliance.md#sql-keywords`.
-
-//============================
-// Start of the keywords list
-//============================
-//--SPARK-KEYWORD-LIST-START
-ADD: 'ADD';
-AFTER: 'AFTER';
-ALL: 'ALL';
-ALTER: 'ALTER';
-ANALYZE: 'ANALYZE';
-AND: 'AND';
-ANTI: 'ANTI';
-ANY: 'ANY';
-ARCHIVE: 'ARCHIVE';
-ARRAY: 'ARRAY';
-AS: 'AS';
-ASC: 'ASC';
-AT: 'AT';
-AUTHORIZATION: 'AUTHORIZATION';
-BETWEEN: 'BETWEEN';
-BOTH: 'BOTH';
-BUCKET: 'BUCKET';
-BUCKETS: 'BUCKETS';
-BY: 'BY';
-CACHE: 'CACHE';
-CASCADE: 'CASCADE';
-CASE: 'CASE';
-CAST: 'CAST';
-CHANGE: 'CHANGE';
-CHECK: 'CHECK';
-CLEAR: 'CLEAR';
-CLUSTER: 'CLUSTER';
-CLUSTERED: 'CLUSTERED';
-CODEGEN: 'CODEGEN';
-COLLATE: 'COLLATE';
-COLLECTION: 'COLLECTION';
-COLUMN: 'COLUMN';
-COLUMNS: 'COLUMNS';
-COMMENT: 'COMMENT';
-COMMIT: 'COMMIT';
-COMPACT: 'COMPACT';
-COMPACTIONS: 'COMPACTIONS';
-COMPUTE: 'COMPUTE';
-CONCATENATE: 'CONCATENATE';
-CONSTRAINT: 'CONSTRAINT';
-COST: 'COST';
-CREATE: 'CREATE';
-CROSS: 'CROSS';
-CUBE: 'CUBE';
-CURRENT: 'CURRENT';
-CURRENT_DATE: 'CURRENT_DATE';
-CURRENT_TIME: 'CURRENT_TIME';
-CURRENT_TIMESTAMP: 'CURRENT_TIMESTAMP';
-CURRENT_USER: 'CURRENT_USER';
-DATA: 'DATA';
-DATABASE: 'DATABASE';
-DATABASES: 'DATABASES' | 'SCHEMAS';
-DBPROPERTIES: 'DBPROPERTIES';
-DEFINED: 'DEFINED';
-DELETE: 'DELETE';
-DELIMITED: 'DELIMITED';
-DESC: 'DESC';
-DESCRIBE: 'DESCRIBE';
-DFS: 'DFS';
-DIRECTORIES: 'DIRECTORIES';
-DIRECTORY: 'DIRECTORY';
-DISTINCT: 'DISTINCT';
-DISTRIBUTE: 'DISTRIBUTE';
-DIV: 'DIV';
-DROP: 'DROP';
-ELSE: 'ELSE';
-END: 'END';
-ESCAPE: 'ESCAPE';
-ESCAPED: 'ESCAPED';
-EXCEPT: 'EXCEPT';
-EXCHANGE: 'EXCHANGE';
-EXISTS: 'EXISTS';
-EXPLAIN: 'EXPLAIN';
-EXPORT: 'EXPORT';
-EXTENDED: 'EXTENDED';
-EXTERNAL: 'EXTERNAL';
-EXTRACT: 'EXTRACT';
-FALSE: 'FALSE';
-FETCH: 'FETCH';
-FIELDS: 'FIELDS';
-FILTER: 'FILTER';
-FILEFORMAT: 'FILEFORMAT';
-FIRST: 'FIRST';
-FOLLOWING: 'FOLLOWING';
-FOR: 'FOR';
-FOREIGN: 'FOREIGN';
-FORMAT: 'FORMAT';
-FORMATTED: 'FORMATTED';
-FROM: 'FROM';
-FULL: 'FULL';
-FUNCTION: 'FUNCTION';
-FUNCTIONS: 'FUNCTIONS';
-GLOBAL: 'GLOBAL';
-GRANT: 'GRANT';
-GROUP: 'GROUP';
-GROUPING: 'GROUPING';
-HAVING: 'HAVING';
-IF: 'IF';
-IGNORE: 'IGNORE';
-IMPORT: 'IMPORT';
-IN: 'IN';
-INDEX: 'INDEX';
-INDEXES: 'INDEXES';
-INNER: 'INNER';
-INPATH: 'INPATH';
-INPUTFORMAT: 'INPUTFORMAT';
-INSERT: 'INSERT';
-INTERSECT: 'INTERSECT';
-INTERVAL: 'INTERVAL';
-INTO: 'INTO';
-IS: 'IS';
-ITEMS: 'ITEMS';
-JOIN: 'JOIN';
-KEYS: 'KEYS';
-LAST: 'LAST';
-LATERAL: 'LATERAL';
-LAZY: 'LAZY';
-LEADING: 'LEADING';
-LEFT: 'LEFT';
-LIKE: 'LIKE';
-LIMIT: 'LIMIT';
-LINES: 'LINES';
-LIST: 'LIST';
-LOAD: 'LOAD';
-LOCAL: 'LOCAL';
-LOCATION: 'LOCATION';
-LOCK: 'LOCK';
-LOCKS: 'LOCKS';
-LOGICAL: 'LOGICAL';
-MACRO: 'MACRO';
-MAP: 'MAP';
-MATCHED: 'MATCHED';
-MERGE: 'MERGE';
-MSCK: 'MSCK';
-NAMESPACE: 'NAMESPACE';
-NAMESPACES: 'NAMESPACES';
-NATURAL: 'NATURAL';
-NO: 'NO';
-NOT: 'NOT' | '!';
-NULL: 'NULL';
-NULLS: 'NULLS';
-OF: 'OF';
-ON: 'ON';
-ONLY: 'ONLY';
-OPTIMIZE: 'OPTIMIZE';
-OPTION: 'OPTION';
-OPTIONS: 'OPTIONS';
-OR: 'OR';
-ORDER: 'ORDER';
-OUT: 'OUT';
-OUTER: 'OUTER';
-OUTPUTFORMAT: 'OUTPUTFORMAT';
-OVER: 'OVER';
-OVERLAPS: 'OVERLAPS';
-OVERLAY: 'OVERLAY';
-OVERWRITE: 'OVERWRITE';
-PARTITION: 'PARTITION';
-PARTITIONED: 'PARTITIONED';
-PARTITIONS: 'PARTITIONS';
-PERCENTLIT: 'PERCENT';
-PIVOT: 'PIVOT';
-PLACING: 'PLACING';
-POSITION: 'POSITION';
-PRECEDING: 'PRECEDING';
-PRIMARY: 'PRIMARY';
-PRINCIPALS: 'PRINCIPALS';
-PROPERTIES: 'PROPERTIES';
-PURGE: 'PURGE';
-QUERY: 'QUERY';
-RANGE: 'RANGE';
-RECORDREADER: 'RECORDREADER';
-RECORDWRITER: 'RECORDWRITER';
-RECOVER: 'RECOVER';
-REDUCE: 'REDUCE';
-REFERENCES: 'REFERENCES';
-REFRESH: 'REFRESH';
-RENAME: 'RENAME';
-REPAIR: 'REPAIR';
-REPLACE: 'REPLACE';
-RESET: 'RESET';
-RESTRICT: 'RESTRICT';
-REVOKE: 'REVOKE';
-RIGHT: 'RIGHT';
-RLIKE: 'RLIKE' | 'REGEXP';
-ROLE: 'ROLE';
-ROLES: 'ROLES';
-ROLLBACK: 'ROLLBACK';
-ROLLUP: 'ROLLUP';
-ROW: 'ROW';
-ROWS: 'ROWS';
-SCHEMA: 'SCHEMA';
-SELECT: 'SELECT';
-SEMI: 'SEMI';
-SEPARATED: 'SEPARATED';
-SERDE: 'SERDE';
-SERDEPROPERTIES: 'SERDEPROPERTIES';
-SESSION_USER: 'SESSION_USER';
-SET: 'SET';
-SETMINUS: 'MINUS';
-SETS: 'SETS';
-SHOW: 'SHOW';
-SKEWED: 'SKEWED';
-SOME: 'SOME';
-SORT: 'SORT';
-SORTED: 'SORTED';
-START: 'START';
-STATISTICS: 'STATISTICS';
-STORED: 'STORED';
-STRATIFY: 'STRATIFY';
-STRUCT: 'STRUCT';
-SUBSTR: 'SUBSTR';
-SUBSTRING: 'SUBSTRING';
-TABLE: 'TABLE';
-TABLES: 'TABLES';
-TABLESAMPLE: 'TABLESAMPLE';
-TBLPROPERTIES: 'TBLPROPERTIES';
-TEMPORARY: 'TEMPORARY' | 'TEMP';
-TERMINATED: 'TERMINATED';
-THEN: 'THEN';
-TO: 'TO';
-TOUCH: 'TOUCH';
-TRAILING: 'TRAILING';
-TRANSACTION: 'TRANSACTION';
-TRANSACTIONS: 'TRANSACTIONS';
-TRANSFORM: 'TRANSFORM';
-TRIM: 'TRIM';
-TRUE: 'TRUE';
-TRUNCATE: 'TRUNCATE';
-TYPE: 'TYPE';
-UNARCHIVE: 'UNARCHIVE';
-UNBOUNDED: 'UNBOUNDED';
-UNCACHE: 'UNCACHE';
-UNION: 'UNION';
-UNIQUE: 'UNIQUE';
-UNKNOWN: 'UNKNOWN';
-UNLOCK: 'UNLOCK';
-UNSET: 'UNSET';
-UPDATE: 'UPDATE';
-USE: 'USE';
-USER: 'USER';
-USING: 'USING';
-VALUES: 'VALUES';
-VIEW: 'VIEW';
-VIEWS: 'VIEWS';
-WHEN: 'WHEN';
-WHERE: 'WHERE';
-WINDOW: 'WINDOW';
-WITH: 'WITH';
-ZORDER: 'ZORDER';
-
-EQ : '=' | '==';
-NSEQ: '<=>';
-NEQ : '<>';
-NEQJ: '!=';
-LT : '<';
-LTE : '<=' | '!>';
-GT : '>';
-GTE : '>=' | '!<';
-
-PLUS: '+';
-MINUS: '-';
-ASTERISK: '*';
-SLASH: '/';
-PERCENT: '%';
-TILDE: '~';
-AMPERSAND: '&';
-PIPE: '|';
-CONCAT_PIPE: '||';
-HAT: '^';
-
-STRING
- : '\'' ( ~('\''|'\\') | ('\\' .) )* '\''
- | '"' ( ~('"'|'\\') | ('\\' .) )* '"'
- ;
-
-BIGINT_LITERAL
- : DIGIT+ 'L'
- ;
-
-SMALLINT_LITERAL
- : DIGIT+ 'S'
- ;
-
-TINYINT_LITERAL
- : DIGIT+ 'Y'
- ;
-
-INTEGER_VALUE
- : DIGIT+
- ;
-
-EXPONENT_VALUE
- : DIGIT+ EXPONENT
- | DECIMAL_DIGITS EXPONENT {isValidDecimal()}?
- ;
-
-DECIMAL_VALUE
- : DECIMAL_DIGITS {isValidDecimal()}?
- ;
-
-DOUBLE_LITERAL
- : DIGIT+ EXPONENT? 'D'
- | DECIMAL_DIGITS EXPONENT? 'D' {isValidDecimal()}?
- ;
-
-BIGDECIMAL_LITERAL
- : DIGIT+ EXPONENT? 'BD'
- | DECIMAL_DIGITS EXPONENT? 'BD' {isValidDecimal()}?
- ;
-
-BACKQUOTED_IDENTIFIER
- : '`' ( ~'`' | '``' )* '`'
- ;
-
-IDENTIFIER
- : (LETTER | DIGIT | '_')+
- ;
-
-fragment DECIMAL_DIGITS
- : DIGIT+ '.' DIGIT*
- | '.' DIGIT+
- ;
-
-fragment EXPONENT
- : 'E' [+-]? DIGIT+
- ;
-
-fragment DIGIT
- : [0-9]
- ;
-
-fragment LETTER
- : [A-Z]
- ;
-
-WS : [ \r\n\t]+ -> channel(HIDDEN)
- ;
\ No newline at end of file
diff --git
a/dev/kyuubi-extension-spark-3-1/src/main/scala/org/apache/kyuubi/sql/zorder/KyuubiZorderExtension.scala
b/dev/kyuubi-extension-spark-3-1/src/main/scala/org/apache/kyuubi/sql/zorder/KyuubiZorderExtension.scala
deleted file mode 100644
index 62effc5..0000000
---
a/dev/kyuubi-extension-spark-3-1/src/main/scala/org/apache/kyuubi/sql/zorder/KyuubiZorderExtension.scala
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.kyuubi.sql.zorder
-
-import org.apache.spark.sql.SparkSessionExtensions
-
-class KyuubiZorderExtension extends (SparkSessionExtensions => Unit) {
- override def apply(extensions: SparkSessionExtensions): Unit = {
- extensions.injectParser{ case (_, parser) => new
ZorderSparkSqlExtensionsParser(parser) }
- }
-}
diff --git
a/dev/kyuubi-extension-spark-3-1/src/main/scala/org/apache/kyuubi/sql/zorder/ZorderSparkSqlExtensionsParser.scala
b/dev/kyuubi-extension-spark-3-1/src/main/scala/org/apache/kyuubi/sql/zorder/ZorderSparkSqlExtensionsParser.scala
index 1046b53..f90cf93 100644
---
a/dev/kyuubi-extension-spark-3-1/src/main/scala/org/apache/kyuubi/sql/zorder/ZorderSparkSqlExtensionsParser.scala
+++
b/dev/kyuubi-extension-spark-3-1/src/main/scala/org/apache/kyuubi/sql/zorder/ZorderSparkSqlExtensionsParser.scala
@@ -17,8 +17,6 @@
package org.apache.kyuubi.sql.zorder
-import java.util.Locale
-
import org.antlr.v4.runtime._
import org.antlr.v4.runtime.atn.PredictionMode
import org.antlr.v4.runtime.misc.{Interval, ParseCancellationException}
@@ -33,12 +31,10 @@ import org.apache.spark.sql.types.{DataType, StructType}
class ZorderSparkSqlExtensionsParser(delegate: ParserInterface) extends
ParserInterface {
private lazy val astBuilder = new ZorderSqlAstBuilder
- override def parsePlan(sqlText: String): LogicalPlan = {
- if (isZorderCommand(sqlText)) {
- parse(sqlText) { parser =>
- astBuilder.visit(parser.singleStatement()) }.asInstanceOf[LogicalPlan]
- } else {
- delegate.parsePlan(sqlText)
+ override def parsePlan(sqlText: String): LogicalPlan = parse(sqlText) {
parser =>
+ astBuilder.visit(parser.singleStatement()) match {
+ case plan: LogicalPlan => plan
+ case _ => delegate.parsePlan(sqlText)
}
}
@@ -82,11 +78,6 @@ class ZorderSparkSqlExtensionsParser(delegate:
ParserInterface) extends ParserIn
}
}
- private def isZorderCommand(sqlText: String): Boolean = {
- val normalized =
sqlText.toLowerCase(Locale.ROOT).trim().replaceAll("\\s+", " ")
- normalized.startsWith("optimize")
- }
-
override def parseExpression(sqlText: String): Expression = {
delegate.parseExpression(sqlText)
}
diff --git
a/dev/kyuubi-extension-spark-3-1/src/main/scala/org/apache/kyuubi/sql/zorder/ZorderSqlAstBuilder.scala
b/dev/kyuubi-extension-spark-3-1/src/main/scala/org/apache/kyuubi/sql/zorder/ZorderSqlAstBuilder.scala
index dc5e4dd..022f330 100644
---
a/dev/kyuubi-extension-spark-3-1/src/main/scala/org/apache/kyuubi/sql/zorder/ZorderSqlAstBuilder.scala
+++
b/dev/kyuubi-extension-spark-3-1/src/main/scala/org/apache/kyuubi/sql/zorder/ZorderSqlAstBuilder.scala
@@ -38,7 +38,7 @@ import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.types._
import org.apache.spark.unsafe.types.UTF8String
-import
org.apache.kyuubi.sql.zorder.ZorderSqlExtensionsParser.{BigDecimalLiteralContext,
BigIntLiteralContext, BooleanLiteralContext, DecimalLiteralContext,
DoubleLiteralContext, ExponentLiteralContext, IntegerLiteralContext,
LegacyDecimalLiteralContext, LogicalBinaryContext, MultipartIdentifierContext,
NullLiteralContext, NumberContext, OptimizeZorderContext, QueryContext,
SingleStatementContext, SmallIntLiteralContext, StringLiteralContext,
TinyIntLiteralContext, TypeConstructorContext [...]
+import
org.apache.kyuubi.sql.zorder.ZorderSqlExtensionsParser.{BigDecimalLiteralContext,
BigIntLiteralContext, BooleanLiteralContext, DecimalLiteralContext,
DoubleLiteralContext, IntegerLiteralContext, LogicalBinaryContext,
MultipartIdentifierContext, NullLiteralContext, NumberContext,
OptimizeZorderContext, PassThroughContext, QueryContext,
SingleStatementContext, SmallIntLiteralContext, StringLiteralContext,
TinyIntLiteralContext, TypeConstructorContext, ZorderClauseContext}
class ZorderSqlAstBuilder extends ZorderSqlExtensionsBaseVisitor[AnyRef] {
/**
@@ -55,6 +55,8 @@ class ZorderSqlAstBuilder extends
ZorderSqlExtensionsBaseVisitor[AnyRef] {
visit(ctx.statement()).asInstanceOf[LogicalPlan]
}
+ override def visitPassThrough(ctx: PassThroughContext): LogicalPlan = null
+
override def visitOptimizeZorder(ctx: OptimizeZorderContext):
OptimizeZorderCommand = withOrigin(ctx) {
val tableIdent = multiPart(ctx.multipartIdentifier())
@@ -225,40 +227,24 @@ class ZorderSqlAstBuilder extends
ZorderSqlExtensionsBaseVisitor[AnyRef] {
Literal(BigDecimal(ctx.getText).underlying())
}
- /**
- * Create a decimal literal for a regular decimal number or a scientific
decimal number.
- */
- override def visitLegacyDecimalLiteral(ctx: LegacyDecimalLiteralContext):
- Literal = withOrigin(ctx) {
- Literal(BigDecimal(ctx.getText).underlying())
- }
-
- /**
- * Create a double literal for number with an exponent, e.g. 1E-30
- */
- override def visitExponentLiteral(ctx: ExponentLiteralContext): Literal = {
- numericLiteral(ctx, ctx.getText, /* exponent values don't have a suffix */
- Double.MinValue, Double.MaxValue, DoubleType.simpleString)(_.toDouble)
- }
-
/** Create a numeric literal expression. */
- private def numericLiteral(ctx: NumberContext,
- rawStrippedQualifier: String,
- minValue: BigDecimal,
- maxValue: BigDecimal,
- typeName: String)(converter: String => Any):
- Literal = withOrigin(ctx) {
- try {
- val rawBigDecimal = BigDecimal(rawStrippedQualifier)
- if (rawBigDecimal < minValue || rawBigDecimal > maxValue) {
- throw new ParseException(s"Numeric literal ${rawStrippedQualifier}
does not " +
- s"fit in range [${minValue}, ${maxValue}] for type ${typeName}",
ctx)
- }
- Literal(converter(rawStrippedQualifier))
- } catch {
- case e: NumberFormatException =>
- throw new ParseException(e.getMessage, ctx)
+ private def numericLiteral(
+ ctx: NumberContext,
+ rawStrippedQualifier: String,
+ minValue: BigDecimal,
+ maxValue: BigDecimal,
+ typeName: String)(converter: String => Any): Literal = withOrigin(ctx) {
+ try {
+ val rawBigDecimal = BigDecimal(rawStrippedQualifier)
+ if (rawBigDecimal < minValue || rawBigDecimal > maxValue) {
+ throw new ParseException(s"Numeric literal ${rawStrippedQualifier}
does not " +
+ s"fit in range [${minValue}, ${maxValue}] for type ${typeName}", ctx)
}
+ Literal(converter(rawStrippedQualifier))
+ } catch {
+ case e: NumberFormatException =>
+ throw new ParseException(e.getMessage, ctx)
+ }
}
/**
@@ -342,5 +328,4 @@ class ZorderSqlAstBuilder extends
ZorderSqlExtensionsBaseVisitor[AnyRef] {
private def typedVisit[T](ctx: ParseTree): T = {
ctx.accept(this).asInstanceOf[T]
}
-
}