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

Query: Adds support for LIKE statement and INT system functions to c# query parser to avoid gateway query plan call when service interop is not available. #2353

Merged
merged 17 commits into from
Apr 21, 2021
Merged
25 changes: 25 additions & 0 deletions Microsoft.Azure.Cosmos/src/Query/Core/Parser/CstToAstVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,27 @@ public override SqlObject VisitIn_scalar_expression([NotNull] sqlParser.In_scala
return SqlInScalarExpression.Create(needle, not, searchList.ToImmutableArray());
}

public override SqlObject VisitLike_scalar_expression([NotNull] sqlParser.Like_scalar_expressionContext context)
leminh98 marked this conversation as resolved.
Show resolved Hide resolved
{
Contract.Requires(context != null);
leminh98 marked this conversation as resolved.
Show resolved Hide resolved

SqlScalarExpression expression = (SqlScalarExpression)this.Visit(context.binary_scalar_expression()[0]);
SqlScalarExpression pattern = (SqlScalarExpression)this.Visit(context.binary_scalar_expression()[1]);
bool not = context.K_NOT() != null;
SqlStringLiteral escapeSequence = (context.escape_expression() != null)
? (SqlStringLiteral)this.Visit(context.escape_expression())
: null;

leminh98 marked this conversation as resolved.
Show resolved Hide resolved
return SqlLikeScalarExpression.Create(expression, pattern, not, escapeSequence);
}

public override SqlObject VisitEscape_expression([NotNull] sqlParser.Escape_expressionContext context)
{
Contract.Requires(context != null);

return (SqlStringLiteral)this.Visit(context.STRING_LITERAL());
}

public override SqlObject VisitLiteralScalarExpression([NotNull] sqlParser.LiteralScalarExpressionContext context)
{
Contract.Requires(context != null);
Expand Down Expand Up @@ -769,6 +790,10 @@ public override SqlObject VisitLogical_scalar_expression([NotNull] sqlParser.Log
{
sqlObject = this.Visit(context.in_scalar_expression());
}
else if (context.like_scalar_expression() != null)
{
sqlObject = this.Visit(context.like_scalar_expression());
}
else
{
throw new NotImplementedException();
Expand Down
1,348 changes: 684 additions & 664 deletions Microsoft.Azure.Cosmos/src/Query/Core/Parser/IsqlListener.cs

Large diffs are not rendered by default.

802 changes: 407 additions & 395 deletions Microsoft.Azure.Cosmos/src/Query/Core/Parser/IsqlVisitor.cs

Large diffs are not rendered by default.

15 changes: 13 additions & 2 deletions Microsoft.Azure.Cosmos/src/Query/Core/Parser/sql.g4
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,21 @@ scalar_expression
logical_scalar_expression
: binary_scalar_expression
| in_scalar_expression
| like_scalar_expression
;

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

like_scalar_expression
: binary_scalar_expression K_NOT? K_LIKE binary_scalar_expression escape_expression?
;
leminh98 marked this conversation as resolved.
Show resolved Hide resolved

escape_expression
: K_ESCAPE STRING_LITERAL
;

binary_scalar_expression
: unary_scalar_expression
| binary_scalar_expression multiplicative_operator binary_scalar_expression
Expand Down Expand Up @@ -184,12 +193,14 @@ K_BETWEEN : B E T W E E N;
K_BY : B Y;
K_DESC : D E S C;
K_DISTINCT : D I S T I N C T;
K_ESCAPE: E S C A P E;
leminh98 marked this conversation as resolved.
Show resolved Hide resolved
K_EXISTS : E X I S T S;
K_FALSE : 'false';
K_FROM : F R O M;
K_GROUP : G R O U P;
K_IN : I N ;
K_JOIN : J O I N;
K_LIKE : L I K E;
K_LIMIT : L I M I T;
K_NOT : N O T;
K_NULL : 'null';
Expand Down Expand Up @@ -248,8 +259,8 @@ fragment SAFECODEPOINT
;

IDENTIFIER
:
| [a-zA-Z_][a-zA-Z_]*DIGIT*
:
| [a-zA-Z_]([a-zA-Z_]|DIGIT)*
;

PARAMETER
Expand Down
855 changes: 855 additions & 0 deletions Microsoft.Azure.Cosmos/src/Query/Core/Parser/sqlBaseListener.cs

Large diffs are not rendered by default.

1,300 changes: 661 additions & 639 deletions Microsoft.Azure.Cosmos/src/Query/Core/Parser/sqlBaseVisitor.cs

Large diffs are not rendered by default.

1,113 changes: 560 additions & 553 deletions Microsoft.Azure.Cosmos/src/Query/Core/Parser/sqlLexer.cs

Large diffs are not rendered by default.

Loading