sqlparser

package
v0.11.644 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssetTypeToDialect added in v0.11.192

func AssetTypeToDialect(assetType pipeline.AssetType) (string, error)

func ConnectionTypeToDialect added in v0.11.644

func ConnectionTypeToDialect(connectionType string) string

ConnectionTypeToDialect maps a connection type identifier (e.g. "clickhouse") to the dialect string used by the rust SQL parser. Returns the empty string when no dialect is registered for the type.

Types

type ColumnLineage

type ColumnLineage struct {
	Name     string           `json:"name"`
	Upstream []UpstreamColumn `json:"upstream"`
	Type     string           `json:"type"`
}

type Lineage

type Lineage struct {
	Columns            []ColumnLineage `json:"columns"`
	NonSelectedColumns []ColumnLineage `json:"non_selected_columns"`
	Errors             []string        `json:"errors"`
}

type Parser added in v0.11.488

type Parser interface {
	Start() error
	ColumnLineage(sql, dialect string, schema Schema) (*Lineage, error)
	UsedTables(sql, dialect string) ([]string, error)
	RenameTables(sql, dialect string, tableMapping map[string]string) (string, error)
	AddLimit(sql string, limit int, dialect string) (string, error)
	IsSingleSelectQuery(sql string, dialect string) (bool, error)
	GetMissingDependenciesForAsset(asset *pipeline.Asset, pipeline *pipeline.Pipeline, renderer jinja.RendererInterface) ([]string, error)
	Close() error
}

type QueryConfig

type QueryConfig struct {
	Name   string `json:"name"`
	Query  string `json:"query"`
	Schema Schema `json:"schema"`
}

type RustSQLParser added in v0.11.488

type RustSQLParser struct {
	MaxQueryLength int
}

func NewRustSQLParser added in v0.11.488

func NewRustSQLParser(_ bool) (*RustSQLParser, error)

func NewRustSQLParserWithConfig added in v0.11.488

func NewRustSQLParserWithConfig(_ bool, maxQueryLength int) (*RustSQLParser, error)

func (*RustSQLParser) AddLimit added in v0.11.488

func (s *RustSQLParser) AddLimit(sql string, limit int, dialect string) (string, error)

func (*RustSQLParser) Close added in v0.11.488

func (s *RustSQLParser) Close() error

func (*RustSQLParser) ColumnLineage added in v0.11.488

func (s *RustSQLParser) ColumnLineage(sql, dialect string, schema Schema) (*Lineage, error)

func (*RustSQLParser) GetMissingDependenciesForAsset added in v0.11.488

func (s *RustSQLParser) GetMissingDependenciesForAsset(asset *pipeline.Asset, pipeline *pipeline.Pipeline, renderer jinja.RendererInterface) ([]string, error)

func (*RustSQLParser) HoistDeclares added in v0.11.587

func (s *RustSQLParser) HoistDeclares(sql string, assetType pipeline.AssetType) (string, error)

HoistDeclares reorders top-level DECLARE statements to the front of a multi-statement script via the in-process Rust SQL parser. Each statement's original text is preserved byte-for-byte; only the order and ';\n' separators are rewritten. DECLAREs nested inside BEGIN..END / CASE..END stay put. On dialect lookup or parse failure the input is returned together with the error so callers can fall back gracefully.

func (*RustSQLParser) HoistDeclaresList added in v0.11.587

func (s *RustSQLParser) HoistDeclaresList(queries []string, assetType pipeline.AssetType) ([]string, error)

HoistDeclaresList reorders a list of pre-split SQL statements so DECLAREs lead, preserving each element's text verbatim.

func (*RustSQLParser) IsSingleSelectQuery added in v0.11.488

func (s *RustSQLParser) IsSingleSelectQuery(sql string, dialect string) (bool, error)

func (*RustSQLParser) RenameTables added in v0.11.488

func (s *RustSQLParser) RenameTables(sql string, dialect string, tableMapping map[string]string) (string, error)

func (*RustSQLParser) Start added in v0.11.488

func (s *RustSQLParser) Start() error

Start is idempotent and effectively free: the Rust SQL parser lives in-process behind CGo, with no subprocess to spin up or state to track. It only verifies that the FFI library is linked (a compile-time guarantee on darwin/linux) and otherwise returns nil. Calling it repeatedly — or not at all — has no effect. Methods like HoistDeclares do not call it internally, so there is no double-start hazard.

func (*RustSQLParser) UsedTables added in v0.11.488

func (s *RustSQLParser) UsedTables(sql, dialect string) ([]string, error)

type SQLParser

type SQLParser struct {
	MaxQueryLength int
	// contains filtered or unexported fields
}

func NewSQLParser

func NewSQLParser(randomize bool) (*SQLParser, error)

func NewSQLParserCached added in v0.11.497

func NewSQLParserCached() (*SQLParser, error)

NewSQLParserCached creates a SQLParser that reuses previously extracted embedded files from a stable temp directory path. This is significantly faster when files already exist (skips ~3s of file extraction) and is safe for concurrent reads across test packages.

func NewSQLParserWithConfig added in v0.11.241

func NewSQLParserWithConfig(randomize bool, maxQueryLength int) (*SQLParser, error)

func (*SQLParser) AddLimit added in v0.11.197

func (s *SQLParser) AddLimit(sql string, limit int, dialect string) (string, error)

func (*SQLParser) Close

func (s *SQLParser) Close() error

func (*SQLParser) ColumnLineage

func (s *SQLParser) ColumnLineage(sql, dialect string, schema Schema) (*Lineage, error)

func (*SQLParser) GetMissingDependenciesForAsset added in v0.11.216

func (s *SQLParser) GetMissingDependenciesForAsset(asset *pipeline.Asset, pipeline *pipeline.Pipeline, renderer jinja.RendererInterface) ([]string, error)

func (*SQLParser) IsSingleSelectQuery added in v0.11.254

func (s *SQLParser) IsSingleSelectQuery(sql string, dialect string) (bool, error)

func (*SQLParser) RenameTables added in v0.11.169

func (s *SQLParser) RenameTables(sql string, dialect string, tableMapping map[string]string) (string, error)

func (*SQLParser) Start

func (s *SQLParser) Start() error

func (*SQLParser) UsedTables added in v0.11.4

func (s *SQLParser) UsedTables(sql, dialect string) ([]string, error)

type Schema

type Schema map[string]map[string]string

type UpstreamColumn

type UpstreamColumn struct {
	Column string `json:"column"`
	Table  string `json:"table"`
}

Jump to

Keyboard shortcuts

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