Skip to content

Fix SQL columns for input with a named record type - #7603

Merged
philrz merged 1 commit into
mainfrom
sql-named-record-columns
Nov 4, 2026
Merged

philrz merged 1 commit into
mainfrom
sql-named-record-columns

Conversation

@philrz

@philrz philrz commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Fixes #7468

When the input to a SQL query has a named record type and another record type, the table's columns came from only one of the record types. #7548 fixed the error values in the original repro, but SELECT * still dropped a column, and a reference to the dropped column was a compile error.

With this PR, the table has the columns of both record types:

$ super -f bsup -o t1.bsup -c "type foo={a:int64} values cast({a:1},foo), {b:2}"
$ super -c "SELECT * FROM 't1.bsup'"
{a:1,b:null}
{a:null,b:2}
$ super -c "SELECT b FROM 't1.bsup'"
{b:null}
{b:2}

(Previously {a:1} / {a:null}, and "b" is not a column or table.)

The fuser keeps named types apart, so the fused type of this input is fusion(foo|{b:int64}), a union with two record types, and recordOf() in compiler/semantic/schema.go used only the first. This PR:

  • fuses all of the union's record types in recordOf(), so the columns are the same as for the input without the named type
  • updates the test from fix bug with projected missing under nullish #7548, which expected the dropped column, and adds cases for SELECT b and for two named record types (where tip kept only b)

The fix covers every way SQL gets its input: a file, a pipe into SELECT, a subquery, or a CTE. With -dynamic, column references like SELECT b already worked. Because such a table now has all its columns, a join can newly report an unqualified column as ambiguous, as it already did for the same input without the named type.

The patch was drafted with Claude Code. I reviewed and tested it, and ran it through Claude Code's /code-review high.

The SQL table for input whose fused type is a union with more than one
record type took its columns from only the first record type.  The
fuser keeps named types apart, so this happens whenever the input has a
named record type and another record type, e.g., the fused type of
foo={a:int64} and {b:int64} is fusion(foo|{b:int64}).  SELECT * then
dropped a column, and a reference to it was a compile error.  Fuse the
union's record types instead, and update the test from #7548, which
expected the dropped column.

Fixes #7468

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@mccanne mccanne left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This stuff is a bit fragile, but step in the right direction.

@philrz
philrz merged commit 05d6e80 into main Nov 4, 2026
2 checks passed
@philrz
philrz deleted the sql-named-record-columns branch November 4, 2026 20:46
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.

Single column returned on "SELECT *" when named type is present

2 participants