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

Add a custom error message for a missing alias after 'aggregate:' #2144

Merged
merged 2 commits into from
Feb 20, 2025

Conversation

mbooth4
Copy link
Collaborator

@mbooth4 mbooth4 commented Feb 19, 2025

Fixes #34

I added a helpful error message: "'aggregate:' entries must include a name (ex: some_name is count())"

Add an error message rewriter for the case:

run: x -> {
  aggregate: count()
}

Was:

image

Now:

image

I also wanted to make sure we could support the aggregate error even when it is nested inside of a view. To do so, we couldn't rely on the same logic because the parser fails to parse the entire view: clause. Instead, I added a new error rewriter option lookbackFromOffendingSymbol that lets us do relative sequence comparisons from the token associated with the error, rather than the token associated with the parser's current position. The Malloy grammar has a lot of ambiguity that is resolved by lookahead logic in the ATN and so we cannot rely on the currentToken to be up-to-date when an error is hit.

source: airports is duckdb.table('../data/airports.parquet') extend {
  measure: airport_count is count()

  view: by_state is {
    where: state is not null
    aggregate: count()
  }
}

Was:

image

Now:

image

@mbooth4 mbooth4 merged commit 79ac867 into main Feb 20, 2025
15 checks passed
@mbooth4 mbooth4 deleted the michaelbooth/aggregate-error branch February 20, 2025 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Throw better error when an alias on a field is omitted
1 participant