Documentation
¶
Index ¶
- func CreateTableNameFromTablePathExpressionNode(node *googlesql.ASTTablePathExpression) (string, bool)
- func HasPartitionDate(metadata *bq.TableMetadata) bool
- func ListAstNode[T googlesql.ASTNode](n *googlesql.ASTScript) []T
- func ListResolvedAstNode[T googlesql.ResolvedNode](output *googlesql.AnalyzerOutput) []T
- func LookupNode[T astNode](n googlesql.ASTNode) (T, bool)
- func ParseLocEnd(loc *googlesql.ParseLocationRange) int
- func ParseLocStart(loc *googlesql.ParseLocationRange) int
- func ParseScript(src string) (*googlesql.ASTScript, error)
- func PipeColumnIdentifier(node googlesql.ASTNode, termOffset int) (ident *googlesql.ASTIdentifier, op googlesql.ASTPipeOperatorNode, isInput bool, ...)
- func SearchAstNode[T googlesql.ASTNode](node googlesql.ASTNode, termOffset int) (T, bool)
- func SearchResolvedAstNode[T googlesql.ResolvedNode](output *googlesql.AnalyzerOutput, termOffset int) (T, bool)
- func TargetTableName(node *googlesql.ASTPathExpression) (string, bool)
- func Walk(node googlesql.ASTNode, fn func(googlesql.ASTNode) error) error
- func WalkResolved(node googlesql.ResolvedNode, fn func(googlesql.ResolvedNode) error) error
- type Analyzer
- func (a *Analyzer) AnalyzeStatement(rawText string, stmt googlesql.ASTStatementNode, catalog *Catalog) (*googlesql.AnalyzerOutput, error)
- func (a *Analyzer) GetTableMetadataFromPath(ctx context.Context, path string) (*bq.TableMetadata, error)
- func (a *Analyzer) ParseFile(uri lsp.DocumentURI, src string) ParsedFile
- func (a *Analyzer) PipeColumn(p ParsedFile, op googlesql.ASTPipeOperatorNode, name string, isInput bool) (*googlesql.ResolvedColumn, bool)
- func (a *Analyzer) ScopeVariables(p ParsedFile, termOffset int) []ScopeVariable
- type Catalog
- func (c *Catalog) AddFunctionWithName(name string, fn *googlesql.Function)
- func (c *Catalog) CatalogNode() *googlesql.SimpleCatalog
- func (c *Catalog) Clone() *Catalog
- func (c *Catalog) EnsureProcedure(path []string) error
- func (c *Catalog) EnsureTable(path []string) error
- func (c *Catalog) FindTableMetadata(path string) (*bq.TableMetadata, error)
- func (c *Catalog) PreloadProceduresFromAST(node *googlesql.ASTScript) error
- func (c *Catalog) PreloadTablesFromAST(node *googlesql.ASTScript) error
- func (c *Catalog) ProcedureLoadError(name string) error
- func (c *Catalog) TableLoadError(name string) error
- func (c *Catalog) TypeFactory() *googlesql.TypeFactory
- type Error
- type FixOffset
- type ParsedFile
- func (p ParsedFile) Close()
- func (p ParsedFile) ExtractSQL(locationRange *googlesql.ParseLocationRange) (string, bool)
- func (p *ParsedFile) FindIncompleteColumnName(pos lsp.Position) string
- func (p *ParsedFile) FindTargetAnalyzeOutput(termOffset int) (*googlesql.AnalyzerOutput, bool)
- func (p ParsedFile) FindTargetStatementNode(termOffset int) (googlesql.ASTStatementNode, bool)
- func (p ParsedFile) OffsetsToLspRange(startOff, endOff int) (lsp.Range, bool)
- func (p ParsedFile) SrcOffset(pos lsp.Position) int
- func (p ParsedFile) TableMetadata(path string) (*bq.TableMetadata, bool)
- func (p ParsedFile) TermOffset(pos lsp.Position) int
- func (p ParsedFile) ToLspRange(r *googlesql.ParseLocationRange) (lsp.Range, bool)
- type ScopeVariable
- type StatementResult
- type TableID
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 ListResolvedAstNode ¶
func ListResolvedAstNode[T googlesql.ResolvedNode](output *googlesql.AnalyzerOutput) []T
func LookupNode ¶
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
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 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
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 (*Analyzer) AnalyzeStatement ¶
func (a *Analyzer) AnalyzeStatement(rawText string, stmt googlesql.ASTStatementNode, catalog *Catalog) (*googlesql.AnalyzerOutput, error)
func (*Analyzer) GetTableMetadataFromPath ¶
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 (*Catalog) AddFunctionWithName ¶
func (*Catalog) CatalogNode ¶ added in v0.5.0
func (c *Catalog) CatalogNode() *googlesql.SimpleCatalog
CatalogNode returns the underlying SimpleCatalog which implements CatalogNode.
func (*Catalog) EnsureProcedure ¶ added in v0.8.0
EnsureProcedure loads a procedure from BigQuery if not already in the catalog.
func (*Catalog) EnsureTable ¶ added in v0.5.0
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
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
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
ProcedureLoadError is TableLoadError for procedures.
func (*Catalog) TableLoadError ¶ added in v0.8.0
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 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
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.