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 SearchAstNode[T googlesql.ASTNode](node googlesql.ASTNode, termOffset int) (T, bool)
- func SearchResolvedAstNode[T googlesql.ResolvedNode](output *googlesql.AnalyzerOutput, termOffset int) (T, 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) 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
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 SearchAstNode ¶
func SearchResolvedAstNode ¶
func SearchResolvedAstNode[T googlesql.ResolvedNode](output *googlesql.AnalyzerOutput, termOffset int) (T, bool)
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) 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 and DML 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.