Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

QueryParser: Adds / Fixes multiple arguments in IN clause #1926

Merged
merged 4 commits into from
Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
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