Skip to content

fix: by-name column access returns column1/column2 for joins and compounds (#709) - #720

Open
dpsiderius wants to merge 1 commit into
fix/707-sqlite-master-selectfrom
fix/709-result-column-names
Open

dpsiderius wants to merge 1 commit into
fix/707-sqlite-master-selectfrom
fix/709-result-column-names

Conversation

@dpsiderius

Copy link
Copy Markdown
Contributor

Stacked on #707 (fix/707-sqlite-master-select) — merge that first.

What

output_column_names_joined (src/codegen/select/order_by.rs)
generalizes SQLite's naming rule — alias if present, else the bare
column name, else the expression text, with a compound taking its names
from the left-most arm — across joined tables' */table.* expansion.
Wired into derive_headers; the select.compound.is_empty()
restriction that scoped this to single-table selects is gone (the
leftmost-arm rule already existed internally).

Before/after

SELECT a.x, b.y FROM a JOIN b ON ...   -- before: column1, column2
                                         -- after:  x, y
SELECT x FROM a UNION SELECT y FROM b  -- before: column1
                                         -- after:  x  (leftmost arm)

Not done, explicitly out of scope: src/api.rs/Row::get_by_name
(PR #705 unmerged) — noted here for whoever lands #705 to delegate to
output_column_names_joined, and to invert/add
tests/unit/api_statement_test.rs::joins_and_compounds_report_positional_column_names.
Spec 013 Req 3's "scoped to single-table selects" sentence should be
removed in that same follow-up; left untouched here.

Known pre-existing gap flagged, not fixed: an unaliased computed
expression (a+1) still falls back to columnN instead of the oracle's
expression-text rendering — true in both the old single-table and new
joined paths, since there is no expr-to-SQL printer. Not in this ticket's
acceptance criteria.

Test plan

  • tests/corpus/result_column_names_test.rs — 9 oracle-diffed shapes:
    2/3-table join, UNION, UNION ALL, EXCEPT, expression columns, t.*
    expansion, subquery-in-FROM, alias, qualified name, duplicate names.
  • Inverted tests/unit/repl_dot_commands.rs::select_with_join_falls_back_to_positional_headersselect_with_join_reports_real_column_names.
  • make test, make lint, make test-corpus, make check-mvl-limit, make check-mod-files, make assurance all pass.

Refs: 013/Req-3, 013/Req-6, #705
Closes #709

spend: matched estimate

…#709)

output_column_names_joined (src/codegen/select/order_by.rs) generalizes
the existing single-table "alias, else bare column name, else columnN"
rule to a joined FROM: a bare column reference already names itself
independent of its table qualifier (SELECT a.x carries name: "x"
regardless of the "a." prefix), so the only real gap was */table.*
expansion, which now draws from each joined table's own schema in
FROM-clause order. A compound SELECT already had the right machinery
internally (compile_select_compound resolves its own trailing ORDER BY
against the leftmost arm's names) — it just wasn't reachable from
header derivation, which is now unconditional instead of requiring
select.compound.is_empty().

derive_headers (src/bin/sqlite-rs/repl.rs) wires both cases in; the CLI
test that asserted the old column1/column2 fallback for a join
(tests/unit/repl_dot_commands.rs::select_with_join_falls_back_to_positional_headers)
is inverted to assert the real names instead.

Known pre-existing gap, not introduced or widened here: an unaliased
*computed* expression (`a + 1`) still falls back to columnN rather than
the oracle's own expression-text rendering, in both the single-table
and joined paths alike — this crate has no expression-to-SQL-text
printer yet. Not covered by this ticket's acceptance criteria.

Not done (api.rs is PR #705, unmerged, out of scope here):
- Row::get_by_name/result_column_names in the embedding API itself —
  once #705 lands, its result_column_names should delegate to
  output_column_names/output_column_names_joined rather than
  reimplementing the rule, and
  tests/unit/api_statement_test.rs::joins_and_compounds_report_positional_column_names
  (named in this ticket's acceptance criteria, but not present on this
  branch) should be added/inverted the same way
  repl_dot_commands.rs's test was here.
- Spec 013 Requirement 3's "scoped to single-table selects" sentence:
  left in place, since spec 013's text lives on the unmerged branch too
  and touching it here isn't safe — flagged for removal in the same PR
  that merges #705.

spend: roughly matched the medium estimate.
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.

bug: by-name column access returns column1/column2 for joins and compounds

1 participant