file

package
v0.8.9 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateTableNameFromTablePathExpressionNode

func CreateTableNameFromTablePathExpressionNode(node *googlesql.ASTTablePathExpression) (string, bool)

func HasPartitionDate added in v0.8.0

func HasPartitionDate(metadata *bq.TableMetadata) bool

HasPartitionDate reports whether BigQuery exposes the _PARTITIONDATE pseudo column, which exists only on daily ingestion-time partitioned tables.

func ListAstNode

func ListAstNode[T googlesql.ASTNode](n *googlesql.ASTScript) []T

func ListResolvedAstNode

func ListResolvedAstNode[T googlesql.ResolvedNode](output *googlesql.AnalyzerOutput) []T

func LookupNode

func LookupNode[T astNode](n googlesql.ASTNode) (T, bool)

func ParseLocEnd added in v0.5.0

func ParseLocEnd(loc *googlesql.ParseLocationRange) int

func ParseLocStart added in v0.5.0

func ParseLocStart(loc *googlesql.ParseLocationRange) int

ParseLocStart/End are exported wrappers for use from other packages.

func ParseScript added in v0.8.1

func ParseScript(src string) (*googlesql.ASTScript, error)

ParseScript parses src as a script without analyzing it, so that the AST keeps the text as written (declared variables are substituted in ParsedFile.Node).

func PipeColumnIdentifier added in v0.8.1

func PipeColumnIdentifier(node googlesql.ASTNode, termOffset int) (ident *googlesql.ASTIdentifier, op googlesql.ASTPipeOperatorNode, isInput bool, ok bool)

PipeColumnIdentifier finds the identifier at termOffset that names a column by itself in a pipe operator: a column of SET, DROP or RENAME, or an alias. It reports whether the name refers to the input of the operator, as the columns of SET, DROP and the old names of RENAME do, or to its output.

func SearchAstNode

func SearchAstNode[T googlesql.ASTNode](node googlesql.ASTNode, termOffset int) (T, bool)

func SearchResolvedAstNode

func SearchResolvedAstNode[T googlesql.ResolvedNode](output *googlesql.AnalyzerOutput, termOffset int) (T, bool)

func TargetTableName added in v0.8.3

func TargetTableName(node *googlesql.ASTPathExpression) (string, bool)

TargetTableName returns the table name when node is the target table of a DML or DDL statement, which the AST holds as a path expression rather than a table path expression.

func Walk added in v0.5.0

func Walk(node googlesql.ASTNode, fn func(googlesql.ASTNode) error) error

Walk traverses an ASTNode tree in depth-first order, calling fn for each node. If fn returns an error, Walk stops and returns that error.

func WalkResolved added in v0.5.0

func WalkResolved(node googlesql.ResolvedNode, fn func(googlesql.ResolvedNode) error) error

WalkResolved traverses a ResolvedNode tree in depth-first order.

Types

type Analyzer

type Analyzer struct {
	// contains filtered or unexported fields
}

func NewAnalyzer

func NewAnalyzer(logger *logrus.Logger, bqClient bigquery.Client) *Analyzer

func (*Analyzer) AnalyzeStatement

func (a *Analyzer) AnalyzeStatement(rawText string, stmt googlesql.ASTStatementNode, catalog *Catalog) (*googlesql.AnalyzerOutput, error)

func (*Analyzer) GetTableMetadataFromPath

func (a *Analyzer) GetTableMetadataFromPath(ctx context.Context, path string) (*bq.TableMetadata, error)

func (*Analyzer) ParseFile

func (a *Analyzer) ParseFile(uri lsp.DocumentURI, src string) ParsedFile

func (*Analyzer) PipeColumn added in v0.8.1

func (a *Analyzer) PipeColumn(p ParsedFile, op googlesql.ASTPipeOperatorNode, name string, isInput bool) (*googlesql.ResolvedColumn, bool)

PipeColumn returns the column that name refers to in the input of op, or in its output if isInput is false. The resolved tree keeps no names of the columns between pipe operators, so the query up to op is analyzed on its own and the name is looked up in its output columns.

func (*Analyzer) ScopeVariables added in v0.8.0

func (a *Analyzer) ScopeVariables(p ParsedFile, termOffset int) []ScopeVariable

ScopeVariables returns the names in scope at termOffset that the enclosing statements bring in, innermost first, so that the first match of a name is the one that shadows the others.

type Catalog

type Catalog struct {
	// contains filtered or unexported fields
}

func NewCatalog

func NewCatalog(bqClient bigquery.Client) *Catalog

func (*Catalog) CatalogNode added in v0.5.0

func (c *Catalog) CatalogNode() *googlesql.SimpleCatalog

CatalogNode returns the underlying SimpleCatalog which implements CatalogNode.

func (*Catalog) Clone

func (c *Catalog) Clone() *Catalog

func (*Catalog) EnsureProcedure added in v0.8.0

func (c *Catalog) EnsureProcedure(path []string) error

EnsureProcedure loads a procedure from BigQuery if not already in the catalog.

func (*Catalog) EnsureTable added in v0.5.0

func (c *Catalog) EnsureTable(path []string) error

EnsureTable loads a table from BigQuery if not already in the catalog.

func (*Catalog) FindTableMetadata added in v0.5.0

func (c *Catalog) FindTableMetadata(path string) (*bq.TableMetadata, error)

