feat: disallow using source-based fields with aggregate functions #10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This feature adds comprehensive compile-time validation rules for aggregate functions (SUM, COUNT, AVG, UNIQUE, etc.) in EventQL queries. The static analyzer now enforces strict semantic constraints to ensure aggregate functions are used correctly and prevent queries that would produce ambiguous or undefined results.
Validation Rules
The feature implements three key validation rules:
1. Aggregate Functions Must Only Appear in PROJECT INTO Clauses
Aggregate functions can only be used within the
PROJECT INTOclause. They are prohibited in:WHEREpredicatesGROUP BYexpressionsORDER BYexpressionsRationale: Aggregate functions compute values across groups of events and only make semantic sense when projecting aggregated results.
Example - Invalid:
Example - Valid:
2. Aggregate Functions Cannot Be Mixed with Source-Bound Fields
Within a single
PROJECT INTOclause, you cannot mix aggregate functions with fields that reference individual source events.Rationale: Aggregate functions operate at the group level (producing one value per group), while source-bound fields operate at the individual event level (producing one value per event). These two cardinalities cannot be reconciled in a single projection.
Example - Invalid:
Example - Valid:
3. Aggregate Function Arguments Must Be Source-Bound Fields
Arguments passed to aggregate functions must be fields derived from the source events being queried. They cannot be:
Rationale: Aggregate functions are designed to compute over event properties across multiple events. Passing constants or function results would produce meaningless aggregations.
Example - Invalid:
Example - Valid: