Skip to content

fix: count, average and NULLIF the way Snowflake records them - #100

Closed
kvlonge wants to merge 2 commits into
mainfrom
fix/count-star
Closed

kvlonge wants to merge 2 commits into
mainfrom
fix/count-star

Conversation

@kvlonge

@kvlonge kvlonge commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Why

Replaying recorded Snowflake results showed three aggregate conversions that disagree with Snowflake:

  • COUNT(t.) and COUNT( EXCLUDE ...) counted every row.
  • AVG(DISTINCT) of NUMBER(38,0) was typed NUMBER(38,6).
  • NULLIF(NULL, x) took the type of x.

Changes

  • COUNT of a qualified or EXCLUDE star counts the rows whose selected columns are all non-NULL, as recorded. DISTINCT, a VARIANT column, or a star that selects no column is refused. Only a bare * still counts every row.
  • AVG(DISTINCT) of NUMBER(38,0) is NUMBER(38,3), as recorded; other input types refuse until they are recorded.
  • NULLIF with a NULL first argument is a NULL typed VARCHAR, as recorded.
  • The COUNT and NULLIF rule conditions in the catalogue are updated.

Verification

  • The recorded translation cases for COUNT, AVG and NULLIF were replayed on DuckDB. COUNT t004/t005, AVG t005 and NULLIF t003 now match. COUNT(* ILIKE) stays refused, because star ILIKE has no rule yet.
  • No repository case regressed.
  • New CLI value tests cover COUNT(input.) = 3 beside COUNT() = 5, COUNT(* EXCLUDE b) = 4, AVG(DISTINCT) = 1.500, and COALESCE(NULLIF(NULL, 1), 'none') = 'none'.

COUNT(input.*) and COUNT(* EXCLUDE ...) were read as COUNT(*), counting
every row. Snowflake counts the rows whose selected columns are all
non-NULL, as the recorded receipts show. DISTINCT, a VARIANT column, and
a star that selects no column are refused.
AVG(DISTINCT) of NUMBER(38,0) is NUMBER(38,3), not the NUMBER(38,6) of a
plain AVG; other input types refuse until recorded. NULLIF with a NULL
first argument is a NULL typed VARCHAR, not the second argument's type.
kvlonge added a commit that referenced this pull request Nov 6, 2026

kvlonge commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

Closing: SQLQuack lands through local-gate trains, not PR merges (D94), so open PRs only add clutter (D628/D630). The branch is kept. Any work here that isn't on main yet is tracked by the train owner and lands through a train.

@kvlonge kvlonge closed this Nov 8, 2026
@kvlonge
kvlonge deleted the fix/count-star branch November 9, 2026 21:31
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.

1 participant