feat(snowflake): transpile CORR with NaN-->NULL#6619
Merged
Conversation
Contributor
SQLGlot Integration Test ResultsComparing:
By Dialect
Overallmain: 5697 total, 5428 passed (pass rate: 95.3%), sqlglot version: sqlglot:trey/corr-sf-duckdb: 5697 total, 5428 passed (pass rate: 95.3%), sqlglot version: Difference: No change |
geooo109
reviewed
Dec 23, 2025
65a57ea to
0d175bc
Compare
geooo109
reviewed
Dec 30, 2025
georgesittas
approved these changes
Jan 7, 2026
Collaborator
|
@treysp let me know if there's anything blocking this. |
0d175bc to
2323b2d
Compare
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.
CORRperforms an internal calculation that hasVARIANCE([column])in the denominator. When that occurs, Snowflake returnsNULLwhile DuckDB returnsNaN.To replicate the Snowflake's
NULLin DuckDB, we must wrap theCORRcall inISNAN:Naively wrapping in
ISNANgenerates invalid syntax for windowed and filtered function calls.Therefore, we add special DuckDB generator handling to route
exp.Window,exp.Window(exp.Filter), andexp.Filterto acorr_sqlmethod designed to accept window and filtered expressions.Examples:
SELECT CORR(a, b) OVER (PARTITION BY c)SELECT CASE WHEN ISNAN(CORR(a, b) OVER (PARTITION BY c)) THEN NULL ELSE CORR(a, b) OVER (PARTITION BY c) ENDSELECT CORR(a, b) FILTER (WHERE c > 0)SELECT CASE WHEN ISNAN(CORR(a, b) FILTER(WHERE c > 0)) THEN NULL ELSE CORR(a, b) FILTER(WHERE c > 0) ENDSELECT CORR(a, b) FILTER (WHERE c > 0) OVER (PARTITION BY d)SELECT CASE WHEN ISNAN(CORR(a, b) FILTER(WHERE c > 0) OVER (PARTITION BY d)) THEN NULL ELSE CORR(a, b) FILTER(WHERE c > 0) OVER (PARTITION BY d) END