Documentation
¶
Index ¶
- Constants
- func ValidateSQLForEditor(sql string) (bool, bool, error)
- type ChangeKind
- type ChangeSummary
- type ChangedTable
- type CompletionContext
- type Diagnostic
- type LSPPosition
- type LSPRange
- type Position
- type RangeReference
- type RangeReferenceKind
- type ScopeSnapshot
- type Segment
- type Statement
- type StatementRange
- type StatementType
Constants ¶
const ( RangeReferenceRelation = parser.RangeReferenceRelation RangeReferenceSubquery = parser.RangeReferenceSubquery RangeReferenceFunction = parser.RangeReferenceFunction RangeReferenceJoinAlias = parser.RangeReferenceJoinAlias RangeReferenceCTE = parser.RangeReferenceCTE )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ChangeKind ¶
type ChangeKind string
ChangeKind describes the top-level kind of table change.
const ( ChangeKindCreate ChangeKind = "CREATE" ChangeKindAlter ChangeKind = "ALTER" ChangeKindDrop ChangeKind = "DROP" ChangeKindDML ChangeKind = "DML" )
type ChangeSummary ¶
type ChangeSummary struct {
Tables []ChangedTable
DMLCount int
InsertCount int
UpdateCount int
DeleteCount int
}
ChangeSummary is an Omni-native Redshift changed-resource summary.
func ExtractChangedResources ¶
func ExtractChangedResources(sql, currentDatabase, currentSchema string) (*ChangeSummary, error)
ExtractChangedResources extracts table-level resource changes from Redshift SQL.
type ChangedTable ¶
type ChangedTable struct {
Database string
Schema string
Name string
Kind ChangeKind
Affected bool
}
ChangedTable identifies a changed table-like resource.
type CompletionContext ¶
type CompletionContext = parser.CompletionContext
CompletionContext is the parser-native context for SQL completion.
func CollectCompletion ¶
func CollectCompletion(sql string, cursorOffset int) *CompletionContext
CollectCompletion returns completion candidates plus a best-effort visible relation scope at cursorOffset. Ordinary Parse remains strict.
type Diagnostic ¶
Diagnostic reports a parser diagnostic over an LSP range.
func Diagnose ¶
func Diagnose(sql string) []Diagnostic
Diagnose returns syntax diagnostics for Redshift SQL.
type LSPPosition ¶
LSPPosition is a zero-based UTF-16 LSP position.
type LSPRange ¶
type LSPRange struct {
Start LSPPosition
End LSPPosition
}
LSPRange is a zero-based UTF-16 LSP range.
type Position ¶
type Position struct {
// Line is 1-based line number.
Line int
// Column is 1-based column in bytes.
Column int
}
Position represents a location in source text.
type RangeReference ¶
type RangeReference = parser.RangeReference
RangeReference is a syntax-level FROM/JOIN reference.
type RangeReferenceKind ¶
type RangeReferenceKind = parser.RangeReferenceKind
RangeReferenceKind classifies a range-table entry visible to completion.
type ScopeSnapshot ¶
type ScopeSnapshot = parser.ScopeSnapshot
ScopeSnapshot describes the SELECT-level relation scope visible at a cursor.
type Segment ¶
type Segment struct {
Text string // the raw text of this segment
ByteStart int // byte offset of start in original sql
ByteEnd int // byte offset of end (exclusive) in original sql
}
Segment represents a portion of SQL text delimited by top-level semicolons.
func Split ¶
Split splits SQL text into segments at top-level semicolons. It is a pure lexical scanner that does not parse SQL, so it works on both valid and invalid SQL. Each returned segment includes the terminating semicolon (if present). Segments are returned with their byte offsets in the original string.
type Statement ¶
type Statement struct {
// Text is the SQL text including trailing semicolon if present.
Text string
// AST is the inner statement node (e.g. *ast.SelectStmt). Nil for empty statements.
AST ast.Node
// ByteStart is the inclusive start byte offset in the original SQL.
ByteStart int
// ByteEnd is the exclusive end byte offset in the original SQL.
ByteEnd int
// Start is the start position (line:column) in the original SQL.
Start Position
// End is the exclusive end position (line:column) in the original SQL.
End Position
}
Statement is the result of parsing a single SQL statement.
func Parse ¶
Parse splits and parses a SQL string into statements. Each statement includes the text, AST, and byte/line positions. Text boundaries are derived from RawStmt.Loc: each statement's text spans from the end of the previous statement to just past the semicolon (or end of input) following the current statement.
type StatementRange ¶
type StatementRange = LSPRange
StatementRange is the source range of a SQL statement.
func StatementRanges ¶
func StatementRanges(sql string) ([]StatementRange, error)
StatementRanges returns LSP UTF-16 ranges for non-empty SQL statements.
type StatementType ¶
type StatementType string
StatementType is a conservative top-level statement classification.
const ( StatementTypeUnknown StatementType = "UNKNOWN" StatementTypeSelect StatementType = "SELECT" StatementTypeDDL StatementType = "DDL" StatementTypeDML StatementType = "DML" StatementTypeShow StatementType = "SHOW" StatementTypeCopy StatementType = "COPY" StatementTypeUnload StatementType = "UNLOAD" StatementTypeExplain StatementType = "EXPLAIN" StatementTypeExplainAnalyze StatementType = "EXPLAIN_ANALYZE" StatementTypeSet StatementType = "SET" )
func ClassifyStatement ¶
func ClassifyStatement(node ast.Node) StatementType
ClassifyStatement classifies a parsed Redshift AST node.
func GetStatementTypes ¶
func GetStatementTypes(sql string) ([]StatementType, error)
GetStatementTypes parses SQL and returns one type per non-empty statement.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package nodes defines PostgreSQL parse tree node types.
|
Package nodes defines PostgreSQL parse tree node types. |
|
cmd/genwalker
command
Command genwalker generates walk_generated.go from parsenodes.go.
|
Command genwalker generates walk_generated.go from parsenodes.go. |
|
cmd/redshift-compat-report
command
|
|
|
Package completion provides parser-native C3-style SQL completion for PostgreSQL.
|
Package completion provides parser-native C3-style SQL completion for PostgreSQL. |
|
Package parser implements a PostgreSQL-compatible SQL lexer and parser.
|
Package parser implements a PostgreSQL-compatible SQL lexer and parser. |
|
Package pgregress provides tools for running PostgreSQL regression test SQL files against the pgparser parser to verify parse compatibility.
|
Package pgregress provides tools for running PostgreSQL regression test SQL files against the pgparser parser to verify parse compatibility. |
|
plpgsql
|
|
|
ast
Package ast defines PL/pgSQL AST node types.
|
Package ast defines PL/pgSQL AST node types. |
|
parser
Package parser implements a recursive descent PL/pgSQL parser.
|
Package parser implements a recursive descent PL/pgSQL parser. |