Repository navigation
D267: statistics aggregates, ADD_MONTHS, MONTHS_BETWEEN and NVL2 from receipts - #127
Merged
Merged
Conversation
23 cases appended to existing files, for receipts before converting: - STDDEV, STDDEV_SAMP, STDDEV_POP, VARIANCE, VAR_SAMP, VAR_POP, VARIANCE_POP, CORR, COVAR_SAMP, COVAR_POP: values near 1e9 with a small spread, and NUMBER(10,2) inputs with SYSTEM$TYPEOF. - ADD_MONTHS: negative counts from month ends, day 31 into shorter months, across a year. - MONTHS_BETWEEN: month ends and equal days with times of day, and a long negative span.
Recorded from wip/d267-edges 148695c (23 cases, utc-v1, no failures).
NVL2(a, b, c) of exactly three arguments, a not semi-structured, converts to CASE WHEN a IS NOT NULL THEN b ELSE c END, its branches unified without reading text, as the recorded NUMBER, FLOAT, text and untyped NULL cases show. Text beside another type, a VARIANT first argument and any other arity refuse.
…sqlquack into fix/d267-functions
The receipts show VARIANCE of a NUMBER is a rounded NUMBER and STDDEV the square root of that rounded value; these cases pin the rounding at an exact tie, the scale rule beyond scales 0 and 2, and how a FLOAT variance near 1e9 cancels.
Recorded from fix/d267-functions b204059 (3 cases, utc-v1, no failures).
# Conflicts: # crates/sqlquack/src/analysis/tests/test_coverage_batch.rs
conversion/constants.rs reached 2,002 lines with main merged in. The TO_CHAR format elements, month-name adjacency, bare FF and separators now live in text_formats with strftime_pattern and clock_format, which read them. No behaviour change.
VARIANCE, VAR_SAMP, VAR_POP and VARIANCE_POP of a NUMBER of scale s are the exact (n*sum(x^2) - sum(x)^2) / (n(n-1)), or / n^2, rounded half up to NUMBER(38, min(6 + 2s, 12)); STDDEV, STDDEV_SAMP and STDDEV_POP are the FLOAT square root of that rounded variance, as recorded bit for bit. FLOAT and text use the same formula in doubles; COVAR_SAMP and COVAR_POP use (sum(xy) - sum(x)sum(y)/n) / d over complete pairs. Both rely on float_sum_order, whose guard raises for the large-mean FLOAT cases, now declared. VARIANCE(DISTINCT) and DISTINCT over an ordered window refuse, as Snowflake rejects them. CORR still refuses: no formula reproduces its NUMBER(10,2) receipt.
ADD_MONTHS moves by DATEADD of the months rounded half away from zero, and a month's last day on to the last day of the month it lands in, keeping the time of day; a TIMESTAMP_TZ moves on its wall clock where its offset is known. MONTHS_BETWEEN of DATEs and TIMESTAMP_NTZs is the whole months where the days match or both are month ends, else the months plus the day and clock difference over 31 days, exact and rounded at six decimals into NUMBER(27,6). The statistics constants move beside their only reader.
Nine forms move from refused to matching: NVL2, MONTHS_BETWEEN, VAR_SAMP and its window form, VARIANCE_POP, STDDEV_SAMP, STDDEV_POP, and COVAR_SAMP and COVAR_POP over windows. Nothing regresses.
kvlonge
added a commit
that referenced
this pull request
Nov 6, 2026
# Conflicts: # coverage/translation/results-baseline.json
…th and NVL2 rules
Contributor
Author
|
Landing gate (D301) on c70e255 (fd1c3b9 + main de14f81; the only conflict, results-baseline.json, taken from main):
|
kvlonge
marked this pull request as ready for review
November 6, 2026 21:37
This was referenced Nov 6, 2026
Closed
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.
Decision D267 (function rules from the website lane's corpus round 4): the statistics aggregates, ADD_MONTHS/MONTHS_BETWEEN and NVL2, each converted only as the recorded receipts show. Evidence comes from A's e510d1a (23 edge cases) and a586f83 (variance ties, scales, large-mean FLOAT).
Rules
rule.nvl2anot semi-structuredrule.variancerule.variance_floatfloat_sum_orderguard.rule.covariancefloat_sum_order.rule.add_monthsrule.months_betweenWhat still refuses, on purpose
refusedand fails closed.SYSTEM$TYPEOFdecimal cases (t007/t008): refused by the existing TYPEOF guard, not by these rules.Declared divergences
float_sum_order. Their sums of products near 1e18 cannot be proven order-exact, so the converted SQL raises loudly instead of guessing Snowflake's cancellation.numeric_range(a NUMBER total beyond 38 digits raises) andfloat_sum_order; ADD_MONTHS joinstimestamp_range, as DATEADD already does.Refactors (no behaviour change)
conversion/constants.rswas at 2,002 lines after main merged in. The TO_CHAR format-element table moved into atext_formatsdomain together withstrftime_pattern/clock_format, its readers. The statistics constants sit beside their only reader.Measured
verifyon this head (current main merged in): 11,826 cases, 0 failed; 226/226 rules verified. Before this change the D267 cases refused; now +150 passed, +3 declared divergences.Draft. GitHub Actions is blocked by billing; the local D94 gate counts.