Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions cosmosdb/CosmosDBLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ EXISTS_SYMBOL: 'EXISTS';
LIKE_SYMBOL: 'LIKE';
HAVING_SYMBOL: 'HAVING';
JOIN_SYMBOL: 'JOIN';
ESCAPE_SYMBOL: 'ESCAPE';
ARRAY_SYMBOL: 'ARRAY';
ROOT_SYMBOL: 'ROOT';
RANK_SYMBOL: 'RANK';

AT_SYMBOL: '@';
LC_BRACKET_SYMBOL: '{';
Expand All @@ -73,6 +77,7 @@ SINGLE_QUOTE_SYMBOL: '\'';
DOUBLE_QUOTE_SYMBOL: '"';
COMMA_SYMBOL: ',';
DOT_SYMBOL: '.';
DOUBLE_QUESTION_MARK_SYMBOL: '??';
QUESTION_MARK_SYMBOL: '?';
COLON_SYMBOL: ':';
PLUS_SYMBOL: '+';
Expand All @@ -93,15 +98,22 @@ LEFT_SHIFT_OPERATOR: '<<';
RIGHT_SHIFT_OPERATOR: '>>';
ZERO_FILL_RIGHT_SHIFT_OPERATOR: '>>>';
NOT_EQUAL_OPERATOR: '!=';
NOT_EQUAL_OPERATOR_2: '<>';


/* Constants */
INFINITY_SYMBOL options { caseInsensitive = false; }: 'Infinity';
NAN_SYMBOL options { caseInsensitive = false; }: 'NaN';

/* Identifiers */
IDENTIFIER: [a-z_] [a-z_0-9]*;

// White space handling
WHITESPACE:
[ \t\f\r\n] -> channel(HIDDEN); // Ignore whitespaces.

LINE_COMMENT: '--' ~[\r\n]* -> channel(HIDDEN);

// Decimal literal.
fragment DEC_DIGIT: [0-9];
fragment DEC_DOT_DEC: (
Expand Down
60 changes: 49 additions & 11 deletions cosmosdb/CosmosDBParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,30 @@ order_by_clause:
COMMA_SYMBOL sort_expression
)*;

sort_expression: scalar_expression (ASC_SYMBOL | DESC_SYMBOL)?;
sort_expression:
scalar_expression (ASC_SYMBOL | DESC_SYMBOL)?
| RANK_SYMBOL scalar_expression;

offset_limit_clause: OFFSET_SYMBOL DECIMAL LIMIT_SYMBOL DECIMAL;

from_specification: from_source;
from_specification: from_source (join_clause)*;

from_source: container_expression (join_clause)*;
from_source:
container_expression (AS_SYMBOL? identifier)?
| identifier IN_SYMBOL container_expression;

container_expression: container_name (AS_SYMBOL? identifier)?;
container_expression:
ROOT_SYMBOL
| container_name
| container_expression DOT_SYMBOL property_name
| container_expression LS_BRACKET_SYMBOL (
DOUBLE_QUOTE_STRING_LITERAL
| SINGLE_QUOTE_STRING_LITERAL
| array_index
) RS_BRACKET_SYMBOL
| LR_BRACKET_SYMBOL select RR_BRACKET_SYMBOL;

join_clause:
JOIN_SYMBOL identifier IN_SYMBOL scalar_expression;
join_clause: JOIN_SYMBOL from_source;

container_name: identifier;

Expand All @@ -70,11 +82,13 @@ scalar_expression:
| LR_BRACKET_SYMBOL scalar_expression RR_BRACKET_SYMBOL
| LR_BRACKET_SYMBOL select RR_BRACKET_SYMBOL
| EXISTS_SYMBOL LR_BRACKET_SYMBOL select RR_BRACKET_SYMBOL
| ARRAY_SYMBOL LR_BRACKET_SYMBOL select RR_BRACKET_SYMBOL
| scalar_expression DOT_SYMBOL property_name
| scalar_expression LS_BRACKET_SYMBOL (
DOUBLE_QUOTE_STRING_LITERAL
| SINGLE_QUOTE_STRING_LITERAL
| array_index
| parameter_name
) RS_BRACKET_SYMBOL
| unary_operator scalar_expression
| NOT_SYMBOL scalar_expression
Expand All @@ -90,9 +104,10 @@ scalar_expression:
scalar_expression (COMMA_SYMBOL scalar_expression)*
)? RR_BRACKET_SYMBOL
| scalar_expression NOT_SYMBOL? BETWEEN_SYMBOL scalar_expression AND_SYMBOL scalar_expression
| scalar_expression NOT_SYMBOL? LIKE_SYMBOL scalar_expression
| scalar_expression NOT_SYMBOL? LIKE_SYMBOL scalar_expression (ESCAPE_SYMBOL scalar_expression)?
| scalar_expression AND_SYMBOL scalar_expression
| scalar_expression OR_SYMBOL scalar_expression
| scalar_expression DOUBLE_QUESTION_MARK_SYMBOL scalar_expression
| scalar_expression QUESTION_MARK_SYMBOL scalar_expression COLON_SYMBOL scalar_expression;

