feat(snowflake)!: provide transpilation support for HASH_AGG#7284
Open
fivetran-ashashankar wants to merge 2 commits intomainfrom
Open
feat(snowflake)!: provide transpilation support for HASH_AGG#7284fivetran-ashashankar wants to merge 2 commits intomainfrom
fivetran-ashashankar wants to merge 2 commits intomainfrom
Conversation
Contributor
SQLGlot Integration Test ResultsComparing:
By Dialect
Overallmain: 4003 total, 4003 passed (pass rate: 100.0%), sqlglot version: sqlglot:RD-1069223-transpile_HASH_AGG: 4003 total, 4003 passed (pass rate: 100.0%), sqlglot version: Transitions: |
geooo109
reviewed
Mar 13, 2026
| bit_xor = exp.BitwiseXorAgg(this=hash_func) | ||
|
|
||
| # Wrap with COALESCE(..., 0) | ||
| result = exp.Coalesce(this=bit_xor, expressions=[exp.Literal.number(0)]) |
Collaborator
There was a problem hiding this comment.
memory D SELECT HASH(NULL);
┌──────────────────────┐
│ hash(NULL) │
│ uint64 │
├──────────────────────┤
│ 13787848793156543929 │
└──────────────────────┘
HASH computes hash even for NULL. There is no need to apply COALESCE.
Comment on lines
+4094
to
+4097
| # HASH_AGG(col) -> COALESCE(BIT_XOR(HASH(col)), 0) | ||
| # HASH_AGG(col1, col2) -> COALESCE(BIT_XOR(HASH((col1, col2))), 0) | ||
| # HASH_AGG(DISTINCT col) -> COALESCE(BIT_XOR(DISTINCT HASH(col)), 0) | ||
| # HASH_AGG(*) -> COALESCE(BIT_XOR(HASH(*)), 0) |
Collaborator
There was a problem hiding this comment.
What happens if the we use as a winodw function ?
| self.validate_all( | ||
| "SELECT HASH_AGG(DISTINCT col1)", | ||
| write={ | ||
| "duckdb": "SELECT COALESCE(BIT_XOR(DISTINCT HASH(col1)), 0)", |
Collaborator
There was a problem hiding this comment.
This is not the correct approach here. We apply the DISTINCT on the HASH result right ? and not on the column.
Comment on lines
+4117
to
+4126
| if isinstance(cols[0], exp.Star): | ||
| # HASH(*) is not supported in DuckDB - HASH() requires explicit columns | ||
| # Generate a warning and use a placeholder | ||
| self.unsupported( | ||
| "HASH_AGG(*) cannot be fully transpiled to DuckDB. " | ||
| "DuckDB's HASH() function requires explicit columns, not *. " | ||
| "Please rewrite as HASH_AGG(col1, col2, ...) with specific columns." | ||
| ) | ||
| # Fall back to using Star - will cause runtime error but preserves intent | ||
| hash_arg = exp.Star() |
Collaborator
There was a problem hiding this comment.
This isn't complete, you can do:
memory D with t as (select 1 as a, 2 as b) select hash(unpack(columns(t.*))) from t;
┌──────────────────────────┐
│ hash(a := t.a, b := t.b) │
│ uint64 │
├──────────────────────────┤
│ 6530802887144669425 │
│ (6.53 quintillion) │
└──────────────────────────┘
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.