diff --git a/packages/cubejs-schema-compiler/src/parser/GenericSql.g4 b/packages/cubejs-schema-compiler/src/parser/GenericSql.g4 index fa4f744cf59db..5040ce9b1af7a 100644 --- a/packages/cubejs-schema-compiler/src/parser/GenericSql.g4 +++ b/packages/cubejs-schema-compiler/src/parser/GenericSql.g4 @@ -15,7 +15,10 @@ selectFields: (field (',' field)*); field: - aliasField | ASTERISK; + selectField | ASTERISK; + +selectField: + exp (AS? identifier)?; aliasField: idPath (AS? identifier)?; @@ -33,10 +36,12 @@ exp: idPath | identifier '(' (exp (',' exp)*) ')' | CAST '(' exp AS identifier ')' | + REGEXP STRING | STRING | numeric | identifier | INDEXED_PARAM | + PARAM_PLACEHOLDER | '(' exp ')' ; @@ -74,8 +79,10 @@ NOT_EQUALS: '<>' | '!='; IS: 'IS'; NULL: 'NULL'; CAST: 'CAST'; +REGEXP: 'REGEXP'; INDEXED_PARAM: '$' [0-9]+ '$'; +PARAM_PLACEHOLDER: '?'; ID: [A-Z_@] [A-Z_@0-9]*; DIGIT: [0-9]; QUOTED_ID: ('"' (~'"')* '"') | ('`' (~'`')* '`'); @@ -83,3 +90,5 @@ STRING: ('\'' (~ '\'' | '\'\'')* '\''); WHITESPACE: [ \t\r\n] -> channel(HIDDEN); +COMMENT: ('--' (~[\r\n])* ('\r'? '\n' | EOF)) -> channel(HIDDEN); +MULTILINE_COMMENT: ('/*' .*? '*/') -> channel(HIDDEN); diff --git a/packages/cubejs-schema-compiler/src/parser/GenericSql.interp b/packages/cubejs-schema-compiler/src/parser/GenericSql.interp index bf28a25029f5a..ae4eb5831e02c 100644 --- a/packages/cubejs-schema-compiler/src/parser/GenericSql.interp +++ b/packages/cubejs-schema-compiler/src/parser/GenericSql.interp @@ -21,6 +21,10 @@ null 'IS' 'NULL' 'CAST' +'REGEXP' +null +'?' +null null null null @@ -51,12 +55,16 @@ NOT_EQUALS IS NULL CAST +REGEXP INDEXED_PARAM +PARAM_PLACEHOLDER ID DIGIT QUOTED_ID STRING WHITESPACE +COMMENT +MULTILINE_COMMENT rule names: statement @@ -64,6 +72,7 @@ query fromTables selectFields field +selectField aliasField boolExp exp @@ -75,4 +84,4 @@ identifier atn: -[4, 1, 27, 165, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 3, 0, 35, 8, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 43, 8, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 3, 5, 3, 50, 8, 3, 10, 3, 12, 3, 53, 9, 3, 1, 4, 1, 4, 3, 4, 57, 8, 4, 1, 5, 1, 5, 3, 5, 61, 8, 5, 1, 5, 3, 5, 64, 8, 5, 1, 6, 1, 6, 1, 6, 1, 6, 3, 6, 70, 8, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 5, 6, 78, 8, 6, 10, 6, 12, 6, 81, 9, 6, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 5, 7, 90, 8, 7, 10, 7, 12, 7, 93, 9, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 3, 7, 112, 8, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 5, 7, 120, 8, 7, 10, 7, 12, 7, 123, 9, 7, 1, 8, 4, 8, 126, 8, 8, 11, 8, 12, 8, 127, 1, 8, 1, 8, 4, 8, 132, 8, 8, 11, 8, 12, 8, 133, 3, 8, 136, 8, 8, 1, 8, 1, 8, 4, 8, 140, 8, 8, 11, 8, 12, 8, 141, 3, 8, 144, 8, 8, 1, 9, 1, 9, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 3, 10, 153, 8, 10, 1, 11, 1, 11, 1, 11, 5, 11, 158, 8, 11, 10, 11, 12, 11, 161, 9, 11, 1, 12, 1, 12, 1, 12, 0, 2, 12, 14, 13, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 0, 2, 1, 0, 13, 18, 2, 0, 23, 23, 25, 25, 177, 0, 34, 1, 0, 0, 0, 2, 36, 1, 0, 0, 0, 4, 44, 1, 0, 0, 0, 6, 46, 1, 0, 0, 0, 8, 56, 1, 0, 0, 0, 10, 58, 1, 0, 0, 0, 12, 69, 1, 0, 0, 0, 14, 111, 1, 0, 0, 0, 16, 143, 1, 0, 0, 0, 18, 145, 1, 0, 0, 0, 20, 152, 1, 0, 0, 0, 22, 154, 1, 0, 0, 0, 24, 162, 1, 0, 0, 0, 26, 27, 3, 2, 1, 0, 27, 28, 5, 0, 0, 1, 28, 35, 1, 0, 0, 0, 29, 30, 5, 1, 0, 0, 30, 31, 3, 2, 1, 0, 31, 32, 5, 2, 0, 0, 32, 33, 5, 0, 0, 1, 33, 35, 1, 0, 0, 0, 34, 26, 1, 0, 0, 0, 34, 29, 1, 0, 0, 0, 35, 1, 1, 0, 0, 0, 36, 37, 5, 5, 0, 0, 37, 38, 3, 6, 3, 0, 38, 39, 5, 7, 0, 0, 39, 42, 3, 4, 2, 0, 40, 41, 5, 8, 0, 0, 41, 43, 3, 12, 6, 0, 42, 40, 1, 0, 0, 0, 42, 43, 1, 0, 0, 0, 43, 3, 1, 0, 0, 0, 44, 45, 3, 10, 5, 0, 45, 5, 1, 0, 0, 0, 46, 51, 3, 8, 4, 0, 47, 48, 5, 3, 0, 0, 48, 50, 3, 8, 4, 0, 49, 47, 1, 0, 0, 0, 50, 53, 1, 0, 0, 0, 51, 49, 1, 0, 0, 0, 51, 52, 1, 0, 0, 0, 52, 7, 1, 0, 0, 0, 53, 51, 1, 0, 0, 0, 54, 57, 3, 10, 5, 0, 55, 57, 5, 6, 0, 0, 56, 54, 1, 0, 0, 0, 56, 55, 1, 0, 0, 0, 57, 9, 1, 0, 0, 0, 58, 63, 3, 22, 11, 0, 59, 61, 5, 12, 0, 0, 60, 59, 1, 0, 0, 0, 60, 61, 1, 0, 0, 0, 61, 62, 1, 0, 0, 0, 62, 64, 3, 24, 12, 0, 63, 60, 1, 0, 0, 0, 63, 64, 1, 0, 0, 0, 64, 11, 1, 0, 0, 0, 65, 66, 6, 6, -1, 0, 66, 70, 3, 14, 7, 0, 67, 68, 5, 11, 0, 0, 68, 70, 3, 12, 6, 1, 69, 65, 1, 0, 0, 0, 69, 67, 1, 0, 0, 0, 70, 79, 1, 0, 0, 0, 71, 72, 10, 3, 0, 0, 72, 73, 5, 9, 0, 0, 73, 78, 3, 12, 6, 4, 74, 75, 10, 2, 0, 0, 75, 76, 5, 10, 0, 0, 76, 78, 3, 12, 6, 3, 77, 71, 1, 0, 0, 0, 77, 74, 1, 0, 0, 0, 78, 81, 1, 0, 0, 0, 79, 77, 1, 0, 0, 0, 79, 80, 1, 0, 0, 0, 80, 13, 1, 0, 0, 0, 81, 79, 1, 0, 0, 0, 82, 83, 6, 7, -1, 0, 83, 112, 3, 22, 11, 0, 84, 85, 3, 24, 12, 0, 85, 86, 5, 1, 0, 0, 86, 91, 3, 14, 7, 0, 87, 88, 5, 3, 0, 0, 88, 90, 3, 14, 7, 0, 89, 87, 1, 0, 0, 0, 90, 93, 1, 0, 0, 0, 91, 89, 1, 0, 0, 0, 91, 92, 1, 0, 0, 0, 92, 94, 1, 0, 0, 0, 93, 91, 1, 0, 0, 0, 94, 95, 5, 2, 0, 0, 95, 112, 1, 0, 0, 0, 96, 97, 5, 21, 0, 0, 97, 98, 5, 1, 0, 0, 98, 99, 3, 14, 7, 0, 99, 100, 5, 12, 0, 0, 100, 101, 3, 24, 12, 0, 101, 102, 5, 2, 0, 0, 102, 112, 1, 0, 0, 0, 103, 112, 5, 26, 0, 0, 104, 112, 3, 16, 8, 0, 105, 112, 3, 24, 12, 0, 106, 112, 5, 22, 0, 0, 107, 108, 5, 1, 0, 0, 108, 109, 3, 14, 7, 0, 109, 110, 5, 2, 0, 0, 110, 112, 1, 0, 0, 0, 111, 82, 1, 0, 0, 0, 111, 84, 1, 0, 0, 0, 111, 96, 1, 0, 0, 0, 111, 103, 1, 0, 0, 0, 111, 104, 1, 0, 0, 0, 111, 105, 1, 0, 0, 0, 111, 106, 1, 0, 0, 0, 111, 107, 1, 0, 0, 0, 112, 121, 1, 0, 0, 0, 113, 114, 10, 10, 0, 0, 114, 115, 3, 18, 9, 0, 115, 116, 3, 14, 7, 11, 116, 120, 1, 0, 0, 0, 117, 118, 10, 9, 0, 0, 118, 120, 3, 20, 10, 0, 119, 113, 1, 0, 0, 0, 119, 117, 1, 0, 0, 0, 120, 123, 1, 0, 0, 0, 121, 119, 1, 0, 0, 0, 121, 122, 1, 0, 0, 0, 122, 15, 1, 0, 0, 0, 123, 121, 1, 0, 0, 0, 124, 126, 5, 24, 0, 0, 125, 124, 1, 0, 0, 0, 126, 127, 1, 0, 0, 0, 127, 125, 1, 0, 0, 0, 127, 128, 1, 0, 0, 0, 128, 135, 1, 0, 0, 0, 129, 131, 5, 4, 0, 0, 130, 132, 5, 24, 0, 0, 131, 130, 1, 0, 0, 0, 132, 133, 1, 0, 0, 0, 133, 131, 1, 0, 0, 0, 133, 134, 1, 0, 0, 0, 134, 136, 1, 0, 0, 0, 135, 129, 1, 0, 0, 0, 135, 136, 1, 0, 0, 0, 136, 144, 1, 0, 0, 0, 137, 139, 5, 4, 0, 0, 138, 140, 5, 24, 0, 0, 139, 138, 1, 0, 0, 0, 140, 141, 1, 0, 0, 0, 141, 139, 1, 0, 0, 0, 141, 142, 1, 0, 0, 0, 142, 144, 1, 0, 0, 0, 143, 125, 1, 0, 0, 0, 143, 137, 1, 0, 0, 0, 144, 17, 1, 0, 0, 0, 145, 146, 7, 0, 0, 0, 146, 19, 1, 0, 0, 0, 147, 148, 5, 19, 0, 0, 148, 153, 5, 20, 0, 0, 149, 150, 5, 19, 0, 0, 150, 151, 5, 11, 0, 0, 151, 153, 5, 20, 0, 0, 152, 147, 1, 0, 0, 0, 152, 149, 1, 0, 0, 0, 153, 21, 1, 0, 0, 0, 154, 159, 3, 24, 12, 0, 155, 156, 5, 4, 0, 0, 156, 158, 3, 24, 12, 0, 157, 155, 1, 0, 0, 0, 158, 161, 1, 0, 0, 0, 159, 157, 1, 0, 0, 0, 159, 160, 1, 0, 0, 0, 160, 23, 1, 0, 0, 0, 161, 159, 1, 0, 0, 0, 162, 163, 7, 1, 0, 0, 163, 25, 1, 0, 0, 0, 20, 34, 42, 51, 56, 60, 63, 69, 77, 79, 91, 111, 119, 121, 127, 133, 135, 141, 143, 152, 159] \ No newline at end of file +[4, 1, 31, 177, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 3, 0, 37, 8, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 45, 8, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 3, 5, 3, 52, 8, 3, 10, 3, 12, 3, 55, 9, 3, 1, 4, 1, 4, 3, 4, 59, 8, 4, 1, 5, 1, 5, 3, 5, 63, 8, 5, 1, 5, 3, 5, 66, 8, 5, 1, 6, 1, 6, 3, 6, 70, 8, 6, 1, 6, 3, 6, 73, 8, 6, 1, 7, 1, 7, 1, 7, 1, 7, 3, 7, 79, 8, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 5, 7, 87, 8, 7, 10, 7, 12, 7, 90, 9, 7, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 5, 8, 99, 8, 8, 10, 8, 12, 8, 102, 9, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 3, 8, 124, 8, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 5, 8, 132, 8, 8, 10, 8, 12, 8, 135, 9, 8, 1, 9, 4, 9, 138, 8, 9, 11, 9, 12, 9, 139, 1, 9, 1, 9, 4, 9, 144, 8, 9, 11, 9, 12, 9, 145, 3, 9, 148, 8, 9, 1, 9, 1, 9, 4, 9, 152, 8, 9, 11, 9, 12, 9, 153, 3, 9, 156, 8, 9, 1, 10, 1, 10, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 3, 11, 165, 8, 11, 1, 12, 1, 12, 1, 12, 5, 12, 170, 8, 12, 10, 12, 12, 12, 173, 9, 12, 1, 13, 1, 13, 1, 13, 0, 2, 14, 16, 14, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 0, 2, 1, 0, 13, 18, 2, 0, 25, 25, 27, 27, 192, 0, 36, 1, 0, 0, 0, 2, 38, 1, 0, 0, 0, 4, 46, 1, 0, 0, 0, 6, 48, 1, 0, 0, 0, 8, 58, 1, 0, 0, 0, 10, 60, 1, 0, 0, 0, 12, 67, 1, 0, 0, 0, 14, 78, 1, 0, 0, 0, 16, 123, 1, 0, 0, 0, 18, 155, 1, 0, 0, 0, 20, 157, 1, 0, 0, 0, 22, 164, 1, 0, 0, 0, 24, 166, 1, 0, 0, 0, 26, 174, 1, 0, 0, 0, 28, 29, 3, 2, 1, 0, 29, 30, 5, 0, 0, 1, 30, 37, 1, 0, 0, 0, 31, 32, 5, 1, 0, 0, 32, 33, 3, 2, 1, 0, 33, 34, 5, 2, 0, 0, 34, 35, 5, 0, 0, 1, 35, 37, 1, 0, 0, 0, 36, 28, 1, 0, 0, 0, 36, 31, 1, 0, 0, 0, 37, 1, 1, 0, 0, 0, 38, 39, 5, 5, 0, 0, 39, 40, 3, 6, 3, 0, 40, 41, 5, 7, 0, 0, 41, 44, 3, 4, 2, 0, 42, 43, 5, 8, 0, 0, 43, 45, 3, 14, 7, 0, 44, 42, 1, 0, 0, 0, 44, 45, 1, 0, 0, 0, 45, 3, 1, 0, 0, 0, 46, 47, 3, 12, 6, 0, 47, 5, 1, 0, 0, 0, 48, 53, 3, 8, 4, 0, 49, 50, 5, 3, 0, 0, 50, 52, 3, 8, 4, 0, 51, 49, 1, 0, 0, 0, 52, 55, 1, 0, 0, 0, 53, 51, 1, 0, 0, 0, 53, 54, 1, 0, 0, 0, 54, 7, 1, 0, 0, 0, 55, 53, 1, 0, 0, 0, 56, 59, 3, 10, 5, 0, 57, 59, 5, 6, 0, 0, 58, 56, 1, 0, 0, 0, 58, 57, 1, 0, 0, 0, 59, 9, 1, 0, 0, 0, 60, 65, 3, 16, 8, 0, 61, 63, 5, 12, 0, 0, 62, 61, 1, 0, 0, 0, 62, 63, 1, 0, 0, 0, 63, 64, 1, 0, 0, 0, 64, 66, 3, 26, 13, 0, 65, 62, 1, 0, 0, 0, 65, 66, 1, 0, 0, 0, 66, 11, 1, 0, 0, 0, 67, 72, 3, 24, 12, 0, 68, 70, 5, 12, 0, 0, 69, 68, 1, 0, 0, 0, 69, 70, 1, 0, 0, 0, 70, 71, 1, 0, 0, 0, 71, 73, 3, 26, 13, 0, 72, 69, 1, 0, 0, 0, 72, 73, 1, 0, 0, 0, 73, 13, 1, 0, 0, 0, 74, 75, 6, 7, -1, 0, 75, 79, 3, 16, 8, 0, 76, 77, 5, 11, 0, 0, 77, 79, 3, 14, 7, 1, 78, 74, 1, 0, 0, 0, 78, 76, 1, 0, 0, 0, 79, 88, 1, 0, 0, 0, 80, 81, 10, 3, 0, 0, 81, 82, 5, 9, 0, 0, 82, 87, 3, 14, 7, 4, 83, 84, 10, 2, 0, 0, 84, 85, 5, 10, 0, 0, 85, 87, 3, 14, 7, 3, 86, 80, 1, 0, 0, 0, 86, 83, 1, 0, 0, 0, 87, 90, 1, 0, 0, 0, 88, 86, 1, 0, 0, 0, 88, 89, 1, 0, 0, 0, 89, 15, 1, 0, 0, 0, 90, 88, 1, 0, 0, 0, 91, 92, 6, 8, -1, 0, 92, 124, 3, 24, 12, 0, 93, 94, 3, 26, 13, 0, 94, 95, 5, 1, 0, 0, 95, 100, 3, 16, 8, 0, 96, 97, 5, 3, 0, 0, 97, 99, 3, 16, 8, 0, 98, 96, 1, 0, 0, 0, 99, 102, 1, 0, 0, 0, 100, 98, 1, 0, 0, 0, 100, 101, 1, 0, 0, 0, 101, 103, 1, 0, 0, 0, 102, 100, 1, 0, 0, 0, 103, 104, 5, 2, 0, 0, 104, 124, 1, 0, 0, 0, 105, 106, 5, 21, 0, 0, 106, 107, 5, 1, 0, 0, 107, 108, 3, 16, 8, 0, 108, 109, 5, 12, 0, 0, 109, 110, 3, 26, 13, 0, 110, 111, 5, 2, 0, 0, 111, 124, 1, 0, 0, 0, 112, 113, 5, 22, 0, 0, 113, 124, 5, 28, 0, 0, 114, 124, 5, 28, 0, 0, 115, 124, 3, 18, 9, 0, 116, 124, 3, 26, 13, 0, 117, 124, 5, 23, 0, 0, 118, 124, 5, 24, 0, 0, 119, 120, 5, 1, 0, 0, 120, 121, 3, 16, 8, 0, 121, 122, 5, 2, 0, 0, 122, 124, 1, 0, 0, 0, 123, 91, 1, 0, 0, 0, 123, 93, 1, 0, 0, 0, 123, 105, 1, 0, 0, 0, 123, 112, 1, 0, 0, 0, 123, 114, 1, 0, 0, 0, 123, 115, 1, 0, 0, 0, 123, 116, 1, 0, 0, 0, 123, 117, 1, 0, 0, 0, 123, 118, 1, 0, 0, 0, 123, 119, 1, 0, 0, 0, 124, 133, 1, 0, 0, 0, 125, 126, 10, 12, 0, 0, 126, 127, 3, 20, 10, 0, 127, 128, 3, 16, 8, 13, 128, 132, 1, 0, 0, 0, 129, 130, 10, 11, 0, 0, 130, 132, 3, 22, 11, 0, 131, 125, 1, 0, 0, 0, 131, 129, 1, 0, 0, 0, 132, 135, 1, 0, 0, 0, 133, 131, 1, 0, 0, 0, 133, 134, 1, 0, 0, 0, 134, 17, 1, 0, 0, 0, 135, 133, 1, 0, 0, 0, 136, 138, 5, 26, 0, 0, 137, 136, 1, 0, 0, 0, 138, 139, 1, 0, 0, 0, 139, 137, 1, 0, 0, 0, 139, 140, 1, 0, 0, 0, 140, 147, 1, 0, 0, 0, 141, 143, 5, 4, 0, 0, 142, 144, 5, 26, 0, 0, 143, 142, 1, 0, 0, 0, 144, 145, 1, 0, 0, 0, 145, 143, 1, 0, 0, 0, 145, 146, 1, 0, 0, 0, 146, 148, 1, 0, 0, 0, 147, 141, 1, 0, 0, 0, 147, 148, 1, 0, 0, 0, 148, 156, 1, 0, 0, 0, 149, 151, 5, 4, 0, 0, 150, 152, 5, 26, 0, 0, 151, 150, 1, 0, 0, 0, 152, 153, 1, 0, 0, 0, 153, 151, 1, 0, 0, 0, 153, 154, 1, 0, 0, 0, 154, 156, 1, 0, 0, 0, 155, 137, 1, 0, 0, 0, 155, 149, 1, 0, 0, 0, 156, 19, 1, 0, 0, 0, 157, 158, 7, 0, 0, 0, 158, 21, 1, 0, 0, 0, 159, 160, 5, 19, 0, 0, 160, 165, 5, 20, 0, 0, 161, 162, 5, 19, 0, 0, 162, 163, 5, 11, 0, 0, 163, 165, 5, 20, 0, 0, 164, 159, 1, 0, 0, 0, 164, 161, 1, 0, 0, 0, 165, 23, 1, 0, 0, 0, 166, 171, 3, 26, 13, 0, 167, 168, 5, 4, 0, 0, 168, 170, 3, 26, 13, 0, 169, 167, 1, 0, 0, 0, 170, 173, 1, 0, 0, 0, 171, 169, 1, 0, 0, 0, 171, 172, 1, 0, 0, 0, 172, 25, 1, 0, 0, 0, 173, 171, 1, 0, 0, 0, 174, 175, 7, 1, 0, 0, 175, 27, 1, 0, 0, 0, 22, 36, 44, 53, 58, 62, 65, 69, 72, 78, 86, 88, 100, 123, 131, 133, 139, 145, 147, 153, 155, 164, 171] \ No newline at end of file diff --git a/packages/cubejs-schema-compiler/src/parser/GenericSql.tokens b/packages/cubejs-schema-compiler/src/parser/GenericSql.tokens index e9c75014b7298..38aeabb864e8e 100644 --- a/packages/cubejs-schema-compiler/src/parser/GenericSql.tokens +++ b/packages/cubejs-schema-compiler/src/parser/GenericSql.tokens @@ -19,12 +19,16 @@ NOT_EQUALS=18 IS=19 NULL=20 CAST=21 -INDEXED_PARAM=22 -ID=23 -DIGIT=24 -QUOTED_ID=25 -STRING=26 -WHITESPACE=27 +REGEXP=22 +INDEXED_PARAM=23 +PARAM_PLACEHOLDER=24 +ID=25 +DIGIT=26 +QUOTED_ID=27 +STRING=28 +WHITESPACE=29 +COMMENT=30 +MULTILINE_COMMENT=31 '('=1 ')'=2 ','=3 @@ -45,3 +49,5 @@ WHITESPACE=27 'IS'=19 'NULL'=20 'CAST'=21 +'REGEXP'=22 +'?'=24 diff --git a/packages/cubejs-schema-compiler/src/parser/GenericSqlLexer.interp b/packages/cubejs-schema-compiler/src/parser/GenericSqlLexer.interp index fdb86ecaa0ad6..f7783b4370f81 100644 --- a/packages/cubejs-schema-compiler/src/parser/GenericSqlLexer.interp +++ b/packages/cubejs-schema-compiler/src/parser/GenericSqlLexer.interp @@ -21,6 +21,10 @@ null 'IS' 'NULL' 'CAST' +'REGEXP' +null +'?' +null null null null @@ -51,12 +55,16 @@ NOT_EQUALS IS NULL CAST +REGEXP INDEXED_PARAM +PARAM_PLACEHOLDER ID DIGIT QUOTED_ID STRING WHITESPACE +COMMENT +MULTILINE_COMMENT rule names: T__0 @@ -80,12 +88,16 @@ NOT_EQUALS IS NULL CAST +REGEXP INDEXED_PARAM +PARAM_PLACEHOLDER ID DIGIT QUOTED_ID STRING WHITESPACE +COMMENT +MULTILINE_COMMENT channel names: DEFAULT_TOKEN_CHANNEL @@ -95,4 +107,4 @@ mode names: DEFAULT_MODE atn: -[4, 0, 27, 178, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 2, 19, 7, 19, 2, 20, 7, 20, 2, 21, 7, 21, 2, 22, 7, 22, 2, 23, 7, 23, 2, 24, 7, 24, 2, 25, 7, 25, 2, 26, 7, 26, 1, 0, 1, 0, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 5, 1, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 1, 8, 1, 9, 1, 9, 1, 9, 1, 10, 1, 10, 1, 10, 1, 10, 1, 11, 1, 11, 1, 11, 1, 12, 1, 12, 1, 13, 1, 13, 1, 13, 1, 14, 1, 14, 1, 15, 1, 15, 1, 15, 1, 16, 1, 16, 1, 17, 1, 17, 1, 17, 1, 17, 3, 17, 114, 8, 17, 1, 18, 1, 18, 1, 18, 1, 19, 1, 19, 1, 19, 1, 19, 1, 19, 1, 20, 1, 20, 1, 20, 1, 20, 1, 20, 1, 21, 1, 21, 4, 21, 131, 8, 21, 11, 21, 12, 21, 132, 1, 21, 1, 21, 1, 22, 1, 22, 5, 22, 139, 8, 22, 10, 22, 12, 22, 142, 9, 22, 1, 23, 1, 23, 1, 24, 1, 24, 5, 24, 148, 8, 24, 10, 24, 12, 24, 151, 9, 24, 1, 24, 1, 24, 1, 24, 5, 24, 156, 8, 24, 10, 24, 12, 24, 159, 9, 24, 1, 24, 3, 24, 162, 8, 24, 1, 25, 1, 25, 1, 25, 1, 25, 5, 25, 168, 8, 25, 10, 25, 12, 25, 171, 9, 25, 1, 25, 1, 25, 1, 26, 1, 26, 1, 26, 1, 26, 0, 0, 27, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, 17, 9, 19, 10, 21, 11, 23, 12, 25, 13, 27, 14, 29, 15, 31, 16, 33, 17, 35, 18, 37, 19, 39, 20, 41, 21, 43, 22, 45, 23, 47, 24, 49, 25, 51, 26, 53, 27, 1, 0, 7, 1, 0, 48, 57, 2, 0, 64, 90, 95, 95, 3, 0, 48, 57, 64, 90, 95, 95, 1, 0, 34, 34, 1, 0, 96, 96, 1, 0, 39, 39, 3, 0, 9, 10, 13, 13, 32, 32, 185, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 0, 23, 1, 0, 0, 0, 0, 25, 1, 0, 0, 0, 0, 27, 1, 0, 0, 0, 0, 29, 1, 0, 0, 0, 0, 31, 1, 0, 0, 0, 0, 33, 1, 0, 0, 0, 0, 35, 1, 0, 0, 0, 0, 37, 1, 0, 0, 0, 0, 39, 1, 0, 0, 0, 0, 41, 1, 0, 0, 0, 0, 43, 1, 0, 0, 0, 0, 45, 1, 0, 0, 0, 0, 47, 1, 0, 0, 0, 0, 49, 1, 0, 0, 0, 0, 51, 1, 0, 0, 0, 0, 53, 1, 0, 0, 0, 1, 55, 1, 0, 0, 0, 3, 57, 1, 0, 0, 0, 5, 59, 1, 0, 0, 0, 7, 61, 1, 0, 0, 0, 9, 63, 1, 0, 0, 0, 11, 70, 1, 0, 0, 0, 13, 72, 1, 0, 0, 0, 15, 77, 1, 0, 0, 0, 17, 83, 1, 0, 0, 0, 19, 87, 1, 0, 0, 0, 21, 90, 1, 0, 0, 0, 23, 94, 1, 0, 0, 0, 25, 97, 1, 0, 0, 0, 27, 99, 1, 0, 0, 0, 29, 102, 1, 0, 0, 0, 31, 104, 1, 0, 0, 0, 33, 107, 1, 0, 0, 0, 35, 113, 1, 0, 0, 0, 37, 115, 1, 0, 0, 0, 39, 118, 1, 0, 0, 0, 41, 123, 1, 0, 0, 0, 43, 128, 1, 0, 0, 0, 45, 136, 1, 0, 0, 0, 47, 143, 1, 0, 0, 0, 49, 161, 1, 0, 0, 0, 51, 163, 1, 0, 0, 0, 53, 174, 1, 0, 0, 0, 55, 56, 5, 40, 0, 0, 56, 2, 1, 0, 0, 0, 57, 58, 5, 41, 0, 0, 58, 4, 1, 0, 0, 0, 59, 60, 5, 44, 0, 0, 60, 6, 1, 0, 0, 0, 61, 62, 5, 46, 0, 0, 62, 8, 1, 0, 0, 0, 63, 64, 5, 83, 0, 0, 64, 65, 5, 69, 0, 0, 65, 66, 5, 76, 0, 0, 66, 67, 5, 69, 0, 0, 67, 68, 5, 67, 0, 0, 68, 69, 5, 84, 0, 0, 69, 10, 1, 0, 0, 0, 70, 71, 5, 42, 0, 0, 71, 12, 1, 0, 0, 0, 72, 73, 5, 70, 0, 0, 73, 74, 5, 82, 0, 0, 74, 75, 5, 79, 0, 0, 75, 76, 5, 77, 0, 0, 76, 14, 1, 0, 0, 0, 77, 78, 5, 87, 0, 0, 78, 79, 5, 72, 0, 0, 79, 80, 5, 69, 0, 0, 80, 81, 5, 82, 0, 0, 81, 82, 5, 69, 0, 0, 82, 16, 1, 0, 0, 0, 83, 84, 5, 65, 0, 0, 84, 85, 5, 78, 0, 0, 85, 86, 5, 68, 0, 0, 86, 18, 1, 0, 0, 0, 87, 88, 5, 79, 0, 0, 88, 89, 5, 82, 0, 0, 89, 20, 1, 0, 0, 0, 90, 91, 5, 78, 0, 0, 91, 92, 5, 79, 0, 0, 92, 93, 5, 84, 0, 0, 93, 22, 1, 0, 0, 0, 94, 95, 5, 65, 0, 0, 95, 96, 5, 83, 0, 0, 96, 24, 1, 0, 0, 0, 97, 98, 5, 60, 0, 0, 98, 26, 1, 0, 0, 0, 99, 100, 5, 60, 0, 0, 100, 101, 5, 61, 0, 0, 101, 28, 1, 0, 0, 0, 102, 103, 5, 62, 0, 0, 103, 30, 1, 0, 0, 0, 104, 105, 5, 62, 0, 0, 105, 106, 5, 61, 0, 0, 106, 32, 1, 0, 0, 0, 107, 108, 5, 61, 0, 0, 108, 34, 1, 0, 0, 0, 109, 110, 5, 60, 0, 0, 110, 114, 5, 62, 0, 0, 111, 112, 5, 33, 0, 0, 112, 114, 5, 61, 0, 0, 113, 109, 1, 0, 0, 0, 113, 111, 1, 0, 0, 0, 114, 36, 1, 0, 0, 0, 115, 116, 5, 73, 0, 0, 116, 117, 5, 83, 0, 0, 117, 38, 1, 0, 0, 0, 118, 119, 5, 78, 0, 0, 119, 120, 5, 85, 0, 0, 120, 121, 5, 76, 0, 0, 121, 122, 5, 76, 0, 0, 122, 40, 1, 0, 0, 0, 123, 124, 5, 67, 0, 0, 124, 125, 5, 65, 0, 0, 125, 126, 5, 83, 0, 0, 126, 127, 5, 84, 0, 0, 127, 42, 1, 0, 0, 0, 128, 130, 5, 36, 0, 0, 129, 131, 7, 0, 0, 0, 130, 129, 1, 0, 0, 0, 131, 132, 1, 0, 0, 0, 132, 130, 1, 0, 0, 0, 132, 133, 1, 0, 0, 0, 133, 134, 1, 0, 0, 0, 134, 135, 5, 36, 0, 0, 135, 44, 1, 0, 0, 0, 136, 140, 7, 1, 0, 0, 137, 139, 7, 2, 0, 0, 138, 137, 1, 0, 0, 0, 139, 142, 1, 0, 0, 0, 140, 138, 1, 0, 0, 0, 140, 141, 1, 0, 0, 0, 141, 46, 1, 0, 0, 0, 142, 140, 1, 0, 0, 0, 143, 144, 7, 0, 0, 0, 144, 48, 1, 0, 0, 0, 145, 149, 5, 34, 0, 0, 146, 148, 8, 3, 0, 0, 147, 146, 1, 0, 0, 0, 148, 151, 1, 0, 0, 0, 149, 147, 1, 0, 0, 0, 149, 150, 1, 0, 0, 0, 150, 152, 1, 0, 0, 0, 151, 149, 1, 0, 0, 0, 152, 162, 5, 34, 0, 0, 153, 157, 5, 96, 0, 0, 154, 156, 8, 4, 0, 0, 155, 154, 1, 0, 0, 0, 156, 159, 1, 0, 0, 0, 157, 155, 1, 0, 0, 0, 157, 158, 1, 0, 0, 0, 158, 160, 1, 0, 0, 0, 159, 157, 1, 0, 0, 0, 160, 162, 5, 96, 0, 0, 161, 145, 1, 0, 0, 0, 161, 153, 1, 0, 0, 0, 162, 50, 1, 0, 0, 0, 163, 169, 5, 39, 0, 0, 164, 168, 8, 5, 0, 0, 165, 166, 5, 39, 0, 0, 166, 168, 5, 39, 0, 0, 167, 164, 1, 0, 0, 0, 167, 165, 1, 0, 0, 0, 168, 171, 1, 0, 0, 0, 169, 167, 1, 0, 0, 0, 169, 170, 1, 0, 0, 0, 170, 172, 1, 0, 0, 0, 171, 169, 1, 0, 0, 0, 172, 173, 5, 39, 0, 0, 173, 52, 1, 0, 0, 0, 174, 175, 7, 6, 0, 0, 175, 176, 1, 0, 0, 0, 176, 177, 6, 26, 0, 0, 177, 54, 1, 0, 0, 0, 9, 0, 113, 132, 140, 149, 157, 161, 167, 169, 1, 0, 1, 0] \ No newline at end of file +[4, 0, 31, 227, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 2, 19, 7, 19, 2, 20, 7, 20, 2, 21, 7, 21, 2, 22, 7, 22, 2, 23, 7, 23, 2, 24, 7, 24, 2, 25, 7, 25, 2, 26, 7, 26, 2, 27, 7, 27, 2, 28, 7, 28, 2, 29, 7, 29, 2, 30, 7, 30, 1, 0, 1, 0, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 5, 1, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 1, 8, 1, 9, 1, 9, 1, 9, 1, 10, 1, 10, 1, 10, 1, 10, 1, 11, 1, 11, 1, 11, 1, 12, 1, 12, 1, 13, 1, 13, 1, 13, 1, 14, 1, 14, 1, 15, 1, 15, 1, 15, 1, 16, 1, 16, 1, 17, 1, 17, 1, 17, 1, 17, 3, 17, 122, 8, 17, 1, 18, 1, 18, 1, 18, 1, 19, 1, 19, 1, 19, 1, 19, 1, 19, 1, 20, 1, 20, 1, 20, 1, 20, 1, 20, 1, 21, 1, 21, 1, 21, 1, 21, 1, 21, 1, 21, 1, 21, 1, 22, 1, 22, 4, 22, 146, 8, 22, 11, 22, 12, 22, 147, 1, 22, 1, 22, 1, 23, 1, 23, 1, 24, 1, 24, 5, 24, 156, 8, 24, 10, 24, 12, 24, 159, 9, 24, 1, 25, 1, 25, 1, 26, 1, 26, 5, 26, 165, 8, 26, 10, 26, 12, 26, 168, 9, 26, 1, 26, 1, 26, 1, 26, 5, 26, 173, 8, 26, 10, 26, 12, 26, 176, 9, 26, 1, 26, 3, 26, 179, 8, 26, 1, 27, 1, 27, 1, 27, 1, 27, 5, 27, 185, 8, 27, 10, 27, 12, 27, 188, 9, 27, 1, 27, 1, 27, 1, 28, 1, 28, 1, 28, 1, 28, 1, 29, 1, 29, 1, 29, 1, 29, 5, 29, 200, 8, 29, 10, 29, 12, 29, 203, 9, 29, 1, 29, 3, 29, 206, 8, 29, 1, 29, 1, 29, 3, 29, 210, 8, 29, 1, 29, 1, 29, 1, 30, 1, 30, 1, 30, 1, 30, 5, 30, 218, 8, 30, 10, 30, 12, 30, 221, 9, 30, 1, 30, 1, 30, 1, 30, 1, 30, 1, 30, 1, 219, 0, 31, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, 17, 9, 19, 10, 21, 11, 23, 12, 25, 13, 27, 14, 29, 15, 31, 16, 33, 17, 35, 18, 37, 19, 39, 20, 41, 21, 43, 22, 45, 23, 47, 24, 49, 25, 51, 26, 53, 27, 55, 28, 57, 29, 59, 30, 61, 31, 1, 0, 8, 1, 0, 48, 57, 2, 0, 64, 90, 95, 95, 3, 0, 48, 57, 64, 90, 95, 95, 1, 0, 34, 34, 1, 0, 96, 96, 1, 0, 39, 39, 3, 0, 9, 10, 13, 13, 32, 32, 2, 0, 10, 10, 13, 13, 238, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 0, 23, 1, 0, 0, 0, 0, 25, 1, 0, 0, 0, 0, 27, 1, 0, 0, 0, 0, 29, 1, 0, 0, 0, 0, 31, 1, 0, 0, 0, 0, 33, 1, 0, 0, 0, 0, 35, 1, 0, 0, 0, 0, 37, 1, 0, 0, 0, 0, 39, 1, 0, 0, 0, 0, 41, 1, 0, 0, 0, 0, 43, 1, 0, 0, 0, 0, 45, 1, 0, 0, 0, 0, 47, 1, 0, 0, 0, 0, 49, 1, 0, 0, 0, 0, 51, 1, 0, 0, 0, 0, 53, 1, 0, 0, 0, 0, 55, 1, 0, 0, 0, 0, 57, 1, 0, 0, 0, 0, 59, 1, 0, 0, 0, 0, 61, 1, 0, 0, 0, 1, 63, 1, 0, 0, 0, 3, 65, 1, 0, 0, 0, 5, 67, 1, 0, 0, 0, 7, 69, 1, 0, 0, 0, 9, 71, 1, 0, 0, 0, 11, 78, 1, 0, 0, 0, 13, 80, 1, 0, 0, 0, 15, 85, 1, 0, 0, 0, 17, 91, 1, 0, 0, 0, 19, 95, 1, 0, 0, 0, 21, 98, 1, 0, 0, 0, 23, 102, 1, 0, 0, 0, 25, 105, 1, 0, 0, 0, 27, 107, 1, 0, 0, 0, 29, 110, 1, 0, 0, 0, 31, 112, 1, 0, 0, 0, 33, 115, 1, 0, 0, 0, 35, 121, 1, 0, 0, 0, 37, 123, 1, 0, 0, 0, 39, 126, 1, 0, 0, 0, 41, 131, 1, 0, 0, 0, 43, 136, 1, 0, 0, 0, 45, 143, 1, 0, 0, 0, 47, 151, 1, 0, 0, 0, 49, 153, 1, 0, 0, 0, 51, 160, 1, 0, 0, 0, 53, 178, 1, 0, 0, 0, 55, 180, 1, 0, 0, 0, 57, 191, 1, 0, 0, 0, 59, 195, 1, 0, 0, 0, 61, 213, 1, 0, 0, 0, 63, 64, 5, 40, 0, 0, 64, 2, 1, 0, 0, 0, 65, 66, 5, 41, 0, 0, 66, 4, 1, 0, 0, 0, 67, 68, 5, 44, 0, 0, 68, 6, 1, 0, 0, 0, 69, 70, 5, 46, 0, 0, 70, 8, 1, 0, 0, 0, 71, 72, 5, 83, 0, 0, 72, 73, 5, 69, 0, 0, 73, 74, 5, 76, 0, 0, 74, 75, 5, 69, 0, 0, 75, 76, 5, 67, 0, 0, 76, 77, 5, 84, 0, 0, 77, 10, 1, 0, 0, 0, 78, 79, 5, 42, 0, 0, 79, 12, 1, 0, 0, 0, 80, 81, 5, 70, 0, 0, 81, 82, 5, 82, 0, 0, 82, 83, 5, 79, 0, 0, 83, 84, 5, 77, 0, 0, 84, 14, 1, 0, 0, 0, 85, 86, 5, 87, 0, 0, 86, 87, 5, 72, 0, 0, 87, 88, 5, 69, 0, 0, 88, 89, 5, 82, 0, 0, 89, 90, 5, 69, 0, 0, 90, 16, 1, 0, 0, 0, 91, 92, 5, 65, 0, 0, 92, 93, 5, 78, 0, 0, 93, 94, 5, 68, 0, 0, 94, 18, 1, 0, 0, 0, 95, 96, 5, 79, 0, 0, 96, 97, 5, 82, 0, 0, 97, 20, 1, 0, 0, 0, 98, 99, 5, 78, 0, 0, 99, 100, 5, 79, 0, 0, 100, 101, 5, 84, 0, 0, 101, 22, 1, 0, 0, 0, 102, 103, 5, 65, 0, 0, 103, 104, 5, 83, 0, 0, 104, 24, 1, 0, 0, 0, 105, 106, 5, 60, 0, 0, 106, 26, 1, 0, 0, 0, 107, 108, 5, 60, 0, 0, 108, 109, 5, 61, 0, 0, 109, 28, 1, 0, 0, 0, 110, 111, 5, 62, 0, 0, 111, 30, 1, 0, 0, 0, 112, 113, 5, 62, 0, 0, 113, 114, 5, 61, 0, 0, 114, 32, 1, 0, 0, 0, 115, 116, 5, 61, 0, 0, 116, 34, 1, 0, 0, 0, 117, 118, 5, 60, 0, 0, 118, 122, 5, 62, 0, 0, 119, 120, 5, 33, 0, 0, 120, 122, 5, 61, 0, 0, 121, 117, 1, 0, 0, 0, 121, 119, 1, 0, 0, 0, 122, 36, 1, 0, 0, 0, 123, 124, 5, 73, 0, 0, 124, 125, 5, 83, 0, 0, 125, 38, 1, 0, 0, 0, 126, 127, 5, 78, 0, 0, 127, 128, 5, 85, 0, 0, 128, 129, 5, 76, 0, 0, 129, 130, 5, 76, 0, 0, 130, 40, 1, 0, 0, 0, 131, 132, 5, 67, 0, 0, 132, 133, 5, 65, 0, 0, 133, 134, 5, 83, 0, 0, 134, 135, 5, 84, 0, 0, 135, 42, 1, 0, 0, 0, 136, 137, 5, 82, 0, 0, 137, 138, 5, 69, 0, 0, 138, 139, 5, 71, 0, 0, 139, 140, 5, 69, 0, 0, 140, 141, 5, 88, 0, 0, 141, 142, 5, 80, 0, 0, 142, 44, 1, 0, 0, 0, 143, 145, 5, 36, 0, 0, 144, 146, 7, 0, 0, 0, 145, 144, 1, 0, 0, 0, 146, 147, 1, 0, 0, 0, 147, 145, 1, 0, 0, 0, 147, 148, 1, 0, 0, 0, 148, 149, 1, 0, 0, 0, 149, 150, 5, 36, 0, 0, 150, 46, 1, 0, 0, 0, 151, 152, 5, 63, 0, 0, 152, 48, 1, 0, 0, 0, 153, 157, 7, 1, 0, 0, 154, 156, 7, 2, 0, 0, 155, 154, 1, 0, 0, 0, 156, 159, 1, 0, 0, 0, 157, 155, 1, 0, 0, 0, 157, 158, 1, 0, 0, 0, 158, 50, 1, 0, 0, 0, 159, 157, 1, 0, 0, 0, 160, 161, 7, 0, 0, 0, 161, 52, 1, 0, 0, 0, 162, 166, 5, 34, 0, 0, 163, 165, 8, 3, 0, 0, 164, 163, 1, 0, 0, 0, 165, 168, 1, 0, 0, 0, 166, 164, 1, 0, 0, 0, 166, 167, 1, 0, 0, 0, 167, 169, 1, 0, 0, 0, 168, 166, 1, 0, 0, 0, 169, 179, 5, 34, 0, 0, 170, 174, 5, 96, 0, 0, 171, 173, 8, 4, 0, 0, 172, 171, 1, 0, 0, 0, 173, 176, 1, 0, 0, 0, 174, 172, 1, 0, 0, 0, 174, 175, 1, 0, 0, 0, 175, 177, 1, 0, 0, 0, 176, 174, 1, 0, 0, 0, 177, 179, 5, 96, 0, 0, 178, 162, 1, 0, 0, 0, 178, 170, 1, 0, 0, 0, 179, 54, 1, 0, 0, 0, 180, 186, 5, 39, 0, 0, 181, 185, 8, 5, 0, 0, 182, 183, 5, 39, 0, 0, 183, 185, 5, 39, 0, 0, 184, 181, 1, 0, 0, 0, 184, 182, 1, 0, 0, 0, 185, 188, 1, 0, 0, 0, 186, 184, 1, 0, 0, 0, 186, 187, 1, 0, 0, 0, 187, 189, 1, 0, 0, 0, 188, 186, 1, 0, 0, 0, 189, 190, 5, 39, 0, 0, 190, 56, 1, 0, 0, 0, 191, 192, 7, 6, 0, 0, 192, 193, 1, 0, 0, 0, 193, 194, 6, 28, 0, 0, 194, 58, 1, 0, 0, 0, 195, 196, 5, 45, 0, 0, 196, 197, 5, 45, 0, 0, 197, 201, 1, 0, 0, 0, 198, 200, 8, 7, 0, 0, 199, 198, 1, 0, 0, 0, 200, 203, 1, 0, 0, 0, 201, 199, 1, 0, 0, 0, 201, 202, 1, 0, 0, 0, 202, 209, 1, 0, 0, 0, 203, 201, 1, 0, 0, 0, 204, 206, 5, 13, 0, 0, 205, 204, 1, 0, 0, 0, 205, 206, 1, 0, 0, 0, 206, 207, 1, 0, 0, 0, 207, 210, 5, 10, 0, 0, 208, 210, 5, 0, 0, 1, 209, 205, 1, 0, 0, 0, 209, 208, 1, 0, 0, 0, 210, 211, 1, 0, 0, 0, 211, 212, 6, 29, 0, 0, 212, 60, 1, 0, 0, 0, 213, 214, 5, 47, 0, 0, 214, 215, 5, 42, 0, 0, 215, 219, 1, 0, 0, 0, 216, 218, 9, 0, 0, 0, 217, 216, 1, 0, 0, 0, 218, 221, 1, 0, 0, 0, 219, 220, 1, 0, 0, 0, 219, 217, 1, 0, 0, 0, 220, 222, 1, 0, 0, 0, 221, 219, 1, 0, 0, 0, 222, 223, 5, 42, 0, 0, 223, 224, 5, 47, 0, 0, 224, 225, 1, 0, 0, 0, 225, 226, 6, 30, 0, 0, 226, 62, 1, 0, 0, 0, 13, 0, 121, 147, 157, 166, 174, 178, 184, 186, 201, 205, 209, 219, 1, 0, 1, 0] \ No newline at end of file diff --git a/packages/cubejs-schema-compiler/src/parser/GenericSqlLexer.tokens b/packages/cubejs-schema-compiler/src/parser/GenericSqlLexer.tokens index e9c75014b7298..38aeabb864e8e 100644 --- a/packages/cubejs-schema-compiler/src/parser/GenericSqlLexer.tokens +++ b/packages/cubejs-schema-compiler/src/parser/GenericSqlLexer.tokens @@ -19,12 +19,16 @@ NOT_EQUALS=18 IS=19 NULL=20 CAST=21 -INDEXED_PARAM=22 -ID=23 -DIGIT=24 -QUOTED_ID=25 -STRING=26 -WHITESPACE=27 +REGEXP=22 +INDEXED_PARAM=23 +PARAM_PLACEHOLDER=24 +ID=25 +DIGIT=26 +QUOTED_ID=27 +STRING=28 +WHITESPACE=29 +COMMENT=30 +MULTILINE_COMMENT=31 '('=1 ')'=2 ','=3 @@ -45,3 +49,5 @@ WHITESPACE=27 'IS'=19 'NULL'=20 'CAST'=21 +'REGEXP'=22 +'?'=24 diff --git a/packages/cubejs-schema-compiler/src/parser/GenericSqlLexer.ts b/packages/cubejs-schema-compiler/src/parser/GenericSqlLexer.ts index bf366c11a838f..4140e65b0b161 100644 --- a/packages/cubejs-schema-compiler/src/parser/GenericSqlLexer.ts +++ b/packages/cubejs-schema-compiler/src/parser/GenericSqlLexer.ts @@ -1,6 +1,5 @@ // Generated from src/parser/GenericSql.g4 by ANTLR 4.13.2 // noinspection ES6UnusedImports,JSUnusedGlobalSymbols,JSUnusedLocalSymbols -// @ts-nocheck import { ATN, ATNDeserializer, @@ -34,12 +33,16 @@ export default class GenericSqlLexer extends Lexer { public static readonly IS = 19; public static readonly NULL = 20; public static readonly CAST = 21; - public static readonly INDEXED_PARAM = 22; - public static readonly ID = 23; - public static readonly DIGIT = 24; - public static readonly QUOTED_ID = 25; - public static readonly STRING = 26; - public static readonly WHITESPACE = 27; + public static readonly REGEXP = 22; + public static readonly INDEXED_PARAM = 23; + public static readonly PARAM_PLACEHOLDER = 24; + public static readonly ID = 25; + public static readonly DIGIT = 26; + public static readonly QUOTED_ID = 27; + public static readonly STRING = 28; + public static readonly WHITESPACE = 29; + public static readonly COMMENT = 30; + public static readonly MULTILINE_COMMENT = 31; public static readonly EOF = Token.EOF; public static readonly channelNames: string[] = [ "DEFAULT_TOKEN_CHANNEL", "HIDDEN" ]; @@ -53,7 +56,9 @@ export default class GenericSqlLexer extends Lexer { "'<='", "'>'", "'>='", "'='", null, "'IS'", - "'NULL'", "'CAST'" ]; + "'NULL'", "'CAST'", + "'REGEXP'", + null, "'?'" ]; public static readonly symbolicNames: (string | null)[] = [ null, null, null, null, null, "SELECT", @@ -65,17 +70,21 @@ export default class GenericSqlLexer extends Lexer { "GT", "GTE", "EQUALS", "NOT_EQUALS", "IS", "NULL", - "CAST", "INDEXED_PARAM", + "CAST", "REGEXP", + "INDEXED_PARAM", + "PARAM_PLACEHOLDER", "ID", "DIGIT", "QUOTED_ID", - "STRING", "WHITESPACE" ]; + "STRING", "WHITESPACE", + "COMMENT", + "MULTILINE_COMMENT" ]; public static readonly modeNames: string[] = [ "DEFAULT_MODE", ]; public static readonly ruleNames: string[] = [ "T__0", "T__1", "T__2", "T__3", "SELECT", "ASTERISK", "FROM", "WHERE", "AND", "OR", "NOT", "AS", "LT", "LTE", "GT", "GTE", "EQUALS", "NOT_EQUALS", - "IS", "NULL", "CAST", "INDEXED_PARAM", "ID", "DIGIT", "QUOTED_ID", "STRING", - "WHITESPACE", + "IS", "NULL", "CAST", "REGEXP", "INDEXED_PARAM", "PARAM_PLACEHOLDER", + "ID", "DIGIT", "QUOTED_ID", "STRING", "WHITESPACE", "COMMENT", "MULTILINE_COMMENT", ]; @@ -96,63 +105,80 @@ export default class GenericSqlLexer extends Lexer { public get modeNames(): string[] { return GenericSqlLexer.modeNames; } - public static readonly _serializedATN: number[] = [4,0,27,178,6,-1,2,0, + public static readonly _serializedATN: number[] = [4,0,31,227,6,-1,2,0, 7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7,6,2,7,7,7,2,8,7,8,2,9, 7,9,2,10,7,10,2,11,7,11,2,12,7,12,2,13,7,13,2,14,7,14,2,15,7,15,2,16,7, 16,2,17,7,17,2,18,7,18,2,19,7,19,2,20,7,20,2,21,7,21,2,22,7,22,2,23,7,23, - 2,24,7,24,2,25,7,25,2,26,7,26,1,0,1,0,1,1,1,1,1,2,1,2,1,3,1,3,1,4,1,4,1, - 4,1,4,1,4,1,4,1,4,1,5,1,5,1,6,1,6,1,6,1,6,1,6,1,7,1,7,1,7,1,7,1,7,1,7,1, - 8,1,8,1,8,1,8,1,9,1,9,1,9,1,10,1,10,1,10,1,10,1,11,1,11,1,11,1,12,1,12, - 1,13,1,13,1,13,1,14,1,14,1,15,1,15,1,15,1,16,1,16,1,17,1,17,1,17,1,17,3, - 17,114,8,17,1,18,1,18,1,18,1,19,1,19,1,19,1,19,1,19,1,20,1,20,1,20,1,20, - 1,20,1,21,1,21,4,21,131,8,21,11,21,12,21,132,1,21,1,21,1,22,1,22,5,22,139, - 8,22,10,22,12,22,142,9,22,1,23,1,23,1,24,1,24,5,24,148,8,24,10,24,12,24, - 151,9,24,1,24,1,24,1,24,5,24,156,8,24,10,24,12,24,159,9,24,1,24,3,24,162, - 8,24,1,25,1,25,1,25,1,25,5,25,168,8,25,10,25,12,25,171,9,25,1,25,1,25,1, - 26,1,26,1,26,1,26,0,0,27,1,1,3,2,5,3,7,4,9,5,11,6,13,7,15,8,17,9,19,10, - 21,11,23,12,25,13,27,14,29,15,31,16,33,17,35,18,37,19,39,20,41,21,43,22, - 45,23,47,24,49,25,51,26,53,27,1,0,7,1,0,48,57,2,0,64,90,95,95,3,0,48,57, - 64,90,95,95,1,0,34,34,1,0,96,96,1,0,39,39,3,0,9,10,13,13,32,32,185,0,1, - 1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,7,1,0,0,0,0,9,1,0,0,0,0,11,1,0,0,0,0, - 13,1,0,0,0,0,15,1,0,0,0,0,17,1,0,0,0,0,19,1,0,0,0,0,21,1,0,0,0,0,23,1,0, - 0,0,0,25,1,0,0,0,0,27,1,0,0,0,0,29,1,0,0,0,0,31,1,0,0,0,0,33,1,0,0,0,0, - 35,1,0,0,0,0,37,1,0,0,0,0,39,1,0,0,0,0,41,1,0,0,0,0,43,1,0,0,0,0,45,1,0, - 0,0,0,47,1,0,0,0,0,49,1,0,0,0,0,51,1,0,0,0,0,53,1,0,0,0,1,55,1,0,0,0,3, - 57,1,0,0,0,5,59,1,0,0,0,7,61,1,0,0,0,9,63,1,0,0,0,11,70,1,0,0,0,13,72,1, - 0,0,0,15,77,1,0,0,0,17,83,1,0,0,0,19,87,1,0,0,0,21,90,1,0,0,0,23,94,1,0, - 0,0,25,97,1,0,0,0,27,99,1,0,0,0,29,102,1,0,0,0,31,104,1,0,0,0,33,107,1, - 0,0,0,35,113,1,0,0,0,37,115,1,0,0,0,39,118,1,0,0,0,41,123,1,0,0,0,43,128, - 1,0,0,0,45,136,1,0,0,0,47,143,1,0,0,0,49,161,1,0,0,0,51,163,1,0,0,0,53, - 174,1,0,0,0,55,56,5,40,0,0,56,2,1,0,0,0,57,58,5,41,0,0,58,4,1,0,0,0,59, - 60,5,44,0,0,60,6,1,0,0,0,61,62,5,46,0,0,62,8,1,0,0,0,63,64,5,83,0,0,64, - 65,5,69,0,0,65,66,5,76,0,0,66,67,5,69,0,0,67,68,5,67,0,0,68,69,5,84,0,0, - 69,10,1,0,0,0,70,71,5,42,0,0,71,12,1,0,0,0,72,73,5,70,0,0,73,74,5,82,0, - 0,74,75,5,79,0,0,75,76,5,77,0,0,76,14,1,0,0,0,77,78,5,87,0,0,78,79,5,72, - 0,0,79,80,5,69,0,0,80,81,5,82,0,0,81,82,5,69,0,0,82,16,1,0,0,0,83,84,5, - 65,0,0,84,85,5,78,0,0,85,86,5,68,0,0,86,18,1,0,0,0,87,88,5,79,0,0,88,89, - 5,82,0,0,89,20,1,0,0,0,90,91,5,78,0,0,91,92,5,79,0,0,92,93,5,84,0,0,93, - 22,1,0,0,0,94,95,5,65,0,0,95,96,5,83,0,0,96,24,1,0,0,0,97,98,5,60,0,0,98, - 26,1,0,0,0,99,100,5,60,0,0,100,101,5,61,0,0,101,28,1,0,0,0,102,103,5,62, - 0,0,103,30,1,0,0,0,104,105,5,62,0,0,105,106,5,61,0,0,106,32,1,0,0,0,107, - 108,5,61,0,0,108,34,1,0,0,0,109,110,5,60,0,0,110,114,5,62,0,0,111,112,5, - 33,0,0,112,114,5,61,0,0,113,109,1,0,0,0,113,111,1,0,0,0,114,36,1,0,0,0, - 115,116,5,73,0,0,116,117,5,83,0,0,117,38,1,0,0,0,118,119,5,78,0,0,119,120, - 5,85,0,0,120,121,5,76,0,0,121,122,5,76,0,0,122,40,1,0,0,0,123,124,5,67, - 0,0,124,125,5,65,0,0,125,126,5,83,0,0,126,127,5,84,0,0,127,42,1,0,0,0,128, - 130,5,36,0,0,129,131,7,0,0,0,130,129,1,0,0,0,131,132,1,0,0,0,132,130,1, - 0,0,0,132,133,1,0,0,0,133,134,1,0,0,0,134,135,5,36,0,0,135,44,1,0,0,0,136, - 140,7,1,0,0,137,139,7,2,0,0,138,137,1,0,0,0,139,142,1,0,0,0,140,138,1,0, - 0,0,140,141,1,0,0,0,141,46,1,0,0,0,142,140,1,0,0,0,143,144,7,0,0,0,144, - 48,1,0,0,0,145,149,5,34,0,0,146,148,8,3,0,0,147,146,1,0,0,0,148,151,1,0, - 0,0,149,147,1,0,0,0,149,150,1,0,0,0,150,152,1,0,0,0,151,149,1,0,0,0,152, - 162,5,34,0,0,153,157,5,96,0,0,154,156,8,4,0,0,155,154,1,0,0,0,156,159,1, - 0,0,0,157,155,1,0,0,0,157,158,1,0,0,0,158,160,1,0,0,0,159,157,1,0,0,0,160, - 162,5,96,0,0,161,145,1,0,0,0,161,153,1,0,0,0,162,50,1,0,0,0,163,169,5,39, - 0,0,164,168,8,5,0,0,165,166,5,39,0,0,166,168,5,39,0,0,167,164,1,0,0,0,167, - 165,1,0,0,0,168,171,1,0,0,0,169,167,1,0,0,0,169,170,1,0,0,0,170,172,1,0, - 0,0,171,169,1,0,0,0,172,173,5,39,0,0,173,52,1,0,0,0,174,175,7,6,0,0,175, - 176,1,0,0,0,176,177,6,26,0,0,177,54,1,0,0,0,9,0,113,132,140,149,157,161, - 167,169,1,0,1,0]; + 2,24,7,24,2,25,7,25,2,26,7,26,2,27,7,27,2,28,7,28,2,29,7,29,2,30,7,30,1, + 0,1,0,1,1,1,1,1,2,1,2,1,3,1,3,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,5,1,5,1,6,1, + 6,1,6,1,6,1,6,1,7,1,7,1,7,1,7,1,7,1,7,1,8,1,8,1,8,1,8,1,9,1,9,1,9,1,10, + 1,10,1,10,1,10,1,11,1,11,1,11,1,12,1,12,1,13,1,13,1,13,1,14,1,14,1,15,1, + 15,1,15,1,16,1,16,1,17,1,17,1,17,1,17,3,17,122,8,17,1,18,1,18,1,18,1,19, + 1,19,1,19,1,19,1,19,1,20,1,20,1,20,1,20,1,20,1,21,1,21,1,21,1,21,1,21,1, + 21,1,21,1,22,1,22,4,22,146,8,22,11,22,12,22,147,1,22,1,22,1,23,1,23,1,24, + 1,24,5,24,156,8,24,10,24,12,24,159,9,24,1,25,1,25,1,26,1,26,5,26,165,8, + 26,10,26,12,26,168,9,26,1,26,1,26,1,26,5,26,173,8,26,10,26,12,26,176,9, + 26,1,26,3,26,179,8,26,1,27,1,27,1,27,1,27,5,27,185,8,27,10,27,12,27,188, + 9,27,1,27,1,27,1,28,1,28,1,28,1,28,1,29,1,29,1,29,1,29,5,29,200,8,29,10, + 29,12,29,203,9,29,1,29,3,29,206,8,29,1,29,1,29,3,29,210,8,29,1,29,1,29, + 1,30,1,30,1,30,1,30,5,30,218,8,30,10,30,12,30,221,9,30,1,30,1,30,1,30,1, + 30,1,30,1,219,0,31,1,1,3,2,5,3,7,4,9,5,11,6,13,7,15,8,17,9,19,10,21,11, + 23,12,25,13,27,14,29,15,31,16,33,17,35,18,37,19,39,20,41,21,43,22,45,23, + 47,24,49,25,51,26,53,27,55,28,57,29,59,30,61,31,1,0,8,1,0,48,57,2,0,64, + 90,95,95,3,0,48,57,64,90,95,95,1,0,34,34,1,0,96,96,1,0,39,39,3,0,9,10,13, + 13,32,32,2,0,10,10,13,13,238,0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,7,1, + 0,0,0,0,9,1,0,0,0,0,11,1,0,0,0,0,13,1,0,0,0,0,15,1,0,0,0,0,17,1,0,0,0,0, + 19,1,0,0,0,0,21,1,0,0,0,0,23,1,0,0,0,0,25,1,0,0,0,0,27,1,0,0,0,0,29,1,0, + 0,0,0,31,1,0,0,0,0,33,1,0,0,0,0,35,1,0,0,0,0,37,1,0,0,0,0,39,1,0,0,0,0, + 41,1,0,0,0,0,43,1,0,0,0,0,45,1,0,0,0,0,47,1,0,0,0,0,49,1,0,0,0,0,51,1,0, + 0,0,0,53,1,0,0,0,0,55,1,0,0,0,0,57,1,0,0,0,0,59,1,0,0,0,0,61,1,0,0,0,1, + 63,1,0,0,0,3,65,1,0,0,0,5,67,1,0,0,0,7,69,1,0,0,0,9,71,1,0,0,0,11,78,1, + 0,0,0,13,80,1,0,0,0,15,85,1,0,0,0,17,91,1,0,0,0,19,95,1,0,0,0,21,98,1,0, + 0,0,23,102,1,0,0,0,25,105,1,0,0,0,27,107,1,0,0,0,29,110,1,0,0,0,31,112, + 1,0,0,0,33,115,1,0,0,0,35,121,1,0,0,0,37,123,1,0,0,0,39,126,1,0,0,0,41, + 131,1,0,0,0,43,136,1,0,0,0,45,143,1,0,0,0,47,151,1,0,0,0,49,153,1,0,0,0, + 51,160,1,0,0,0,53,178,1,0,0,0,55,180,1,0,0,0,57,191,1,0,0,0,59,195,1,0, + 0,0,61,213,1,0,0,0,63,64,5,40,0,0,64,2,1,0,0,0,65,66,5,41,0,0,66,4,1,0, + 0,0,67,68,5,44,0,0,68,6,1,0,0,0,69,70,5,46,0,0,70,8,1,0,0,0,71,72,5,83, + 0,0,72,73,5,69,0,0,73,74,5,76,0,0,74,75,5,69,0,0,75,76,5,67,0,0,76,77,5, + 84,0,0,77,10,1,0,0,0,78,79,5,42,0,0,79,12,1,0,0,0,80,81,5,70,0,0,81,82, + 5,82,0,0,82,83,5,79,0,0,83,84,5,77,0,0,84,14,1,0,0,0,85,86,5,87,0,0,86, + 87,5,72,0,0,87,88,5,69,0,0,88,89,5,82,0,0,89,90,5,69,0,0,90,16,1,0,0,0, + 91,92,5,65,0,0,92,93,5,78,0,0,93,94,5,68,0,0,94,18,1,0,0,0,95,96,5,79,0, + 0,96,97,5,82,0,0,97,20,1,0,0,0,98,99,5,78,0,0,99,100,5,79,0,0,100,101,5, + 84,0,0,101,22,1,0,0,0,102,103,5,65,0,0,103,104,5,83,0,0,104,24,1,0,0,0, + 105,106,5,60,0,0,106,26,1,0,0,0,107,108,5,60,0,0,108,109,5,61,0,0,109,28, + 1,0,0,0,110,111,5,62,0,0,111,30,1,0,0,0,112,113,5,62,0,0,113,114,5,61,0, + 0,114,32,1,0,0,0,115,116,5,61,0,0,116,34,1,0,0,0,117,118,5,60,0,0,118,122, + 5,62,0,0,119,120,5,33,0,0,120,122,5,61,0,0,121,117,1,0,0,0,121,119,1,0, + 0,0,122,36,1,0,0,0,123,124,5,73,0,0,124,125,5,83,0,0,125,38,1,0,0,0,126, + 127,5,78,0,0,127,128,5,85,0,0,128,129,5,76,0,0,129,130,5,76,0,0,130,40, + 1,0,0,0,131,132,5,67,0,0,132,133,5,65,0,0,133,134,5,83,0,0,134,135,5,84, + 0,0,135,42,1,0,0,0,136,137,5,82,0,0,137,138,5,69,0,0,138,139,5,71,0,0,139, + 140,5,69,0,0,140,141,5,88,0,0,141,142,5,80,0,0,142,44,1,0,0,0,143,145,5, + 36,0,0,144,146,7,0,0,0,145,144,1,0,0,0,146,147,1,0,0,0,147,145,1,0,0,0, + 147,148,1,0,0,0,148,149,1,0,0,0,149,150,5,36,0,0,150,46,1,0,0,0,151,152, + 5,63,0,0,152,48,1,0,0,0,153,157,7,1,0,0,154,156,7,2,0,0,155,154,1,0,0,0, + 156,159,1,0,0,0,157,155,1,0,0,0,157,158,1,0,0,0,158,50,1,0,0,0,159,157, + 1,0,0,0,160,161,7,0,0,0,161,52,1,0,0,0,162,166,5,34,0,0,163,165,8,3,0,0, + 164,163,1,0,0,0,165,168,1,0,0,0,166,164,1,0,0,0,166,167,1,0,0,0,167,169, + 1,0,0,0,168,166,1,0,0,0,169,179,5,34,0,0,170,174,5,96,0,0,171,173,8,4,0, + 0,172,171,1,0,0,0,173,176,1,0,0,0,174,172,1,0,0,0,174,175,1,0,0,0,175,177, + 1,0,0,0,176,174,1,0,0,0,177,179,5,96,0,0,178,162,1,0,0,0,178,170,1,0,0, + 0,179,54,1,0,0,0,180,186,5,39,0,0,181,185,8,5,0,0,182,183,5,39,0,0,183, + 185,5,39,0,0,184,181,1,0,0,0,184,182,1,0,0,0,185,188,1,0,0,0,186,184,1, + 0,0,0,186,187,1,0,0,0,187,189,1,0,0,0,188,186,1,0,0,0,189,190,5,39,0,0, + 190,56,1,0,0,0,191,192,7,6,0,0,192,193,1,0,0,0,193,194,6,28,0,0,194,58, + 1,0,0,0,195,196,5,45,0,0,196,197,5,45,0,0,197,201,1,0,0,0,198,200,8,7,0, + 0,199,198,1,0,0,0,200,203,1,0,0,0,201,199,1,0,0,0,201,202,1,0,0,0,202,209, + 1,0,0,0,203,201,1,0,0,0,204,206,5,13,0,0,205,204,1,0,0,0,205,206,1,0,0, + 0,206,207,1,0,0,0,207,210,5,10,0,0,208,210,5,0,0,1,209,205,1,0,0,0,209, + 208,1,0,0,0,210,211,1,0,0,0,211,212,6,29,0,0,212,60,1,0,0,0,213,214,5,47, + 0,0,214,215,5,42,0,0,215,219,1,0,0,0,216,218,9,0,0,0,217,216,1,0,0,0,218, + 221,1,0,0,0,219,220,1,0,0,0,219,217,1,0,0,0,220,222,1,0,0,0,221,219,1,0, + 0,0,222,223,5,42,0,0,223,224,5,47,0,0,224,225,1,0,0,0,225,226,6,30,0,0, + 226,62,1,0,0,0,13,0,121,147,157,166,174,178,184,186,201,205,209,219,1,0, + 1,0]; private static __ATN: ATN; public static get _ATN(): ATN { diff --git a/packages/cubejs-schema-compiler/src/parser/GenericSqlListener.ts b/packages/cubejs-schema-compiler/src/parser/GenericSqlListener.ts index ee43d57d5fba5..7916c82405d3c 100644 --- a/packages/cubejs-schema-compiler/src/parser/GenericSqlListener.ts +++ b/packages/cubejs-schema-compiler/src/parser/GenericSqlListener.ts @@ -1,5 +1,4 @@ // Generated from src/parser/GenericSql.g4 by ANTLR 4.13.2 -// @ts-nocheck import {ParseTreeListener} from "antlr4"; @@ -9,6 +8,7 @@ import { QueryContext } from "./GenericSqlParser.js"; import { FromTablesContext } from "./GenericSqlParser.js"; import { SelectFieldsContext } from "./GenericSqlParser.js"; import { FieldContext } from "./GenericSqlParser.js"; +import { SelectFieldContext } from "./GenericSqlParser.js"; import { AliasFieldContext } from "./GenericSqlParser.js"; import { BoolExpContext } from "./GenericSqlParser.js"; import { ExpContext } from "./GenericSqlParser.js"; @@ -74,6 +74,16 @@ export default class GenericSqlListener extends ParseTreeListener { * @param ctx the parse tree */ exitField?: (ctx: FieldContext) => void; + /** + * Enter a parse tree produced by `GenericSqlParser.selectField`. + * @param ctx the parse tree + */ + enterSelectField?: (ctx: SelectFieldContext) => void; + /** + * Exit a parse tree produced by `GenericSqlParser.selectField`. + * @param ctx the parse tree + */ + exitSelectField?: (ctx: SelectFieldContext) => void; /** * Enter a parse tree produced by `GenericSqlParser.aliasField`. * @param ctx the parse tree diff --git a/packages/cubejs-schema-compiler/src/parser/GenericSqlParser.ts b/packages/cubejs-schema-compiler/src/parser/GenericSqlParser.ts index 6245eb95352b7..f46c3bc5d0b70 100644 --- a/packages/cubejs-schema-compiler/src/parser/GenericSqlParser.ts +++ b/packages/cubejs-schema-compiler/src/parser/GenericSqlParser.ts @@ -1,6 +1,5 @@ // Generated from src/parser/GenericSql.g4 by ANTLR 4.13.2 // noinspection ES6UnusedImports,JSUnusedGlobalSymbols,JSUnusedLocalSymbols -// @ts-nocheck import { ATN, @@ -41,26 +40,31 @@ export default class GenericSqlParser extends Parser { public static readonly IS = 19; public static readonly NULL = 20; public static readonly CAST = 21; - public static readonly INDEXED_PARAM = 22; - public static readonly ID = 23; - public static readonly DIGIT = 24; - public static readonly QUOTED_ID = 25; - public static readonly STRING = 26; - public static readonly WHITESPACE = 27; + public static readonly REGEXP = 22; + public static readonly INDEXED_PARAM = 23; + public static readonly PARAM_PLACEHOLDER = 24; + public static readonly ID = 25; + public static readonly DIGIT = 26; + public static readonly QUOTED_ID = 27; + public static readonly STRING = 28; + public static readonly WHITESPACE = 29; + public static readonly COMMENT = 30; + public static readonly MULTILINE_COMMENT = 31; public static override readonly EOF = Token.EOF; public static readonly RULE_statement = 0; public static readonly RULE_query = 1; public static readonly RULE_fromTables = 2; public static readonly RULE_selectFields = 3; public static readonly RULE_field = 4; - public static readonly RULE_aliasField = 5; - public static readonly RULE_boolExp = 6; - public static readonly RULE_exp = 7; - public static readonly RULE_numeric = 8; - public static readonly RULE_binaryOperator = 9; - public static readonly RULE_unaryOperator = 10; - public static readonly RULE_idPath = 11; - public static readonly RULE_identifier = 12; + public static readonly RULE_selectField = 5; + public static readonly RULE_aliasField = 6; + public static readonly RULE_boolExp = 7; + public static readonly RULE_exp = 8; + public static readonly RULE_numeric = 9; + public static readonly RULE_binaryOperator = 10; + public static readonly RULE_unaryOperator = 11; + public static readonly RULE_idPath = 12; + public static readonly RULE_identifier = 13; public static readonly literalNames: (string | null)[] = [ null, "'('", "')'", "','", "'.'", "'SELECT'", @@ -71,7 +75,9 @@ export default class GenericSqlParser extends Parser { "'<='", "'>'", "'>='", "'='", null, "'IS'", - "'NULL'", "'CAST'" ]; + "'NULL'", "'CAST'", + "'REGEXP'", + null, "'?'" ]; public static readonly symbolicNames: (string | null)[] = [ null, null, null, null, null, "SELECT", @@ -83,15 +89,19 @@ export default class GenericSqlParser extends Parser { "GT", "GTE", "EQUALS", "NOT_EQUALS", "IS", "NULL", - "CAST", "INDEXED_PARAM", + "CAST", "REGEXP", + "INDEXED_PARAM", + "PARAM_PLACEHOLDER", "ID", "DIGIT", "QUOTED_ID", - "STRING", "WHITESPACE" ]; + "STRING", "WHITESPACE", + "COMMENT", + "MULTILINE_COMMENT" ]; // tslint:disable:no-trailing-whitespace public static readonly ruleNames: string[] = [ - "statement", "query", "fromTables", "selectFields", "field", "aliasField", - "boolExp", "exp", "numeric", "binaryOperator", "unaryOperator", "idPath", - "identifier", + "statement", "query", "fromTables", "selectFields", "field", "selectField", + "aliasField", "boolExp", "exp", "numeric", "binaryOperator", "unaryOperator", + "idPath", "identifier", ]; public get grammarFileName(): string { return "GenericSql.g4"; } public get literalNames(): (string | null)[] { return GenericSqlParser.literalNames; } @@ -112,28 +122,28 @@ export default class GenericSqlParser extends Parser { let localctx: StatementContext = new StatementContext(this, this._ctx, this.state); this.enterRule(localctx, 0, GenericSqlParser.RULE_statement); try { - this.state = 34; + this.state = 36; this._errHandler.sync(this); switch (this._input.LA(1)) { case 5: this.enterOuterAlt(localctx, 1); { - this.state = 26; + this.state = 28; this.query(); - this.state = 27; + this.state = 29; this.match(GenericSqlParser.EOF); } break; case 1: this.enterOuterAlt(localctx, 2); { - this.state = 29; + this.state = 31; this.match(GenericSqlParser.T__0); - this.state = 30; + this.state = 32; this.query(); - this.state = 31; + this.state = 33; this.match(GenericSqlParser.T__1); - this.state = 32; + this.state = 34; this.match(GenericSqlParser.EOF); } break; @@ -163,22 +173,22 @@ export default class GenericSqlParser extends Parser { try { this.enterOuterAlt(localctx, 1); { - this.state = 36; + this.state = 38; this.match(GenericSqlParser.SELECT); - this.state = 37; + this.state = 39; this.selectFields(); - this.state = 38; + this.state = 40; this.match(GenericSqlParser.FROM); - this.state = 39; + this.state = 41; localctx._from_ = this.fromTables(); - this.state = 42; + this.state = 44; this._errHandler.sync(this); _la = this._input.LA(1); if (_la===8) { { - this.state = 40; + this.state = 42; this.match(GenericSqlParser.WHERE); - this.state = 41; + this.state = 43; localctx._where = this.boolExp(0); } } @@ -206,7 +216,7 @@ export default class GenericSqlParser extends Parser { try { this.enterOuterAlt(localctx, 1); { - this.state = 44; + this.state = 46; this.aliasField(); } } @@ -233,21 +243,21 @@ export default class GenericSqlParser extends Parser { this.enterOuterAlt(localctx, 1); { { - this.state = 46; + this.state = 48; this.field(); - this.state = 51; + this.state = 53; this._errHandler.sync(this); _la = this._input.LA(1); while (_la===3) { { { - this.state = 47; + this.state = 49; this.match(GenericSqlParser.T__2); - this.state = 48; + this.state = 50; this.field(); } } - this.state = 53; + this.state = 55; this._errHandler.sync(this); _la = this._input.LA(1); } @@ -273,21 +283,29 @@ export default class GenericSqlParser extends Parser { let localctx: FieldContext = new FieldContext(this, this._ctx, this.state); this.enterRule(localctx, 8, GenericSqlParser.RULE_field); try { - this.state = 56; + this.state = 58; this._errHandler.sync(this); switch (this._input.LA(1)) { + case 1: + case 4: + case 21: + case 22: case 23: + case 24: case 25: + case 26: + case 27: + case 28: this.enterOuterAlt(localctx, 1); { - this.state = 54; - this.aliasField(); + this.state = 56; + this.selectField(); } break; case 6: this.enterOuterAlt(localctx, 2); { - this.state = 55; + this.state = 57; this.match(GenericSqlParser.ASTERISK); } break; @@ -310,31 +328,77 @@ export default class GenericSqlParser extends Parser { return localctx; } // @RuleVersion(0) + public selectField(): SelectFieldContext { + let localctx: SelectFieldContext = new SelectFieldContext(this, this._ctx, this.state); + this.enterRule(localctx, 10, GenericSqlParser.RULE_selectField); + let _la: number; + try { + this.enterOuterAlt(localctx, 1); + { + this.state = 60; + this.exp(0); + this.state = 65; + this._errHandler.sync(this); + _la = this._input.LA(1); + if ((((_la) & ~0x1F) === 0 && ((1 << _la) & 167776256) !== 0)) { + { + this.state = 62; + this._errHandler.sync(this); + _la = this._input.LA(1); + if (_la===12) { + { + this.state = 61; + this.match(GenericSqlParser.AS); + } + } + + this.state = 64; + this.identifier(); + } + } + + } + } + catch (re) { + if (re instanceof RecognitionException) { + localctx.exception = re; + this._errHandler.reportError(this, re); + this._errHandler.recover(this, re); + } else { + throw re; + } + } + finally { + this.exitRule(); + } + return localctx; + } + // @RuleVersion(0) public aliasField(): AliasFieldContext { let localctx: AliasFieldContext = new AliasFieldContext(this, this._ctx, this.state); - this.enterRule(localctx, 10, GenericSqlParser.RULE_aliasField); + this.enterRule(localctx, 12, GenericSqlParser.RULE_aliasField); let _la: number; try { this.enterOuterAlt(localctx, 1); { - this.state = 58; + this.state = 67; this.idPath(); - this.state = 63; + this.state = 72; this._errHandler.sync(this); _la = this._input.LA(1); - if ((((_la) & ~0x1F) === 0 && ((1 << _la) & 41947136) !== 0)) { + if ((((_la) & ~0x1F) === 0 && ((1 << _la) & 167776256) !== 0)) { { - this.state = 60; + this.state = 69; this._errHandler.sync(this); _la = this._input.LA(1); if (_la===12) { { - this.state = 59; + this.state = 68; this.match(GenericSqlParser.AS); } } - this.state = 62; + this.state = 71; this.identifier(); } } @@ -368,13 +432,13 @@ export default class GenericSqlParser extends Parser { let _parentState: number = this.state; let localctx: BoolExpContext = new BoolExpContext(this, this._ctx, _parentState); let _prevctx: BoolExpContext = localctx; - let _startState: number = 12; - this.enterRecursionRule(localctx, 12, GenericSqlParser.RULE_boolExp, _p); + let _startState: number = 14; + this.enterRecursionRule(localctx, 14, GenericSqlParser.RULE_boolExp, _p); try { let _alt: number; this.enterOuterAlt(localctx, 1); { - this.state = 69; + this.state = 78; this._errHandler.sync(this); switch (this._input.LA(1)) { case 1: @@ -385,16 +449,18 @@ export default class GenericSqlParser extends Parser { case 24: case 25: case 26: + case 27: + case 28: { - this.state = 66; + this.state = 75; this.exp(0); } break; case 11: { - this.state = 67; + this.state = 76; this.match(GenericSqlParser.NOT); - this.state = 68; + this.state = 77; this.boolExp(1); } break; @@ -402,9 +468,9 @@ export default class GenericSqlParser extends Parser { throw new NoViableAltException(this); } this._ctx.stop = this._input.LT(-1); - this.state = 79; + this.state = 88; this._errHandler.sync(this); - _alt = this._interp.adaptivePredict(this._input, 8, this._ctx); + _alt = this._interp.adaptivePredict(this._input, 10, this._ctx); while (_alt !== 2 && _alt !== ATN.INVALID_ALT_NUMBER) { if (_alt === 1) { if (this._parseListeners != null) { @@ -412,20 +478,20 @@ export default class GenericSqlParser extends Parser { } _prevctx = localctx; { - this.state = 77; + this.state = 86; this._errHandler.sync(this); - switch ( this._interp.adaptivePredict(this._input, 7, this._ctx) ) { + switch ( this._interp.adaptivePredict(this._input, 9, this._ctx) ) { case 1: { localctx = new BoolExpContext(this, _parentctx, _parentState); this.pushNewRecursionContext(localctx, _startState, GenericSqlParser.RULE_boolExp); - this.state = 71; + this.state = 80; if (!(this.precpred(this._ctx, 3))) { throw this.createFailedPredicateException("this.precpred(this._ctx, 3)"); } - this.state = 72; + this.state = 81; this.match(GenericSqlParser.AND); - this.state = 73; + this.state = 82; this.boolExp(4); } break; @@ -433,22 +499,22 @@ export default class GenericSqlParser extends Parser { { localctx = new BoolExpContext(this, _parentctx, _parentState); this.pushNewRecursionContext(localctx, _startState, GenericSqlParser.RULE_boolExp); - this.state = 74; + this.state = 83; if (!(this.precpred(this._ctx, 2))) { throw this.createFailedPredicateException("this.precpred(this._ctx, 2)"); } - this.state = 75; + this.state = 84; this.match(GenericSqlParser.OR); - this.state = 76; + this.state = 85; this.boolExp(3); } break; } } } - this.state = 81; + this.state = 90; this._errHandler.sync(this); - _alt = this._interp.adaptivePredict(this._input, 8, this._ctx); + _alt = this._interp.adaptivePredict(this._input, 10, this._ctx); } } } @@ -479,107 +545,121 @@ export default class GenericSqlParser extends Parser { let _parentState: number = this.state; let localctx: ExpContext = new ExpContext(this, this._ctx, _parentState); let _prevctx: ExpContext = localctx; - let _startState: number = 14; - this.enterRecursionRule(localctx, 14, GenericSqlParser.RULE_exp, _p); + let _startState: number = 16; + this.enterRecursionRule(localctx, 16, GenericSqlParser.RULE_exp, _p); let _la: number; try { let _alt: number; this.enterOuterAlt(localctx, 1); { - this.state = 111; + this.state = 123; this._errHandler.sync(this); - switch ( this._interp.adaptivePredict(this._input, 10, this._ctx) ) { + switch ( this._interp.adaptivePredict(this._input, 12, this._ctx) ) { case 1: { - this.state = 83; + this.state = 92; this.idPath(); } break; case 2: { - this.state = 84; + this.state = 93; this.identifier(); - this.state = 85; + this.state = 94; this.match(GenericSqlParser.T__0); { - this.state = 86; + this.state = 95; this.exp(0); - this.state = 91; + this.state = 100; this._errHandler.sync(this); _la = this._input.LA(1); while (_la===3) { { { - this.state = 87; + this.state = 96; this.match(GenericSqlParser.T__2); - this.state = 88; + this.state = 97; this.exp(0); } } - this.state = 93; + this.state = 102; this._errHandler.sync(this); _la = this._input.LA(1); } } - this.state = 94; + this.state = 103; this.match(GenericSqlParser.T__1); } break; case 3: { - this.state = 96; + this.state = 105; this.match(GenericSqlParser.CAST); - this.state = 97; + this.state = 106; this.match(GenericSqlParser.T__0); - this.state = 98; + this.state = 107; this.exp(0); - this.state = 99; + this.state = 108; this.match(GenericSqlParser.AS); - this.state = 100; + this.state = 109; this.identifier(); - this.state = 101; + this.state = 110; this.match(GenericSqlParser.T__1); } break; case 4: { - this.state = 103; + this.state = 112; + this.match(GenericSqlParser.REGEXP); + this.state = 113; this.match(GenericSqlParser.STRING); } break; case 5: { - this.state = 104; - this.numeric(); + this.state = 114; + this.match(GenericSqlParser.STRING); } break; case 6: { - this.state = 105; - this.identifier(); + this.state = 115; + this.numeric(); } break; case 7: { - this.state = 106; - this.match(GenericSqlParser.INDEXED_PARAM); + this.state = 116; + this.identifier(); } break; case 8: { - this.state = 107; + this.state = 117; + this.match(GenericSqlParser.INDEXED_PARAM); + } + break; + case 9: + { + this.state = 118; + this.match(GenericSqlParser.PARAM_PLACEHOLDER); + } + break; + case 10: + { + this.state = 119; this.match(GenericSqlParser.T__0); - this.state = 108; + this.state = 120; this.exp(0); - this.state = 109; + this.state = 121; this.match(GenericSqlParser.T__1); } break; } this._ctx.stop = this._input.LT(-1); - this.state = 121; + this.state = 133; this._errHandler.sync(this); - _alt = this._interp.adaptivePredict(this._input, 12, this._ctx); + _alt = this._interp.adaptivePredict(this._input, 14, this._ctx); while (_alt !== 2 && _alt !== ATN.INVALID_ALT_NUMBER) { if (_alt === 1) { if (this._parseListeners != null) { @@ -587,41 +667,41 @@ export default class GenericSqlParser extends Parser { } _prevctx = localctx; { - this.state = 119; + this.state = 131; this._errHandler.sync(this); - switch ( this._interp.adaptivePredict(this._input, 11, this._ctx) ) { + switch ( this._interp.adaptivePredict(this._input, 13, this._ctx) ) { case 1: { localctx = new ExpContext(this, _parentctx, _parentState); this.pushNewRecursionContext(localctx, _startState, GenericSqlParser.RULE_exp); - this.state = 113; - if (!(this.precpred(this._ctx, 10))) { - throw this.createFailedPredicateException("this.precpred(this._ctx, 10)"); + this.state = 125; + if (!(this.precpred(this._ctx, 12))) { + throw this.createFailedPredicateException("this.precpred(this._ctx, 12)"); } - this.state = 114; + this.state = 126; this.binaryOperator(); - this.state = 115; - this.exp(11); + this.state = 127; + this.exp(13); } break; case 2: { localctx = new ExpContext(this, _parentctx, _parentState); this.pushNewRecursionContext(localctx, _startState, GenericSqlParser.RULE_exp); - this.state = 117; - if (!(this.precpred(this._ctx, 9))) { - throw this.createFailedPredicateException("this.precpred(this._ctx, 9)"); + this.state = 129; + if (!(this.precpred(this._ctx, 11))) { + throw this.createFailedPredicateException("this.precpred(this._ctx, 11)"); } - this.state = 118; + this.state = 130; this.unaryOperator(); } break; } } } - this.state = 123; + this.state = 135; this._errHandler.sync(this); - _alt = this._interp.adaptivePredict(this._input, 12, this._ctx); + _alt = this._interp.adaptivePredict(this._input, 14, this._ctx); } } } @@ -642,16 +722,16 @@ export default class GenericSqlParser extends Parser { // @RuleVersion(0) public numeric(): NumericContext { let localctx: NumericContext = new NumericContext(this, this._ctx, this.state); - this.enterRule(localctx, 16, GenericSqlParser.RULE_numeric); + this.enterRule(localctx, 18, GenericSqlParser.RULE_numeric); try { let _alt: number; - this.state = 143; + this.state = 155; this._errHandler.sync(this); switch (this._input.LA(1)) { - case 24: + case 26: this.enterOuterAlt(localctx, 1); { - this.state = 125; + this.state = 137; this._errHandler.sync(this); _alt = 1; do { @@ -659,7 +739,7 @@ export default class GenericSqlParser extends Parser { case 1: { { - this.state = 124; + this.state = 136; this.match(GenericSqlParser.DIGIT); } } @@ -667,18 +747,18 @@ export default class GenericSqlParser extends Parser { default: throw new NoViableAltException(this); } - this.state = 127; + this.state = 139; this._errHandler.sync(this); - _alt = this._interp.adaptivePredict(this._input, 13, this._ctx); + _alt = this._interp.adaptivePredict(this._input, 15, this._ctx); } while (_alt !== 2 && _alt !== ATN.INVALID_ALT_NUMBER); - this.state = 135; + this.state = 147; this._errHandler.sync(this); - switch ( this._interp.adaptivePredict(this._input, 15, this._ctx) ) { + switch ( this._interp.adaptivePredict(this._input, 17, this._ctx) ) { case 1: { - this.state = 129; + this.state = 141; this.match(GenericSqlParser.T__3); - this.state = 131; + this.state = 143; this._errHandler.sync(this); _alt = 1; do { @@ -686,7 +766,7 @@ export default class GenericSqlParser extends Parser { case 1: { { - this.state = 130; + this.state = 142; this.match(GenericSqlParser.DIGIT); } } @@ -694,9 +774,9 @@ export default class GenericSqlParser extends Parser { default: throw new NoViableAltException(this); } - this.state = 133; + this.state = 145; this._errHandler.sync(this); - _alt = this._interp.adaptivePredict(this._input, 14, this._ctx); + _alt = this._interp.adaptivePredict(this._input, 16, this._ctx); } while (_alt !== 2 && _alt !== ATN.INVALID_ALT_NUMBER); } break; @@ -706,9 +786,9 @@ export default class GenericSqlParser extends Parser { case 4: this.enterOuterAlt(localctx, 2); { - this.state = 137; + this.state = 149; this.match(GenericSqlParser.T__3); - this.state = 139; + this.state = 151; this._errHandler.sync(this); _alt = 1; do { @@ -716,7 +796,7 @@ export default class GenericSqlParser extends Parser { case 1: { { - this.state = 138; + this.state = 150; this.match(GenericSqlParser.DIGIT); } } @@ -724,9 +804,9 @@ export default class GenericSqlParser extends Parser { default: throw new NoViableAltException(this); } - this.state = 141; + this.state = 153; this._errHandler.sync(this); - _alt = this._interp.adaptivePredict(this._input, 16, this._ctx); + _alt = this._interp.adaptivePredict(this._input, 18, this._ctx); } while (_alt !== 2 && _alt !== ATN.INVALID_ALT_NUMBER); } break; @@ -751,12 +831,12 @@ export default class GenericSqlParser extends Parser { // @RuleVersion(0) public binaryOperator(): BinaryOperatorContext { let localctx: BinaryOperatorContext = new BinaryOperatorContext(this, this._ctx, this.state); - this.enterRule(localctx, 18, GenericSqlParser.RULE_binaryOperator); + this.enterRule(localctx, 20, GenericSqlParser.RULE_binaryOperator); let _la: number; try { this.enterOuterAlt(localctx, 1); { - this.state = 145; + this.state = 157; _la = this._input.LA(1); if(!((((_la) & ~0x1F) === 0 && ((1 << _la) & 516096) !== 0))) { this._errHandler.recoverInline(this); @@ -784,28 +864,28 @@ export default class GenericSqlParser extends Parser { // @RuleVersion(0) public unaryOperator(): UnaryOperatorContext { let localctx: UnaryOperatorContext = new UnaryOperatorContext(this, this._ctx, this.state); - this.enterRule(localctx, 20, GenericSqlParser.RULE_unaryOperator); + this.enterRule(localctx, 22, GenericSqlParser.RULE_unaryOperator); try { - this.state = 152; + this.state = 164; this._errHandler.sync(this); - switch ( this._interp.adaptivePredict(this._input, 18, this._ctx) ) { + switch ( this._interp.adaptivePredict(this._input, 20, this._ctx) ) { case 1: this.enterOuterAlt(localctx, 1); { - this.state = 147; + this.state = 159; this.match(GenericSqlParser.IS); - this.state = 148; + this.state = 160; this.match(GenericSqlParser.NULL); } break; case 2: this.enterOuterAlt(localctx, 2); { - this.state = 149; + this.state = 161; this.match(GenericSqlParser.IS); - this.state = 150; + this.state = 162; this.match(GenericSqlParser.NOT); - this.state = 151; + this.state = 163; this.match(GenericSqlParser.NULL); } break; @@ -828,30 +908,30 @@ export default class GenericSqlParser extends Parser { // @RuleVersion(0) public idPath(): IdPathContext { let localctx: IdPathContext = new IdPathContext(this, this._ctx, this.state); - this.enterRule(localctx, 22, GenericSqlParser.RULE_idPath); + this.enterRule(localctx, 24, GenericSqlParser.RULE_idPath); try { let _alt: number; this.enterOuterAlt(localctx, 1); { - this.state = 154; + this.state = 166; this.identifier(); - this.state = 159; + this.state = 171; this._errHandler.sync(this); - _alt = this._interp.adaptivePredict(this._input, 19, this._ctx); + _alt = this._interp.adaptivePredict(this._input, 21, this._ctx); while (_alt !== 2 && _alt !== ATN.INVALID_ALT_NUMBER) { if (_alt === 1) { { { - this.state = 155; + this.state = 167; this.match(GenericSqlParser.T__3); - this.state = 156; + this.state = 168; this.identifier(); } } } - this.state = 161; + this.state = 173; this._errHandler.sync(this); - _alt = this._interp.adaptivePredict(this._input, 19, this._ctx); + _alt = this._interp.adaptivePredict(this._input, 21, this._ctx); } } } @@ -872,14 +952,14 @@ export default class GenericSqlParser extends Parser { // @RuleVersion(0) public identifier(): IdentifierContext { let localctx: IdentifierContext = new IdentifierContext(this, this._ctx, this.state); - this.enterRule(localctx, 24, GenericSqlParser.RULE_identifier); + this.enterRule(localctx, 26, GenericSqlParser.RULE_identifier); let _la: number; try { this.enterOuterAlt(localctx, 1); { - this.state = 162; + this.state = 174; _la = this._input.LA(1); - if(!(_la===23 || _la===25)) { + if(!(_la===25 || _la===27)) { this._errHandler.recoverInline(this); } else { @@ -905,9 +985,9 @@ export default class GenericSqlParser extends Parser { public sempred(localctx: RuleContext, ruleIndex: number, predIndex: number): boolean { switch (ruleIndex) { - case 6: - return this.boolExp_sempred(localctx as BoolExpContext, predIndex); case 7: + return this.boolExp_sempred(localctx as BoolExpContext, predIndex); + case 8: return this.exp_sempred(localctx as ExpContext, predIndex); } return true; @@ -924,65 +1004,69 @@ export default class GenericSqlParser extends Parser { private exp_sempred(localctx: ExpContext, predIndex: number): boolean { switch (predIndex) { case 2: - return this.precpred(this._ctx, 10); + return this.precpred(this._ctx, 12); case 3: - return this.precpred(this._ctx, 9); + return this.precpred(this._ctx, 11); } return true; } - public static readonly _serializedATN: number[] = [4,1,27,165,2,0,7,0,2, + public static readonly _serializedATN: number[] = [4,1,31,177,2,0,7,0,2, 1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7,6,2,7,7,7,2,8,7,8,2,9,7,9,2, - 10,7,10,2,11,7,11,2,12,7,12,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,3,0,35,8,0, - 1,1,1,1,1,1,1,1,1,1,1,1,3,1,43,8,1,1,2,1,2,1,3,1,3,1,3,5,3,50,8,3,10,3, - 12,3,53,9,3,1,4,1,4,3,4,57,8,4,1,5,1,5,3,5,61,8,5,1,5,3,5,64,8,5,1,6,1, - 6,1,6,1,6,3,6,70,8,6,1,6,1,6,1,6,1,6,1,6,1,6,5,6,78,8,6,10,6,12,6,81,9, - 6,1,7,1,7,1,7,1,7,1,7,1,7,1,7,5,7,90,8,7,10,7,12,7,93,9,7,1,7,1,7,1,7,1, - 7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,3,7,112,8,7,1,7,1, - 7,1,7,1,7,1,7,1,7,5,7,120,8,7,10,7,12,7,123,9,7,1,8,4,8,126,8,8,11,8,12, - 8,127,1,8,1,8,4,8,132,8,8,11,8,12,8,133,3,8,136,8,8,1,8,1,8,4,8,140,8,8, - 11,8,12,8,141,3,8,144,8,8,1,9,1,9,1,10,1,10,1,10,1,10,1,10,3,10,153,8,10, - 1,11,1,11,1,11,5,11,158,8,11,10,11,12,11,161,9,11,1,12,1,12,1,12,0,2,12, - 14,13,0,2,4,6,8,10,12,14,16,18,20,22,24,0,2,1,0,13,18,2,0,23,23,25,25,177, - 0,34,1,0,0,0,2,36,1,0,0,0,4,44,1,0,0,0,6,46,1,0,0,0,8,56,1,0,0,0,10,58, - 1,0,0,0,12,69,1,0,0,0,14,111,1,0,0,0,16,143,1,0,0,0,18,145,1,0,0,0,20,152, - 1,0,0,0,22,154,1,0,0,0,24,162,1,0,0,0,26,27,3,2,1,0,27,28,5,0,0,1,28,35, - 1,0,0,0,29,30,5,1,0,0,30,31,3,2,1,0,31,32,5,2,0,0,32,33,5,0,0,1,33,35,1, - 0,0,0,34,26,1,0,0,0,34,29,1,0,0,0,35,1,1,0,0,0,36,37,5,5,0,0,37,38,3,6, - 3,0,38,39,5,7,0,0,39,42,3,4,2,0,40,41,5,8,0,0,41,43,3,12,6,0,42,40,1,0, - 0,0,42,43,1,0,0,0,43,3,1,0,0,0,44,45,3,10,5,0,45,5,1,0,0,0,46,51,3,8,4, - 0,47,48,5,3,0,0,48,50,3,8,4,0,49,47,1,0,0,0,50,53,1,0,0,0,51,49,1,0,0,0, - 51,52,1,0,0,0,52,7,1,0,0,0,53,51,1,0,0,0,54,57,3,10,5,0,55,57,5,6,0,0,56, - 54,1,0,0,0,56,55,1,0,0,0,57,9,1,0,0,0,58,63,3,22,11,0,59,61,5,12,0,0,60, - 59,1,0,0,0,60,61,1,0,0,0,61,62,1,0,0,0,62,64,3,24,12,0,63,60,1,0,0,0,63, - 64,1,0,0,0,64,11,1,0,0,0,65,66,6,6,-1,0,66,70,3,14,7,0,67,68,5,11,0,0,68, - 70,3,12,6,1,69,65,1,0,0,0,69,67,1,0,0,0,70,79,1,0,0,0,71,72,10,3,0,0,72, - 73,5,9,0,0,73,78,3,12,6,4,74,75,10,2,0,0,75,76,5,10,0,0,76,78,3,12,6,3, - 77,71,1,0,0,0,77,74,1,0,0,0,78,81,1,0,0,0,79,77,1,0,0,0,79,80,1,0,0,0,80, - 13,1,0,0,0,81,79,1,0,0,0,82,83,6,7,-1,0,83,112,3,22,11,0,84,85,3,24,12, - 0,85,86,5,1,0,0,86,91,3,14,7,0,87,88,5,3,0,0,88,90,3,14,7,0,89,87,1,0,0, - 0,90,93,1,0,0,0,91,89,1,0,0,0,91,92,1,0,0,0,92,94,1,0,0,0,93,91,1,0,0,0, - 94,95,5,2,0,0,95,112,1,0,0,0,96,97,5,21,0,0,97,98,5,1,0,0,98,99,3,14,7, - 0,99,100,5,12,0,0,100,101,3,24,12,0,101,102,5,2,0,0,102,112,1,0,0,0,103, - 112,5,26,0,0,104,112,3,16,8,0,105,112,3,24,12,0,106,112,5,22,0,0,107,108, - 5,1,0,0,108,109,3,14,7,0,109,110,5,2,0,0,110,112,1,0,0,0,111,82,1,0,0,0, - 111,84,1,0,0,0,111,96,1,0,0,0,111,103,1,0,0,0,111,104,1,0,0,0,111,105,1, - 0,0,0,111,106,1,0,0,0,111,107,1,0,0,0,112,121,1,0,0,0,113,114,10,10,0,0, - 114,115,3,18,9,0,115,116,3,14,7,11,116,120,1,0,0,0,117,118,10,9,0,0,118, - 120,3,20,10,0,119,113,1,0,0,0,119,117,1,0,0,0,120,123,1,0,0,0,121,119,1, - 0,0,0,121,122,1,0,0,0,122,15,1,0,0,0,123,121,1,0,0,0,124,126,5,24,0,0,125, - 124,1,0,0,0,126,127,1,0,0,0,127,125,1,0,0,0,127,128,1,0,0,0,128,135,1,0, - 0,0,129,131,5,4,0,0,130,132,5,24,0,0,131,130,1,0,0,0,132,133,1,0,0,0,133, - 131,1,0,0,0,133,134,1,0,0,0,134,136,1,0,0,0,135,129,1,0,0,0,135,136,1,0, - 0,0,136,144,1,0,0,0,137,139,5,4,0,0,138,140,5,24,0,0,139,138,1,0,0,0,140, - 141,1,0,0,0,141,139,1,0,0,0,141,142,1,0,0,0,142,144,1,0,0,0,143,125,1,0, - 0,0,143,137,1,0,0,0,144,17,1,0,0,0,145,146,7,0,0,0,146,19,1,0,0,0,147,148, - 5,19,0,0,148,153,5,20,0,0,149,150,5,19,0,0,150,151,5,11,0,0,151,153,5,20, - 0,0,152,147,1,0,0,0,152,149,1,0,0,0,153,21,1,0,0,0,154,159,3,24,12,0,155, - 156,5,4,0,0,156,158,3,24,12,0,157,155,1,0,0,0,158,161,1,0,0,0,159,157,1, - 0,0,0,159,160,1,0,0,0,160,23,1,0,0,0,161,159,1,0,0,0,162,163,7,1,0,0,163, - 25,1,0,0,0,20,34,42,51,56,60,63,69,77,79,91,111,119,121,127,133,135,141, - 143,152,159]; + 10,7,10,2,11,7,11,2,12,7,12,2,13,7,13,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,3, + 0,37,8,0,1,1,1,1,1,1,1,1,1,1,1,1,3,1,45,8,1,1,2,1,2,1,3,1,3,1,3,5,3,52, + 8,3,10,3,12,3,55,9,3,1,4,1,4,3,4,59,8,4,1,5,1,5,3,5,63,8,5,1,5,3,5,66,8, + 5,1,6,1,6,3,6,70,8,6,1,6,3,6,73,8,6,1,7,1,7,1,7,1,7,3,7,79,8,7,1,7,1,7, + 1,7,1,7,1,7,1,7,5,7,87,8,7,10,7,12,7,90,9,7,1,8,1,8,1,8,1,8,1,8,1,8,1,8, + 5,8,99,8,8,10,8,12,8,102,9,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1, + 8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,3,8,124,8,8,1,8,1,8,1,8,1,8,1,8,1, + 8,5,8,132,8,8,10,8,12,8,135,9,8,1,9,4,9,138,8,9,11,9,12,9,139,1,9,1,9,4, + 9,144,8,9,11,9,12,9,145,3,9,148,8,9,1,9,1,9,4,9,152,8,9,11,9,12,9,153,3, + 9,156,8,9,1,10,1,10,1,11,1,11,1,11,1,11,1,11,3,11,165,8,11,1,12,1,12,1, + 12,5,12,170,8,12,10,12,12,12,173,9,12,1,13,1,13,1,13,0,2,14,16,14,0,2,4, + 6,8,10,12,14,16,18,20,22,24,26,0,2,1,0,13,18,2,0,25,25,27,27,192,0,36,1, + 0,0,0,2,38,1,0,0,0,4,46,1,0,0,0,6,48,1,0,0,0,8,58,1,0,0,0,10,60,1,0,0,0, + 12,67,1,0,0,0,14,78,1,0,0,0,16,123,1,0,0,0,18,155,1,0,0,0,20,157,1,0,0, + 0,22,164,1,0,0,0,24,166,1,0,0,0,26,174,1,0,0,0,28,29,3,2,1,0,29,30,5,0, + 0,1,30,37,1,0,0,0,31,32,5,1,0,0,32,33,3,2,1,0,33,34,5,2,0,0,34,35,5,0,0, + 1,35,37,1,0,0,0,36,28,1,0,0,0,36,31,1,0,0,0,37,1,1,0,0,0,38,39,5,5,0,0, + 39,40,3,6,3,0,40,41,5,7,0,0,41,44,3,4,2,0,42,43,5,8,0,0,43,45,3,14,7,0, + 44,42,1,0,0,0,44,45,1,0,0,0,45,3,1,0,0,0,46,47,3,12,6,0,47,5,1,0,0,0,48, + 53,3,8,4,0,49,50,5,3,0,0,50,52,3,8,4,0,51,49,1,0,0,0,52,55,1,0,0,0,53,51, + 1,0,0,0,53,54,1,0,0,0,54,7,1,0,0,0,55,53,1,0,0,0,56,59,3,10,5,0,57,59,5, + 6,0,0,58,56,1,0,0,0,58,57,1,0,0,0,59,9,1,0,0,0,60,65,3,16,8,0,61,63,5,12, + 0,0,62,61,1,0,0,0,62,63,1,0,0,0,63,64,1,0,0,0,64,66,3,26,13,0,65,62,1,0, + 0,0,65,66,1,0,0,0,66,11,1,0,0,0,67,72,3,24,12,0,68,70,5,12,0,0,69,68,1, + 0,0,0,69,70,1,0,0,0,70,71,1,0,0,0,71,73,3,26,13,0,72,69,1,0,0,0,72,73,1, + 0,0,0,73,13,1,0,0,0,74,75,6,7,-1,0,75,79,3,16,8,0,76,77,5,11,0,0,77,79, + 3,14,7,1,78,74,1,0,0,0,78,76,1,0,0,0,79,88,1,0,0,0,80,81,10,3,0,0,81,82, + 5,9,0,0,82,87,3,14,7,4,83,84,10,2,0,0,84,85,5,10,0,0,85,87,3,14,7,3,86, + 80,1,0,0,0,86,83,1,0,0,0,87,90,1,0,0,0,88,86,1,0,0,0,88,89,1,0,0,0,89,15, + 1,0,0,0,90,88,1,0,0,0,91,92,6,8,-1,0,92,124,3,24,12,0,93,94,3,26,13,0,94, + 95,5,1,0,0,95,100,3,16,8,0,96,97,5,3,0,0,97,99,3,16,8,0,98,96,1,0,0,0,99, + 102,1,0,0,0,100,98,1,0,0,0,100,101,1,0,0,0,101,103,1,0,0,0,102,100,1,0, + 0,0,103,104,5,2,0,0,104,124,1,0,0,0,105,106,5,21,0,0,106,107,5,1,0,0,107, + 108,3,16,8,0,108,109,5,12,0,0,109,110,3,26,13,0,110,111,5,2,0,0,111,124, + 1,0,0,0,112,113,5,22,0,0,113,124,5,28,0,0,114,124,5,28,0,0,115,124,3,18, + 9,0,116,124,3,26,13,0,117,124,5,23,0,0,118,124,5,24,0,0,119,120,5,1,0,0, + 120,121,3,16,8,0,121,122,5,2,0,0,122,124,1,0,0,0,123,91,1,0,0,0,123,93, + 1,0,0,0,123,105,1,0,0,0,123,112,1,0,0,0,123,114,1,0,0,0,123,115,1,0,0,0, + 123,116,1,0,0,0,123,117,1,0,0,0,123,118,1,0,0,0,123,119,1,0,0,0,124,133, + 1,0,0,0,125,126,10,12,0,0,126,127,3,20,10,0,127,128,3,16,8,13,128,132,1, + 0,0,0,129,130,10,11,0,0,130,132,3,22,11,0,131,125,1,0,0,0,131,129,1,0,0, + 0,132,135,1,0,0,0,133,131,1,0,0,0,133,134,1,0,0,0,134,17,1,0,0,0,135,133, + 1,0,0,0,136,138,5,26,0,0,137,136,1,0,0,0,138,139,1,0,0,0,139,137,1,0,0, + 0,139,140,1,0,0,0,140,147,1,0,0,0,141,143,5,4,0,0,142,144,5,26,0,0,143, + 142,1,0,0,0,144,145,1,0,0,0,145,143,1,0,0,0,145,146,1,0,0,0,146,148,1,0, + 0,0,147,141,1,0,0,0,147,148,1,0,0,0,148,156,1,0,0,0,149,151,5,4,0,0,150, + 152,5,26,0,0,151,150,1,0,0,0,152,153,1,0,0,0,153,151,1,0,0,0,153,154,1, + 0,0,0,154,156,1,0,0,0,155,137,1,0,0,0,155,149,1,0,0,0,156,19,1,0,0,0,157, + 158,7,0,0,0,158,21,1,0,0,0,159,160,5,19,0,0,160,165,5,20,0,0,161,162,5, + 19,0,0,162,163,5,11,0,0,163,165,5,20,0,0,164,159,1,0,0,0,164,161,1,0,0, + 0,165,23,1,0,0,0,166,171,3,26,13,0,167,168,5,4,0,0,168,170,3,26,13,0,169, + 167,1,0,0,0,170,173,1,0,0,0,171,169,1,0,0,0,171,172,1,0,0,0,172,25,1,0, + 0,0,173,171,1,0,0,0,174,175,7,1,0,0,175,27,1,0,0,0,22,36,44,53,58,62,65, + 69,72,78,86,88,100,123,131,133,139,145,147,153,155,164,171]; private static __ATN: ATN; public static get _ATN(): ATN { @@ -1154,8 +1238,8 @@ export class FieldContext extends ParserRuleContext { super(parent, invokingState); this.parser = parser; } - public aliasField(): AliasFieldContext { - return this.getTypedRuleContext(AliasFieldContext, 0) as AliasFieldContext; + public selectField(): SelectFieldContext { + return this.getTypedRuleContext(SelectFieldContext, 0) as SelectFieldContext; } public ASTERISK(): TerminalNode { return this.getToken(GenericSqlParser.ASTERISK, 0); @@ -1184,6 +1268,44 @@ export class FieldContext extends ParserRuleContext { } +export class SelectFieldContext extends ParserRuleContext { + constructor(parser?: GenericSqlParser, parent?: ParserRuleContext, invokingState?: number) { + super(parent, invokingState); + this.parser = parser; + } + public exp(): ExpContext { + return this.getTypedRuleContext(ExpContext, 0) as ExpContext; + } + public identifier(): IdentifierContext { + return this.getTypedRuleContext(IdentifierContext, 0) as IdentifierContext; + } + public AS(): TerminalNode { + return this.getToken(GenericSqlParser.AS, 0); + } + public get ruleIndex(): number { + return GenericSqlParser.RULE_selectField; + } + public enterRule(listener: GenericSqlListener): void { + if(listener.enterSelectField) { + listener.enterSelectField(this); + } + } + public exitRule(listener: GenericSqlListener): void { + if(listener.exitSelectField) { + listener.exitSelectField(this); + } + } + // @Override + public accept(visitor: GenericSqlVisitor): Result { + if (visitor.visitSelectField) { + return visitor.visitSelectField(this); + } else { + return visitor.visitChildren(this); + } + } +} + + export class AliasFieldContext extends ParserRuleContext { constructor(parser?: GenericSqlParser, parent?: ParserRuleContext, invokingState?: number) { super(parent, invokingState); @@ -1292,6 +1414,9 @@ export class ExpContext extends ParserRuleContext { public AS(): TerminalNode { return this.getToken(GenericSqlParser.AS, 0); } + public REGEXP(): TerminalNode { + return this.getToken(GenericSqlParser.REGEXP, 0); + } public STRING(): TerminalNode { return this.getToken(GenericSqlParser.STRING, 0); } @@ -1301,6 +1426,9 @@ export class ExpContext extends ParserRuleContext { public INDEXED_PARAM(): TerminalNode { return this.getToken(GenericSqlParser.INDEXED_PARAM, 0); } + public PARAM_PLACEHOLDER(): TerminalNode { + return this.getToken(GenericSqlParser.PARAM_PLACEHOLDER, 0); + } public binaryOperator(): BinaryOperatorContext { return this.getTypedRuleContext(BinaryOperatorContext, 0) as BinaryOperatorContext; } diff --git a/packages/cubejs-schema-compiler/src/parser/GenericSqlVisitor.ts b/packages/cubejs-schema-compiler/src/parser/GenericSqlVisitor.ts index 67ad1dc485619..e413ae92f6a9e 100644 --- a/packages/cubejs-schema-compiler/src/parser/GenericSqlVisitor.ts +++ b/packages/cubejs-schema-compiler/src/parser/GenericSqlVisitor.ts @@ -1,5 +1,4 @@ // Generated from src/parser/GenericSql.g4 by ANTLR 4.13.2 -// @ts-nocheck import {ParseTreeVisitor} from 'antlr4'; @@ -9,6 +8,7 @@ import { QueryContext } from "./GenericSqlParser.js"; import { FromTablesContext } from "./GenericSqlParser.js"; import { SelectFieldsContext } from "./GenericSqlParser.js"; import { FieldContext } from "./GenericSqlParser.js"; +import { SelectFieldContext } from "./GenericSqlParser.js"; import { AliasFieldContext } from "./GenericSqlParser.js"; import { BoolExpContext } from "./GenericSqlParser.js"; import { ExpContext } from "./GenericSqlParser.js"; @@ -57,6 +57,12 @@ export default class GenericSqlVisitor extends ParseTreeVisitor * @return the visitor result */ visitField?: (ctx: FieldContext) => Result; + /** + * Visit a parse tree produced by `GenericSqlParser.selectField`. + * @param ctx the parse tree + * @return the visitor result + */ + visitSelectField?: (ctx: SelectFieldContext) => Result; /** * Visit a parse tree produced by `GenericSqlParser.aliasField`. * @param ctx the parse tree diff --git a/packages/cubejs-schema-compiler/src/parser/SqlParser.ts b/packages/cubejs-schema-compiler/src/parser/SqlParser.ts index d63d686d9696a..7d906c60b89a6 100644 --- a/packages/cubejs-schema-compiler/src/parser/SqlParser.ts +++ b/packages/cubejs-schema-compiler/src/parser/SqlParser.ts @@ -64,9 +64,19 @@ export class SqlParser { protected static sqlUpperCase(sql) { let result = ''; let openChar; + let commentType: ('--' | '/*' | '') = ''; for (let i = 0; i < sql.length; i++) { - if (openChar) { + if (commentType) { + if (commentType === '--' && (sql[i] === '\n' || sql[i] === '\r')) { + commentType = ''; + } else if (commentType === '/*' && sql[i] === '*' && sql[i + 1] === '/') { + result += sql[i]; + i++; + commentType = ''; + } + result += sql[i]; + } else if (openChar) { if (openChar === '\'' && sql[i] === openChar && sql[i + 1] === openChar) { result += sql[i]; i++; @@ -74,10 +84,20 @@ export class SqlParser { openChar = null; } result += sql[i]; + } else if (sql[i] === '-' && sql[i + 1] === '-') { + // Check for start of single-line comment + commentType = '--'; + result += sql[i]; + } else if (sql[i] === '/' && sql[i + 1] === '*') { + // Check for start of multi-line comment + commentType = '/*'; + result += sql[i]; + } else if (sql[i] === '\'' || sql[i] === '"' || sql[i] === '`') { + // Check for string literals + openChar = sql[i]; + result += sql[i]; } else { - if (sql[i] === '\'' || sql[i] === '"' || sql[i] === '`') { - openChar = sql[i]; - } + // Regular character - convert to uppercase result += sql[i].toUpperCase(); } } diff --git a/packages/cubejs-schema-compiler/test/unit/sql-parser.test.ts b/packages/cubejs-schema-compiler/test/unit/sql-parser.test.ts index f0493762096a9..74250a97e3758 100644 --- a/packages/cubejs-schema-compiler/test/unit/sql-parser.test.ts +++ b/packages/cubejs-schema-compiler/test/unit/sql-parser.test.ts @@ -97,4 +97,35 @@ describe('SqlParser', () => { expect(sqlParser.isSimpleAsteriskQuery()).toEqual(true); expect(sqlParser.extractWhereConditions('x')).toEqual('1 = 1'); }); + + it('sql with comment and question mark', () => { + const sqlParser = new SqlParser('SELECT 1 as test FROM table_name -- this is comment that kaputs Cube -> ?'); + expect(sqlParser.canParse()).toEqual(true); + }); + + it('sql with regex containing question mark', () => { + const sqlParser = new SqlParser('SELECT * FROM users WHERE name = ? AND REGEXP \'^stripe(?!_direct).{1,}$\''); + expect(sqlParser.canParse()).toEqual(true); + }); + + it('sql with multiline comment containing question mark', () => { + const sqlParser = new SqlParser(`SELECT 1 as test FROM table_name + /* this is a real + multiline comment that + contains ? character */`); + expect(sqlParser.canParse()).toEqual(true); + }); + + it('numeric literal in SELECT with table alias extraction', () => { + const sqlParser = new SqlParser(`SELECT 1 as test_literal, 2.5 as decimal_literal + FROM users u + WHERE u.status = 'active' AND u.created_at > '2024-01-01'`); + + expect(sqlParser.canParse()).toEqual(true); + expect(sqlParser.isSimpleAsteriskQuery()).toEqual(false); + + // Verify table alias extraction still works after grammar changes + const extractedConditions = sqlParser.extractWhereConditions('t'); + expect(extractedConditions).toEqual(`t.status = 'active' AND t.created_at > '2024-01-01'`); + }); });