FindTableMetadata returns the BigQuery metadata for a table path (e.g., "project.dataset.table").

func (*Catalog) PreloadProceduresFromAST added in v0.8.0

func (c *Catalog) PreloadProceduresFromAST(node *googlesql.ASTScript) error

PreloadProceduresFromAST loads the procedures that CALL statements refer to. It returns the errors that ProcedureLoadError reports, so that the caller can log them.

func (*Catalog) PreloadTablesFromAST added in v0.5.0

func (c *Catalog) PreloadTablesFromAST(node *googlesql.ASTScript) error

PreloadTablesFromAST walks the AST to find all table path expressions, DML target tables and DDL target tables, and pre-loads them. It returns the errors that TableLoadError reports, so that the caller can log them.

func (*Catalog) ProcedureLoadError added in v0.8.0

func (c *Catalog) ProcedureLoadError(name string) error

ProcedureLoadError is TableLoadError for procedures.

func (*Catalog) TableLoadError added in v0.8.0

func (c *Catalog) TableLoadError(name string) error

TableLoadError returns why the table referenced by name, as written in the query, could not be registered, unless the cause is about the query itself, e.g. the table does not exist.

func (*Catalog) TypeFactory added in v0.5.0

func (c *Catalog) TypeFactory() *googlesql.TypeFactory

TypeFactory returns the TypeFactory for creating types.

type Error

type Error struct {
	Msg                  string
	Position             lsp.Position
	TermLength           int
	IncompleteColumnName string
	Severity             lsp.DiagnosticSeverity
}

func (Error) Error

func (e Error) Error() string

type FixOffset

type FixOffset struct {
	Offset int
	Length int
	// contains filtered or unexported fields
}

type ParsedFile

type ParsedFile struct {
	URI lsp.DocumentURI
	Src string
	// FixedSrc matches the byte offsets in Node, RNode, and ParseTree.
	FixedSrc string

	// googlesql AST node
	Node *googlesql.ASTScript
	// RNode holds the outputs of the statements whose analysis succeeded, in
	// Node's statement order.
	RNode []*googlesql.AnalyzerOutput
	// Statements holds the result of every statement analyzed in the final
	// pass, so that a failed statement does not shift which output belongs to
	// which statement. When the retry limit is reached, the final pass applies
	// no fix-up, so the statement it would fix up keeps its error.
	Statements []StatementResult

	ParseTree *bqparser.Node

	FixOffsets []FixOffset

	// Errors are positioned in Src, unlike the offsets of the nodes.
	Errors []Error
	// contains filtered or unexported fields
}

func (ParsedFile) Close added in v0.5.0

func (p ParsedFile) Close()

func (ParsedFile) ExtractSQL

func (p ParsedFile) ExtractSQL(locationRange *googlesql.ParseLocationRange) (string, bool)

func (*ParsedFile) FindIncompleteColumnName

func (p *ParsedFile) FindIncompleteColumnName(pos lsp.Position) string

func (*ParsedFile) FindTargetAnalyzeOutput

func (p *ParsedFile) FindTargetAnalyzeOutput(termOffset int) (*googlesql.AnalyzerOutput, bool)

func (ParsedFile) FindTargetStatementNode

func (p ParsedFile) FindTargetStatementNode(termOffset int) (googlesql.ASTStatementNode, bool)

func (ParsedFile) OffsetsToLspRange added in v0.8.0

func (p ParsedFile) OffsetsToLspRange(startOff, endOff int) (lsp.Range, bool)

OffsetsToLspRange converts byte offsets in FixedSrc to an LSP range in Src.

func (ParsedFile) SrcOffset added in v0.8.0

func (p ParsedFile) SrcOffset(pos lsp.Position) int

SrcOffset is TermOffset in Src, for looking at what the user wrote where a fix-up rewrote it.

func (ParsedFile) TableMetadata added in v0.8.0

func (p ParsedFile) TableMetadata(path string) (*bq.TableMetadata, bool)

TableMetadata returns the metadata the analysis already fetched for path, so that callers can avoid asking BigQuery for the same table again.

func (ParsedFile) TermOffset

func (p ParsedFile) TermOffset(pos lsp.Position) int

func (ParsedFile) ToLspRange

func (p ParsedFile) ToLspRange(r *googlesql.ParseLocationRange) (lsp.Range, bool)

type ScopeVariable added in v0.8.0

type ScopeVariable struct {
	Name string
	Type googlesql.Googlesql_TypeNode
}

ScopeVariable is a name that an enclosing statement brings into scope, such as the variable of a FOR...IN loop.

type StatementResult added in v0.8.0

type StatementResult struct {
	Stmt   googlesql.ASTStatementNode
	Output *googlesql.AnalyzerOutput
	Err    *Error
}

StatementResult is the analysis result of a single statement. Output is nil when the analysis failed or the statement produces no output, such as SET.

type TableID added in v0.8.4

type TableID struct {
	Project, Dataset, Table string
}

TableID names a table as GetTableMetadata takes it.

func TableReferences added in v0.8.4

func TableReferences(src string, defaultProject func() string) []TableID

TableReferences returns, without duplicates, the tables whose metadata analyzing src fetches with GetTableMetadata, so that a caller can fetch them ahead of the analysis. It is a guess: a CTE referenced through a dotted path is listed too, and nothing is listed for src that does not parse.

Jump to

Keyboard shortcuts

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