Repository navigation
feat(sql-macros)!: relation slots with COLUMNS groups, replacing COLUMN OF - #1254
Merged
Merged
Conversation
…MN OF A RELATION type declares everything a macro reads from it as slots: typed single columns and untyped COLUMNS groups the caller fills. Bodies read a slot as alias.@rel.slot, or plainly as @rel.slot: a plain group read always stands as bare column names, and a plain single-slot read always reads the slot's column through the passed relation. A plain group read inside a subquery fails when a relation of that subquery has one of its columns, or its columns are unknown, since the bare names could bind there. Calls map slots with rel.slot := column or rel.slot := (columns). Group positions, mappings, overlaps, types and name clashes are checked with exact messages. BREAKING CHANGE: COLUMN OF SQL macro arguments are removed; use relation slots.
…r column A mapped slot reads whatever column the call passes, so alias.@rel.slot AS slot is no self-alias. Aliased reads neutralize whole and bare reads hide the slot name.
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.
Why
A SQL macro meant for several grains had to be written once per grain, and
COLUMN OFsplit oneinput across arguments that had to agree with it.
Changes
RELATION (...)declares slots: typed single columns and untypedCOLUMNSgroups.rel.slot := columnorrel.slot := (a, b). Groups must be mapped.alias.@rel.slotreads through the alias; a group's prefix applies to every column.two joined relations share fails with
B003, as hand-written SQL does.USING (...)are always bare. Forwarded slots keep their inner kind.LATERAL) fails withP017when arelation there other than the passed one has one of its columns, or its columns are unknown.
ASoutside expression subqueries,P018clashes with defined or bare columns) have exact messages.
COLUMN OFis removed; use relation slots.BREAKING CHANGE:
COLUMN OFSQL macro arguments are removed; use relation slots.Verification
@weekly.keysplainly inPARTITION BY, later CTEs andGROUP BYcompiles at two grains to SQL byte-identical to two per-grain macros, with the same rows.
Capture,
LATERAL, forwarding,USING, subqueryASand clash cases, ambiguous joins,lineage, Rules, typing,
--since.make test,make check-ci,fensu checkand the hygiene scan pass.