Conversation
Signed-off-by: 1fanwang <1fannnw@gmail.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #25521 +/- ##
==========================================
+ Coverage 82.38% 82.42% +0.03%
==========================================
Files 1138 1138
Lines 434309 435443 +1134
Branches 434309 435443 +1134
==========================================
+ Hits 357803 358893 +1090
+ Misses 54875 54845 -30
- Partials 21631 21705 +74 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Thank you @1fanwang for picking this issue. I left one comment please take a look.
| alias: Option<ast::TableAlias>, | ||
| lateral: bool, | ||
| ) -> Result<()> { | ||
| let preserve_names = matches!(plan, LogicalPlan::Projection(_)) |
There was a problem hiding this comment.
Output-name preservation should not depend on the derived table having a table alias. BigQueryDialect does not require one, so derive_with_dialect_alias passes None and this condition remains false. The inner computed expression is then anonymous while the outer projection references its encoded logical name, producing invalid GoogleSQL. Could we preserve names whenever no table-column alias list already provides them, and add a BigQuery or alias-less regression test?
Signed-off-by: 1fanwang <1fannnw@gmail.com>
Which issue does this PR close?
Related to #21066.
Rationale for this change
An outer query can reference a computed result by its logical output name while the generated inner query leaves that result unnamed. The database cannot resolve the outer reference. For example, BigQuery output refers to
sum_40j1_46j1_id_41without defining it in the derived table.What changes are included in this PR?
Derived projections now emit matching output names whether or not the table has an alias. The unparser waits until the final table alias is known, so a table-column alias list still supplies the names. Explicit expression aliases and plain column references keep their existing SQL.
What is the testing strategy for this PR?
The regression exercises PostgreSQL and BigQuery output through the unparser. Existing column-alias and UNNEST snapshots remain unchanged. Roundtrip tests still compare the whole logical plan after removing only unqualified, metadata-free column self-aliases.
Testing Done
SQLite 3.51.0 executes the emitted BigQuery SQL without rewriting it. This uses local SQLite, not the Google BigQuery service. The pre-fix query below was captured from 4abdeef; the fixed query comes directly from the regression run.
python3 - "$log"belowno such column: sum_40j1_46j1_id_41python3 - "$log"below[(3,)]Run from this checkout:
Raw logs
Are there any user-facing changes?
Generated derived projections expose the computed column names used by outer queries, including when the dialect does not require a table alias. SQL input validation and public APIs are unchanged.