constructsql

package
v0.0.20 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package constructsql is the leeway constructor family of ADR-0181 §SD2: LW_PLAIN, LW_TV, LW_TV_MEMB and LW_TV_SUPPORT as the client-side nanopass expansion pass LwConstructExpand. A constructor call wraps an expression and mints the physical leeway column name for it, expanding into `<expr> AS "<physical name>"` before the statement ships — the write-direction dual of column handles (ADR-0116): a handle resolves an existing column, a constructor mints a new one.

Nothing is installed server-side. The expanded output is plain SQL any endpoint runs; an unexpanded call reaching a raw server fails loudly as an unknown function. Name composition is lwsql's spec→name seam (§SD6), so the spec tokens mean the same thing here, in `leeway ddl compose`, and in tests.

Index

Constants

View Source
const (
	NameComponent       = "LW_COMPONENT"
	NameComponentFilter = "LW_COMPONENT_FILTER"
)

The component family's SQL-visible names.

View Source
const (
	NamePlain      = "LW_PLAIN"
	NameTagged     = "LW_TV"
	NameMembership = "LW_TV_MEMB"
	NameSupport    = "LW_TV_SUPPORT"
)

The constructor names (LW_ + UPPER_SNAKE per the repo-wide namespace rule). Matching in SQL is case- and quoting-insensitive.

View Source
const (
	NameGet     = "LW_GET"
	NameGetNull = "LW_GET_NULL"
	NameGetList = "LW_GET_LIST"

	// NameSel and NameSelAttrs are the selector half: they return index
	// selectors rather than values, so the caller's own arrayMap /
	// arrayFilter / LW_CO_GATHER does the reading.
	//
	// This is the "argwhere + gather" plan the array-idioms how-to
	// describes. The pack already ships the gather half (LW_CO_GATHER); the
	// argwhere half is what these mint, against a section and a membership
	// instead of a physical lane.
	NameSel      = "LW_SEL"
	NameSelAttrs = "LW_SEL_ATTRS"
)

The extraction names (LW_ + UPPER_SNAKE per the repo-wide namespace rule). Matching in SQL is case- and quoting-insensitive.

View Source
const ComponentPassName = "LwComponentExpand"

ComponentPassName names the expansion pass in the registry and in errors.

View Source
const ExtractPassName = "LwExtractExpand"

ExtractPassName is the registered nanopass name of the extraction pass.

View Source
const PassName = "LwConstructExpand"

PassName is the registered nanopass name of the expansion pass.

View Source
const ShapeCheckPassName = "LwShapeCheck"

ShapeCheckPassName is the registered nanopass name of the shape check.

View Source
const ShapeCheckTargetPassName = "LwShapeCheckTarget"

ShapeCheckTargetPassName is the registered nanopass name of the target-aware shape check.

View Source
const TargetPassName = "LwConstructExpandTarget"

