parseDorisSQL parses the given SQL statement using the omni Doris parser. Returns one *omniAST per non-empty segment (empty / comment-only segments are skipped). This retains the historical signature shape used by other doris package files; on the first parse error it returns a *base.SyntaxError wi
(statement string)
| 83 | // files; on the first parse error it returns a *base.SyntaxError with the |
| 84 | // position translated into the coordinates of the original input. |
| 85 | func parseDorisSQL(statement string) ([]*omniAST, error) { |
| 86 | stmts, err := SplitSQL(statement) |
| 87 | if err != nil { |
| 88 | return nil, err |
| 89 | } |
| 90 | |
| 91 | var result []*omniAST |
| 92 | for _, stmt := range stmts { |
| 93 | if stmt.Empty || strings.TrimSpace(stmt.Text) == "" { |
| 94 | continue |
| 95 | } |
| 96 | file, errs := parser.Parse(stmt.Text) |
| 97 | if len(errs) > 0 { |
| 98 | pe := errs[0] |
| 99 | return nil, convertParseError(stmt.Text, &pe, stmt.Start) |
| 100 | } |
| 101 | var node ast.Node |
| 102 | if file != nil && len(file.Stmts) > 0 { |
| 103 | node = file.Stmts[0] |
| 104 | } |
| 105 | result = append(result, &omniAST{ |
| 106 | node: node, |
| 107 | startPos: stmt.Start, |
| 108 | }) |
| 109 | } |
| 110 | return result, nil |
| 111 | } |
| 112 | |
| 113 | // convertParseError converts an omni *parser.ParseError to a |
| 114 | // *base.SyntaxError that sql_service.go recognises for structured |