parseDorisStatements is the ParseStatementsFunc for Doris. Returns []ParsedStatement with both text and AST populated. For non-empty segments, the AST is an *omniAST wrapping the omni AST node. The first parse error encountered (per-segment) is returned to the caller, matching the prior behaviour o
(statement string)
| 39 | // The first parse error encountered (per-segment) is returned to the caller, |
| 40 | // matching the prior behaviour of bailing out on the first syntax error. |
| 41 | func parseDorisStatements(statement string) ([]base.ParsedStatement, error) { |
| 42 | stmts, err := SplitSQL(statement) |
| 43 | if err != nil { |
| 44 | return nil, err |
| 45 | } |
| 46 | |
| 47 | result := make([]base.ParsedStatement, 0, len(stmts)) |
| 48 | for _, stmt := range stmts { |
| 49 | ps := base.ParsedStatement{ |
| 50 | Statement: stmt, |
| 51 | } |
| 52 | if stmt.Empty || strings.TrimSpace(stmt.Text) == "" { |
| 53 | result = append(result, ps) |
| 54 | continue |
| 55 | } |
| 56 | // Parse the segment text on its own so byte offsets in any ParseError |
| 57 | // align with stmt.Text; convertParseError then shifts them into the |
| 58 | // coordinates of the original multi-statement script. |
| 59 | file, errs := parser.Parse(stmt.Text) |
| 60 | if len(errs) > 0 { |
| 61 | pe := errs[0] |
| 62 | return nil, convertParseError(stmt.Text, &pe, stmt.Start) |
| 63 | } |
| 64 | var node ast.Node |
| 65 | if file != nil && len(file.Stmts) > 0 { |
| 66 | node = file.Stmts[0] |
| 67 | } |
| 68 | ps.AST = &omniAST{ |
| 69 | node: node, |
| 70 | startPos: stmt.Start, |
| 71 | } |
| 72 | result = append(result, ps) |
| 73 | } |
| 74 | |
| 75 | return result, nil |
| 76 | } |
| 77 | |
| 78 | // parseDorisSQL parses the given SQL statement using the omni Doris parser. |
| 79 | // Returns one *omniAST per non-empty segment (empty / comment-only segments |
nothing calls this directly
no test coverage detected