Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(impala): support impala #184

Merged
merged 27 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c1bd56d
feat(impala): add impala sqlLexer
LuckyFBB Oct 17, 2023
5b0ccfd
feat(impala): add impala grammar
LuckyFBB Oct 25, 2023
87a6a68
feat(impala): add alter table sql
LuckyFBB Nov 13, 2023
b84fc3e
feat(impala): update alter table sql
LuckyFBB Nov 14, 2023
8e4933f
feat(impala): add alter db sql
LuckyFBB Nov 14, 2023
f8f2daa
feat(impala): add alter view sql
LuckyFBB Nov 14, 2023
c08eece
feat(impala): add compute stats/comment statement and update partitio…
LuckyFBB Nov 14, 2023
fc788a4
feat(impala): add drop statement sql
LuckyFBB Nov 14, 2023
a579070
feat(impala): add revoke and grant sql
LuckyFBB Nov 14, 2023
6323e45
feat(impala): add create db/function/role/view sql
LuckyFBB Nov 15, 2023
acf45ee
feat(impala): add describe/explain/invalidata_metadata/load_data sql
LuckyFBB Nov 15, 2023
8cce58d
feat(impala): add refresh/set/shutdown sql
LuckyFBB Nov 15, 2023
217f230
feat(impala): add truncate_table/use/values sql
LuckyFBB Nov 15, 2023
37dc390
fix(impala): update shutdown and invaliddate_metadata
LuckyFBB Nov 15, 2023
db9679d
feat(impala): add show/update/upsert sql
LuckyFBB Nov 15, 2023
ca4d10e
feat(impala): add create/insert sql
LuckyFBB Nov 17, 2023
4ac3b65
feat(impala): add select and delete sql
LuckyFBB Nov 19, 2023
37488fe
feat(impala): add impala tokens and fix todo
LuckyFBB Nov 20, 2023
8829d53
feat(impala): update impalaparser and some test unit
LuckyFBB Nov 21, 2023
3dfdb1d
feat(impala): add syntax suggestion
LuckyFBB Nov 22, 2023
9dd12c4
feat(impala): add syntax suggestion
LuckyFBB Nov 23, 2023
e37d85e
feat(impala): update test unit
LuckyFBB Nov 23, 2023
b1f4a52
feat(impala): remove reference
LuckyFBB Nov 27, 2023
843a8b8
fix(impala): add statement for sqlname and collect tableName
LuckyFBB Nov 27, 2023
8ae2ab3
fix(impala): fix syntax suggestion unit test
LuckyFBB Nov 28, 2023
6790202
fix(impala): update syntax suggestion and collect column
LuckyFBB Nov 28, 2023
d9e398e
feat(impala): add collect column create
LuckyFBB Nov 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/antlr4.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const chalk = require('chalk');
const grammarsPath = path.resolve(__dirname, '../src/grammar');
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';

Expand Down
366 changes: 366 additions & 0 deletions src/grammar/impala/ImpalaSqlLexer.g4
Original file line number Diff line number Diff line change
@@ -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'; // 文本文件格式
LuckyFBB marked this conversation as resolved.
Show resolved Hide resolved
KW_ORC : 'ORC'; //ORC文件格式
KW_AVRO : 'AVRO'; //Avro文件格式
KW_SEQUENCEFILE : 'SEQUENCEFILE'; //Sequence文件格式
KW_RCFILE : 'RCFILE'; //RC文件格式
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)
;
Loading
Loading