Skip to content

feat: ANY macro arguments, macro return types in contract checks and per-kind macro folder counts - #1240

Merged
kvlonge merged 11 commits into
mainfrom
feat/sql-macro-gaps
Oct 23, 2026
Merged

kvlonge merged 11 commits into
mainfrom
feat/sql-macro-gaps

Conversation

@kvlonge

@kvlonge kvlonge commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Why

Converting Python macros to SQL macros showed three gaps: an argument the body only casts had to be VARIANT to take numbers and strings; a call declared returns VARCHAR still needed an outer CAST to satisfy a VARCHAR contract column (K003, SQBRCONTRACT105); and the declaration layout Rules counted a macro folder's python/ and sql/ subtrees as one container, so 6 + 7 files read as 13.

Changes

  • ANY argument type: any scalar expression, no type check. Lists and relations fail with P017; ANY CONST, LIST ANY and SET ANY fail with P015. DEFAULT is allowed. A runtime ANY where SQL needs a literal fails with P023.
  • A select item that is one expression macro call under an alias, in the main query or a top-level CTE, including each branch of their set operation, takes the macro's returns type when the inferred type is unknown or exactly that type. Any other known type stands and K002 reports it. The type flows to contracts, SQBRCONTRACT105 and downstream models. Compiled SQL is unchanged; the cache key includes these types, and cache hits skip the retyping.
  • SQBRDECLARATION302–306 treat python/ and sql/ under a macro folder as separate containers. 306 tells SQL macro files to move into a subfolder of sql/, keeping their names.
  • Docs: ANY versus VARIANT, call types from returns, per-kind folder counts.

Verification

  • Rust unit tests: ANY parsing, declared output types, branches and names, cache hits keeping the type, kind-folder layout.
  • E2E: ANY builds and misuse; returns satisfying contracts with no K003/SQBRCONTRACT105 in the main query, CTEs, joins and UNION ALL branches, cold and warm; TIME, array, wider text, decimal and timestamptz bodies still report K002; a conflicting union sibling still reports; unusual outer queries compile; layout Rules.
  • make test, make check-ci, make compiler-differential (no golden changes) and the hygiene scan pass.

@kvlonge
kvlonge enabled auto-merge (squash) October 23, 2026 20:07
@kvlonge
kvlonge merged commit 8b9f207 into main Oct 23, 2026
46 checks passed
@kvlonge
kvlonge deleted the feat/sql-macro-gaps branch October 23, 2026 20:39
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