Skip to content

Commit

Permalink
Internal QueryParser: Adds / Fixes multiple arguments in IN clause (#…
Browse files Browse the repository at this point in the history
…1926)

* fixed issue with multiple arguments in IN clause

* added double quotes object create baseline test
  • Loading branch information
bchong95 authored Oct 19, 2020
1 parent 967bc7f commit 0e0bdb7
Show file tree
Hide file tree
Showing 6 changed files with 721 additions and 687 deletions.
5 changes: 3 additions & 2 deletions Microsoft.Azure.Cosmos/src/Query/Core/Parser/sql.g4
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ logical_scalar_expression
;

in_scalar_expression
: binary_scalar_expression K_NOT? K_IN scalar_expression_list
: binary_scalar_expression K_NOT? K_IN '(' scalar_expression_list ')'
;

binary_scalar_expression
Expand Down Expand Up @@ -227,7 +227,8 @@ NUMERIC_LITERAL
;

STRING_LITERAL
: ('\'' | '"') (ESC | SAFECODEPOINT)* ('\'' | '"')
: '"' (ESC | SAFECODEPOINT)* '"'
| '\'' (ESC | SAFECODEPOINT)* '\''
;

fragment ESC
Expand Down
759 changes: 384 additions & 375 deletions Microsoft.Azure.Cosmos/src/Query/Core/Parser/sqlLexer.cs

Large diffs are not rendered by default.

614 changes: 309 additions & 305 deletions Microsoft.Azure.Cosmos/src/Query/Core/Parser/sqlParser.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,19 @@
<Result>
<Input>
<Description><![CDATA[multiple arguments]]></Description>
<Query><![CDATA[SELECT VALUE 42 IN ('asdf', 'as')]]></Query>
<Query><![CDATA[SELECT VALUE 42 IN (1, 2, 3)]]></Query>
</Input>
<Output>
<ParsedQuery><![CDATA[SELECT VALUE (42 IN ("asdf', 'as"))]]></ParsedQuery>
<ParsedQuery><![CDATA[SELECT VALUE (42 IN (1, 2, 3))]]></ParsedQuery>
</Output>
</Result>
<Result>
<Input>
<Description><![CDATA[multiple string arguments]]></Description>
<Query><![CDATA[SELECT VALUE 42 IN ("WA", "CA")]]></Query>
</Input>
<Output>
<ParsedQuery><![CDATA[SELECT VALUE (42 IN ("WA", "CA"))]]></ParsedQuery>
</Output>
</Result>
<Result>
Expand All @@ -41,7 +50,7 @@
<Query><![CDATA[SELECT VALUE 42 IN (-123]]></Query>
</Input>
<Output>
<Exception><![CDATA[Exception of type 'Antlr4.Runtime.NoViableAltException' was thrown.]]></Exception>
<Exception><![CDATA[can not recover.]]></Exception>
</Output>
</Result>
<Result>
Expand Down Expand Up @@ -77,7 +86,7 @@
<Query><![CDATA[SELECT VALUE 42 IN ]]></Query>
</Input>
<Output>
<Exception><![CDATA[Exception of type 'Antlr4.Runtime.NoViableAltException' was thrown.]]></Exception>
<Exception><![CDATA[can not recover.]]></Exception>
</Output>
</Result>
<Result>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@
<ParsedQuery><![CDATA[SELECT VALUE {"prop1' : 42, 'prop2": 1337}]]></ParsedQuery>
</Output>
</Result>
<Result>
<Input>
<Description><![CDATA[Double Quotes]]></Description>
<Query><![CDATA[SELECT VALUE { "prop" : "Some String" }]]></Query>
</Input>
<Output>
<ParsedQuery><![CDATA[SELECT VALUE {"prop": "Some String"}]]></ParsedQuery>
</Output>
</Result>
<Result>
<Input>
<Description><![CDATA[Missing Close Brace]]></Description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ public void In()
{
// Positive
CreateInput(description: "Basic", scalarExpression: "42 IN(42)"),
CreateInput(description: "multiple arguments", scalarExpression: "42 IN ('asdf', 'as')"),
CreateInput(description: "multiple arguments", scalarExpression: "42 IN (1, 2, 3)"),
CreateInput(description: "multiple string arguments", scalarExpression: "42 IN (\"WA\", \"CA\")"),
CreateInput(description: "NOT IN", scalarExpression: "42 NOT IN (42)"),

// Negative
Expand Down Expand Up @@ -282,6 +283,7 @@ public void ObjectCreate()
CreateInput(description: "Empty Object", scalarExpression: "{}"),
CreateInput(description: "Single Property", scalarExpression: "{ 'prop' : 42 }"),
CreateInput(description: "Multiple Property", scalarExpression: "{ 'prop1' : 42, 'prop2' : 1337 }"),
CreateInput(description: "Double Quotes", scalarExpression: "{ \"prop\" : \"Some String\" }"),

// Negative
CreateInput(description: "Missing Close Brace", scalarExpression: "{"),
Expand Down

0 comments on commit 0e0bdb7

Please sign in to comment.