fix: resolve qualified column references after aggregation in binary expressions #17626
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.
When aggregation operations produce unqualified column names in their output schema, subsequent operations (like binary expressions) may still reference the original qualified names. This fix adds fallback resolution that attempts to match qualified column references to unqualified column names when the exact qualified match is not found.
This resolves errors like:
'No field named table.column. Valid fields are column'
that occur in expressions like
avg(table.column) / 1024where the aggregation produces an unqualified 'value' field but the division still references 'table.column'.Includes test case demonstrating the issue and fix.
Which issue does this PR close?
This PR addresses a schema resolution issue discovered during integration testing. No existing issue was filed.
Rationale for this change
Currently, when an aggregation function produces an unqualified output schema (e.g., just "value" without a table qualifier), subsequent binary operations that reference the original qualified column name fail with a schema resolution error. This is a common pattern in SQL queries where aggregations are combined with arithmetic operations.
For example:
The aggregation produces an unqualified "value" field, but the division operation still carries the qualified reference "metrics.value", causing the query to fail.
What changes are included in this PR?
Are these changes tested?
Yes, includes a new test case that:
Are there any user-facing changes?
This is a bug fix that makes previously failing queries work correctly. No breaking changes to existing functionality.