Documentation
¶
Overview ¶
Package mapper translates libpg_query AST nodes to sqld IR proto types.
Index ¶
- func MapColumn(cd *pg.ColumnDef, pos uint32) *irv1.Column
- func MapCompositeType(cs *pg.CompositeTypeStmt) *irv1.CompositeType
- func MapConstraint(c *pg.Constraint, fallbackCol string) *irv1.Constraint
- func MapCreateDomain(ds *pg.CreateDomainStmt) *irv1.DomainType
- func MapCreateEnum(es *pg.CreateEnumStmt) *irv1.EnumType
- func MapCreateFunction(cf *pg.CreateFunctionStmt) (*irv1.Function, *irv1.Procedure)
- func MapCreateRange(rs *pg.CreateRangeStmt) *irv1.RangeType
- func MapCreateSequence(ss *pg.CreateSeqStmt) *irv1.Sequence
- func MapCreateTable(cs *pg.CreateStmt) *irv1.Table
- func MapCreateTrigger(ct *pg.CreateTrigStmt) *irv1.Trigger
- func MapExpr(node *pg.Node, id nodeid.Builder) *irv1.Expr
- func MapIndex(is *pg.IndexStmt) *irv1.Index
- func MapMaterializedView(cta *pg.CreateTableAsStmt) *irv1.MaterializedView
- func MapStatement(node *pg.Node, id nodeid.Builder) *irv1.Statement
- func MapType(tn *pg.TypeName) *irv1.TypeRef
- func MapView(vs *pg.ViewStmt) *irv1.View
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MapColumn ¶
MapColumn converts a pg.ColumnDef to an IR Column (position is 1-based). Returns nil for nil input.
func MapCompositeType ¶
func MapCompositeType(cs *pg.CompositeTypeStmt) *irv1.CompositeType
MapCompositeType converts a pg.CompositeTypeStmt to an IR CompositeType. Returns nil for nil input.
func MapConstraint ¶
func MapConstraint(c *pg.Constraint, fallbackCol string) *irv1.Constraint
MapConstraint converts a pg.Constraint to an IR Constraint. fallbackCol is the column name to use when Keys is empty (column-level constraint). Returns nil for nil input or for constraint types that produce no IR object.
func MapCreateDomain ¶
func MapCreateDomain(ds *pg.CreateDomainStmt) *irv1.DomainType
MapCreateDomain converts a pg.CreateDomainStmt to an IR DomainType. Returns nil for nil input.
func MapCreateEnum ¶
func MapCreateEnum(es *pg.CreateEnumStmt) *irv1.EnumType
MapCreateEnum converts a pg.CreateEnumStmt to an IR EnumType. Returns nil for nil input.
func MapCreateFunction ¶
MapCreateFunction converts a pg.CreateFunctionStmt to either a Function or a Procedure IR object (exactly one will be non-nil). Returns (nil, nil) for nil input.
func MapCreateRange ¶
func MapCreateRange(rs *pg.CreateRangeStmt) *irv1.RangeType
MapCreateRange converts a pg.CreateRangeStmt to an IR RangeType. Returns nil for nil input.
Verified accessor paths (empirically confirmed):
CreateRangeStmt.GetTypeName() []*Node — String_ nodes: [schema, name] or [name]
CreateRangeStmt.GetParams() []*Node — DefElem nodes; all args are TypeName nodes.
"subtype" → arg.GetTypeName() → MapType(tn)
"subtype_opclass" → arg.GetTypeName() → extractPgName(tn) (e.g. "timestamptz_ops")
"collation" → arg.GetTypeName() → extractPgName(tn)
"canonical" → arg.GetTypeName() → extractPgName(tn) (function name)
"subtype_diff" → arg.GetTypeName() → extractPgName(tn) (function name)
"multirange_type_name" → arg.GetTypeName() → bare name (schema qualifier,
if any, dropped). When absent, derived from the
range name via deriveMultirangeName.
func MapCreateSequence ¶
func MapCreateSequence(ss *pg.CreateSeqStmt) *irv1.Sequence
MapCreateSequence converts a pg.CreateSeqStmt to an IR Sequence. Sequence options are parsed best-effort from the DefElem option list. Returns nil for nil input.
func MapCreateTable ¶
func MapCreateTable(cs *pg.CreateStmt) *irv1.Table
MapCreateTable converts a pg.CreateStmt to an IR Table. Returns nil for nil input.
func MapCreateTrigger ¶
func MapCreateTrigger(ct *pg.CreateTrigStmt) *irv1.Trigger
MapCreateTrigger converts a pg.CreateTrigStmt to an IR Trigger. Returns nil for nil input.
Timing bitmask (empirically verified):
BEFORE = 2 (bit 1) AFTER = 0 (no bit set) INSTEAD_OF = 64 (bit 6)
Event bitmask:
INSERT = 4 (bit 2) DELETE = 8 (bit 3) UPDATE = 16 (bit 4) TRUNCATE = 32 (bit 5)
func MapExpr ¶
MapExpr maps a single libpg_query AST Node to an IR Expr, assigning the stable node_id from id. Every recursive child uses a child Builder so ids are unique and deterministic.
Accessor paths used (for Task 8 reference):
ColumnRef : node.GetColumnRef().GetFields() → each *pg.Node:
.GetString_().GetSval() — column/qualifier name
.GetAStar() — wildcard (*)
A_Expr : node.GetAExpr()
.GetName() → []*pg.Node → .GetString_().GetSval() (operator symbol)
.GetLexpr() *pg.Node — left operand (may be nil for unary)
.GetRexpr() *pg.Node — right operand; for IN/BETWEEN it is a List
.GetKind() A_Expr_Kind — AEXPR_OP, AEXPR_IN, AEXPR_LIKE, etc.
BoolExpr : node.GetBoolExpr()
.GetBoolop() BoolExprType — AND_EXPR / OR_EXPR / NOT_EXPR
.GetArgs() []*pg.Node
NullTest : node.GetNullTest()
.GetArg() *pg.Node
.GetNulltesttype() NullTestType — IS_NULL / IS_NOT_NULL
FuncCall : node.GetFuncCall()
.GetFuncname() []*pg.Node → .GetString_().GetSval()
.GetArgs() []*pg.Node
.GetAggStar() bool
.GetAggDistinct() bool
.GetFuncVariadic() bool
CaseExpr : node.GetCaseExpr()
.GetArg() *pg.Node — CASE operand (optional)
.GetArgs() []*pg.Node — each via .GetCaseWhen()
.GetDefresult() *pg.Node — ELSE result
TypeCast : node.GetTypeCast()
.GetArg() *pg.Node
.GetTypeName() *pg.TypeName
SubLink : node.GetSubLink() → raw_sql fallback (TODO task8)
Deparse fallback: wraps the node in a minimal SELECT and calls pg.Deparse. If that fails the raw_sql value is set to "<raw_sql_unavailable>".
The function never panics and never returns nil for a non-nil input.
func MapMaterializedView ¶
func MapMaterializedView(cta *pg.CreateTableAsStmt) *irv1.MaterializedView
MapMaterializedView converts a pg.CreateTableAsStmt to an IR MaterializedView. Returns nil for nil input or if the statement is not a materialized view.
func MapStatement ¶
MapStatement maps a *pg.Node to an IR *irv1.Statement. It never panics; unknown nodes fall through to RawStatement.
func MapType ¶
MapType maps a parsed PostgreSQL TypeName AST node to an IR TypeRef.
AST accessor path:
- Names: tn.GetNames() → each *pg.Node → .GetString_().GetSval()
- Typmods: tn.GetTypmods() → each *pg.Node → .GetAConst().GetIval().GetIval() (int32)
- ArrayBounds: tn.GetArrayBounds() — non-empty means an array type
The function never returns nil and never panics: unknown shapes produce a TypeRef with Kind=SCALAR and PgName set.
Types ¶
This section is empty.