Commit d36f6b3
committed
fix(db2): unwrap Alias(Select) before SYSDUMMY1 injection to fix column alias placement
db2_sqlglot registers _add_sysibm_dual as a preprocessor on exp.Select.
When the top-level node is Alias(Select, alias=name) — produced by
exp.select(expr).as_("col") — the generator renders the inner Select
(which adds FROM SYSIBM.SYSDUMMY1 via the preprocessor) and then appends
AS name after the fully-rendered SQL string, giving:
SELECT ... FROM SYSIBM.SYSDUMMY1 AS the_col ← broken
instead of:
SELECT ... AS the_col FROM SYSIBM.SYSDUMMY1 ← correct
The column has no alias in the result so pandas sees column name '1'.
Fix in _fetch_native_df: when the expression is Alias(Select), move the
alias onto the first selected expression before the generator sees it.
The generator then processes a bare Select, SYSDUMMY1 lands in the right
place, and the column alias is emitted correctly.
Also add db2 to the col_name uppercase branch in test_to_time_column:
Db2 returns column names in uppercase (THE_COL) after normalize_identifiers,
same as Snowflake. Root cause is the db2_sqlglot dialect Alias/Select bug;
correct fix is in db2_sqlglot but is worked around here pending that fix.1 parent d760fb4 commit d36f6b3
2 files changed
Lines changed: 23 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
789 | 789 | | |
790 | 790 | | |
791 | 791 | | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
792 | 813 | | |
793 | 814 | | |
794 | 815 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2726 | 2726 | | |
2727 | 2727 | | |
2728 | 2728 | | |
2729 | | - | |
| 2729 | + | |
| 2730 | + | |
2730 | 2731 | | |
2731 | 2732 | | |
2732 | 2733 | | |
| |||
0 commit comments