feat(agg): BIT/BOOL aggregates + FIRST_VALUE/LAST_VALUE/NTH_VALUE window helpers - #167
Merged
Merged
Conversation
…dow helpers Adds five aggregate builders (bitAnd, bitOr, bitXor, boolAnd, boolOr) and three window-value builders (firstValue, lastValue, nthValue) with per-dialect gating via new feature flags BIT_AGGREGATES, BIT_XOR_AGG, BOOL_AGGREGATES, NTH_VALUE_FN. Printer overrides refuse the unsupported combos (MSSQL has no BIT_*/BOOL_*/NTH_VALUE; MySQL has no BOOL_*; SQLite has no BIT_XOR; PG matrix excludes BIT_XOR pending per-version gating). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
productdevbook
force-pushed
the
feat/bit-bool-window-value-builders
branch
from
May 19, 2026 11:33
88e966e to
4453944
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.
Summary
Adds eight typed builders for SQL aggregate and window functions that were missing from the public surface:
bitAnd,bitOr,bitXor(PG/MySQL/SQLite 3.44+ for AND/OR; MySQL-only for XOR)boolAnd,boolOr(PG and SQLite 3.45+; MySQL/MSSQL refuse — workaround isMIN/MAX(CAST(b AS int)))firstValue,lastValue,nthValue(window-only — already inWINDOW_ONLY_FUNCTIONS; previously callers had to reach forsqlFn)Per-dialect gating goes through four new feature flags (
BIT_AGGREGATES,BIT_XOR_AGG,BOOL_AGGREGATES,NTH_VALUE_FN). Printer overrides surface the matrix at compile time so unsupported combos throwUnsupportedDialectFeatureErrorinstead of leaking through to a runtime "no such function" parse error.PG: also gates
BIT_XOR(PG 14+ does ship it natively, but older PG versions surface a UDF-lookup error — PG 14+ users can bypass viasqlFn("BIT_XOR", expr)).Files
src/builder/aggregate.ts— 8 new builders, all JSDoc-annotated with the dialect matrix and theLAST_VALUEframe-default footgunsrc/dialect/features.ts— 4 new feature entriessrc/printer/function-tables.ts— adds BIT_/BOOL_ toSTANDARD_FUNCTIONSsrc/printer/{pg,mysql,sqlite,mssql}.ts— gating overridessrc/builder/eb.ts,src/index.ts,src/ns/win.ts— re-exports (window helpers also mirrored into thewinnamespace alongsidelag/lead)docs/recipes.md— new subsections for bitwise/boolean aggregates and window-value functionsTest plan
pnpm fmt && pnpm lint && pnpm typecheck && pnpm vitest run— 2458 passedtest/builder/bit-bool-aggregates.test.ts— SQL output across all four dialects, refusal checks, PGlite roundtrip verifying the actual fold resulttest/builder/window-value-fns.test.ts— SQL output, OVER-required check, MSSQL NTH_VALUE refusal,winnamespace mirror, PGlite roundtrip for opening/closing/Nth valuesTradeoffs
BIT_XOR_AGGlists only MySQL even though PG 14+ has the function. sumak has no per-version gating today; the safe default is "refuse" with ansqlFnescape hatch documented in the JSDoc. Following the same pattern as the trigonometry feature flag.BOOL_AND/BOOL_ORcould have a portable rewrite toMIN(CAST(b AS int))on MySQL/MSSQL but the result type and NULL semantics differ subtly (boolean vs int). Refuse + document the workaround keeps the builder surface honest.firstValue/lastValue/nthValueare documented as window-only and the printer already enforces it via the existingWINDOW_ONLY_FUNCTIONSallowlist — no new gating needed for the OVER-required check.🤖 Generated with Claude Code