Skip to content

ANTLR grammar fails to parse tabular subquery on the right of in #194

Description

The KQL docs mention that this is a valid expression:

StormEvents 
| where State in (
    StormEvents
    | summarize count() by State
    | top 5 by count_
    ) 
| count

https://learn.microsoft.com/en-us/kusto/query/in-cs-operator?view=azure-data-explorer#tabular-expression

The KQL ANTLR grammar in the repo fails to parse it:

line 5:4 mismatched input '|' expecting {')', ','}
line 7:4 mismatched input ')' expecting {<EOF>, ';'}

This seems to be due to this line in Kql.g4:

listEqualityExpression:
    Left=relationalExpression OperatorToken=(IN | NOT_IN | IN_CI | NOT_IN_CI | HAS_ANY | HAS_ALL) '(' Expressions+=invocationExpression (',' Expressions+=invocationExpression)* ')';

which may need to be replaced with something like this (extra pipeExpression):

listEqualityExpression:
      Left=relationalExpression OperatorToken=(IN | NOT_IN | IN_CI | NOT_IN_CI | HAS_ANY | HAS_ALL) '(' Subquery=pipeExpression ')'
    | Left=relationalExpression OperatorToken=(IN | NOT_IN | IN_CI | NOT_IN_CI | HAS_ANY | HAS_ALL) '(' Expressions+=invocationExpression (',' Expressions+=invocationExpression)* ')'
    ;

Full repro:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions