feat: support impala (#184)
* feat(impala): add impala sqlLexer * feat(impala): add impala grammar * feat(impala): add alter table sql * feat(impala): update alter table sql * feat(impala): add alter db sql * feat(impala): add alter view sql * feat(impala): add compute stats/comment statement and update partition_desc for alter table * feat(impala): add drop statement sql * feat(impala): add revoke and grant sql * feat(impala): add create db/function/role/view sql * feat(impala): add describe/explain/invalidata_metadata/load_data sql * feat(impala): add refresh/set/shutdown sql * feat(impala): add truncate_table/use/values sql * fix(impala): update shutdown and invaliddate_metadata * feat(impala): add show/update/upsert sql * feat(impala): add create/insert sql * feat(impala): add select and delete sql * feat(impala): add impala tokens and fix todo * feat(impala): update impalaparser and some test unit * feat(impala): add syntax suggestion * feat(impala): add syntax suggestion * feat(impala): update test unit * feat(impala): remove reference * fix(impala): add statement for sqlname and collect tableName * fix(impala): fix syntax suggestion unit test * fix(impala): update syntax suggestion and collect column * feat(impala): add collect column create
This commit is contained in:
parent
db05cb3e4f
commit
e203f1a48a
@ -8,7 +8,7 @@ const chalk = require('chalk');
|
|||||||
const grammarsPath = path.resolve(__dirname, '../src/grammar');
|
const grammarsPath = path.resolve(__dirname, '../src/grammar');
|
||||||
const outputPath = path.resolve(__dirname, '../src/lib');
|
const outputPath = path.resolve(__dirname, '../src/lib');
|
||||||
|
|
||||||
const languageEntries = fs.readdirSync(grammarsPath).filter((item) => item !== 'impala'); // impala is not support yet.
|
const languageEntries = fs.readdirSync(grammarsPath);
|
||||||
|
|
||||||
const baseCmd = 'antlr4ts -visitor -listener -Xexact-output-dir -o';
|
const baseCmd = 'antlr4ts -visitor -listener -Xexact-output-dir -o';
|
||||||
|
|
||||||
|
366
src/grammar/impala/ImpalaSqlLexer.g4
Normal file
366
src/grammar/impala/ImpalaSqlLexer.g4
Normal file
@ -0,0 +1,366 @@
|
|||||||
|
/*
|
||||||
|
Apache Impala grammar.
|
||||||
|
The MIT License (MIT).
|
||||||
|
Copyright (c) 2023, Michał Lorek.
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
lexer grammar ImpalaSqlLexer;
|
||||||
|
|
||||||
|
options { caseInsensitive = true; }
|
||||||
|
|
||||||
|
KW_ADD : 'ADD';
|
||||||
|
KW_ALL : 'ALL';
|
||||||
|
KW_ANALYTIC : 'ANALYTIC';
|
||||||
|
KW_ALTER : 'ALTER';
|
||||||
|
KW_AND : 'AND';
|
||||||
|
KW_ANY : 'ANY';
|
||||||
|
KW_ANTI : 'ANTI';
|
||||||
|
KW_ARRAY : 'ARRAY';
|
||||||
|
KW_AS : 'AS';
|
||||||
|
KW_ASC : 'ASC';
|
||||||
|
KW_AT : 'AT';
|
||||||
|
KW_AGGREGATE : 'AGGREGATE';
|
||||||
|
KW_AUTHORIZATION : 'AUTHORIZATION';
|
||||||
|
KW_BERNOULLI : 'BERNOULLI';
|
||||||
|
KW_BETWEEN : 'BETWEEN';
|
||||||
|
KW_BLOCK_SIZE : 'BLOCK_SIZE';
|
||||||
|
KW_PARTITIONED : 'PARTITIONED';
|
||||||
|
KW_PREPARE_FN : 'PREPARE_FN';
|
||||||
|
KW_EXTERNAL : 'EXTERNAL';
|
||||||
|
KW_CLOSEFN : 'CLOSEFN';
|
||||||
|
KW_SORT : 'SORT';
|
||||||
|
KW_PURGE : 'PURGE';
|
||||||
|
KW_STORED : 'STORED';
|
||||||
|
KW_LOCATION : 'LOCATION';
|
||||||
|
KW_TBLPROPERTIES : 'TBLPROPERTIES';
|
||||||
|
KW_BY : 'BY';
|
||||||
|
KW_CASCADE : 'CASCADE';
|
||||||
|
KW_CASE : 'CASE';
|
||||||
|
KW_CAST : 'CAST';
|
||||||
|
KW_CACHED : 'CACHED';
|
||||||
|
KW_CHANGE : 'CHANGE';
|
||||||
|
KW_COLUMN : 'COLUMN';
|
||||||
|
KW_COLUMNS : 'COLUMNS';
|
||||||
|
KW_COMMENT : 'COMMENT';
|
||||||
|
KW_COMPRESSION : 'COMPRESSION';
|
||||||
|
KW_COMPUTE : 'COMPUTE';
|
||||||
|
KW_CREATE : 'CREATE';
|
||||||
|
KW_CROSS : 'CROSS';
|
||||||
|
KW_CURRENT : 'CURRENT';
|
||||||
|
KW_CURRENT_DATE : 'CURRENT_DATE';
|
||||||
|
KW_CURRENT_PATH : 'CURRENT_PATH';
|
||||||
|
KW_CURRENT_TIME : 'CURRENT_TIME';
|
||||||
|
KW_CURRENT_TIMESTAMP : 'CURRENT_TIMESTAMP';
|
||||||
|
KW_CURRENT_USER : 'CURRENT_USER';
|
||||||
|
KW_DATA : 'DATA';
|
||||||
|
KW_DATABASE : 'DATABASE';
|
||||||
|
KW_DATABASES : 'DATABASES';
|
||||||
|
KW_DAY : 'DAY';
|
||||||
|
KW_DAYS : 'DAYS';
|
||||||
|
KW_DELETE : 'DELETE';
|
||||||
|
KW_DEFAULT : 'DEFAULT';
|
||||||
|
KW_DELIMITED : 'DELIMITED';
|
||||||
|
KW_DISABLE : 'DISABLE';
|
||||||
|
KW_UPDATE : 'UPDATE';
|
||||||
|
KW_DESC : 'DESC';
|
||||||
|
KW_DESCRIBE : 'DESCRIBE';
|
||||||
|
KW_DISTINCT : 'DISTINCT';
|
||||||
|
KW_DROP : 'DROP';
|
||||||
|
KW_ELSE : 'ELSE';
|
||||||
|
KW_ENCODING : 'ENCODING';
|
||||||
|
KW_END : 'END';
|
||||||
|
KW_ESCAPE : 'ESCAPE';
|
||||||
|
KW_ESCAPED : 'ESCAPED';
|
||||||
|
KW_EXCEPT : 'EXCEPT';
|
||||||
|
KW_EXCLUDING : 'EXCLUDING';
|
||||||
|
KW_EXISTS : 'EXISTS';
|
||||||
|
KW_EXPLAIN : 'EXPLAIN';
|
||||||
|
KW_EXTRACT : 'EXTRACT';
|
||||||
|
KW_EXTENDED : 'EXTENDED';
|
||||||
|
KW_FALSE : 'FALSE';
|
||||||
|
KW_FIELDS : 'FIELDS';
|
||||||
|
KW_FILEFORMAT : 'FILEFORMAT';
|
||||||
|
KW_FILES : 'FILES';
|
||||||
|
KW_FILTER : 'FILTER';
|
||||||
|
KW_FIRST : 'FIRST';
|
||||||
|
KW_FINALIZE_FN : 'FINALIZE_FN';
|
||||||
|
KW_FOLLOWING : 'FOLLOWING';
|
||||||
|
KW_FOR : 'FOR';
|
||||||
|
KW_FORMAT : 'FORMAT';
|
||||||
|
KW_FORMATTED : 'FORMATTED';
|
||||||
|
KW_FOREIGN : 'FOREIGN';
|
||||||
|
KW_FROM : 'FROM';
|
||||||
|
KW_FULL : 'FULL';
|
||||||
|
KW_FUNCTION : 'FUNCTION';
|
||||||
|
KW_FUNCTIONS : 'FUNCTIONS';
|
||||||
|
KW_GRANT : 'GRANT';
|
||||||
|
KW_GROUP : 'GROUP';
|
||||||
|
KW_GROUPING : 'GROUPING';
|
||||||
|
KW_HASH : 'HASH';
|
||||||
|
KW_HAVING : 'HAVING';
|
||||||
|
KW_HOUR : 'HOUR';
|
||||||
|
KW_HOURS : 'HOURS';
|
||||||
|
KW_IF : 'IF';
|
||||||
|
KW_IN : 'IN';
|
||||||
|
KW_INCLUDING : 'INCLUDING';
|
||||||
|
KW_INCREMENTAL : 'INCREMENTAL';
|
||||||
|
KW_INNER : 'INNER';
|
||||||
|
KW_INPATH : 'INPATH';
|
||||||
|
KW_INSERT : 'INSERT';
|
||||||
|
KW_INTERSECT : 'INTERSECT';
|
||||||
|
KW_INTERVAL : 'INTERVAL';
|
||||||
|
KW_INTERMEDIATE : 'INTERMEDIATE';
|
||||||
|
KW_INTO : 'INTO';
|
||||||
|
KW_INIT_FN : 'INIT_FN';
|
||||||
|
KW_INVALIDATE : 'INVALIDATE';
|
||||||
|
KW_IS : 'IS';
|
||||||
|
KW_JOIN : 'JOIN';
|
||||||
|
KW_KEY : 'KEY';
|
||||||
|
KW_KUDU : 'KUDU';
|
||||||
|
KW_LAST : 'LAST';
|
||||||
|
KW_LATERAL : 'LATERAL';
|
||||||
|
KW_LEFT : 'LEFT';
|
||||||
|
KW_LIKE : 'LIKE';
|
||||||
|
KW_LIMIT : 'LIMIT';
|
||||||
|
KW_LINES : 'LINES';
|
||||||
|
KW_LOAD : 'LOAD';
|
||||||
|
KW_LOCALTIME : 'LOCALTIME';
|
||||||
|
KW_LOCALTIMESTAMP : 'LOCALTIMESTAMP';
|
||||||
|
KW_METADATA : 'METADATA';
|
||||||
|
KW_MAP : 'MAP';
|
||||||
|
KW_MINUTE : 'MINUTE';
|
||||||
|
KW_MINUTES : 'MINUTES';
|
||||||
|
KW_MONTH : 'MONTH';
|
||||||
|
KW_MONTHS : 'MONTHS';
|
||||||
|
KW_MERGE_FN : 'MERGE_FN';
|
||||||
|
KW_NFC : 'NFC';
|
||||||
|
KW_NFD : 'NFD';
|
||||||
|
KW_NFKC : 'NFKC';
|
||||||
|
KW_NFKD : 'NFKD';
|
||||||
|
KW_NORMALIZE : 'NORMALIZE';
|
||||||
|
KW_NOT : 'NOT';
|
||||||
|
KW_NULL : 'NULL';
|
||||||
|
KW_NULLS : 'NULLS';
|
||||||
|
KW_OFFSET : 'OFFSET';
|
||||||
|
KW_ON : 'ON';
|
||||||
|
KW_OPTION : 'OPTION';
|
||||||
|
KW_OR : 'OR';
|
||||||
|
KW_ORDER : 'ORDER';
|
||||||
|
KW_ORDINALITY : 'ORDINALITY';
|
||||||
|
KW_OUTER : 'OUTER';
|
||||||
|
KW_OWNER : 'OWNER';
|
||||||
|
KW_OVER : 'OVER';
|
||||||
|
KW_OVERWRITE : 'OVERWRITE';
|
||||||
|
KW_PARTITION : 'PARTITION';
|
||||||
|
KW_PARTITIONS : 'PARTITIONS';
|
||||||
|
KW_PARQUET : 'PARQUET';
|
||||||
|
KW_POSITION : 'POSITION';
|
||||||
|
KW_PRECEDING : 'PRECEDING';
|
||||||
|
KW_PRIMARY : 'PRIMARY';
|
||||||
|
KW_REPLICATION : 'REPLICATION';
|
||||||
|
KW_PRIVILEGES : 'PRIVILEGES';
|
||||||
|
KW_PROPERTIES : 'PROPERTIES';
|
||||||
|
KW_RANGE : 'RANGE';
|
||||||
|
KW_RECOVER : 'RECOVER';
|
||||||
|
KW_RENAME : 'RENAME';
|
||||||
|
KW_REPEATABLE : 'REPEATABLE';
|
||||||
|
KW_REPLACE : 'REPLACE';
|
||||||
|
KW_RESTRICT : 'RESTRICT';
|
||||||
|
KW_RETURNS : 'RETURNS';
|
||||||
|
KW_REVOKE : 'REVOKE';
|
||||||
|
KW_REFRESH : 'REFRESH';
|
||||||
|
KW_REGEXP : 'REGEXP';
|
||||||
|
KW_RLIKE : 'RLIKE';
|
||||||
|
KW_RIGHT : 'RIGHT';
|
||||||
|
KW_ROLE : 'ROLE';
|
||||||
|
KW_ROLES : 'ROLES';
|
||||||
|
KW_ROW : 'ROW';
|
||||||
|
KW_ROWS : 'ROWS';
|
||||||
|
KW_SCHEMA : 'SCHEMA';
|
||||||
|
KW_SCHEMAS : 'SCHEMAS';
|
||||||
|
KW_SECOND : 'SECOND';
|
||||||
|
KW_SECONDS : 'SECONDS';
|
||||||
|
KW_SELECT : 'SELECT';
|
||||||
|
KW_SERDEPROPERTIES : 'SERDEPROPERTIES';
|
||||||
|
KW_SET : 'SET';
|
||||||
|
KW_SEMI : 'SEMI';
|
||||||
|
KW_SERVER : 'SERVER';
|
||||||
|
KW_SHOW : 'SHOW';
|
||||||
|
KW_SHUTDOWN : 'SHUTDOWN';
|
||||||
|
KW_SOME : 'SOME';
|
||||||
|
KW_STATS : 'STATS';
|
||||||
|
KW_STRUCT : 'STRUCT';
|
||||||
|
KW_STRAIGHT_JOIN : 'STRAIGHT_JOIN';
|
||||||
|
KW_SUBSTRING : 'SUBSTRING';
|
||||||
|
KW_SYSTEM : 'SYSTEM';
|
||||||
|
KW_SYMBOL : 'SYMBOL';
|
||||||
|
KW_SERIALIZE_FN : 'SERIALIZE_FN';
|
||||||
|
KW_TABLE : 'TABLE';
|
||||||
|
KW_TABLES : 'TABLES';
|
||||||
|
KW_TABLESAMPLE : 'TABLESAMPLE';
|
||||||
|
KW_TERMINATED : 'TERMINATED ';
|
||||||
|
KW_THEN : 'THEN';
|
||||||
|
KW_TO : 'TO';
|
||||||
|
KW_TRUE : 'TRUE';
|
||||||
|
KW_TRY_CAST : 'TRY_CAST';
|
||||||
|
KW_TRUNCATE : 'TRUNCATE';
|
||||||
|
KW_UNCACHED : 'UNCACHED';
|
||||||
|
KW_UESCAPE : 'UESCAPE';
|
||||||
|
KW_UNBOUNDED : 'UNBOUNDED';
|
||||||
|
KW_UNION : 'UNION';
|
||||||
|
KW_UNNEST : 'UNNEST';
|
||||||
|
KW_UNSET : 'UNSET';
|
||||||
|
KW_USE : 'USE';
|
||||||
|
KW_USER : 'USER';
|
||||||
|
KW_USING : 'USING';
|
||||||
|
KW_UPDATE_FN : 'UPDATE_FN';
|
||||||
|
KW_UPSERT : 'UPSERT';
|
||||||
|
KW_URI : 'URI';
|
||||||
|
KW_VALUE : 'VALUE';
|
||||||
|
KW_VALUES : 'VALUES';
|
||||||
|
KW_VIEW : 'VIEW';
|
||||||
|
KW_VIEWS : 'VIEWS';
|
||||||
|
KW_WHEN : 'WHEN';
|
||||||
|
KW_WHERE : 'WHERE';
|
||||||
|
KW_WITH : 'WITH';
|
||||||
|
KW_YEAR : 'YEAR';
|
||||||
|
KW_YEARS : 'YEARS';
|
||||||
|
KW_TEXTFILE : 'TEXTFILE';
|
||||||
|
KW_ORC : 'ORC';
|
||||||
|
KW_AVRO : 'AVRO';
|
||||||
|
KW_SEQUENCEFILE : 'SEQUENCEFILE';
|
||||||
|
KW_RCFILE : 'RCFILE';
|
||||||
|
KW_REFERENCES : 'REFERENCES';
|
||||||
|
KW_NOVALIDATE : 'NOVALIDATE';
|
||||||
|
KW_RELY : 'RELY';
|
||||||
|
|
||||||
|
STATS_NUMDVS : '\'NUMDVS\'';
|
||||||
|
STATS_NUMNULLS : '\'NUMNULLS\'';
|
||||||
|
STATS_AVGSIZE : '\'AVGSIZE\'';
|
||||||
|
STATS_MAXSIZE : '\'MAXSIZE\'';
|
||||||
|
|
||||||
|
EQ : '=';
|
||||||
|
NEQ : '<>' | '!=';
|
||||||
|
LT : '<';
|
||||||
|
LTE : '<=';
|
||||||
|
GT : '>';
|
||||||
|
GTE : '>=';
|
||||||
|
PLUS: '+';
|
||||||
|
MINUS: '-';
|
||||||
|
ASTERISK: '*';
|
||||||
|
SLASH: '/';
|
||||||
|
PERCENT: '%';
|
||||||
|
CONCAT: '||';
|
||||||
|
|
||||||
|
DOT : '.';
|
||||||
|
SEMICOLON: ';';
|
||||||
|
COMMA: ',';
|
||||||
|
COLON : ':' ;
|
||||||
|
LPAREN : '(' ;
|
||||||
|
RPAREN : ')' ;
|
||||||
|
LSQUARE : '[' ;
|
||||||
|
RSQUARE : ']' ;
|
||||||
|
LCURLY : '{';
|
||||||
|
RCURLY : '}';
|
||||||
|
|
||||||
|
BITWISEOR : '|';
|
||||||
|
QUESTION : '?';
|
||||||
|
|
||||||
|
RIGHT_ARROW : '->';
|
||||||
|
|
||||||
|
STRING
|
||||||
|
: '\'' ( ~'\'' | '\'\'' )* '\''
|
||||||
|
| '"' ( ~'"' | '""' )* '"'
|
||||||
|
;
|
||||||
|
|
||||||
|
UNICODE_STRING
|
||||||
|
: 'U&\'' ( ~'\'' | '\'\'' )* '\''
|
||||||
|
;
|
||||||
|
|
||||||
|
// Note: we allow any character inside the binary literal and validate
|
||||||
|
// its a correct literal when the AST is being constructed. This
|
||||||
|
// allows us to provide more meaningful error messages to the user
|
||||||
|
BINARY_LITERAL
|
||||||
|
: 'X\'' (~'\'')* '\''
|
||||||
|
;
|
||||||
|
|
||||||
|
INTEGER_VALUE
|
||||||
|
: DIGIT+
|
||||||
|
;
|
||||||
|
|
||||||
|
DECIMAL_VALUE
|
||||||
|
: DIGIT+ '.' DIGIT*
|
||||||
|
| '.' DIGIT+
|
||||||
|
;
|
||||||
|
|
||||||
|
DOUBLE_VALUE
|
||||||
|
: DIGIT+ ('.' DIGIT*)? EXPONENT
|
||||||
|
| '.' DIGIT+ EXPONENT
|
||||||
|
;
|
||||||
|
|
||||||
|
IDENTIFIER
|
||||||
|
: (LETTER | '_') (LETTER | DIGIT | '_' | '@' | ':')*
|
||||||
|
;
|
||||||
|
|
||||||
|
DIGIT_IDENTIFIER
|
||||||
|
: DIGIT (LETTER | DIGIT | '_' | '@' | ':')+
|
||||||
|
;
|
||||||
|
|
||||||
|
QUOTED_IDENTIFIER
|
||||||
|
: '"' ( ~'"' | '""' )* '"'
|
||||||
|
;
|
||||||
|
|
||||||
|
BACKQUOTED_IDENTIFIER
|
||||||
|
: '`' ( ~'`' | '``' )* '`'
|
||||||
|
;
|
||||||
|
|
||||||
|
TIME_WITH_TIME_ZONE
|
||||||
|
: 'TIME' WS 'WITH' WS 'TIME' WS 'ZONE'
|
||||||
|
;
|
||||||
|
|
||||||
|
TIMESTAMP_WITH_TIME_ZONE
|
||||||
|
: 'TIMESTAMP' WS 'WITH' WS 'TIME' WS 'ZONE'
|
||||||
|
;
|
||||||
|
|
||||||
|
DOUBLE_PRECISION
|
||||||
|
: 'DOUBLE' WS 'PRECISION'
|
||||||
|
;
|
||||||
|
|
||||||
|
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)
|
||||||
|
;
|
946
src/grammar/impala/ImpalaSqlParser.g4
Normal file
946
src/grammar/impala/ImpalaSqlParser.g4
Normal file
@ -0,0 +1,946 @@
|
|||||||
|
/*
|
||||||
|
* Licensed 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
parser grammar ImpalaSqlParser;
|
||||||
|
|
||||||
|
options
|
||||||
|
{
|
||||||
|
tokenVocab=ImpalaSqlLexer;
|
||||||
|
}
|
||||||
|
|
||||||
|
program : (statement SEMICOLON?)* EOF;
|
||||||
|
|
||||||
|
statement
|
||||||
|
: queryStatement
|
||||||
|
| useStatement
|
||||||
|
| createStatement
|
||||||
|
| alterStatement
|
||||||
|
| truncateTableStatement
|
||||||
|
| describeStatement
|
||||||
|
| computeStatement
|
||||||
|
| dropStatement
|
||||||
|
| grantStatement
|
||||||
|
| revokeStatement
|
||||||
|
| insertStatement
|
||||||
|
| deleteStatement
|
||||||
|
| updateStatement
|
||||||
|
| upsertStatement
|
||||||
|
| showStatement
|
||||||
|
| addCommentStatement
|
||||||
|
| explainStatement
|
||||||
|
| setStatement
|
||||||
|
| shutdownStatement
|
||||||
|
| invalidateMetaStatement
|
||||||
|
| loadDataStatement
|
||||||
|
| refreshStatement
|
||||||
|
;
|
||||||
|
|
||||||
|
useStatement: KW_USE databaseNamePath;
|
||||||
|
|
||||||
|
createStatement
|
||||||
|
: createSchema
|
||||||
|
| createRole
|
||||||
|
| createAggregateFunction
|
||||||
|
| createFunction
|
||||||
|
| createView
|
||||||
|
| createKuduTableAsSelect
|
||||||
|
| createTableLike
|
||||||
|
| createTableSelect
|
||||||
|
;
|
||||||
|
|
||||||
|
createTableSelect
|
||||||
|
: KW_CREATE KW_EXTERNAL? KW_TABLE ifNotExists? tableNameCreate
|
||||||
|
(LPAREN columnDefinition (COMMA columnDefinition)* (COMMA constraintSpecification)? RPAREN)?
|
||||||
|
(KW_PARTITIONED KW_BY (partitionedBy | createColumnAliases) )?
|
||||||
|
createCommonItem
|
||||||
|
(KW_AS queryStatement)?
|
||||||
|
;
|
||||||
|
|
||||||
|
createTableLike
|
||||||
|
: KW_CREATE KW_EXTERNAL? KW_TABLE ifNotExists? tableNameCreate
|
||||||
|
KW_LIKE (tableNamePath | KW_PARQUET parquet=stringLiteral)
|
||||||
|
(KW_PARTITIONED KW_BY partitionedBy)?
|
||||||
|
createCommonItem
|
||||||
|
;
|
||||||
|
|
||||||
|
createKuduTableAsSelect
|
||||||
|
: KW_CREATE KW_EXTERNAL? KW_TABLE ifNotExists? tableNameCreate
|
||||||
|
(LPAREN kuduTableElement (COMMA kuduTableElement)* (COMMA KW_PRIMARY KW_KEY columnAliases)? RPAREN)?
|
||||||
|
(KW_PRIMARY KW_KEY columnAliases?)?
|
||||||
|
(KW_PARTITION KW_BY kuduPartitionClause)?
|
||||||
|
(KW_COMMENT stringLiteral)?
|
||||||
|
KW_STORED KW_AS KW_KUDU
|
||||||
|
(KW_TBLPROPERTIES tblProp=properties)?
|
||||||
|
(KW_AS queryStatement)?
|
||||||
|
;
|
||||||
|
|
||||||
|
createView: KW_CREATE KW_VIEW ifNotExists? viewNameCreate viewColumns? (KW_COMMENT stringLiteral)? (KW_TBLPROPERTIES tblProp=properties)? KW_AS queryStatement;
|
||||||
|
|
||||||
|
createSchema:
|
||||||
|
KW_CREATE (KW_SCHEMA | KW_DATABASE) ifNotExists? databaseNameCreate
|
||||||
|
(KW_COMMENT comment=stringLiteral)? (KW_LOCATION location=stringLiteral)?
|
||||||
|
;
|
||||||
|
|
||||||
|
createRole: KW_CREATE KW_ROLE name=identifier;
|
||||||
|
|
||||||
|
createAggregateFunction
|
||||||
|
: KW_CREATE KW_AGGREGATE? KW_FUNCTION ifNotExists? functionNameCreate (LPAREN(type (COMMA type)*)? RPAREN)?
|
||||||
|
KW_RETURNS type
|
||||||
|
(KW_INTERMEDIATE type)?
|
||||||
|
KW_LOCATION STRING
|
||||||
|
(KW_INIT_FN EQ STRING)?
|
||||||
|
KW_UPDATE_FN EQ STRING
|
||||||
|
KW_MERGE_FN EQ STRING
|
||||||
|
(KW_PREPARE_FN EQ STRING)?
|
||||||
|
(KW_CLOSEFN EQ STRING)?
|
||||||
|
(KW_SERIALIZE_FN EQ STRING)?
|
||||||
|
(KW_FINALIZE_FN EQ STRING)?
|
||||||
|
;
|
||||||
|
|
||||||
|
createFunction
|
||||||
|
: KW_CREATE KW_FUNCTION ifNotExists? functionNameCreate (LPAREN(type (COMMA type)*)? RPAREN)?
|
||||||
|
(KW_RETURNS type)?
|
||||||
|
KW_LOCATION STRING
|
||||||
|
KW_SYMBOL EQ symbol=stringLiteral
|
||||||
|
;
|
||||||
|
|
||||||
|
alterStatement
|
||||||
|
: alterDatabase
|
||||||
|
| alterUnSetOrSetViewTblproperties
|
||||||
|
| renameTable
|
||||||
|
| alterViewOwner
|
||||||
|
| alterView
|
||||||
|
| renameView
|
||||||
|
| dropPartitionByRangeOrValue
|
||||||
|
| alterFormat
|
||||||
|
| recoverPartitions
|
||||||
|
| addPartitionByRangeOrValue
|
||||||
|
| alterTableNonKuduOrKuduOnly
|
||||||
|
| addSingleColumn
|
||||||
|
| replaceOrAddColumns
|
||||||
|
| changeColumnDefine
|
||||||
|
| alterStatsKey
|
||||||
|
| alterPartitionCache
|
||||||
|
| alterDropSingleColumn
|
||||||
|
| alterTableOwner
|
||||||
|
;
|
||||||
|
|
||||||
|
alterDatabase: KW_ALTER KW_DATABASE databaseNamePath KW_SET KW_OWNER (KW_USER | KW_ROLE) identifier;
|
||||||
|
|
||||||
|
alterStatsKey: KW_ALTER KW_TABLE tableNamePath KW_SET KW_COLUMN KW_STATS columnNamePath LPAREN statsKey EQ stringLiteral (COMMA statsKey EQ stringLiteral)? RPAREN;
|
||||||
|
|
||||||
|
alterPartitionCache: KW_ALTER KW_TABLE tableNamePath (KW_PARTITION expression)? KW_SET ((KW_CACHED KW_IN stringLiteral (KW_WITH KW_REPLICATION EQ number)?) | KW_UNCACHED);
|
||||||
|
|
||||||
|
changeColumnDefine: KW_ALTER KW_TABLE tableNamePath KW_CHANGE KW_COLUMN columnSpecWithKudu;
|
||||||
|
|
||||||
|
alterDropSingleColumn: KW_ALTER KW_TABLE tableNamePath KW_DROP (KW_COLUMN)? columnNamePath;
|
||||||
|
|
||||||
|
alterTableOwner: KW_ALTER KW_TABLE tableNamePath KW_SET KW_OWNER (KW_USER | KW_ROLE) identifier;
|
||||||
|
|
||||||
|
replaceOrAddColumns: KW_ALTER KW_TABLE tableNamePath (KW_REPLACE | KW_ADD ifNotExists?) KW_COLUMNS LPAREN columnSpecWithKudu (COMMA columnSpecWithKudu)*? RPAREN;
|
||||||
|
|
||||||
|
addSingleColumn: KW_ALTER KW_TABLE tableNamePath KW_ADD KW_COLUMN ifNotExists? createColumnSpecWithKudu;
|
||||||
|
|
||||||
|
alterTableNonKuduOrKuduOnly: KW_ALTER KW_TABLE tableNamePath KW_ALTER (KW_COLUMN)? columnNamePath (KW_SET (kuduStorageAttr | KW_COMMENT stringLiteral ) | KW_DROP KW_DEFAULT);
|
||||||
|
|
||||||
|
addPartitionByRangeOrValue: KW_ALTER KW_TABLE tableNamePath KW_ADD ifNotExists? (KW_PARTITION expression (KW_LOCATION stringLiteral)? (cacheSpec)? | KW_RANGE KW_PARTITION kuduPartitionSpec);
|
||||||
|
|
||||||
|
alterFormat: KW_ALTER KW_TABLE tableNamePath (KW_PARTITION expression)? KW_SET ((KW_FILEFORMAT fileFormat) | (KW_ROW KW_FORMAT rowFormat) | (KW_LOCATION stringLiteral) | (KW_TBLPROPERTIES tblProp=properties) | (KW_SERDEPROPERTIES tblProp=properties));
|
||||||
|
|
||||||
|
recoverPartitions: KW_ALTER KW_TABLE tableNamePath KW_RECOVER KW_PARTITIONS;
|
||||||
|
|
||||||
|
dropPartitionByRangeOrValue: KW_ALTER KW_TABLE tableNamePath KW_DROP ifExists? (KW_PARTITION expression KW_PURGE? | KW_RANGE KW_PARTITION kuduPartitionSpec);
|
||||||
|
|
||||||
|
alterView: KW_ALTER KW_VIEW viewNamePath viewColumns? KW_AS queryStatement;
|
||||||
|
|
||||||
|
renameView: KW_ALTER KW_VIEW viewNamePath KW_RENAME KW_TO viewNamePath;
|
||||||
|
|
||||||
|
alterViewOwner: KW_ALTER KW_VIEW viewNamePath KW_SET KW_OWNER (KW_USER | KW_ROLE) qualifiedName;
|
||||||
|
|
||||||
|
renameTable: KW_ALTER KW_TABLE tableNamePath KW_RENAME KW_TO tableNamePath;
|
||||||
|
|
||||||
|
alterUnSetOrSetViewTblproperties: KW_ALTER KW_VIEW viewNamePath (KW_UNSET | KW_SET) KW_TBLPROPERTIES tblProp=properties;
|
||||||
|
|
||||||
|
truncateTableStatement: KW_TRUNCATE KW_TABLE? ifExists? tableNamePath;
|
||||||
|
|
||||||
|
describeStatement: KW_DESCRIBE KW_DATABASE? (KW_FORMATTED | KW_EXTENDED)? qualifiedName;
|
||||||
|
|
||||||
|
computeStatement
|
||||||
|
: computeStats
|
||||||
|
| computeIncrementalStats
|
||||||
|
;
|
||||||
|
|
||||||
|
computeStats: KW_COMPUTE KW_STATS tableNamePath (columnAliases)? (KW_TABLESAMPLE KW_SYSTEM LPAREN number RPAREN (KW_REPEATABLE LPAREN number RPAREN)?)?;
|
||||||
|
|
||||||
|
computeIncrementalStats: KW_COMPUTE KW_INCREMENTAL KW_STATS tableNamePath (KW_PARTITION expression)?;
|
||||||
|
|
||||||
|
dropStatement
|
||||||
|
: dropRole
|
||||||
|
| dropFunction
|
||||||
|
| dropIncrementalStats
|
||||||
|
| dropView
|
||||||
|
| dropTable
|
||||||
|
| dropSchema
|
||||||
|
;
|
||||||
|
|
||||||
|
dropSchema: KW_DROP (KW_SCHEMA | KW_DATABASE) (ifExists)? databaseNamePath (KW_CASCADE | KW_RESTRICT)?;
|
||||||
|
|
||||||
|
dropView: KW_DROP KW_VIEW ifExists? viewNamePath;
|
||||||
|
|
||||||
|
dropTable: KW_DROP KW_TABLE ifExists? tableNamePath KW_PURGE?;
|
||||||
|
|
||||||
|
dropIncrementalStats: KW_DROP KW_INCREMENTAL? KW_STATS tableNamePath (KW_PARTITION expression)?;
|
||||||
|
|
||||||
|
dropFunction: KW_DROP KW_AGGREGATE? KW_FUNCTION ifExists? functionNamePath (LPAREN(type (COMMA type)*)? RPAREN)?;
|
||||||
|
|
||||||
|
dropRole: KW_DROP KW_ROLE name=identifier;
|
||||||
|
|
||||||
|
grantStatement
|
||||||
|
: grantRole
|
||||||
|
| grant
|
||||||
|
;
|
||||||
|
|
||||||
|
grantRole: KW_GRANT KW_ROLE identifier KW_TO KW_GROUP identifier;
|
||||||
|
|
||||||
|
grant: KW_GRANT privilege KW_ON objectType (qualifiedName)? KW_TO grantee=principal;
|
||||||
|
|
||||||
|
revokeStatement
|
||||||
|
: revokeRole
|
||||||
|
| revoke
|
||||||
|
;
|
||||||
|
|
||||||
|
revokeRole: KW_REVOKE KW_ROLE identifier KW_FROM KW_GROUP identifier;
|
||||||
|
|
||||||
|
revoke: KW_REVOKE (KW_GRANT KW_OPTION KW_FOR)? privilege KW_ON objectType (qualifiedName)? KW_FROM (grantee=principal | (KW_ROLE)? identifier);
|
||||||
|
|
||||||
|
insertStatement
|
||||||
|
: with? KW_INSERT (KW_INTO | KW_OVERWRITE) KW_TABLE? tableNamePath
|
||||||
|
columnAliases?
|
||||||
|
(KW_PARTITION LPAREN expression(COMMA expression)*RPAREN)?
|
||||||
|
queryStatement
|
||||||
|
;
|
||||||
|
|
||||||
|
deleteStatement
|
||||||
|
: delete
|
||||||
|
| deleteTableRef
|
||||||
|
;
|
||||||
|
|
||||||
|
delete: KW_DELETE KW_FROM? tableNamePath (KW_WHERE booleanExpression)?;
|
||||||
|
|
||||||
|
deleteTableRef: KW_DELETE tableNamePath (KW_AS? identifier)? KW_FROM (relation (COMMA relation)*)? (KW_WHERE booleanExpression)?;
|
||||||
|
|
||||||
|
updateStatement: KW_UPDATE tableNamePath KW_SET assignmentList (KW_FROM relation (COMMA relation)*)? (KW_WHERE booleanExpression)?;
|
||||||
|
|
||||||
|
upsertStatement: KW_UPSERT KW_INTO KW_TABLE? tableNamePath columnAliases? queryStatement;
|
||||||
|
|
||||||
|
showStatement
|
||||||
|
: showRoles
|
||||||
|
| showRoleGrant
|
||||||
|
| showGrants
|
||||||
|
| showFiles
|
||||||
|
| showPartitions
|
||||||
|
| showColumnStats
|
||||||
|
| showTableStats
|
||||||
|
| showCreateView
|
||||||
|
| showCreateTable
|
||||||
|
| showFunctions
|
||||||
|
| showTables
|
||||||
|
| showSchemas
|
||||||
|
;
|
||||||
|
|
||||||
|
showSchemas
|
||||||
|
: KW_SHOW (KW_SCHEMAS | KW_DATABASES)
|
||||||
|
(KW_LIKE? pattern=stringLiteral (BITWISEOR stringLiteral)*)?
|
||||||
|
;
|
||||||
|
|
||||||
|
showTables
|
||||||
|
:
|
||||||
|
KW_SHOW KW_TABLES (KW_IN tableNamePath)?
|
||||||
|
(KW_LIKE? pattern=stringLiteral (BITWISEOR stringLiteral)*)?
|
||||||
|
;
|
||||||
|
|
||||||
|
showFunctions
|
||||||
|
:
|
||||||
|
KW_SHOW (KW_AGGREGATE | KW_ANALYTIC)? KW_FUNCTIONS (KW_IN databaseNamePath)?
|
||||||
|
(KW_LIKE? pattern=stringLiteral (BITWISEOR stringLiteral)*)?
|
||||||
|
;
|
||||||
|
|
||||||
|
showCreateTable: KW_SHOW KW_CREATE KW_TABLE tableNamePath;
|
||||||
|
|
||||||
|
showCreateView: KW_SHOW KW_CREATE KW_VIEW viewNamePath;
|
||||||
|
|
||||||
|
showTableStats: KW_SHOW KW_TABLE KW_STATS tableNamePath;
|
||||||
|
|
||||||
|
showColumnStats: KW_SHOW KW_COLUMN KW_STATS tableNamePath;
|
||||||
|
|
||||||
|
showPartitions: KW_SHOW (KW_RANGE)? KW_PARTITIONS tableNamePath;
|
||||||
|
|
||||||
|
showFiles: KW_SHOW KW_FILES KW_IN tableNamePath (KW_PARTITION LPAREN expression (COMMA expression)?RPAREN)?;
|
||||||
|
|
||||||
|
showRoles: KW_SHOW (KW_CURRENT)? KW_ROLES;
|
||||||
|
|
||||||
|
showRoleGrant: KW_SHOW KW_ROLE KW_GRANT KW_GROUP identifier;
|
||||||
|
|
||||||
|
showGrants
|
||||||
|
: showDatabaseGrant
|
||||||
|
| showTableGrant
|
||||||
|
| showColumnGrant
|
||||||
|
| KW_SHOW KW_GRANT (KW_USER | KW_ROLE | KW_GROUP) identifier
|
||||||
|
(KW_ON (KW_SERVER | KW_URI) (qualifiedName)?)?
|
||||||
|
;
|
||||||
|
|
||||||
|
showDatabaseGrant:
|
||||||
|
KW_SHOW KW_GRANT (KW_USER | KW_ROLE | KW_GROUP) identifier
|
||||||
|
(KW_ON KW_DATABASE (databaseNamePath)?)?
|
||||||
|
;
|
||||||
|
|
||||||
|
showTableGrant:
|
||||||
|
KW_SHOW KW_GRANT (KW_USER | KW_ROLE | KW_GROUP) identifier
|
||||||
|
(KW_ON KW_TABLE (tableNamePath)?)?
|
||||||
|
;
|
||||||
|
|
||||||
|
showColumnGrant:
|
||||||
|
KW_SHOW KW_GRANT (KW_USER | KW_ROLE | KW_GROUP) identifier
|
||||||
|
(KW_ON KW_COLUMN (columnNamePath)?)?
|
||||||
|
;
|
||||||
|
|
||||||
|
addCommentStatement
|
||||||
|
: addDatabaseComments
|
||||||
|
| addTableComments
|
||||||
|
| addColumnComments
|
||||||
|
;
|
||||||
|
|
||||||
|
addDatabaseComments: KW_COMMENT KW_ON KW_DATABASE databaseNamePath KW_IS (stringLiteral | KW_NULL);
|
||||||
|
|
||||||
|
addTableComments: KW_COMMENT KW_ON KW_TABLE tableNamePath KW_IS (stringLiteral | KW_NULL);
|
||||||
|
|
||||||
|
addColumnComments: KW_COMMENT KW_ON KW_COLUMN columnNamePath KW_IS (stringLiteral | KW_NULL);
|
||||||
|
|
||||||
|
explainStatement: KW_EXPLAIN statement;
|
||||||
|
|
||||||
|
setStatement: KW_SET (KW_ALL | identifier EQ expression)?;
|
||||||
|
|
||||||
|
shutdownStatement: COLON KW_SHUTDOWN LPAREN (stringLiteral? | stringLiteral (COMMA expression)? | expression) RPAREN;
|
||||||
|
|
||||||
|
invalidateMetaStatement: KW_INVALIDATE KW_METADATA tableNamePath;
|
||||||
|
|
||||||
|
loadDataStatement:
|
||||||
|
KW_LOAD KW_DATA KW_INPATH STRING (KW_OVERWRITE)? KW_INTO KW_TABLE tableNamePath
|
||||||
|
(KW_PARTITION LPAREN expression (COMMA expression)?RPAREN)?
|
||||||
|
;
|
||||||
|
|
||||||
|
refreshStatement: refreshMeta | refreshAuth | refreshFunction;
|
||||||
|
|
||||||
|
refreshMeta: KW_REFRESH tableNamePath (KW_PARTITION LPAREN expression (COMMA expression)*? RPAREN)?;
|
||||||
|
|
||||||
|
refreshAuth: KW_REFRESH KW_AUTHORIZATION;
|
||||||
|
|
||||||
|
refreshFunction: KW_REFRESH KW_FUNCTIONS functionNamePath;
|
||||||
|
|
||||||
|
ifExists
|
||||||
|
: KW_IF KW_EXISTS
|
||||||
|
;
|
||||||
|
|
||||||
|
ifNotExists
|
||||||
|
: KW_IF KW_NOT KW_EXISTS
|
||||||
|
;
|
||||||
|
|
||||||
|
tableNameCreate: qualifiedName;
|
||||||
|
|
||||||
|
databaseNameCreate: qualifiedName;
|
||||||
|
|
||||||
|
viewNameCreate: qualifiedName;
|
||||||
|
|
||||||
|
functionNameCreate: qualifiedName;
|
||||||
|
|
||||||
|
columnNamePathCreate: qualifiedName;
|
||||||
|
|
||||||
|
databaseNamePath: qualifiedName;
|
||||||
|
|
||||||
|
tableNamePath: identifier (DOT identifier)*;
|
||||||
|
|
||||||
|
viewNamePath: identifier (DOT identifier)*;
|
||||||
|
|
||||||
|
functionNamePath: qualifiedName;
|
||||||
|
|
||||||
|
columnNamePath: qualifiedName;
|
||||||
|
|
||||||
|
tableOrViewPath: tableNamePath | viewNamePath;
|
||||||
|
|
||||||
|
createCommonItem
|
||||||
|
:
|
||||||
|
(KW_SORT KW_BY columnAliases)?
|
||||||
|
(KW_COMMENT comment=stringLiteral)?
|
||||||
|
(KW_ROW KW_FORMAT rowFormat)?
|
||||||
|
(KW_WITH KW_SERDEPROPERTIES serdProp=properties)?
|
||||||
|
(KW_STORED KW_AS fileFormat)?
|
||||||
|
(KW_LOCATION location=stringLiteral)?
|
||||||
|
(KW_CACHED KW_IN cacheName=qualifiedName (KW_WITH KW_REPLICATION EQ INTEGER_VALUE )? | KW_UNCACHED)?
|
||||||
|
(KW_TBLPROPERTIES tblProp=properties)?
|
||||||
|
;
|
||||||
|
|
||||||
|
assignmentList
|
||||||
|
: assignmentItem (COMMA assignmentItem)*
|
||||||
|
;
|
||||||
|
|
||||||
|
assignmentItem
|
||||||
|
: qualifiedName EQ expression
|
||||||
|
;
|
||||||
|
|
||||||
|
viewColumns
|
||||||
|
: LPAREN columnNamePath (KW_COMMENT stringLiteral)? (COMMA identifier (KW_COMMENT stringLiteral)?)* RPAREN
|
||||||
|
;
|
||||||
|
|
||||||
|
queryStatement
|
||||||
|
: with? queryNoWith
|
||||||
|
;
|
||||||
|
|
||||||
|
with
|
||||||
|
: KW_WITH namedQuery (COMMA namedQuery)*
|
||||||
|
;
|
||||||
|
|
||||||
|
constraintSpecification
|
||||||
|
:
|
||||||
|
KW_PRIMARY KW_KEY columnAliases (KW_DISABLE)? (KW_NOVALIDATE | COMMA KW_NOVALIDATE)? (KW_RELY | COMMA KW_RELY)? ((COMMA foreignKeySpecification | foreignKeySpecification) (COMMA foreignKeySpecification)*?)?
|
||||||
|
;
|
||||||
|
|
||||||
|
foreignKeySpecification
|
||||||
|
:
|
||||||
|
KW_FOREIGN KW_KEY columnAliases KW_REFERENCES tableNamePath columnAliases (KW_DISABLE)? (KW_NOVALIDATE)? (KW_RELY)?
|
||||||
|
;
|
||||||
|
|
||||||
|
columnDefinition
|
||||||
|
: columnNamePathCreate type (KW_COMMENT stringLiteral)?
|
||||||
|
;
|
||||||
|
|
||||||
|
kuduTableElement
|
||||||
|
: kuduColumnDefinition
|
||||||
|
;
|
||||||
|
|
||||||
|
kuduColumnDefinition
|
||||||
|
: columnNamePathCreate type (kuduAttributes kuduAttributes*?)? (KW_COMMENT stringLiteral)? (KW_PRIMARY KW_KEY )?
|
||||||
|
;
|
||||||
|
|
||||||
|
columnSpecWithKudu
|
||||||
|
: columnNamePath type (KW_COMMENT stringLiteral)? (kuduAttributes kuduAttributes*?)?
|
||||||
|
;
|
||||||
|
|
||||||
|
createColumnSpecWithKudu
|
||||||
|
: columnNamePathCreate type (KW_COMMENT stringLiteral)? (kuduAttributes kuduAttributes*?)?
|
||||||
|
;
|
||||||
|
|
||||||
|
kuduAttributes
|
||||||
|
: ((KW_NOT)? KW_NULL | kuduStorageAttr)
|
||||||
|
;
|
||||||
|
|
||||||
|
kuduStorageAttr
|
||||||
|
: KW_ENCODING expression
|
||||||
|
| KW_COMPRESSION expression
|
||||||
|
| KW_DEFAULT expression
|
||||||
|
| KW_BLOCK_SIZE number
|
||||||
|
;
|
||||||
|
|
||||||
|
statsKey
|
||||||
|
: STATS_NUMDVS
|
||||||
|
| STATS_NUMNULLS
|
||||||
|
| STATS_AVGSIZE
|
||||||
|
| STATS_MAXSIZE
|
||||||
|
;
|
||||||
|
|
||||||
|
fileFormat
|
||||||
|
: KW_TEXTFILE
|
||||||
|
| KW_PARQUET
|
||||||
|
| KW_ORC
|
||||||
|
| KW_AVRO
|
||||||
|
| KW_SEQUENCEFILE
|
||||||
|
| KW_RCFILE
|
||||||
|
;
|
||||||
|
|
||||||
|
kuduPartitionClause
|
||||||
|
: (hashClause (COMMA hashClause)*? (COMMA rangeClause)?) | rangeClause
|
||||||
|
;
|
||||||
|
|
||||||
|
hashClause
|
||||||
|
: KW_HASH columnAliases? KW_PARTITIONS number
|
||||||
|
;
|
||||||
|
|
||||||
|
rangeClause
|
||||||
|
: KW_RANGE columnAliases? LPAREN (KW_PARTITION kuduPartitionSpec (COMMA KW_PARTITION kuduPartitionSpec)*?) RPAREN
|
||||||
|
;
|
||||||
|
|
||||||
|
kuduPartitionSpec
|
||||||
|
: KW_VALUE partitionCol expression | (expression rangeOperator)? KW_VALUES (rangeOperator expression)?
|
||||||
|
;
|
||||||
|
|
||||||
|
cacheSpec
|
||||||
|
: KW_CACHED KW_IN identifier (KW_WITH KW_REPLICATION EQ number)?
|
||||||
|
| KW_UNCACHED
|
||||||
|
;
|
||||||
|
|
||||||
|
rangeOperator
|
||||||
|
:
|
||||||
|
| LT
|
||||||
|
| LTE
|
||||||
|
| GT
|
||||||
|
| GTE
|
||||||
|
;
|
||||||
|
|
||||||
|
partitionCol
|
||||||
|
: EQ
|
||||||
|
| NEQ
|
||||||
|
| KW_LIKE
|
||||||
|
| KW_RLIKE
|
||||||
|
| KW_REGEXP
|
||||||
|
| KW_BETWEEN
|
||||||
|
| KW_IN
|
||||||
|
| rangeOperator
|
||||||
|
;
|
||||||
|
|
||||||
|
likeClause
|
||||||
|
: KW_LIKE qualifiedName (optionType=(KW_INCLUDING | KW_EXCLUDING) KW_PROPERTIES)?
|
||||||
|
;
|
||||||
|
|
||||||
|
properties
|
||||||
|
: LPAREN property (COMMA property)* RPAREN
|
||||||
|
;
|
||||||
|
|
||||||
|
partitionedBy
|
||||||
|
: LPAREN columnDefinition (COMMA columnDefinition)*? RPAREN
|
||||||
|
;
|
||||||
|
|
||||||
|
sortedBy
|
||||||
|
: expression (COMMA expression)*
|
||||||
|
;
|
||||||
|
|
||||||
|
rowFormat
|
||||||
|
: KW_DELIMITED (KW_FIELDS KW_TERMINATED KW_BY stringLiteral (KW_ESCAPED KW_BY stringLiteral)?)? (KW_LINES KW_TERMINATED KW_BY stringLiteral)?
|
||||||
|
;
|
||||||
|
|
||||||
|
property
|
||||||
|
: identifier (EQ expression)?
|
||||||
|
;
|
||||||
|
|
||||||
|
queryNoWith:
|
||||||
|
queryTerm
|
||||||
|
(KW_ORDER KW_BY sortItem (COMMA sortItem)*)?
|
||||||
|
(KW_LIMIT rows=expression (KW_OFFSET offset=INTEGER_VALUE )?)?
|
||||||
|
;
|
||||||
|
|
||||||
|
queryTerm
|
||||||
|
: queryPrimary #queryTermDefault
|
||||||
|
| left=queryTerm operator=KW_INTERSECT setQuantifier? right=queryTerm #setOperation
|
||||||
|
| left=queryTerm operator=(KW_UNION | KW_EXCEPT) setQuantifier? right=queryTerm #setOperation
|
||||||
|
;
|
||||||
|
|
||||||
|
queryPrimary
|
||||||
|
: querySpecification #queryPrimaryDefault
|
||||||
|
| KW_TABLE tableNamePath #table
|
||||||
|
| KW_VALUES expression (COMMA expression)* #inlineTable
|
||||||
|
| LPAREN queryNoWith RPAREN #subquery
|
||||||
|
;
|
||||||
|
|
||||||
|
sortItem
|
||||||
|
: columnItem ordering=(KW_ASC | KW_DESC)? (KW_NULLS nullOrdering=(KW_FIRST | KW_LAST))?
|
||||||
|
;
|
||||||
|
|
||||||
|
querySpecification
|
||||||
|
: KW_SELECT setQuantifier? (KW_STRAIGHT_JOIN)? selectItem (COMMA selectItem)*
|
||||||
|
(KW_FROM relation (COMMA relation)*)?
|
||||||
|
(KW_WHERE where=booleanExpression)?
|
||||||
|
(KW_GROUP KW_BY groupBy)?
|
||||||
|
(KW_HAVING having=booleanExpression)?
|
||||||
|
;
|
||||||
|
|
||||||
|
groupBy
|
||||||
|
: setQuantifier? groupingElement (COMMA groupingElement)*
|
||||||
|
;
|
||||||
|
|
||||||
|
groupingElement
|
||||||
|
: groupingSet #singleGroupingSet
|
||||||
|
;
|
||||||
|
|
||||||
|
groupingSet
|
||||||
|
: LPAREN (columnItem (COMMA columnItem)*)? RPAREN
|
||||||
|
| columnItem
|
||||||
|
;
|
||||||
|
|
||||||
|
namedQuery
|
||||||
|
: name=identifier (columnAliases)? KW_AS subQueryRelation
|
||||||
|
;
|
||||||
|
|
||||||
|
setQuantifier
|
||||||
|
: KW_DISTINCT
|
||||||
|
| KW_ALL
|
||||||
|
;
|
||||||
|
|
||||||
|
selectItem
|
||||||
|
: columnItem (KW_AS? identifier)? #selectSingle
|
||||||
|
| qualifiedName DOT ASTERISK #selectAll
|
||||||
|
| ASTERISK #selectAll
|
||||||
|
;
|
||||||
|
|
||||||
|
relation
|
||||||
|
: left=relation
|
||||||
|
( KW_CROSS KW_JOIN right=sampledRelation
|
||||||
|
| joinType KW_JOIN rightRelation=relation joinCriteria
|
||||||
|
) #joinRelation
|
||||||
|
| sampledRelation #relationDefault
|
||||||
|
;
|
||||||
|
|
||||||
|
joinType
|
||||||
|
: KW_INNER?
|
||||||
|
| KW_LEFT KW_INNER?
|
||||||
|
| KW_RIGHT KW_INNER?
|
||||||
|
| KW_LEFT KW_OUTER?
|
||||||
|
| KW_RIGHT KW_OUTER?
|
||||||
|
| KW_FULL KW_OUTER?
|
||||||
|
| KW_LEFT KW_SEMI
|
||||||
|
| KW_RIGHT KW_SEMI
|
||||||
|
| KW_LEFT KW_ANTI
|
||||||
|
| KW_RIGHT KW_ANTI
|
||||||
|
;
|
||||||
|
|
||||||
|
joinCriteria
|
||||||
|
: KW_ON booleanExpression
|
||||||
|
| KW_USING LPAREN identifier (COMMA identifier)* RPAREN
|
||||||
|
;
|
||||||
|
|
||||||
|
sampledRelation
|
||||||
|
: aliasedRelation (
|
||||||
|
KW_TABLESAMPLE sampleType LPAREN percentage=expression RPAREN (KW_REPEATABLE LPAREN seed=expression RPAREN)?
|
||||||
|
)?
|
||||||
|
;
|
||||||
|
|
||||||
|
sampleType
|
||||||
|
: KW_BERNOULLI
|
||||||
|
| KW_SYSTEM
|
||||||
|
;
|
||||||
|
|
||||||
|
aliasedRelation
|
||||||
|
: relationPrimary (KW_AS? identifier columnAliases?)?
|
||||||
|
;
|
||||||
|
|
||||||
|
columnAliases
|
||||||
|
: LPAREN columnNamePath (COMMA columnNamePath)* RPAREN
|
||||||
|
;
|
||||||
|
|
||||||
|
createColumnAliases
|
||||||
|
: LPAREN columnNamePathCreate (COMMA columnNamePathCreate)* RPAREN
|
||||||
|
;
|
||||||
|
|
||||||
|
relationPrimary
|
||||||
|
: tableOrViewPath
|
||||||
|
| KW_LATERAL? subQueryRelation
|
||||||
|
| unnest
|
||||||
|
| parenthesizedRelation
|
||||||
|
;
|
||||||
|
|
||||||
|
subQueryRelation: LPAREN queryStatement RPAREN;
|
||||||
|
|
||||||
|
unnest: KW_UNNEST LPAREN expression (COMMA expression)* RPAREN (KW_WITH KW_ORDINALITY)?;
|
||||||
|
|
||||||
|
parenthesizedRelation: LPAREN relation RPAREN;
|
||||||
|
|
||||||
|
columnItem: columnNamePath | expression;
|
||||||
|
|
||||||
|
expression
|
||||||
|
: booleanExpression
|
||||||
|
;
|
||||||
|
|
||||||
|
booleanExpression
|
||||||
|
: valueExpression predicate[$valueExpression.ctx]? #predicated
|
||||||
|
| KW_NOT booleanExpression #logicalNot
|
||||||
|
| left=booleanExpression operator=KW_AND right=booleanExpression #logicalBinary
|
||||||
|
| left=booleanExpression operator=KW_OR right=booleanExpression #logicalBinary
|
||||||
|
;
|
||||||
|
|
||||||
|
predicate[ParserRuleContext value]
|
||||||
|
: comparisonOperator right=valueExpression #comparison
|
||||||
|
| comparisonOperator comparisonQuantifier subQueryRelation #quantifiedComparison
|
||||||
|
| KW_NOT? KW_BETWEEN lower=valueExpression KW_AND upper=valueExpression #between
|
||||||
|
| KW_NOT? KW_IN LPAREN expression (COMMA expression)* RPAREN #inList
|
||||||
|
| KW_NOT? KW_IN subQueryRelation #inSubquery
|
||||||
|
| KW_NOT? KW_LIKE pattern=valueExpression (KW_ESCAPE escape=valueExpression)? #like
|
||||||
|
| KW_REGEXP pattern=valueExpression #REGEXP
|
||||||
|
| KW_IS KW_NOT? KW_NULL #nullPredicate
|
||||||
|
| KW_IS KW_NOT? KW_DISTINCT KW_FROM right=valueExpression #distinctFrom
|
||||||
|
;
|
||||||
|
|
||||||
|
valueExpression
|
||||||
|
: primaryExpression #valueExpressionDefault
|
||||||
|
| operator=(MINUS | PLUS) valueExpression #arithmeticUnary
|
||||||
|
| left=valueExpression operator=(ASTERISK | SLASH | PERCENT) right=valueExpression #arithmeticBinary
|
||||||
|
| left=valueExpression operator=(PLUS | MINUS) right=valueExpression #arithmeticBinary
|
||||||
|
| left=valueExpression CONCAT right=valueExpression #concatenation
|
||||||
|
;
|
||||||
|
|
||||||
|
primaryExpression
|
||||||
|
: KW_NULL #nullLiteral
|
||||||
|
| interval #intervalLiteral
|
||||||
|
| identifier stringLiteral #typeConstructor
|
||||||
|
| DOUBLE_PRECISION stringLiteral #typeConstructor
|
||||||
|
| number #numericLiteral
|
||||||
|
| booleanValue #booleanLiteral
|
||||||
|
| stringLiteral #stringLiteralValues
|
||||||
|
| BINARY_LITERAL #binaryLiteral
|
||||||
|
| QUESTION #parameter
|
||||||
|
| KW_POSITION LPAREN valueExpression KW_IN valueExpression RPAREN #position
|
||||||
|
| LPAREN expression (KW_AS type)? (COMMA expression (KW_AS type)?)*? RPAREN #rowConstructor
|
||||||
|
| KW_ROW LPAREN expression (COMMA expression)* RPAREN #rowConstructor
|
||||||
|
| functionNamePath LPAREN ASTERISK RPAREN filter? over? #functionCall
|
||||||
|
| functionNamePath LPAREN (setQuantifier? expression (COMMA expression)*)?
|
||||||
|
(KW_ORDER KW_BY sortItem (COMMA sortItem)*)? RPAREN filter? over? #functionCall
|
||||||
|
| identifier RIGHT_ARROW expression #lambda
|
||||||
|
| LPAREN (identifier (COMMA identifier)*)? RPAREN RIGHT_ARROW expression #lambda
|
||||||
|
| LPAREN queryStatement RPAREN #subqueryExpression
|
||||||
|
| KW_EXISTS LPAREN queryStatement RPAREN #exists
|
||||||
|
| KW_CASE valueExpression whenClause+ (KW_ELSE elseExpression=expression)? KW_END #simpleCase
|
||||||
|
| KW_CASE whenClause+ (KW_ELSE elseExpression=expression)? KW_END #searchedCase
|
||||||
|
| KW_CAST LPAREN expression KW_AS type RPAREN #cast
|
||||||
|
| KW_TRY_CAST LPAREN expression KW_AS type RPAREN #cast
|
||||||
|
| KW_ARRAY LSQUARE (expression (COMMA expression)*)? RSQUARE #arrayConstructor
|
||||||
|
| value=primaryExpression LSQUARE index=valueExpression RSQUARE #subscript
|
||||||
|
| identifier #columnReference
|
||||||
|
| base=primaryExpression DOT fieldName=identifier #dereference
|
||||||
|
| name=KW_CURRENT_DATE #specialDateTimeFunction
|
||||||
|
| name=KW_CURRENT_TIME (LPAREN precision=INTEGER_VALUE RPAREN)? #specialDateTimeFunction
|
||||||
|
| name=KW_CURRENT_TIMESTAMP (LPAREN precision=INTEGER_VALUE RPAREN)? #specialDateTimeFunction
|
||||||
|
| name=KW_LOCALTIME (LPAREN precision=INTEGER_VALUE RPAREN)? #specialDateTimeFunction
|
||||||
|
| name=KW_LOCALTIMESTAMP (LPAREN precision=INTEGER_VALUE RPAREN)? #specialDateTimeFunction
|
||||||
|
| name=KW_CURRENT_USER #currentUser
|
||||||
|
| name=KW_CURRENT_PATH #currentPath
|
||||||
|
| KW_SUBSTRING LPAREN valueExpression KW_FROM valueExpression (KW_FOR valueExpression)? RPAREN #substring
|
||||||
|
| KW_NORMALIZE LPAREN valueExpression (COMMA normalForm)? RPAREN #normalize
|
||||||
|
| KW_EXTRACT LPAREN identifier KW_FROM valueExpression RPAREN #extract
|
||||||
|
| LPAREN expression RPAREN #parenthesizedExpression
|
||||||
|
| KW_GROUPING LPAREN (qualifiedName (COMMA qualifiedName)*)? RPAREN #groupingOperation
|
||||||
|
;
|
||||||
|
|
||||||
|
stringLiteral
|
||||||
|
: STRING #basicStringLiteral
|
||||||
|
| UNICODE_STRING (KW_UESCAPE STRING)? #unicodeStringLiteral
|
||||||
|
;
|
||||||
|
|
||||||
|
comparisonOperator
|
||||||
|
: EQ | NEQ | LT | LTE | GT | GTE
|
||||||
|
;
|
||||||
|
|
||||||
|
comparisonQuantifier
|
||||||
|
: KW_ALL | KW_SOME | KW_ANY
|
||||||
|
;
|
||||||
|
|
||||||
|
booleanValue
|
||||||
|
: KW_TRUE | KW_FALSE
|
||||||
|
;
|
||||||
|
|
||||||
|
interval
|
||||||
|
: INTEGER_VALUE intervalField
|
||||||
|
| LPAREN INTEGER_VALUE RPAREN intervalField
|
||||||
|
| KW_INTERVAL INTEGER_VALUE intervalField
|
||||||
|
| KW_INTERVAL LPAREN INTEGER_VALUE RPAREN intervalField
|
||||||
|
;
|
||||||
|
|
||||||
|
intervalField
|
||||||
|
: KW_YEAR | KW_YEARS | KW_MONTH | KW_MONTHS | KW_DAY | KW_DAYS | KW_HOUR | KW_HOURS | KW_MINUTE | KW_MINUTES | KW_SECOND | KW_SECONDS
|
||||||
|
;
|
||||||
|
|
||||||
|
normalForm
|
||||||
|
: KW_NFD | KW_NFC | KW_NFKD | KW_NFKC
|
||||||
|
;
|
||||||
|
|
||||||
|
type
|
||||||
|
: type KW_ARRAY
|
||||||
|
| KW_ARRAY LT type GT
|
||||||
|
| KW_MAP LT type COMMA type GT
|
||||||
|
| KW_STRUCT LT identifier COLON type (COMMA identifier COLON type)* GT
|
||||||
|
| baseType (LPAREN typeParameter (COMMA typeParameter)* RPAREN)?
|
||||||
|
;
|
||||||
|
|
||||||
|
typeParameter
|
||||||
|
: INTEGER_VALUE | type
|
||||||
|
;
|
||||||
|
|
||||||
|
baseType
|
||||||
|
: TIME_WITH_TIME_ZONE
|
||||||
|
| TIMESTAMP_WITH_TIME_ZONE
|
||||||
|
| DOUBLE_PRECISION
|
||||||
|
| identifier
|
||||||
|
;
|
||||||
|
|
||||||
|
whenClause
|
||||||
|
: KW_WHEN condition=expression KW_THEN result=expression
|
||||||
|
;
|
||||||
|
|
||||||
|
filter
|
||||||
|
: KW_FILTER LPAREN KW_WHERE booleanExpression RPAREN
|
||||||
|
;
|
||||||
|
|
||||||
|
over
|
||||||
|
: KW_OVER LPAREN
|
||||||
|
(KW_PARTITION KW_BY partition+=expression (COMMA partition+=expression)*)?
|
||||||
|
(KW_ORDER KW_BY sortItem (COMMA sortItem)*)?
|
||||||
|
windowFrame?
|
||||||
|
RPAREN
|
||||||
|
;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* replace start identifier with start_ in grammar.
|
||||||
|
* https://github.com/tunnelvisionlabs/antlr4ts/issues/417
|
||||||
|
*/
|
||||||
|
windowFrame
|
||||||
|
: frameType=KW_RANGE start_=frameBound
|
||||||
|
| frameType=KW_ROWS start_=frameBound
|
||||||
|
| frameType=KW_RANGE KW_BETWEEN start_=frameBound KW_AND end=frameBound
|
||||||
|
| frameType=KW_ROWS KW_BETWEEN start_=frameBound KW_AND end=frameBound
|
||||||
|
;
|
||||||
|
|
||||||
|
frameBound
|
||||||
|
: KW_UNBOUNDED boundType=KW_PRECEDING #unboundedFrame
|
||||||
|
| KW_UNBOUNDED boundType=KW_FOLLOWING #unboundedFrame
|
||||||
|
| KW_CURRENT KW_ROW #currentRowBound
|
||||||
|
| expression boundType=(KW_PRECEDING | KW_FOLLOWING) #boundedFrame
|
||||||
|
;
|
||||||
|
|
||||||
|
pathElement
|
||||||
|
: identifier DOT identifier #qualifiedArgument
|
||||||
|
| identifier #unqualifiedArgument
|
||||||
|
;
|
||||||
|
|
||||||
|
pathSpecification
|
||||||
|
: pathElement (COMMA pathElement)*
|
||||||
|
;
|
||||||
|
|
||||||
|
privilege
|
||||||
|
: KW_ALL | KW_ALTER | KW_DROP | KW_CREATE | KW_INSERT | KW_REFRESH | KW_SELECT (LPAREN columnName=identifier RPAREN)?
|
||||||
|
;
|
||||||
|
objectType
|
||||||
|
: KW_SERVER | KW_URI | KW_DATABASE | KW_TABLE
|
||||||
|
;
|
||||||
|
qualifiedName
|
||||||
|
: identifier (DOT identifier)*
|
||||||
|
;
|
||||||
|
|
||||||
|
principal
|
||||||
|
: KW_ROLE identifier #rolePrincipal
|
||||||
|
| KW_USER identifier #userPrincipal
|
||||||
|
| KW_GROUP identifier #groupPrincipal
|
||||||
|
;
|
||||||
|
|
||||||
|
identifier
|
||||||
|
: IDENTIFIER #unquotedIdentifier
|
||||||
|
| STRING #quotedIdentifier
|
||||||
|
| nonReserved #unquotedIdentifier
|
||||||
|
| BACKQUOTED_IDENTIFIER #backQuotedIdentifier
|
||||||
|
| DIGIT_IDENTIFIER #digitIdentifier
|
||||||
|
;
|
||||||
|
|
||||||
|
number
|
||||||
|
: MINUS? DECIMAL_VALUE #decimalLiteral
|
||||||
|
| MINUS? DOUBLE_VALUE #doubleLiteral
|
||||||
|
| MINUS? INTEGER_VALUE #integerLiteral
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
nonReserved
|
||||||
|
// IMPORTANT: this rule must only contain tokens. Nested rules are not supported. See SqlParser.exitNonReserved
|
||||||
|
: KW_ADD
|
||||||
|
| KW_ALL
|
||||||
|
| KW_ANY
|
||||||
|
| KW_ARRAY
|
||||||
|
| KW_ASC
|
||||||
|
| KW_AT
|
||||||
|
| KW_BERNOULLI
|
||||||
|
| KW_CASCADE
|
||||||
|
| KW_COLUMN
|
||||||
|
| KW_COLUMNS
|
||||||
|
| KW_COMMENT
|
||||||
|
| KW_CURRENT
|
||||||
|
| KW_DATA
|
||||||
|
| KW_DATABASE
|
||||||
|
| KW_DATABASES
|
||||||
|
| KW_DAY
|
||||||
|
| KW_DAYS
|
||||||
|
| KW_DESC
|
||||||
|
| KW_EXCLUDING
|
||||||
|
| KW_EXPLAIN
|
||||||
|
| KW_FILTER
|
||||||
|
| KW_FIRST
|
||||||
|
| KW_FOLLOWING
|
||||||
|
| KW_FORMAT
|
||||||
|
| KW_FUNCTIONS
|
||||||
|
| KW_GRANT
|
||||||
|
| KW_HOUR
|
||||||
|
| KW_IF
|
||||||
|
| KW_INCLUDING
|
||||||
|
| KW_INTERVAL
|
||||||
|
| KW_LAST
|
||||||
|
| KW_LATERAL
|
||||||
|
| KW_LIMIT
|
||||||
|
| KW_MAP
|
||||||
|
| KW_MINUTE
|
||||||
|
| KW_MONTH
|
||||||
|
| KW_NFC
|
||||||
|
| KW_NFD
|
||||||
|
| KW_NFKC
|
||||||
|
| KW_NFKD
|
||||||
|
| KW_NULLS
|
||||||
|
| KW_OFFSET
|
||||||
|
| KW_OPTION
|
||||||
|
| KW_ORDINALITY
|
||||||
|
| KW_OVER
|
||||||
|
| KW_PARTITION
|
||||||
|
| KW_PARTITIONS
|
||||||
|
| KW_PARQUET
|
||||||
|
| KW_POSITION
|
||||||
|
| KW_PRECEDING
|
||||||
|
| KW_PRIVILEGES
|
||||||
|
| KW_PROPERTIES
|
||||||
|
| KW_RANGE
|
||||||
|
| KW_RENAME
|
||||||
|
| KW_REPEATABLE
|
||||||
|
| KW_REPLACE
|
||||||
|
| KW_RESTRICT
|
||||||
|
| KW_REVOKE
|
||||||
|
| KW_ROLE
|
||||||
|
| KW_ROLES
|
||||||
|
| KW_ROW
|
||||||
|
| KW_ROWS
|
||||||
|
| KW_SCHEMA
|
||||||
|
| KW_SCHEMAS
|
||||||
|
| KW_SECOND
|
||||||
|
| KW_SECONDS
|
||||||
|
| KW_SET
|
||||||
|
| KW_SHOW
|
||||||
|
| KW_SOME
|
||||||
|
| KW_STATS
|
||||||
|
| KW_SUBSTRING
|
||||||
|
| KW_SYSTEM
|
||||||
|
| KW_TABLES
|
||||||
|
| KW_TABLESAMPLE
|
||||||
|
| KW_TRUNCATE
|
||||||
|
| KW_TO
|
||||||
|
| KW_TRY_CAST
|
||||||
|
| KW_UNBOUNDED
|
||||||
|
| KW_USE
|
||||||
|
| KW_USER
|
||||||
|
| KW_VIEW
|
||||||
|
| KW_VIEWS
|
||||||
|
| KW_YEAR
|
||||||
|
| KW_DEFAULT
|
||||||
|
| KW_TEXTFILE
|
||||||
|
| KW_ORC
|
||||||
|
| KW_AVRO
|
||||||
|
| KW_SEQUENCEFILE
|
||||||
|
| KW_RCFILE
|
||||||
|
;
|
@ -1,3 +0,0 @@
|
|||||||
# Impala SQL Grammar
|
|
||||||
|
|
||||||
SQL-like HiveQL, [Hive Grammar](https://github.com/apache/hive/tree/master/hplsql/src/main/antlr4/org/apache/hive/hplsql)
|
|
830
src/lib/impala/ImpalaSqlLexer.interp
Normal file
830
src/lib/impala/ImpalaSqlLexer.interp
Normal file
File diff suppressed because one or more lines are too long
523
src/lib/impala/ImpalaSqlLexer.tokens
Normal file
523
src/lib/impala/ImpalaSqlLexer.tokens
Normal file
@ -0,0 +1,523 @@
|
|||||||
|
KW_ADD=1
|
||||||
|
KW_ALL=2
|
||||||
|
KW_ANALYTIC=3
|
||||||
|
KW_ALTER=4
|
||||||
|
KW_AND=5
|
||||||
|
KW_ANY=6
|
||||||
|
KW_ANTI=7
|
||||||
|
KW_ARRAY=8
|
||||||
|
KW_AS=9
|
||||||
|
KW_ASC=10
|
||||||
|
KW_AT=11
|
||||||
|
KW_AGGREGATE=12
|
||||||
|
KW_AUTHORIZATION=13
|
||||||
|
KW_BERNOULLI=14
|
||||||
|
KW_BETWEEN=15
|
||||||
|
KW_BLOCK_SIZE=16
|
||||||
|
KW_PARTITIONED=17
|
||||||
|
KW_PREPARE_FN=18
|
||||||
|
KW_EXTERNAL=19
|
||||||
|
KW_CLOSEFN=20
|
||||||
|
KW_SORT=21
|
||||||
|
KW_PURGE=22
|
||||||
|
KW_STORED=23
|
||||||
|
KW_LOCATION=24
|
||||||
|
KW_TBLPROPERTIES=25
|
||||||
|
KW_BY=26
|
||||||
|
KW_CASCADE=27
|
||||||
|
KW_CASE=28
|
||||||
|
KW_CAST=29
|
||||||
|
KW_CACHED=30
|
||||||
|
KW_CHANGE=31
|
||||||
|
KW_COLUMN=32
|
||||||
|
KW_COLUMNS=33
|
||||||
|
KW_COMMENT=34
|
||||||
|
KW_COMPRESSION=35
|
||||||
|
KW_COMPUTE=36
|
||||||
|
KW_CREATE=37
|
||||||
|
KW_CROSS=38
|
||||||
|
KW_CURRENT=39
|
||||||
|
KW_CURRENT_DATE=40
|
||||||
|
KW_CURRENT_PATH=41
|
||||||
|
KW_CURRENT_TIME=42
|
||||||
|
KW_CURRENT_TIMESTAMP=43
|
||||||
|
KW_CURRENT_USER=44
|
||||||
|
KW_DATA=45
|
||||||
|
KW_DATABASE=46
|
||||||
|
KW_DATABASES=47
|
||||||
|
KW_DAY=48
|
||||||
|
KW_DAYS=49
|
||||||
|
KW_DELETE=50
|
||||||
|
KW_DEFAULT=51
|
||||||
|
KW_DELIMITED=52
|
||||||
|
KW_DISABLE=53
|
||||||
|
KW_UPDATE=54
|
||||||
|
KW_DESC=55
|
||||||
|
KW_DESCRIBE=56
|
||||||
|
KW_DISTINCT=57
|
||||||
|
KW_DROP=58
|
||||||
|
KW_ELSE=59
|
||||||
|
KW_ENCODING=60
|
||||||
|
KW_END=61
|
||||||
|
KW_ESCAPE=62
|
||||||
|
KW_ESCAPED=63
|
||||||
|
KW_EXCEPT=64
|
||||||
|
KW_EXCLUDING=65
|
||||||
|
KW_EXISTS=66
|
||||||
|
KW_EXPLAIN=67
|
||||||
|
KW_EXTRACT=68
|
||||||
|
KW_EXTENDED=69
|
||||||
|
KW_FALSE=70
|
||||||
|
KW_FIELDS=71
|
||||||
|
KW_FILEFORMAT=72
|
||||||
|
KW_FILES=73
|
||||||
|
KW_FILTER=74
|
||||||
|
KW_FIRST=75
|
||||||
|
KW_FINALIZE_FN=76
|
||||||
|
KW_FOLLOWING=77
|
||||||
|
KW_FOR=78
|
||||||
|
KW_FORMAT=79
|
||||||
|
KW_FORMATTED=80
|
||||||
|
KW_FOREIGN=81
|
||||||
|
KW_FROM=82
|
||||||
|
KW_FULL=83
|
||||||
|
KW_FUNCTION=84
|
||||||
|
KW_FUNCTIONS=85
|
||||||
|
KW_GRANT=86
|
||||||
|
KW_GROUP=87
|
||||||
|
KW_GROUPING=88
|
||||||
|
KW_HASH=89
|
||||||
|
KW_HAVING=90
|
||||||
|
KW_HOUR=91
|
||||||
|
KW_HOURS=92
|
||||||
|
KW_IF=93
|
||||||
|
KW_IN=94
|
||||||
|
KW_INCLUDING=95
|
||||||
|
KW_INCREMENTAL=96
|
||||||
|
KW_INNER=97
|
||||||
|
KW_INPATH=98
|
||||||
|
KW_INSERT=99
|
||||||
|
KW_INTERSECT=100
|
||||||
|
KW_INTERVAL=101
|
||||||
|
KW_INTERMEDIATE=102
|
||||||
|
KW_INTO=103
|
||||||
|
KW_INIT_FN=104
|
||||||
|
KW_INVALIDATE=105
|
||||||
|
KW_IS=106
|
||||||
|
KW_JOIN=107
|
||||||
|
KW_KEY=108
|
||||||
|
KW_KUDU=109
|
||||||
|
KW_LAST=110
|
||||||
|
KW_LATERAL=111
|
||||||
|
KW_LEFT=112
|
||||||
|
KW_LIKE=113
|
||||||
|
KW_LIMIT=114
|
||||||
|
KW_LINES=115
|
||||||
|
KW_LOAD=116
|
||||||
|
KW_LOCALTIME=117
|
||||||
|
KW_LOCALTIMESTAMP=118
|
||||||
|
KW_METADATA=119
|
||||||
|
KW_MAP=120
|
||||||
|
KW_MINUTE=121
|
||||||
|
KW_MINUTES=122
|
||||||
|
KW_MONTH=123
|
||||||
|
KW_MONTHS=124
|
||||||
|
KW_MERGE_FN=125
|
||||||
|
KW_NFC=126
|
||||||
|
KW_NFD=127
|
||||||
|
KW_NFKC=128
|
||||||
|
KW_NFKD=129
|
||||||
|
KW_NORMALIZE=130
|
||||||
|
KW_NOT=131
|
||||||
|
KW_NULL=132
|
||||||
|
KW_NULLS=133
|
||||||
|
KW_OFFSET=134
|
||||||
|
KW_ON=135
|
||||||
|
KW_OPTION=136
|
||||||
|
KW_OR=137
|
||||||
|
KW_ORDER=138
|
||||||
|
KW_ORDINALITY=139
|
||||||
|
KW_OUTER=140
|
||||||
|
KW_OWNER=141
|
||||||
|
KW_OVER=142
|
||||||
|
KW_OVERWRITE=143
|
||||||
|
KW_PARTITION=144
|
||||||
|
KW_PARTITIONS=145
|
||||||
|
KW_PARQUET=146
|
||||||
|
KW_POSITION=147
|
||||||
|
KW_PRECEDING=148
|
||||||
|
KW_PRIMARY=149
|
||||||
|
KW_REPLICATION=150
|
||||||
|
KW_PRIVILEGES=151
|
||||||
|
KW_PROPERTIES=152
|
||||||
|
KW_RANGE=153
|
||||||
|
KW_RECOVER=154
|
||||||
|
KW_RENAME=155
|
||||||
|
KW_REPEATABLE=156
|
||||||
|
KW_REPLACE=157
|
||||||
|
KW_RESTRICT=158
|
||||||
|
KW_RETURNS=159
|
||||||
|
KW_REVOKE=160
|
||||||
|
KW_REFRESH=161
|
||||||
|
KW_REGEXP=162
|
||||||
|
KW_RLIKE=163
|
||||||
|
KW_RIGHT=164
|
||||||
|
KW_ROLE=165
|
||||||
|
KW_ROLES=166
|
||||||
|
KW_ROW=167
|
||||||
|
KW_ROWS=168
|
||||||
|
KW_SCHEMA=169
|
||||||
|
KW_SCHEMAS=170
|
||||||
|
KW_SECOND=171
|
||||||
|
KW_SECONDS=172
|
||||||
|
KW_SELECT=173
|
||||||
|
KW_SERDEPROPERTIES=174
|
||||||
|
KW_SET=175
|
||||||
|
KW_SEMI=176
|
||||||
|
KW_SERVER=177
|
||||||
|
KW_SHOW=178
|
||||||
|
KW_SHUTDOWN=179
|
||||||
|
KW_SOME=180
|
||||||
|
KW_STATS=181
|
||||||
|
KW_STRUCT=182
|
||||||
|
KW_STRAIGHT_JOIN=183
|
||||||
|
KW_SUBSTRING=184
|
||||||
|
KW_SYSTEM=185
|
||||||
|
KW_SYMBOL=186
|
||||||
|
KW_SERIALIZE_FN=187
|
||||||
|
KW_TABLE=188
|
||||||
|
KW_TABLES=189
|
||||||
|
KW_TABLESAMPLE=190
|
||||||
|
KW_TERMINATED=191
|
||||||
|
KW_THEN=192
|
||||||
|
KW_TO=193
|
||||||
|
KW_TRUE=194
|
||||||
|
KW_TRY_CAST=195
|
||||||
|
KW_TRUNCATE=196
|
||||||
|
KW_UNCACHED=197
|
||||||
|
KW_UESCAPE=198
|
||||||
|
KW_UNBOUNDED=199
|
||||||
|
KW_UNION=200
|
||||||
|
KW_UNNEST=201
|
||||||
|
KW_UNSET=202
|
||||||
|
KW_USE=203
|
||||||
|
KW_USER=204
|
||||||
|
KW_USING=205
|
||||||
|
KW_UPDATE_FN=206
|
||||||
|
KW_UPSERT=207
|
||||||
|
KW_URI=208
|
||||||
|
KW_VALUE=209
|
||||||
|
KW_VALUES=210
|
||||||
|
KW_VIEW=211
|
||||||
|
KW_VIEWS=212
|
||||||
|
KW_WHEN=213
|
||||||
|
KW_WHERE=214
|
||||||
|
KW_WITH=215
|
||||||
|
KW_YEAR=216
|
||||||
|
KW_YEARS=217
|
||||||
|
KW_TEXTFILE=218
|
||||||
|
KW_ORC=219
|
||||||
|
KW_AVRO=220
|
||||||
|
KW_SEQUENCEFILE=221
|
||||||
|
KW_RCFILE=222
|
||||||
|
KW_REFERENCES=223
|
||||||
|
KW_NOVALIDATE=224
|
||||||
|
KW_RELY=225
|
||||||
|
STATS_NUMDVS=226
|
||||||
|
STATS_NUMNULLS=227
|
||||||
|
STATS_AVGSIZE=228
|
||||||
|
STATS_MAXSIZE=229
|
||||||
|
EQ=230
|
||||||
|
NEQ=231
|
||||||
|
LT=232
|
||||||
|
LTE=233
|
||||||
|
GT=234
|
||||||
|
GTE=235
|
||||||
|
PLUS=236
|
||||||
|
MINUS=237
|
||||||
|
ASTERISK=238
|
||||||
|
SLASH=239
|
||||||
|
PERCENT=240
|
||||||
|
CONCAT=241
|
||||||
|
DOT=242
|
||||||
|
SEMICOLON=243
|
||||||
|
COMMA=244
|
||||||
|
COLON=245
|
||||||
|
LPAREN=246
|
||||||
|
RPAREN=247
|
||||||
|
LSQUARE=248
|
||||||
|
RSQUARE=249
|
||||||
|
LCURLY=250
|
||||||
|
RCURLY=251
|
||||||
|
BITWISEOR=252
|
||||||
|
QUESTION=253
|
||||||
|
RIGHT_ARROW=254
|
||||||
|
STRING=255
|
||||||
|
UNICODE_STRING=256
|
||||||
|
BINARY_LITERAL=257
|
||||||
|
INTEGER_VALUE=258
|
||||||
|
DECIMAL_VALUE=259
|
||||||
|
DOUBLE_VALUE=260
|
||||||
|
IDENTIFIER=261
|
||||||
|
DIGIT_IDENTIFIER=262
|
||||||
|
QUOTED_IDENTIFIER=263
|
||||||
|
BACKQUOTED_IDENTIFIER=264
|
||||||
|
TIME_WITH_TIME_ZONE=265
|
||||||
|
TIMESTAMP_WITH_TIME_ZONE=266
|
||||||
|
DOUBLE_PRECISION=267
|
||||||
|
SIMPLE_COMMENT=268
|
||||||
|
BRACKETED_COMMENT=269
|
||||||
|
WS=270
|
||||||
|
'ADD'=1
|
||||||
|
'ALL'=2
|
||||||
|
'ANALYTIC'=3
|
||||||
|
'ALTER'=4
|
||||||
|
'AND'=5
|
||||||
|
'ANY'=6
|
||||||
|
'ANTI'=7
|
||||||
|
'ARRAY'=8
|
||||||
|
'AS'=9
|
||||||
|
'ASC'=10
|
||||||
|
'AT'=11
|
||||||
|
'AGGREGATE'=12
|
||||||
|
'AUTHORIZATION'=13
|
||||||
|
'BERNOULLI'=14
|
||||||
|
'BETWEEN'=15
|
||||||
|
'BLOCK_SIZE'=16
|
||||||
|
'PARTITIONED'=17
|
||||||
|
'PREPARE_FN'=18
|
||||||
|
'EXTERNAL'=19
|
||||||
|
'CLOSEFN'=20
|
||||||
|
'SORT'=21
|
||||||
|
'PURGE'=22
|
||||||
|
'STORED'=23
|
||||||
|
'LOCATION'=24
|
||||||
|
'TBLPROPERTIES'=25
|
||||||
|
'BY'=26
|
||||||
|
'CASCADE'=27
|
||||||
|
'CASE'=28
|
||||||
|
'CAST'=29
|
||||||
|
'CACHED'=30
|
||||||
|
'CHANGE'=31
|
||||||
|
'COLUMN'=32
|
||||||
|
'COLUMNS'=33
|
||||||
|
'COMMENT'=34
|
||||||
|
'COMPRESSION'=35
|
||||||
|
'COMPUTE'=36
|
||||||
|
'CREATE'=37
|
||||||
|
'CROSS'=38
|
||||||
|
'CURRENT'=39
|
||||||
|
'CURRENT_DATE'=40
|
||||||
|
'CURRENT_PATH'=41
|
||||||
|
'CURRENT_TIME'=42
|
||||||
|
'CURRENT_TIMESTAMP'=43
|
||||||
|
'CURRENT_USER'=44
|
||||||
|
'DATA'=45
|
||||||
|
'DATABASE'=46
|
||||||
|
'DATABASES'=47
|
||||||
|
'DAY'=48
|
||||||
|
'DAYS'=49
|
||||||
|
'DELETE'=50
|
||||||
|
'DEFAULT'=51
|
||||||
|
'DELIMITED'=52
|
||||||
|
'DISABLE'=53
|
||||||
|
'UPDATE'=54
|
||||||
|
'DESC'=55
|
||||||
|
'DESCRIBE'=56
|
||||||
|
'DISTINCT'=57
|
||||||
|
'DROP'=58
|
||||||
|
'ELSE'=59
|
||||||
|
'ENCODING'=60
|
||||||
|
'END'=61
|
||||||
|
'ESCAPE'=62
|
||||||
|
'ESCAPED'=63
|
||||||
|
'EXCEPT'=64
|
||||||
|
'EXCLUDING'=65
|
||||||
|
'EXISTS'=66
|
||||||
|
'EXPLAIN'=67
|
||||||
|
'EXTRACT'=68
|
||||||
|
'EXTENDED'=69
|
||||||
|
'FALSE'=70
|
||||||
|
'FIELDS'=71
|
||||||
|
'FILEFORMAT'=72
|
||||||
|
'FILES'=73
|
||||||
|
'FILTER'=74
|
||||||
|
'FIRST'=75
|
||||||
|
'FINALIZE_FN'=76
|
||||||
|
'FOLLOWING'=77
|
||||||
|
'FOR'=78
|
||||||
|
'FORMAT'=79
|
||||||
|
'FORMATTED'=80
|
||||||
|
'FOREIGN'=81
|
||||||
|
'FROM'=82
|
||||||
|
'FULL'=83
|
||||||
|
'FUNCTION'=84
|
||||||
|
'FUNCTIONS'=85
|
||||||
|
'GRANT'=86
|
||||||
|
'GROUP'=87
|
||||||
|
'GROUPING'=88
|
||||||
|
'HASH'=89
|
||||||
|
'HAVING'=90
|
||||||
|
'HOUR'=91
|
||||||
|
'HOURS'=92
|
||||||
|
'IF'=93
|
||||||
|
'IN'=94
|
||||||
|
'INCLUDING'=95
|
||||||
|
'INCREMENTAL'=96
|
||||||
|
'INNER'=97
|
||||||
|
'INPATH'=98
|
||||||
|
'INSERT'=99
|
||||||
|
'INTERSECT'=100
|
||||||
|
'INTERVAL'=101
|
||||||
|
'INTERMEDIATE'=102
|
||||||
|
'INTO'=103
|
||||||
|
'INIT_FN'=104
|
||||||
|
'INVALIDATE'=105
|
||||||
|
'IS'=106
|
||||||
|
'JOIN'=107
|
||||||
|
'KEY'=108
|
||||||
|
'KUDU'=109
|
||||||
|
'LAST'=110
|
||||||
|
'LATERAL'=111
|
||||||
|
'LEFT'=112
|
||||||
|
'LIKE'=113
|
||||||
|
'LIMIT'=114
|
||||||
|
'LINES'=115
|
||||||
|
'LOAD'=116
|
||||||
|
'LOCALTIME'=117
|
||||||
|
'LOCALTIMESTAMP'=118
|
||||||
|
'METADATA'=119
|
||||||
|
'MAP'=120
|
||||||
|
'MINUTE'=121
|
||||||
|
'MINUTES'=122
|
||||||
|
'MONTH'=123
|
||||||
|
'MONTHS'=124
|
||||||
|
'MERGE_FN'=125
|
||||||
|
'NFC'=126
|
||||||
|
'NFD'=127
|
||||||
|
'NFKC'=128
|
||||||
|
'NFKD'=129
|
||||||
|
'NORMALIZE'=130
|
||||||
|
'NOT'=131
|
||||||
|
'NULL'=132
|
||||||
|
'NULLS'=133
|
||||||
|
'OFFSET'=134
|
||||||
|
'ON'=135
|
||||||
|
'OPTION'=136
|
||||||
|
'OR'=137
|
||||||
|
'ORDER'=138
|
||||||
|
'ORDINALITY'=139
|
||||||
|
'OUTER'=140
|
||||||
|
'OWNER'=141
|
||||||
|
'OVER'=142
|
||||||
|
'OVERWRITE'=143
|
||||||
|
'PARTITION'=144
|
||||||
|
'PARTITIONS'=145
|
||||||
|
'PARQUET'=146
|
||||||
|
'POSITION'=147
|
||||||
|
'PRECEDING'=148
|
||||||
|
'PRIMARY'=149
|
||||||
|
'REPLICATION'=150
|
||||||
|
'PRIVILEGES'=151
|
||||||
|
'PROPERTIES'=152
|
||||||
|
'RANGE'=153
|
||||||
|
'RECOVER'=154
|
||||||
|
'RENAME'=155
|
||||||
|
'REPEATABLE'=156
|
||||||
|
'REPLACE'=157
|
||||||
|
'RESTRICT'=158
|
||||||
|
'RETURNS'=159
|
||||||
|
'REVOKE'=160
|
||||||
|
'REFRESH'=161
|
||||||
|
'REGEXP'=162
|
||||||
|
'RLIKE'=163
|
||||||
|
'RIGHT'=164
|
||||||
|
'ROLE'=165
|
||||||
|
'ROLES'=166
|
||||||
|
'ROW'=167
|
||||||
|
'ROWS'=168
|
||||||
|
'SCHEMA'=169
|
||||||
|
'SCHEMAS'=170
|
||||||
|
'SECOND'=171
|
||||||
|
'SECONDS'=172
|
||||||
|
'SELECT'=173
|
||||||
|
'SERDEPROPERTIES'=174
|
||||||
|
'SET'=175
|
||||||
|
'SEMI'=176
|
||||||
|
'SERVER'=177
|
||||||
|
'SHOW'=178
|
||||||
|
'SHUTDOWN'=179
|
||||||
|
'SOME'=180
|
||||||
|
'STATS'=181
|
||||||
|
'STRUCT'=182
|
||||||
|
'STRAIGHT_JOIN'=183
|
||||||
|
'SUBSTRING'=184
|
||||||
|
'SYSTEM'=185
|
||||||
|
'SYMBOL'=186
|
||||||
|
'SERIALIZE_FN'=187
|
||||||
|
'TABLE'=188
|
||||||
|
'TABLES'=189
|
||||||
|
'TABLESAMPLE'=190
|
||||||
|
'TERMINATED '=191
|
||||||
|
'THEN'=192
|
||||||
|
'TO'=193
|
||||||
|
'TRUE'=194
|
||||||
|
'TRY_CAST'=195
|
||||||
|
'TRUNCATE'=196
|
||||||
|
'UNCACHED'=197
|
||||||
|
'UESCAPE'=198
|
||||||
|
'UNBOUNDED'=199
|
||||||
|
'UNION'=200
|
||||||
|
'UNNEST'=201
|
||||||
|
'UNSET'=202
|
||||||
|
'USE'=203
|
||||||
|
'USER'=204
|
||||||
|
'USING'=205
|
||||||
|
'UPDATE_FN'=206
|
||||||
|
'UPSERT'=207
|
||||||
|
'URI'=208
|
||||||
|
'VALUE'=209
|
||||||
|
'VALUES'=210
|
||||||
|
'VIEW'=211
|
||||||
|
'VIEWS'=212
|
||||||
|
'WHEN'=213
|
||||||
|
'WHERE'=214
|
||||||
|
'WITH'=215
|
||||||
|
'YEAR'=216
|
||||||
|
'YEARS'=217
|
||||||
|
'TEXTFILE'=218
|
||||||
|
'ORC'=219
|
||||||
|
'AVRO'=220
|
||||||
|
'SEQUENCEFILE'=221
|
||||||
|
'RCFILE'=222
|
||||||
|
'REFERENCES'=223
|
||||||
|
'NOVALIDATE'=224
|
||||||
|
'RELY'=225
|
||||||
|
'\'NUMDVS\''=226
|
||||||
|
'\'NUMNULLS\''=227
|
||||||
|
'\'AVGSIZE\''=228
|
||||||
|
'\'MAXSIZE\''=229
|
||||||
|
'='=230
|
||||||
|
'<'=232
|
||||||
|
'<='=233
|
||||||
|
'>'=234
|
||||||
|
'>='=235
|
||||||
|
'+'=236
|
||||||
|
'-'=237
|
||||||
|
'*'=238
|
||||||
|
'/'=239
|
||||||
|
'%'=240
|
||||||
|
'||'=241
|
||||||
|
'.'=242
|
||||||
|
';'=243
|
||||||
|
','=244
|
||||||
|
':'=245
|
||||||
|
'('=246
|
||||||
|
')'=247
|
||||||
|
'['=248
|
||||||
|
']'=249
|
||||||
|
'{'=250
|
||||||
|
'}'=251
|
||||||
|
'|'=252
|
||||||
|
'?'=253
|
||||||
|
'->'=254
|
1749
src/lib/impala/ImpalaSqlLexer.ts
Normal file
1749
src/lib/impala/ImpalaSqlLexer.ts
Normal file
File diff suppressed because it is too large
Load Diff
731
src/lib/impala/ImpalaSqlParser.interp
Normal file
731
src/lib/impala/ImpalaSqlParser.interp
Normal file
File diff suppressed because one or more lines are too long
523
src/lib/impala/ImpalaSqlParser.tokens
Normal file
523
src/lib/impala/ImpalaSqlParser.tokens
Normal file
@ -0,0 +1,523 @@
|
|||||||
|
KW_ADD=1
|
||||||
|
KW_ALL=2
|
||||||
|
KW_ANALYTIC=3
|
||||||
|
KW_ALTER=4
|
||||||
|
KW_AND=5
|
||||||
|
KW_ANY=6
|
||||||
|
KW_ANTI=7
|
||||||
|
KW_ARRAY=8
|
||||||
|
KW_AS=9
|
||||||
|
KW_ASC=10
|
||||||
|
KW_AT=11
|
||||||
|
KW_AGGREGATE=12
|
||||||
|
KW_AUTHORIZATION=13
|
||||||
|
KW_BERNOULLI=14
|
||||||
|
KW_BETWEEN=15
|
||||||
|
KW_BLOCK_SIZE=16
|
||||||
|
KW_PARTITIONED=17
|
||||||
|
KW_PREPARE_FN=18
|
||||||
|
KW_EXTERNAL=19
|
||||||
|
KW_CLOSEFN=20
|
||||||
|
KW_SORT=21
|
||||||
|
KW_PURGE=22
|
||||||
|
KW_STORED=23
|
||||||
|
KW_LOCATION=24
|
||||||
|
KW_TBLPROPERTIES=25
|
||||||
|
KW_BY=26
|
||||||
|
KW_CASCADE=27
|
||||||
|
KW_CASE=28
|
||||||
|
KW_CAST=29
|
||||||
|
KW_CACHED=30
|
||||||
|
KW_CHANGE=31
|
||||||
|
KW_COLUMN=32
|
||||||
|
KW_COLUMNS=33
|
||||||
|
KW_COMMENT=34
|
||||||
|
KW_COMPRESSION=35
|
||||||
|
KW_COMPUTE=36
|
||||||
|
KW_CREATE=37
|
||||||
|
KW_CROSS=38
|
||||||
|
KW_CURRENT=39
|
||||||
|
KW_CURRENT_DATE=40
|
||||||
|
KW_CURRENT_PATH=41
|
||||||
|
KW_CURRENT_TIME=42
|
||||||
|
KW_CURRENT_TIMESTAMP=43
|
||||||
|
KW_CURRENT_USER=44
|
||||||
|
KW_DATA=45
|
||||||
|
KW_DATABASE=46
|
||||||
|
KW_DATABASES=47
|
||||||
|
KW_DAY=48
|
||||||
|
KW_DAYS=49
|
||||||
|
KW_DELETE=50
|
||||||
|
KW_DEFAULT=51
|
||||||
|
KW_DELIMITED=52
|
||||||
|
KW_DISABLE=53
|
||||||
|
KW_UPDATE=54
|
||||||
|
KW_DESC=55
|
||||||
|
KW_DESCRIBE=56
|
||||||
|
KW_DISTINCT=57
|
||||||
|
KW_DROP=58
|
||||||
|
KW_ELSE=59
|
||||||
|
KW_ENCODING=60
|
||||||
|
KW_END=61
|
||||||
|
KW_ESCAPE=62
|
||||||
|
KW_ESCAPED=63
|
||||||
|
KW_EXCEPT=64
|
||||||
|
KW_EXCLUDING=65
|
||||||
|
KW_EXISTS=66
|
||||||
|
KW_EXPLAIN=67
|
||||||
|
KW_EXTRACT=68
|
||||||
|
KW_EXTENDED=69
|
||||||
|
KW_FALSE=70
|
||||||
|
KW_FIELDS=71
|
||||||
|
KW_FILEFORMAT=72
|
||||||
|
KW_FILES=73
|
||||||
|
KW_FILTER=74
|
||||||
|
KW_FIRST=75
|
||||||
|
KW_FINALIZE_FN=76
|
||||||
|
KW_FOLLOWING=77
|
||||||
|
KW_FOR=78
|
||||||
|
KW_FORMAT=79
|
||||||
|
KW_FORMATTED=80
|
||||||
|
KW_FOREIGN=81
|
||||||
|
KW_FROM=82
|
||||||
|
KW_FULL=83
|
||||||
|
KW_FUNCTION=84
|
||||||
|
KW_FUNCTIONS=85
|
||||||
|
KW_GRANT=86
|
||||||
|
KW_GROUP=87
|
||||||
|
KW_GROUPING=88
|
||||||
|
KW_HASH=89
|
||||||
|
KW_HAVING=90
|
||||||
|
KW_HOUR=91
|
||||||
|
KW_HOURS=92
|
||||||
|
KW_IF=93
|
||||||
|
KW_IN=94
|
||||||
|
KW_INCLUDING=95
|
||||||
|
KW_INCREMENTAL=96
|
||||||
|
KW_INNER=97
|
||||||
|
KW_INPATH=98
|
||||||
|
KW_INSERT=99
|
||||||
|
KW_INTERSECT=100
|
||||||
|
KW_INTERVAL=101
|
||||||
|
KW_INTERMEDIATE=102
|
||||||
|
KW_INTO=103
|
||||||
|
KW_INIT_FN=104
|
||||||
|
KW_INVALIDATE=105
|
||||||
|
KW_IS=106
|
||||||
|
KW_JOIN=107
|
||||||
|
KW_KEY=108
|
||||||
|
KW_KUDU=109
|
||||||
|
KW_LAST=110
|
||||||
|
KW_LATERAL=111
|
||||||
|
KW_LEFT=112
|
||||||
|
KW_LIKE=113
|
||||||
|
KW_LIMIT=114
|
||||||
|
KW_LINES=115
|
||||||
|
KW_LOAD=116
|
||||||
|
KW_LOCALTIME=117
|
||||||
|
KW_LOCALTIMESTAMP=118
|
||||||
|
KW_METADATA=119
|
||||||
|
KW_MAP=120
|
||||||
|
KW_MINUTE=121
|
||||||
|
KW_MINUTES=122
|
||||||
|
KW_MONTH=123
|
||||||
|
KW_MONTHS=124
|
||||||
|
KW_MERGE_FN=125
|
||||||
|
KW_NFC=126
|
||||||
|
KW_NFD=127
|
||||||
|
KW_NFKC=128
|
||||||
|
KW_NFKD=129
|
||||||
|
KW_NORMALIZE=130
|
||||||
|
KW_NOT=131
|
||||||
|
KW_NULL=132
|
||||||
|
KW_NULLS=133
|
||||||
|
KW_OFFSET=134
|
||||||
|
KW_ON=135
|
||||||
|
KW_OPTION=136
|
||||||
|
KW_OR=137
|
||||||
|
KW_ORDER=138
|
||||||
|
KW_ORDINALITY=139
|
||||||
|
KW_OUTER=140
|
||||||
|
KW_OWNER=141
|
||||||
|
KW_OVER=142
|
||||||
|
KW_OVERWRITE=143
|
||||||
|
KW_PARTITION=144
|
||||||
|
KW_PARTITIONS=145
|
||||||
|
KW_PARQUET=146
|
||||||
|
KW_POSITION=147
|
||||||
|
KW_PRECEDING=148
|
||||||
|
KW_PRIMARY=149
|
||||||
|
KW_REPLICATION=150
|
||||||
|
KW_PRIVILEGES=151
|
||||||
|
KW_PROPERTIES=152
|
||||||
|
KW_RANGE=153
|
||||||
|
KW_RECOVER=154
|
||||||
|
KW_RENAME=155
|
||||||
|
KW_REPEATABLE=156
|
||||||
|
KW_REPLACE=157
|
||||||
|
KW_RESTRICT=158
|
||||||
|
KW_RETURNS=159
|
||||||
|
KW_REVOKE=160
|
||||||
|
KW_REFRESH=161
|
||||||
|
KW_REGEXP=162
|
||||||
|
KW_RLIKE=163
|
||||||
|
KW_RIGHT=164
|
||||||
|
KW_ROLE=165
|
||||||
|
KW_ROLES=166
|
||||||
|
KW_ROW=167
|
||||||
|
KW_ROWS=168
|
||||||
|
KW_SCHEMA=169
|
||||||
|
KW_SCHEMAS=170
|
||||||
|
KW_SECOND=171
|
||||||
|
KW_SECONDS=172
|
||||||
|
KW_SELECT=173
|
||||||
|
KW_SERDEPROPERTIES=174
|
||||||
|
KW_SET=175
|
||||||
|
KW_SEMI=176
|
||||||
|
KW_SERVER=177
|
||||||
|
KW_SHOW=178
|
||||||
|
KW_SHUTDOWN=179
|
||||||
|
KW_SOME=180
|
||||||
|
KW_STATS=181
|
||||||
|
KW_STRUCT=182
|
||||||
|
KW_STRAIGHT_JOIN=183
|
||||||
|
KW_SUBSTRING=184
|
||||||
|
KW_SYSTEM=185
|
||||||
|
KW_SYMBOL=186
|
||||||
|
KW_SERIALIZE_FN=187
|
||||||
|
KW_TABLE=188
|
||||||
|
KW_TABLES=189
|
||||||
|
KW_TABLESAMPLE=190
|
||||||
|
KW_TERMINATED=191
|
||||||
|
KW_THEN=192
|
||||||
|
KW_TO=193
|
||||||
|
KW_TRUE=194
|
||||||
|
KW_TRY_CAST=195
|
||||||
|
KW_TRUNCATE=196
|
||||||
|
KW_UNCACHED=197
|
||||||
|
KW_UESCAPE=198
|
||||||
|
KW_UNBOUNDED=199
|
||||||
|
KW_UNION=200
|
||||||
|
KW_UNNEST=201
|
||||||
|
KW_UNSET=202
|
||||||
|
KW_USE=203
|
||||||
|
KW_USER=204
|
||||||
|
KW_USING=205
|
||||||
|
KW_UPDATE_FN=206
|
||||||
|
KW_UPSERT=207
|
||||||
|
KW_URI=208
|
||||||
|
KW_VALUE=209
|
||||||
|
KW_VALUES=210
|
||||||
|
KW_VIEW=211
|
||||||
|
KW_VIEWS=212
|
||||||
|
KW_WHEN=213
|
||||||
|
KW_WHERE=214
|
||||||
|
KW_WITH=215
|
||||||
|
KW_YEAR=216
|
||||||
|
KW_YEARS=217
|
||||||
|
KW_TEXTFILE=218
|
||||||
|
KW_ORC=219
|
||||||
|
KW_AVRO=220
|
||||||
|
KW_SEQUENCEFILE=221
|
||||||
|
KW_RCFILE=222
|
||||||
|
KW_REFERENCES=223
|
||||||
|
KW_NOVALIDATE=224
|
||||||
|
KW_RELY=225
|
||||||
|
STATS_NUMDVS=226
|
||||||
|
STATS_NUMNULLS=227
|
||||||
|
STATS_AVGSIZE=228
|
||||||
|
STATS_MAXSIZE=229
|
||||||
|
EQ=230
|
||||||
|
NEQ=231
|
||||||
|
LT=232
|
||||||
|
LTE=233
|
||||||
|
GT=234
|
||||||
|
GTE=235
|
||||||
|
PLUS=236
|
||||||
|
MINUS=237
|
||||||
|
ASTERISK=238
|
||||||
|
SLASH=239
|
||||||
|
PERCENT=240
|
||||||
|
CONCAT=241
|
||||||
|
DOT=242
|
||||||
|
SEMICOLON=243
|
||||||
|
COMMA=244
|
||||||
|
COLON=245
|
||||||
|
LPAREN=246
|
||||||
|
RPAREN=247
|
||||||
|
LSQUARE=248
|
||||||
|
RSQUARE=249
|
||||||
|
LCURLY=250
|
||||||
|
RCURLY=251
|
||||||
|
BITWISEOR=252
|
||||||
|
QUESTION=253
|
||||||
|
RIGHT_ARROW=254
|
||||||
|
STRING=255
|
||||||
|
UNICODE_STRING=256
|
||||||
|
BINARY_LITERAL=257
|
||||||
|
INTEGER_VALUE=258
|
||||||
|
DECIMAL_VALUE=259
|
||||||
|
DOUBLE_VALUE=260
|
||||||
|
IDENTIFIER=261
|
||||||
|
DIGIT_IDENTIFIER=262
|
||||||
|
QUOTED_IDENTIFIER=263
|
||||||
|
BACKQUOTED_IDENTIFIER=264
|
||||||
|
TIME_WITH_TIME_ZONE=265
|
||||||
|
TIMESTAMP_WITH_TIME_ZONE=266
|
||||||
|
DOUBLE_PRECISION=267
|
||||||
|
SIMPLE_COMMENT=268
|
||||||
|
BRACKETED_COMMENT=269
|
||||||
|
WS=270
|
||||||
|
'ADD'=1
|
||||||
|
'ALL'=2
|
||||||
|
'ANALYTIC'=3
|
||||||
|
'ALTER'=4
|
||||||
|
'AND'=5
|
||||||
|
'ANY'=6
|
||||||
|
'ANTI'=7
|
||||||
|
'ARRAY'=8
|
||||||
|
'AS'=9
|
||||||
|
'ASC'=10
|
||||||
|
'AT'=11
|
||||||
|
'AGGREGATE'=12
|
||||||
|
'AUTHORIZATION'=13
|
||||||
|
'BERNOULLI'=14
|
||||||
|
'BETWEEN'=15
|
||||||
|
'BLOCK_SIZE'=16
|
||||||
|
'PARTITIONED'=17
|
||||||
|
'PREPARE_FN'=18
|
||||||
|
'EXTERNAL'=19
|
||||||
|
'CLOSEFN'=20
|
||||||
|
'SORT'=21
|
||||||
|
'PURGE'=22
|
||||||
|
'STORED'=23
|
||||||
|
'LOCATION'=24
|
||||||
|
'TBLPROPERTIES'=25
|
||||||
|
'BY'=26
|
||||||
|
'CASCADE'=27
|
||||||
|
'CASE'=28
|
||||||
|
'CAST'=29
|
||||||
|
'CACHED'=30
|
||||||
|
'CHANGE'=31
|
||||||
|
'COLUMN'=32
|
||||||
|
'COLUMNS'=33
|
||||||
|
'COMMENT'=34
|
||||||
|
'COMPRESSION'=35
|
||||||
|
'COMPUTE'=36
|
||||||
|
'CREATE'=37
|
||||||
|
'CROSS'=38
|
||||||
|
'CURRENT'=39
|
||||||
|
'CURRENT_DATE'=40
|
||||||
|
'CURRENT_PATH'=41
|
||||||
|
'CURRENT_TIME'=42
|
||||||
|
'CURRENT_TIMESTAMP'=43
|
||||||
|
'CURRENT_USER'=44
|
||||||
|
'DATA'=45
|
||||||
|
'DATABASE'=46
|
||||||
|
'DATABASES'=47
|
||||||
|
'DAY'=48
|
||||||
|
'DAYS'=49
|
||||||
|
'DELETE'=50
|
||||||
|
'DEFAULT'=51
|
||||||
|
'DELIMITED'=52
|
||||||
|
'DISABLE'=53
|
||||||
|
'UPDATE'=54
|
||||||
|
'DESC'=55
|
||||||
|
'DESCRIBE'=56
|
||||||
|
'DISTINCT'=57
|
||||||
|
'DROP'=58
|
||||||
|
'ELSE'=59
|
||||||
|
'ENCODING'=60
|
||||||
|
'END'=61
|
||||||
|
'ESCAPE'=62
|
||||||
|
'ESCAPED'=63
|
||||||
|
'EXCEPT'=64
|
||||||
|
'EXCLUDING'=65
|
||||||
|
'EXISTS'=66
|
||||||
|
'EXPLAIN'=67
|
||||||
|
'EXTRACT'=68
|
||||||
|
'EXTENDED'=69
|
||||||
|
'FALSE'=70
|
||||||
|
'FIELDS'=71
|
||||||
|
'FILEFORMAT'=72
|
||||||
|
'FILES'=73
|
||||||
|
'FILTER'=74
|
||||||
|
'FIRST'=75
|
||||||
|
'FINALIZE_FN'=76
|
||||||
|
'FOLLOWING'=77
|
||||||
|
'FOR'=78
|
||||||
|
'FORMAT'=79
|
||||||
|
'FORMATTED'=80
|
||||||
|
'FOREIGN'=81
|
||||||
|
'FROM'=82
|
||||||
|
'FULL'=83
|
||||||
|
'FUNCTION'=84
|
||||||
|
'FUNCTIONS'=85
|
||||||
|
'GRANT'=86
|
||||||
|
'GROUP'=87
|
||||||
|
'GROUPING'=88
|
||||||
|
'HASH'=89
|
||||||
|
'HAVING'=90
|
||||||
|
'HOUR'=91
|
||||||
|
'HOURS'=92
|
||||||
|
'IF'=93
|
||||||
|
'IN'=94
|
||||||
|
'INCLUDING'=95
|
||||||
|
'INCREMENTAL'=96
|
||||||
|
'INNER'=97
|
||||||
|
'INPATH'=98
|
||||||
|
'INSERT'=99
|
||||||
|
'INTERSECT'=100
|
||||||
|
'INTERVAL'=101
|
||||||
|
'INTERMEDIATE'=102
|
||||||
|
'INTO'=103
|
||||||
|
'INIT_FN'=104
|
||||||
|
'INVALIDATE'=105
|
||||||
|
'IS'=106
|
||||||
|
'JOIN'=107
|
||||||
|
'KEY'=108
|
||||||
|
'KUDU'=109
|
||||||
|
'LAST'=110
|
||||||
|
'LATERAL'=111
|
||||||
|
'LEFT'=112
|
||||||
|
'LIKE'=113
|
||||||
|
'LIMIT'=114
|
||||||
|
'LINES'=115
|
||||||
|
'LOAD'=116
|
||||||
|
'LOCALTIME'=117
|
||||||
|
'LOCALTIMESTAMP'=118
|
||||||
|
'METADATA'=119
|
||||||
|
'MAP'=120
|
||||||
|
'MINUTE'=121
|
||||||
|
'MINUTES'=122
|
||||||
|
'MONTH'=123
|
||||||
|
'MONTHS'=124
|
||||||
|
'MERGE_FN'=125
|
||||||
|
'NFC'=126
|
||||||
|
'NFD'=127
|
||||||
|
'NFKC'=128
|
||||||
|
'NFKD'=129
|
||||||
|
'NORMALIZE'=130
|
||||||
|
'NOT'=131
|
||||||
|
'NULL'=132
|
||||||
|
'NULLS'=133
|
||||||
|
'OFFSET'=134
|
||||||
|
'ON'=135
|
||||||
|
'OPTION'=136
|
||||||
|
'OR'=137
|
||||||
|
'ORDER'=138
|
||||||
|
'ORDINALITY'=139
|
||||||
|
'OUTER'=140
|
||||||
|
'OWNER'=141
|
||||||
|
'OVER'=142
|
||||||
|
'OVERWRITE'=143
|
||||||
|
'PARTITION'=144
|
||||||
|
'PARTITIONS'=145
|
||||||
|
'PARQUET'=146
|
||||||
|
'POSITION'=147
|
||||||
|
'PRECEDING'=148
|
||||||
|
'PRIMARY'=149
|
||||||
|
'REPLICATION'=150
|
||||||
|
'PRIVILEGES'=151
|
||||||
|
'PROPERTIES'=152
|
||||||
|
'RANGE'=153
|
||||||
|
'RECOVER'=154
|
||||||
|
'RENAME'=155
|
||||||
|
'REPEATABLE'=156
|
||||||
|
'REPLACE'=157
|
||||||
|
'RESTRICT'=158
|
||||||
|
'RETURNS'=159
|
||||||
|
'REVOKE'=160
|
||||||
|
'REFRESH'=161
|
||||||
|
'REGEXP'=162
|
||||||
|
'RLIKE'=163
|
||||||
|
'RIGHT'=164
|
||||||
|
'ROLE'=165
|
||||||
|
'ROLES'=166
|
||||||
|
'ROW'=167
|
||||||
|
'ROWS'=168
|
||||||
|
'SCHEMA'=169
|
||||||
|
'SCHEMAS'=170
|
||||||
|
'SECOND'=171
|
||||||
|
'SECONDS'=172
|
||||||
|
'SELECT'=173
|
||||||
|
'SERDEPROPERTIES'=174
|
||||||
|
'SET'=175
|
||||||
|
'SEMI'=176
|
||||||
|
'SERVER'=177
|
||||||
|
'SHOW'=178
|
||||||
|
'SHUTDOWN'=179
|
||||||
|
'SOME'=180
|
||||||
|
'STATS'=181
|
||||||
|
'STRUCT'=182
|
||||||
|
'STRAIGHT_JOIN'=183
|
||||||
|
'SUBSTRING'=184
|
||||||
|
'SYSTEM'=185
|
||||||
|
'SYMBOL'=186
|
||||||
|
'SERIALIZE_FN'=187
|
||||||
|
'TABLE'=188
|
||||||
|
'TABLES'=189
|
||||||
|
'TABLESAMPLE'=190
|
||||||
|
'TERMINATED '=191
|
||||||
|
'THEN'=192
|
||||||
|
'TO'=193
|
||||||
|
'TRUE'=194
|
||||||
|
'TRY_CAST'=195
|
||||||
|
'TRUNCATE'=196
|
||||||
|
'UNCACHED'=197
|
||||||
|
'UESCAPE'=198
|
||||||
|
'UNBOUNDED'=199
|
||||||
|
'UNION'=200
|
||||||
|
'UNNEST'=201
|
||||||
|
'UNSET'=202
|
||||||
|
'USE'=203
|
||||||
|
'USER'=204
|
||||||
|
'USING'=205
|
||||||
|
'UPDATE_FN'=206
|
||||||
|
'UPSERT'=207
|
||||||
|
'URI'=208
|
||||||
|
'VALUE'=209
|
||||||
|
'VALUES'=210
|
||||||
|
'VIEW'=211
|
||||||
|
'VIEWS'=212
|
||||||
|
'WHEN'=213
|
||||||
|
'WHERE'=214
|
||||||
|
'WITH'=215
|
||||||
|
'YEAR'=216
|
||||||
|
'YEARS'=217
|
||||||
|
'TEXTFILE'=218
|
||||||
|
'ORC'=219
|
||||||
|
'AVRO'=220
|
||||||
|
'SEQUENCEFILE'=221
|
||||||
|
'RCFILE'=222
|
||||||
|
'REFERENCES'=223
|
||||||
|
'NOVALIDATE'=224
|
||||||
|
'RELY'=225
|
||||||
|
'\'NUMDVS\''=226
|
||||||
|
'\'NUMNULLS\''=227
|
||||||
|
'\'AVGSIZE\''=228
|
||||||
|
'\'MAXSIZE\''=229
|
||||||
|
'='=230
|
||||||
|
'<'=232
|
||||||
|
'<='=233
|
||||||
|
'>'=234
|
||||||
|
'>='=235
|
||||||
|
'+'=236
|
||||||
|
'-'=237
|
||||||
|
'*'=238
|
||||||
|
'/'=239
|
||||||
|
'%'=240
|
||||||
|
'||'=241
|
||||||
|
'.'=242
|
||||||
|
';'=243
|
||||||
|
','=244
|
||||||
|
':'=245
|
||||||
|
'('=246
|
||||||
|
')'=247
|
||||||
|
'['=248
|
||||||
|
']'=249
|
||||||
|
'{'=250
|
||||||
|
'}'=251
|
||||||
|
'|'=252
|
||||||
|
'?'=253
|
||||||
|
'->'=254
|
25304
src/lib/impala/ImpalaSqlParser.ts
Normal file
25304
src/lib/impala/ImpalaSqlParser.ts
Normal file
File diff suppressed because one or more lines are too long
3195
src/lib/impala/ImpalaSqlParserListener.ts
Normal file
3195
src/lib/impala/ImpalaSqlParserListener.ts
Normal file
File diff suppressed because it is too large
Load Diff
2113
src/lib/impala/ImpalaSqlParserVisitor.ts
Normal file
2113
src/lib/impala/ImpalaSqlParserVisitor.ts
Normal file
File diff suppressed because it is too large
Load Diff
139
src/parser/impala.ts
Normal file
139
src/parser/impala.ts
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
import { Token } from 'antlr4ts';
|
||||||
|
import { CandidatesCollection } from 'antlr4-c3';
|
||||||
|
import { ImpalaSqlLexer } from '../lib/impala/ImpalaSqlLexer';
|
||||||
|
import { ImpalaSqlParser, ProgramContext, StatementContext } from '../lib/impala/ImpalaSqlParser';
|
||||||
|
import BasicParser from './common/basicParser';
|
||||||
|
import { ImpalaSqlParserListener } from '../lib/impala/ImpalaSqlParserListener';
|
||||||
|
import { SyntaxContextType, Suggestions, SyntaxSuggestion } from './common/basic-parser-types';
|
||||||
|
|
||||||
|
export default class ImpalaSQL extends BasicParser<
|
||||||
|
ImpalaSqlLexer,
|
||||||
|
ProgramContext,
|
||||||
|
ImpalaSqlParser
|
||||||
|
> {
|
||||||
|
protected createLexerFormCharStream(charStreams) {
|
||||||
|
const lexer = new ImpalaSqlLexer(charStreams);
|
||||||
|
return lexer;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected createParserFromTokenStream(tokenStream) {
|
||||||
|
return new ImpalaSqlParser(tokenStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected preferredRules: Set<number> = new Set([
|
||||||
|
ImpalaSqlParser.RULE_functionNameCreate,
|
||||||
|
ImpalaSqlParser.RULE_tableNameCreate,
|
||||||
|
ImpalaSqlParser.RULE_viewNameCreate,
|
||||||
|
ImpalaSqlParser.RULE_databaseNameCreate,
|
||||||
|
ImpalaSqlParser.RULE_columnNamePathCreate,
|
||||||
|
ImpalaSqlParser.RULE_tableNamePath,
|
||||||
|
ImpalaSqlParser.RULE_functionNamePath,
|
||||||
|
ImpalaSqlParser.RULE_viewNamePath,
|
||||||
|
ImpalaSqlParser.RULE_databaseNamePath,
|
||||||
|
ImpalaSqlParser.RULE_columnNamePath,
|
||||||
|
]);
|
||||||
|
|
||||||
|
protected get splitListener() {
|
||||||
|
return new ImpalaSqlSplitListener();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected processCandidates(
|
||||||
|
candidates: CandidatesCollection,
|
||||||
|
allTokens: Token[],
|
||||||
|
caretTokenIndex: number,
|
||||||
|
tokenIndexOffset: number
|
||||||
|
): Suggestions<Token> {
|
||||||
|
const originalSyntaxSuggestions: SyntaxSuggestion<Token>[] = [];
|
||||||
|
const keywords: string[] = [];
|
||||||
|
for (let candidate of candidates.rules) {
|
||||||
|
const [ruleType, candidateRule] = candidate;
|
||||||
|
const startTokenIndex = candidateRule.startTokenIndex + tokenIndexOffset;
|
||||||
|
const tokenRanges = allTokens.slice(
|
||||||
|
startTokenIndex,
|
||||||
|
caretTokenIndex + tokenIndexOffset + 1
|
||||||
|
);
|
||||||
|
|
||||||
|
let syntaxContextType: SyntaxContextType;
|
||||||
|
switch (ruleType) {
|
||||||
|
case ImpalaSqlParser.RULE_functionNameCreate: {
|
||||||
|
syntaxContextType = SyntaxContextType.FUNCTION_CREATE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ImpalaSqlParser.RULE_tableNameCreate: {
|
||||||
|
syntaxContextType = SyntaxContextType.TABLE_CREATE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ImpalaSqlParser.RULE_databaseNameCreate: {
|
||||||
|
syntaxContextType = SyntaxContextType.DATABASE_CREATE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ImpalaSqlParser.RULE_viewNameCreate: {
|
||||||
|
syntaxContextType = SyntaxContextType.VIEW_CREATE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ImpalaSqlParser.RULE_columnNamePathCreate: {
|
||||||
|
syntaxContextType = SyntaxContextType.COLUMN_CREATE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ImpalaSqlParser.RULE_databaseNamePath: {
|
||||||
|
syntaxContextType = SyntaxContextType.DATABASE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ImpalaSqlParser.RULE_tableNamePath: {
|
||||||
|
syntaxContextType = SyntaxContextType.TABLE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ImpalaSqlParser.RULE_viewNamePath: {
|
||||||
|
syntaxContextType = SyntaxContextType.VIEW;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ImpalaSqlParser.RULE_functionNamePath: {
|
||||||
|
syntaxContextType = SyntaxContextType.FUNCTION;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ImpalaSqlParser.RULE_columnNamePath: {
|
||||||
|
syntaxContextType = SyntaxContextType.COLUMN;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (syntaxContextType) {
|
||||||
|
originalSyntaxSuggestions.push({
|
||||||
|
syntaxContextType,
|
||||||
|
wordRanges: tokenRanges,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let candidate of candidates.tokens) {
|
||||||
|
const symbolicName = this._parser.vocabulary.getSymbolicName(candidate[0]);
|
||||||
|
const displayName = this._parser.vocabulary.getDisplayName(candidate[0]);
|
||||||
|
if (symbolicName && symbolicName.startsWith('KW_')) {
|
||||||
|
const keyword =
|
||||||
|
displayName.startsWith("'") && displayName.endsWith("'")
|
||||||
|
? displayName.slice(1, -1)
|
||||||
|
: displayName;
|
||||||
|
keywords.push(keyword);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
syntax: originalSyntaxSuggestions,
|
||||||
|
keywords,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ImpalaSqlSplitListener implements ImpalaSqlParserListener {
|
||||||
|
private _statementContext: StatementContext[] = [];
|
||||||
|
|
||||||
|
exitStatement = (ctx: StatementContext) => {
|
||||||
|
this._statementContext.push(ctx);
|
||||||
|
};
|
||||||
|
|
||||||
|
enterStatement = (ctx: StatementContext) => {};
|
||||||
|
|
||||||
|
get statementsContext() {
|
||||||
|
return this._statementContext;
|
||||||
|
}
|
||||||
|
}
|
@ -5,3 +5,4 @@ export { default as FlinkSQL } from './flinksql';
|
|||||||
export { default as SparkSQL } from './spark';
|
export { default as SparkSQL } from './spark';
|
||||||
export { default as PostgresSQL } from './pgsql';
|
export { default as PostgresSQL } from './pgsql';
|
||||||
export { default as TrinoSQL } from './trinosql';
|
export { default as TrinoSQL } from './trinosql';
|
||||||
|
export { default as ImpalaSQL } from './impala';
|
||||||
|
12
test/parser/impala/lexer.test.ts
Normal file
12
test/parser/impala/lexer.test.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import ImpalaSQL from '../../../src/parser/impala';
|
||||||
|
|
||||||
|
describe('ImpalaSQL Lexer tests', () => {
|
||||||
|
const parser = new ImpalaSQL();
|
||||||
|
|
||||||
|
const sql = 'SELECT * FROM table1';
|
||||||
|
const tokens = parser.getAllTokens(sql);
|
||||||
|
|
||||||
|
test('token counts', () => {
|
||||||
|
expect(tokens.length).toBe(7);
|
||||||
|
});
|
||||||
|
});
|
24
test/parser/impala/listener.test.ts
Normal file
24
test/parser/impala/listener.test.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import impalaSQL from '../../../src/parser/impala';
|
||||||
|
import { ImpalaSqlParserListener } from '../../../src/lib/impala/ImpalaSqlParserListener';
|
||||||
|
import { ParseTreeListener } from 'antlr4ts/tree';
|
||||||
|
|
||||||
|
describe('impala SQL Listener Tests', () => {
|
||||||
|
const expectTableName = 'user1';
|
||||||
|
const sql = `select id,name,sex from ${expectTableName};`;
|
||||||
|
const parser = new impalaSQL();
|
||||||
|
|
||||||
|
const parseTree = parser.parse(sql);
|
||||||
|
|
||||||
|
test('Listener enterTableName', async () => {
|
||||||
|
let result = '';
|
||||||
|
class MyListener implements ImpalaSqlParserListener {
|
||||||
|
enterTableNamePath = (ctx): void => {
|
||||||
|
result = ctx.text.toLowerCase();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const listenTableName = new MyListener();
|
||||||
|
|
||||||
|
await parser.listen(listenTableName as ParseTreeListener, parseTree);
|
||||||
|
expect(result).toBe(expectTableName);
|
||||||
|
});
|
||||||
|
});
|
45
test/parser/impala/suggestion/fixtures/syntaxSuggestion.sql
Normal file
45
test/parser/impala/suggestion/fixtures/syntaxSuggestion.sql
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
SELECT * FROM cat.a;
|
||||||
|
|
||||||
|
SELECT name, calculate_age(birthdate) AS age FROM students;
|
||||||
|
|
||||||
|
ALTER DATABASE cat;
|
||||||
|
|
||||||
|
ALTER TABLE my_table CHANGE COLUMN age;
|
||||||
|
|
||||||
|
ALTER VIEW my_view;
|
||||||
|
|
||||||
|
DROP VIEW v;
|
||||||
|
|
||||||
|
DROP DATABASE my_db;
|
||||||
|
|
||||||
|
DROP TABLE my_table;
|
||||||
|
|
||||||
|
DROP FUNCTION my_func;
|
||||||
|
|
||||||
|
DELETE FROM my_table WHERE col1 LIKE 'prefix%';
|
||||||
|
|
||||||
|
CREATE VIEW cv;
|
||||||
|
|
||||||
|
CREATE TABLE cat.db ;
|
||||||
|
|
||||||
|
CREATE FUNCTION fnc;
|
||||||
|
|
||||||
|
CREATE DATABASE FIRST_DB;
|
||||||
|
|
||||||
|
SHOW TABLES in cat;
|
||||||
|
|
||||||
|
SHOW COLUMN STATS vie;
|
||||||
|
|
||||||
|
SHOW CREATE TABLE tb1;
|
||||||
|
|
||||||
|
SHOW CREATE VIEW v1;
|
||||||
|
|
||||||
|
SELECT id GROUP BY id;
|
||||||
|
|
||||||
|
SELECT id ORDER BY id;
|
||||||
|
|
||||||
|
CREATE TABLE census_data (last_name STRING);
|
||||||
|
|
||||||
|
ALTER TABLE my_table ADD COLUMN age INT COMMENT 'Updated Age';
|
||||||
|
|
||||||
|
CREATE TABLE kudu_no_partition_by_clause (id bigint PRIMARY KEY, s STRING, b BOOLEAN ) STORED AS KUDU;
|
@ -0,0 +1,9 @@
|
|||||||
|
ALTER ;
|
||||||
|
|
||||||
|
CREATE ;
|
||||||
|
|
||||||
|
DROP ;
|
||||||
|
|
||||||
|
INSERT ;
|
||||||
|
|
||||||
|
SHOW ;
|
349
test/parser/impala/suggestion/syntaxSuggestion.test.ts
Normal file
349
test/parser/impala/suggestion/syntaxSuggestion.test.ts
Normal file
@ -0,0 +1,349 @@
|
|||||||
|
import fs from 'fs';
|
||||||
|
import path from 'path';
|
||||||
|
import { CaretPosition, SyntaxContextType } from '../../../../src/parser/common/basic-parser-types';
|
||||||
|
import ImpalaSQL from '../../../../src/parser/impala';
|
||||||
|
|
||||||
|
const syntaxSql = fs.readFileSync(
|
||||||
|
path.join(__dirname, 'fixtures', 'syntaxSuggestion.sql'),
|
||||||
|
'utf-8'
|
||||||
|
);
|
||||||
|
|
||||||
|
describe('Impala SQL Syntax Suggestion', () => {
|
||||||
|
const parser = new ImpalaSQL();
|
||||||
|
|
||||||
|
test('Select table', () => {
|
||||||
|
const pos: CaretPosition = {
|
||||||
|
lineNumber: 1,
|
||||||
|
column: 20,
|
||||||
|
};
|
||||||
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||||
|
const suggestion = syntaxes?.find(
|
||||||
|
(syn) => syn.syntaxContextType === SyntaxContextType.TABLE
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(suggestion).not.toBeUndefined();
|
||||||
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['cat', '.', 'a']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Function call', () => {
|
||||||
|
const pos: CaretPosition = {
|
||||||
|
lineNumber: 3,
|
||||||
|
column: 27,
|
||||||
|
};
|
||||||
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||||
|
const suggestion = syntaxes?.find(
|
||||||
|
(syn) => syn.syntaxContextType === SyntaxContextType.FUNCTION
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(suggestion).not.toBeUndefined();
|
||||||
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['calculate_age']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Alter database', () => {
|
||||||
|
const pos: CaretPosition = {
|
||||||
|
lineNumber: 5,
|
||||||
|
column: 19,
|
||||||
|
};
|
||||||
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||||
|
const suggestion = syntaxes?.find(
|
||||||
|
(syn) => syn.syntaxContextType === SyntaxContextType.DATABASE
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(suggestion).not.toBeUndefined();
|
||||||
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['cat']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Alter table', () => {
|
||||||
|
const pos: CaretPosition = {
|
||||||
|
lineNumber: 7,
|
||||||
|
column: 21,
|
||||||
|
};
|
||||||
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||||
|
const suggestion = syntaxes?.find(
|
||||||
|
(syn) => syn.syntaxContextType === SyntaxContextType.TABLE
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(suggestion).not.toBeUndefined();
|
||||||
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['my_table']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Alter table column', () => {
|
||||||
|
const pos: CaretPosition = {
|
||||||
|
lineNumber: 7,
|
||||||
|
column: 39,
|
||||||
|
};
|
||||||
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||||
|
const suggestion = syntaxes?.find(
|
||||||
|
(syn) => syn.syntaxContextType === SyntaxContextType.COLUMN
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(suggestion).not.toBeUndefined();
|
||||||
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['age']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Alter view', () => {
|
||||||
|
const pos: CaretPosition = {
|
||||||
|
lineNumber: 9,
|
||||||
|
column: 19,
|
||||||
|
};
|
||||||
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||||
|
const suggestion = syntaxes?.find(
|
||||||
|
(syn) => syn.syntaxContextType === SyntaxContextType.VIEW
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(suggestion).not.toBeUndefined();
|
||||||
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['my_view']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Drop view', () => {
|
||||||
|
const pos: CaretPosition = {
|
||||||
|
lineNumber: 11,
|
||||||
|
column: 12,
|
||||||
|
};
|
||||||
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||||
|
const suggestion = syntaxes?.find(
|
||||||
|
(syn) => syn.syntaxContextType === SyntaxContextType.VIEW
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(suggestion).not.toBeUndefined();
|
||||||
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['v']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Drop database', () => {
|
||||||
|
const pos: CaretPosition = {
|
||||||
|
lineNumber: 13,
|
||||||
|
column: 20,
|
||||||
|
};
|
||||||
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||||
|
const suggestion = syntaxes?.find(
|
||||||
|
(syn) => syn.syntaxContextType === SyntaxContextType.DATABASE
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(suggestion).not.toBeUndefined();
|
||||||
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['my_db']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Drop table', () => {
|
||||||
|
const pos: CaretPosition = {
|
||||||
|
lineNumber: 15,
|
||||||
|
column: 20,
|
||||||
|
};
|
||||||
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||||
|
const suggestion = syntaxes?.find(
|
||||||
|
(syn) => syn.syntaxContextType === SyntaxContextType.TABLE
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(suggestion).not.toBeUndefined();
|
||||||
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['my_table']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Drop function', () => {
|
||||||
|
const pos: CaretPosition = {
|
||||||
|
lineNumber: 17,
|
||||||
|
column: 22,
|
||||||
|
};
|
||||||
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||||
|
const suggestion = syntaxes?.find(
|
||||||
|
(syn) => syn.syntaxContextType === SyntaxContextType.FUNCTION
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(suggestion).not.toBeUndefined();
|
||||||
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['my_func']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('DELETE table', () => {
|
||||||
|
const pos: CaretPosition = {
|
||||||
|
lineNumber: 19,
|
||||||
|
column: 21,
|
||||||
|
};
|
||||||
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||||
|
const suggestion = syntaxes?.find(
|
||||||
|
(syn) => syn.syntaxContextType === SyntaxContextType.TABLE
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(suggestion).not.toBeUndefined();
|
||||||
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['my_table']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Create view', () => {
|
||||||
|
const pos: CaretPosition = {
|
||||||
|
lineNumber: 21,
|
||||||
|
column: 15,
|
||||||
|
};
|
||||||
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||||
|
const suggestion = syntaxes?.find(
|
||||||
|
(syn) => syn.syntaxContextType === SyntaxContextType.VIEW_CREATE
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(suggestion).not.toBeUndefined();
|
||||||
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['cv']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Create table', () => {
|
||||||
|
const pos: CaretPosition = {
|
||||||
|
lineNumber: 23,
|
||||||
|
column: 20,
|
||||||
|
};
|
||||||
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||||
|
const suggestion = syntaxes?.find(
|
||||||
|
(syn) => syn.syntaxContextType === SyntaxContextType.TABLE_CREATE
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(suggestion).not.toBeUndefined();
|
||||||
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['cat', '.', 'db']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Create Function', () => {
|
||||||
|
const pos: CaretPosition = {
|
||||||
|
lineNumber: 25,
|
||||||
|
column: 20,
|
||||||
|
};
|
||||||
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||||
|
const suggestion = syntaxes?.find(
|
||||||
|
(syn) => syn.syntaxContextType === SyntaxContextType.FUNCTION_CREATE
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(suggestion).not.toBeUndefined();
|
||||||
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['fnc']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Create database', () => {
|
||||||
|
const pos: CaretPosition = {
|
||||||
|
lineNumber: 27,
|
||||||
|
column: 25,
|
||||||
|
};
|
||||||
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||||
|
const suggestion = syntaxes?.find(
|
||||||
|
(syn) => syn.syntaxContextType === SyntaxContextType.DATABASE_CREATE
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(suggestion).not.toBeUndefined();
|
||||||
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['FIRST_DB']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Show tables in', () => {
|
||||||
|
const pos: CaretPosition = {
|
||||||
|
lineNumber: 29,
|
||||||
|
column: 19,
|
||||||
|
};
|
||||||
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||||
|
const suggestion = syntaxes?.find(
|
||||||
|
(syn) => syn.syntaxContextType === SyntaxContextType.TABLE
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(suggestion).not.toBeUndefined();
|
||||||
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['cat']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Show column stats table', () => {
|
||||||
|
const pos: CaretPosition = {
|
||||||
|
lineNumber: 31,
|
||||||
|
column: 22,
|
||||||
|
};
|
||||||
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||||
|
const suggestion = syntaxes?.find(
|
||||||
|
(syn) => syn.syntaxContextType === SyntaxContextType.TABLE
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(suggestion).not.toBeUndefined();
|
||||||
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['vie']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Show create table', () => {
|
||||||
|
const pos: CaretPosition = {
|
||||||
|
lineNumber: 33,
|
||||||
|
column: 22,
|
||||||
|
};
|
||||||
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||||
|
const suggestion = syntaxes?.find(
|
||||||
|
(syn) => syn.syntaxContextType === SyntaxContextType.TABLE
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(suggestion).not.toBeUndefined();
|
||||||
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['tb1']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Show create view', () => {
|
||||||
|
const pos: CaretPosition = {
|
||||||
|
lineNumber: 35,
|
||||||
|
column: 20,
|
||||||
|
};
|
||||||
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||||
|
const suggestion = syntaxes?.find(
|
||||||
|
(syn) => syn.syntaxContextType === SyntaxContextType.VIEW
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(suggestion).not.toBeUndefined();
|
||||||
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['v1']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Select group by', () => {
|
||||||
|
const pos: CaretPosition = {
|
||||||
|
lineNumber: 37,
|
||||||
|
column: 22,
|
||||||
|
};
|
||||||
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||||
|
const suggestion = syntaxes?.find(
|
||||||
|
(syn) => syn.syntaxContextType === SyntaxContextType.COLUMN
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(suggestion).not.toBeUndefined();
|
||||||
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['id']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Select order by', () => {
|
||||||
|
const pos: CaretPosition = {
|
||||||
|
lineNumber: 39,
|
||||||
|
column: 22,
|
||||||
|
};
|
||||||
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||||
|
const suggestion = syntaxes?.find(
|
||||||
|
(syn) => syn.syntaxContextType === SyntaxContextType.COLUMN
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(suggestion).not.toBeUndefined();
|
||||||
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['id']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Create Table column', () => {
|
||||||
|
const pos: CaretPosition = {
|
||||||
|
lineNumber: 41,
|
||||||
|
column: 36,
|
||||||
|
};
|
||||||
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||||
|
const suggestion = syntaxes?.find(
|
||||||
|
(syn) => syn.syntaxContextType === SyntaxContextType.COLUMN_CREATE
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(suggestion).not.toBeUndefined();
|
||||||
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['last_name']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Alert Table column', () => {
|
||||||
|
const pos: CaretPosition = {
|
||||||
|
lineNumber: 43,
|
||||||
|
column: 36,
|
||||||
|
};
|
||||||
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||||
|
const suggestion = syntaxes?.find(
|
||||||
|
(syn) => syn.syntaxContextType === SyntaxContextType.COLUMN_CREATE
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(suggestion).not.toBeUndefined();
|
||||||
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['age']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Create Table kudu', () => {
|
||||||
|
const pos: CaretPosition = {
|
||||||
|
lineNumber: 45,
|
||||||
|
column: 45,
|
||||||
|
};
|
||||||
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||||
|
const suggestion = syntaxes?.find(
|
||||||
|
(syn) => syn.syntaxContextType === SyntaxContextType.COLUMN_CREATE
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(suggestion).not.toBeUndefined();
|
||||||
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['id']);
|
||||||
|
});
|
||||||
|
});
|
109
test/parser/impala/suggestion/tokenSuggestion.test.ts
Normal file
109
test/parser/impala/suggestion/tokenSuggestion.test.ts
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
import fs from 'fs';
|
||||||
|
import path from 'path';
|
||||||
|
import { CaretPosition } from '../../../../src/parser/common/basic-parser-types';
|
||||||
|
import impalaSQL from '../../../../src/parser/impala';
|
||||||
|
import { commentOtherLine } from '../../../helper';
|
||||||
|
|
||||||
|
const tokenSql = fs.readFileSync(path.join(__dirname, 'fixtures', 'tokenSuggestion.sql'), 'utf-8');
|
||||||
|
|
||||||
|
describe('Impala SQL Token Suggestion', () => {
|
||||||
|
const parser = new impalaSQL();
|
||||||
|
|
||||||
|
test('After ALTER', () => {
|
||||||
|
const pos: CaretPosition = {
|
||||||
|
lineNumber: 1,
|
||||||
|
column: 7,
|
||||||
|
};
|
||||||
|
const suggestion = parser.getSuggestionAtCaretPosition(tokenSql, pos)?.keywords;
|
||||||
|
|
||||||
|
expect(suggestion).toEqual(['TABLE', 'VIEW', 'DATABASE']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('After CREATE', () => {
|
||||||
|
const pos: CaretPosition = {
|
||||||
|
lineNumber: 3,
|
||||||
|
column: 8,
|
||||||
|
};
|
||||||
|
const suggestion = parser.getSuggestionAtCaretPosition(
|
||||||
|
commentOtherLine(tokenSql, pos.lineNumber),
|
||||||
|
pos
|
||||||
|
)?.keywords;
|
||||||
|
|
||||||
|
expect(suggestion).toEqual([
|
||||||
|
'TABLE',
|
||||||
|
'EXTERNAL',
|
||||||
|
'VIEW',
|
||||||
|
'FUNCTION',
|
||||||
|
'AGGREGATE',
|
||||||
|
'ROLE',
|
||||||
|
'DATABASE',
|
||||||
|
'SCHEMA',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('After DROP', () => {
|
||||||
|
const pos: CaretPosition = {
|
||||||
|
lineNumber: 5,
|
||||||
|
column: 6,
|
||||||
|
};
|
||||||
|
const suggestion = parser.getSuggestionAtCaretPosition(
|
||||||
|
commentOtherLine(tokenSql, pos.lineNumber),
|
||||||
|
pos
|
||||||
|
)?.keywords;
|
||||||
|
|
||||||
|
expect(suggestion).toEqual([
|
||||||
|
'DATABASE',
|
||||||
|
'SCHEMA',
|
||||||
|
'TABLE',
|
||||||
|
'VIEW',
|
||||||
|
'STATS',
|
||||||
|
'INCREMENTAL',
|
||||||
|
'FUNCTION',
|
||||||
|
'AGGREGATE',
|
||||||
|
'ROLE',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('After INSERT', () => {
|
||||||
|
const pos: CaretPosition = {
|
||||||
|
lineNumber: 7,
|
||||||
|
column: 8,
|
||||||
|
};
|
||||||
|
const suggestion = parser.getSuggestionAtCaretPosition(
|
||||||
|
commentOtherLine(tokenSql, pos.lineNumber),
|
||||||
|
pos
|
||||||
|
)?.keywords;
|
||||||
|
|
||||||
|
expect(suggestion).toEqual(['INTO', 'OVERWRITE']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('After SHOW', () => {
|
||||||
|
const pos: CaretPosition = {
|
||||||
|
lineNumber: 9,
|
||||||
|
column: 6,
|
||||||
|
};
|
||||||
|
const suggestion = parser.getSuggestionAtCaretPosition(
|
||||||
|
commentOtherLine(tokenSql, pos.lineNumber),
|
||||||
|
pos
|
||||||
|
)?.keywords;
|
||||||
|
|
||||||
|
expect(suggestion).toEqual([
|
||||||
|
'DATABASES',
|
||||||
|
'SCHEMAS',
|
||||||
|
'TABLES',
|
||||||
|
'FUNCTIONS',
|
||||||
|
'ANALYTIC',
|
||||||
|
'AGGREGATE',
|
||||||
|
'CREATE',
|
||||||
|
'TABLE',
|
||||||
|
'COLUMN',
|
||||||
|
'PARTITIONS',
|
||||||
|
'RANGE',
|
||||||
|
'FILES',
|
||||||
|
'GRANT',
|
||||||
|
'ROLE',
|
||||||
|
'ROLES',
|
||||||
|
'CURRENT',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
34
test/parser/impala/syntax/alterStatement.test.ts
Normal file
34
test/parser/impala/syntax/alterStatement.test.ts
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import ImpalaSQL from '../../../../src/parser/impala';
|
||||||
|
import { readSQL } from '../../../helper';
|
||||||
|
|
||||||
|
const parser = new ImpalaSQL();
|
||||||
|
|
||||||
|
const features = {
|
||||||
|
tables: readSQL(__dirname, 'alter_table.sql'),
|
||||||
|
dbs: readSQL(__dirname, 'alter_db.sql'),
|
||||||
|
views: readSQL(__dirname, 'alter_view.sql'),
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('ImpalaSQL Alter Syntax Tests', () => {
|
||||||
|
describe('ALTER TABLE', () => {
|
||||||
|
features.tables.forEach((db) => {
|
||||||
|
it(db, () => {
|
||||||
|
expect(parser.validate(db).length).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('ALTER DATABASE', () => {
|
||||||
|
features.dbs.forEach((db) => {
|
||||||
|
it(db, () => {
|
||||||
|
expect(parser.validate(db).length).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('ALTER VIEW', () => {
|
||||||
|
features.views.forEach((db) => {
|
||||||
|
it(db, () => {
|
||||||
|
expect(parser.validate(db).length).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
50
test/parser/impala/syntax/creataStatement.test.ts
Normal file
50
test/parser/impala/syntax/creataStatement.test.ts
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
import ImpalaSQL from '../../../../src/parser/impala';
|
||||||
|
import { readSQL } from '../../../helper';
|
||||||
|
|
||||||
|
const parser = new ImpalaSQL();
|
||||||
|
|
||||||
|
const features = {
|
||||||
|
dbs: readSQL(__dirname, 'create_db.sql'),
|
||||||
|
functions: readSQL(__dirname, 'create_function.sql'),
|
||||||
|
roles: readSQL(__dirname, 'create_role.sql'),
|
||||||
|
tables: readSQL(__dirname, 'create_table.sql'),
|
||||||
|
views: readSQL(__dirname, 'create_view.sql'),
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('ImpalaSQL Create Syntax Tests', () => {
|
||||||
|
describe('CREATE DB', () => {
|
||||||
|
features.dbs.forEach((db) => {
|
||||||
|
it(db, () => {
|
||||||
|
expect(parser.validate(db).length).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('CREATE FUNCTION', () => {
|
||||||
|
features.functions.forEach((db) => {
|
||||||
|
it(db, () => {
|
||||||
|
expect(parser.validate(db).length).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('CREATE ROLE', () => {
|
||||||
|
features.roles.forEach((db) => {
|
||||||
|
it(db, () => {
|
||||||
|
expect(parser.validate(db).length).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('CREATE TABLE', () => {
|
||||||
|
features.tables.forEach((db) => {
|
||||||
|
it(db, () => {
|
||||||
|
expect(parser.validate(db).length).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('CREATE VIEW', () => {
|
||||||
|
features.views.forEach((db) => {
|
||||||
|
it(db, () => {
|
||||||
|
expect(parser.validate(db).length).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
18
test/parser/impala/syntax/delete.test.ts
Normal file
18
test/parser/impala/syntax/delete.test.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import ImpalaSQL from '../../../../src/parser/impala';
|
||||||
|
import { readSQL } from '../../../helper';
|
||||||
|
|
||||||
|
const parser = new ImpalaSQL();
|
||||||
|
|
||||||
|
const features = {
|
||||||
|
deletes: readSQL(__dirname, 'delete.sql'),
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('ImpalaSQL Delete Syntax Tests', () => {
|
||||||
|
describe('DELETE', () => {
|
||||||
|
features.deletes.forEach((db) => {
|
||||||
|
it(db, () => {
|
||||||
|
expect(parser.validate(db).length).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
58
test/parser/impala/syntax/dropStatement.test.ts
Normal file
58
test/parser/impala/syntax/dropStatement.test.ts
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
import ImpalaSQL from '../../../../src/parser/impala';
|
||||||
|
import { readSQL } from '../../../helper';
|
||||||
|
|
||||||
|
const parser = new ImpalaSQL();
|
||||||
|
|
||||||
|
const features = {
|
||||||
|
dbs: readSQL(__dirname, 'drop_db.sql'),
|
||||||
|
functions: readSQL(__dirname, 'drop_function.sql'),
|
||||||
|
roles: readSQL(__dirname, 'drop_role.sql'),
|
||||||
|
stats: readSQL(__dirname, 'drop_stats.sql'),
|
||||||
|
tables: readSQL(__dirname, 'drop_table.sql'),
|
||||||
|
views: readSQL(__dirname, 'drop_view.sql'),
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('ImpalaSQL Drop Syntax Tests', () => {
|
||||||
|
describe('DROP DATABASE', () => {
|
||||||
|
features.dbs.forEach((db) => {
|
||||||
|
it(db, () => {
|
||||||
|
expect(parser.validate(db).length).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('DROP FUNCTION', () => {
|
||||||
|
features.functions.forEach((db) => {
|
||||||
|
it(db, () => {
|
||||||
|
expect(parser.validate(db).length).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('DROP ROLE', () => {
|
||||||
|
features.roles.forEach((db) => {
|
||||||
|
it(db, () => {
|
||||||
|
expect(parser.validate(db).length).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('DROP STATS', () => {
|
||||||
|
features.stats.forEach((db) => {
|
||||||
|
it(db, () => {
|
||||||
|
expect(parser.validate(db).length).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('DROP TABLE', () => {
|
||||||
|
features.tables.forEach((db) => {
|
||||||
|
it(db, () => {
|
||||||
|
expect(parser.validate(db).length).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('DROP VIEW', () => {
|
||||||
|
features.views.forEach((db) => {
|
||||||
|
it(db, () => {
|
||||||
|
expect(parser.validate(db).length).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
2
test/parser/impala/syntax/fixtures/alter_db.sql
Normal file
2
test/parser/impala/syntax/fixtures/alter_db.sql
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
-- ALTER DATABASE database_name SET OWNER USER user_name;
|
||||||
|
ALTER DATABASE my_db SET OWNER USER 'impala';
|
133
test/parser/impala/syntax/fixtures/alter_table.sql
Normal file
133
test/parser/impala/syntax/fixtures/alter_table.sql
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
-- ALTER TABLE [old_db_name.]old_table_name RENAME TO [new_db_name.]new_table_name
|
||||||
|
ALTER TABLE old_table_name RENAME TO new_table_name;
|
||||||
|
ALTER TABLE old_db_name.old_table_name RENAME TO new_table_name;
|
||||||
|
ALTER TABLE old_table_name RENAME TO new_db_name.new_table_name;
|
||||||
|
ALTER TABLE old_db_name.old_table_name RENAME TO new_db_name.new_table_name;
|
||||||
|
|
||||||
|
-- ALTER TABLE name ADD [IF NOT EXISTS] COLUMNS (col_spec[, col_spec ...])
|
||||||
|
ALTER TABLE my_table ADD COLUMNS (id INT COMMENT 'Identifier', name STRING COMMENT 'Name');
|
||||||
|
ALTER TABLE my_table ADD IF NOT EXISTS COLUMNS (age INT COMMENT 'Age');
|
||||||
|
ALTER TABLE my_table ADD COLUMNS (email STRING COMMENT 'Email');
|
||||||
|
|
||||||
|
-- ALTER TABLE name REPLACE COLUMNS (col_spec[, col_spec ...])
|
||||||
|
ALTER TABLE my_table REPLACE COLUMNS (age INT COMMENT 'Updated Age');
|
||||||
|
ALTER TABLE my_table REPLACE COLUMNS (email STRING COMMENT 'Updated Email', address STRING COMMENT 'Updated Address');
|
||||||
|
|
||||||
|
-- ALTER TABLE name ADD COLUMN [IF NOT EXISTS] col_spec
|
||||||
|
ALTER TABLE my_table ADD COLUMN age INT COMMENT 'Updated Age';
|
||||||
|
ALTER TABLE my_table ADD COLUMN IF NOT EXISTS age INT COMMENT 'Updated Age';
|
||||||
|
|
||||||
|
-- ALTER TABLE name DROP [COLUMN] column_name
|
||||||
|
ALTER TABLE my_table DROP COLUMN column_name;
|
||||||
|
ALTER TABLE my_table DROP column_name;
|
||||||
|
|
||||||
|
-- ALTER TABLE name CHANGE column_name col_spec
|
||||||
|
ALTER TABLE my_table CHANGE COLUMN age INT COMMENT 'Updated Age';
|
||||||
|
|
||||||
|
-- ALTER TABLE name SET OWNER USER user_name
|
||||||
|
ALTER TABLE my_table SET OWNER USER user_name;
|
||||||
|
|
||||||
|
/* Kudu tables only.
|
||||||
|
ALTER TABLE name ALTER [COLUMN] column_name
|
||||||
|
{ SET kudu_storage_attr attr_value
|
||||||
|
| DROP DEFAULT } */
|
||||||
|
ALTER TABLE my_table ALTER COLUMN size SET BLOCK_SIZE 1024 ;
|
||||||
|
ALTER TABLE my_table ALTER COLUMN id SET DEFAULT 0 ;
|
||||||
|
ALTER TABLE my_table ALTER COLUMN name SET ENCODING 'plain' ;
|
||||||
|
ALTER TABLE my_table ALTER COLUMN address SET COMPRESSION 'lz4';
|
||||||
|
ALTER TABLE my_table ALTER COLUMN id DROP DEFAULT;
|
||||||
|
|
||||||
|
/* Non-Kudu tables only.
|
||||||
|
ALTER TABLE name ALTER [COLUMN] column_name
|
||||||
|
SET COMMENT 'comment_text' */
|
||||||
|
ALTER TABLE my_table ALTER age SET COMMENT '年龄';
|
||||||
|
ALTER TABLE my_table ALTER COLUMN age SET COMMENT '年龄';
|
||||||
|
|
||||||
|
/* ALTER TABLE name ADD [IF NOT EXISTS] PARTITION (partition_spec)
|
||||||
|
[location_spec]
|
||||||
|
[cache_spec] */
|
||||||
|
ALTER TABLE my_table ADD PARTITION (date = '2023-01-01');
|
||||||
|
ALTER TABLE my_table ADD IF NOT EXISTS PARTITION (date = '2023-01-01');
|
||||||
|
ALTER TABLE my_table ADD PARTITION (country = 'USA') LOCATION '/path/to/partition';
|
||||||
|
ALTER TABLE my_table ADD IF NOT EXISTS PARTITION (category = 'Books') LOCATION '/path/to/books_partition';
|
||||||
|
ALTER TABLE my_table ADD PARTITION (date = '2023-01-01') CACHED IN 'pool_name' WITH REPLICATION = 3;
|
||||||
|
ALTER TABLE my_table ADD IF NOT EXISTS PARTITION (date = '2023-01-01') CACHED IN 'pool_name' WITH REPLICATION = 3;
|
||||||
|
ALTER TABLE my_table ADD PARTITION (country = 'USA') UNCACHED;
|
||||||
|
ALTER TABLE my_table ADD IF NOT EXISTS PARTITION (country = 'USA') UNCACHED;
|
||||||
|
|
||||||
|
-- ALTER TABLE name ADD [IF NOT EXISTS] RANGE PARTITION kudu_partition_spec
|
||||||
|
ALTER TABLE my_table ADD RANGE PARTITION VALUE = 100;
|
||||||
|
ALTER TABLE my_table ADD IF NOT EXISTS RANGE PARTITION 10 < VALUES < 20;
|
||||||
|
|
||||||
|
|
||||||
|
/* ALTER TABLE name DROP [IF EXISTS] PARTITION (partition_spec)
|
||||||
|
[PURGE] */
|
||||||
|
ALTER TABLE my_table DROP PARTITION (date = '2023-01-01');
|
||||||
|
ALTER TABLE my_table DROP IF EXISTS PARTITION (name = 'impala');
|
||||||
|
|
||||||
|
-- ALTER TABLE name DROP [IF EXISTS] RANGE PARTITION kudu_partition_spec
|
||||||
|
ALTER TABLE my_table DROP RANGE PARTITION VALUE != 100;
|
||||||
|
ALTER TABLE my_table DROP IF EXISTS RANGE PARTITION 10 >= VALUES < 20;
|
||||||
|
|
||||||
|
-- ALTER TABLE name RECOVER PARTITIONS
|
||||||
|
ALTER TABLE my_table RECOVER PARTITIONS
|
||||||
|
|
||||||
|
/* ALTER TABLE name [PARTITION (partition_spec)]
|
||||||
|
SET { FILEFORMAT file_format
|
||||||
|
| ROW FORMAT row_format
|
||||||
|
| LOCATION 'hdfs_path_of_directory'
|
||||||
|
| TBLPROPERTIES (table_properties)
|
||||||
|
| SERDEPROPERTIES (serde_properties) } */
|
||||||
|
ALTER TABLE my_table SET FILEFORMAT parquet ;
|
||||||
|
ALTER TABLE my_table PARTITION (date = '2023-01-01') SET FILEFORMAT orc;
|
||||||
|
ALTER TABLE my_table SET ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';
|
||||||
|
ALTER TABLE my_table SET LOCATION '/path/to/new_location';
|
||||||
|
ALTER TABLE my_table PARTITION (region = 'Europe') SET LOCATION '/path/to/europe_partition';
|
||||||
|
ALTER TABLE my_table SET TBLPROPERTIES ('comment' = 'This is a table');
|
||||||
|
ALTER TABLE my_table PARTITION (category = 'Books') SET TBLPROPERTIES ('compression' = 'gzip');
|
||||||
|
ALTER TABLE my_table SET SERDEPROPERTIES ('field.delim' = '|');
|
||||||
|
ALTER TABLE my_table PARTITION (date = '2023-01-01') SET SERDEPROPERTIES ('serialization.null.format' = '\N');
|
||||||
|
|
||||||
|
/* ALTER TABLE name colname
|
||||||
|
('statsKey'='val', ...) */
|
||||||
|
alter table t1 set column stats x ('numDVs'='2','numNulls'='0');
|
||||||
|
alter table t1 set column stats s ('numdvs'='3','maxsize'='4');
|
||||||
|
|
||||||
|
-- ALTER TABLE name [PARTITION (partition_spec)] SET { CACHED IN 'pool_name' [WITH REPLICATION = integer] | UNCACHED }
|
||||||
|
ALTER TABLE my_table SET CACHED IN 'pool_name';
|
||||||
|
ALTER TABLE my_table PARTITION (date = '2023-01-01') SET CACHED IN 'pool_name';
|
||||||
|
ALTER TABLE my_table SET CACHED IN 'pool_name' WITH REPLICATION = 3 ;
|
||||||
|
ALTER TABLE my_table PARTITION (date = '2023-01-01') SET CACHED IN 'pool_name' WITH REPLICATION = 2;
|
||||||
|
ALTER TABLE my_table SET UNCACHED;
|
||||||
|
ALTER TABLE my_table PARTITION (date = '2023-01-01') SET UNCACHED;
|
||||||
|
|
||||||
|
-- example
|
||||||
|
alter table historical_data drop partition (year < 1995);
|
||||||
|
alter table historical_data drop partition (year < 1995, last_name like 'A%');
|
||||||
|
alter table historical_data drop partition (year = 1996 and month between 1 and 6);
|
||||||
|
alter table fast_growing_data partition (year = 2016, month in (10,11,12)) set fileformat parquet;
|
||||||
|
alter table d1.mobile rename to mobile;
|
||||||
|
alter table d2.mobile rename to d3.mobile;
|
||||||
|
alter table p1 add partition (month=1, day=1);
|
||||||
|
alter table p1 add partition (month=1, day=2);
|
||||||
|
alter table p1 add partition (month=2, day=1);
|
||||||
|
alter table p1 add partition (month=2, day=2);
|
||||||
|
alter table p1 partition (month=1, day=1) set location '/usr/external_data/new_years_day';
|
||||||
|
alter table t1 add partition (yy = 2016, mm = 2);
|
||||||
|
alter table t1 add partition (yy = 2016, mm = 3);
|
||||||
|
alter table t1 recover partitions;
|
||||||
|
alter table analysis_data set tblproperties('numRows'='1001000000', 'STATS_GENERATED_VIA_STATS_TASK'='true');
|
||||||
|
alter table partitioned_data partition(year=2009, month=4) set tblproperties ('numRows'='30000', 'STATS_GENERATED_VIA_STATS_TASK'='true');
|
||||||
|
alter table partitioned_data set tblproperties ('numRows'='1030000', 'STATS_GENERATED_VIA_STATS_TASK'='true');
|
||||||
|
alter table t1 set column stats x ('numDVs'='2','numNulls'='0');
|
||||||
|
alter table t1 set column stats s ('numdvs'='3','maxsize'='4');
|
||||||
|
alter table optional_columns drop column a2;
|
||||||
|
alter table optional_columns drop column a1;
|
||||||
|
alter table p1 partition (month=2, day=2) set fileformat parquet;
|
||||||
|
alter table partition_t add partition (y=2000);
|
||||||
|
ALTER TABLE t1 ADD COLUMNS (y STRING ENCODING prefix_encoding);
|
||||||
|
ALTER TABLE t1 ADD COLUMNS (z INT DEFAULT 10);
|
||||||
|
ALTER TABLE t1 ADD COLUMNS (a STRING NOT NULL DEFAULT '', t TIMESTAMP COMPRESSION default_compression);
|
||||||
|
alter table kt alter column s set encoding prefix_encoding;
|
||||||
|
alter table kt alter x set block_size 2048;
|
||||||
|
alter table kt alter column t set compression zlib;
|
43
test/parser/impala/syntax/fixtures/alter_view.sql
Normal file
43
test/parser/impala/syntax/fixtures/alter_view.sql
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
-- ALTER VIEW [database_name.]view_name [(column_name [COMMENT 'column_comment'][, ...])] AS select_statement;
|
||||||
|
ALTER VIEW my_view
|
||||||
|
AS SELECT column_name1, column_name2, column_name3 FROM table_name;
|
||||||
|
ALTER VIEW my_view
|
||||||
|
(column_name1 COMMENT 'Column 1', column_name2, column_name3 COMMENT 'Column 3')
|
||||||
|
AS SELECT column_name1, column_name2, column_name3 FROM table_name;
|
||||||
|
ALTER VIEW db1.my_view
|
||||||
|
(column_name1 COMMENT 'Column 1', column_name2, column_name3 COMMENT 'Column 3')
|
||||||
|
AS SELECT column_name1, column_name2, column_name3 FROM table_name;
|
||||||
|
ALTER VIEW my_view
|
||||||
|
(col1 COMMENT 'Description for Column 1', col2, col3 COMMENT 'Description for Column 3')
|
||||||
|
AS SELECT col1, col2, col3 FROM my_table;
|
||||||
|
|
||||||
|
-- ALTER VIEW [database_name.]view_name RENAME TO [database_name.]view_name;
|
||||||
|
ALTER VIEW db1.v1 RENAME TO db2.v2;
|
||||||
|
ALTER VIEW v1 RENAME TO db2.v2;
|
||||||
|
ALTER VIEW v1 RENAME TO v2;
|
||||||
|
ALTER VIEW db1.v1 RENAME TO v2;
|
||||||
|
|
||||||
|
-- ALTER VIEW [database_name.]view_name SET OWNER USER user_name;
|
||||||
|
ALTER VIEW my_view SET OWNER USER 'name';
|
||||||
|
ALTER VIEW db.my_view SET OWNER USER 'name';
|
||||||
|
|
||||||
|
-- ALTER VIEW [database_name.]view_name SET TBLPROPERTIES ('name' = 'value'[, 'name' = 'value' ...]);
|
||||||
|
ALTER VIEW v1 SET TBLPROPERTIES ('tblp1' = '1', 'tblp2' = '2', 'tblp3' = '3');
|
||||||
|
ALTER VIEW db.v1 SET TBLPROPERTIES ('tblp1' = '1', 'tblp2' = '2', 'tblp3' = '3');
|
||||||
|
ALTER VIEW db.v1 SET TBLPROPERTIES ('tblp1' = '1');
|
||||||
|
|
||||||
|
|
||||||
|
-- ALTER VIEW [database_name.]view_name UNSET TBLPROPERTIES ('name'[, ...]);
|
||||||
|
ALTER VIEW v1 UNSET TBLPROPERTIES ('tblp1', 'tblp2');
|
||||||
|
ALTER VIEW db.v1 UNSET TBLPROPERTIES ('tblp1');
|
||||||
|
ALTER VIEW db.v1 UNSET TBLPROPERTIES ('tblp1', 'tblp2', 'tblp3');
|
||||||
|
|
||||||
|
-- example
|
||||||
|
ALTER VIEW v1 AS SELECT x, UPPER(s) s FROM t2;
|
||||||
|
ALTER VIEW v1 (c1, c2) AS SELECT x, UPPER(s) s FROM t2;
|
||||||
|
ALTER VIEW v7 (c1 COMMENT 'Comment for c1', c2) AS SELECT t1.c1, t1.c2 FROM t1;
|
||||||
|
ALTER VIEW db1.v1 RENAME TO db2.v2;
|
||||||
|
ALTER VIEW db1.v1 RENAME TO db1.v2;
|
||||||
|
ALTER VIEW db1.v1 RENAME TO db2.v1;
|
||||||
|
ALTER VIEW v1 SET TBLPROPERTIES ('tblp1' = '1', 'tblp2' = '2');
|
||||||
|
ALTER VIEW v1 UNSET TBLPROPERTIES ('tblp1', 'tblp2');
|
15
test/parser/impala/syntax/fixtures/comment.sql
Normal file
15
test/parser/impala/syntax/fixtures/comment.sql
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
-- COMMENT ON DATABASE db_name IS {'comment' | NULL}
|
||||||
|
COMMENT ON DATABASE my_database IS 'This is my database.';
|
||||||
|
COMMENT ON DATABASE my_database IS NULL;
|
||||||
|
|
||||||
|
-- COMMENT ON TABLE [db_name.]table_name IS {'comment' | NULL}
|
||||||
|
COMMENT ON TABLE my_database.my_table IS 'This is my table.';
|
||||||
|
COMMENT ON TABLE my_database.my_table IS NULL;
|
||||||
|
COMMENT ON TABLE my_table IS 'This is my table.';
|
||||||
|
COMMENT ON TABLE my_table IS NULL;
|
||||||
|
|
||||||
|
-- COMMENT ON COLUMN [db_name.]table_name.column_name IS {'comment' | NULL}
|
||||||
|
COMMENT ON COLUMN my_database.my_table.age IS 'save for age.';
|
||||||
|
COMMENT ON COLUMN my_database.my_table.age IS NULL;
|
||||||
|
COMMENT ON COLUMN my_table.age IS 'This is my table.';
|
||||||
|
COMMENT ON COLUMN my_table.age IS NULL;
|
20
test/parser/impala/syntax/fixtures/compute_stats.sql
Normal file
20
test/parser/impala/syntax/fixtures/compute_stats.sql
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
-- COMPUTE STATS [db_name.]table_name [ ( column_list ) ] [TABLESAMPLE SYSTEM(percentage) [REPEATABLE(seed)]]
|
||||||
|
COMPUTE STATS my_table;
|
||||||
|
COMPUTE STATS my_table (column1, column2);
|
||||||
|
COMPUTE STATS my_table TABLESAMPLE SYSTEM(20);
|
||||||
|
COMPUTE STATS my_table (column1, column2) TABLESAMPLE SYSTEM(2) REPEATABLE(456);
|
||||||
|
COMPUTE STATS my_table TABLESAMPLE SYSTEM(2) REPEATABLE(456);
|
||||||
|
|
||||||
|
|
||||||
|
-- COMPUTE INCREMENTAL STATS [db_name.]table_name [PARTITION (partition_spec)]
|
||||||
|
COMPUTE INCREMENTAL STATS my_table;
|
||||||
|
COMPUTE INCREMENTAL STATS my_table PARTITION (date='2023-11-14');
|
||||||
|
|
||||||
|
-- example
|
||||||
|
compute stats t1;
|
||||||
|
compute incremental stats int_partitions partition (x < 100);
|
||||||
|
compute incremental stats int_partitions partition (x in (100, 150, 200));
|
||||||
|
compute incremental stats int_partitions partition (x between 100 and 175);
|
||||||
|
compute incremental stats int_partitions partition (x in (100, 150, 200) or x < 100);
|
||||||
|
compute incremental stats int_partitions partition (x != 150);
|
||||||
|
compute incremental stats item_partitioned;
|
17
test/parser/impala/syntax/fixtures/create_db.sql
Normal file
17
test/parser/impala/syntax/fixtures/create_db.sql
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
-- CREATE (DATABASE|SCHEMA) [IF NOT EXISTS] database_name[COMMENT 'database_comment'] [LOCATION hdfs_path];
|
||||||
|
CREATE DATABASE my_db;
|
||||||
|
CREATE DATABASE IF NOT EXISTS my_db1;
|
||||||
|
CREATE DATABASE my_db COMMENT 'my first db';
|
||||||
|
CREATE DATABASE my_db LOCATION '/path/to/partition';
|
||||||
|
CREATE DATABASE my_db COMMENT 'my first db' LOCATION '/path/to/partition';
|
||||||
|
CREATE DATABASE IF NOT EXISTS my_db COMMENT 'my first db' LOCATION '/path/to/partition';
|
||||||
|
CREATE SCHEMA my_schema;
|
||||||
|
CREATE SCHEMA IF NOT EXISTS my_schema1;
|
||||||
|
CREATE SCHEMA my_schema COMMENT 'my first schema';
|
||||||
|
CREATE SCHEMA my_schema LOCATION '/path/to/partition';
|
||||||
|
CREATE SCHEMA my_schema COMMENT 'my first schema' LOCATION '/path/to/partition';
|
||||||
|
CREATE SCHEMA IF NOT EXISTS my_schema COMMENT 'my first schema' LOCATION '/path/to/partition';
|
||||||
|
|
||||||
|
|
||||||
|
-- example
|
||||||
|
create database first_db;
|
83
test/parser/impala/syntax/fixtures/create_function.sql
Normal file
83
test/parser/impala/syntax/fixtures/create_function.sql
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
/* CREATE FUNCTION [IF NOT EXISTS] [db_name.]function_name([arg_type[, arg_type...])
|
||||||
|
RETURNS return_type
|
||||||
|
LOCATION 'hdfs_path_to_dot_so'
|
||||||
|
SYMBOL='symbol_name' */
|
||||||
|
CREATE FUNCTION function_name(arg_type1, arg_type2)
|
||||||
|
RETURNS return_type
|
||||||
|
LOCATION 'hdfs_path_to_dot_so'
|
||||||
|
SYMBOL='symbol_name';
|
||||||
|
CREATE FUNCTION db_name.function_name(arg_type1, arg_type2)
|
||||||
|
RETURNS return_type
|
||||||
|
LOCATION 'hdfs_path_to_dot_so'
|
||||||
|
SYMBOL='symbol_name';
|
||||||
|
CREATE FUNCTION IF NOT EXISTS function_name(arg_type1, arg_type2)
|
||||||
|
RETURNS return_type
|
||||||
|
LOCATION 'hdfs_path_to_dot_so'
|
||||||
|
SYMBOL='symbol_name';
|
||||||
|
CREATE FUNCTION IF NOT EXISTS db_name.function_name(arg_type1)
|
||||||
|
RETURNS return_type
|
||||||
|
LOCATION 'hdfs_path_to_dot_so'
|
||||||
|
SYMBOL='symbol_name';
|
||||||
|
CREATE FUNCTION IF NOT EXISTS db_name.function_name(arg_type1, arg_type2, arg_type3)
|
||||||
|
RETURNS return_type
|
||||||
|
LOCATION 'hdfs_path_to_dot_so'
|
||||||
|
SYMBOL='symbol_name';
|
||||||
|
|
||||||
|
/* CREATE FUNCTION [IF NOT EXISTS] [db_name.]function_name
|
||||||
|
LOCATION 'hdfs_path_to_jar'
|
||||||
|
SYMBOL='class_name' */
|
||||||
|
CREATE FUNCTION function_name
|
||||||
|
LOCATION 'hdfs_path_to_dot_so'
|
||||||
|
SYMBOL='symbol_name';
|
||||||
|
CREATE FUNCTION db_name.function_name
|
||||||
|
LOCATION 'hdfs_path_to_dot_so'
|
||||||
|
SYMBOL='symbol_name';
|
||||||
|
CREATE FUNCTION IF NOT EXISTS function_name
|
||||||
|
LOCATION 'hdfs_path_to_dot_so'
|
||||||
|
SYMBOL='symbol_name';
|
||||||
|
CREATE FUNCTION IF NOT EXISTS db_name.function_name
|
||||||
|
LOCATION 'hdfs_path_to_dot_so'
|
||||||
|
SYMBOL='symbol_name';
|
||||||
|
|
||||||
|
/* CREATE [AGGREGATE] FUNCTION [IF NOT EXISTS] [db_name.]function_name([arg_type[, arg_type...])
|
||||||
|
RETURNS return_type
|
||||||
|
[INTERMEDIATE type_spec]
|
||||||
|
LOCATION 'hdfs_path'
|
||||||
|
[INIT_FN='function]
|
||||||
|
UPDATE_FN='function
|
||||||
|
MERGE_FN='function
|
||||||
|
[PREPARE_FN='function]
|
||||||
|
[CLOSEFN='function]
|
||||||
|
[SERIALIZE_FN='function]
|
||||||
|
[FINALIZE_FN='function] */
|
||||||
|
CREATE AGGREGATE FUNCTION function_name(arg_type1, arg_type2)
|
||||||
|
RETURNS return_type
|
||||||
|
LOCATION 'hdfs_path'
|
||||||
|
UPDATE_FN='update_function'
|
||||||
|
MERGE_FN='merge_function';
|
||||||
|
CREATE AGGREGATE FUNCTION db_name.function_name(arg_type1, arg_type2)
|
||||||
|
RETURNS return_type
|
||||||
|
LOCATION 'hdfs_path'
|
||||||
|
UPDATE_FN='update_function'
|
||||||
|
MERGE_FN='merge_function';
|
||||||
|
CREATE AGGREGATE FUNCTION IF NOT EXISTS function_name(arg_type1, arg_type2)
|
||||||
|
RETURNS return_type
|
||||||
|
LOCATION 'hdfs_path'
|
||||||
|
UPDATE_FN='update_function'
|
||||||
|
MERGE_FN='merge_function';
|
||||||
|
CREATE AGGREGATE FUNCTION function_name(arg_type1, arg_type2)
|
||||||
|
RETURNS return_type
|
||||||
|
INTERMEDIATE intermediate_type
|
||||||
|
LOCATION 'hdfs_path'
|
||||||
|
INIT_FN ='init_function'
|
||||||
|
UPDATE_FN='update_function'
|
||||||
|
MERGE_FN='merge_function'
|
||||||
|
PREPARE_FN = 'prepare_fn'
|
||||||
|
CLOSEFN = 'closefn'
|
||||||
|
SERIALIZE_FN = 'serialize_function'
|
||||||
|
FINALIZE_FN = 'finalize_function';
|
||||||
|
|
||||||
|
|
||||||
|
-- example
|
||||||
|
create function my_func location '/user/impala/udfs/udf-examples.jar'
|
||||||
|
symbol='org.apache.impala.TestUdf';
|
2
test/parser/impala/syntax/fixtures/create_role.sql
Normal file
2
test/parser/impala/syntax/fixtures/create_role.sql
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
-- CREATE ROLE role_name
|
||||||
|
CREATE ROLE 'impala';
|
181
test/parser/impala/syntax/fixtures/create_table.sql
Normal file
181
test/parser/impala/syntax/fixtures/create_table.sql
Normal file
@ -0,0 +1,181 @@
|
|||||||
|
CREATE EXTERNAL TABLE external_parquet (c1 INT, c2 STRING, c3 TIMESTAMP)
|
||||||
|
STORED AS PARQUET LOCATION '/user/etl/destination';
|
||||||
|
|
||||||
|
create table census (name string, census_year int) partitioned by (year int);
|
||||||
|
|
||||||
|
CREATE TABLE census_data (last_name STRING, first_name STRING, state STRING, address STRING)
|
||||||
|
SORT BY (last_name, state)
|
||||||
|
STORED AS PARQUET
|
||||||
|
TBLPROPERTIES ('transactional'='true', 'transactional_properties'='insert_only');
|
||||||
|
|
||||||
|
CREATE TABLE sorted_census_data
|
||||||
|
SORT BY (last_name, state)
|
||||||
|
STORED AS PARQUET
|
||||||
|
AS SELECT last_name, first_name, state, address
|
||||||
|
FROM unsorted_census_data;
|
||||||
|
|
||||||
|
CREATE TABLE yy2 (s STRING, year INT);
|
||||||
|
|
||||||
|
CREATE TABLE kudu_no_partition_by_clause
|
||||||
|
(
|
||||||
|
id bigint PRIMARY KEY, s STRING, b BOOLEAN
|
||||||
|
)
|
||||||
|
STORED AS KUDU;
|
||||||
|
|
||||||
|
CREATE TABLE kudu_t1 (id BIGINT PRIMARY key, s STRING, b BOOLEAN)
|
||||||
|
PARTITION BY HASH (id) PARTITIONS 20 STORED AS KUDU;
|
||||||
|
|
||||||
|
CREATE TABLE kudu_t2 (id BIGINT, s STRING, b BOOLEAN, PRIMARY KEY (id,s))
|
||||||
|
PARTITION BY HASH (s) PARTITIONS 30 STORED AS KUDU;
|
||||||
|
|
||||||
|
CREATE TABLE kudu_t3 (id BIGINT, year INT, s STRING,
|
||||||
|
b BOOLEAN, PRIMARY KEY (id,year))
|
||||||
|
PARTITION BY HASH (id) PARTITIONS 20,
|
||||||
|
RANGE (year) (PARTITION 1980 <= VALUES < 1990,
|
||||||
|
PARTITION 1990 <= VALUES < 2000,
|
||||||
|
PARTITION VALUE = 2001,
|
||||||
|
PARTITION 2001 < VALUES < 2003)
|
||||||
|
STORED AS KUDU;
|
||||||
|
|
||||||
|
CREATE EXTERNAL TABLE external_t1 STORED AS KUDU
|
||||||
|
TBLPROPERTIES ('kudu.table_name'='kudu_tbl_created_via_api');
|
||||||
|
|
||||||
|
CREATE EXTERNAL TABLE myextkudutbl (
|
||||||
|
id int PRIMARY KEY,
|
||||||
|
name string)
|
||||||
|
PARTITION BY HASH PARTITIONS 8
|
||||||
|
STORED AS KUDU
|
||||||
|
TBLPROPERTIES ('external.table.purge'='true');
|
||||||
|
|
||||||
|
CREATE TABLE ctas_t1
|
||||||
|
PRIMARY KEY (id) PARTITION BY HASH (id) PARTITIONS 10
|
||||||
|
STORED AS KUDU
|
||||||
|
AS SELECT id, s FROM kudu_t1;
|
||||||
|
|
||||||
|
CREATE TABLE pk_multiple_columns
|
||||||
|
(
|
||||||
|
col1 BIGINT,
|
||||||
|
col2 STRING,
|
||||||
|
col3 BOOLEAN,
|
||||||
|
PRIMARY KEY (col1, col2)
|
||||||
|
) PARTITION BY HASH(col2) PARTITIONS 2 STORED AS KUDU;
|
||||||
|
|
||||||
|
CREATE TABLE user.inline_pk_rewritten (
|
||||||
|
id BIGINT NOT NULL ENCODING AUTO_ENCODING COMPRESSION DEFAULT_COMPRESSION,
|
||||||
|
s STRING NULL ENCODING AUTO_ENCODING COMPRESSION DEFAULT_COMPRESSION,
|
||||||
|
PRIMARY KEY (id)
|
||||||
|
)
|
||||||
|
PARTITION BY HASH (id) PARTITIONS 2
|
||||||
|
STORED AS KUDU
|
||||||
|
TBLPROPERTIES ('kudu.master_addresses'='host.example.com');
|
||||||
|
|
||||||
|
CREATE TABLE default_vals
|
||||||
|
(
|
||||||
|
id BIGINT PRIMARY KEY,
|
||||||
|
name STRING NOT NULL DEFAULT 'unknown',
|
||||||
|
address STRING DEFAULT upper('no fixed address'),
|
||||||
|
age INT DEFAULT -1,
|
||||||
|
earthling BOOLEAN DEFAULT TRUE,
|
||||||
|
planet_of_origin STRING DEFAULT 'Earth',
|
||||||
|
optional_col STRING DEFAULT NULL
|
||||||
|
) PARTITION BY HASH(id) PARTITIONS 2 STORED AS KUDU;
|
||||||
|
|
||||||
|
CREATE TABLE various_encodings
|
||||||
|
(
|
||||||
|
id BIGINT PRIMARY KEY,
|
||||||
|
c1 BIGINT ENCODING PLAIN_ENCODING,
|
||||||
|
c2 BIGINT ENCODING AUTO_ENCODING,
|
||||||
|
c3 TINYINT ENCODING BIT_SHUFFLE,
|
||||||
|
c4 DOUBLE ENCODING BIT_SHUFFLE,
|
||||||
|
c5 BOOLEAN ENCODING RLE,
|
||||||
|
c6 STRING ENCODING DICT_ENCODING,
|
||||||
|
c7 STRING ENCODING PREFIX_ENCODING
|
||||||
|
) PARTITION BY HASH(id) PARTITIONS 2 STORED AS KUDU;
|
||||||
|
|
||||||
|
|
||||||
|
CREATE TABLE blog_posts
|
||||||
|
(
|
||||||
|
user_id STRING ENCODING DICT_ENCODING,
|
||||||
|
post_id BIGINT ENCODING BIT_SHUFFLE,
|
||||||
|
subject STRING ENCODING PLAIN_ENCODING,
|
||||||
|
body STRING COMPRESSION LZ4,
|
||||||
|
spanish_translation STRING COMPRESSION SNAPPY,
|
||||||
|
esperanto_translation STRING COMPRESSION ZLIB,
|
||||||
|
PRIMARY KEY (user_id, post_id)
|
||||||
|
) PARTITION BY HASH(user_id, post_id) PARTITIONS 2 STORED AS KUDU;
|
||||||
|
|
||||||
|
|
||||||
|
CREATE TABLE various_encodings
|
||||||
|
(
|
||||||
|
id BIGINT PRIMARY KEY,
|
||||||
|
c1 BIGINT ENCODING PLAIN_ENCODING,
|
||||||
|
c2 BIGINT ENCODING AUTO_ENCODING,
|
||||||
|
c3 TINYINT ENCODING BIT_SHUFFLE,
|
||||||
|
c4 DOUBLE ENCODING BIT_SHUFFLE,
|
||||||
|
c5 BOOLEAN ENCODING RLE,
|
||||||
|
c6 STRING ENCODING DICT_ENCODING,
|
||||||
|
c7 STRING ENCODING PREFIX_ENCODING
|
||||||
|
) PARTITION BY HASH(id) PARTITIONS 2 STORED AS KUDU;
|
||||||
|
|
||||||
|
create table million_rows_one_range (id string primary key, s string)
|
||||||
|
partition by hash(id) partitions 50,
|
||||||
|
range (partition 'a' <= values < '{')
|
||||||
|
stored as kudu;
|
||||||
|
|
||||||
|
create table million_rows_two_ranges (id string primary key, s string)
|
||||||
|
partition by hash(id) partitions 50,
|
||||||
|
range (partition 'a' <= values < '{', partition 'A' <= values < '[', partition value = '00000')
|
||||||
|
stored as kudu;
|
||||||
|
|
||||||
|
create table million_rows_three_ranges (id string primary key, s string)
|
||||||
|
partition by hash (school) partitions 10,
|
||||||
|
range (letter_grade) (partition value = 'A', partition value = 'B',
|
||||||
|
partition value = 'C', partition value = 'D', partition value = 'F')
|
||||||
|
stored as kudu;
|
||||||
|
|
||||||
|
create table hash_t5 (x bigint, y bigint, s string, primary key (x,y))
|
||||||
|
partition by hash (x) partitions 10, hash (y) partitions 20, hash (y) partitions 20
|
||||||
|
stored as kudu;
|
||||||
|
|
||||||
|
create table range_t1 (x bigint, s string, s2 string, primary key (x, s))
|
||||||
|
partition by range (x)
|
||||||
|
(
|
||||||
|
partition 0 <= values <= 49, partition 50 <= values <= 100,
|
||||||
|
partition value < 0, partition 100 < values <= 500,
|
||||||
|
partition values < 0, partition 100 < values
|
||||||
|
)
|
||||||
|
stored as kudu;
|
||||||
|
|
||||||
|
create table combined_t1 (x bigint, s string, s2 string, primary key (x, s))
|
||||||
|
partition by hash (x) partitions 10, range (x)
|
||||||
|
(
|
||||||
|
partition 0 <= values <= 49, partition 50 <= values <= 100
|
||||||
|
)
|
||||||
|
stored as kudu;
|
||||||
|
|
||||||
|
CREATE TABLE t5 AS SELECT upper(y) AS s, x+1 AS a, 'Entirely new column' AS n FROM t1;
|
||||||
|
|
||||||
|
CREATE TABLE parquet_version_of_t1 STORED AS PARQUET AS SELECT * FROM t1;
|
||||||
|
|
||||||
|
create table partitions_yes partitioned by (year, month)
|
||||||
|
as select s, year, month from partitions_no;
|
||||||
|
|
||||||
|
CREATE TABLE my_first_table (id BIGINT, name STRING, PRIMARY KEY (id)) PARTITION BY HASH PARTITIONS 16 STORED AS KUDU TBLPROPERTIES ('kudu.num_tablet_replicas' = '1');
|
||||||
|
|
||||||
|
CREATE TABLE parquet_table (id INT) STORED AS PARQUET;
|
||||||
|
|
||||||
|
CREATE TABLE games3 (id BIGINT, play ARRAY < MAP < STRING, BIGINT > >) STORED AS PARQUET;
|
||||||
|
|
||||||
|
CREATE TABLE games3 (id BIGINT, play ARRAY < MAP < STRING, BIGINT > >) STORED AS PARQUET;
|
||||||
|
|
||||||
|
create table unsorted (x bigint);
|
||||||
|
|
||||||
|
CREATE TABLE pk(col1 INT, col2 STRING, PRIMARY KEY(col1, col2));
|
||||||
|
|
||||||
|
CREATE TABLE fk(id INT, col1 INT, col2 STRING, PRIMARY KEY(id),
|
||||||
|
FOREIGN KEY(col1, col2) REFERENCES pk(col1, col2));
|
||||||
|
|
||||||
|
CREATE TABLE pk(id INT, PRIMARY KEY(id) DISABLE, NOVALIDATE, RELY);
|
||||||
|
|
||||||
|
CREATE TABLE fk(id INT, col1 INT, col2 STRING, PRIMARY KEY(id),
|
||||||
|
FOREIGN KEY(col1, col2) REFERENCES pk(col1, col2));
|
22
test/parser/impala/syntax/fixtures/create_view.sql
Normal file
22
test/parser/impala/syntax/fixtures/create_view.sql
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
/* CREATE VIEW [IF NOT EXISTS] view_name
|
||||||
|
[(column_name [COMMENT 'column_comment'][, ...])]
|
||||||
|
[COMMENT 'view_comment']
|
||||||
|
[TBLPROPERTIES ('name' = 'value'[, ...])]
|
||||||
|
AS select_statement */
|
||||||
|
CREATE VIEW my_view AS SELECT * FROM my_table;
|
||||||
|
CREATE VIEW IF NOT EXISTS my_view AS SELECT * FROM my_table;
|
||||||
|
CREATE VIEW IF NOT EXISTS my_view (age COMMENT 'this is number col') AS SELECT * FROM my_table;
|
||||||
|
CREATE VIEW IF NOT EXISTS my_view (age COMMENT 'this is number col') COMMENT 'this is test view' AS SELECT * FROM my_table;
|
||||||
|
CREATE VIEW my_view (age COMMENT 'this is number col') COMMENT 'this is test view' TBLPROPERTIES ('tblp1' = '1', 'aaa' = '2') AS SELECT * FROM my_table;
|
||||||
|
CREATE VIEW my_view COMMENT 'this is test view' TBLPROPERTIES ('tblp1' = '1', 'aaa' = '2') AS SELECT * FROM my_table;
|
||||||
|
CREATE VIEW my_view (age COMMENT 'this is number col', age1 COMMENT 'this is number col') TBLPROPERTIES ('tblp1' = '1') AS SELECT * FROM my_table;
|
||||||
|
|
||||||
|
-- example
|
||||||
|
CREATE VIEW v1 AS SELECT * FROM t1;
|
||||||
|
CREATE VIEW v2 AS SELECT c1, c3, c7 FROM t1;
|
||||||
|
CREATE VIEW v3 AS SELECT DISTINCT c1, c3, c7 FROM t1 WHERE c1 IS NOT NULL AND c5 > 0;
|
||||||
|
CREATE VIEW v4 AS SELECT c4 AS last_name, c6 AS address, c2 AS birth_date FROM t1;
|
||||||
|
CREATE VIEW v5 AS SELECT c1, CAST(c3 AS STRING) c3, CONCAT(c4,c5) c5, TRIM(c6) c6, "Constant" c8 FROM t1;
|
||||||
|
CREATE VIEW v6 AS SELECT t1.c1, t2.c2 FROM t1 JOIN t2 ON t1.id = t2.id;
|
||||||
|
CREATE VIEW v7 (c1 COMMENT 'Comment for c1', c2) COMMENT 'Comment for v7' AS SELECT t1.c1, t1.c2 FROM t1;
|
||||||
|
CREATE VIEW v7 (c1 , c2) TBLPROPERTIES ('tblp1' = '1') AS SELECT t1.c1, t1.c2 FROM t1;
|
42
test/parser/impala/syntax/fixtures/delete.sql
Normal file
42
test/parser/impala/syntax/fixtures/delete.sql
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
-- DELETE [FROM] [database_name.]table_name [ WHERE where_conditions ]
|
||||||
|
DELETE FROM my_database.my_table;
|
||||||
|
|
||||||
|
DELETE my_database.my_table;
|
||||||
|
|
||||||
|
DELETE my_table;
|
||||||
|
|
||||||
|
DELETE FROM my_table;
|
||||||
|
|
||||||
|
DELETE FROM my_table WHERE col1 LIKE 'prefix%';
|
||||||
|
|
||||||
|
DELETE FROM my_table WHERE col1 IN (SELECT col2 FROM other_table WHERE col3 = 'value1');
|
||||||
|
|
||||||
|
-- example
|
||||||
|
DELETE FROM my_table;
|
||||||
|
|
||||||
|
DELETE my_table;
|
||||||
|
|
||||||
|
DELETE FROM my_table WHERE c1 = 100;
|
||||||
|
|
||||||
|
DELETE FROM my_table WHERE
|
||||||
|
(c1 > c2 OR c3 IN ('hello','world')) AND c4 IS NOT NULL;
|
||||||
|
|
||||||
|
DELETE FROM t1 WHERE
|
||||||
|
(c1 IN (1,2,3) AND c2 > c3) OR c4 IS NOT NULL;
|
||||||
|
|
||||||
|
DELETE FROM time_series WHERE
|
||||||
|
year = 2016 AND month IN (11,12) AND day > 15;
|
||||||
|
|
||||||
|
DELETE FROM t1 WHERE
|
||||||
|
c5 IN (SELECT DISTINCT other_col FROM other_my_table);
|
||||||
|
|
||||||
|
DELETE FROM my_table WHERE 1 = 0;
|
||||||
|
|
||||||
|
DELETE t1 FROM t1 JOIN t2 ON t1.x = t2.x;
|
||||||
|
|
||||||
|
DELETE t1 FROM t1 JOIN t2 ON t1.x = t2.x
|
||||||
|
WHERE t1.y = FALSE and t2.z > 100;
|
||||||
|
|
||||||
|
DELETE t1 FROM my_table t1 JOIN other_table t2 ON t1.x = t2.x;
|
||||||
|
|
||||||
|
DELETE t2 FROM non_kudu_non_ice_table t1 JOIN kudu_or_ice_table t2 ON t1.x = t2.x;
|
17
test/parser/impala/syntax/fixtures/describe.sql
Normal file
17
test/parser/impala/syntax/fixtures/describe.sql
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
-- DESCRIBE [DATABASE] [FORMATTED|EXTENDED] object_name
|
||||||
|
DESCRIBE my_table;
|
||||||
|
DESCRIBE DATABASE my_table;
|
||||||
|
DESCRIBE DATABASE FORMATTED my_table;
|
||||||
|
DESCRIBE DATABASE EXTENDED my_table;
|
||||||
|
DESCRIBE FORMATTED my_table;
|
||||||
|
DESCRIBE EXTENDED my_table;
|
||||||
|
DESCRIBE FORMATTED my_table;
|
||||||
|
DESCRIBE EXTENDED my_db_name.my_table.my_col;
|
||||||
|
DESCRIBE FORMATTED my_db;
|
||||||
|
|
||||||
|
-- example
|
||||||
|
describe my_table;
|
||||||
|
describe my_database.my_table;
|
||||||
|
describe formatted my_table;
|
||||||
|
describe customer.c_orders.item;
|
||||||
|
describe customer.c_orders.item.o_lineitems;
|
13
test/parser/impala/syntax/fixtures/drop_db.sql
Normal file
13
test/parser/impala/syntax/fixtures/drop_db.sql
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
-- DROP (DATABASE|SCHEMA) [IF EXISTS] database_name [RESTRICT | CASCADE];
|
||||||
|
DROP DATABASE my_database;
|
||||||
|
DROP DATABASE IF EXISTS my_database;
|
||||||
|
DROP DATABASE my_database RESTRICT;
|
||||||
|
DROP DATABASE IF EXISTS my_database CASCADE;
|
||||||
|
DROP SCHEMA my_database;
|
||||||
|
DROP SCHEMA IF EXISTS my_database;
|
||||||
|
DROP SCHEMA my_database RESTRICT;
|
||||||
|
DROP SCHEMA IF EXISTS my_database CASCADE;
|
||||||
|
|
||||||
|
-- example
|
||||||
|
drop database temp;
|
||||||
|
drop database temp cascade;
|
16
test/parser/impala/syntax/fixtures/drop_function.sql
Normal file
16
test/parser/impala/syntax/fixtures/drop_function.sql
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
-- DROP [AGGREGATE] FUNCTION [IF EXISTS] [db_name.]function_name(type[, type...])
|
||||||
|
DROP FUNCTION my_function(integer, text);
|
||||||
|
DROP FUNCTION IF EXISTS my_function(integer, boolean);
|
||||||
|
DROP FUNCTION my_database.my_function(integer);
|
||||||
|
DROP AGGREGATE FUNCTION my_function(integer, text);
|
||||||
|
DROP AGGREGATE FUNCTION IF EXISTS my_function(integer, text, binary);
|
||||||
|
DROP AGGREGATE FUNCTION my_database.my_function(integer);
|
||||||
|
|
||||||
|
-- DROP FUNCTION [IF EXISTS] [db_name.]function_name
|
||||||
|
DROP FUNCTION my_db.my_func;
|
||||||
|
DROP FUNCTION IF EXISTS my_func;
|
||||||
|
DROP FUNCTION my_func;
|
||||||
|
DROP FUNCTION IF EXISTS my_db.my_func;
|
||||||
|
|
||||||
|
-- example
|
||||||
|
drop function my_func;
|
2
test/parser/impala/syntax/fixtures/drop_role.sql
Normal file
2
test/parser/impala/syntax/fixtures/drop_role.sql
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
-- DROP ROLE role_name
|
||||||
|
DROP ROLE 'impala';
|
12
test/parser/impala/syntax/fixtures/drop_stats.sql
Normal file
12
test/parser/impala/syntax/fixtures/drop_stats.sql
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
-- DROP STATS [database_name.]table_name
|
||||||
|
DROP STATS my_table;
|
||||||
|
DROP STATS my_db.my_table;
|
||||||
|
|
||||||
|
-- DROP INCREMENTAL STATS [database_name.]table_name PARTITION (partition_spec)
|
||||||
|
DROP INCREMENTAL STATS my_table PARTITION (date = "1111-11-11");
|
||||||
|
DROP INCREMENTAL STATS my_db.my_table PARTITION (year < 1995 and last_name like 'A%');
|
||||||
|
|
||||||
|
-- example
|
||||||
|
drop incremental stats item_partitioned partition (i_category='Sports');
|
||||||
|
drop incremental stats item_partitioned partition (i_category='Electronics');
|
||||||
|
drop stats item_partitioned;
|
10
test/parser/impala/syntax/fixtures/drop_table.sql
Normal file
10
test/parser/impala/syntax/fixtures/drop_table.sql
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
-- DROP TABLE [IF EXISTS] [db_name.]table_name [PURGE]
|
||||||
|
DROP TABLE my_table;
|
||||||
|
DROP TABLE my_db.my_table;
|
||||||
|
DROP TABLE IF EXISTS my_table;
|
||||||
|
DROP TABLE IF EXISTS my_db.my_table;
|
||||||
|
DROP TABLE IF EXISTS my_db.my_table PURGE;
|
||||||
|
|
||||||
|
-- example
|
||||||
|
drop table unimportant;
|
||||||
|
drop table my_db.trivial;
|
9
test/parser/impala/syntax/fixtures/drop_view.sql
Normal file
9
test/parser/impala/syntax/fixtures/drop_view.sql
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
-- DROP VIEW [IF EXISTS] [db_name.]view_name
|
||||||
|
DROP VIEW my_view;
|
||||||
|
DROP VIEW my_db.my_view;
|
||||||
|
DROP VIEW IF EXISTS my_view;
|
||||||
|
DROP VIEW IF EXISTS my_db.my_view;
|
||||||
|
|
||||||
|
-- example
|
||||||
|
drop view unimportant;
|
||||||
|
drop view my_db.trivial;
|
11
test/parser/impala/syntax/fixtures/explain.sql
Normal file
11
test/parser/impala/syntax/fixtures/explain.sql
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
-- EXPLAIN { select_query | ctas_stmt | insert_stmt }
|
||||||
|
EXPLAIN SELECT * FROM my_table;
|
||||||
|
EXPLAIN CREATE TABLE t1 (x INT, y STRING);
|
||||||
|
EXPLAIN INSERT INTO t1 VALUES (1, 'one'), (2, 'two'), (3, 'three');
|
||||||
|
|
||||||
|
-- example
|
||||||
|
EXPLAIN SELECT COUNT(*) FROM customer_address;
|
||||||
|
EXPLAIN SELECT * FROM functional_kudu.alltypestiny WHERE bigint_col < 1000 / 100;
|
||||||
|
EXPLAIN SELECT x,y from kudu_table WHERE
|
||||||
|
x = 1 AND y NOT IN (2,3) AND z = 1
|
||||||
|
AND a IS NOT NULL AND b > 0 AND length(s) > 5;
|
35
test/parser/impala/syntax/fixtures/grant.sql
Normal file
35
test/parser/impala/syntax/fixtures/grant.sql
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
-- GRANT ROLE role_name TO GROUP group_name
|
||||||
|
GRANT ROLE role_name TO GROUP group_name
|
||||||
|
|
||||||
|
-- GRANT privilege ON object_type object_name TO USER user_name
|
||||||
|
GRANT ALL ON SERVER my_server TO USER 'impala';
|
||||||
|
GRANT ALTER ON DATABASE my_database TO USER 'impala';
|
||||||
|
GRANT CREATE ON TABLE my_table TO USER 'impala';
|
||||||
|
GRANT DROP ON URI my_uri TO USER 'impala';
|
||||||
|
GRANT INSERT ON URI my_uri TO USER 'impala';
|
||||||
|
GRANT REFRESH ON TABLE my_table TO USER 'impala';
|
||||||
|
GRANT SELECT ON TABLE my_table TO USER 'impala';
|
||||||
|
GRANT SELECT(column_name) ON TABLE my_table TO USER 'impala';
|
||||||
|
|
||||||
|
-- GRANT privilege ON object_type object_name TO GROUP group_name
|
||||||
|
GRANT ALL ON SERVER my_server TO GROUP 'impala_group';
|
||||||
|
GRANT ALTER ON DATABASE my_database TO GROUP 'impala_group';
|
||||||
|
GRANT CREATE ON TABLE my_table TO GROUP 'impala_group';
|
||||||
|
GRANT DROP ON URI my_uri TO GROUP 'impala_group';
|
||||||
|
GRANT INSERT ON URI my_uri TO GROUP 'impala_group';
|
||||||
|
GRANT REFRESH ON TABLE my_table TO GROUP 'impala_group';
|
||||||
|
GRANT SELECT ON TABLE my_table TO GROUP 'impala_group';
|
||||||
|
GRANT SELECT(column_name) ON TABLE my_table TO GROUP 'impala_group';
|
||||||
|
|
||||||
|
-- GRANT privilege ON object_type object_name TO ROLE group_name
|
||||||
|
GRANT ALL ON SERVER my_server TO ROLE 'impala_role';
|
||||||
|
GRANT ALTER ON DATABASE my_database TO ROLE 'impala_role';
|
||||||
|
GRANT CREATE ON TABLE my_table TO ROLE 'impala_role';
|
||||||
|
GRANT DROP ON URI my_uri TO ROLE 'impala_role';
|
||||||
|
GRANT INSERT ON URI my_uri TO ROLE 'impala_role';
|
||||||
|
GRANT REFRESH ON TABLE my_table TO ROLE 'impala_role';
|
||||||
|
GRANT SELECT ON TABLE my_table TO ROLE 'impala_role';
|
||||||
|
GRANT SELECT(column_name) ON TABLE my_table TO ROLE 'impala_role';
|
||||||
|
|
||||||
|
-- example
|
||||||
|
GRANT ALL ON SERVER TO ROLE foo_role;
|
199
test/parser/impala/syntax/fixtures/insert.sql
Normal file
199
test/parser/impala/syntax/fixtures/insert.sql
Normal file
@ -0,0 +1,199 @@
|
|||||||
|
/* [with_clause]
|
||||||
|
INSERT [hint_clause] { INTO | OVERWRITE } [TABLE] table_name
|
||||||
|
[(column_list)]
|
||||||
|
[ PARTITION (partition_clause)]
|
||||||
|
{
|
||||||
|
[hint_clause] select_statement
|
||||||
|
| VALUES (value [, value ...]) [, (value [, value ...]) ...]
|
||||||
|
} */
|
||||||
|
-- INSERT [hint_clause] { INTO | OVERWRITE } table_name [hint_clause] select_statement
|
||||||
|
INSERT INTO my_table
|
||||||
|
SELECT
|
||||||
|
*
|
||||||
|
from
|
||||||
|
my_table1;
|
||||||
|
|
||||||
|
INSERT OVERWRITE my_table
|
||||||
|
SELECT
|
||||||
|
*
|
||||||
|
from
|
||||||
|
my_table1;
|
||||||
|
|
||||||
|
INSERT
|
||||||
|
INTO target_table
|
||||||
|
SELECT
|
||||||
|
val1,
|
||||||
|
val2,
|
||||||
|
val3
|
||||||
|
FROM
|
||||||
|
dual
|
||||||
|
WHERE
|
||||||
|
NOT EXISTS (
|
||||||
|
SELECT
|
||||||
|
1
|
||||||
|
FROM
|
||||||
|
target_table
|
||||||
|
WHERE
|
||||||
|
col1 = val1
|
||||||
|
);
|
||||||
|
|
||||||
|
-- INSERT { INTO | OVERWRITE } table_name [(column_list)] [ PARTITION (partition_clause)] select_statement
|
||||||
|
INSERT INTO
|
||||||
|
target_table (col1, col2, col3) PARTITION (year = 2016, month IN (10, 11, 12))
|
||||||
|
SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
dual;
|
||||||
|
|
||||||
|
INSERT OVERWRITE target_table (col1, col2, col3) PARTITION (year BETWEEN 2016 AND 2030, month IN (10, 11, 12))
|
||||||
|
SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
dual;
|
||||||
|
|
||||||
|
-- INSERT [hint_clause] { INTO | OVERWRITE } table_name [hint_clause] VALUES (value [, value ...]) [, (value [, value ...]) ...]
|
||||||
|
INSERT
|
||||||
|
OVERWRITE target_table (col1, col2, col3) PARTITION (year BETWEEN 2016 AND 2030, month IN (10, 11, 12))
|
||||||
|
VALUES
|
||||||
|
(col1, 'a'),
|
||||||
|
(col2, 'b'),
|
||||||
|
(col3, 'xyzzy');
|
||||||
|
|
||||||
|
WITH
|
||||||
|
cte AS (
|
||||||
|
SELECT
|
||||||
|
col1,
|
||||||
|
col2
|
||||||
|
FROM
|
||||||
|
source_table
|
||||||
|
WHERE
|
||||||
|
condition
|
||||||
|
)
|
||||||
|
INSERT INTO
|
||||||
|
target_table (col1, col2)
|
||||||
|
SELECT
|
||||||
|
col1,
|
||||||
|
col2
|
||||||
|
FROM
|
||||||
|
cte;
|
||||||
|
|
||||||
|
-- example
|
||||||
|
insert into
|
||||||
|
table text_table
|
||||||
|
select
|
||||||
|
*
|
||||||
|
from
|
||||||
|
default.tab1;
|
||||||
|
|
||||||
|
insert overwrite table parquet_table
|
||||||
|
select
|
||||||
|
*
|
||||||
|
from
|
||||||
|
default.tab1
|
||||||
|
limit
|
||||||
|
3;
|
||||||
|
|
||||||
|
insert into
|
||||||
|
val_test_1
|
||||||
|
values
|
||||||
|
(100, 99.9 / 10, 'abc', true, now ());
|
||||||
|
|
||||||
|
insert overwrite val_test_2
|
||||||
|
values
|
||||||
|
(1, 'a'),
|
||||||
|
(2, 'b'),
|
||||||
|
(-1, 'xyzzy');
|
||||||
|
|
||||||
|
insert into
|
||||||
|
t2
|
||||||
|
select
|
||||||
|
*
|
||||||
|
from
|
||||||
|
t1;
|
||||||
|
|
||||||
|
insert into
|
||||||
|
t2
|
||||||
|
select
|
||||||
|
c1,
|
||||||
|
c2
|
||||||
|
from
|
||||||
|
t1;
|
||||||
|
|
||||||
|
insert into
|
||||||
|
t2 (c1)
|
||||||
|
select
|
||||||
|
c1
|
||||||
|
from
|
||||||
|
t1;
|
||||||
|
|
||||||
|
insert into
|
||||||
|
t2 (c2, c1)
|
||||||
|
select
|
||||||
|
c1,
|
||||||
|
c2
|
||||||
|
from
|
||||||
|
t1;
|
||||||
|
|
||||||
|
insert into
|
||||||
|
t2 (y)
|
||||||
|
select
|
||||||
|
c1
|
||||||
|
from
|
||||||
|
t1;
|
||||||
|
|
||||||
|
INSERT INTO
|
||||||
|
t1 PARTITION (x = 10, y = 'a')
|
||||||
|
SELECT
|
||||||
|
c1
|
||||||
|
FROM
|
||||||
|
some_other_table;
|
||||||
|
|
||||||
|
INSERT INTO
|
||||||
|
t1 PARTITION (x, y)
|
||||||
|
VALUES
|
||||||
|
(1, 2, ' c ');
|
||||||
|
|
||||||
|
INSERT INTO
|
||||||
|
t1 (w) PARTITION (x, y)
|
||||||
|
VALUES
|
||||||
|
(1, 2, ' c ');
|
||||||
|
|
||||||
|
INSERT INTO
|
||||||
|
t1 PARTITION (x, y = 'c')
|
||||||
|
VALUES
|
||||||
|
(1, 2);
|
||||||
|
|
||||||
|
INSERT INTO
|
||||||
|
t1 PARTITION (x = 20, y)
|
||||||
|
SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
source;
|
||||||
|
|
||||||
|
with
|
||||||
|
t1 as (
|
||||||
|
select
|
||||||
|
1
|
||||||
|
),
|
||||||
|
t2 as (
|
||||||
|
select
|
||||||
|
2
|
||||||
|
)
|
||||||
|
insert into
|
||||||
|
tab
|
||||||
|
select
|
||||||
|
*
|
||||||
|
from
|
||||||
|
t1
|
||||||
|
union all
|
||||||
|
select
|
||||||
|
*
|
||||||
|
from
|
||||||
|
t2;
|
||||||
|
|
||||||
|
insert into
|
||||||
|
sample_demo_partitions partition (n = 3)
|
||||||
|
select
|
||||||
|
*
|
||||||
|
from
|
||||||
|
sample_demo;
|
@ -0,0 +1,6 @@
|
|||||||
|
-- INVALIDATE METADATA [[db_name.]table_name]
|
||||||
|
INVALIDATE METADATA new_table_from_hive;
|
||||||
|
INVALIDATE METADATA new_db_from_hive.new_table_from_hive;
|
||||||
|
|
||||||
|
-- example
|
||||||
|
INVALIDATE METADATA new_db_from_hive.new_table_from_hive;
|
9
test/parser/impala/syntax/fixtures/load_data.sql
Normal file
9
test/parser/impala/syntax/fixtures/load_data.sql
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
/* LOAD DATA INPATH 'hdfs_file_or_directory_path' [OVERWRITE] INTO TABLE tablename
|
||||||
|
[PARTITION (partcol1=val1, partcol2=val2 ...)] */
|
||||||
|
LOAD DATA INPATH 'hdfs_file_or_directory_path' INTO TABLE my_table;
|
||||||
|
LOAD DATA INPATH 'hdfs_file_or_directory_path' OVERWRITE INTO TABLE my_table;
|
||||||
|
LOAD DATA INPATH 'hdfs_file_or_directory_path' INTO TABLE my_table PARTITION (country = 'USA', age = 18);
|
||||||
|
LOAD DATA INPATH 'hdfs_file_or_directory_path' OVERWRITE INTO TABLE my_table PARTITION (country = 'USA', age = 18);
|
||||||
|
|
||||||
|
-- example
|
||||||
|
load data inpath '/user/doc_demo/thousand_strings.txt' into table t1;
|
9
test/parser/impala/syntax/fixtures/refresh.sql
Normal file
9
test/parser/impala/syntax/fixtures/refresh.sql
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
-- REFRESH [db_name.]table_name [PARTITION (key_col1=val1 [, key_col2=val2...])]
|
||||||
|
REFRESH my_table;
|
||||||
|
REFRESH my_db.my_table;
|
||||||
|
REFRESH my_db.my_table PARTITION (age BETWEEN 100 AND 200, key_col2=val2, date = "1110-10-10");
|
||||||
|
REFRESH table_name PARTITION (key_col1=val1, key_col2=val2, date = "1110-10-10");
|
||||||
|
|
||||||
|
-- example
|
||||||
|
refresh p2 partition (y=0, z=3);
|
||||||
|
refresh p2 partition (y=0, z=-1);
|
@ -0,0 +1,2 @@
|
|||||||
|
-- REFRESH AUTHORIZATION
|
||||||
|
REFRESH AUTHORIZATION;
|
2
test/parser/impala/syntax/fixtures/refresh_function.sql
Normal file
2
test/parser/impala/syntax/fixtures/refresh_function.sql
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
--REFRESH FUNCTIONS db_name
|
||||||
|
REFRESH FUNCTIONS my_db;
|
32
test/parser/impala/syntax/fixtures/revoke.sql
Normal file
32
test/parser/impala/syntax/fixtures/revoke.sql
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
-- REVOKE ROLE role_name FROM GROUP group_name
|
||||||
|
REVOKE ROLE my_role FROM GROUP my_group;
|
||||||
|
|
||||||
|
-- REVOKE privilege ON object_type object_name FROM USER user_name
|
||||||
|
REVOKE ALL ON SERVER my_server FROM USER 'impala';
|
||||||
|
REVOKE ALTER ON DATABASE my_database FROM USER 'impala';
|
||||||
|
REVOKE CREATE ON TABLE my_table FROM USER 'impala';
|
||||||
|
REVOKE DROP ON URI my_uri FROM USER 'impala';
|
||||||
|
REVOKE INSERT ON URI my_uri FROM USER 'impala';
|
||||||
|
REVOKE REFRESH ON TABLE my_table FROM USER 'impala';
|
||||||
|
REVOKE SELECT ON TABLE my_table FROM USER 'impala';
|
||||||
|
REVOKE SELECT(column_name) ON TABLE my_table FROM USER 'impala';
|
||||||
|
|
||||||
|
-- REVOKE privilege ON object_type object_name FROM GROUP group_name
|
||||||
|
REVOKE ALL ON SERVER my_server FROM GROUP 'impala_group';
|
||||||
|
REVOKE ALTER ON DATABASE my_database FROM GROUP 'impala_group';
|
||||||
|
REVOKE CREATE ON TABLE my_table FROM GROUP 'impala_group';
|
||||||
|
REVOKE DROP ON URI my_uri FROM GROUP 'impala_group';
|
||||||
|
REVOKE INSERT ON URI my_uri FROM GROUP 'impala_group';
|
||||||
|
REVOKE REFRESH ON TABLE my_table FROM GROUP 'impala_group';
|
||||||
|
REVOKE SELECT ON TABLE my_table FROM GROUP 'impala';
|
||||||
|
REVOKE SELECT(column_name) ON TABLE my_table FROM GROUP 'impala_group';
|
||||||
|
|
||||||
|
-- REVOKE [GRANT OPTION FOR] privilege ON object_type object_name FROM [ROLE] role_name
|
||||||
|
REVOKE ALL ON SERVER my_server FROM 'impala_role';
|
||||||
|
REVOKE GRANT OPTION FOR ALL ON SERVER my_server FROM ROLE 'impala_role';
|
||||||
|
REVOKE SELECT ON DATABASE my_table FROM ROLE 'impala_role';
|
||||||
|
REVOKE GRANT OPTION FOR SELECT(column_name) ON TABLE my_table FROM 'impala_role';
|
||||||
|
|
||||||
|
-- example
|
||||||
|
REVOKE GRANT OPTION FOR ALL ON SERVER FROM ROLE foo_role;
|
||||||
|
REVOKE ALL ON SERVER FROM ROLE foo_role;
|
191
test/parser/impala/syntax/fixtures/select.sql
Normal file
191
test/parser/impala/syntax/fixtures/select.sql
Normal file
@ -0,0 +1,191 @@
|
|||||||
|
-- example
|
||||||
|
-- JOINS
|
||||||
|
SELECT * from a;
|
||||||
|
SELECT t1.c1, t2.c2 FROM t1 JOIN t2
|
||||||
|
ON t1.id = t2.id and t1.type_flag = t2.type_flag
|
||||||
|
WHERE t1.c1 > 100;
|
||||||
|
|
||||||
|
SELECT t1.c1, t2.c2 FROM t1 JOIN t2
|
||||||
|
USING (id, type_flag)
|
||||||
|
WHERE t1.c1 > 100;
|
||||||
|
|
||||||
|
SELECT t1.c1, t2.c2 FROM t1, t2
|
||||||
|
WHERE
|
||||||
|
t1.id = t2.id AND t1.type_flag = t2.type_flag
|
||||||
|
AND t1.c1 > 100;
|
||||||
|
|
||||||
|
SELECT lhs.id, rhs.parent, lhs.c1, rhs.c2 FROM tree_data lhs, tree_data rhs WHERE lhs.id = rhs.parent;
|
||||||
|
|
||||||
|
SELECT t1.id, c1, c2 FROM t1, t2 WHERE t1.id = t2.id;
|
||||||
|
|
||||||
|
SELECT t1.id, c1, c2 FROM t1 JOIN t2 ON t1.id = t2.id;
|
||||||
|
|
||||||
|
SELECT t1.id, c1, c2 FROM t1 INNER JOIN t2 ON t1.id = t2.id;
|
||||||
|
|
||||||
|
SELECT * FROM t1 LEFT OUTER JOIN t2 ON t1.id = t2.id;
|
||||||
|
|
||||||
|
SELECT * FROM t1 RIGHT OUTER JOIN t2 ON t1.id = t2.id;
|
||||||
|
|
||||||
|
SELECT * FROM t1 FULL OUTER JOIN t2 ON t1.id = t2.id;
|
||||||
|
|
||||||
|
SELECT * FROM t1 CROSS JOIN t2 WHERE t1.total > t2.maximum_price;
|
||||||
|
|
||||||
|
SELECT * FROM t1 LEFT OUTER JOIN t2 ON t1.int_col < t2.int_col;
|
||||||
|
|
||||||
|
SELECT t1.c1, t1.c2, t1.c2 FROM t1 LEFT SEMI JOIN t2 ON t1.id = t2.id;
|
||||||
|
|
||||||
|
select t1.c1 as first_id, t2.c2 as second_id from
|
||||||
|
t1 join t2 on first_id = second_id;
|
||||||
|
|
||||||
|
select fact.custno, dimension.custno from
|
||||||
|
customer_data as fact join customer_address as dimension
|
||||||
|
using (custno);
|
||||||
|
|
||||||
|
-- ORDER BY
|
||||||
|
SELECT id FROM games ORDER BY score DESC;
|
||||||
|
|
||||||
|
SELECT id, item FROM games, games.score
|
||||||
|
WHERE item > 1000000
|
||||||
|
ORDER BY id, item desc;
|
||||||
|
|
||||||
|
SELECT id, info.key1 AS k, info.value1 AS v from games3, games3.play AS plays, games3.item AS info
|
||||||
|
WHERE info.KEY1 = 'score' AND info.VALUE1 > 1000000
|
||||||
|
ORDER BY id, info.value1 desc;
|
||||||
|
|
||||||
|
SELECT user_id AS "Top 10 Visitors", SUM(page_views) FROM web_stats
|
||||||
|
GROUP BY page_views, user_id
|
||||||
|
ORDER BY SUM(page_views) DESC LIMIT 10;
|
||||||
|
|
||||||
|
SELECT page_title AS "Page 3 of search results", page_url FROM search_content
|
||||||
|
WHERE LOWER(page_title) LIKE '%game%'
|
||||||
|
ORDER BY page_title LIMIT 10 OFFSET 20;
|
||||||
|
|
||||||
|
select x from numbers order by x desc nulls last;
|
||||||
|
|
||||||
|
-- GROUP BY
|
||||||
|
select
|
||||||
|
ss_item_sk as Item,
|
||||||
|
count(ss_item_sk) as Times_Purchased,
|
||||||
|
sum(ss_quantity) as Total_Quantity_Purchased
|
||||||
|
from store_sales
|
||||||
|
group by ss_item_sk
|
||||||
|
order by sum(ss_quantity) desc
|
||||||
|
limit 5;
|
||||||
|
|
||||||
|
select
|
||||||
|
ss_item_sk as Item,
|
||||||
|
count(ss_item_sk) as Times_Purchased,
|
||||||
|
sum(ss_quantity) as Total_Quantity_Purchased
|
||||||
|
from store_sales
|
||||||
|
group by ss_item_sk
|
||||||
|
having times_purchased >= 100
|
||||||
|
order by sum(ss_quantity)
|
||||||
|
limit 5;
|
||||||
|
|
||||||
|
select ss_wholesale_cost, avg(ss_quantity * ss_sales_price) as avg_revenue_per_sale
|
||||||
|
from sales
|
||||||
|
group by ss_wholesale_cost
|
||||||
|
order by avg_revenue_per_sale desc
|
||||||
|
limit 5;
|
||||||
|
|
||||||
|
select x as "Top 3" from numbers order by x desc limit 3;
|
||||||
|
|
||||||
|
SELECT X FROM T1 LIMIT LENGTH('HELLO WORLD');
|
||||||
|
SELECT x FROM t1 LIMIT cast(truncate(9.9) AS INT);
|
||||||
|
|
||||||
|
-- UNION
|
||||||
|
select * from (select x from few_ints union all select x from few_ints) as t1 order by x;
|
||||||
|
|
||||||
|
-- Subqueries
|
||||||
|
SELECT employee_name, employee_id FROM employees one WHERE
|
||||||
|
salary > (SELECT avg(salary) FROM employees two WHERE one.dept_id = two.dept_id);
|
||||||
|
|
||||||
|
SELECT avg(t1.x), max(t2.y) FROM
|
||||||
|
(SELECT id, cast(a AS DECIMAL(10,5)) AS x FROM raw_data WHERE a BETWEEN 0 AND 100) AS t1
|
||||||
|
JOIN
|
||||||
|
(SELECT id, length(s) AS y FROM raw_data WHERE s LIKE 'A%') AS t2
|
||||||
|
USING (id);
|
||||||
|
|
||||||
|
SELECT count(x) FROM t1 WHERE EXISTS(SELECT 1 FROM t2 WHERE t1.x = t2.y * 10);
|
||||||
|
|
||||||
|
SELECT x FROM t1 WHERE x IN (SELECT y FROM t2 WHERE state = 'CA');
|
||||||
|
|
||||||
|
SELECT x FROM t1 WHERE y = (SELECT max(z) FROM t2);
|
||||||
|
|
||||||
|
SELECT x FROM t1 WHERE y > (SELECT count(z) FROM t2);
|
||||||
|
|
||||||
|
SELECT * FROM t1 one WHERE id IN (SELECT parent FROM t1 two WHERE t1.parent = t2.id);
|
||||||
|
|
||||||
|
-- TABLESAMPLE
|
||||||
|
select distinct x from sample_demo tablesample system(50);
|
||||||
|
|
||||||
|
select distinct x from sample_demo
|
||||||
|
tablesample system(50) repeatable (12345);
|
||||||
|
|
||||||
|
select count(*) from sample_demo_partitions
|
||||||
|
tablesample system(50) where n = 1;
|
||||||
|
|
||||||
|
-- WITH
|
||||||
|
with t1 as (select 1), t2 as (select 2) insert into tab select * from t1 union all select * from t2;
|
||||||
|
|
||||||
|
-- DISTINCT
|
||||||
|
SELECT COUNT(DISTINCT c_salutation, c_last_name) FROM customer;
|
||||||
|
|
||||||
|
SELECT DISTINCT c_salutation, c_last_name FROM customer;
|
||||||
|
|
||||||
|
-- OTHERS
|
||||||
|
select
|
||||||
|
r_name,
|
||||||
|
count(r_nations.item.n_nationkey) as count,
|
||||||
|
sum(r_nations.item.n_nationkey) as sum,
|
||||||
|
avg(r_nations.item.n_nationkey) as avg,
|
||||||
|
min(r_nations.item.n_name) as minimum,
|
||||||
|
max(r_nations.item.n_name) as maximum,
|
||||||
|
ndv(r_nations.item.n_nationkey) as distinct_vals
|
||||||
|
from
|
||||||
|
region, region.r_nations as r_nations
|
||||||
|
group by r_name
|
||||||
|
order by r_name;
|
||||||
|
|
||||||
|
select "contains an even number" as assertion from t3 where exists (select z from t3 where z % 2 = 0) limit 1;
|
||||||
|
|
||||||
|
select null is distinct from null, null != null;
|
||||||
|
|
||||||
|
select
|
||||||
|
'x' is distinct from 'x ' as string_with_trailing_spaces,
|
||||||
|
cast('x' as char(5)) is distinct from cast('x ' as char(5)) as char_with_trailing_spaces;
|
||||||
|
|
||||||
|
select c_first_name, c_last_name from customer where c_first_name regexp '^J.*';
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
t1.transaction_id as transaction_id1,
|
||||||
|
t1.customer_id,
|
||||||
|
t1.transaction_date,
|
||||||
|
t1.transaction_amount,
|
||||||
|
t2.transaction_id as subsequent_transaction_id
|
||||||
|
FROM
|
||||||
|
transactions t1
|
||||||
|
LEFT JOIN (
|
||||||
|
SELECT
|
||||||
|
transaction_id,
|
||||||
|
customer_id,
|
||||||
|
transaction_date,
|
||||||
|
transaction_amount,
|
||||||
|
LEAD (transaction_id) OVER (
|
||||||
|
PARTITION BY
|
||||||
|
customer_id
|
||||||
|
ORDER BY
|
||||||
|
transaction_date
|
||||||
|
) AS transaction_id
|
||||||
|
FROM
|
||||||
|
transactions
|
||||||
|
) t2 ON t1.transaction_id = t2.transaction_id
|
||||||
|
AND t1.customer_id = t2.customer_id
|
||||||
|
AND t1.transaction_date = t2.transaction_date
|
||||||
|
AND t1.transaction_amount = t2.transaction_amount;
|
||||||
|
|
||||||
|
select appx_median(x) from million_numbers;
|
||||||
|
|
||||||
|
select count(x) as higher from million_numbers where x > (select appx_median(x) from million_numbers);
|
||||||
|
|
||||||
|
select avg(length(s)) from t1;
|
7
test/parser/impala/syntax/fixtures/set.sql
Normal file
7
test/parser/impala/syntax/fixtures/set.sql
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
-- SET
|
||||||
|
SET;
|
||||||
|
-- SET ALL
|
||||||
|
SET ALL;
|
||||||
|
-- SET query_option=option_value
|
||||||
|
set compression_codec=gzip;
|
||||||
|
set mt_dop = 0;
|
167
test/parser/impala/syntax/fixtures/show.sql
Normal file
167
test/parser/impala/syntax/fixtures/show.sql
Normal file
@ -0,0 +1,167 @@
|
|||||||
|
-- SHOW DATABASES [[LIKE] 'pattern']
|
||||||
|
SHOW DATABASES;
|
||||||
|
|
||||||
|
SHOW DATABASES 'xxx';
|
||||||
|
|
||||||
|
SHOW DATABASES LIKE 'xxx';
|
||||||
|
|
||||||
|
-- SHOW SCHEMAS [[LIKE] 'pattern']
|
||||||
|
SHOW SCHEMAS;
|
||||||
|
|
||||||
|
SHOW SCHEMAS 'xxx';
|
||||||
|
|
||||||
|
SHOW SCHEMAS LIKE 'xxx';
|
||||||
|
|
||||||
|
-- SHOW TABLES [IN database_name] [[LIKE] 'pattern']
|
||||||
|
SHOW TABLES;
|
||||||
|
|
||||||
|
SHOW TABLES 'xxx';
|
||||||
|
|
||||||
|
SHOW TABLES LIKE 'xxx';
|
||||||
|
|
||||||
|
SHOW TABLES IN my_db;
|
||||||
|
|
||||||
|
SHOW TABLES IN my_db 'xxx';
|
||||||
|
|
||||||
|
SHOW TABLES IN my_db LIKE 'xxx';
|
||||||
|
|
||||||
|
-- SHOW [AGGREGATE | ANALYTIC] FUNCTIONS [IN database_name] [[LIKE] 'pattern']
|
||||||
|
SHOW FUNCTIONS;
|
||||||
|
|
||||||
|
SHOW FUNCTIONS 'xxx';
|
||||||
|
|
||||||
|
SHOW FUNCTIONS LIKE 'xxx';
|
||||||
|
|
||||||
|
SHOW FUNCTIONS IN my_db;
|
||||||
|
|
||||||
|
SHOW FUNCTIONS IN my_db 'xxx';
|
||||||
|
|
||||||
|
SHOW FUNCTIONS IN my_db LIKE 'xxx';
|
||||||
|
|
||||||
|
SHOW ANALYTIC FUNCTIONS IN my_db LIKE 'xxx';
|
||||||
|
|
||||||
|
SHOW AGGREGATE FUNCTIONS IN my_db LIKE 'xxx';
|
||||||
|
|
||||||
|
-- SHOW CREATE TABLE [database_name].table_name
|
||||||
|
SHOW CREATE TABLE my_table;
|
||||||
|
|
||||||
|
SHOW CREATE TABLE my_db.my_table;
|
||||||
|
|
||||||
|
-- SHOW CREATE VIEW [database_name].view_name
|
||||||
|
SHOW CREATE VIEW my_table;
|
||||||
|
|
||||||
|
SHOW CREATE VIEW my_db.my_table;
|
||||||
|
|
||||||
|
-- SHOW TABLE STATS [database_name.]table_name
|
||||||
|
SHOW TABLE STATS my_table;
|
||||||
|
|
||||||
|
SHOW TABLE STATS my_db.my_table;
|
||||||
|
|
||||||
|
-- SHOW COLUMN STATS [database_name.]table_name
|
||||||
|
SHOW COLUMN STATS my_table;
|
||||||
|
|
||||||
|
SHOW COLUMN STATS my_db.my_table;
|
||||||
|
|
||||||
|
-- SHOW PARTITIONS [database_name.]table_name
|
||||||
|
SHOW PARTITIONS my_table;
|
||||||
|
|
||||||
|
SHOW PARTITIONS my_db.my_table;
|
||||||
|
|
||||||
|
-- SHOW [RANGE] PARTITIONS [database_name.]table_name
|
||||||
|
SHOW RANGE PARTITIONS my_table;
|
||||||
|
|
||||||
|
SHOW RANGE PARTITIONS my_db.my_table;
|
||||||
|
|
||||||
|
-- SHOW FILES IN [database_name.]table_name [PARTITION (key_col_expression [, key_col_expression]]
|
||||||
|
SHOW FILES IN my_table;
|
||||||
|
|
||||||
|
SHOW FILES IN my_db.my_table;
|
||||||
|
|
||||||
|
SHOW FILES IN my_db.my_table PARTITION (
|
||||||
|
"date" = "1110-11-11",
|
||||||
|
age BETWEEN 100
|
||||||
|
AND 200
|
||||||
|
);
|
||||||
|
|
||||||
|
SHOW ROLES;
|
||||||
|
|
||||||
|
SHOW CURRENT ROLES;
|
||||||
|
|
||||||
|
SHOW ROLE GRANT GROUP group_name;
|
||||||
|
|
||||||
|
SHOW GRANT USER user_name;
|
||||||
|
|
||||||
|
SHOW GRANT USER user_name ON SERVER;
|
||||||
|
|
||||||
|
SHOW GRANT USER user_name ON DATABASE database_name;
|
||||||
|
|
||||||
|
SHOW GRANT USER user_name ON TABLE database_name.table_name;
|
||||||
|
|
||||||
|
SHOW GRANT USER user_name ON URI my_uri;
|
||||||
|
|
||||||
|
SHOW GRANT USER user_name ON COLUMN database_name.table_name.column_name;
|
||||||
|
|
||||||
|
SHOW GRANT ROLE role_name;
|
||||||
|
|
||||||
|
SHOW GRANT ROLE role_name ON SERVER;
|
||||||
|
|
||||||
|
SHOW GRANT ROLE role_name ON DATABASE database_name;
|
||||||
|
|
||||||
|
SHOW GRANT ROLE role_name ON TABLE database_name.table_name;
|
||||||
|
|
||||||
|
SHOW GRANT ROLE role_name ON URI my_uri;
|
||||||
|
|
||||||
|
SHOW GRANT ROLE role_name ON COLUMN database_name.table_name.column_name;
|
||||||
|
|
||||||
|
SHOW GRANT GROUP group_name ON SERVER;
|
||||||
|
|
||||||
|
SHOW GRANT GROUP group_name ON DATABASE database_name;
|
||||||
|
|
||||||
|
SHOW GRANT GROUP group_name ON TABLE database_name.table_name;
|
||||||
|
|
||||||
|
SHOW GRANT GROUP group_name ON URI my_uri;
|
||||||
|
|
||||||
|
SHOW GRANT GROUP group_name ON COLUMN database_name.table_name.column_name;
|
||||||
|
|
||||||
|
-- example
|
||||||
|
SHOW DATABASES 'a*';
|
||||||
|
|
||||||
|
SHOW DATABASES LIKE 'a*';
|
||||||
|
|
||||||
|
SHOW TABLES IN some_db LIKE '*fact*';
|
||||||
|
|
||||||
|
SHOW TABLES '*dim*|*fact*';
|
||||||
|
|
||||||
|
show files in sample_table partition (j < 5);
|
||||||
|
|
||||||
|
show files in sample_table partition (
|
||||||
|
k = 3,
|
||||||
|
l between 1
|
||||||
|
and 10
|
||||||
|
);
|
||||||
|
|
||||||
|
show files in sample_table partition (month like 'J%');
|
||||||
|
|
||||||
|
show files in unpart_text;
|
||||||
|
|
||||||
|
show partitions part_text;
|
||||||
|
|
||||||
|
show files in s3_testing.sample_data_s3;
|
||||||
|
|
||||||
|
show roles;
|
||||||
|
|
||||||
|
show current roles;
|
||||||
|
|
||||||
|
show tables in full_db like 'dim*';
|
||||||
|
|
||||||
|
show CREATE TABLE numeric_grades_default_letter;
|
||||||
|
|
||||||
|
show range partitions numeric_grades_default_letter;
|
||||||
|
|
||||||
|
show table stats kudu_table;
|
||||||
|
|
||||||
|
show column stats customer;
|
||||||
|
|
||||||
|
show functions in _impala_builtins;
|
||||||
|
|
||||||
|
show functions in _impala_builtins like '*week*';
|
14
test/parser/impala/syntax/fixtures/shutdown.sql
Normal file
14
test/parser/impala/syntax/fixtures/shutdown.sql
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
-- :SHUTDOWN();
|
||||||
|
:SHUTDOWN();
|
||||||
|
|
||||||
|
-- :SHUTDOWN([host_name[:port_number] )
|
||||||
|
:SHUTDOWN("hostname:1234");
|
||||||
|
:SHUTDOWN('hostname');
|
||||||
|
|
||||||
|
-- :SHUTDOWN(deadline)
|
||||||
|
:SHUTDOWN(0);
|
||||||
|
:SHUTDOWN(10);
|
||||||
|
|
||||||
|
-- :SHUTDOWN([host_name[:port_number], deadline)
|
||||||
|
:SHUTDOWN('hostname', 10);
|
||||||
|
:SHUTDOWN('hostname:11', 10 * 60);
|
10
test/parser/impala/syntax/fixtures/truncate_table.sql
Normal file
10
test/parser/impala/syntax/fixtures/truncate_table.sql
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
-- TRUNCATE [TABLE] [IF EXISTS] [db_name.]table_name
|
||||||
|
TRUNCATE my_table;
|
||||||
|
TRUNCATE my_db.my_table;
|
||||||
|
TRUNCATE TABLE my_table;
|
||||||
|
TRUNCATE IF EXISTS my_db.my_table;
|
||||||
|
TRUNCATE TABLE IF EXISTS my_db.my_table;
|
||||||
|
|
||||||
|
-- example
|
||||||
|
TRUNCATE TABLE truncate_demo;
|
||||||
|
TRUNCATE TABLE IF EXISTS staging_table2;
|
146
test/parser/impala/syntax/fixtures/update.sql
Normal file
146
test/parser/impala/syntax/fixtures/update.sql
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
/* UPDATE [database_name.]table_name SET col = val [, col = val ... ]
|
||||||
|
[ FROM joined_table_refs ]
|
||||||
|
[ WHERE where_conditions ] */
|
||||||
|
UPDATE
|
||||||
|
my_table
|
||||||
|
SET
|
||||||
|
col1 = 1,
|
||||||
|
col2 = 2,
|
||||||
|
col3 = 3;
|
||||||
|
|
||||||
|
UPDATE
|
||||||
|
my_db.my_table
|
||||||
|
SET
|
||||||
|
col1 = 1;
|
||||||
|
|
||||||
|
UPDATE
|
||||||
|
my_db.my_table
|
||||||
|
SET
|
||||||
|
col1 = 1
|
||||||
|
WHERE
|
||||||
|
col2 = 1;
|
||||||
|
|
||||||
|
UPDATE
|
||||||
|
my_db.my_table
|
||||||
|
SET
|
||||||
|
col1 = 1
|
||||||
|
WHERE
|
||||||
|
col2 = 1
|
||||||
|
AND col3 BETWEEN 100
|
||||||
|
AND 300;
|
||||||
|
|
||||||
|
UPDATE
|
||||||
|
my_table
|
||||||
|
SET
|
||||||
|
col1 = 'new_value'
|
||||||
|
FROM
|
||||||
|
other_table
|
||||||
|
WHERE
|
||||||
|
my_table.id = other_table.id;
|
||||||
|
|
||||||
|
UPDATE
|
||||||
|
my_table
|
||||||
|
SET
|
||||||
|
col1 = (
|
||||||
|
SELECT
|
||||||
|
MAX(col2)
|
||||||
|
FROM
|
||||||
|
other_table
|
||||||
|
WHERE
|
||||||
|
other_table.id = my_table.id
|
||||||
|
)
|
||||||
|
WHERE
|
||||||
|
col3 = 'value';
|
||||||
|
|
||||||
|
UPDATE
|
||||||
|
my_table
|
||||||
|
SET
|
||||||
|
col1 = CASE
|
||||||
|
WHEN col2 > 10 THEN 'High'
|
||||||
|
WHEN col2 > 5 THEN 'Medium'
|
||||||
|
ELSE 'Low'
|
||||||
|
END
|
||||||
|
WHERE
|
||||||
|
col3 = 'value';
|
||||||
|
|
||||||
|
UPDATE
|
||||||
|
my_table
|
||||||
|
SET
|
||||||
|
col1 = (
|
||||||
|
SELECT
|
||||||
|
AVG(col2)
|
||||||
|
FROM
|
||||||
|
other_table
|
||||||
|
WHERE
|
||||||
|
other_table.id = my_table.id
|
||||||
|
GROUP BY
|
||||||
|
other_table.id
|
||||||
|
)
|
||||||
|
WHERE
|
||||||
|
col3 = 'value';
|
||||||
|
|
||||||
|
UPDATE
|
||||||
|
my_table
|
||||||
|
SET
|
||||||
|
col1 = other_table.val1
|
||||||
|
FROM
|
||||||
|
my_table
|
||||||
|
JOIN other_table ON my_table.id = other_table.id
|
||||||
|
WHERE
|
||||||
|
my_table.col2 = 'value';
|
||||||
|
|
||||||
|
--example
|
||||||
|
UPDATE
|
||||||
|
kudu_table
|
||||||
|
SET
|
||||||
|
c3 = 'not applicable';
|
||||||
|
|
||||||
|
UPDATE
|
||||||
|
kudu_table
|
||||||
|
SET
|
||||||
|
c3 = NULL
|
||||||
|
WHERE
|
||||||
|
c1 > 100
|
||||||
|
AND c3 IS NULL;
|
||||||
|
|
||||||
|
UPDATE
|
||||||
|
kudu_table
|
||||||
|
SET
|
||||||
|
c3 = 'impossible'
|
||||||
|
WHERE
|
||||||
|
1 = 0;
|
||||||
|
|
||||||
|
UPDATE
|
||||||
|
kudu_table
|
||||||
|
SET
|
||||||
|
c3 = upper(c3),
|
||||||
|
c4 = FALSE,
|
||||||
|
c5 = 0
|
||||||
|
WHERE
|
||||||
|
c6 = TRUE;
|
||||||
|
|
||||||
|
UPDATE
|
||||||
|
kudu_table
|
||||||
|
SET
|
||||||
|
c3 = upper(c3)
|
||||||
|
FROM
|
||||||
|
kudu_table
|
||||||
|
JOIN non_kudu_table ON kudu_table.id = non_kudu_table.id;
|
||||||
|
|
||||||
|
UPDATE
|
||||||
|
t1
|
||||||
|
SET
|
||||||
|
c3 = upper(c3)
|
||||||
|
FROM
|
||||||
|
kudu_table t1
|
||||||
|
JOIN non_kudu_table t2 ON t1.id = t2.id;
|
||||||
|
|
||||||
|
UPDATE
|
||||||
|
t1
|
||||||
|
SET
|
||||||
|
c3 = upper(c3)
|
||||||
|
FROM
|
||||||
|
kudu_table t1
|
||||||
|
JOIN non_kudu_table t2 ON t1.id = t2.id
|
||||||
|
WHERE
|
||||||
|
c3 != upper(c3);
|
89
test/parser/impala/syntax/fixtures/upsert.sql
Normal file
89
test/parser/impala/syntax/fixtures/upsert.sql
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
/* UPSERT [hint_clause] INTO [TABLE] [db_name.]table_name
|
||||||
|
[(column_list)]
|
||||||
|
{
|
||||||
|
[hint_clause] select_statement
|
||||||
|
| VALUES (value [, value ...]) [, (value [, value ...]) ...]
|
||||||
|
} */
|
||||||
|
UPSERT INTO my_table
|
||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
'new_value1',
|
||||||
|
'new_value2'
|
||||||
|
FROM
|
||||||
|
other_table
|
||||||
|
WHERE
|
||||||
|
condition;
|
||||||
|
|
||||||
|
UPSERT -- +NOSHUFFLE -- +CLUSTERED
|
||||||
|
INTO my_table
|
||||||
|
/* +NOSHUFFLE */
|
||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
'new_value1',
|
||||||
|
'new_value2'
|
||||||
|
FROM
|
||||||
|
other_table
|
||||||
|
WHERE
|
||||||
|
condition;
|
||||||
|
|
||||||
|
UPSERT INTO my_table -- +SHUFFLE
|
||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
'new_value1',
|
||||||
|
'new_value2'
|
||||||
|
FROM
|
||||||
|
other_table
|
||||||
|
WHERE
|
||||||
|
condition;
|
||||||
|
|
||||||
|
UPSERT INTO my_table (id, col1, col2)
|
||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
'new_value1',
|
||||||
|
'new_value2'
|
||||||
|
FROM
|
||||||
|
other_table
|
||||||
|
WHERE
|
||||||
|
condition;
|
||||||
|
|
||||||
|
UPSERT INTO TABLE my_db.my_table (id, col1, col2)
|
||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
'new_value1',
|
||||||
|
'new_value2'
|
||||||
|
FROM
|
||||||
|
other_table
|
||||||
|
WHERE
|
||||||
|
condition;
|
||||||
|
|
||||||
|
UPSERT INTO my_table (id, col1, col2)
|
||||||
|
VALUES
|
||||||
|
(1, 'new_value1', 'new_value2'),
|
||||||
|
(2, 'new_value3', 'new_value4');
|
||||||
|
|
||||||
|
UPSERT -- +NOSHUFFLE -- +CLUSTERED
|
||||||
|
INTO my_db.my_table
|
||||||
|
VALUES
|
||||||
|
(1, 'new_value1', 'new_value2'),
|
||||||
|
(2, 'new_value3', 'new_value4');
|
||||||
|
|
||||||
|
-- example
|
||||||
|
UPSERT INTO kudu_table (pk, c1, c2, c3)
|
||||||
|
VALUES
|
||||||
|
(0, 'hello', 50, true),
|
||||||
|
(1, 'world', -1, false);
|
||||||
|
|
||||||
|
UPSERT INTO production_table
|
||||||
|
SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
staging_table;
|
||||||
|
|
||||||
|
UPSERT INTO production_table
|
||||||
|
SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
staging_table
|
||||||
|
WHERE
|
||||||
|
c1 IS NOT NULL
|
||||||
|
AND c2 > 0;
|
2
test/parser/impala/syntax/fixtures/use.sql
Normal file
2
test/parser/impala/syntax/fixtures/use.sql
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
-- USE db_name
|
||||||
|
USE my_db;
|
10
test/parser/impala/syntax/fixtures/values.sql
Normal file
10
test/parser/impala/syntax/fixtures/values.sql
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
-- VALUES (row)[, (row), ...];
|
||||||
|
VALUES ('r1_c1', 'r1_c2', 'r1_c3');
|
||||||
|
VALUES ('r1_c1', 'r1_c2', 'r1_c3'), ('r1_c1', 'r1_c2', 'r1_c3');
|
||||||
|
VALUES ('r1_c1', 'r1_c2', 'r1_c3'), ('r1_c1', 'r1_c2', 'r1_c3'), ('r1_c1', 'r1_c2', 'r1_c3');
|
||||||
|
VALUES ('r1_c1' as 'hi', 'r1_c2', 'r1_c3'), ('r1_c1', 'r1_c2', 'r1_c3' as 'hi');
|
||||||
|
|
||||||
|
-- example
|
||||||
|
VALUES(4,5,6),(7,8,9);
|
||||||
|
VALUES(1 AS c1, true AS c2, 'abc' AS c3), (100,false,'xyz');
|
||||||
|
VALUES (CAST('2019-01-01' AS TIMESTAMP)), ('2019-02-02');
|
18
test/parser/impala/syntax/insert.test.ts
Normal file
18
test/parser/impala/syntax/insert.test.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import ImpalaSQL from '../../../../src/parser/impala';
|
||||||
|
import { readSQL } from '../../../helper';
|
||||||
|
|
||||||
|
const parser = new ImpalaSQL();
|
||||||
|
|
||||||
|
const features = {
|
||||||
|
insert: readSQL(__dirname, 'insert.sql'),
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('ImpalaSQL Insert Syntax Tests', () => {
|
||||||
|
describe('INSERT', () => {
|
||||||
|
features.insert.forEach((db) => {
|
||||||
|
it(db, () => {
|
||||||
|
expect(parser.validate(db).length).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
114
test/parser/impala/syntax/otherStatement.test.ts
Normal file
114
test/parser/impala/syntax/otherStatement.test.ts
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
import ImpalaSQL from '../../../../src/parser/impala';
|
||||||
|
import { readSQL } from '../../../helper';
|
||||||
|
|
||||||
|
const parser = new ImpalaSQL();
|
||||||
|
|
||||||
|
const features = {
|
||||||
|
computeStats: readSQL(__dirname, 'compute_stats.sql'),
|
||||||
|
comments: readSQL(__dirname, 'comment.sql'),
|
||||||
|
grants: readSQL(__dirname, 'grant.sql'),
|
||||||
|
revokes: readSQL(__dirname, 'revoke.sql'),
|
||||||
|
loadData: readSQL(__dirname, 'load_data.sql'),
|
||||||
|
describes: readSQL(__dirname, 'describe.sql'),
|
||||||
|
explains: readSQL(__dirname, 'explain.sql'),
|
||||||
|
invalidates: readSQL(__dirname, 'invalidate_metadata.sql'),
|
||||||
|
set: readSQL(__dirname, 'set.sql'),
|
||||||
|
shutdown: readSQL(__dirname, 'shutdown.sql'),
|
||||||
|
truncate: readSQL(__dirname, 'truncate_table.sql'),
|
||||||
|
use: readSQL(__dirname, 'use.sql'),
|
||||||
|
values: readSQL(__dirname, 'values.sql'),
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('ImpalaSQL Other Syntax Tests', () => {
|
||||||
|
describe('COMPUTE STATS', () => {
|
||||||
|
features.computeStats.forEach((db) => {
|
||||||
|
it(db, () => {
|
||||||
|
expect(parser.validate(db).length).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('COMMENT STATEMENT', () => {
|
||||||
|
features.comments.forEach((db) => {
|
||||||
|
it(db, () => {
|
||||||
|
expect(parser.validate(db).length).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('GRANT STATEMENT', () => {
|
||||||
|
features.grants.forEach((db) => {
|
||||||
|
it(db, () => {
|
||||||
|
expect(parser.validate(db).length).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('REVOKE STATEMENT', () => {
|
||||||
|
features.revokes.forEach((db) => {
|
||||||
|
it(db, () => {
|
||||||
|
expect(parser.validate(db).length).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('LOAD DATA STATEMENT', () => {
|
||||||
|
features.loadData.forEach((db) => {
|
||||||
|
it(db, () => {
|
||||||
|
expect(parser.validate(db).length).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('DESCRIBE STATEMENT', () => {
|
||||||
|
features.describes.forEach((db) => {
|
||||||
|
it(db, () => {
|
||||||
|
expect(parser.validate(db).length).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('EXPLAIN STATEMENT', () => {
|
||||||
|
features.explains.forEach((db) => {
|
||||||
|
it(db, () => {
|
||||||
|
expect(parser.validate(db).length).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('INVALIDATE METADATA STATEMENT', () => {
|
||||||
|
features.invalidates.forEach((db) => {
|
||||||
|
it(db, () => {
|
||||||
|
expect(parser.validate(db).length).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('SET STATEMENT', () => {
|
||||||
|
features.set.forEach((db) => {
|
||||||
|
it(db, () => {
|
||||||
|
expect(parser.validate(db).length).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('SHUTDOWN STATEMENT', () => {
|
||||||
|
features.shutdown.forEach((db) => {
|
||||||
|
it(db, () => {
|
||||||
|
expect(parser.validate(db).length).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('TRUNCATE TABLE STATEMENT', () => {
|
||||||
|
features.truncate.forEach((db) => {
|
||||||
|
it(db, () => {
|
||||||
|
expect(parser.validate(db).length).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('USE STATEMENT', () => {
|
||||||
|
features.use.forEach((db) => {
|
||||||
|
it(db, () => {
|
||||||
|
expect(parser.validate(db).length).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('VALUES STATEMENT', () => {
|
||||||
|
features.values.forEach((db) => {
|
||||||
|
it(db, () => {
|
||||||
|
expect(parser.validate(db).length).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
34
test/parser/impala/syntax/refresh.test.ts
Normal file
34
test/parser/impala/syntax/refresh.test.ts
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import ImpalaSQL from '../../../../src/parser/impala';
|
||||||
|
import { readSQL } from '../../../helper';
|
||||||
|
|
||||||
|
const parser = new ImpalaSQL();
|
||||||
|
|
||||||
|
const features = {
|
||||||
|
refresh: readSQL(__dirname, 'refresh.sql'),
|
||||||
|
authorization: readSQL(__dirname, 'refresh_authorization.sql'),
|
||||||
|
function: readSQL(__dirname, 'refresh_function.sql'),
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('ImpalaSQL Refresh Syntax Tests', () => {
|
||||||
|
describe('REFRESH', () => {
|
||||||
|
features.refresh.forEach((db) => {
|
||||||
|
it(db, () => {
|
||||||
|
expect(parser.validate(db).length).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('REFRESH AUTHORIZATION', () => {
|
||||||
|
features.authorization.forEach((db) => {
|
||||||
|
it(db, () => {
|
||||||
|
expect(parser.validate(db).length).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('REFRESH FUNCTION', () => {
|
||||||
|
features.function.forEach((db) => {
|
||||||
|
it(db, () => {
|
||||||
|
expect(parser.validate(db).length).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
18
test/parser/impala/syntax/select.test.ts
Normal file
18
test/parser/impala/syntax/select.test.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import ImpalaSQL from '../../../../src/parser/impala';
|
||||||
|
import { readSQL } from '../../../helper';
|
||||||
|
|
||||||
|
const parser = new ImpalaSQL();
|
||||||
|
|
||||||
|
const features = {
|
||||||
|
select: readSQL(__dirname, 'select.sql'),
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('ImpalaSQL Select Syntax Tests', () => {
|
||||||
|
describe('SELECT', () => {
|
||||||
|
features.select.forEach((db) => {
|
||||||
|
it(db, () => {
|
||||||
|
expect(parser.validate(db).length).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
18
test/parser/impala/syntax/show.test.ts
Normal file
18
test/parser/impala/syntax/show.test.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import ImpalaSQL from '../../../../src/parser/impala';
|
||||||
|
import { readSQL } from '../../../helper';
|
||||||
|
|
||||||
|
const parser = new ImpalaSQL();
|
||||||
|
|
||||||
|
const features = {
|
||||||
|
shows: readSQL(__dirname, 'show.sql'),
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('ImpalaSQL Show Syntax Tests', () => {
|
||||||
|
describe('SHOW', () => {
|
||||||
|
features.shows.forEach((db) => {
|
||||||
|
it(db, () => {
|
||||||
|
expect(parser.validate(db).length).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
18
test/parser/impala/syntax/update.test.ts
Normal file
18
test/parser/impala/syntax/update.test.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import ImpalaSQL from '../../../../src/parser/impala';
|
||||||
|
import { readSQL } from '../../../helper';
|
||||||
|
|
||||||
|
const parser = new ImpalaSQL();
|
||||||
|
|
||||||
|
const features = {
|
||||||
|
update: readSQL(__dirname, 'update.sql'),
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('ImpalaSQL Update Syntax Tests', () => {
|
||||||
|
describe('UPDATE', () => {
|
||||||
|
features.update.forEach((db) => {
|
||||||
|
it(db, () => {
|
||||||
|
expect(parser.validate(db).length).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
18
test/parser/impala/syntax/upsert.test.ts
Normal file
18
test/parser/impala/syntax/upsert.test.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import ImpalaSQL from '../../../../src/parser/impala';
|
||||||
|
import { readSQL } from '../../../helper';
|
||||||
|
|
||||||
|
const parser = new ImpalaSQL();
|
||||||
|
|
||||||
|
const features = {
|
||||||
|
update: readSQL(__dirname, 'upsert.sql'),
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('ImpalaSQL Upsert Syntax Tests', () => {
|
||||||
|
describe('UPSERT', () => {
|
||||||
|
features.update.forEach((db) => {
|
||||||
|
it(db, () => {
|
||||||
|
expect(parser.validate(db).length).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
32
test/parser/impala/visitor.test.ts
Normal file
32
test/parser/impala/visitor.test.ts
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import impalaSQL from '../../../src/parser/impala';
|
||||||
|
import { ImpalaSqlParserVisitor } from '../../../src/lib/impala/ImpalaSqlParserVisitor';
|
||||||
|
import { AbstractParseTreeVisitor } from 'antlr4ts/tree';
|
||||||
|
|
||||||
|
describe('impala SQL Visitor Tests', () => {
|
||||||
|
const expectTableName = 'user1';
|
||||||
|
const sql = `select id,name,sex from ${expectTableName};`;
|
||||||
|
const parser = new impalaSQL();
|
||||||
|
|
||||||
|
const parseTree = parser.parse(sql, (error) => {
|
||||||
|
console.log('Parse error:', error);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Visitor visitTableName', () => {
|
||||||
|
let result = '';
|
||||||
|
class MyVisitor
|
||||||
|
extends AbstractParseTreeVisitor<any>
|
||||||
|
implements ImpalaSqlParserVisitor<any>
|
||||||
|
{
|
||||||
|
protected defaultResult() {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
visitTableNamePath = (ctx): void => {
|
||||||
|
result = ctx.text.toLowerCase();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const visitor: any = new MyVisitor();
|
||||||
|
visitor.visit(parseTree);
|
||||||
|
|
||||||
|
expect(result).toBe(expectTableName);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user