diff --git a/parser/ast.go b/parser/ast.go index 156cd2f..318a7a2 100644 --- a/parser/ast.go +++ b/parser/ast.go @@ -24,6 +24,47 @@ type DDL interface { Type() string } +type SelectItem struct { + Expr Expr + // Please refer: https://clickhouse.com/docs/en/sql-reference/statements/select#select-modifiers + Modifiers []*FunctionExpr +} + +func (s *SelectItem) Pos() Pos { + return s.Expr.Pos() +} + +func (s *SelectItem) End() Pos { + if len(s.Modifiers) > 0 { + return s.Modifiers[len(s.Modifiers)-1].End() + } + return s.Expr.End() +} + +func (s *SelectItem) String() string { + var builder strings.Builder + builder.WriteString(s.Expr.String()) + for _, modifier := range s.Modifiers { + builder.WriteByte(' ') + builder.WriteString(modifier.String()) + } + return builder.String() +} + +func (s *SelectItem) Accept(visitor ASTVisitor) error { + visitor.enter(s) + defer visitor.leave(s) + if err := s.Expr.Accept(visitor); err != nil { + return err + } + for _, modifier := range s.Modifiers { + if err := modifier.Accept(visitor); err != nil { + return err + } + } + return visitor.VisitSelectItem(s) +} + type OperationExpr struct { OperationPos Pos Kind TokenKind @@ -5047,7 +5088,7 @@ type SelectQuery struct { StatementEnd Pos With *WithClause Top *TopClause - SelectColumns *ColumnExprList + SelectItems []*SelectItem From *FromClause ArrayJoin *ArrayJoinClause Window *WindowClause @@ -5092,10 +5133,9 @@ func (s *SelectQuery) String() string { // nolint: funlen builder.WriteString(s.Top.String()) builder.WriteString(" ") } - columns := s.SelectColumns.Items - for i, column := range columns { - builder.WriteString(column.String()) - if i != len(columns)-1 { + for i, selectItem := range s.SelectItems { + builder.WriteString(selectItem.String()) + if i != len(s.SelectItems)-1 { builder.WriteString(", ") } } @@ -5173,9 +5213,11 @@ func (s *SelectQuery) Accept(visitor ASTVisitor) error { return err } } - if s.SelectColumns != nil { - if err := s.SelectColumns.Accept(visitor); err != nil { - return err + if s.SelectItems != nil { + for _, item := range s.SelectItems { + if err := item.Accept(visitor); err != nil { + return err + } } } if s.From != nil { diff --git a/parser/ast_visitor.go b/parser/ast_visitor.go index 0435dcf..c88631d 100644 --- a/parser/ast_visitor.go +++ b/parser/ast_visitor.go @@ -154,6 +154,7 @@ type ASTVisitor interface { VisitExplainExpr(expr *ExplainStmt) error VisitPrivilegeExpr(expr *PrivilegeClause) error VisitGrantPrivilegeExpr(expr *GrantPrivilegeStmt) error + VisitSelectItem(expr *SelectItem) error enter(expr Expr) leave(expr Expr) @@ -1236,6 +1237,13 @@ func (v *DefaultASTVisitor) VisitGrantPrivilegeExpr(expr *GrantPrivilegeStmt) er return nil } +func (v *DefaultASTVisitor) VisitSelectItem(expr *SelectItem) error { + if v.Visit != nil { + return v.Visit(expr) + } + return nil +} + func (v *DefaultASTVisitor) enter(expr Expr) {} func (v *DefaultASTVisitor) leave(expr Expr) {} diff --git a/parser/keyword.go b/parser/keyword.go index d0c04ad..beac806 100644 --- a/parser/keyword.go +++ b/parser/keyword.go @@ -10,6 +10,7 @@ const ( KeywordAnd = "AND" KeywordAnti = "ANTI" KeywordAny = "ANY" + KeywordApply = "APPLY" KeywordArray = "ARRAY" KeywordAs = "AS" KeywordAsc = "ASC" @@ -233,6 +234,7 @@ var keywords = NewSet( KeywordAnd, KeywordAnti, KeywordAny, + KeywordApply, KeywordArray, KeywordAs, KeywordAsc, diff --git a/parser/parser_column.go b/parser/parser_column.go index 3ae5111..34210b8 100644 --- a/parser/parser_column.go +++ b/parser/parser_column.go @@ -477,6 +477,24 @@ func (p *Parser) parseColumnExprListWithTerm(term TokenKind, pos Pos) (*ColumnEx return columnExprList, nil } +func (p *Parser) parseSelectItems() ([]*SelectItem, error) { + selectItems := make([]*SelectItem, 0) + for !p.lexer.isEOF() || p.last() != nil { + selectItem, err := p.parseSelectItem() + if err != nil { + return nil, err + } + if selectItem == nil { + break + } + selectItems = append(selectItems, selectItem) + if p.tryConsumeTokenKind(",") == nil { + break + } + } + return selectItems, nil +} + // Syntax: INTERVAL expr interval func (p *Parser) parseColumnExprInterval(pos Pos) (Expr, error) { if err := p.consumeKeyword(KeywordInterval); err != nil { @@ -504,10 +522,7 @@ func (p *Parser) parseColumnExprInterval(pos Pos) (Expr, error) { }, nil } -func (p *Parser) parseFunctionExpr(_ Pos) (Expr, error) { - if _, err := p.consumeTokenKind(TokenIdent); err != nil { - return nil, err - } +func (p *Parser) parseFunctionExpr(_ Pos) (*FunctionExpr, error) { // parse function name name, err := p.parseIdent() if err != nil { @@ -674,6 +689,30 @@ func (p *Parser) parseColumnsExpr(pos Pos) (Expr, error) { return p.parseExpr(pos) } +func (p *Parser) parseSelectItem() (*SelectItem, error) { + expr, err := p.parseExpr(p.Pos()) + if err != nil { + return nil, err + } + + modifiers := make([]*FunctionExpr, 0) + for { + if p.matchKeyword(KeywordExcept) || p.matchKeyword(KeywordApply) || p.matchKeyword(KeywordReplace) { + modifier, err := p.parseFunctionExpr(p.Pos()) + if err != nil { + return nil, err + } + modifiers = append(modifiers, modifier) + } else { + break + } + } + return &SelectItem{ + Expr: expr, + Modifiers: modifiers, + }, nil +} + func (p *Parser) parseColumnCaseExpr(pos Pos) (*CaseExpr, error) { // CASE expr caseExpr := &CaseExpr{CasePos: pos} diff --git a/parser/parser_query.go b/parser/parser_query.go index d981071..376ec3d 100644 --- a/parser/parser_query.go +++ b/parser/parser_query.go @@ -803,11 +803,15 @@ func (p *Parser) parseSelectStmt(pos Pos) (*SelectQuery, error) { // nolint: fun if err != nil { return nil, err } - selectColumns, err := p.parseColumnExprListWithRoundBracket(p.Pos()) + selectItems, err := p.parseSelectItems() if err != nil { return nil, err } - statementEnd := selectColumns.End() + + statementEnd := pos + if len(selectItems) > 0 { + statementEnd = selectItems[len(selectItems)-1].End() + } from, err := p.tryParseFromClause(p.Pos()) if err != nil { return nil, err @@ -916,24 +920,24 @@ func (p *Parser) parseSelectStmt(pos Pos) (*SelectQuery, error) { // nolint: fun } return &SelectQuery{ - With: withClause, - SelectPos: pos, - StatementEnd: statementEnd, - Top: top, - SelectColumns: selectColumns, - From: from, - ArrayJoin: arrayJoin, - Window: window, - Prewhere: prewhere, - Where: where, - GroupBy: groupBy, - Having: having, - OrderBy: orderBy, - LimitBy: limitBy, - Limit: limit, - Settings: settings, - Format: format, - WithTotal: withTotal, + With: withClause, + SelectPos: pos, + StatementEnd: statementEnd, + Top: top, + SelectItems: selectItems, + From: from, + ArrayJoin: arrayJoin, + Window: window, + Prewhere: prewhere, + Where: where, + GroupBy: groupBy, + Having: having, + OrderBy: orderBy, + LimitBy: limitBy, + Limit: limit, + Settings: settings, + Format: format, + WithTotal: withTotal, }, nil } diff --git a/parser/testdata/ddl/output/bug_001.sql.golden.json b/parser/testdata/ddl/output/bug_001.sql.golden.json index 1bf1334..6546f99 100644 --- a/parser/testdata/ddl/output/bug_001.sql.golden.json +++ b/parser/testdata/ddl/output/bug_001.sql.golden.json @@ -51,24 +51,27 @@ "StatementEnd": 635, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 118, - "ListEnd": 591, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Name": "event_ts", "QuoteType": 1, "NamePos": 118, "NameEnd": 126 }, - { + "Modifiers": [] + }, + { + "Expr": { "Name": "org_id", "QuoteType": 1, "NamePos": 132, "NameEnd": 138 }, - { + "Modifiers": [] + }, + { + "Expr": { "Expr": { "Name": { "Name": "visitParamExtractString", @@ -108,7 +111,10 @@ "NameEnd": 189 } }, - { + "Modifiers": [] + }, + { + "Expr": { "Expr": { "Name": { "Name": "visitParamExtractString", @@ -148,7 +154,10 @@ "NameEnd": 240 } }, - { + "Modifiers": [] + }, + { + "Expr": { "Expr": { "Name": { "Name": "visitParamExtractString", @@ -188,7 +197,10 @@ "NameEnd": 291 } }, - { + "Modifiers": [] + }, + { + "Expr": { "Expr": { "Name": { "Name": "visitParamExtractString", @@ -228,7 +240,10 @@ "NameEnd": 342 } }, - { + "Modifiers": [] + }, + { + "Expr": { "Expr": { "Name": { "Name": "visitParamExtractString", @@ -268,7 +283,10 @@ "NameEnd": 393 } }, - { + "Modifiers": [] + }, + { + "Expr": { "Expr": { "Name": { "Name": "visitParamExtractString", @@ -308,7 +326,10 @@ "NameEnd": 444 } }, - { + "Modifiers": [] + }, + { + "Expr": { "Expr": { "Name": { "Name": "visitParamExtractString", @@ -348,7 +369,10 @@ "NameEnd": 495 } }, - { + "Modifiers": [] + }, + { + "Expr": { "Expr": { "Name": { "Name": "visitParamExtractInt", @@ -388,7 +412,10 @@ "NameEnd": 543 } }, - { + "Modifiers": [] + }, + { + "Expr": { "Expr": { "Name": { "Name": "visitParamExtractInt", @@ -427,9 +454,10 @@ "NamePos": 590, "NameEnd": 591 } - } - ] - }, + }, + "Modifiers": [] + } + ], "From": { "FromPos": 592, "Expr": { diff --git a/parser/testdata/ddl/output/create_live_view_basic.sql.golden.json b/parser/testdata/ddl/output/create_live_view_basic.sql.golden.json index e8d127e..19b6e6c 100644 --- a/parser/testdata/ddl/output/create_live_view_basic.sql.golden.json +++ b/parser/testdata/ddl/output/create_live_view_basic.sql.golden.json @@ -82,19 +82,17 @@ "StatementEnd": 101, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 85, - "ListEnd": 87, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Name": "id", "QuoteType": 1, "NamePos": 85, "NameEnd": 87 - } - ] - }, + }, + "Modifiers": [] + } + ], "From": { "FromPos": 88, "Expr": { diff --git a/parser/testdata/ddl/output/create_materialized_view_basic.sql.golden.json b/parser/testdata/ddl/output/create_materialized_view_basic.sql.golden.json index 51b25c2..a7da2e6 100644 --- a/parser/testdata/ddl/output/create_materialized_view_basic.sql.golden.json +++ b/parser/testdata/ddl/output/create_materialized_view_basic.sql.golden.json @@ -248,24 +248,27 @@ "StatementEnd": 537, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 215, - "ListEnd": 456, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Name": "f1", "QuoteType": 1, "NamePos": 215, "NameEnd": 217 }, - { + "Modifiers": [] + }, + { + "Expr": { "Name": "f2", "QuoteType": 1, "NamePos": 226, "NameEnd": 228 }, - { + "Modifiers": [] + }, + { + "Expr": { "Expr": { "Name": { "Name": "visitParamExtractString", @@ -305,7 +308,10 @@ "NameEnd": 286 } }, - { + "Modifiers": [] + }, + { + "Expr": { "Expr": { "Name": { "Name": "visitParamExtractString", @@ -345,7 +351,10 @@ "NameEnd": 347 } }, - { + "Modifiers": [] + }, + { + "Expr": { "Expr": { "Name": { "Name": "visitParamExtractString", @@ -385,7 +394,10 @@ "NameEnd": 406 } }, - { + "Modifiers": [] + }, + { + "Expr": { "Expr": { "Name": { "Name": "visitParamExtractInt", @@ -424,9 +436,10 @@ "NamePos": 454, "NameEnd": 456 } - } - ] - }, + }, + "Modifiers": [] + } + ], "From": { "FromPos": 457, "Expr": { diff --git a/parser/testdata/ddl/output/create_materialized_view_with_empty_table_schema.sql.golden.json b/parser/testdata/ddl/output/create_materialized_view_with_empty_table_schema.sql.golden.json index ead806a..3dab6e6 100644 --- a/parser/testdata/ddl/output/create_materialized_view_with_empty_table_schema.sql.golden.json +++ b/parser/testdata/ddl/output/create_materialized_view_with_empty_table_schema.sql.golden.json @@ -129,30 +129,36 @@ "StatementEnd": 460, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 211, - "ListEnd": 243, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Name": "f0", "QuoteType": 1, "NamePos": 211, "NameEnd": 213 }, - { + "Modifiers": [] + }, + { + "Expr": { "Name": "f1", "QuoteType": 1, "NamePos": 214, "NameEnd": 216 }, - { + "Modifiers": [] + }, + { + "Expr": { "Name": "f2", "QuoteType": 1, "NamePos": 217, "NameEnd": 219 }, - { + "Modifiers": [] + }, + { + "Expr": { "Expr": { "Name": { "Name": "coalesce", @@ -192,9 +198,10 @@ "NamePos": 239, "NameEnd": 243 } - } - ] - }, + }, + "Modifiers": [] + } + ], "From": { "FromPos": 244, "Expr": { @@ -208,30 +215,36 @@ "StatementEnd": 433, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 270, - "ListEnd": 354, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Name": "f0", "QuoteType": 1, "NamePos": 270, "NameEnd": 272 }, - { + "Modifiers": [] + }, + { + "Expr": { "Name": "f1", "QuoteType": 1, "NamePos": 273, "NameEnd": 275 }, - { + "Modifiers": [] + }, + { + "Expr": { "Name": "f2", "QuoteType": 1, "NamePos": 276, "NameEnd": 278 }, - { + "Modifiers": [] + }, + { + "Expr": { "Expr": { "Function": { "Name": { @@ -324,9 +337,10 @@ "NamePos": 352, "NameEnd": 354 } - } - ] - }, + }, + "Modifiers": [] + } + ], "From": { "FromPos": 360, "Expr": { diff --git a/parser/testdata/ddl/output/create_view_basic.sql.golden.json b/parser/testdata/ddl/output/create_view_basic.sql.golden.json index a8cd120..333d47d 100644 --- a/parser/testdata/ddl/output/create_view_basic.sql.golden.json +++ b/parser/testdata/ddl/output/create_view_basic.sql.golden.json @@ -89,25 +89,26 @@ "StatementEnd": 104, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 74, - "ListEnd": 86, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Name": "id", "QuoteType": 1, "NamePos": 74, "NameEnd": 76 }, - { + "Modifiers": [] + }, + { + "Expr": { "Name": "name", "QuoteType": 1, "NamePos": 82, "NameEnd": 86 - } - ] - }, + }, + "Modifiers": [] + } + ], "From": { "FromPos": 87, "Expr": { diff --git a/parser/testdata/ddl/output/create_view_on_cluster_with_uuid.sql.golden.json b/parser/testdata/ddl/output/create_view_on_cluster_with_uuid.sql.golden.json index f5cf10a..3757f88 100644 --- a/parser/testdata/ddl/output/create_view_on_cluster_with_uuid.sql.golden.json +++ b/parser/testdata/ddl/output/create_view_on_cluster_with_uuid.sql.golden.json @@ -40,25 +40,26 @@ "StatementEnd": 199, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 151, - "ListEnd": 171, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Name": "column1", "QuoteType": 1, "NamePos": 151, "NameEnd": 158 }, - { + "Modifiers": [] + }, + { + "Expr": { "Name": "column2", "QuoteType": 1, "NamePos": 164, "NameEnd": 171 - } - ] - }, + }, + "Modifiers": [] + } + ], "From": { "FromPos": 176, "Expr": { diff --git a/parser/testdata/dml/output/insert_with_select.sql.golden.json b/parser/testdata/dml/output/insert_with_select.sql.golden.json index 28502bb..5872912 100644 --- a/parser/testdata/dml/output/insert_with_select.sql.golden.json +++ b/parser/testdata/dml/output/insert_with_select.sql.golden.json @@ -23,37 +23,44 @@ "StatementEnd": 103, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 40, - "ListEnd": 86, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Name": "CounterID", "QuoteType": 1, "NamePos": 40, "NameEnd": 49 }, - { + "Modifiers": [] + }, + { + "Expr": { "Name": "StartDate", "QuoteType": 1, "NamePos": 55, "NameEnd": 64 }, - { + "Modifiers": [] + }, + { + "Expr": { "Name": "Sign", "QuoteType": 1, "NamePos": 70, "NameEnd": 74 }, - { + "Modifiers": [] + }, + { + "Expr": { "Name": "UserID", "QuoteType": 1, "NamePos": 80, "NameEnd": 86 - } - ] - }, + }, + "Modifiers": [] + } + ], "From": { "FromPos": 87, "Expr": { diff --git a/parser/testdata/query/format/select_item_with_modifiers.sql b/parser/testdata/query/format/select_item_with_modifiers.sql new file mode 100644 index 0000000..c170697 --- /dev/null +++ b/parser/testdata/query/format/select_item_with_modifiers.sql @@ -0,0 +1,10 @@ +-- Origin SQL: +SELECT c0 REPLACE(c0 AS c1) FROM t0; +SELECT * REPLACE(i + 1 AS i) FROM t1; +SELECT * REPLACE(i + 1 AS i) EXCEPT (j) APPLY(sum) from t2; + + +-- Format SQL: +SELECT c0 REPLACE(c0 AS c1) FROM t0; +SELECT * REPLACE(i + 1 AS i) FROM t1; +SELECT * REPLACE(i + 1 AS i) EXCEPT(j) APPLY(sum) FROM t2; diff --git a/parser/testdata/query/output/select_cast.sql.golden.json b/parser/testdata/query/output/select_cast.sql.golden.json index bab844b..9bb5cbe 100644 --- a/parser/testdata/query/output/select_cast.sql.golden.json +++ b/parser/testdata/query/output/select_cast.sql.golden.json @@ -4,12 +4,9 @@ "StatementEnd": 34, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 7, - "ListEnd": 34, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Expr": { "CastPos": 7, "Expr": { @@ -36,9 +33,10 @@ "NamePos": 29, "NameEnd": 34 } - } - ] - }, + }, + "Modifiers": [] + } + ], "From": null, "ArrayJoin": null, "Window": null, @@ -61,12 +59,9 @@ "StatementEnd": 70, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 43, - "ListEnd": 70, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Expr": { "CastPos": 43, "Expr": { @@ -90,9 +85,10 @@ "NamePos": 65, "NameEnd": 70 } - } - ] - }, + }, + "Modifiers": [] + } + ], "From": null, "ArrayJoin": null, "Window": null, @@ -115,12 +111,9 @@ "StatementEnd": 102, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 79, - "ListEnd": 102, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Expr": { "LeftParenPos": 79, "RightParenPos": 92, @@ -155,9 +148,10 @@ "NamePos": 97, "NameEnd": 102 } - } - ] - }, + }, + "Modifiers": [] + } + ], "From": null, "ArrayJoin": null, "Window": null, @@ -180,12 +174,9 @@ "StatementEnd": 130, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 111, - "ListEnd": 130, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Expr": { "LeftExpr": { "NumPos": 111, @@ -210,9 +201,10 @@ "NamePos": 125, "NameEnd": 130 } - } - ] - }, + }, + "Modifiers": [] + } + ], "From": null, "ArrayJoin": null, "Window": null, diff --git a/parser/testdata/query/output/select_column_alias_string.sql.golden.json b/parser/testdata/query/output/select_column_alias_string.sql.golden.json index 25e1997..38b505c 100644 --- a/parser/testdata/query/output/select_column_alias_string.sql.golden.json +++ b/parser/testdata/query/output/select_column_alias_string.sql.golden.json @@ -4,12 +4,9 @@ "StatementEnd": 23, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 8, - "ListEnd": 23, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Expr": { "LiteralPos": 8, "LiteralEnd": 11, @@ -22,9 +19,10 @@ "NamePos": 17, "NameEnd": 23 } - } - ] - }, + }, + "Modifiers": [] + } + ], "From": null, "ArrayJoin": null, "Window": null, diff --git a/parser/testdata/query/output/select_expr.sql.golden.json b/parser/testdata/query/output/select_expr.sql.golden.json index 088d53b..b7583d6 100644 --- a/parser/testdata/query/output/select_expr.sql.golden.json +++ b/parser/testdata/query/output/select_expr.sql.golden.json @@ -4,12 +4,9 @@ "StatementEnd": 10, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 7, - "ListEnd": 10, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "LeftExpr": { "NumPos": 7, "NumEnd": 8, @@ -25,9 +22,10 @@ }, "HasGlobal": false, "HasNot": false - } - ] - }, + }, + "Modifiers": [] + } + ], "From": null, "ArrayJoin": null, "Window": null, diff --git a/parser/testdata/query/output/select_item_with_modifiers.sql.golden.json b/parser/testdata/query/output/select_item_with_modifiers.sql.golden.json new file mode 100644 index 0000000..e2a1213 --- /dev/null +++ b/parser/testdata/query/output/select_item_with_modifiers.sql.golden.json @@ -0,0 +1,349 @@ +[ + { + "SelectPos": 0, + "StatementEnd": 35, + "With": null, + "Top": null, + "SelectItems": [ + { + "Expr": { + "Name": "c0", + "QuoteType": 1, + "NamePos": 7, + "NameEnd": 9 + }, + "Modifiers": [ + { + "Name": { + "Name": "REPLACE", + "QuoteType": 1, + "NamePos": 10, + "NameEnd": 17 + }, + "Params": { + "LeftParenPos": 17, + "RightParenPos": 26, + "Items": { + "ListPos": 18, + "ListEnd": 26, + "HasDistinct": false, + "Items": [ + { + "Expr": { + "Name": "c0", + "QuoteType": 1, + "NamePos": 18, + "NameEnd": 20 + }, + "AliasPos": 24, + "Alias": { + "Name": "c1", + "QuoteType": 1, + "NamePos": 24, + "NameEnd": 26 + } + } + ] + }, + "ColumnArgList": null + } + } + ] + } + ], + "From": { + "FromPos": 28, + "Expr": { + "Table": { + "TablePos": 33, + "TableEnd": 35, + "Alias": null, + "Expr": { + "Database": null, + "Table": { + "Name": "t0", + "QuoteType": 1, + "NamePos": 33, + "NameEnd": 35 + } + }, + "HasFinal": false + }, + "StatementEnd": 35, + "SampleRatio": null, + "HasFinal": false + } + }, + "ArrayJoin": null, + "Window": null, + "Prewhere": null, + "Where": null, + "GroupBy": null, + "WithTotal": false, + "Having": null, + "OrderBy": null, + "LimitBy": null, + "Limit": null, + "Settings": null, + "Format": null, + "UnionAll": null, + "UnionDistinct": null, + "Except": null + }, + { + "SelectPos": 37, + "StatementEnd": 73, + "With": null, + "Top": null, + "SelectItems": [ + { + "Expr": { + "Name": "*", + "QuoteType": 0, + "NamePos": 44, + "NameEnd": 44 + }, + "Modifiers": [ + { + "Name": { + "Name": "REPLACE", + "QuoteType": 1, + "NamePos": 46, + "NameEnd": 53 + }, + "Params": { + "LeftParenPos": 53, + "RightParenPos": 64, + "Items": { + "ListPos": 54, + "ListEnd": 64, + "HasDistinct": false, + "Items": [ + { + "Expr": { + "LeftExpr": { + "Name": "i", + "QuoteType": 1, + "NamePos": 54, + "NameEnd": 55 + }, + "Operation": "+", + "RightExpr": { + "NumPos": 58, + "NumEnd": 59, + "Literal": "1", + "Base": 10 + }, + "HasGlobal": false, + "HasNot": false + }, + "AliasPos": 63, + "Alias": { + "Name": "i", + "QuoteType": 1, + "NamePos": 63, + "NameEnd": 64 + } + } + ] + }, + "ColumnArgList": null + } + } + ] + } + ], + "From": { + "FromPos": 66, + "Expr": { + "Table": { + "TablePos": 71, + "TableEnd": 73, + "Alias": null, + "Expr": { + "Database": null, + "Table": { + "Name": "t1", + "QuoteType": 1, + "NamePos": 71, + "NameEnd": 73 + } + }, + "HasFinal": false + }, + "StatementEnd": 73, + "SampleRatio": null, + "HasFinal": false + } + }, + "ArrayJoin": null, + "Window": null, + "Prewhere": null, + "Where": null, + "GroupBy": null, + "WithTotal": false, + "Having": null, + "OrderBy": null, + "LimitBy": null, + "Limit": null, + "Settings": null, + "Format": null, + "UnionAll": null, + "UnionDistinct": null, + "Except": null + }, + { + "SelectPos": 75, + "StatementEnd": 133, + "With": null, + "Top": null, + "SelectItems": [ + { + "Expr": { + "Name": "*", + "QuoteType": 0, + "NamePos": 82, + "NameEnd": 82 + }, + "Modifiers": [ + { + "Name": { + "Name": "REPLACE", + "QuoteType": 1, + "NamePos": 84, + "NameEnd": 91 + }, + "Params": { + "LeftParenPos": 91, + "RightParenPos": 102, + "Items": { + "ListPos": 92, + "ListEnd": 102, + "HasDistinct": false, + "Items": [ + { + "Expr": { + "LeftExpr": { + "Name": "i", + "QuoteType": 1, + "NamePos": 92, + "NameEnd": 93 + }, + "Operation": "+", + "RightExpr": { + "NumPos": 96, + "NumEnd": 97, + "Literal": "1", + "Base": 10 + }, + "HasGlobal": false, + "HasNot": false + }, + "AliasPos": 101, + "Alias": { + "Name": "i", + "QuoteType": 1, + "NamePos": 101, + "NameEnd": 102 + } + } + ] + }, + "ColumnArgList": null + } + }, + { + "Name": { + "Name": "EXCEPT", + "QuoteType": 1, + "NamePos": 104, + "NameEnd": 110 + }, + "Params": { + "LeftParenPos": 111, + "RightParenPos": 113, + "Items": { + "ListPos": 112, + "ListEnd": 113, + "HasDistinct": false, + "Items": [ + { + "Name": "j", + "QuoteType": 1, + "NamePos": 112, + "NameEnd": 113 + } + ] + }, + "ColumnArgList": null + } + }, + { + "Name": { + "Name": "APPLY", + "QuoteType": 1, + "NamePos": 115, + "NameEnd": 120 + }, + "Params": { + "LeftParenPos": 120, + "RightParenPos": 124, + "Items": { + "ListPos": 121, + "ListEnd": 124, + "HasDistinct": false, + "Items": [ + { + "Name": "sum", + "QuoteType": 1, + "NamePos": 121, + "NameEnd": 124 + } + ] + }, + "ColumnArgList": null + } + } + ] + } + ], + "From": { + "FromPos": 126, + "Expr": { + "Table": { + "TablePos": 131, + "TableEnd": 133, + "Alias": null, + "Expr": { + "Database": null, + "Table": { + "Name": "t2", + "QuoteType": 1, + "NamePos": 131, + "NameEnd": 133 + } + }, + "HasFinal": false + }, + "StatementEnd": 133, + "SampleRatio": null, + "HasFinal": false + } + }, + "ArrayJoin": null, + "Window": null, + "Prewhere": null, + "Where": null, + "GroupBy": null, + "WithTotal": false, + "Having": null, + "OrderBy": null, + "LimitBy": null, + "Limit": null, + "Settings": null, + "Format": null, + "UnionAll": null, + "UnionDistinct": null, + "Except": null + } +] \ No newline at end of file diff --git a/parser/testdata/query/output/select_order_by_timestamp.sql.golden.json b/parser/testdata/query/output/select_order_by_timestamp.sql.golden.json index 4ac287c..fb9b0ee 100644 --- a/parser/testdata/query/output/select_order_by_timestamp.sql.golden.json +++ b/parser/testdata/query/output/select_order_by_timestamp.sql.golden.json @@ -4,19 +4,17 @@ "StatementEnd": 47, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 7, - "ListEnd": 16, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Name": "Timestamp", "QuoteType": 1, "NamePos": 7, "NameEnd": 16 - } - ] - }, + }, + "Modifiers": [] + } + ], "From": { "FromPos": 17, "Expr": { diff --git a/parser/testdata/query/output/select_simple.sql.golden.json b/parser/testdata/query/output/select_simple.sql.golden.json index f6c6d37..780ce58 100644 --- a/parser/testdata/query/output/select_simple.sql.golden.json +++ b/parser/testdata/query/output/select_simple.sql.golden.json @@ -4,18 +4,18 @@ "StatementEnd": 277, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 11, - "ListEnd": 96, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Name": "f0", "QuoteType": 1, "NamePos": 11, "NameEnd": 13 }, - { + "Modifiers": [] + }, + { + "Expr": { "Expr": { "Name": { "Name": "coalesce", @@ -56,7 +56,10 @@ "NameEnd": 37 } }, - { + "Modifiers": [] + }, + { + "Expr": { "Expr": { "Function": { "Name": { @@ -123,9 +126,10 @@ "NamePos": 94, "NameEnd": 96 } - } - ] - }, + }, + "Modifiers": [] + } + ], "From": { "FromPos": 97, "Expr": { diff --git a/parser/testdata/query/output/select_simple_with_bracket.sql.golden.json b/parser/testdata/query/output/select_simple_with_bracket.sql.golden.json index 8c12b68..947e5ba 100644 --- a/parser/testdata/query/output/select_simple_with_bracket.sql.golden.json +++ b/parser/testdata/query/output/select_simple_with_bracket.sql.golden.json @@ -4,12 +4,9 @@ "StatementEnd": 66, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 7, - "ListEnd": 66, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Expr": { "Name": { "Name": "arrayConcat", @@ -107,7 +104,10 @@ "NameEnd": 49 } }, - { + "Modifiers": [] + }, + { + "Expr": { "Expr": { "Object": { "Name": "f1", @@ -140,9 +140,10 @@ "NamePos": 64, "NameEnd": 66 } - } - ] - }, + }, + "Modifiers": [] + } + ], "From": null, "ArrayJoin": null, "Window": null, diff --git a/parser/testdata/query/output/select_simple_with_cte_with_column_aliases.sql.golden.json b/parser/testdata/query/output/select_simple_with_cte_with_column_aliases.sql.golden.json index d46ee71..6ef5312 100644 --- a/parser/testdata/query/output/select_simple_with_cte_with_column_aliases.sql.golden.json +++ b/parser/testdata/query/output/select_simple_with_cte_with_column_aliases.sql.golden.json @@ -51,31 +51,35 @@ "StatementEnd": 58, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 37, - "ListEnd": 47, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Name": "f4", "QuoteType": 1, "NamePos": 37, "NameEnd": 39 }, - { + "Modifiers": [] + }, + { + "Expr": { "Name": "f5", "QuoteType": 1, "NamePos": 41, "NameEnd": 43 }, - { + "Modifiers": [] + }, + { + "Expr": { "Name": "f6", "QuoteType": 1, "NamePos": 45, "NameEnd": 47 - } - ] - }, + }, + "Modifiers": [] + } + ], "From": { "FromPos": 48, "Expr": { @@ -119,12 +123,9 @@ ] }, "Top": null, - "SelectColumns": { - "ListPos": 71, - "ListEnd": 119, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Expr": { "Name": "f1", "QuoteType": 1, @@ -139,7 +140,10 @@ "NameEnd": 83 } }, - { + "Modifiers": [] + }, + { + "Expr": { "Expr": { "Name": "f2", "QuoteType": 1, @@ -154,7 +158,10 @@ "NameEnd": 101 } }, - { + "Modifiers": [] + }, + { + "Expr": { "Expr": { "Name": "f3", "QuoteType": 1, @@ -168,9 +175,10 @@ "NamePos": 113, "NameEnd": 119 } - } - ] - }, + }, + "Modifiers": [] + } + ], "From": { "FromPos": 120, "Expr": { diff --git a/parser/testdata/query/output/select_simple_with_group_by_with_cube_totals.sql.golden.json b/parser/testdata/query/output/select_simple_with_group_by_with_cube_totals.sql.golden.json index 5028eed..c6c2a47 100644 --- a/parser/testdata/query/output/select_simple_with_group_by_with_cube_totals.sql.golden.json +++ b/parser/testdata/query/output/select_simple_with_group_by_with_cube_totals.sql.golden.json @@ -4,18 +4,18 @@ "StatementEnd": 86, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 7, - "ListEnd": 17, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Name": "a", "QuoteType": 1, "NamePos": 7, "NameEnd": 8 }, - { + "Modifiers": [] + }, + { + "Expr": { "Name": { "Name": "COUNT", "QuoteType": 1, @@ -40,9 +40,10 @@ }, "ColumnArgList": null } - } - ] - }, + }, + "Modifiers": [] + } + ], "From": { "FromPos": 19, "Expr": { diff --git a/parser/testdata/query/output/select_simple_with_is_not_null.sql.golden.json b/parser/testdata/query/output/select_simple_with_is_not_null.sql.golden.json index 4867063..26d471d 100644 --- a/parser/testdata/query/output/select_simple_with_is_not_null.sql.golden.json +++ b/parser/testdata/query/output/select_simple_with_is_not_null.sql.golden.json @@ -4,30 +4,36 @@ "StatementEnd": 133, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 7, - "ListEnd": 24, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Name": "f0", "QuoteType": 1, "NamePos": 7, "NameEnd": 9 }, - { + "Modifiers": [] + }, + { + "Expr": { "Name": "f1", "QuoteType": 1, "NamePos": 10, "NameEnd": 12 }, - { + "Modifiers": [] + }, + { + "Expr": { "Name": "f2", "QuoteType": 1, "NamePos": 13, "NameEnd": 15 }, - { + "Modifiers": [] + }, + { + "Expr": { "Expr": { "Name": "f3", "QuoteType": 1, @@ -41,9 +47,10 @@ "NamePos": 22, "NameEnd": 24 } - } - ] - }, + }, + "Modifiers": [] + } + ], "From": { "FromPos": 25, "Expr": { diff --git a/parser/testdata/query/output/select_simple_with_is_null.sql.golden.json b/parser/testdata/query/output/select_simple_with_is_null.sql.golden.json index f6c0114..ec1a135 100644 --- a/parser/testdata/query/output/select_simple_with_is_null.sql.golden.json +++ b/parser/testdata/query/output/select_simple_with_is_null.sql.golden.json @@ -4,30 +4,36 @@ "StatementEnd": 112, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 7, - "ListEnd": 24, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Name": "f0", "QuoteType": 1, "NamePos": 7, "NameEnd": 9 }, - { + "Modifiers": [] + }, + { + "Expr": { "Name": "f1", "QuoteType": 1, "NamePos": 10, "NameEnd": 12 }, - { + "Modifiers": [] + }, + { + "Expr": { "Name": "f2", "QuoteType": 1, "NamePos": 13, "NameEnd": 15 }, - { + "Modifiers": [] + }, + { + "Expr": { "Expr": { "Name": "f3", "QuoteType": 1, @@ -41,9 +47,10 @@ "NamePos": 22, "NameEnd": 24 } - } - ] - }, + }, + "Modifiers": [] + } + ], "From": { "FromPos": 25, "Expr": { diff --git a/parser/testdata/query/output/select_simple_with_top_clause.sql.golden.json b/parser/testdata/query/output/select_simple_with_top_clause.sql.golden.json index c584082..2d79b96 100644 --- a/parser/testdata/query/output/select_simple_with_top_clause.sql.golden.json +++ b/parser/testdata/query/output/select_simple_with_top_clause.sql.golden.json @@ -14,19 +14,17 @@ }, "WithTies": false }, - "SelectColumns": { - "ListPos": 14, - "ListEnd": 23, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Name": "my_column", "QuoteType": 1, "NamePos": 14, "NameEnd": 23 - } - ] - }, + }, + "Modifiers": [] + } + ], "From": { "FromPos": 24, "Expr": { diff --git a/parser/testdata/query/output/select_simple_with_with_clause.sql.golden.json b/parser/testdata/query/output/select_simple_with_with_clause.sql.golden.json index a0dddd9..b12ec1b 100644 --- a/parser/testdata/query/output/select_simple_with_with_clause.sql.golden.json +++ b/parser/testdata/query/output/select_simple_with_with_clause.sql.golden.json @@ -19,19 +19,17 @@ "StatementEnd": 35, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 25, - "ListEnd": 27, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Name": "f1", "QuoteType": 1, "NamePos": 25, "NameEnd": 27 - } - ] - }, + }, + "Modifiers": [] + } + ], "From": { "FromPos": 28, "Expr": { @@ -85,19 +83,17 @@ "StatementEnd": 68, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 58, - "ListEnd": 60, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Name": "f2", "QuoteType": 1, "NamePos": 58, "NameEnd": 60 - } - ] - }, + }, + "Modifiers": [] + } + ], "From": { "FromPos": 61, "Expr": { @@ -141,12 +137,9 @@ ] }, "Top": null, - "SelectColumns": { - "ListPos": 81, - "ListEnd": 112, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Database": null, "Table": { "Name": "cte1", @@ -161,7 +154,10 @@ "NameEnd": 88 } }, - { + "Modifiers": [] + }, + { + "Expr": { "Database": null, "Table": { "Name": "cte2", @@ -176,7 +172,10 @@ "NameEnd": 101 } }, - { + "Modifiers": [] + }, + { + "Expr": { "Database": null, "Table": { "Name": "t3", @@ -190,9 +189,10 @@ "NamePos": 110, "NameEnd": 112 } - } - ] - }, + }, + "Modifiers": [] + } + ], "From": { "FromPos": 113, "Expr": { diff --git a/parser/testdata/query/output/select_table_alias_without_keyword.sql.golden.json b/parser/testdata/query/output/select_table_alias_without_keyword.sql.golden.json index 1487980..2903a11 100644 --- a/parser/testdata/query/output/select_table_alias_without_keyword.sql.golden.json +++ b/parser/testdata/query/output/select_table_alias_without_keyword.sql.golden.json @@ -4,12 +4,9 @@ "StatementEnd": 36, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 7, - "ListEnd": 19, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Database": null, "Table": { "Name": "t1", @@ -23,9 +20,10 @@ "NamePos": 10, "NameEnd": 19 } - } - ] - }, + }, + "Modifiers": [] + } + ], "From": { "FromPos": 20, "Expr": { diff --git a/parser/testdata/query/output/select_when_condition.sql.golden.json b/parser/testdata/query/output/select_when_condition.sql.golden.json index c51c10c..efe9774 100644 --- a/parser/testdata/query/output/select_when_condition.sql.golden.json +++ b/parser/testdata/query/output/select_when_condition.sql.golden.json @@ -4,12 +4,9 @@ "StatementEnd": 0, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 7, - "ListEnd": 0, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "CasePos": 7, "EndPos": 0, "Expr": null, @@ -38,9 +35,10 @@ "LiteralEnd": 47, "Literal": "world" } - } - ] - }, + }, + "Modifiers": [] + } + ], "From": null, "ArrayJoin": null, "Window": null, diff --git a/parser/testdata/query/output/select_with_join_only.sql.golden.json b/parser/testdata/query/output/select_with_join_only.sql.golden.json index 2e61223..bbfb30c 100644 --- a/parser/testdata/query/output/select_with_join_only.sql.golden.json +++ b/parser/testdata/query/output/select_with_join_only.sql.golden.json @@ -4,19 +4,17 @@ "StatementEnd": 17, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 7, - "ListEnd": 7, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Name": "*", "QuoteType": 0, "NamePos": 7, "NameEnd": 7 - } - ] - }, + }, + "Modifiers": [] + } + ], "From": { "FromPos": 9, "Expr": { diff --git a/parser/testdata/query/output/select_with_left_join.sql.golden.json b/parser/testdata/query/output/select_with_left_join.sql.golden.json index 2ea4c66..5704615 100644 --- a/parser/testdata/query/output/select_with_left_join.sql.golden.json +++ b/parser/testdata/query/output/select_with_left_join.sql.golden.json @@ -19,12 +19,9 @@ "StatementEnd": 54, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 44, - "ListEnd": 54, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Expr": { "NumPos": 44, "NumEnd": 45, @@ -38,9 +35,10 @@ "NamePos": 49, "NameEnd": 54 } - } - ] - }, + }, + "Modifiers": [] + } + ], "From": null, "ArrayJoin": null, "Window": null, @@ -72,12 +70,9 @@ "StatementEnd": 98, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 88, - "ListEnd": 98, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Expr": { "NumPos": 88, "NumEnd": 89, @@ -91,9 +86,10 @@ "NamePos": 93, "NameEnd": 98 } - } - ] - }, + }, + "Modifiers": [] + } + ], "From": null, "ArrayJoin": null, "Window": null, @@ -115,19 +111,17 @@ ] }, "Top": null, - "SelectColumns": { - "ListPos": 112, - "ListEnd": 112, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Name": "*", "QuoteType": 0, "NamePos": 112, "NameEnd": 112 - } - ] - }, + }, + "Modifiers": [] + } + ], "From": { "FromPos": 114, "Expr": { diff --git a/parser/testdata/query/output/select_with_literal_table_name.sql.golden.json b/parser/testdata/query/output/select_with_literal_table_name.sql.golden.json index 4f8a106..e9070ad 100644 --- a/parser/testdata/query/output/select_with_literal_table_name.sql.golden.json +++ b/parser/testdata/query/output/select_with_literal_table_name.sql.golden.json @@ -4,19 +4,17 @@ "StatementEnd": 60, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 7, - "ListEnd": 17, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Name": "table_name", "QuoteType": 1, "NamePos": 7, "NameEnd": 17 - } - ] - }, + }, + "Modifiers": [] + } + ], "From": { "FromPos": 18, "Expr": { diff --git a/parser/testdata/query/output/select_with_multi_join.sql.golden.json b/parser/testdata/query/output/select_with_multi_join.sql.golden.json index 5113869..b6d3427 100644 --- a/parser/testdata/query/output/select_with_multi_join.sql.golden.json +++ b/parser/testdata/query/output/select_with_multi_join.sql.golden.json @@ -19,12 +19,9 @@ "StatementEnd": 41, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 25, - "ListEnd": 41, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Expr": { "LiteralPos": 25, "LiteralEnd": 31, @@ -37,9 +34,10 @@ "NamePos": 36, "NameEnd": 41 } - } - ] - }, + }, + "Modifiers": [] + } + ], "From": null, "ArrayJoin": null, "Window": null, @@ -71,12 +69,9 @@ "StatementEnd": 81, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 65, - "ListEnd": 81, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Expr": { "LiteralPos": 65, "LiteralEnd": 71, @@ -89,9 +84,10 @@ "NamePos": 76, "NameEnd": 81 } - } - ] - }, + }, + "Modifiers": [] + } + ], "From": null, "ArrayJoin": null, "Window": null, @@ -123,12 +119,9 @@ "StatementEnd": 121, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 105, - "ListEnd": 121, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Expr": { "LiteralPos": 105, "LiteralEnd": 111, @@ -141,9 +134,10 @@ "NamePos": 116, "NameEnd": 121 } - } - ] - }, + }, + "Modifiers": [] + } + ], "From": null, "ArrayJoin": null, "Window": null, @@ -165,12 +159,9 @@ ] }, "Top": null, - "SelectColumns": { - "ListPos": 139, - "ListEnd": 205, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Expr": { "Database": null, "Table": { @@ -194,7 +185,10 @@ "NameEnd": 157 } }, - { + "Modifiers": [] + }, + { + "Expr": { "Expr": { "Database": null, "Table": { @@ -218,7 +212,10 @@ "NameEnd": 181 } }, - { + "Modifiers": [] + }, + { + "Expr": { "Expr": { "Database": null, "Table": { @@ -241,9 +238,10 @@ "NamePos": 199, "NameEnd": 205 } - } - ] - }, + }, + "Modifiers": [] + } + ], "From": { "FromPos": 206, "Expr": { diff --git a/parser/testdata/query/output/select_with_multi_line_comment.sql.golden.json b/parser/testdata/query/output/select_with_multi_line_comment.sql.golden.json index 2a6b80e..1633180 100644 --- a/parser/testdata/query/output/select_with_multi_line_comment.sql.golden.json +++ b/parser/testdata/query/output/select_with_multi_line_comment.sql.golden.json @@ -4,19 +4,17 @@ "StatementEnd": 61, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 48, - "ListEnd": 48, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Name": "*", "QuoteType": 0, "NamePos": 48, "NameEnd": 48 - } - ] - }, + }, + "Modifiers": [] + } + ], "From": { "FromPos": 50, "Expr": { diff --git a/parser/testdata/query/output/select_with_multi_union.sql.golden.json b/parser/testdata/query/output/select_with_multi_union.sql.golden.json index 0535e66..76349ed 100644 --- a/parser/testdata/query/output/select_with_multi_union.sql.golden.json +++ b/parser/testdata/query/output/select_with_multi_union.sql.golden.json @@ -4,12 +4,9 @@ "StatementEnd": 14, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 7, - "ListEnd": 14, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Expr": { "NumPos": 7, "NumEnd": 8, @@ -23,9 +20,10 @@ "NamePos": 12, "NameEnd": 14 } - } - ] - }, + }, + "Modifiers": [] + } + ], "From": null, "ArrayJoin": null, "Window": null, @@ -44,12 +42,9 @@ "StatementEnd": 39, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 32, - "ListEnd": 39, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Expr": { "NumPos": 32, "NumEnd": 33, @@ -63,9 +58,10 @@ "NamePos": 37, "NameEnd": 39 } - } - ] - }, + }, + "Modifiers": [] + } + ], "From": null, "ArrayJoin": null, "Window": null, @@ -84,12 +80,9 @@ "StatementEnd": 64, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 57, - "ListEnd": 64, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Expr": { "NumPos": 57, "NumEnd": 58, @@ -103,9 +96,10 @@ "NamePos": 62, "NameEnd": 64 } - } - ] - }, + }, + "Modifiers": [] + } + ], "From": null, "ArrayJoin": null, "Window": null, diff --git a/parser/testdata/query/output/select_with_query_parameter.sql.golden.json b/parser/testdata/query/output/select_with_query_parameter.sql.golden.json index 4be4217..a61d054 100644 --- a/parser/testdata/query/output/select_with_query_parameter.sql.golden.json +++ b/parser/testdata/query/output/select_with_query_parameter.sql.golden.json @@ -158,12 +158,9 @@ "StatementEnd": 218, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 136, - "ListEnd": 218, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "LBracePos": 136, "RBracePos": 146, "Name": { @@ -181,7 +178,10 @@ } } }, - { + "Modifiers": [] + }, + { + "Expr": { "LBracePos": 153, "RBracePos": 163, "Name": { @@ -199,7 +199,10 @@ } } }, - { + "Modifiers": [] + }, + { + "Expr": { "LBracePos": 170, "RBracePos": 182, "Name": { @@ -217,7 +220,10 @@ } } }, - { + "Modifiers": [] + }, + { + "Expr": { "LBracePos": 189, "RBracePos": 218, "Name": { @@ -266,9 +272,10 @@ } ] } - } - ] - }, + }, + "Modifiers": [] + } + ], "From": null, "ArrayJoin": null, "Window": null, @@ -291,19 +298,17 @@ "StatementEnd": 283, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 229, - "ListEnd": 229, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Name": "*", "QuoteType": 0, "NamePos": 229, "NameEnd": 229 - } - ] - }, + }, + "Modifiers": [] + } + ], "From": { "FromPos": 231, "Expr": { diff --git a/parser/testdata/query/output/select_with_string_expr.sql.golden.json b/parser/testdata/query/output/select_with_string_expr.sql.golden.json index 1872786..9f65a73 100644 --- a/parser/testdata/query/output/select_with_string_expr.sql.golden.json +++ b/parser/testdata/query/output/select_with_string_expr.sql.golden.json @@ -19,12 +19,9 @@ "StatementEnd": 28, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 22, - "ListEnd": 28, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Expr": { "NumPos": 22, "NumEnd": 23, @@ -38,9 +35,10 @@ "NamePos": 27, "NameEnd": 28 } - } - ] - }, + }, + "Modifiers": [] + } + ], "From": null, "ArrayJoin": null, "Window": null, @@ -62,19 +60,17 @@ ] }, "Top": null, - "SelectColumns": { - "ListPos": 37, - "ListEnd": 37, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Name": "*", "QuoteType": 0, "NamePos": 37, "NameEnd": 37 - } - ] - }, + }, + "Modifiers": [] + } + ], "From": { "FromPos": 39, "Expr": { diff --git a/parser/testdata/query/output/select_with_union_distinct.sql.golden.json b/parser/testdata/query/output/select_with_union_distinct.sql.golden.json index a98c0b0..979b52e 100644 --- a/parser/testdata/query/output/select_with_union_distinct.sql.golden.json +++ b/parser/testdata/query/output/select_with_union_distinct.sql.golden.json @@ -4,19 +4,17 @@ "StatementEnd": 43, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 7, - "ListEnd": 19, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Name": "replica_name", "QuoteType": 1, "NamePos": 7, "NameEnd": 19 - } - ] - }, + }, + "Modifiers": [] + } + ], "From": { "FromPos": 20, "Expr": { @@ -63,19 +61,17 @@ "StatementEnd": 121, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 66, - "ListEnd": 78, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Name": "replica_name", "QuoteType": 1, "NamePos": 66, "NameEnd": 78 - } - ] - }, + }, + "Modifiers": [] + } + ], "From": { "FromPos": 79, "Expr": { diff --git a/parser/testdata/query/output/select_with_variable.sql.golden.json b/parser/testdata/query/output/select_with_variable.sql.golden.json index e27d903..e87c2f1 100644 --- a/parser/testdata/query/output/select_with_variable.sql.golden.json +++ b/parser/testdata/query/output/select_with_variable.sql.golden.json @@ -19,12 +19,9 @@ "StatementEnd": 27, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 21, - "ListEnd": 27, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Expr": { "NumPos": 21, "NumEnd": 22, @@ -38,9 +35,10 @@ "NamePos": 26, "NameEnd": 27 } - } - ] - }, + }, + "Modifiers": [] + } + ], "From": null, "ArrayJoin": null, "Window": null, @@ -62,19 +60,17 @@ ] }, "Top": null, - "SelectColumns": { - "ListPos": 36, - "ListEnd": 36, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Name": "*", "QuoteType": 0, "NamePos": 36, "NameEnd": 36 - } - ] - }, + }, + "Modifiers": [] + } + ], "From": { "FromPos": 38, "Expr": { diff --git a/parser/testdata/query/output/selelct_with_placeholder.sql.golden.json b/parser/testdata/query/output/selelct_with_placeholder.sql.golden.json index 5173b07..8cb197a 100644 --- a/parser/testdata/query/output/selelct_with_placeholder.sql.golden.json +++ b/parser/testdata/query/output/selelct_with_placeholder.sql.golden.json @@ -4,19 +4,17 @@ "StatementEnd": 28, "With": null, "Top": null, - "SelectColumns": { - "ListPos": 7, - "ListEnd": 7, - "HasDistinct": false, - "Items": [ - { + "SelectItems": [ + { + "Expr": { "Name": "*", "QuoteType": 0, "NamePos": 7, "NameEnd": 7 - } - ] - }, + }, + "Modifiers": [] + } + ], "From": { "FromPos": 9, "Expr": { diff --git a/parser/testdata/query/select_item_with_modifiers.sql b/parser/testdata/query/select_item_with_modifiers.sql new file mode 100644 index 0000000..dc1e150 --- /dev/null +++ b/parser/testdata/query/select_item_with_modifiers.sql @@ -0,0 +1,3 @@ +SELECT c0 REPLACE(c0 AS c1) FROM t0; +SELECT * REPLACE(i + 1 AS i) FROM t1; +SELECT * REPLACE(i + 1 AS i) EXCEPT (j) APPLY(sum) from t2;