TargetPassName is the registered nanopass name of the target-adopting constructor expansion. It runs INSTEAD of the unbound LwConstructExpand on hosts that carry a schema binding (ordered just before it; whichever runs first consumes every constructor call and the other's marker scan finds nothing).

Variables

ExpandPass is LwConstructExpand over the fresh-table default segments (':'-separated, row config 0, no groups) — the standard-set registration. Idempotent by construction: expansion leaves no constructor call behind, and a nested or misplaced call is an error, never a partial rewrite.

View Source
var ShapeCheckPass = nanopass.LiftBodyPass(ShapeCheckPassName, shapeCheckImpl, nanopass.PassProperties{
	Idempotent: true,
	Reads:      nanopass.RegionBody,
	Writes:     nanopass.RegionBody,
})

ShapeCheckPass is LwShapeCheck as an opt-in pass.

Functions

func CheckOutputColumns

func CheckOutputColumns(names []string) (err error)

CheckOutputColumns is the name-level shape check over one output column set: parse, discover, validate, and enforce per-channel section completeness, section-segment agreement, and co-section-group wholeness.

func ComponentExpandPass

func ComponentExpandPass(comps ComponentSourceI, defaultDatabase string) nanopass.Pass

ComponentExpandPass is LwComponentExpand bound to a component source.

Idempotent by construction: expansion leaves no LW_COMPONENT call behind, and an unresolvable one is an error rather than a partial rewrite.

defaultDatabase resolves an unqualified table reference in the statement's FROM against the kind's bound table, the same way the extraction pass and the selection-conditions pass take one.

func ComponentExpansionDependencies

func ComponentExpansionDependencies() (names []string)

ComponentExpansionDependencies are the server-side functions an expanded LW_COMPONENT may call. LW_COMPONENT_FILTER calls none of them.

func ExpandPassWithSegments

func ExpandPassWithSegments(seg lwsql.TableSegments) nanopass.Pass

ExpandPassWithSegments is LwConstructExpand with the table-level naming segments chosen — the target-adoption variant for hosts that know the statement's destination table (adopt its separator and row config via lwsql.Resolver.TableSegments, the way NameConditions does).

func ExpandPassWithTargetAdoption

func ExpandPassWithTargetAdoption(schema TargetSchemaI, defaultDatabase string) nanopass.Pass

ExpandPassWithTargetAdoption is LwConstructExpand bound to a schema: a statement that is not an INSERT, or whose target the schema does not know, expands exactly as the unbound pass does; an INSERT with a resolved target mints in that target's terms.

func ExtractExpandPass

func ExtractExpandPass(lanes LaneSourceI, defaultDatabase string) nanopass.Pass

ExtractExpandPass is LwExtractExpand bound to a schema. Idempotent by construction: expansion leaves no LW_GET call behind, and an unresolvable one is an error, never a partial rewrite.

defaultDatabase resolves unqualified table references, the same way the selection-conditions pass takes one.

func ExtractExpandPassWithIds

func ExtractExpandPassWithIds(lanes LaneSourceI, ids MembershipIdsI, defaultDatabase string) nanopass.Pass

ExtractExpandPassWithIds is ExtractExpandPass with a membership-id lookup, so a ref channel takes a NAME instead of a registry id (ADR-0171 §SD4).

Resolution happens at expansion time, client-side, which keeps the emitted SQL carrying constants — the property ADR-0066 chose deliberately over a query-time dictGet, and the reason this is a binding rather than a join.

func ExtractExpansionDependencies

func ExtractExpansionDependencies() (names []string)

ExtractExpansionDependencies are the server-side functions an expanded extraction may call (ADR-0174 §SD6). The panel marks the family against them, so "installed client-side" does not read as "works everywhere".

The fast form calls fewer of these, and which form a given call takes depends on the section it reads, so the list is what an expansion MAY need rather than what any one expansion does need.

func HasAuthoringMarker

func HasAuthoringMarker(sql string) bool

HasAuthoringMarker is the cheap pre-parse scan (ADR-0181 §SD7): standard-set registration must cost approximately nothing on the overwhelming majority of queries that carry no constructor call. False positives (the substring inside a string literal or comment) merely cost the parse the pass would otherwise always run; false negatives are impossible because every call spelling — quoted included — contains one of the two substrings.

func HasComponentMarker

func HasComponentMarker(sql string) bool

HasComponentMarker reports whether sql could contain a component call. Both names share the LW_COMPONENT prefix, so one check covers the family.

func HasExtractMarker

func HasExtractMarker(sql string) bool

HasExtractMarker is the cheap pre-parse scan (ADR-0181 §SD7). Every spelling of every family member contains "lw_get" or "lw_sel", quoted included — LW_SEL_ATTRS is caught by the LW_SEL prefix.

func ShapeCheckPassWithTarget

func ShapeCheckPassWithTarget(columns passes.SchemaProviderI, defaultDatabase string) nanopass.Pass

ShapeCheckPassWithTarget (ADR-0181 §SD8 M2) is the INSERT half of the transform contract's validation, opt-in like LwShapeCheck: under a wrapper it verifies the SELECT's output column names against the destination's physical names — the vertical-subset rule applied to a concrete table — and, when a column list is present, that the list and the output correspond position by position. Names compare fold-equivalent (case and separator insensitive), so an adopted mint, a pass-through physical, and a hand-spelled variant all land on the column they mean; a true miss errors naming both sides. A statement without a wrapper falls back to the closure check LwShapeCheck performs.

Types

type ComponentSourceI

type ComponentSourceI interface {
	Lookup(kind string) (b componentsql.Binding, ok bool)
	Kinds() (kinds []string)
}

ComponentSourceI resolves a component kind to its artefacts. github.com/stergiotis/boxer/public/semistructured/leeway/marshall/clickhouse/componentsql.Registry satisfies it; the pass takes the interface so a host can scope a registry to one query without building a second global.

type Function

type Function struct {
	Name   string
	Params []sqlvocab.Param
	Doc    string
}

Function is one constructor family entry, declared as data for the vocabulary panel (ADR-0174 §SD3): the spelling a query uses, the parameters in order, and one line on what it does.

func ComponentFunctions

func ComponentFunctions() (fns []Function)

ComponentFunctions is the component family, for the vocabulary panel.

The two names differ in what they need installed, which is the distinction ADR-0189 §SD8 asks the panel to show: LW_COMPONENT_FILTER expands to ClickHouse built-ins and runs anywhere, while LW_COMPONENT expands to the named-tuple projection, which calls the read-back helper family.

func ExtractFunctions

func ExtractFunctions() (fns []Function)

ExtractFunctions returns the extraction family, declared as data for the vocabulary panel (ADR-0174 §SD3).

Client-expanded like the constructors, but with a server-side dependency they do not have: the expansion calls the read-back helper family, so a server without it fails on the expansion rather than on the name.

func Functions

func Functions() (fns []Function)

Functions returns the constructor family. Every entry is client-only: expanded by LwConstructExpand, never installed server-side.

type LaneSourceI

type LaneSourceI interface {
	ExtractLanesFor(dbName string, tableName string, section string) (lanes lwsql.ExtractLanes, ok bool)
	Sections(dbName string, tableName string) (names []string)
}

LaneSourceI is what the pass needs of a schema: which sections a table carries, and what a section's lanes are. lwsql.Resolver implements it.

type MembershipIdsI

type MembershipIdsI interface {
	LookupMembership(name string) (id uint64, err error)
}

MembershipIdsI resolves a membership name to the uint64 a ref lane carries (ADR-0171 §SD4). One method, spelled exactly as marshallreflect.LookupI and readback.IdLookup spell it, so any registry that satisfies those satisfies this.

Optional. Without it a ref channel still takes an id, which is what it took before §SD4 — the pass degrades to the older, wordier form rather than refusing to run.

type TargetSchemaI

type TargetSchemaI interface {
	LaneSourceI
	TableSegments(dbName string, tableName string) (seg lwsql.TableSegments, ok bool)
	Resolve(dbName string, tableName string, handle string) passes.ResolveResult
}

TargetSchemaI is what target adoption needs of a schema: the fold-tolerant section lookup extraction already uses, the handle path for plain and support columns, and the table-level naming segments for the compose fallback. *lwsql.Resolver implements all three, so a host bound for handle resolution is bound for adoption too.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL