Documentation
¶
Overview ¶
Package core defines the shared language of the LeapSQL system.
This package contains:
- Domain entities (Model, DialectConfig, Run, etc.)
- Service interfaces (Adapter, Store)
- Configuration types (ProjectConfig, TargetConfig)
- Lint types (Severity, RuleInfo)
- Base AST interface (Node)
The Golden Rule: pkg/core imports ONLY pkg/token and stdlib. All other packages depend on core, not the reverse.
Index ¶
- Constants
- Variables
- func AllKnownClauses() map[token.TokenType]string
- func IsKnownClause(t token.TokenType) (string, bool)
- func RecordClause(t token.TokenType, name string)
- type AcceptedValuesConfig
- type Adapter
- type AdapterConfig
- type BetweenExpr
- type BinaryExpr
- type CTE
- type CaseExpr
- type CastExpr
- type ClauseDef
- type ClauseSlot
- type Column
- type ColumnInfo
- type ColumnRef
- type Conditional
- type Dependency
- type DerivedTable
- type Dialect
- func (d *Dialect) ClauseDefFor(t token.TokenType) (ClauseDef, bool)
- func (d *Dialect) ClauseSequence() []token.TokenType
- func (d *Dialect) Config() *DialectConfig
- func (d *Dialect) FromItemHandler(t token.TokenType) any
- func (d *Dialect) FunctionLineageTypeOf(name string) FunctionLineageType
- func (d *Dialect) GetDoc(name string) (FunctionDoc, bool)
- func (d *Dialect) GetName() string
- func (d *Dialect) InfixHandler(t token.TokenType) any
- func (d *Dialect) IsAggregate(name string) bool
- func (d *Dialect) IsClauseToken(t token.TokenType) bool
- func (d *Dialect) IsFromItemToken(t token.TokenType) bool
- func (d *Dialect) IsGenerator(name string) bool
- func (d *Dialect) IsJoinTypeToken(t token.TokenType) bool
- func (d *Dialect) IsReservedWord(word string) bool
- func (d *Dialect) IsStarModifierToken(t token.TokenType) bool
- func (d *Dialect) IsTableFunction(name string) bool
- func (d *Dialect) IsWindow(name string) bool
- func (d *Dialect) JoinTypeDefFor(t token.TokenType) (JoinTypeDef, bool)
- func (d *Dialect) LookupKeyword(name string) (token.TokenType, bool)
- func (d *Dialect) NormalizeName(name string) string
- func (d *Dialect) Precedence(t token.TokenType) int
- func (d *Dialect) PrefixHandler(t token.TokenType) any
- func (d *Dialect) QuoteIdentifier(name string) string
- func (d *Dialect) QuoteIdentifierIfNeeded(name string) string
- func (d *Dialect) StarModifierHandler(t token.TokenType) any
- func (d *Dialect) SymbolsMap() map[string]token.TokenType
- type DialectConfig
- type Environment
- type ExcludeModifier
- type ExistsExpr
- type Expr
- type FetchClause
- type FrameBound
- type FrameBoundType
- type FrameSpec
- type FrameType
- type FromClause
- type FuncCall
- type FunctionDoc
- type FunctionLineageType
- type IdentifierConfig
- type InExpr
- type IndexExpr
- type IsBoolExpr
- type IsNullExpr
- type Join
- type JoinType
- type JoinTypeDef
- type LambdaExpr
- type LateralTable
- type LikeExpr
- type LintConfig
- type ListLiteral
- type Literal
- type LiteralType
- type MacroExpr
- type MacroFunction
- type MacroNamespace
- type MacroTable
- type Model
- type ModelRun
- type ModelRunStatus
- type ModelRunWithInfo
- type ModelType
- type Node
- type NodeInfo
- type NormalizationStrategy
- type OperatorDef
- type OrderByItem
- type ParenExpr
- type PersistedModel
- type PivotAggregate
- type PivotInValue
- type PivotTable
- type PlaceholderStyle
- type ProjectConfig
- type ProjectHealthConfig
- type ProjectHealthThresholds
- type QueryableStore
- type RenameItem
- type RenameModifier
- type ReplaceItem
- type ReplaceModifier
- type Rows
- type RuleInfo
- type RuleOptions
- type Run
- type RunStatus
- type SelectBody
- type SelectCore
- type SelectItem
- type SelectStmt
- type SetOpType
- type Severity
- type SourceRef
- type StarExpr
- type StarModifier
- type Stmt
- type Store
- type StructField
- type StructLiteral
- type SubqueryExpr
- type TableMetadata
- type TableName
- type TableRef
- type TargetConfig
- type TestConfig
- type TraceResult
- type TransformType
- type UnaryExpr
- type UnpivotInGroup
- type UnpivotTable
- type WhenClause
- type WindowDef
- type WindowSpec
- type WithClause
Constants ¶
const ( JoinInner = "INNER" JoinLeft = "LEFT" JoinRight = "RIGHT" JoinFull = "FULL" JoinCross = "CROSS" )
Standard ANSI SQL join type values.
const ( MaterializationTable = "table" MaterializationView = "view" MaterializationIncremental = "incremental" )
Materialization constants for model types.
const ( PrecedenceNone = 0 PrecedenceOr = 1 PrecedenceAnd = 2 PrecedenceNot = 3 PrecedenceComparison = 4 // =, <>, <, >, <=, >=, LIKE, ILIKE, IN, BETWEEN PrecedenceAddition = 5 // +, -, || PrecedenceMultiply = 6 // *, /, % PrecedenceUnary = 7 // -, +, NOT PrecedencePostfix = 8 // ::, [], () )
Precedence constants for operator precedence parsing.
Variables ¶
var ErrDialectRequired = errors.New("dialect is required")
ErrDialectRequired is returned when a dialect is required but not provided.
Functions ¶
func AllKnownClauses ¶
AllKnownClauses returns all registered clause tokens. Useful for debugging and testing.
func IsKnownClause ¶
IsKnownClause returns true if ANY registered dialect uses this token as a clause. Returns the clause name for error messages.
func RecordClause ¶
RecordClause registers a token as a clause keyword. Called automatically by dialect.Builder.ClauseHandler().
Types ¶
type AcceptedValuesConfig ¶
AcceptedValuesConfig represents accepted values test configuration.
type Adapter ¶
type Adapter interface {
// Connect establishes a connection to the database.
Connect(ctx context.Context, cfg AdapterConfig) error
// Close closes the database connection.
Close() error
// Exec executes a SQL statement that doesn't return rows.
Exec(ctx context.Context, sql string) error
// Query executes a SQL statement that returns rows.
Query(ctx context.Context, sql string) (*Rows, error)
// GetTableMetadata retrieves metadata for a table.
GetTableMetadata(ctx context.Context, table string) (*TableMetadata, error)
// LoadCSV loads data from a CSV file into a table.
LoadCSV(ctx context.Context, tableName, filePath string) error
// DialectConfig returns the static dialect configuration.
DialectConfig() *DialectConfig
}
Adapter defines the interface that all database adapters must implement.
type AdapterConfig ¶
type AdapterConfig struct {
Type string
Path string
Host string
Port int
Database string
Username string
Password string
Schema string
Options map[string]string
Params map[string]any
}
AdapterConfig holds configuration for connecting to a database.
type BetweenExpr ¶
BetweenExpr represents a BETWEEN expression.
type BinaryExpr ¶
BinaryExpr represents a binary expression.
func (*BinaryExpr) GetRight ¶
func (b *BinaryExpr) GetRight() Expr
GetRight returns the right operand.
type CTE ¶
type CTE struct {
NodeInfo
Name string
Select *SelectStmt
}
CTE represents a Common Table Expression.
type CaseExpr ¶
type CaseExpr struct {
Operand Expr // CASE operand WHEN... (optional)
Whens []WhenClause
Else Expr
}
CaseExpr represents a CASE expression.
type ClauseDef ¶
type ClauseDef struct {
Token token.TokenType
Handler any // spi.ClauseHandler - cast at call site
Slot ClauseSlot
Keywords []string
Inline bool
}
ClauseDef bundles clause parsing logic with storage destination. Handler is stored as 'any' to avoid import cycles with pkg/spi. Consumers cast to spi.ClauseHandler when invoking.
type ClauseSlot ¶
type ClauseSlot int
ClauseSlot specifies where a parsed clause result should be stored in SelectCore. This enables dialects to declaratively specify storage locations for their clauses.
const ( SlotWhere ClauseSlot = iota SlotGroupBy SlotHaving SlotWindow SlotOrderBy SlotLimit SlotOffset SlotQualify SlotFetch // FETCH FIRST/NEXT clause SlotExtensions // Default for custom/dialect-specific clauses )
ClauseSlot constants define where parsed clause results are stored in SelectCore.
func (ClauseSlot) String ¶
func (s ClauseSlot) String() string
String returns the slot name for debugging.
type ColumnInfo ¶
type ColumnInfo struct {
Name string
Index int
TransformType TransformType // "" (direct) or "EXPR"
Function string // "sum", "count", etc.
Sources []SourceRef // where this column comes from
}
ColumnInfo represents column lineage information.
type ColumnRef ¶
ColumnRef represents a column reference (possibly qualified).
type Conditional ¶
Conditional represents an #if directive block.
type Dependency ¶
Dependency represents an edge in the model dependency graph.
type DerivedTable ¶
type DerivedTable struct {
NodeInfo
Select *SelectStmt
Alias string
}
DerivedTable represents a subquery in FROM clause.
type Dialect ¶
type Dialect struct {
Name string
Identifiers IdentifierConfig
// Database-specific settings
DefaultSchema string
Placeholder PlaceholderStyle
// Function classifications (normalized names)
Aggregates map[string]struct{}
Generators map[string]struct{}
Windows map[string]struct{}
TableFunctions map[string]struct{}
// Documentation for LSP
Docs map[string]FunctionDoc
// Keywords and types for autocomplete
Keywords map[string]struct{}
ReservedWords map[string]struct{}
DataTypes []string
// Parsing behavior - handlers stored as 'any'
ClauseSeq []token.TokenType
ClauseDefs map[token.TokenType]ClauseDef
Symbols map[string]token.TokenType
DynamicKw map[string]token.TokenType
Precedences map[token.TokenType]int
InfixHandlers map[token.TokenType]any // spi.InfixHandler
PrefixHandlers map[token.TokenType]any // spi.PrefixHandler
JoinTypes map[token.TokenType]JoinTypeDef
StarModifiers map[token.TokenType]any // core.StarModifierHandler
FromItems map[token.TokenType]any // spi.FromItemHandler
}
Dialect represents a SQL dialect configuration with runtime behavior. Handler fields use 'any' to keep core free of spi imports. The pkg/dialect Builder provides type-safe construction.
func (*Dialect) ClauseDefFor ¶
ClauseDefFor returns the definition for a clause token type.
func (*Dialect) ClauseSequence ¶
ClauseSequence returns the ordered list of clause token types.
func (*Dialect) Config ¶
func (d *Dialect) Config() *DialectConfig
Config returns the pure data configuration for this dialect.
func (*Dialect) FromItemHandler ¶
FromItemHandler returns the handler for a FROM item extension (as any).
func (*Dialect) FunctionLineageTypeOf ¶
func (d *Dialect) FunctionLineageTypeOf(name string) FunctionLineageType
FunctionLineageTypeOf returns the lineage classification for a function.
func (*Dialect) GetDoc ¶
func (d *Dialect) GetDoc(name string) (FunctionDoc, bool)
GetDoc returns documentation for a function.
func (*Dialect) InfixHandler ¶
InfixHandler returns the custom infix handler (as any). Caller casts to spi.InfixHandler.
func (*Dialect) IsAggregate ¶
IsAggregate returns true if the function is an aggregate function.
func (*Dialect) IsClauseToken ¶
IsClauseToken returns true if this dialect supports the given clause.
func (*Dialect) IsFromItemToken ¶
IsFromItemToken returns true if the token is a FROM item extension.
func (*Dialect) IsGenerator ¶
IsGenerator returns true if the function generates values.
func (*Dialect) IsJoinTypeToken ¶
IsJoinTypeToken returns true if the token is a dialect-specific join type.
func (*Dialect) IsReservedWord ¶
IsReservedWord returns true if the word needs quoting.
func (*Dialect) IsStarModifierToken ¶
IsStarModifierToken returns true if the token is a star modifier.
func (*Dialect) IsTableFunction ¶
IsTableFunction returns true if the function acts as a table source.
func (*Dialect) JoinTypeDefFor ¶
func (d *Dialect) JoinTypeDefFor(t token.TokenType) (JoinTypeDef, bool)
JoinTypeDefFor returns the definition for a join type token.
func (*Dialect) LookupKeyword ¶
LookupKeyword returns the token type for a dynamic keyword.
func (*Dialect) NormalizeName ¶
NormalizeName normalizes an identifier according to dialect rules.
func (*Dialect) Precedence ¶
Precedence returns the precedence level for an operator token.
func (*Dialect) PrefixHandler ¶
PrefixHandler returns the custom prefix handler (as any).
func (*Dialect) QuoteIdentifier ¶
QuoteIdentifier quotes an identifier using the dialect's quote characters.
func (*Dialect) QuoteIdentifierIfNeeded ¶
QuoteIdentifierIfNeeded quotes an identifier only if it's a reserved word.
func (*Dialect) StarModifierHandler ¶
StarModifierHandler returns the handler for a star modifier (as any).
type DialectConfig ¶
type DialectConfig struct {
// Name is the dialect identifier (e.g., "duckdb", "postgres")
Name string
// Identifiers defines quoting and normalization rules
Identifiers IdentifierConfig
// DefaultSchema is the default schema name ("main" for DuckDB, "public" for Postgres)
DefaultSchema string
// Placeholder defines how query parameters are formatted
Placeholder PlaceholderStyle
// Function classifications (normalized names)
Aggregates []string // SUM, COUNT, AVG, etc.
Generators []string // NOW, UUID, RANDOM, etc.
Windows []string // ROW_NUMBER, LAG, LEAD, etc.
TableFunctions []string // read_csv, generate_series, etc.
// Keywords for autocomplete/highlighting
Keywords []string
DataTypes []string
// Feature Flags - Builder auto-wires based on these
//
// Clause extensions
SupportsQualify bool // QUALIFY clause for window filtering
SupportsReturning bool // RETURNING clause for DML
SupportsGroupByAll bool // GROUP BY ALL
SupportsOrderByAll bool // ORDER BY ALL
// Operator extensions
SupportsIlike bool // ILIKE case-insensitive LIKE
SupportsCastOperator bool // :: cast operator
// Join extensions
SupportsSemiAntiJoins bool // SEMI/ANTI join types
}
DialectConfig holds the static configuration for a SQL dialect. This is pure data — no handler functions.
The runtime behavior (clause handlers, infix handlers, etc.) lives in pkg/core.Dialect, which embeds this config.
type Environment ¶
Environment represents a virtual environment pointer.
type ExcludeModifier ¶
type ExcludeModifier struct {
Columns []string // Column names to exclude
}
ExcludeModifier represents * EXCLUDE (col1, col2, ...).
type ExistsExpr ¶
type ExistsExpr struct {
Not bool
Select *SelectStmt
}
ExistsExpr represents an EXISTS expression.
type Expr ¶
type Expr interface {
Node
// contains filtered or unexported methods
}
Expr is a marker interface for expression nodes.
type FetchClause ¶
type FetchClause struct {
First bool // true = FIRST, false = NEXT (semantically identical)
Count Expr // Number of rows (nil = 1 row implied)
Percent bool // FETCH FIRST n PERCENT ROWS
WithTies bool // true = WITH TIES, false = ONLY
}
FetchClause represents FETCH FIRST/NEXT n ROWS ONLY/WITH TIES (SQL:2008).
type FrameBound ¶
type FrameBound struct {
Type FrameBoundType
Offset Expr // for N PRECEDING/FOLLOWING
}
FrameBound represents a window frame bound.
type FrameBoundType ¶
type FrameBoundType string
FrameBoundType represents the type of frame bound.
const ( FrameUnboundedPreceding FrameBoundType = "UNBOUNDED PRECEDING" FrameUnboundedFollowing FrameBoundType = "UNBOUNDED FOLLOWING" FrameCurrentRow FrameBoundType = "CURRENT ROW" FrameExprPreceding FrameBoundType = "EXPR PRECEDING" FrameExprFollowing FrameBoundType = "EXPR FOLLOWING" )
FrameBoundType constants for window frame bound types.
type FrameSpec ¶
type FrameSpec struct {
Type FrameType
Start *FrameBound
End *FrameBound
}
FrameSpec represents a window frame specification.
type FromClause ¶
FromClause represents the FROM clause.
type FuncCall ¶
type FuncCall struct {
Name string
Distinct bool
Args []Expr
Star bool // COUNT(*)
Window *WindowSpec // OVER clause
Filter Expr // FILTER (WHERE ...) clause
}
FuncCall represents a function call.
type FunctionDoc ¶
FunctionDoc contains documentation metadata for LSP features.
type FunctionLineageType ¶
type FunctionLineageType int
FunctionLineageType classifies how a function affects lineage.
const ( // LineagePassthrough indicates the function passes through columns unchanged. LineagePassthrough FunctionLineageType = iota // LineageAggregate indicates an aggregate function. LineageAggregate // LineageGenerator indicates a function that generates values without input columns. LineageGenerator // LineageWindow indicates a window function. LineageWindow // LineageTable indicates a table-valued function. LineageTable )
FunctionLineageType constants classify function behavior for lineage analysis.
func (FunctionLineageType) String ¶
func (t FunctionLineageType) String() string
String returns the string representation of FunctionLineageType.
type IdentifierConfig ¶
type IdentifierConfig struct {
Quote string // Quote character: ", `, [
QuoteEnd string // End quote character (usually same as Quote, ] for [)
Escape string // Escape sequence: "", “, ]]
Normalization NormalizationStrategy // How to normalize unquoted identifiers
}
IdentifierConfig defines how identifiers are quoted and normalized.
type InExpr ¶
type InExpr struct {
Expr Expr
Not bool
Values []Expr // IN (1, 2, 3)
Query *SelectStmt // IN (SELECT ...)
}
InExpr represents an IN expression.
type IndexExpr ¶
type IndexExpr struct {
NodeInfo
Expr Expr // The expression being indexed
Index Expr // Simple index (non-nil if not a slice)
// For slicing (arr[start:stop])
IsSlice bool
Start Expr // nil means from beginning
Stop Expr // nil means to end (named Stop to avoid shadowing End() method)
}
IndexExpr represents array indexing or slicing: arr[i] or arr[start:stop]. Supports DuckDB array subscript and slice syntax.
type IsBoolExpr ¶
IsBoolExpr represents an IS [NOT] TRUE/FALSE expression.
type IsNullExpr ¶
IsNullExpr represents an IS NULL expression.
type Join ¶
type Join struct {
NodeInfo
Type JoinType
Natural bool // NATURAL JOIN modifier
Right TableRef
Condition Expr // ON clause (mutually exclusive with Using)
Using []string // USING (col1, col2) columns
}
Join represents a JOIN clause.
type JoinType ¶
type JoinType string
JoinType represents the type of join. The value is the SQL keyword (e.g., "LEFT", "INNER", "SEMI"). Join type constants are defined in their respective dialect packages:
- Standard joins (INNER, LEFT, RIGHT, FULL, CROSS): pkg/dialect/joins.go
- DuckDB joins (SEMI, ANTI, ASOF, POSITIONAL): pkg/dialects/duckdb/join_types.go
const JoinComma JoinType = ","
JoinComma represents an implicit cross join using comma syntax. This is kept in the core package because it's syntactically unique (not a TYPE JOIN keyword pattern) and universal across all SQL dialects.
type JoinTypeDef ¶
type JoinTypeDef struct {
Token token.TokenType // The trigger token for this join type
Type string // JoinType value (e.g., "LEFT", "SEMI")
OptionalToken token.TokenType // Optional modifier token (OUTER) - 0 means none
RequiresOn bool // true if ON clause is required
AllowsUsing bool // true if USING clause is allowed
}
JoinTypeDef defines a dialect-specific join type.
type LambdaExpr ¶
type LambdaExpr struct {
NodeInfo
Params []string // Parameter names
Body Expr // Lambda body expression
}
LambdaExpr represents a lambda expression: x -> expr or (x, y) -> expr. Used with list functions like list_transform, list_filter, list_reduce.
func (*LambdaExpr) GetParams ¶
func (l *LambdaExpr) GetParams() []string
GetParams returns the parameter names.
type LateralTable ¶
type LateralTable struct {
NodeInfo
Select *SelectStmt
Alias string
}
LateralTable represents a LATERAL subquery.
type LikeExpr ¶
type LikeExpr struct {
Expr Expr
Not bool
Pattern Expr
Op token.TokenType // token.LIKE or dialect-registered ILIKE
}
LikeExpr represents a LIKE expression.
type LintConfig ¶
type LintConfig struct {
// Disabled contains rule IDs to disable
Disabled []string `koanf:"disabled"`
// Severity maps rule ID to severity override (error, warning, info, hint)
Severity map[string]string `koanf:"severity"`
// Rules contains rule-specific options
Rules map[string]RuleOptions `koanf:"rules"`
// ProjectHealth holds project-level linting configuration
ProjectHealth *ProjectHealthConfig `koanf:"project_health"`
}
LintConfig holds lint rule configuration.
type ListLiteral ¶
ListLiteral represents a list/array literal: [expr, expr, ...]. DuckDB syntax for creating array values.
type Literal ¶
type Literal struct {
Type LiteralType
Value string
}
Literal represents a literal value.
type LiteralType ¶
type LiteralType int
LiteralType represents the type of a literal.
const ( LiteralNumber LiteralType = iota LiteralString LiteralBool LiteralNull )
LiteralType constants for SQL literal value types.
type MacroFunction ¶
MacroFunction represents a function exported from a macro namespace.
type MacroNamespace ¶
MacroNamespace represents a macro namespace from a .star file.
type MacroTable ¶
type MacroTable struct {
NodeInfo
Content string // raw {{ ... }} content including delimiters
Alias string
}
MacroTable represents a macro used as a table reference (e.g., {{ ref('table') }}).
type Model ¶
type Model struct {
// Path is the model path (e.g., "staging.customers")
Path string
// Name is the model name (filename without extension)
Name string
// FilePath is the absolute path to the SQL file
FilePath string
// Materialized defines how the model is stored: table, view, incremental
Materialized string
// UniqueKey for incremental models
UniqueKey string
// Owner is the team/person responsible for this model
Owner string
// Schema is the database schema for this model
Schema string
// Description is a human-readable description of the model
Description string
// Tags are metadata labels for filtering/organizing models
Tags []string
// Meta contains custom extension fields
Meta map[string]any
// Tests contains test configurations
Tests []TestConfig
// Imports are explicit model dependencies from @import pragmas (legacy)
Imports []string
// Sources are all table names referenced in the SQL
Sources []string
// Columns contains column-level lineage information
Columns []ColumnInfo
// UsesSelectStar is true if model uses SELECT * or t.*
UsesSelectStar bool
// SQL is the raw SQL content (excluding frontmatter)
SQL string
// RawContent is the full file content including frontmatter
RawContent string
// Conditionals are #if directives for environment-specific SQL
Conditionals []Conditional
// HasFrontmatter indicates if YAML frontmatter was found
HasFrontmatter bool
}
Model represents a SQL model (transformation unit). This contains the core identity fields only. Persistence-specific fields (ID, ContentHash, timestamps) belong in state.PersistedModel.
type ModelRun ¶
type ModelRun struct {
ID string
RunID string
ModelID string
Status ModelRunStatus
RowsAffected int64
StartedAt time.Time
CompletedAt *time.Time
Error string
RenderMS int64 // Time spent rendering template
ExecutionMS int64 // Time spent executing SQL
}
ModelRun represents a single execution of a model within a run.
type ModelRunStatus ¶
type ModelRunStatus string
ModelRunStatus represents the status of an individual model execution.
const ( ModelRunStatusPending ModelRunStatus = "pending" ModelRunStatusRunning ModelRunStatus = "running" ModelRunStatusSuccess ModelRunStatus = "success" ModelRunStatusFailed ModelRunStatus = "failed" ModelRunStatusSkipped ModelRunStatus = "skipped" )
Model run status constants.
type ModelRunWithInfo ¶
ModelRunWithInfo represents a model run with additional model info. Used for UI display where we need model path and name alongside run data.
type Node ¶
type Node interface {
// Pos returns the position of the first character of the node.
Pos() token.Position
// End returns the position of the character immediately after the node.
End() token.Position
}
Node is the base interface for all AST nodes. This provides type safety for parser extension points (spi.ClauseHandler, etc.) without requiring pkg/core to import pkg/spi.
type NodeInfo ¶
type NodeInfo struct {
Span token.Span
LeadingComments []*token.Comment
TrailingComments []*token.Comment
}
NodeInfo provides common fields for all AST nodes. Embed this in node types that need position/comment tracking.
func (*NodeInfo) AddLeadingComment ¶
AddLeadingComment adds a leading comment to the node.
func (*NodeInfo) AddTrailingComment ¶
AddTrailingComment adds a trailing comment to the node.
type NormalizationStrategy ¶
type NormalizationStrategy int
NormalizationStrategy defines how unquoted identifiers are normalized.
const ( // NormLowercase normalizes unquoted identifiers to lowercase (default SQL behavior). NormLowercase NormalizationStrategy = iota // NormUppercase normalizes unquoted identifiers to uppercase (Snowflake, Oracle). NormUppercase // NormCaseSensitive preserves identifier case exactly (MySQL, ClickHouse). NormCaseSensitive // NormCaseInsensitive normalizes to lowercase for comparison (BigQuery, Hive, DuckDB). NormCaseInsensitive )
type OperatorDef ¶
type OperatorDef struct {
Token token.TokenType
Symbol string
Precedence int
Handler any // spi.InfixHandler - cast at call site
}
OperatorDef defines an infix operator with precedence. Handler is stored as 'any' to avoid import cycles.
type OrderByItem ¶
type OrderByItem struct {
Expr Expr
Desc bool
NullsFirst *bool // nil means default, true = NULLS FIRST, false = NULLS LAST
}
OrderByItem represents an item in ORDER BY clause.
type ParenExpr ¶
type ParenExpr struct {
Expr Expr
}
ParenExpr represents a parenthesized expression.
type PersistedModel ¶
type PersistedModel struct {
*Model // Embed core identity
ID string // Database primary key
ContentHash string // For change detection
CreatedAt time.Time
UpdatedAt time.Time
}
PersistedModel represents a model stored in the state database. It wraps core.Model with persistence-specific fields.
type PivotAggregate ¶
type PivotAggregate struct {
Func *FuncCall // The aggregate function
Alias string // Optional alias for the result columns
}
PivotAggregate represents an aggregate in PIVOT.
type PivotInValue ¶
type PivotInValue struct {
Value Expr // The value (literal, identifier, or expression)
Alias string // Optional column name alias
}
PivotInValue represents a value in PIVOT ... IN (...).
type PivotTable ¶
type PivotTable struct {
NodeInfo
Source TableRef // The source table/subquery
Aggregates []PivotAggregate // Aggregate functions to compute
ForColumn string // Column to pivot on
InValues []PivotInValue // Values to pivot (or InStar=true for *)
InStar bool // true if IN *
Alias string // Optional alias
}
PivotTable represents a PIVOT operation in FROM clause. SELECT * FROM table PIVOT (agg FOR col IN (values))
type PlaceholderStyle ¶
type PlaceholderStyle int
PlaceholderStyle defines how query parameters are formatted.
const ( // PlaceholderQuestion uses ? for all parameters (DuckDB, MySQL, SQLite). PlaceholderQuestion PlaceholderStyle = iota // PlaceholderDollar uses $1, $2, etc. for parameters (PostgreSQL). PlaceholderDollar )
func (PlaceholderStyle) FormatPlaceholder ¶
func (p PlaceholderStyle) FormatPlaceholder(index int) string
FormatPlaceholder returns a placeholder for the given parameter index (1-based). Returns "?" for PlaceholderQuestion style, "$1", "$2" etc. for PlaceholderDollar style.
type ProjectConfig ¶
type ProjectConfig struct {
ModelsDir string `koanf:"models_dir"`
SeedsDir string `koanf:"seeds_dir"`
MacrosDir string `koanf:"macros_dir"`
Target *TargetConfig `koanf:"target"`
Lint *LintConfig `koanf:"lint"`
}
ProjectConfig holds project-level configuration.
type ProjectHealthConfig ¶
type ProjectHealthConfig struct {
// Enabled controls whether project health linting is enabled (default: true)
Enabled *bool `koanf:"enabled"`
// Thresholds for various rules
Thresholds ProjectHealthThresholds `koanf:"thresholds"`
// Rules maps rule IDs to severity overrides (off, info, warning, error)
Rules map[string]string `koanf:"rules"`
}
ProjectHealthConfig holds configuration for project-level linting.
func (*ProjectHealthConfig) IsEnabled ¶
func (c *ProjectHealthConfig) IsEnabled() bool
IsEnabled returns whether project health linting is enabled.
type ProjectHealthThresholds ¶
type ProjectHealthThresholds struct {
ModelFanout int `koanf:"model_fanout"` // PM04: default 3
TooManyJoins int `koanf:"too_many_joins"` // PM05: default 7
PassthroughColumns int `koanf:"passthrough_columns"` // PL01: default 20
StarlarkComplexity int `koanf:"starlark_complexity"` // PT01: default 10
}
ProjectHealthThresholds holds configurable thresholds for project health rules.
type QueryableStore ¶
type QueryableStore interface {
Store
// DB returns the underlying database connection for direct queries.
DB() *sql.DB
}
QueryableStore is an optional interface that stores can implement to allow direct database queries (used by dev server for efficiency).
type RenameItem ¶
RenameItem represents a single rename in RENAME modifier.
type RenameModifier ¶
type RenameModifier struct {
Items []RenameItem
}
RenameModifier represents * RENAME (old AS new, ...).
type ReplaceItem ¶
ReplaceItem represents a single replacement in REPLACE modifier.
type ReplaceModifier ¶
type ReplaceModifier struct {
Items []ReplaceItem
}
ReplaceModifier represents * REPLACE (expr AS col, ...).
type RuleInfo ¶
type RuleInfo struct {
ID string `json:"id"`
Name string `json:"name"`
Group string `json:"group"`
Description string `json:"description"`
DefaultSeverity Severity `json:"default_severity"`
ConfigKeys []string `json:"config_keys,omitempty"`
Dialects []string `json:"dialects,omitempty"` // Only for SQL rules
Type string `json:"type"` // "sql" or "project"
// Documentation fields
Rationale string `json:"rationale,omitempty"`
BadExample string `json:"bad_example,omitempty"`
GoodExample string `json:"good_example,omitempty"`
Fix string `json:"fix,omitempty"`
}
RuleInfo provides metadata about a lint rule for documentation/tooling. This is a DTO (Data Transfer Object) - it carries data without behavior.
type RuleOptions ¶
RuleOptions holds rule-specific configuration options.
type Run ¶
type Run struct {
ID string
Environment string
Status RunStatus
StartedAt time.Time
CompletedAt *time.Time
Error string
}
Run represents a pipeline execution session.
type SelectBody ¶
type SelectBody struct {
NodeInfo
Left *SelectCore
Op SetOpType // UNION, INTERSECT, EXCEPT, or empty
All bool // UNION ALL
ByName bool // DuckDB: BY NAME (match columns by name, not position)
Right *SelectBody // For chained set operations
}
SelectBody represents the body of a SELECT with possible set operations.
type SelectCore ¶
type SelectCore struct {
NodeInfo
Distinct bool
Columns []SelectItem
From *FromClause
Where Expr
GroupBy []Expr
GroupByAll bool // DuckDB: GROUP BY ALL (auto-group by non-aggregate columns)
Having Expr
Windows []WindowDef // Named window definitions (WINDOW clause)
Qualify Expr // DuckDB/Snowflake window function filter
OrderBy []OrderByItem
OrderByAll bool // DuckDB: ORDER BY ALL (order by all select columns)
OrderByAllDesc bool // DuckDB: Direction for ORDER BY ALL (true = DESC)
Limit Expr
Offset Expr
Fetch *FetchClause // FETCH FIRST/NEXT support (SQL:2008)
// Extensions holds rare/custom dialect-specific nodes (e.g., CONNECT BY, SAMPLE).
// Use this for dialect features that are too specialized to warrant typed fields.
Extensions []Node
}
SelectCore represents the core SELECT clause.
type SelectItem ¶
type SelectItem struct {
Star bool // SELECT *
TableStar string // SELECT t.*
Expr Expr // Expression
Alias string // AS alias
Modifiers []StarModifier // DuckDB: EXCLUDE, REPLACE, RENAME modifiers
}
SelectItem represents an item in the SELECT list.
type SelectStmt ¶
type SelectStmt struct {
NodeInfo
With *WithClause
Body *SelectBody
}
SelectStmt represents a complete SELECT statement with optional WITH clause.
type Severity ¶
type Severity int
Severity indicates the importance of a lint diagnostic.
const ( // SeverityError indicates a critical issue that should be fixed. SeverityError Severity = iota // SeverityWarning indicates a potential issue that should be reviewed. SeverityWarning // SeverityInfo indicates informational feedback. SeverityInfo // SeverityHint indicates a suggestion for improvement. SeverityHint )
Severity levels for diagnostics.
func ParseSeverity ¶
ParseSeverity converts a string to a Severity value. Returns the severity and true if valid, or SeverityWarning and false if invalid.
type StarExpr ¶
type StarExpr struct {
Table string // optional table qualifier for t.*
}
StarExpr represents a * expression (for SELECT *).
type StarModifier ¶
type StarModifier interface {
// contains filtered or unexported methods
}
StarModifier is the interface for star expression modifiers (DuckDB). Implemented by ExcludeModifier, ReplaceModifier, and RenameModifier.
type Stmt ¶
type Stmt interface {
Node
// contains filtered or unexported methods
}
Stmt is a marker interface for statement nodes.
type Store ¶
type Store interface {
Open(path string) error
Close() error
InitSchema() error
// Run operations
CreateRun(env string) (*Run, error)
GetRun(id string) (*Run, error)
CompleteRun(id string, status RunStatus, errMsg string) error
GetLatestRun(env string) (*Run, error)
ListRuns(limit int) ([]*Run, error)
// Model operations (uses PersistedModel for storage)
RegisterModel(model *PersistedModel) error
GetModelByID(id string) (*PersistedModel, error)
GetModelByPath(path string) (*PersistedModel, error)
GetModelByFilePath(filePath string) (*PersistedModel, error)
UpdateModelHash(id string, contentHash string) error
ListModels() ([]*PersistedModel, error)
DeleteModelByFilePath(filePath string) error
// Model run operations
RecordModelRun(modelRun *ModelRun) error
UpdateModelRun(id string, status ModelRunStatus, rowsAffected int64, errMsg string, renderMS int64, executionMS int64) error
GetModelRunsForRun(runID string) ([]*ModelRun, error)
GetModelRunsWithModelInfo(runID string) ([]*ModelRunWithInfo, error)
GetLatestModelRun(modelID string) (*ModelRun, error)
// Dependency operations
SetDependencies(modelID string, parentIDs []string) error
GetDependencies(modelID string) ([]string, error)
GetDependents(modelID string) ([]string, error)
// Environment operations
CreateEnvironment(name string) (*Environment, error)
GetEnvironment(name string) (*Environment, error)
UpdateEnvironmentRef(name string, commitRef string) error
// Column lineage operations
SaveModelColumns(modelPath string, columns []ColumnInfo) error
GetModelColumns(modelPath string) ([]ColumnInfo, error)
DeleteModelColumns(modelPath string) error
TraceColumnBackward(modelPath, columnName string) ([]TraceResult, error)
TraceColumnForward(modelPath, columnName string) ([]TraceResult, error)
// Macro operations
SaveMacroNamespace(ns *MacroNamespace, functions []*MacroFunction) error
GetMacroNamespaces() ([]*MacroNamespace, error)
GetMacroNamespace(name string) (*MacroNamespace, error)
GetMacroFunctions(namespace string) ([]*MacroFunction, error)
GetMacroFunction(namespace, name string) (*MacroFunction, error)
MacroFunctionExists(namespace, name string) (bool, error)
SearchMacroNamespaces(prefix string) ([]*MacroNamespace, error)
SearchMacroFunctions(namespace, prefix string) ([]*MacroFunction, error)
DeleteMacroNamespace(name string) error
DeleteMacroNamespaceByFilePath(filePath string) error
// File hash tracking
GetContentHash(filePath string) (string, error)
SetContentHash(filePath, hash, fileType string) error
DeleteContentHash(filePath string) error
// List tracked file paths
ListModelFilePaths() ([]string, error)
ListMacroFilePaths() ([]string, error)
// Column snapshot operations
SaveColumnSnapshot(runID, modelPath, sourceTable string, columns []string) error
GetColumnSnapshot(modelPath, sourceTable string) (columns []string, runID string, err error)
DeleteOldSnapshots(keepRuns int) error
// Batch operations
BatchGetAllColumns() (map[string][]ColumnInfo, error)
BatchGetAllDependencies() (map[string][]string, error)
BatchGetAllDependents() (map[string][]string, error)
}
Store defines the interface for state management operations.
type StructField ¶
type StructField struct {
Key string // Field name (can be identifier or string)
Value Expr // Field value
}
StructField represents a field in a struct literal.
type StructLiteral ¶
type StructLiteral struct {
NodeInfo
Fields []StructField
}
StructLiteral represents a struct literal: {'key': value, ...}. DuckDB syntax for creating anonymous structs/records.
type SubqueryExpr ¶
type SubqueryExpr struct {
Select *SelectStmt
}
SubqueryExpr represents a subquery used as an expression (e.g., in EXISTS).
type TableMetadata ¶
type TableMetadata struct {
Schema string
Name string
Columns []Column
RowCount int64
SizeBytes int64
}
TableMetadata holds metadata about a database table.
type TableRef ¶
type TableRef interface {
Node
// contains filtered or unexported methods
}
TableRef is a marker interface for table reference nodes.
type TargetConfig ¶
type TargetConfig struct {
Type string `koanf:"type"` // duckdb, postgres, snowflake, bigquery
// File-based databases (DuckDB, SQLite)
Database string `koanf:"database"` // file path or database name
// Network databases
Host string `koanf:"host"`
Port int `koanf:"port"`
User string `koanf:"user"`
Password string `koanf:"password"`
// Common
Schema string `koanf:"schema"`
// Snowflake-specific
Account string `koanf:"account"`
Warehouse string `koanf:"warehouse"`
Role string `koanf:"role"`
// Additional driver-specific options
Options map[string]string `koanf:"options"`
// Params holds adapter-specific configuration (e.g., DuckDB extensions, secrets, settings)
Params map[string]any `koanf:"params"`
}
TargetConfig holds database target configuration.
type TestConfig ¶
type TestConfig struct {
Unique []string
NotNull []string
AcceptedValues *AcceptedValuesConfig
}
TestConfig represents test configuration for a model.
type TraceResult ¶
TraceResult represents a single node in a column lineage trace.
type TransformType ¶
type TransformType string
TransformType describes how source columns are transformed.
const ( // TransformDirect means the column is a direct copy (no transformation). TransformDirect TransformType = "" // TransformExpression means the column is derived from an expression. TransformExpression TransformType = "EXPR" )
type UnpivotInGroup ¶
type UnpivotInGroup struct {
Columns []string // Column name(s) in this group
Alias string // Optional row value alias
}
UnpivotInGroup represents a group of columns in UNPIVOT ... IN (...). For simple UNPIVOT: single column per group. For multi-column UNPIVOT: multiple columns per group.
type UnpivotTable ¶
type UnpivotTable struct {
NodeInfo
Source TableRef // The source table/subquery
ValueColumns []string // Output column(s) for values
NameColumn string // Output column for names
InColumns []UnpivotInGroup // Source columns to unpivot
Alias string // Optional alias
}
UnpivotTable represents an UNPIVOT operation in FROM clause. SELECT * FROM table UNPIVOT (value FOR name IN (columns))
type WhenClause ¶
WhenClause represents a WHEN clause in CASE expression.
type WindowDef ¶
type WindowDef struct {
Name string
Spec *WindowSpec
}
WindowDef represents a named window definition in the WINDOW clause. Example: WINDOW w AS (PARTITION BY x ORDER BY y)
type WindowSpec ¶
type WindowSpec struct {
Name string // Named window reference
PartitionBy []Expr
OrderBy []OrderByItem
Frame *FrameSpec
}
WindowSpec represents a window specification (OVER clause).
type WithClause ¶
WithClause represents a WITH clause with CTEs.