create_array_expression:
Expand Down Expand Up @@ -139,6 +154,7 @@ shift_operator:
comparison_operator:
EQUAL_SYMBOL
| NOT_EQUAL_OPERATOR
| NOT_EQUAL_OPERATOR_2
| LESS_THAN_OPERATOR
| LESS_THAN_EQUAL_OPERATOR
| GREATER_THAN_OPERATOR
Expand All @@ -162,7 +178,7 @@ null_constant: NULL_SYMBOL;

boolean_constant: TRUE_SYMBOL | FALSE_SYMBOL;

number_constant: decimal_literal | hexadecimal_literal;
number_constant: decimal_literal | hexadecimal_literal | INFINITY_SYMBOL | NAN_SYMBOL;

string_constant: string_literal;

Expand Down Expand Up @@ -192,9 +208,31 @@ identifier:
| EXISTS_SYMBOL
| LIKE_SYMBOL
| HAVING_SYMBOL
| JOIN_SYMBOL;

property_name: identifier;
| JOIN_SYMBOL
| ESCAPE_SYMBOL
| ARRAY_SYMBOL
| ROOT_SYMBOL
| RANK_SYMBOL;

property_name:
identifier
| SELECT_SYMBOL
| FROM_SYMBOL
| WHERE_SYMBOL
| NOT_SYMBOL
| AND_SYMBOL
| OR_SYMBOL
| AS_SYMBOL
| TRUE_SYMBOL
| FALSE_SYMBOL
| NULL_SYMBOL
| UNDEFINED_SYMBOL
| UDF_SYMBOL
| DISTINCT_SYMBOL
| ARRAY_SYMBOL
| ROOT_SYMBOL
| ESCAPE_SYMBOL
| RANK_SYMBOL;

array_index: DECIMAL;

Expand Down
635 changes: 340 additions & 295 deletions cosmosdb/cosmosdb_lexer.go

Large diffs are not rendered by default.

2,145 changes: 1,486 additions & 659 deletions cosmosdb/cosmosdb_parser.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions cosmosdb/examples/array_subquery.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT c.name, ARRAY(SELECT VALUE t FROM t IN c.tags WHERE t.active = true) AS activeTags FROM c
1 change: 1 addition & 0 deletions cosmosdb/examples/bracket_parameter.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT c.id, c[@fieldName] AS fieldValue FROM c WHERE c[@filterField] = @filterValue
1 change: 1 addition & 0 deletions cosmosdb/examples/coalesce_operator.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT c.name ?? "unknown" AS displayName, c.nickname ?? c.name ?? "anonymous" AS nick FROM c
1 change: 1 addition & 0 deletions cosmosdb/examples/from_in_iteration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT VALUE s FROM s IN products.sizes WHERE s.key = 'l'
1 change: 1 addition & 0 deletions cosmosdb/examples/from_root.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT * FROM ROOT r WHERE r.id = '1'
1 change: 1 addition & 0 deletions cosmosdb/examples/from_subquery.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT sub.name FROM (SELECT c.name, c.city FROM c) AS sub
1 change: 1 addition & 0 deletions cosmosdb/examples/from_subroot.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT VALUE s FROM products.sizes s
1 change: 1 addition & 0 deletions cosmosdb/examples/fulltext_search.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT TOP 10 c.name, c.description FROM c WHERE FullTextContains(c.description, 'bicycle') ORDER BY RANK FullTextScore(c.description, ['bicycle'])
1 change: 1 addition & 0 deletions cosmosdb/examples/infinity_nan.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT c.name, c.value = Infinity AS isInfinite, IS_NUMBER(NaN) AS nanCheck FROM c
1 change: 1 addition & 0 deletions cosmosdb/examples/join_subquery.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT p.name, t.tag FROM products p JOIN t IN p.tags WHERE t.active = true
1 change: 1 addition & 0 deletions cosmosdb/examples/keyword_property_names.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT c.id, c.value, c.order, c.type, c["select"], c["from"], c["where"] FROM c
1 change: 1 addition & 0 deletions cosmosdb/examples/like_escape.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT * FROM c WHERE c.name LIKE '%20^%%' ESCAPE '^'
1 change: 1 addition & 0 deletions cosmosdb/examples/line_comment.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT c.name, c.city FROM c WHERE c.city = 'New York' -- filter by city
1 change: 1 addition & 0 deletions cosmosdb/examples/not_equal_diamond.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT * FROM c WHERE c.status <> 'active'
Loading