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

Open
#194 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
72/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
java, python
Domain
compilers

Research direction

Start with the listEqualityExpression rule in Kql.g4 and reproduce the failure using the provided Java ANTLR generation command and Python parser example. Update the grammar so the tabular subquery form parses while preserving the comma-separated invocation form, then rerun the full KQL example and confirm it produces no parse errors.

Written by the indexing model from the issue text.

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:

Dominant language
C#
Stars
680
Forks
122
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/Kusto-Query-Language

All issues in microsoft/Kusto-Query-Language

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.