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 ALL Scalar Expression #3509

Merged
merged 17 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from 10 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
35 changes: 22 additions & 13 deletions Microsoft.Azure.Cosmos/src/Query/Core/Parser/CstToAstVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ public override SqlObject VisitSelect_item([NotNull] sqlParser.Select_itemContex

SqlScalarExpression sqlScalarExpression = (SqlScalarExpression)this.Visit(context.scalar_expression());
SqlIdentifier alias;
if (context.IDENTIFIER() != null)
if (context.identifier() != null)
ezrahaleva-msft marked this conversation as resolved.
Show resolved Hide resolved
{
alias = SqlIdentifier.Create(context.IDENTIFIER().GetText());
alias = SqlIdentifier.Create(context.identifier().GetText());
}
else
{
Expand Down Expand Up @@ -233,9 +233,9 @@ public override SqlObject VisitAliasedCollectionExpression([NotNull] sqlParser.A

SqlCollection sqlCollection = (SqlCollection)this.Visit(context.collection());
SqlIdentifier alias;
if (context.IDENTIFIER() != null)
if (context.identifier() != null)
{
alias = SqlIdentifier.Create(context.IDENTIFIER().GetText());
alias = SqlIdentifier.Create(context.identifier().GetText());
}
else
{
Expand All @@ -250,7 +250,7 @@ public override SqlObject VisitArrayIteratorCollectionExpression([NotNull] sqlPa
Contract.Requires(context != null);

SqlCollection sqlCollection = (SqlCollection)this.Visit(context.collection());
SqlIdentifier identifier = SqlIdentifier.Create(context.IDENTIFIER().GetText());
SqlIdentifier identifier = SqlIdentifier.Create(context.identifier().GetText());

return SqlArrayIteratorCollectionExpression.Create(identifier, sqlCollection);
}
Expand All @@ -269,7 +269,7 @@ public override SqlObject VisitInputPathCollection([NotNull] sqlParser.InputPath
{
Contract.Requires(context != null);

SqlIdentifier identifier = SqlIdentifier.Create(context.IDENTIFIER().GetText());
SqlIdentifier identifier = SqlIdentifier.Create(context.identifier().GetText());
SqlPathExpression pathExpression;
if (context.path_expression() != null)
{
Expand Down Expand Up @@ -302,7 +302,7 @@ public override SqlObject VisitIdentifierPathExpression([NotNull] sqlParser.Iden
Contract.Requires(context != null);

SqlPathExpression pathExpression = (SqlPathExpression)this.Visit(context.path_expression());
SqlIdentifier identifier = SqlIdentifier.Create(context.IDENTIFIER().GetText());
SqlIdentifier identifier = SqlIdentifier.Create(context.identifier().GetText());

return SqlIdentifierPathExpression.Create(parentPath: pathExpression, value: identifier);
}
Expand Down Expand Up @@ -458,6 +458,15 @@ public override SqlObject VisitLimit_count([NotNull] sqlParser.Limit_countContex
#endregion
#region ScalarExpressions

public override SqlObject VisitAllScalarExpression([NotNull] sqlParser.AllScalarExpressionContext context)
{
Contract.Requires(context != null);
// K_ALL '(' sql_query ')'
Contract.Requires(context.ChildCount == 4);

SqlQuery subquery = (SqlQuery)this.Visit(context.children[2]);
return SqlAllScalarExpression.Create(subquery);
}
public override SqlObject VisitArrayCreateScalarExpression([NotNull] sqlParser.ArrayCreateScalarExpressionContext context)
{
Contract.Requires(context != null);
Expand Down Expand Up @@ -562,10 +571,10 @@ public override SqlObject VisitExistsScalarExpression([NotNull] sqlParser.Exists
public override SqlObject VisitFunctionCallScalarExpression([NotNull] sqlParser.FunctionCallScalarExpressionContext context)
{
Contract.Requires(context != null);
// (K_UDF '.')? IDENTIFIER '(' scalar_expression_list? ')'
// (K_UDF '.')? identifier '(' scalar_expression_list? ')'

bool udf = context.K_UDF() != null;
SqlIdentifier identifier = SqlIdentifier.Create(context.IDENTIFIER().GetText());
SqlIdentifier identifier = SqlIdentifier.Create(context.identifier().GetText());
List<SqlScalarExpression> arguments = new List<SqlScalarExpression>();
if (context.scalar_expression_list() != null)
{
Expand Down Expand Up @@ -719,20 +728,20 @@ public override SqlObject VisitParameterRefScalarExpression([NotNull] sqlParser.
public override SqlObject VisitPropertyRefScalarExpressionBase([NotNull] sqlParser.PropertyRefScalarExpressionBaseContext context)
{
Contract.Requires(context != null);
// IDENTIFIER
// identifier

return SqlPropertyRefScalarExpression.Create(
member: null,
SqlIdentifier.Create(context.IDENTIFIER().GetText()));
SqlIdentifier.Create(context.identifier().GetText()));
}

public override SqlObject VisitPropertyRefScalarExpressionRecursive([NotNull] sqlParser.PropertyRefScalarExpressionRecursiveContext context)
{
Contract.Requires(context != null);
// primary_expression '.' IDENTIFIER
// primary_expression '.' identifier

SqlScalarExpression memberExpression = (SqlScalarExpression)this.Visit(context.primary_expression());
SqlIdentifier indentifier = SqlIdentifier.Create(context.IDENTIFIER().GetText());
SqlIdentifier indentifier = SqlIdentifier.Create(context.identifier().GetText());

return SqlPropertyRefScalarExpression.Create(memberExpression, indentifier);
}
Expand Down
110 changes: 66 additions & 44 deletions Microsoft.Azure.Cosmos/src/Query/Core/Parser/IsqlListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -526,137 +526,149 @@ internal interface IsqlListener : IParseTreeListener {
/// <param name="context">The parse tree.</param>
void ExitUnary_operator([NotNull] sqlParser.Unary_operatorContext context);
/// <summary>
/// Enter a parse tree produced by the <c>SubqueryScalarExpression</c>
/// Enter a parse tree produced by the <c>AllScalarExpression</c>
/// labeled alternative in <see cref="sqlParser.primary_expression"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void EnterSubqueryScalarExpression([NotNull] sqlParser.SubqueryScalarExpressionContext context);
void EnterAllScalarExpression([NotNull] sqlParser.AllScalarExpressionContext context);
/// <summary>
/// Exit a parse tree produced by the <c>SubqueryScalarExpression</c>
/// Exit a parse tree produced by the <c>AllScalarExpression</c>
/// labeled alternative in <see cref="sqlParser.primary_expression"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void ExitSubqueryScalarExpression([NotNull] sqlParser.SubqueryScalarExpressionContext context);
void ExitAllScalarExpression([NotNull] sqlParser.AllScalarExpressionContext context);
/// <summary>
/// Enter a parse tree produced by the <c>PropertyRefScalarExpressionBase</c>
/// Enter a parse tree produced by the <c>LiteralScalarExpression</c>
/// labeled alternative in <see cref="sqlParser.primary_expression"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void EnterPropertyRefScalarExpressionBase([NotNull] sqlParser.PropertyRefScalarExpressionBaseContext context);
void EnterLiteralScalarExpression([NotNull] sqlParser.LiteralScalarExpressionContext context);
/// <summary>
/// Exit a parse tree produced by the <c>PropertyRefScalarExpressionBase</c>
/// Exit a parse tree produced by the <c>LiteralScalarExpression</c>
/// labeled alternative in <see cref="sqlParser.primary_expression"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void ExitPropertyRefScalarExpressionBase([NotNull] sqlParser.PropertyRefScalarExpressionBaseContext context);
void ExitLiteralScalarExpression([NotNull] sqlParser.LiteralScalarExpressionContext context);
/// <summary>
/// Enter a parse tree produced by the <c>FunctionCallScalarExpression</c>
/// Enter a parse tree produced by the <c>ObjectCreateScalarExpression</c>
/// labeled alternative in <see cref="sqlParser.primary_expression"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void EnterFunctionCallScalarExpression([NotNull] sqlParser.FunctionCallScalarExpressionContext context);
void EnterObjectCreateScalarExpression([NotNull] sqlParser.ObjectCreateScalarExpressionContext context);
/// <summary>
/// Exit a parse tree produced by the <c>FunctionCallScalarExpression</c>
/// Exit a parse tree produced by the <c>ObjectCreateScalarExpression</c>
/// labeled alternative in <see cref="sqlParser.primary_expression"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void ExitFunctionCallScalarExpression([NotNull] sqlParser.FunctionCallScalarExpressionContext context);
void ExitObjectCreateScalarExpression([NotNull] sqlParser.ObjectCreateScalarExpressionContext context);
/// <summary>
/// Enter a parse tree produced by the <c>LiteralScalarExpression</c>
/// Enter a parse tree produced by the <c>ArrayCreateScalarExpression</c>
/// labeled alternative in <see cref="sqlParser.primary_expression"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void EnterLiteralScalarExpression([NotNull] sqlParser.LiteralScalarExpressionContext context);
void EnterArrayCreateScalarExpression([NotNull] sqlParser.ArrayCreateScalarExpressionContext context);
/// <summary>
/// Exit a parse tree produced by the <c>LiteralScalarExpression</c>
/// Exit a parse tree produced by the <c>ArrayCreateScalarExpression</c>
/// labeled alternative in <see cref="sqlParser.primary_expression"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void ExitLiteralScalarExpression([NotNull] sqlParser.LiteralScalarExpressionContext context);
void ExitArrayCreateScalarExpression([NotNull] sqlParser.ArrayCreateScalarExpressionContext context);
/// <summary>
/// Enter a parse tree produced by the <c>ObjectCreateScalarExpression</c>
/// Enter a parse tree produced by the <c>MemberIndexerScalarExpression</c>
/// labeled alternative in <see cref="sqlParser.primary_expression"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void EnterObjectCreateScalarExpression([NotNull] sqlParser.ObjectCreateScalarExpressionContext context);
void EnterMemberIndexerScalarExpression([NotNull] sqlParser.MemberIndexerScalarExpressionContext context);
/// <summary>
/// Exit a parse tree produced by the <c>ObjectCreateScalarExpression</c>
/// Exit a parse tree produced by the <c>MemberIndexerScalarExpression</c>
/// labeled alternative in <see cref="sqlParser.primary_expression"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void ExitObjectCreateScalarExpression([NotNull] sqlParser.ObjectCreateScalarExpressionContext context);
void ExitMemberIndexerScalarExpression([NotNull] sqlParser.MemberIndexerScalarExpressionContext context);
/// <summary>
/// Enter a parse tree produced by the <c>ParenthesizedScalarExperession</c>
/// Enter a parse tree produced by the <c>SubqueryScalarExpression</c>
/// labeled alternative in <see cref="sqlParser.primary_expression"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void EnterParenthesizedScalarExperession([NotNull] sqlParser.ParenthesizedScalarExperessionContext context);
void EnterSubqueryScalarExpression([NotNull] sqlParser.SubqueryScalarExpressionContext context);
/// <summary>
/// Exit a parse tree produced by the <c>ParenthesizedScalarExperession</c>
/// Exit a parse tree produced by the <c>SubqueryScalarExpression</c>
/// labeled alternative in <see cref="sqlParser.primary_expression"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void ExitParenthesizedScalarExperession([NotNull] sqlParser.ParenthesizedScalarExperessionContext context);
void ExitSubqueryScalarExpression([NotNull] sqlParser.SubqueryScalarExpressionContext context);
/// <summary>
/// Enter a parse tree produced by the <c>ParameterRefScalarExpression</c>
/// Enter a parse tree produced by the <c>PropertyRefScalarExpressionBase</c>
/// labeled alternative in <see cref="sqlParser.primary_expression"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void EnterParameterRefScalarExpression([NotNull] sqlParser.ParameterRefScalarExpressionContext context);
void EnterPropertyRefScalarExpressionBase([NotNull] sqlParser.PropertyRefScalarExpressionBaseContext context);
/// <summary>
/// Exit a parse tree produced by the <c>ParameterRefScalarExpression</c>
/// Exit a parse tree produced by the <c>PropertyRefScalarExpressionBase</c>
/// labeled alternative in <see cref="sqlParser.primary_expression"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void ExitParameterRefScalarExpression([NotNull] sqlParser.ParameterRefScalarExpressionContext context);
void ExitPropertyRefScalarExpressionBase([NotNull] sqlParser.PropertyRefScalarExpressionBaseContext context);
/// <summary>
/// Enter a parse tree produced by the <c>ArrayCreateScalarExpression</c>
/// Enter a parse tree produced by the <c>FunctionCallScalarExpression</c>
/// labeled alternative in <see cref="sqlParser.primary_expression"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void EnterArrayCreateScalarExpression([NotNull] sqlParser.ArrayCreateScalarExpressionContext context);
void EnterFunctionCallScalarExpression([NotNull] sqlParser.FunctionCallScalarExpressionContext context);
/// <summary>
/// Exit a parse tree produced by the <c>ArrayCreateScalarExpression</c>
/// Exit a parse tree produced by the <c>FunctionCallScalarExpression</c>
/// labeled alternative in <see cref="sqlParser.primary_expression"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void ExitArrayCreateScalarExpression([NotNull] sqlParser.ArrayCreateScalarExpressionContext context);
void ExitFunctionCallScalarExpression([NotNull] sqlParser.FunctionCallScalarExpressionContext context);
/// <summary>
/// Enter a parse tree produced by the <c>ExistsScalarExpression</c>
/// Enter a parse tree produced by the <c>ParenthesizedScalarExperession</c>
/// labeled alternative in <see cref="sqlParser.primary_expression"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void EnterExistsScalarExpression([NotNull] sqlParser.ExistsScalarExpressionContext context);
void EnterParenthesizedScalarExperession([NotNull] sqlParser.ParenthesizedScalarExperessionContext context);
/// <summary>
/// Exit a parse tree produced by the <c>ExistsScalarExpression</c>
/// Exit a parse tree produced by the <c>ParenthesizedScalarExperession</c>
/// labeled alternative in <see cref="sqlParser.primary_expression"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void ExitExistsScalarExpression([NotNull] sqlParser.ExistsScalarExpressionContext context);
void ExitParenthesizedScalarExperession([NotNull] sqlParser.ParenthesizedScalarExperessionContext context);
/// <summary>
/// Enter a parse tree produced by the <c>ArrayScalarExpression</c>
/// Enter a parse tree produced by the <c>ParameterRefScalarExpression</c>
/// labeled alternative in <see cref="sqlParser.primary_expression"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void EnterArrayScalarExpression([NotNull] sqlParser.ArrayScalarExpressionContext context);
void EnterParameterRefScalarExpression([NotNull] sqlParser.ParameterRefScalarExpressionContext context);
/// <summary>
/// Exit a parse tree produced by the <c>ArrayScalarExpression</c>
/// Exit a parse tree produced by the <c>ParameterRefScalarExpression</c>
/// labeled alternative in <see cref="sqlParser.primary_expression"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void ExitArrayScalarExpression([NotNull] sqlParser.ArrayScalarExpressionContext context);
void ExitParameterRefScalarExpression([NotNull] sqlParser.ParameterRefScalarExpressionContext context);
/// <summary>
/// Enter a parse tree produced by the <c>MemberIndexerScalarExpression</c>
/// Enter a parse tree produced by the <c>ExistsScalarExpression</c>
/// labeled alternative in <see cref="sqlParser.primary_expression"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void EnterMemberIndexerScalarExpression([NotNull] sqlParser.MemberIndexerScalarExpressionContext context);
void EnterExistsScalarExpression([NotNull] sqlParser.ExistsScalarExpressionContext context);
/// <summary>
/// Exit a parse tree produced by the <c>MemberIndexerScalarExpression</c>
/// Exit a parse tree produced by the <c>ExistsScalarExpression</c>
/// labeled alternative in <see cref="sqlParser.primary_expression"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void ExitMemberIndexerScalarExpression([NotNull] sqlParser.MemberIndexerScalarExpressionContext context);
void ExitExistsScalarExpression([NotNull] sqlParser.ExistsScalarExpressionContext context);
/// <summary>
/// Enter a parse tree produced by the <c>ArrayScalarExpression</c>
/// labeled alternative in <see cref="sqlParser.primary_expression"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void EnterArrayScalarExpression([NotNull] sqlParser.ArrayScalarExpressionContext context);
/// <summary>
/// Exit a parse tree produced by the <c>ArrayScalarExpression</c>
/// labeled alternative in <see cref="sqlParser.primary_expression"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void ExitArrayScalarExpression([NotNull] sqlParser.ArrayScalarExpressionContext context);
/// <summary>
/// Enter a parse tree produced by the <c>PropertyRefScalarExpressionRecursive</c>
/// labeled alternative in <see cref="sqlParser.primary_expression"/>.
Expand Down Expand Up @@ -700,6 +712,16 @@ internal interface IsqlListener : IParseTreeListener {
/// <param name="context">The parse tree.</param>
void ExitObject_property([NotNull] sqlParser.Object_propertyContext context);
/// <summary>
/// Enter a parse tree produced by <see cref="sqlParser.identifier"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void EnterIdentifier([NotNull] sqlParser.IdentifierContext context);
/// <summary>
/// Exit a parse tree produced by <see cref="sqlParser.identifier"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void ExitIdentifier([NotNull] sqlParser.IdentifierContext context);
/// <summary>
/// Enter a parse tree produced by <see cref="sqlParser.literal"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
Expand Down
Loading