MCPcopy Create free account
hub / github.com/bytebase/bytebase / parseSnowflakeStatements

Function parseSnowflakeStatements

backend/plugin/parser/snowflake/snowflake.go:27–56  ·  view source on GitHub ↗

parseSnowflakeStatements is the ParseStatementsFunc for Snowflake. Returns []ParsedStatement with both text and AST populated. Each non-empty statement is parsed with the omni parser (the legacy ANTLR parser is gone). A parse failure on any statement fails the whole batch with a *base.SyntaxError —

(statement string)

Source from the content-addressed store, hash-verified

25// whole input, so positions inside one statement stay relative to it and are
26// offset by the statement's start position afterwards.
27func parseSnowflakeStatements(statement string) ([]base.ParsedStatement, error) {
28 // First split to get Statement with text and positions
29 stmts, err := SplitSQL(statement)
30 if err != nil {
31 return nil, err
32 }
33
34 var result []base.ParsedStatement
35 for _, stmt := range stmts {
36 ps := base.ParsedStatement{
37 Statement: stmt,
38 }
39 if !stmt.Empty {
40 node, err := parseOmniStatementNode(stmt.Text)
41 if err != nil {
42 return nil, convertOmniParseError(err, stmt)
43 }
44 ps.AST = &OmniAST{
45 Node: node,
46 Text: stmt.Text,
47 // Keep the legacy ASTStartPosition shape: 1-based line of the
48 // statement start, no column component.
49 StartPosition: &storepb.Position{Line: int32(stmt.BaseLine()) + 1},
50 }
51 }
52 result = append(result, ps)
53 }
54
55 return result, nil
56}
57
58// IsSnowflakeKeyword returns true if the given string is a snowflake keyword.
59// Follows https://docs.snowflake.com/en/sql-reference/reserved-keywords.

Calls 4

parseOmniStatementNodeFunction · 0.85
BaseLineMethod · 0.80
SplitSQLFunction · 0.70
convertOmniParseErrorFunction · 0.70