From 675fd43f6bb028ac57d415e0bfd7fe4b43624c6d Mon Sep 17 00:00:00 2001 From: hulk Date: Thu, 26 Sep 2024 14:26:37 +0800 Subject: [PATCH] Refactor parseExpr to allow to use the priority precedence (#102) --- parser/ast.go | 154 +++-- parser/ast_visitor.go | 20 +- parser/lexer.go | 7 + parser/parser_column.go | 341 +++++------ parser/parser_query.go | 60 +- parser/parser_table.go | 19 +- parser/parser_view.go | 28 +- parser/testdata/ddl/format/bug_001.sql | 2 +- .../ddl/format/create_live_view_basic.sql | 2 +- .../format/create_materialized_view_basic.sql | 2 +- ...erialized_view_with_empty_table_schema.sql | 2 +- .../testdata/ddl/format/create_view_basic.sql | 2 +- .../alter_table_add_index.sql.golden.json | 80 ++- ...alter_table_add_projection.sql.golden.json | 33 +- .../output/attach_table_basic.sql.golden.json | 104 ++-- .../ddl/output/bug_001.sql.golden.json | 575 +++++++++--------- .../create_distributed_table.sql.golden.json | 68 ++- .../create_function_simple.sql.golden.json | 33 +- .../create_live_view_basic.sql.golden.json | 5 +- ...te_materialized_view_basic.sql.golden.json | 260 ++++---- ...ew_with_empty_table_schema.sql.golden.json | 462 +++++++------- .../output/create_table_basic.sql.golden.json | 167 ++--- ...ate_table_with_codec_delta.sql.golden.json | 192 +++--- .../create_table_with_index.sql.golden.json | 211 ++++--- ..._with_keyword_partition_by.sql.golden.json | 34 +- ...create_table_with_nullable.sql.golden.json | 73 ++- ...eate_table_with_on_clsuter.sql.golden.json | 104 ++-- ...reate_table_with_sample_by.sql.golden.json | 145 +++-- .../create_table_with_uuid.sql.golden.json | 104 ++-- .../output/create_view_basic.sql.golden.json | 8 +- ..._view_on_cluster_with_uuid.sql.golden.json | 8 +- .../output/grant_privilege.sql.golden.json | 187 +++--- .../ddl/output/optimize.sql.golden.json | 340 ++++++----- .../output/insert_with_select.sql.golden.json | 12 +- .../query/format/query_with_expr_compare.sql | 10 + .../query_with_expr_compare.sql.golden.json | 300 +++++++++ .../query/output/select_cast.sql.golden.json | 189 +++--- ...select_column_alias_string.sql.golden.json | 23 +- .../query/output/select_expr.sql.golden.json | 3 +- ...select_item_with_modifiers.sql.golden.json | 34 +- .../select_order_by_timestamp.sql.golden.json | 4 +- .../output/select_simple.sql.golden.json | 383 ++++++------ ...select_simple_with_bracket.sql.golden.json | 188 +++--- ...th_cte_with_column_aliases.sql.golden.json | 117 ++-- ..._group_by_with_cube_totals.sql.golden.json | 29 +- ...ct_simple_with_is_not_null.sql.golden.json | 147 +++-- ...select_simple_with_is_null.sql.golden.json | 145 +++-- ...ect_simple_with_top_clause.sql.golden.json | 3 +- ...ct_simple_with_with_clause.sql.golden.json | 15 +- ...able_alias_without_keyword.sql.golden.json | 66 +- .../select_when_condition.sql.golden.json | 3 +- .../select_with_join_only.sql.golden.json | 14 +- .../select_with_left_join.sql.golden.json | 64 +- ...ct_with_literal_table_name.sql.golden.json | 3 +- .../select_with_multi_join.sql.golden.json | 202 +++--- ...ct_with_multi_line_comment.sql.golden.json | 3 +- .../select_with_multi_union.sql.golden.json | 75 +-- ...elect_with_query_parameter.sql.golden.json | 59 +- .../select_with_string_expr.sql.golden.json | 28 +- ...select_with_union_distinct.sql.golden.json | 6 +- .../select_with_variable.sql.golden.json | 28 +- .../selelct_with_placeholder.sql.golden.json | 3 +- .../query/query_with_expr_compare.sql | 6 + 63 files changed, 3500 insertions(+), 2494 deletions(-) create mode 100644 parser/testdata/query/format/query_with_expr_compare.sql create mode 100644 parser/testdata/query/output/query_with_expr_compare.sql.golden.json create mode 100644 parser/testdata/query/query_with_expr_compare.sql diff --git a/parser/ast.go b/parser/ast.go index 318a7a2..24ebbe4 100644 --- a/parser/ast.go +++ b/parser/ast.go @@ -28,6 +28,7 @@ type SelectItem struct { Expr Expr // Please refer: https://clickhouse.com/docs/en/sql-reference/statements/select#select-modifiers Modifiers []*FunctionExpr + Alias *Ident } func (s *SelectItem) Pos() Pos { @@ -35,6 +36,9 @@ func (s *SelectItem) Pos() Pos { } func (s *SelectItem) End() Pos { + if s.Alias != nil { + return s.Alias.End() + } if len(s.Modifiers) > 0 { return s.Modifiers[len(s.Modifiers)-1].End() } @@ -48,6 +52,10 @@ func (s *SelectItem) String() string { builder.WriteByte(' ') builder.WriteString(modifier.String()) } + if s.Alias != nil { + builder.WriteString(" AS ") + builder.WriteString(s.Alias.String()) + } return builder.String() } @@ -62,6 +70,11 @@ func (s *SelectItem) Accept(visitor ASTVisitor) error { return err } } + if s.Alias != nil { + if err := s.Alias.Accept(visitor); err != nil { + return err + } + } return visitor.VisitSelectItem(s) } @@ -552,7 +565,7 @@ type AlterTableAddColumn struct { AddPos Pos StatementEnd Pos - Column *ColumnExpr + Column *ColumnDef IfNotExists bool After *NestedIdentifier } @@ -1190,7 +1203,7 @@ type AlterTableModifyColumn struct { StatementEnd Pos IfExists bool - Column *ColumnExpr + Column *ColumnDef RemovePropertyType *RemovePropertyType } @@ -1306,7 +1319,7 @@ type TableIndex struct { IndexPos Pos Name *NestedIdentifier - ColumnExpr Expr + ColumnExpr *ColumnExpr ColumnType Expr Granularity *NumberLiteral } @@ -1324,9 +1337,9 @@ func (a *TableIndex) String() string { builder.WriteString("INDEX") builder.WriteByte(' ') builder.WriteString(a.Name.String()) - // a.ColumnExpr = *Ident --- e.g. INDEX idx column TYPE ... - // a.ColumnExpr = *ParamExprList --- e.g. INDEX idx(column) TYPE ... - if _, ok := a.ColumnExpr.(*Ident); ok { + // a.ColumnDef = *Ident --- e.g. INDEX idx column TYPE ... + // a.ColumnDef = *ParamExprList --- e.g. INDEX idx(column) TYPE ... + if _, ok := a.ColumnExpr.Expr.(*Ident); ok { builder.WriteByte(' ') } builder.WriteString(a.ColumnExpr.String()) @@ -1475,7 +1488,7 @@ type CreateTable struct { OnCluster *ClusterClause TableSchema *TableSchemaClause Engine *EngineExpr - SubQuery *SubQueryClause + SubQuery *SubQuery HasTemporary bool } @@ -1518,6 +1531,7 @@ func (c *CreateTable) String() string { builder.WriteString(c.Engine.String()) } if c.SubQuery != nil { + builder.WriteString(" AS ") builder.WriteString(c.SubQuery.String()) } return builder.String() @@ -1562,7 +1576,7 @@ type CreateMaterializedView struct { OnCluster *ClusterClause Engine *EngineExpr Destination *DestinationClause - SubQuery *SubQueryClause + SubQuery *SubQuery Populate bool } @@ -1604,6 +1618,7 @@ func (c *CreateMaterializedView) String() string { builder.WriteString(" POPULATE ") } if c.SubQuery != nil { + builder.WriteString(" AS ") builder.WriteString(c.SubQuery.String()) } return builder.String() @@ -1651,7 +1666,7 @@ type CreateView struct { UUID *UUID OnCluster *ClusterClause TableSchema *TableSchemaClause - SubQuery *SubQueryClause + SubQuery *SubQuery } func (c *CreateView) Pos() Pos { @@ -1689,6 +1704,7 @@ func (c *CreateView) String() string { } if c.SubQuery != nil { + builder.WriteString(" AS ") builder.WriteString(c.SubQuery.String()) } return builder.String() @@ -2697,6 +2713,7 @@ func (t *TTLClause) Accept(visitor ASTVisitor) error { type OrderExpr struct { OrderPos Pos Expr Expr + Alias *Ident Direction OrderDirection } @@ -2705,12 +2722,19 @@ func (o *OrderExpr) Pos() Pos { } func (o *OrderExpr) End() Pos { + if o.Alias != nil { + return o.Alias.End() + } return o.Expr.End() } func (o *OrderExpr) String() string { var builder strings.Builder builder.WriteString(o.Expr.String()) + if o.Alias != nil { + builder.WriteString(" AS ") + builder.WriteString(o.Alias.String()) + } if o.Direction != OrderDirectionNone { builder.WriteByte(' ') builder.WriteString(string(o.Direction)) @@ -2724,6 +2748,11 @@ func (o *OrderExpr) Accept(visitor ASTVisitor) error { if err := o.Expr.Accept(visitor); err != nil { return err } + if o.Alias != nil { + if err := o.Alias.Accept(visitor); err != nil { + return err + } + } return visitor.VisitOrderByExpr(o) } @@ -3099,6 +3128,46 @@ func (w *WindowFunctionExpr) Accept(visitor ASTVisitor) error { } type ColumnExpr struct { + Expr Expr + Alias *Ident +} + +func (c *ColumnExpr) Pos() Pos { + return c.Expr.Pos() +} + +func (c *ColumnExpr) End() Pos { + if c.Alias != nil { + return c.Alias.NameEnd + } + return c.Expr.End() +} + +func (c *ColumnExpr) String() string { + var builder strings.Builder + builder.WriteString(c.Expr.String()) + if c.Alias != nil { + builder.WriteString(" AS ") + builder.WriteString(c.Alias.String()) + } + return builder.String() +} + +func (c *ColumnExpr) Accept(visitor ASTVisitor) error { + visitor.enter(c) + defer visitor.leave(c) + if err := c.Expr.Accept(visitor); err != nil { + return err + } + if c.Alias != nil { + if err := c.Alias.Accept(visitor); err != nil { + return err + } + } + return visitor.VisitColumnExpr(c) +} + +type ColumnDef struct { NamePos Pos ColumnEnd Pos Name *NestedIdentifier @@ -3117,15 +3186,15 @@ type ColumnExpr struct { CompressionCodec *Ident } -func (c *ColumnExpr) Pos() Pos { +func (c *ColumnDef) Pos() Pos { return c.Name.Pos() } -func (c *ColumnExpr) End() Pos { +func (c *ColumnDef) End() Pos { return c.ColumnEnd } -func (c *ColumnExpr) String() string { +func (c *ColumnDef) String() string { var builder strings.Builder builder.WriteString(c.Name.String()) if c.Type != nil { @@ -3164,7 +3233,7 @@ func (c *ColumnExpr) String() string { return builder.String() } -func (c *ColumnExpr) Accept(visitor ASTVisitor) error { +func (c *ColumnDef) Accept(visitor ASTVisitor) error { visitor.enter(c) defer visitor.leave(c) if err := c.Name.Accept(visitor); err != nil { @@ -3215,7 +3284,7 @@ func (c *ColumnExpr) Accept(visitor ASTVisitor) error { return err } } - return visitor.VisitColumn(c) + return visitor.VisitColumnDef(c) } type ScalarTypeExpr struct { @@ -4113,7 +4182,7 @@ type CreateLiveView struct { Destination *DestinationClause TableSchema *TableSchemaClause WithTimeout *WithTimeoutClause - SubQuery *SubQueryClause + SubQuery *SubQuery } func (c *CreateLiveView) Type() string { @@ -4157,6 +4226,7 @@ func (c *CreateLiveView) String() string { } if c.SubQuery != nil { + builder.WriteString(" AS ") builder.WriteString(c.SubQuery.String()) } @@ -4942,31 +5012,32 @@ func (f *WindowFrameExtendExpr) Accept(visitor ASTVisitor) error { return visitor.VisitWindowFrameExtendExpr(f) } -type WindowFrameRangeClause struct { - BetweenPos Pos - Between Expr - AndPos Pos - And Expr +type BetweenClause struct { + Expr Expr + Between Expr + AndPos Pos + And Expr } -func (f *WindowFrameRangeClause) Pos() Pos { - return f.BetweenPos +func (f *BetweenClause) Pos() Pos { + return f.Expr.Pos() } -func (f *WindowFrameRangeClause) End() Pos { +func (f *BetweenClause) End() Pos { return f.And.End() } -func (f *WindowFrameRangeClause) String() string { +func (f *BetweenClause) String() string { var builder strings.Builder - builder.WriteString("BETWEEN ") + builder.WriteString(f.Expr.String()) + builder.WriteString(" BETWEEN ") builder.WriteString(f.Between.String()) builder.WriteString(" AND ") builder.WriteString(f.And.String()) return builder.String() } -func (f *WindowFrameRangeClause) Accept(visitor ASTVisitor) error { +func (f *BetweenClause) Accept(visitor ASTVisitor) error { visitor.enter(f) defer visitor.leave(f) if err := f.Between.Accept(visitor); err != nil { @@ -4975,7 +5046,7 @@ func (f *WindowFrameRangeClause) Accept(visitor ASTVisitor) error { if err := f.And.Accept(visitor); err != nil { return err } - return visitor.VisitWindowFrameRangeExpr(f) + return visitor.VisitBetweenClause(f) } type WindowFrameCurrentRow struct { @@ -5298,28 +5369,31 @@ func (s *SelectQuery) Accept(visitor ASTVisitor) error { return visitor.VisitSelectQuery(s) } -type SubQueryClause struct { - AsPos Pos - Select *SelectQuery +type SubQuery struct { + HasParen bool + Select *SelectQuery } -func (s *SubQueryClause) Pos() Pos { - return s.AsPos +func (s *SubQuery) Pos() Pos { + return s.Select.Pos() } -func (s *SubQueryClause) End() Pos { +func (s *SubQuery) End() Pos { return s.Select.End() } -func (s *SubQueryClause) String() string { - var builder strings.Builder - builder.WriteString(" AS (") - builder.WriteString(s.Select.String()) - builder.WriteString(")") - return builder.String() +func (s *SubQuery) String() string { + if s.HasParen { + var builder strings.Builder + builder.WriteString("(") + builder.WriteString(s.Select.String()) + builder.WriteString(")") + return builder.String() + } + return s.Select.String() } -func (s *SubQueryClause) Accept(visitor ASTVisitor) error { +func (s *SubQuery) Accept(visitor ASTVisitor) error { visitor.enter(s) defer visitor.leave(s) if s.Select != nil { diff --git a/parser/ast_visitor.go b/parser/ast_visitor.go index c88631d..7cd3957 100644 --- a/parser/ast_visitor.go +++ b/parser/ast_visitor.go @@ -71,7 +71,8 @@ type ASTVisitor interface { VisitObjectParams(expr *ObjectParams) error VisitFunctionExpr(expr *FunctionExpr) error VisitWindowFunctionExpr(expr *WindowFunctionExpr) error - VisitColumn(expr *ColumnExpr) error + VisitColumnDef(expr *ColumnDef) error + VisitColumnExpr(expr *ColumnExpr) error VisitScalarTypeExpr(expr *ScalarTypeExpr) error VisitPropertyTypeExpr(expr *PropertyTypeExpr) error VisitTypeWithParamsExpr(expr *TypeWithParamsExpr) error @@ -115,13 +116,13 @@ type ASTVisitor interface { VisitWindowExpr(expr *WindowClause) error VisitWindowFrameExpr(expr *WindowFrameClause) error VisitWindowFrameExtendExpr(expr *WindowFrameExtendExpr) error - VisitWindowFrameRangeExpr(expr *WindowFrameRangeClause) error + VisitBetweenClause(expr *BetweenClause) error VisitWindowFrameCurrentRow(expr *WindowFrameCurrentRow) error VisitWindowFrameUnbounded(expr *WindowFrameUnbounded) error VisitWindowFrameNumber(expr *WindowFrameNumber) error VisitArrayJoinExpr(expr *ArrayJoinClause) error VisitSelectQuery(expr *SelectQuery) error - VisitSubQueryExpr(expr *SubQueryClause) error + VisitSubQueryExpr(expr *SubQuery) error VisitNotExpr(expr *NotExpr) error VisitNegateExpr(expr *NegateExpr) error VisitGlobalInExpr(expr *GlobalInOperation) error @@ -663,7 +664,14 @@ func (v *DefaultASTVisitor) VisitWindowFunctionExpr(expr *WindowFunctionExpr) er return nil } -func (v *DefaultASTVisitor) VisitColumn(expr *ColumnExpr) error { +func (v *DefaultASTVisitor) VisitColumnDef(expr *ColumnDef) error { + if v.Visit != nil { + return v.Visit(expr) + } + return nil +} + +func (v *DefaultASTVisitor) VisitColumnExpr(expr *ColumnExpr) error { if v.Visit != nil { return v.Visit(expr) } @@ -964,7 +972,7 @@ func (v *DefaultASTVisitor) VisitWindowFrameExtendExpr(expr *WindowFrameExtendEx return nil } -func (v *DefaultASTVisitor) VisitWindowFrameRangeExpr(expr *WindowFrameRangeClause) error { +func (v *DefaultASTVisitor) VisitBetweenClause(expr *BetweenClause) error { if v.Visit != nil { return v.Visit(expr) } @@ -1006,7 +1014,7 @@ func (v *DefaultASTVisitor) VisitSelectQuery(expr *SelectQuery) error { return nil } -func (v *DefaultASTVisitor) VisitSubQueryExpr(expr *SubQueryClause) error { +func (v *DefaultASTVisitor) VisitSubQueryExpr(expr *SubQuery) error { if v.Visit != nil { return v.Visit(expr) } diff --git a/parser/lexer.go b/parser/lexer.go index fc241ff..4de4d54 100644 --- a/parser/lexer.go +++ b/parser/lexer.go @@ -36,6 +36,13 @@ type Token struct { QuoteType int } +func (t *Token) ToString() string { + if t.Kind == TokenKeyword { + return strings.ToUpper(t.String) + } + return t.String +} + type Lexer struct { input string current int diff --git a/parser/parser_column.go b/parser/parser_column.go index 34210b8..effd569 100644 --- a/parser/parser_column.go +++ b/parser/parser_column.go @@ -5,6 +5,24 @@ import ( "strings" ) +const ( + PrecedenceUnknown = iota + PrecedenceOr + PrecedenceAnd + PrecedenceQuery + PrecedenceNot + PrecedenceGlobal + PrecedenceIs + PrecedenceCompare + PrecedenceBetweenLike + precedenceIn + PrecedenceAddSub + PrecedenceMulDivMod + PrecedenceBracket + PrecedenceArrow + PrecedenceDoubleColon +) + func (p *Parser) tryParseColumnComment(pos Pos) (*StringLiteral, error) { if p.tryConsumeKeyword(KeywordComment) == nil { return nil, nil // nolint @@ -12,121 +30,108 @@ func (p *Parser) tryParseColumnComment(pos Pos) (*StringLiteral, error) { return p.parseString(pos) } -func (p *Parser) parseExpr(pos Pos) (Expr, error) { - orExpr, err := p.parseOrExpr(pos) - if err != nil { - return orExpr, err +func (p *Parser) getNextPrecedence() int { + switch { + case p.matchKeyword(KeywordOr): + return PrecedenceOr + case p.matchKeyword(KeywordAnd): + return PrecedenceAnd + case p.matchKeyword(KeywordIs): + return PrecedenceIs + case p.matchKeyword(KeywordNot): + return PrecedenceNot + case p.matchTokenKind(opTypeCast): + return PrecedenceDoubleColon + case p.matchTokenKind(opTypeEQ), p.matchTokenKind(opTypeLT), p.matchTokenKind(opTypeLE), + p.matchTokenKind(opTypeGE), p.matchTokenKind(opTypeGT), p.matchTokenKind(opTypeDoubleEQ), + p.matchTokenKind(opTypeNE), p.matchTokenKind("<>"): + return PrecedenceCompare + case p.matchTokenKind(opTypePlus), p.matchTokenKind(opTypeMinus): + return PrecedenceAddSub + case p.matchTokenKind(opTypeMul), p.matchTokenKind(opTypeDiv), p.matchTokenKind(opTypeMod): + return PrecedenceMulDivMod + case p.matchTokenKind(opTypeArrow): + return PrecedenceArrow + case p.matchTokenKind("("), p.matchTokenKind("["): + return PrecedenceBracket + case p.matchTokenKind(opTypeCast): + return PrecedenceDoubleColon + case p.matchKeyword(KeywordBetween), p.matchKeyword(KeywordLike), p.matchKeyword(KeywordIlike): + return PrecedenceBetweenLike + case p.matchKeyword(KeywordIn): + return precedenceIn + case p.matchKeyword(KeywordGlobal): + return PrecedenceGlobal + case p.matchTokenKind(opTypeQuery): + return PrecedenceQuery + default: + return PrecedenceUnknown } +} + +func (p *Parser) parseInfix(expr Expr, precedence int) (Expr, error) { switch { - case p.matchKeyword(KeywordAs): // syntax: columnExpr (alias | AS identifier) + case p.matchTokenKind(opTypeEQ), p.matchTokenKind(opTypeLT), p.matchTokenKind(opTypeLE), + p.matchTokenKind(opTypeGE), p.matchTokenKind(opTypeGT), + p.matchTokenKind(opTypeNE), p.matchTokenKind("<>"), + p.matchTokenKind(opTypeMinus), p.matchTokenKind(opTypePlus), p.matchTokenKind(opTypeMul), + p.matchTokenKind(opTypeDiv), p.matchTokenKind(opTypeMod), + p.matchKeyword(KeywordIn), p.matchKeyword(KeywordLike), + p.matchKeyword(KeywordIlike), p.matchKeyword(KeywordAnd), p.matchKeyword(KeywordOr), + p.matchTokenKind(opTypeCast), p.matchTokenKind(opTypeArrow), p.matchTokenKind(opTypeDoubleEQ): + op := p.last().ToString() _ = p.lexer.consumeToken() - alias, err := p.parseIdent() + rightExpr, err := p.parseSubExpr(p.Pos(), precedence) if err != nil { return nil, err } - return &AliasExpr{ - AliasPos: alias.Pos(), - Expr: orExpr, - Alias: alias, + return &BinaryOperation{ + LeftExpr: expr, + Operation: TokenKind(op), + RightExpr: rightExpr, }, nil - } - return orExpr, nil -} - -func (p *Parser) parseOrExpr(pos Pos) (Expr, error) { - expr, err := p.parseAndExpr(pos) - if err != nil { - return nil, err - } - for { - if p.tryConsumeKeyword(KeywordOr) == nil { - return expr, nil + case p.matchKeyword(KeywordBetween): + return p.parseBetweenClause(expr) + case p.matchKeyword(KeywordGlobal): + _ = p.lexer.consumeToken() + if p.consumeKeyword(KeywordIn) != nil { + return nil, fmt.Errorf("expected IN after GLOBAL, got %s", p.lastTokenKind()) } - - rightExpr, err := p.parseAndExpr(p.Pos()) + rightExpr, err := p.parseSubExpr(p.Pos(), precedence) if err != nil { return nil, err } - expr = &BinaryOperation{ + return &BinaryOperation{ LeftExpr: expr, - Operation: opTypeOr, + Operation: "GLOBAL IN", RightExpr: rightExpr, - } - } -} + }, nil -func (p *Parser) parseAndExpr(pos Pos) (Expr, error) { - expr, err := p.parseNotExpr(pos) - if err != nil { - return nil, err - } - for { - if p.tryConsumeKeyword(KeywordAnd) == nil { - return expr, nil + case p.matchKeyword(KeywordNot): + _ = p.lexer.consumeToken() + switch { + case p.matchKeyword(KeywordIn): + case p.matchKeyword(KeywordLike): + case p.matchKeyword(KeywordIlike): + default: + return nil, fmt.Errorf("expected IN, LIKE or ILIKE after NOT, got %s", p.lastTokenKind()) } - - rightExpr, err := p.parseNotExpr(p.Pos()) + if p.matchKeyword(KeywordBetween) { + return p.parseBetweenClause(expr) + } + op := p.last().ToString() + _ = p.lexer.consumeToken() + rightExpr, err := p.parseSubExpr(p.Pos(), precedence) if err != nil { return nil, err } - expr = &BinaryOperation{ + return &BinaryOperation{ LeftExpr: expr, - Operation: opTypeAnd, + Operation: TokenKind("NOT " + op), RightExpr: rightExpr, - } - } -} - -func (p *Parser) parseNotExpr(pos Pos) (Expr, error) { - if p.tryConsumeKeyword(KeywordNot) == nil { - return p.parseIsOrNotNull(p.Pos()) - } - - notExpr, err := p.parseNotExpr(p.Pos()) - if err != nil { - return nil, err - } - return &NotExpr{ - NotPos: pos, - Expr: notExpr, - }, nil -} - -func (p *Parser) parseIsOrNotNull(pos Pos) (Expr, error) { - expr, err := p.parseCompareExpr(p.Pos()) - if err != nil { - return nil, err - } - if p.tryConsumeKeyword(KeywordIs) == nil { - return expr, nil - } - - isNotNull := p.tryConsumeKeyword(KeywordNot) != nil - if err := p.consumeKeyword(KeywordNull); err != nil { - return nil, err - } - - if isNotNull { - return &IsNotNullExpr{ - IsPos: pos, - Expr: expr, }, nil - } - return &IsNullExpr{ - IsPos: pos, - Expr: expr, - }, nil -} - -func (p *Parser) parseCompareExpr(pos Pos) (Expr, error) { - hasNot, hasGlobal := false, false - expr, err := p.parseAddSubExpr(pos) - if err != nil { - return nil, err - } - switch { case p.matchTokenKind("["): - params, err := p.parseArrayParams(pos) + params, err := p.parseArrayParams(p.Pos()) if err != nil { return nil, err } @@ -134,73 +139,50 @@ func (p *Parser) parseCompareExpr(pos Pos) (Expr, error) { Object: expr, Params: params, }, nil - case p.matchTokenKind(opTypeEQ): - case p.matchTokenKind(opTypeLT): - case p.matchTokenKind(opTypeLE): - case p.matchTokenKind(opTypeGE): - case p.matchTokenKind(opTypeGT): - case p.matchTokenKind(opTypeDoubleEQ): - case p.matchTokenKind(opTypeNE): - case p.matchTokenKind("<>"): case p.matchTokenKind(opTypeQuery): - case p.matchKeyword(KeywordIn): - case p.matchKeyword(KeywordLike): - case p.matchKeyword(KeywordIlike): - case p.matchKeyword(KeywordGlobal): - _ = p.lexer.consumeToken() - hasGlobal = true - case p.matchKeyword(KeywordNot): + return p.parseTernaryExpr(expr) + case p.matchKeyword(KeywordIs): _ = p.lexer.consumeToken() - switch { - case p.matchKeyword(KeywordIn): - case p.matchKeyword(KeywordLike): - case p.matchKeyword(KeywordIlike): - default: - return nil, fmt.Errorf("expected IN, LIKE or ILIKE after NOT, got %s", p.lastTokenKind()) + isNotNull := p.tryConsumeKeyword(KeywordNot) != nil + if err := p.consumeKeyword(KeywordNull); err != nil { + return nil, err + } + if isNotNull { + return &IsNotNullExpr{ + IsPos: p.Pos(), + Expr: expr, + }, nil } - hasNot = true + return &IsNullExpr{ + IsPos: p.Pos(), + Expr: expr, + }, nil default: - return expr, nil + return nil, fmt.Errorf("unexpected token kind: %s", p.lastTokenKind()) } - op := TokenKind(strings.ToUpper(p.last().String)) - _ = p.lexer.consumeToken() +} - rightExpr, err := p.parseAddSubExpr(p.Pos()) - if err != nil { - return nil, err - } - return &BinaryOperation{ - LeftExpr: expr, - HasNot: hasNot, - HasGlobal: hasGlobal, - Operation: op, - RightExpr: rightExpr, - }, nil +func (p *Parser) parseExpr(pos Pos) (Expr, error) { + return p.parseSubExpr(pos, PrecedenceUnknown) } -func (p *Parser) parseAddSubExpr(pos Pos) (Expr, error) { - expr, err := p.parseMulDivModExpr(pos) +func (p *Parser) parseSubExpr(pos Pos, precedence int) (Expr, error) { + expr, err := p.parseUnaryExpr(pos) if err != nil { return nil, err } - for { - switch { - case p.matchTokenKind(opTypePlus), p.matchTokenKind(opTypeMinus): - op := p.lastTokenKind() - _ = p.lexer.consumeToken() - rightExpr, err := p.parseMulDivModExpr(p.Pos()) - if err != nil { - return nil, err - } - expr = &BinaryOperation{ - LeftExpr: expr, - Operation: op, - RightExpr: rightExpr, - } - default: + for !p.lexer.isEOF() { + nextPrecedence := p.getNextPrecedence() + if nextPrecedence <= precedence { return expr, nil } + // parse binary operation + expr, err = p.parseInfix(expr, nextPrecedence) + if err != nil { + return nil, err + } } + return expr, nil } func (p *Parser) parseTernaryExpr(condition Expr) (*TernaryOperation, error) { @@ -225,37 +207,6 @@ func (p *Parser) parseTernaryExpr(condition Expr) (*TernaryOperation, error) { }, nil } -func (p *Parser) parseMulDivModExpr(pos Pos) (Expr, error) { - expr, err := p.parseUnaryExpr(pos) - if err != nil { - return nil, err - } - for { - switch { - case p.matchTokenKind(opTypeQuery): - return p.parseTernaryExpr(expr) - case p.matchTokenKind(opTypeMul), - p.matchTokenKind(opTypeDiv), - p.matchTokenKind(opTypeMod), - p.matchTokenKind(opTypeArrow), - p.matchTokenKind(opTypeCast): - op := p.lastTokenKind() - _ = p.lexer.consumeToken() - rightExpr, err := p.parseUnaryExpr(p.Pos()) - if err != nil { - return nil, err - } - expr = &BinaryOperation{ - LeftExpr: expr, - Operation: op, - RightExpr: rightExpr, - } - default: - return expr, nil - } - } -} - func (p *Parser) parseColumnExtractExpr(pos Pos) (*ExtractExpr, error) { if err := p.consumeKeyword(KeywordExtract); err != nil { return nil, err @@ -346,7 +297,7 @@ func (p *Parser) parseColumnExpr(pos Pos) (Expr, error) { //nolint:funlen return nil, err } if nextToken != nil && nextToken.Kind == TokenString { - return p.parseString(pos) + return p.parseString(p.Pos()) } return p.parseIdentOrFunction(pos) case p.matchKeyword(KeywordCast): @@ -365,7 +316,7 @@ func (p *Parser) parseColumnExpr(pos Pos) (Expr, error) { //nolint:funlen case p.matchTokenKind("("): if peek, _ := p.lexer.peekToken(); peek != nil { if peek.Kind == TokenKeyword && strings.EqualFold(peek.String, KeywordSelect) { - return p.parseSelectQuery(pos) + return p.parseSubQuery(pos) } } return p.parseFunctionParams(p.Pos()) @@ -458,7 +409,7 @@ func (p *Parser) parseColumnExprListWithTerm(term TokenKind, pos Pos) (*ColumnEx if term != "" && p.matchTokenKind(term) { break } - columnExpr, err := p.parseColumnsExpr(pos) + columnExpr, err := p.parseColumnsExpr(p.Pos()) if err != nil { return nil, err } @@ -685,8 +636,23 @@ func (p *Parser) parseArrayParams(pos Pos) (*ArrayParamList, error) { }, nil } -func (p *Parser) parseColumnsExpr(pos Pos) (Expr, error) { - return p.parseExpr(pos) +func (p *Parser) parseColumnsExpr(pos Pos) (*ColumnExpr, error) { + expr, err := p.parseExpr(pos) + if err != nil { + return nil, err + } + + var alias *Ident + if p.tryConsumeKeyword(KeywordAs) != nil { + alias, err = p.parseIdent() + if err != nil { + return nil, err + } + } + return &ColumnExpr{ + Expr: expr, + Alias: alias, + }, nil } func (p *Parser) parseSelectItem() (*SelectItem, error) { @@ -707,9 +673,18 @@ func (p *Parser) parseSelectItem() (*SelectItem, error) { break } } + + var alias *Ident + if p.tryConsumeKeyword(KeywordAs) != nil { + alias, err = p.parseIdent() + if err != nil { + return nil, err + } + } return &SelectItem{ Expr: expr, Modifiers: modifiers, + Alias: alias, }, nil } @@ -869,7 +844,7 @@ func (p *Parser) parseEnumExpr(pos Pos) (*EnumValueList, error) { func (p *Parser) parseColumnTypeWithParams(name *Ident, pos Pos) (*TypeWithParamsExpr, error) { params := make([]Literal, 0) - param, err := p.parseLiteral(pos) + param, err := p.parseLiteral(p.Pos()) if err != nil { return nil, err } diff --git a/parser/parser_query.go b/parser/parser_query.go index 376ec3d..1dd1e97 100644 --- a/parser/parser_query.go +++ b/parser/parser_query.go @@ -304,7 +304,7 @@ func (p *Parser) parseTableExpr(pos Pos) (*TableExpr, error) { } } case p.matchTokenKind("("): - expr, err = p.parseSelectQuery(p.Pos()) + expr, err = p.parseSubQuery(p.Pos()) default: return nil, errors.New("expect table name or subquery") } @@ -495,6 +495,34 @@ func (p *Parser) tryParseLimitByClause(pos Pos) (Expr, error) { return p.parseLimitByClause(pos) } +func (p *Parser) parseBetweenClause(expr Expr) (*BetweenClause, error) { + if err := p.consumeKeyword(KeywordBetween); err != nil { + return nil, err + } + + betweenExpr, err := p.parseSubExpr(p.Pos(), PrecedenceBetweenLike) + if err != nil { + return nil, err + } + + andPos := p.Pos() + if err := p.consumeKeyword(KeywordAnd); err != nil { + return nil, err + } + + andExpr, err := p.parseSubExpr(p.Pos(), PrecedenceBetweenLike) + if err != nil { + return nil, err + } + + return &BetweenClause{ + Expr: expr, + Between: betweenExpr, + AndPos: andPos, + And: andExpr, + }, nil +} + func (p *Parser) parseLimitByClause(pos Pos) (Expr, error) { limit, err := p.parseLimitClause(pos) if err != nil { @@ -545,11 +573,11 @@ func (p *Parser) parseWindowFrameClause(pos Pos) (*WindowFrameClause, error) { if err != nil { return nil, err } - expr = &WindowFrameRangeClause{ - BetweenPos: pos, - Between: betweenWindowFrame, - AndPos: andPos, - And: andWindowFrame, + expr = &BetweenClause{ + Expr: expr, + Between: betweenWindowFrame, + AndPos: andPos, + And: andWindowFrame, } case p.matchKeyword(KeywordCurrent): currentPos := p.Pos() @@ -729,19 +757,23 @@ func (p *Parser) parseHavingClause(pos Pos) (*HavingClause, error) { }, nil } -func (p *Parser) parseSubQueryClause(pos Pos) (*SubQueryClause, error) { - if err := p.consumeKeyword(KeywordAs); err != nil { - return nil, err - } +func (p *Parser) parseSubQuery(_ Pos) (*SubQuery, error) { + + hasParen := p.tryConsumeTokenKind("(") != nil selectQuery, err := p.parseSelectQuery(p.Pos()) if err != nil { return nil, err } + if hasParen { + if _, err := p.consumeTokenKind(")"); err != nil { + return nil, err + } + } - return &SubQueryClause{ - AsPos: pos, - Select: selectQuery, + return &SubQuery{ + HasParen: hasParen, + Select: selectQuery, }, nil } @@ -942,7 +974,7 @@ func (p *Parser) parseSelectStmt(pos Pos) (*SelectQuery, error) { // nolint: fun } func (p *Parser) parseCTEStmt(pos Pos) (*CTEStmt, error) { - expr, err := p.parseOrExpr(pos) + expr, err := p.parseExpr(pos) if err != nil { return nil, err } diff --git a/parser/parser_table.go b/parser/parser_table.go index eb0fdab..c00937e 100644 --- a/parser/parser_table.go +++ b/parser/parser_table.go @@ -158,8 +158,8 @@ func (p *Parser) parseCreateTable(pos Pos) (*CreateTable, error) { createTable.StatementEnd = engineExpr.End() } - if p.matchKeyword(KeywordAs) { - subQuery, err := p.parseSubQueryClause(p.Pos()) + if p.tryConsumeKeyword(KeywordAs) != nil { + subQuery, err := p.parseSubQuery(p.Pos()) if err != nil { return nil, err } @@ -396,16 +396,16 @@ func (p *Parser) parseTableColumns() ([]Expr, error) { return columns, nil } -func (p *Parser) tryParseTableColumnExpr(pos Pos) (*ColumnExpr, error) { +func (p *Parser) tryParseTableColumnExpr(pos Pos) (*ColumnDef, error) { if !p.matchTokenKind(TokenIdent) { return nil, nil // nolint } return p.parseTableColumnExpr(pos) } -func (p *Parser) parseTableColumnExpr(pos Pos) (*ColumnExpr, error) { +func (p *Parser) parseTableColumnExpr(pos Pos) (*ColumnDef, error) { // Not a column definition, just return - column := &ColumnExpr{NamePos: pos} + column := &ColumnDef{NamePos: pos} // parse column name name, err := p.ParseNestedIdentifier(p.Pos()) if err != nil { @@ -649,6 +649,14 @@ func (p *Parser) parseOrderExpr(pos Pos) (*OrderExpr, error) { return nil, err } + var alias *Ident + if p.tryConsumeKeyword(KeywordAs) != nil { + alias, err = p.parseIdent() + if err != nil { + return nil, err + } + } + direction := OrderDirectionNone switch { case p.matchKeyword(KeywordAsc), p.matchKeyword(KeywordAscending): @@ -660,6 +668,7 @@ func (p *Parser) parseOrderExpr(pos Pos) (*OrderExpr, error) { } return &OrderExpr{ OrderPos: pos, + Alias: alias, Expr: columnExpr, Direction: direction, }, nil diff --git a/parser/parser_view.go b/parser/parser_view.go index c4bd367..7b3f295 100644 --- a/parser/parser_view.go +++ b/parser/parser_view.go @@ -61,8 +61,8 @@ func (p *Parser) parseCreateMaterializedView(pos Pos) (*CreateMaterializedView, default: return nil, fmt.Errorf("unexpected token: %q, expected TO or ENGINE", p.lastTokenKind()) } - if p.matchKeyword(KeywordAs) { - subQuery, err := p.parseSubQueryClause(p.Pos()) + if p.tryConsumeKeyword(KeywordAs) != nil { + subQuery, err := p.parseSubQuery(p.Pos()) if err != nil { return nil, err } @@ -111,12 +111,14 @@ func (p *Parser) parseCreateView(pos Pos) (*CreateView, error) { createView.TableSchema = tableSchema } - subQuery, err := p.parseSubQueryClause(p.Pos()) - if err != nil { - return nil, err + if p.tryConsumeKeyword(KeywordAs) != nil { + subQuery, err := p.parseSubQuery(p.Pos()) + if err != nil { + return nil, err + } + createView.SubQuery = subQuery + createView.StatementEnd = subQuery.End() } - createView.SubQuery = subQuery - createView.StatementEnd = subQuery.End() return createView, nil } @@ -182,12 +184,14 @@ func (p *Parser) parseCreateLiveView(pos Pos) (*CreateLiveView, error) { createLiveView.TableSchema = tableSchema } - subQuery, err := p.parseSubQueryClause(p.Pos()) - if err != nil { - return nil, err + if p.tryConsumeKeyword(KeywordAs) != nil { + subQuery, err := p.parseSubQuery(p.Pos()) + if err != nil { + return nil, err + } + createLiveView.SubQuery = subQuery + createLiveView.StatementEnd = subQuery.End() } - createLiveView.SubQuery = subQuery - createLiveView.StatementEnd = subQuery.End() return createLiveView, nil } diff --git a/parser/testdata/ddl/format/bug_001.sql b/parser/testdata/ddl/format/bug_001.sql index 6d764cf..4339c0f 100644 --- a/parser/testdata/ddl/format/bug_001.sql +++ b/parser/testdata/ddl/format/bug_001.sql @@ -18,4 +18,4 @@ FROM db.table WHERE db.table.event = 'hello'; -- Format SQL: -CREATE MATERIALIZED VIEW IF NOT EXISTS db.table ON CLUSTER 'default_cluster' TO db.table_mv AS (SELECT event_ts, org_id, visitParamExtractString(properties, 'x') AS x, visitParamExtractString(properties, 'y') AS y, visitParamExtractString(properties, 'z') AS z, visitParamExtractString(properties, 'a') AS a, visitParamExtractString(properties, 'b') AS b, visitParamExtractString(properties, 'c') AS c, visitParamExtractString(properties, 'd') AS d, visitParamExtractInt(properties, 'e') AS e, visitParamExtractInt(properties, 'f') AS f FROM db.table WHERE db.table.event = 'hello'); +CREATE MATERIALIZED VIEW IF NOT EXISTS db.table ON CLUSTER 'default_cluster' TO db.table_mv AS SELECT event_ts, org_id, visitParamExtractString(properties, 'x') AS x, visitParamExtractString(properties, 'y') AS y, visitParamExtractString(properties, 'z') AS z, visitParamExtractString(properties, 'a') AS a, visitParamExtractString(properties, 'b') AS b, visitParamExtractString(properties, 'c') AS c, visitParamExtractString(properties, 'd') AS d, visitParamExtractInt(properties, 'e') AS e, visitParamExtractInt(properties, 'f') AS f FROM db.table WHERE db.table.event = 'hello'; diff --git a/parser/testdata/ddl/format/create_live_view_basic.sql b/parser/testdata/ddl/format/create_live_view_basic.sql index f5d2299..17e5101 100644 --- a/parser/testdata/ddl/format/create_live_view_basic.sql +++ b/parser/testdata/ddl/format/create_live_view_basic.sql @@ -5,4 +5,4 @@ AS SELECT id FROM my_table; -- Format SQL: -CREATE LIVE VIEW my_live_view WITH TIMEOUT 10 TO my_destination (id String) AS (SELECT id FROM my_table); +CREATE LIVE VIEW my_live_view WITH TIMEOUT 10 TO my_destination (id String) AS SELECT id FROM my_table; diff --git a/parser/testdata/ddl/format/create_materialized_view_basic.sql b/parser/testdata/ddl/format/create_materialized_view_basic.sql index cd5b040..50721ab 100644 --- a/parser/testdata/ddl/format/create_materialized_view_basic.sql +++ b/parser/testdata/ddl/format/create_materialized_view_basic.sql @@ -22,4 +22,4 @@ WHERE infra_bm.table_name1.event = 'test-event'; -- Format SQL: -CREATE MATERIALIZED VIEW infra_bm.view_name ON CLUSTER 'default_cluster' TO infra_bm.table_name (`f1` DateTime64(3), `f2` String, `f3` String, `f4` String, `f5` String, `f6` Int64) AS (SELECT f1, f2, visitParamExtractString(properties, 'f3') AS f3, visitParamExtractString(properties, 'f4') AS f4, visitParamExtractString(properties, 'f5') AS f5, visitParamExtractInt(properties, 'f6') AS f6 FROM infra_bm.table_name1 WHERE infra_bm.table_name1.event = 'test-event'); +CREATE MATERIALIZED VIEW infra_bm.view_name ON CLUSTER 'default_cluster' TO infra_bm.table_name (`f1` DateTime64(3), `f2` String, `f3` String, `f4` String, `f5` String, `f6` Int64) AS SELECT f1, f2, visitParamExtractString(properties, 'f3') AS f3, visitParamExtractString(properties, 'f4') AS f4, visitParamExtractString(properties, 'f5') AS f5, visitParamExtractInt(properties, 'f6') AS f6 FROM infra_bm.table_name1 WHERE infra_bm.table_name1.event = 'test-event'; diff --git a/parser/testdata/ddl/format/create_materialized_view_with_empty_table_schema.sql b/parser/testdata/ddl/format/create_materialized_view_with_empty_table_schema.sql index 99183ab..0cbf223 100644 --- a/parser/testdata/ddl/format/create_materialized_view_with_empty_table_schema.sql +++ b/parser/testdata/ddl/format/create_materialized_view_with_empty_table_schema.sql @@ -16,4 +16,4 @@ from where rn = 1; -- Format SQL: -CREATE MATERIALIZED VIEW test.t0 ON CLUSTER default_cluster ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/{layer}-{shard}/test/t0', '{replica}') PARTITION BY toYYYYMM(f0) ORDER BY (f0) POPULATE AS (SELECT f0, f1, f2, coalesce(f0, f1) AS f333 FROM (SELECT f0, f1, f2, ROW_NUMBER() OVER ( PARTITION BY f0 ORDER BY coalesce(f1, f2)) AS rn FROM test.t WHERE f3 IN ('foo', 'bar', 'test') AND env = 'test') AS tmp WHERE rn = 1); +CREATE MATERIALIZED VIEW test.t0 ON CLUSTER default_cluster ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/{layer}-{shard}/test/t0', '{replica}') PARTITION BY toYYYYMM(f0) ORDER BY (f0) POPULATE AS SELECT f0, f1, f2, coalesce(f0, f1) AS f333 FROM (SELECT f0, f1, f2, ROW_NUMBER() OVER ( PARTITION BY f0 ORDER BY coalesce(f1, f2)) AS rn FROM test.t WHERE f3 IN ('foo', 'bar', 'test') AND env = 'test') AS tmp WHERE rn = 1; diff --git a/parser/testdata/ddl/format/create_view_basic.sql b/parser/testdata/ddl/format/create_view_basic.sql index 408ab4f..b1b3fd6 100644 --- a/parser/testdata/ddl/format/create_view_basic.sql +++ b/parser/testdata/ddl/format/create_view_basic.sql @@ -8,4 +8,4 @@ FROM my_table; -- Format SQL: -CREATE VIEW IF NOT EXISTS my_view (col1 String, col2 String) AS (SELECT id, name FROM my_table); +CREATE VIEW IF NOT EXISTS my_view (col1 String, col2 String) AS SELECT id, name FROM my_table; diff --git a/parser/testdata/ddl/output/alter_table_add_index.sql.golden.json b/parser/testdata/ddl/output/alter_table_add_index.sql.golden.json index d4b7c55..569f618 100644 --- a/parser/testdata/ddl/output/alter_table_add_index.sql.golden.json +++ b/parser/testdata/ddl/output/alter_table_add_index.sql.golden.json @@ -40,22 +40,28 @@ "DotIdent": null }, "ColumnExpr": { - "LeftParenPos": 77, - "RightParenPos": 80, - "Items": { - "ListPos": 78, - "ListEnd": 80, - "HasDistinct": false, - "Items": [ - { - "Name": "f0", - "QuoteType": 1, - "NamePos": 78, - "NameEnd": 80 - } - ] + "Expr": { + "LeftParenPos": 77, + "RightParenPos": 80, + "Items": { + "ListPos": 78, + "ListEnd": 80, + "HasDistinct": false, + "Items": [ + { + "Expr": { + "Name": "f0", + "QuoteType": 1, + "NamePos": 78, + "NameEnd": 80 + }, + "Alias": null + } + ] + }, + "ColumnArgList": null }, - "ColumnArgList": null + "Alias": null }, "ColumnType": { "Name": { @@ -118,10 +124,13 @@ "DotIdent": null }, "ColumnExpr": { - "Name": "api_id", - "QuoteType": 1, - "NamePos": 192, - "NameEnd": 198 + "Expr": { + "Name": "api_id", + "QuoteType": 1, + "NamePos": 192, + "NameEnd": 198 + }, + "Alias": null }, "ColumnType": { "LeftParenPos": 208, @@ -194,10 +203,13 @@ "DotIdent": null }, "ColumnExpr": { - "Name": "arr", - "QuoteType": 1, - "NamePos": 305, - "NameEnd": 308 + "Expr": { + "Name": "arr", + "QuoteType": 1, + "NamePos": 305, + "NameEnd": 308 + }, + "Alias": null }, "ColumnType": { "LeftParenPos": 327, @@ -270,10 +282,13 @@ "DotIdent": null }, "ColumnExpr": { - "Name": "content", - "QuoteType": 1, - "NamePos": 429, - "NameEnd": 436 + "Expr": { + "Name": "content", + "QuoteType": 1, + "NamePos": 429, + "NameEnd": 436 + }, + "Alias": null }, "ColumnType": { "LeftParenPos": 453, @@ -358,10 +373,13 @@ "DotIdent": null }, "ColumnExpr": { - "Name": "output", - "QuoteType": 1, - "NamePos": 561, - "NameEnd": 567 + "Expr": { + "Name": "output", + "QuoteType": 1, + "NamePos": 561, + "NameEnd": 567 + }, + "Alias": null }, "ColumnType": { "LeftParenPos": 584, diff --git a/parser/testdata/ddl/output/alter_table_add_projection.sql.golden.json b/parser/testdata/ddl/output/alter_table_add_projection.sql.golden.json index b7f4c47..168d3b6 100644 --- a/parser/testdata/ddl/output/alter_table_add_projection.sql.golden.json +++ b/parser/testdata/ddl/output/alter_table_add_projection.sql.golden.json @@ -38,10 +38,13 @@ "HasDistinct": false, "Items": [ { - "Name": "*", - "QuoteType": 0, - "NamePos": 84, - "NameEnd": 84 + "Expr": { + "Name": "*", + "QuoteType": 0, + "NamePos": 84, + "NameEnd": 84 + }, + "Alias": null } ] }, @@ -54,10 +57,13 @@ "HasDistinct": false, "Items": [ { - "Name": "user_name", - "QuoteType": 1, - "NamePos": 95, - "NameEnd": 104 + "Expr": { + "Name": "user_name", + "QuoteType": 1, + "NamePos": 95, + "NameEnd": 104 + }, + "Alias": null } ] }, @@ -73,10 +79,13 @@ "HasDistinct": false, "Items": [ { - "Name": "user_name", - "QuoteType": 1, - "NamePos": 114, - "NameEnd": 123 + "Expr": { + "Name": "user_name", + "QuoteType": 1, + "NamePos": 114, + "NameEnd": 123 + }, + "Alias": null } ] } diff --git a/parser/testdata/ddl/output/attach_table_basic.sql.golden.json b/parser/testdata/ddl/output/attach_table_basic.sql.golden.json index 3936530..0936734 100644 --- a/parser/testdata/ddl/output/attach_table_basic.sql.golden.json +++ b/parser/testdata/ddl/output/attach_table_basic.sql.golden.json @@ -325,14 +325,20 @@ "HasDistinct": false, "Items": [ { - "LiteralPos": 259, - "LiteralEnd": 311, - "Literal": "/clickhouse/tables/{layer}-{shard}/test/events_local" + "Expr": { + "LiteralPos": 259, + "LiteralEnd": 311, + "Literal": "/clickhouse/tables/{layer}-{shard}/test/events_local" + }, + "Alias": null }, { - "LiteralPos": 315, - "LiteralEnd": 324, - "Literal": "{replica}" + "Expr": { + "LiteralPos": 315, + "LiteralEnd": 324, + "Literal": "{replica}" + }, + "Alias": null } ] }, @@ -347,30 +353,36 @@ "HasDistinct": false, "Items": [ { - "Name": { - "Name": "toYYYYMMDD", - "QuoteType": 1, - "NamePos": 366, - "NameEnd": 376 - }, - "Params": { - "LeftParenPos": 376, - "RightParenPos": 379, - "Items": { - "ListPos": 377, - "ListEnd": 379, - "HasDistinct": false, - "Items": [ - { - "Name": "f3", - "QuoteType": 1, - "NamePos": 377, - "NameEnd": 379 - } - ] + "Expr": { + "Name": { + "Name": "toYYYYMMDD", + "QuoteType": 1, + "NamePos": 366, + "NameEnd": 376 }, - "ColumnArgList": null - } + "Params": { + "LeftParenPos": 376, + "RightParenPos": 379, + "Items": { + "ListPos": 377, + "ListEnd": 379, + "HasDistinct": false, + "Items": [ + { + "Expr": { + "Name": "f3", + "QuoteType": 1, + "NamePos": 377, + "NameEnd": 379 + }, + "Alias": null + } + ] + }, + "ColumnArgList": null + } + }, + "Alias": null } ] } @@ -427,27 +439,37 @@ "HasDistinct": false, "Items": [ { - "Name": "f0", - "QuoteType": 1, - "NamePos": 391, - "NameEnd": 393 + "Expr": { + "Name": "f0", + "QuoteType": 1, + "NamePos": 391, + "NameEnd": 393 + }, + "Alias": null }, { - "Name": "f1", - "QuoteType": 1, - "NamePos": 394, - "NameEnd": 396 + "Expr": { + "Name": "f1", + "QuoteType": 1, + "NamePos": 394, + "NameEnd": 396 + }, + "Alias": null }, { - "Name": "f2", - "QuoteType": 1, - "NamePos": 397, - "NameEnd": 399 + "Expr": { + "Name": "f2", + "QuoteType": 1, + "NamePos": 397, + "NameEnd": 399 + }, + "Alias": null } ] }, "ColumnArgList": null }, + "Alias": null, "Direction": "None" } ] diff --git a/parser/testdata/ddl/output/bug_001.sql.golden.json b/parser/testdata/ddl/output/bug_001.sql.golden.json index 6546f99..ef4a635 100644 --- a/parser/testdata/ddl/output/bug_001.sql.golden.json +++ b/parser/testdata/ddl/output/bug_001.sql.golden.json @@ -45,7 +45,7 @@ "TableSchema": null }, "SubQuery": { - "AsPos": 104, + "HasParen": false, "Select": { "SelectPos": 107, "StatementEnd": 635, @@ -59,7 +59,8 @@ "NamePos": 118, "NameEnd": 126 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null }, { "Expr": { @@ -68,394 +69,422 @@ "NamePos": 132, "NameEnd": 138 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null }, { "Expr": { - "Expr": { - "Name": { - "Name": "visitParamExtractString", - "QuoteType": 1, - "NamePos": 144, - "NameEnd": 167 - }, - "Params": { - "LeftParenPos": 167, - "RightParenPos": 183, - "Items": { - "ListPos": 168, - "ListEnd": 182, - "HasDistinct": false, - "Items": [ - { + "Name": { + "Name": "visitParamExtractString", + "QuoteType": 1, + "NamePos": 144, + "NameEnd": 167 + }, + "Params": { + "LeftParenPos": 167, + "RightParenPos": 183, + "Items": { + "ListPos": 168, + "ListEnd": 182, + "HasDistinct": false, + "Items": [ + { + "Expr": { "Name": "properties", "QuoteType": 1, "NamePos": 168, "NameEnd": 178 }, - { + "Alias": null + }, + { + "Expr": { "LiteralPos": 181, "LiteralEnd": 182, "Literal": "x" - } - ] - }, - "ColumnArgList": null - } - }, - "AliasPos": 188, - "Alias": { - "Name": "x", - "QuoteType": 1, - "NamePos": 188, - "NameEnd": 189 + }, + "Alias": null + } + ] + }, + "ColumnArgList": null } }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "x", + "QuoteType": 1, + "NamePos": 188, + "NameEnd": 189 + } }, { "Expr": { - "Expr": { - "Name": { - "Name": "visitParamExtractString", - "QuoteType": 1, - "NamePos": 195, - "NameEnd": 218 - }, - "Params": { - "LeftParenPos": 218, - "RightParenPos": 234, - "Items": { - "ListPos": 219, - "ListEnd": 233, - "HasDistinct": false, - "Items": [ - { + "Name": { + "Name": "visitParamExtractString", + "QuoteType": 1, + "NamePos": 195, + "NameEnd": 218 + }, + "Params": { + "LeftParenPos": 218, + "RightParenPos": 234, + "Items": { + "ListPos": 219, + "ListEnd": 233, + "HasDistinct": false, + "Items": [ + { + "Expr": { "Name": "properties", "QuoteType": 1, "NamePos": 219, "NameEnd": 229 }, - { + "Alias": null + }, + { + "Expr": { "LiteralPos": 232, "LiteralEnd": 233, "Literal": "y" - } - ] - }, - "ColumnArgList": null - } - }, - "AliasPos": 239, - "Alias": { - "Name": "y", - "QuoteType": 1, - "NamePos": 239, - "NameEnd": 240 + }, + "Alias": null + } + ] + }, + "ColumnArgList": null } }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "y", + "QuoteType": 1, + "NamePos": 239, + "NameEnd": 240 + } }, { "Expr": { - "Expr": { - "Name": { - "Name": "visitParamExtractString", - "QuoteType": 1, - "NamePos": 246, - "NameEnd": 269 - }, - "Params": { - "LeftParenPos": 269, - "RightParenPos": 285, - "Items": { - "ListPos": 270, - "ListEnd": 284, - "HasDistinct": false, - "Items": [ - { + "Name": { + "Name": "visitParamExtractString", + "QuoteType": 1, + "NamePos": 246, + "NameEnd": 269 + }, + "Params": { + "LeftParenPos": 269, + "RightParenPos": 285, + "Items": { + "ListPos": 270, + "ListEnd": 284, + "HasDistinct": false, + "Items": [ + { + "Expr": { "Name": "properties", "QuoteType": 1, "NamePos": 270, "NameEnd": 280 }, - { + "Alias": null + }, + { + "Expr": { "LiteralPos": 283, "LiteralEnd": 284, "Literal": "z" - } - ] - }, - "ColumnArgList": null - } - }, - "AliasPos": 290, - "Alias": { - "Name": "z", - "QuoteType": 1, - "NamePos": 290, - "NameEnd": 291 + }, + "Alias": null + } + ] + }, + "ColumnArgList": null } }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "z", + "QuoteType": 1, + "NamePos": 290, + "NameEnd": 291 + } }, { "Expr": { - "Expr": { - "Name": { - "Name": "visitParamExtractString", - "QuoteType": 1, - "NamePos": 297, - "NameEnd": 320 - }, - "Params": { - "LeftParenPos": 320, - "RightParenPos": 336, - "Items": { - "ListPos": 321, - "ListEnd": 335, - "HasDistinct": false, - "Items": [ - { + "Name": { + "Name": "visitParamExtractString", + "QuoteType": 1, + "NamePos": 297, + "NameEnd": 320 + }, + "Params": { + "LeftParenPos": 320, + "RightParenPos": 336, + "Items": { + "ListPos": 321, + "ListEnd": 335, + "HasDistinct": false, + "Items": [ + { + "Expr": { "Name": "properties", "QuoteType": 1, "NamePos": 321, "NameEnd": 331 }, - { + "Alias": null + }, + { + "Expr": { "LiteralPos": 334, "LiteralEnd": 335, "Literal": "a" - } - ] - }, - "ColumnArgList": null - } - }, - "AliasPos": 341, - "Alias": { - "Name": "a", - "QuoteType": 1, - "NamePos": 341, - "NameEnd": 342 + }, + "Alias": null + } + ] + }, + "ColumnArgList": null } }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "a", + "QuoteType": 1, + "NamePos": 341, + "NameEnd": 342 + } }, { "Expr": { - "Expr": { - "Name": { - "Name": "visitParamExtractString", - "QuoteType": 1, - "NamePos": 348, - "NameEnd": 371 - }, - "Params": { - "LeftParenPos": 371, - "RightParenPos": 387, - "Items": { - "ListPos": 372, - "ListEnd": 386, - "HasDistinct": false, - "Items": [ - { + "Name": { + "Name": "visitParamExtractString", + "QuoteType": 1, + "NamePos": 348, + "NameEnd": 371 + }, + "Params": { + "LeftParenPos": 371, + "RightParenPos": 387, + "Items": { + "ListPos": 372, + "ListEnd": 386, + "HasDistinct": false, + "Items": [ + { + "Expr": { "Name": "properties", "QuoteType": 1, "NamePos": 372, "NameEnd": 382 }, - { + "Alias": null + }, + { + "Expr": { "LiteralPos": 385, "LiteralEnd": 386, "Literal": "b" - } - ] - }, - "ColumnArgList": null - } - }, - "AliasPos": 392, - "Alias": { - "Name": "b", - "QuoteType": 1, - "NamePos": 392, - "NameEnd": 393 + }, + "Alias": null + } + ] + }, + "ColumnArgList": null } }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "b", + "QuoteType": 1, + "NamePos": 392, + "NameEnd": 393 + } }, { "Expr": { - "Expr": { - "Name": { - "Name": "visitParamExtractString", - "QuoteType": 1, - "NamePos": 399, - "NameEnd": 422 - }, - "Params": { - "LeftParenPos": 422, - "RightParenPos": 438, - "Items": { - "ListPos": 423, - "ListEnd": 437, - "HasDistinct": false, - "Items": [ - { + "Name": { + "Name": "visitParamExtractString", + "QuoteType": 1, + "NamePos": 399, + "NameEnd": 422 + }, + "Params": { + "LeftParenPos": 422, + "RightParenPos": 438, + "Items": { + "ListPos": 423, + "ListEnd": 437, + "HasDistinct": false, + "Items": [ + { + "Expr": { "Name": "properties", "QuoteType": 1, "NamePos": 423, "NameEnd": 433 }, - { + "Alias": null + }, + { + "Expr": { "LiteralPos": 436, "LiteralEnd": 437, "Literal": "c" - } - ] - }, - "ColumnArgList": null - } - }, - "AliasPos": 443, - "Alias": { - "Name": "c", - "QuoteType": 1, - "NamePos": 443, - "NameEnd": 444 + }, + "Alias": null + } + ] + }, + "ColumnArgList": null } }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "c", + "QuoteType": 1, + "NamePos": 443, + "NameEnd": 444 + } }, { "Expr": { - "Expr": { - "Name": { - "Name": "visitParamExtractString", - "QuoteType": 1, - "NamePos": 450, - "NameEnd": 473 - }, - "Params": { - "LeftParenPos": 473, - "RightParenPos": 489, - "Items": { - "ListPos": 474, - "ListEnd": 488, - "HasDistinct": false, - "Items": [ - { + "Name": { + "Name": "visitParamExtractString", + "QuoteType": 1, + "NamePos": 450, + "NameEnd": 473 + }, + "Params": { + "LeftParenPos": 473, + "RightParenPos": 489, + "Items": { + "ListPos": 474, + "ListEnd": 488, + "HasDistinct": false, + "Items": [ + { + "Expr": { "Name": "properties", "QuoteType": 1, "NamePos": 474, "NameEnd": 484 }, - { + "Alias": null + }, + { + "Expr": { "LiteralPos": 487, "LiteralEnd": 488, "Literal": "d" - } - ] - }, - "ColumnArgList": null - } - }, - "AliasPos": 494, - "Alias": { - "Name": "d", - "QuoteType": 1, - "NamePos": 494, - "NameEnd": 495 + }, + "Alias": null + } + ] + }, + "ColumnArgList": null } }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "d", + "QuoteType": 1, + "NamePos": 494, + "NameEnd": 495 + } }, { "Expr": { - "Expr": { - "Name": { - "Name": "visitParamExtractInt", - "QuoteType": 1, - "NamePos": 501, - "NameEnd": 521 - }, - "Params": { - "LeftParenPos": 521, - "RightParenPos": 537, - "Items": { - "ListPos": 522, - "ListEnd": 536, - "HasDistinct": false, - "Items": [ - { + "Name": { + "Name": "visitParamExtractInt", + "QuoteType": 1, + "NamePos": 501, + "NameEnd": 521 + }, + "Params": { + "LeftParenPos": 521, + "RightParenPos": 537, + "Items": { + "ListPos": 522, + "ListEnd": 536, + "HasDistinct": false, + "Items": [ + { + "Expr": { "Name": "properties", "QuoteType": 1, "NamePos": 522, "NameEnd": 532 }, - { + "Alias": null + }, + { + "Expr": { "LiteralPos": 535, "LiteralEnd": 536, "Literal": "e" - } - ] - }, - "ColumnArgList": null - } - }, - "AliasPos": 542, - "Alias": { - "Name": "e", - "QuoteType": 1, - "NamePos": 542, - "NameEnd": 543 + }, + "Alias": null + } + ] + }, + "ColumnArgList": null } }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "e", + "QuoteType": 1, + "NamePos": 542, + "NameEnd": 543 + } }, { "Expr": { - "Expr": { - "Name": { - "Name": "visitParamExtractInt", - "QuoteType": 1, - "NamePos": 549, - "NameEnd": 569 - }, - "Params": { - "LeftParenPos": 569, - "RightParenPos": 585, - "Items": { - "ListPos": 570, - "ListEnd": 584, - "HasDistinct": false, - "Items": [ - { + "Name": { + "Name": "visitParamExtractInt", + "QuoteType": 1, + "NamePos": 549, + "NameEnd": 569 + }, + "Params": { + "LeftParenPos": 569, + "RightParenPos": 585, + "Items": { + "ListPos": 570, + "ListEnd": 584, + "HasDistinct": false, + "Items": [ + { + "Expr": { "Name": "properties", "QuoteType": 1, "NamePos": 570, "NameEnd": 580 }, - { + "Alias": null + }, + { + "Expr": { "LiteralPos": 583, "LiteralEnd": 584, "Literal": "f" - } - ] - }, - "ColumnArgList": null - } - }, - "AliasPos": 590, - "Alias": { - "Name": "f", - "QuoteType": 1, - "NamePos": 590, - "NameEnd": 591 + }, + "Alias": null + } + ] + }, + "ColumnArgList": null } }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "f", + "QuoteType": 1, + "NamePos": 590, + "NameEnd": 591 + } } ], "From": { diff --git a/parser/testdata/ddl/output/create_distributed_table.sql.golden.json b/parser/testdata/ddl/output/create_distributed_table.sql.golden.json index c856202..37c4d3a 100644 --- a/parser/testdata/ddl/output/create_distributed_table.sql.golden.json +++ b/parser/testdata/ddl/output/create_distributed_table.sql.golden.json @@ -59,41 +59,53 @@ "HasDistinct": false, "Items": [ { - "Name": "default_cluster", - "QuoteType": 1, - "NamePos": 104, - "NameEnd": 119 - }, - { - "Name": "test", - "QuoteType": 1, - "NamePos": 125, - "NameEnd": 129 + "Expr": { + "Name": "default_cluster", + "QuoteType": 1, + "NamePos": 104, + "NameEnd": 119 + }, + "Alias": null }, { - "Name": "events_local", - "QuoteType": 1, - "NamePos": 135, - "NameEnd": 147 + "Expr": { + "Name": "test", + "QuoteType": 1, + "NamePos": 125, + "NameEnd": 129 + }, + "Alias": null }, { - "Name": { - "Name": "rand", + "Expr": { + "Name": "events_local", "QuoteType": 1, - "NamePos": 153, - "NameEnd": 157 + "NamePos": 135, + "NameEnd": 147 }, - "Params": { - "LeftParenPos": 157, - "RightParenPos": 158, - "Items": { - "ListPos": 158, - "ListEnd": 158, - "HasDistinct": false, - "Items": [] + "Alias": null + }, + { + "Expr": { + "Name": { + "Name": "rand", + "QuoteType": 1, + "NamePos": 153, + "NameEnd": 157 }, - "ColumnArgList": null - } + "Params": { + "LeftParenPos": 157, + "RightParenPos": 158, + "Items": { + "ListPos": 158, + "ListEnd": 158, + "HasDistinct": false, + "Items": [] + }, + "ColumnArgList": null + } + }, + "Alias": null } ] }, diff --git a/parser/testdata/ddl/output/create_function_simple.sql.golden.json b/parser/testdata/ddl/output/create_function_simple.sql.golden.json index 4ca1d4c..db749e9 100644 --- a/parser/testdata/ddl/output/create_function_simple.sql.golden.json +++ b/parser/testdata/ddl/output/create_function_simple.sql.golden.json @@ -18,22 +18,31 @@ "HasDistinct": false, "Items": [ { - "Name": "x", - "QuoteType": 1, - "NamePos": 36, - "NameEnd": 37 + "Expr": { + "Name": "x", + "QuoteType": 1, + "NamePos": 36, + "NameEnd": 37 + }, + "Alias": null }, { - "Name": "k", - "QuoteType": 1, - "NamePos": 39, - "NameEnd": 40 + "Expr": { + "Name": "k", + "QuoteType": 1, + "NamePos": 39, + "NameEnd": 40 + }, + "Alias": null }, { - "Name": "b", - "QuoteType": 1, - "NamePos": 42, - "NameEnd": 43 + "Expr": { + "Name": "b", + "QuoteType": 1, + "NamePos": 42, + "NameEnd": 43 + }, + "Alias": null } ] }, 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 19b6e6c..d3295f9 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 @@ -76,7 +76,7 @@ } }, "SubQuery": { - "AsPos": 75, + "HasParen": false, "Select": { "SelectPos": 78, "StatementEnd": 101, @@ -90,7 +90,8 @@ "NamePos": 85, "NameEnd": 87 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null } ], "From": { 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 a7da2e6..69c32d2 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 @@ -242,7 +242,7 @@ } }, "SubQuery": { - "AsPos": 205, + "HasParen": false, "Select": { "SelectPos": 208, "StatementEnd": 537, @@ -256,7 +256,8 @@ "NamePos": 215, "NameEnd": 217 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null }, { "Expr": { @@ -265,179 +266,192 @@ "NamePos": 226, "NameEnd": 228 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null }, { "Expr": { - "Expr": { - "Name": { - "Name": "visitParamExtractString", - "QuoteType": 1, - "NamePos": 237, - "NameEnd": 260 - }, - "Params": { - "LeftParenPos": 260, - "RightParenPos": 277, - "Items": { - "ListPos": 261, - "ListEnd": 276, - "HasDistinct": false, - "Items": [ - { + "Name": { + "Name": "visitParamExtractString", + "QuoteType": 1, + "NamePos": 237, + "NameEnd": 260 + }, + "Params": { + "LeftParenPos": 260, + "RightParenPos": 277, + "Items": { + "ListPos": 261, + "ListEnd": 276, + "HasDistinct": false, + "Items": [ + { + "Expr": { "Name": "properties", "QuoteType": 1, "NamePos": 261, "NameEnd": 271 }, - { + "Alias": null + }, + { + "Expr": { "LiteralPos": 274, "LiteralEnd": 276, "Literal": "f3" - } - ] - }, - "ColumnArgList": null - } - }, - "AliasPos": 284, - "Alias": { - "Name": "f3", - "QuoteType": 1, - "NamePos": 284, - "NameEnd": 286 + }, + "Alias": null + } + ] + }, + "ColumnArgList": null } }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "f3", + "QuoteType": 1, + "NamePos": 284, + "NameEnd": 286 + } }, { "Expr": { - "Expr": { - "Name": { - "Name": "visitParamExtractString", - "QuoteType": 1, - "NamePos": 295, - "NameEnd": 318 - }, - "Params": { - "LeftParenPos": 318, - "RightParenPos": 335, - "Items": { - "ListPos": 319, - "ListEnd": 334, - "HasDistinct": false, - "Items": [ - { + "Name": { + "Name": "visitParamExtractString", + "QuoteType": 1, + "NamePos": 295, + "NameEnd": 318 + }, + "Params": { + "LeftParenPos": 318, + "RightParenPos": 335, + "Items": { + "ListPos": 319, + "ListEnd": 334, + "HasDistinct": false, + "Items": [ + { + "Expr": { "Name": "properties", "QuoteType": 1, "NamePos": 319, "NameEnd": 329 }, - { + "Alias": null + }, + { + "Expr": { "LiteralPos": 332, "LiteralEnd": 334, "Literal": "f4" - } - ] - }, - "ColumnArgList": null - } - }, - "AliasPos": 345, - "Alias": { - "Name": "f4", - "QuoteType": 1, - "NamePos": 345, - "NameEnd": 347 + }, + "Alias": null + } + ] + }, + "ColumnArgList": null } }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "f4", + "QuoteType": 1, + "NamePos": 345, + "NameEnd": 347 + } }, { "Expr": { - "Expr": { - "Name": { - "Name": "visitParamExtractString", - "QuoteType": 1, - "NamePos": 356, - "NameEnd": 379 - }, - "Params": { - "LeftParenPos": 379, - "RightParenPos": 396, - "Items": { - "ListPos": 380, - "ListEnd": 395, - "HasDistinct": false, - "Items": [ - { + "Name": { + "Name": "visitParamExtractString", + "QuoteType": 1, + "NamePos": 356, + "NameEnd": 379 + }, + "Params": { + "LeftParenPos": 379, + "RightParenPos": 396, + "Items": { + "ListPos": 380, + "ListEnd": 395, + "HasDistinct": false, + "Items": [ + { + "Expr": { "Name": "properties", "QuoteType": 1, "NamePos": 380, "NameEnd": 390 }, - { + "Alias": null + }, + { + "Expr": { "LiteralPos": 393, "LiteralEnd": 395, "Literal": "f5" - } - ] - }, - "ColumnArgList": null - } - }, - "AliasPos": 404, - "Alias": { - "Name": "f5", - "QuoteType": 1, - "NamePos": 404, - "NameEnd": 406 + }, + "Alias": null + } + ] + }, + "ColumnArgList": null } }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "f5", + "QuoteType": 1, + "NamePos": 404, + "NameEnd": 406 + } }, { "Expr": { - "Expr": { - "Name": { - "Name": "visitParamExtractInt", - "QuoteType": 1, - "NamePos": 412, - "NameEnd": 432 - }, - "Params": { - "LeftParenPos": 432, - "RightParenPos": 449, - "Items": { - "ListPos": 433, - "ListEnd": 448, - "HasDistinct": false, - "Items": [ - { + "Name": { + "Name": "visitParamExtractInt", + "QuoteType": 1, + "NamePos": 412, + "NameEnd": 432 + }, + "Params": { + "LeftParenPos": 432, + "RightParenPos": 449, + "Items": { + "ListPos": 433, + "ListEnd": 448, + "HasDistinct": false, + "Items": [ + { + "Expr": { "Name": "properties", "QuoteType": 1, "NamePos": 433, "NameEnd": 443 }, - { + "Alias": null + }, + { + "Expr": { "LiteralPos": 446, "LiteralEnd": 448, "Literal": "f6" - } - ] - }, - "ColumnArgList": null - } - }, - "AliasPos": 454, - "Alias": { - "Name": "f6", - "QuoteType": 1, - "NamePos": 454, - "NameEnd": 456 + }, + "Alias": null + } + ] + }, + "ColumnArgList": null } }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "f6", + "QuoteType": 1, + "NamePos": 454, + "NameEnd": 456 + } } ], "From": { 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 3dab6e6..ffc7715 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 @@ -39,14 +39,20 @@ "HasDistinct": false, "Items": [ { - "LiteralPos": 101, - "LiteralEnd": 136, - "Literal": "/clickhouse/{layer}-{shard}/test/t0" + "Expr": { + "LiteralPos": 101, + "LiteralEnd": 136, + "Literal": "/clickhouse/{layer}-{shard}/test/t0" + }, + "Alias": null }, { - "LiteralPos": 140, - "LiteralEnd": 149, - "Literal": "{replica}" + "Expr": { + "LiteralPos": 140, + "LiteralEnd": 149, + "Literal": "{replica}" + }, + "Alias": null } ] }, @@ -61,30 +67,36 @@ "HasDistinct": false, "Items": [ { - "Name": { - "Name": "toYYYYMM", - "QuoteType": 1, - "NamePos": 165, - "NameEnd": 173 - }, - "Params": { - "LeftParenPos": 173, - "RightParenPos": 176, - "Items": { - "ListPos": 174, - "ListEnd": 176, - "HasDistinct": false, - "Items": [ - { - "Name": "f0", - "QuoteType": 1, - "NamePos": 174, - "NameEnd": 176 - } - ] + "Expr": { + "Name": { + "Name": "toYYYYMM", + "QuoteType": 1, + "NamePos": 165, + "NameEnd": 173 }, - "ColumnArgList": null - } + "Params": { + "LeftParenPos": 173, + "RightParenPos": 176, + "Items": { + "ListPos": 174, + "ListEnd": 176, + "HasDistinct": false, + "Items": [ + { + "Expr": { + "Name": "f0", + "QuoteType": 1, + "NamePos": 174, + "NameEnd": 176 + }, + "Alias": null + } + ] + }, + "ColumnArgList": null + } + }, + "Alias": null } ] } @@ -107,15 +119,19 @@ "HasDistinct": false, "Items": [ { - "Name": "f0", - "QuoteType": 1, - "NamePos": 188, - "NameEnd": 190 + "Expr": { + "Name": "f0", + "QuoteType": 1, + "NamePos": 188, + "NameEnd": 190 + }, + "Alias": null } ] }, "ColumnArgList": null }, + "Alias": null, "Direction": "None" } ] @@ -123,7 +139,7 @@ }, "Destination": null, "SubQuery": { - "AsPos": 201, + "HasParen": false, "Select": { "SelectPos": 204, "StatementEnd": 460, @@ -137,7 +153,8 @@ "NamePos": 211, "NameEnd": 213 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null }, { "Expr": { @@ -146,7 +163,8 @@ "NamePos": 214, "NameEnd": 216 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null }, { "Expr": { @@ -155,51 +173,55 @@ "NamePos": 217, "NameEnd": 219 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null }, { "Expr": { - "Expr": { - "Name": { - "Name": "coalesce", - "QuoteType": 1, - "NamePos": 220, - "NameEnd": 228 - }, - "Params": { - "LeftParenPos": 228, - "RightParenPos": 234, - "Items": { - "ListPos": 229, - "ListEnd": 234, - "HasDistinct": false, - "Items": [ - { + "Name": { + "Name": "coalesce", + "QuoteType": 1, + "NamePos": 220, + "NameEnd": 228 + }, + "Params": { + "LeftParenPos": 228, + "RightParenPos": 234, + "Items": { + "ListPos": 229, + "ListEnd": 234, + "HasDistinct": false, + "Items": [ + { + "Expr": { "Name": "f0", "QuoteType": 1, "NamePos": 229, "NameEnd": 231 }, - { + "Alias": null + }, + { + "Expr": { "Name": "f1", "QuoteType": 1, "NamePos": 232, "NameEnd": 234 - } - ] - }, - "ColumnArgList": null - } - }, - "AliasPos": 239, - "Alias": { - "Name": "f333", - "QuoteType": 1, - "NamePos": 239, - "NameEnd": 243 + }, + "Alias": null + } + ] + }, + "ColumnArgList": null } }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "f333", + "QuoteType": 1, + "NamePos": 239, + "NameEnd": 243 + } } ], "From": { @@ -211,40 +233,44 @@ "Alias": null, "Expr": { "Expr": { - "SelectPos": 254, - "StatementEnd": 433, - "With": null, - "Top": null, - "SelectItems": [ - { - "Expr": { - "Name": "f0", - "QuoteType": 1, - "NamePos": 270, - "NameEnd": 272 + "HasParen": true, + "Select": { + "SelectPos": 254, + "StatementEnd": 433, + "With": null, + "Top": null, + "SelectItems": [ + { + "Expr": { + "Name": "f0", + "QuoteType": 1, + "NamePos": 270, + "NameEnd": 272 + }, + "Modifiers": [], + "Alias": null }, - "Modifiers": [] - }, - { - "Expr": { - "Name": "f1", - "QuoteType": 1, - "NamePos": 273, - "NameEnd": 275 + { + "Expr": { + "Name": "f1", + "QuoteType": 1, + "NamePos": 273, + "NameEnd": 275 + }, + "Modifiers": [], + "Alias": null }, - "Modifiers": [] - }, - { - "Expr": { - "Name": "f2", - "QuoteType": 1, - "NamePos": 276, - "NameEnd": 278 + { + "Expr": { + "Name": "f2", + "QuoteType": 1, + "NamePos": 276, + "NameEnd": 278 + }, + "Modifiers": [], + "Alias": null }, - "Modifiers": [] - }, - { - "Expr": { + { "Expr": { "Function": { "Name": { @@ -277,10 +303,13 @@ "HasDistinct": false, "Items": [ { - "Name": "f0", - "QuoteType": 1, - "NamePos": 320, - "NameEnd": 322 + "Expr": { + "Name": "f0", + "QuoteType": 1, + "NamePos": 320, + "NameEnd": 322 + }, + "Alias": null } ] } @@ -307,22 +336,29 @@ "HasDistinct": false, "Items": [ { - "Name": "f1", - "QuoteType": 1, - "NamePos": 341, - "NameEnd": 343 + "Expr": { + "Name": "f1", + "QuoteType": 1, + "NamePos": 341, + "NameEnd": 343 + }, + "Alias": null }, { - "Name": "f2", - "QuoteType": 1, - "NamePos": 344, - "NameEnd": 346 + "Expr": { + "Name": "f2", + "QuoteType": 1, + "NamePos": 344, + "NameEnd": 346 + }, + "Alias": null } ] }, "ColumnArgList": null } }, + "Alias": null, "Direction": "None" } ] @@ -330,121 +366,129 @@ "Frame": null } }, - "AliasPos": 352, + "Modifiers": [], "Alias": { "Name": "rn", "QuoteType": 1, "NamePos": 352, "NameEnd": 354 } - }, - "Modifiers": [] - } - ], - "From": { - "FromPos": 360, - "Expr": { - "Table": { - "TablePos": 365, - "TableEnd": 371, - "Alias": null, - "Expr": { - "Database": { - "Name": "test", - "QuoteType": 1, - "NamePos": 365, - "NameEnd": 369 + } + ], + "From": { + "FromPos": 360, + "Expr": { + "Table": { + "TablePos": 365, + "TableEnd": 371, + "Alias": null, + "Expr": { + "Database": { + "Name": "test", + "QuoteType": 1, + "NamePos": 365, + "NameEnd": 369 + }, + "Table": { + "Name": "t", + "QuoteType": 1, + "NamePos": 370, + "NameEnd": 371 + } }, - "Table": { - "Name": "t", - "QuoteType": 1, - "NamePos": 370, - "NameEnd": 371 - } + "HasFinal": false }, + "StatementEnd": 371, + "SampleRatio": null, "HasFinal": false - }, - "StatementEnd": 371, - "SampleRatio": null, - "HasFinal": false - } - }, - "ArrayJoin": null, - "Window": null, - "Prewhere": null, - "Where": { - "WherePos": 377, - "Expr": { - "LeftExpr": { + } + }, + "ArrayJoin": null, + "Window": null, + "Prewhere": null, + "Where": { + "WherePos": 377, + "Expr": { "LeftExpr": { - "Name": "f3", - "QuoteType": 1, - "NamePos": 383, - "NameEnd": 385 - }, - "Operation": "IN", - "RightExpr": { - "LeftParenPos": 389, - "RightParenPos": 410, - "Items": { - "ListPos": 391, - "ListEnd": 409, - "HasDistinct": false, - "Items": [ - { - "LiteralPos": 391, - "LiteralEnd": 394, - "Literal": "foo" - }, - { - "LiteralPos": 398, - "LiteralEnd": 401, - "Literal": "bar" - }, - { - "LiteralPos": 405, - "LiteralEnd": 409, - "Literal": "test" - } - ] + "LeftExpr": { + "Name": "f3", + "QuoteType": 1, + "NamePos": 383, + "NameEnd": 385 }, - "ColumnArgList": null - }, - "HasGlobal": false, - "HasNot": false - }, - "Operation": "AND", - "RightExpr": { - "LeftExpr": { - "Name": "env", - "QuoteType": 1, - "NamePos": 423, - "NameEnd": 426 + "Operation": "IN", + "RightExpr": { + "LeftParenPos": 389, + "RightParenPos": 410, + "Items": { + "ListPos": 391, + "ListEnd": 409, + "HasDistinct": false, + "Items": [ + { + "Expr": { + "LiteralPos": 391, + "LiteralEnd": 394, + "Literal": "foo" + }, + "Alias": null + }, + { + "Expr": { + "LiteralPos": 398, + "LiteralEnd": 401, + "Literal": "bar" + }, + "Alias": null + }, + { + "Expr": { + "LiteralPos": 405, + "LiteralEnd": 409, + "Literal": "test" + }, + "Alias": null + } + ] + }, + "ColumnArgList": null + }, + "HasGlobal": false, + "HasNot": false }, - "Operation": "=", + "Operation": "AND", "RightExpr": { - "LiteralPos": 429, - "LiteralEnd": 433, - "Literal": "test" + "LeftExpr": { + "Name": "env", + "QuoteType": 1, + "NamePos": 423, + "NameEnd": 426 + }, + "Operation": "=", + "RightExpr": { + "LiteralPos": 429, + "LiteralEnd": 433, + "Literal": "test" + }, + "HasGlobal": false, + "HasNot": false }, "HasGlobal": false, "HasNot": false - }, - "HasGlobal": false, - "HasNot": false - } - }, - "GroupBy": null, - "WithTotal": false, - "Having": null, - "OrderBy": null, - "LimitBy": null, - "Limit": null, - "Settings": null, - "Format": null, - "UnionAll": null, - "UnionDistinct": null, - "Except": null + } + }, + "GroupBy": null, + "WithTotal": false, + "Having": null, + "OrderBy": null, + "LimitBy": null, + "Limit": null, + "Settings": null, + "Format": null, + "UnionAll": null, + "UnionDistinct": null, + "Except": null + } }, "AliasPos": 444, "Alias": { diff --git a/parser/testdata/ddl/output/create_table_basic.sql.golden.json b/parser/testdata/ddl/output/create_table_basic.sql.golden.json index c1e268d..4718328 100644 --- a/parser/testdata/ddl/output/create_table_basic.sql.golden.json +++ b/parser/testdata/ddl/output/create_table_basic.sql.golden.json @@ -581,28 +581,34 @@ "HasDistinct": false, "Items": [ { - "Object": { - "Name": "f7", - "QuoteType": 1, - "NamePos": 520, - "NameEnd": 522 - }, - "Params": { - "LeftBracketPos": 522, - "RightBracketPos": 528, - "Items": { - "ListPos": 524, - "ListEnd": 527, - "HasDistinct": false, - "Items": [ - { - "LiteralPos": 524, - "LiteralEnd": 527, - "Literal": "f70" - } - ] + "Expr": { + "Object": { + "Name": "f7", + "QuoteType": 1, + "NamePos": 520, + "NameEnd": 522 + }, + "Params": { + "LeftBracketPos": 522, + "RightBracketPos": 528, + "Items": { + "ListPos": 524, + "ListEnd": 527, + "HasDistinct": false, + "Items": [ + { + "Expr": { + "LiteralPos": 524, + "LiteralEnd": 527, + "Literal": "f70" + }, + "Alias": null + } + ] + } } - } + }, + "Alias": null } ] }, @@ -670,22 +676,31 @@ "HasDistinct": false, "Items": [ { - "Name": "f0", - "QuoteType": 1, - "NamePos": 592, - "NameEnd": 594 + "Expr": { + "Name": "f0", + "QuoteType": 1, + "NamePos": 592, + "NameEnd": 594 + }, + "Alias": null }, { - "Name": "f1", - "QuoteType": 1, - "NamePos": 596, - "NameEnd": 598 + "Expr": { + "Name": "f1", + "QuoteType": 1, + "NamePos": 596, + "NameEnd": 598 + }, + "Alias": null }, { - "Name": "f2", - "QuoteType": 1, - "NamePos": 600, - "NameEnd": 602 + "Expr": { + "Name": "f2", + "QuoteType": 1, + "NamePos": 600, + "NameEnd": 602 + }, + "Alias": null } ] }, @@ -700,30 +715,36 @@ "HasDistinct": false, "Items": [ { - "Name": { - "Name": "toYYYYMMDD", - "QuoteType": 1, - "NamePos": 617, - "NameEnd": 627 - }, - "Params": { - "LeftParenPos": 627, - "RightParenPos": 630, - "Items": { - "ListPos": 628, - "ListEnd": 630, - "HasDistinct": false, - "Items": [ - { - "Name": "f3", - "QuoteType": 1, - "NamePos": 628, - "NameEnd": 630 - } - ] + "Expr": { + "Name": { + "Name": "toYYYYMMDD", + "QuoteType": 1, + "NamePos": 617, + "NameEnd": 627 }, - "ColumnArgList": null - } + "Params": { + "LeftParenPos": 627, + "RightParenPos": 630, + "Items": { + "ListPos": 628, + "ListEnd": 630, + "HasDistinct": false, + "Items": [ + { + "Expr": { + "Name": "f3", + "QuoteType": 1, + "NamePos": 628, + "NameEnd": 630 + }, + "Alias": null + } + ] + }, + "ColumnArgList": null + } + }, + "Alias": null } ] } @@ -780,27 +801,37 @@ "HasDistinct": false, "Items": [ { - "Name": "f1", - "QuoteType": 1, - "NamePos": 668, - "NameEnd": 670 + "Expr": { + "Name": "f1", + "QuoteType": 1, + "NamePos": 668, + "NameEnd": 670 + }, + "Alias": null }, { - "Name": "f2", - "QuoteType": 1, - "NamePos": 671, - "NameEnd": 673 + "Expr": { + "Name": "f2", + "QuoteType": 1, + "NamePos": 671, + "NameEnd": 673 + }, + "Alias": null }, { - "Name": "f3", - "QuoteType": 1, - "NamePos": 674, - "NameEnd": 676 + "Expr": { + "Name": "f3", + "QuoteType": 1, + "NamePos": 674, + "NameEnd": 676 + }, + "Alias": null } ] }, "ColumnArgList": null }, + "Alias": null, "Direction": "None" } ] diff --git a/parser/testdata/ddl/output/create_table_with_codec_delta.sql.golden.json b/parser/testdata/ddl/output/create_table_with_codec_delta.sql.golden.json index b3fa45a..df3adfc 100644 --- a/parser/testdata/ddl/output/create_table_with_codec_delta.sql.golden.json +++ b/parser/testdata/ddl/output/create_table_with_codec_delta.sql.golden.json @@ -389,22 +389,28 @@ "DotIdent": null }, "ColumnExpr": { - "LeftParenPos": 337, - "RightParenPos": 347, - "Items": { - "ListPos": 338, - "ListEnd": 347, - "HasDistinct": false, - "Items": [ - { - "Name": "timestamp", - "QuoteType": 1, - "NamePos": 338, - "NameEnd": 347 - } - ] + "Expr": { + "LeftParenPos": 337, + "RightParenPos": 347, + "Items": { + "ListPos": 338, + "ListEnd": 347, + "HasDistinct": false, + "Items": [ + { + "Expr": { + "Name": "timestamp", + "QuoteType": 1, + "NamePos": 338, + "NameEnd": 347 + }, + "Alias": null + } + ] + }, + "ColumnArgList": null }, - "ColumnArgList": null + "Alias": null }, "ColumnType": { "Name": { @@ -438,14 +444,20 @@ "HasDistinct": false, "Items": [ { - "LiteralPos": 407, - "LiteralEnd": 423, - "Literal": "/root/test_local" + "Expr": { + "LiteralPos": 407, + "LiteralEnd": 423, + "Literal": "/root/test_local" + }, + "Alias": null }, { - "LiteralPos": 427, - "LiteralEnd": 436, - "Literal": "{replica}" + "Expr": { + "LiteralPos": 427, + "LiteralEnd": 436, + "Literal": "{replica}" + }, + "Alias": null } ] }, @@ -460,30 +472,36 @@ "HasDistinct": false, "Items": [ { - "Name": { - "Name": "toStartOfHour", - "QuoteType": 1, - "NamePos": 452, - "NameEnd": 465 - }, - "Params": { - "LeftParenPos": 465, - "RightParenPos": 477, - "Items": { - "ListPos": 467, - "ListEnd": 476, - "HasDistinct": false, - "Items": [ - { - "Name": "timestamp", - "QuoteType": 3, - "NamePos": 467, - "NameEnd": 476 - } - ] + "Expr": { + "Name": { + "Name": "toStartOfHour", + "QuoteType": 1, + "NamePos": 452, + "NameEnd": 465 }, - "ColumnArgList": null - } + "Params": { + "LeftParenPos": 465, + "RightParenPos": 477, + "Items": { + "ListPos": 467, + "ListEnd": 476, + "HasDistinct": false, + "Items": [ + { + "Expr": { + "Name": "timestamp", + "QuoteType": 3, + "NamePos": 467, + "NameEnd": 476 + }, + "Alias": null + } + ] + }, + "ColumnArgList": null + } + }, + "Alias": null } ] } @@ -512,10 +530,13 @@ "HasDistinct": false, "Items": [ { - "Name": "timestamp", - "QuoteType": 3, - "NamePos": 554, - "NameEnd": 563 + "Expr": { + "Name": "timestamp", + "QuoteType": 3, + "NamePos": 554, + "NameEnd": 563 + }, + "Alias": null } ] }, @@ -561,10 +582,13 @@ "HasDistinct": false, "Items": [ { - "Name": "timestamp", - "QuoteType": 3, - "NamePos": 598, - "NameEnd": 607 + "Expr": { + "Name": "timestamp", + "QuoteType": 3, + "NamePos": 598, + "NameEnd": 607 + }, + "Alias": null } ] }, @@ -688,41 +712,51 @@ "HasDistinct": false, "Items": [ { - "Name": { - "Name": "toUnixTimestamp64Nano", - "QuoteType": 1, - "NamePos": 489, - "NameEnd": 510 - }, - "Params": { - "LeftParenPos": 510, - "RightParenPos": 522, - "Items": { - "ListPos": 512, - "ListEnd": 521, - "HasDistinct": false, - "Items": [ - { - "Name": "timestamp", - "QuoteType": 3, - "NamePos": 512, - "NameEnd": 521 - } - ] + "Expr": { + "Name": { + "Name": "toUnixTimestamp64Nano", + "QuoteType": 1, + "NamePos": 489, + "NameEnd": 510 }, - "ColumnArgList": null - } + "Params": { + "LeftParenPos": 510, + "RightParenPos": 522, + "Items": { + "ListPos": 512, + "ListEnd": 521, + "HasDistinct": false, + "Items": [ + { + "Expr": { + "Name": "timestamp", + "QuoteType": 3, + "NamePos": 512, + "NameEnd": 521 + }, + "Alias": null + } + ] + }, + "ColumnArgList": null + } + }, + "Alias": null }, { - "Name": "api_id", - "QuoteType": 3, - "NamePos": 526, - "NameEnd": 532 + "Expr": { + "Name": "api_id", + "QuoteType": 3, + "NamePos": 526, + "NameEnd": 532 + }, + "Alias": null } ] }, "ColumnArgList": null }, + "Alias": null, "Direction": "None" } ] diff --git a/parser/testdata/ddl/output/create_table_with_index.sql.golden.json b/parser/testdata/ddl/output/create_table_with_index.sql.golden.json index e9ec0d2..0a2f0aa 100644 --- a/parser/testdata/ddl/output/create_table_with_index.sql.golden.json +++ b/parser/testdata/ddl/output/create_table_with_index.sql.golden.json @@ -248,10 +248,13 @@ "DotIdent": null }, "ColumnExpr": { - "Name": "id", - "QuoteType": 1, - "NamePos": 196, - "NameEnd": 198 + "Expr": { + "Name": "id", + "QuoteType": 1, + "NamePos": 196, + "NameEnd": 198 + }, + "Alias": null }, "ColumnType": { "Name": { @@ -280,10 +283,13 @@ "DotIdent": null }, "ColumnExpr": { - "Name": "api_id", - "QuoteType": 1, - "NamePos": 245, - "NameEnd": 251 + "Expr": { + "Name": "api_id", + "QuoteType": 1, + "NamePos": 245, + "NameEnd": 251 + }, + "Alias": null }, "ColumnType": { "LeftParenPos": 261, @@ -322,10 +328,13 @@ "DotIdent": null }, "ColumnExpr": { - "Name": "arr", - "QuoteType": 1, - "NamePos": 296, - "NameEnd": 299 + "Expr": { + "Name": "arr", + "QuoteType": 1, + "NamePos": 296, + "NameEnd": 299 + }, + "Alias": null }, "ColumnType": { "LeftParenPos": 318, @@ -364,10 +373,13 @@ "DotIdent": null }, "ColumnExpr": { - "Name": "content", - "QuoteType": 1, - "NamePos": 358, - "NameEnd": 365 + "Expr": { + "Name": "content", + "QuoteType": 1, + "NamePos": 358, + "NameEnd": 365 + }, + "Alias": null }, "ColumnType": { "LeftParenPos": 382, @@ -418,10 +430,13 @@ "DotIdent": null }, "ColumnExpr": { - "Name": "output", - "QuoteType": 1, - "NamePos": 428, - "NameEnd": 434 + "Expr": { + "Name": "output", + "QuoteType": 1, + "NamePos": 428, + "NameEnd": 434 + }, + "Alias": null }, "ColumnType": { "LeftParenPos": 451, @@ -483,14 +498,20 @@ "HasDistinct": false, "Items": [ { - "LiteralPos": 513, - "LiteralEnd": 529, - "Literal": "/root/test_local" + "Expr": { + "LiteralPos": 513, + "LiteralEnd": 529, + "Literal": "/root/test_local" + }, + "Alias": null }, { - "LiteralPos": 533, - "LiteralEnd": 542, - "Literal": "{replica}" + "Expr": { + "LiteralPos": 533, + "LiteralEnd": 542, + "Literal": "{replica}" + }, + "Alias": null } ] }, @@ -505,30 +526,36 @@ "HasDistinct": false, "Items": [ { - "Name": { - "Name": "toStartOfHour", - "QuoteType": 1, - "NamePos": 558, - "NameEnd": 571 - }, - "Params": { - "LeftParenPos": 571, - "RightParenPos": 583, - "Items": { - "ListPos": 573, - "ListEnd": 582, - "HasDistinct": false, - "Items": [ - { - "Name": "timestamp", - "QuoteType": 3, - "NamePos": 573, - "NameEnd": 582 - } - ] + "Expr": { + "Name": { + "Name": "toStartOfHour", + "QuoteType": 1, + "NamePos": 558, + "NameEnd": 571 }, - "ColumnArgList": null - } + "Params": { + "LeftParenPos": 571, + "RightParenPos": 583, + "Items": { + "ListPos": 573, + "ListEnd": 582, + "HasDistinct": false, + "Items": [ + { + "Expr": { + "Name": "timestamp", + "QuoteType": 3, + "NamePos": 573, + "NameEnd": 582 + }, + "Alias": null + } + ] + }, + "ColumnArgList": null + } + }, + "Alias": null } ] } @@ -557,10 +584,13 @@ "HasDistinct": false, "Items": [ { - "Name": "timestamp", - "QuoteType": 3, - "NamePos": 660, - "NameEnd": 669 + "Expr": { + "Name": "timestamp", + "QuoteType": 3, + "NamePos": 660, + "NameEnd": 669 + }, + "Alias": null } ] }, @@ -606,10 +636,13 @@ "HasDistinct": false, "Items": [ { - "Name": "timestamp", - "QuoteType": 3, - "NamePos": 704, - "NameEnd": 713 + "Expr": { + "Name": "timestamp", + "QuoteType": 3, + "NamePos": 704, + "NameEnd": 713 + }, + "Alias": null } ] }, @@ -733,41 +766,51 @@ "HasDistinct": false, "Items": [ { - "Name": { - "Name": "toUnixTimestamp64Nano", - "QuoteType": 1, - "NamePos": 595, - "NameEnd": 616 - }, - "Params": { - "LeftParenPos": 616, - "RightParenPos": 628, - "Items": { - "ListPos": 618, - "ListEnd": 627, - "HasDistinct": false, - "Items": [ - { - "Name": "timestamp", - "QuoteType": 3, - "NamePos": 618, - "NameEnd": 627 - } - ] + "Expr": { + "Name": { + "Name": "toUnixTimestamp64Nano", + "QuoteType": 1, + "NamePos": 595, + "NameEnd": 616 }, - "ColumnArgList": null - } + "Params": { + "LeftParenPos": 616, + "RightParenPos": 628, + "Items": { + "ListPos": 618, + "ListEnd": 627, + "HasDistinct": false, + "Items": [ + { + "Expr": { + "Name": "timestamp", + "QuoteType": 3, + "NamePos": 618, + "NameEnd": 627 + }, + "Alias": null + } + ] + }, + "ColumnArgList": null + } + }, + "Alias": null }, { - "Name": "api_id", - "QuoteType": 3, - "NamePos": 632, - "NameEnd": 638 + "Expr": { + "Name": "api_id", + "QuoteType": 3, + "NamePos": 632, + "NameEnd": 638 + }, + "Alias": null } ] }, "ColumnArgList": null }, + "Alias": null, "Direction": "None" } ] diff --git a/parser/testdata/ddl/output/create_table_with_keyword_partition_by.sql.golden.json b/parser/testdata/ddl/output/create_table_with_keyword_partition_by.sql.golden.json index 1bd8bf8..6ae223f 100644 --- a/parser/testdata/ddl/output/create_table_with_keyword_partition_by.sql.golden.json +++ b/parser/testdata/ddl/output/create_table_with_keyword_partition_by.sql.golden.json @@ -167,10 +167,13 @@ "HasDistinct": false, "Items": [ { - "Name": "date", - "QuoteType": 1, - "NamePos": 195, - "NameEnd": 199 + "Expr": { + "Name": "date", + "QuoteType": 1, + "NamePos": 195, + "NameEnd": 199 + }, + "Alias": null } ] } @@ -213,21 +216,28 @@ "HasDistinct": false, "Items": [ { - "Name": "f1", - "QuoteType": 1, - "NamePos": 214, - "NameEnd": 216 + "Expr": { + "Name": "f1", + "QuoteType": 1, + "NamePos": 214, + "NameEnd": 216 + }, + "Alias": null }, { - "Name": "f2", - "QuoteType": 1, - "NamePos": 218, - "NameEnd": 220 + "Expr": { + "Name": "f2", + "QuoteType": 1, + "NamePos": 218, + "NameEnd": 220 + }, + "Alias": null } ] }, "ColumnArgList": null }, + "Alias": null, "Direction": "None" } ] diff --git a/parser/testdata/ddl/output/create_table_with_nullable.sql.golden.json b/parser/testdata/ddl/output/create_table_with_nullable.sql.golden.json index 10c5071..ab339d0 100644 --- a/parser/testdata/ddl/output/create_table_with_nullable.sql.golden.json +++ b/parser/testdata/ddl/output/create_table_with_nullable.sql.golden.json @@ -335,41 +335,47 @@ "HasDistinct": false, "Items": [ { - "LeftExpr": { - "Name": { - "Name": "xxHash32", - "QuoteType": 1, - "NamePos": 347, - "NameEnd": 355 - }, - "Params": { - "LeftParenPos": 355, - "RightParenPos": 362, - "Items": { - "ListPos": 356, - "ListEnd": 362, - "HasDistinct": false, - "Items": [ - { - "Name": "tag_id", - "QuoteType": 1, - "NamePos": 356, - "NameEnd": 362 - } - ] + "Expr": { + "LeftExpr": { + "Name": { + "Name": "xxHash32", + "QuoteType": 1, + "NamePos": 347, + "NameEnd": 355 }, - "ColumnArgList": null - } - }, - "Operation": "%", - "RightExpr": { - "NumPos": 366, - "NumEnd": 368, - "Literal": "20", - "Base": 10 + "Params": { + "LeftParenPos": 355, + "RightParenPos": 362, + "Items": { + "ListPos": 356, + "ListEnd": 362, + "HasDistinct": false, + "Items": [ + { + "Expr": { + "Name": "tag_id", + "QuoteType": 1, + "NamePos": 356, + "NameEnd": 362 + }, + "Alias": null + } + ] + }, + "ColumnArgList": null + } + }, + "Operation": "%", + "RightExpr": { + "NumPos": 366, + "NumEnd": 368, + "Literal": "20", + "Base": 10 + }, + "HasGlobal": false, + "HasNot": false }, - "HasGlobal": false, - "HasNot": false + "Alias": null } ] } @@ -409,6 +415,7 @@ "NamePos": 378, "NameEnd": 386 }, + "Alias": null, "Direction": "None" } ] diff --git a/parser/testdata/ddl/output/create_table_with_on_clsuter.sql.golden.json b/parser/testdata/ddl/output/create_table_with_on_clsuter.sql.golden.json index 3936530..0936734 100644 --- a/parser/testdata/ddl/output/create_table_with_on_clsuter.sql.golden.json +++ b/parser/testdata/ddl/output/create_table_with_on_clsuter.sql.golden.json @@ -325,14 +325,20 @@ "HasDistinct": false, "Items": [ { - "LiteralPos": 259, - "LiteralEnd": 311, - "Literal": "/clickhouse/tables/{layer}-{shard}/test/events_local" + "Expr": { + "LiteralPos": 259, + "LiteralEnd": 311, + "Literal": "/clickhouse/tables/{layer}-{shard}/test/events_local" + }, + "Alias": null }, { - "LiteralPos": 315, - "LiteralEnd": 324, - "Literal": "{replica}" + "Expr": { + "LiteralPos": 315, + "LiteralEnd": 324, + "Literal": "{replica}" + }, + "Alias": null } ] }, @@ -347,30 +353,36 @@ "HasDistinct": false, "Items": [ { - "Name": { - "Name": "toYYYYMMDD", - "QuoteType": 1, - "NamePos": 366, - "NameEnd": 376 - }, - "Params": { - "LeftParenPos": 376, - "RightParenPos": 379, - "Items": { - "ListPos": 377, - "ListEnd": 379, - "HasDistinct": false, - "Items": [ - { - "Name": "f3", - "QuoteType": 1, - "NamePos": 377, - "NameEnd": 379 - } - ] + "Expr": { + "Name": { + "Name": "toYYYYMMDD", + "QuoteType": 1, + "NamePos": 366, + "NameEnd": 376 }, - "ColumnArgList": null - } + "Params": { + "LeftParenPos": 376, + "RightParenPos": 379, + "Items": { + "ListPos": 377, + "ListEnd": 379, + "HasDistinct": false, + "Items": [ + { + "Expr": { + "Name": "f3", + "QuoteType": 1, + "NamePos": 377, + "NameEnd": 379 + }, + "Alias": null + } + ] + }, + "ColumnArgList": null + } + }, + "Alias": null } ] } @@ -427,27 +439,37 @@ "HasDistinct": false, "Items": [ { - "Name": "f0", - "QuoteType": 1, - "NamePos": 391, - "NameEnd": 393 + "Expr": { + "Name": "f0", + "QuoteType": 1, + "NamePos": 391, + "NameEnd": 393 + }, + "Alias": null }, { - "Name": "f1", - "QuoteType": 1, - "NamePos": 394, - "NameEnd": 396 + "Expr": { + "Name": "f1", + "QuoteType": 1, + "NamePos": 394, + "NameEnd": 396 + }, + "Alias": null }, { - "Name": "f2", - "QuoteType": 1, - "NamePos": 397, - "NameEnd": 399 + "Expr": { + "Name": "f2", + "QuoteType": 1, + "NamePos": 397, + "NameEnd": 399 + }, + "Alias": null } ] }, "ColumnArgList": null }, + "Alias": null, "Direction": "None" } ] diff --git a/parser/testdata/ddl/output/create_table_with_sample_by.sql.golden.json b/parser/testdata/ddl/output/create_table_with_sample_by.sql.golden.json index 69bc028..c46b9a1 100644 --- a/parser/testdata/ddl/output/create_table_with_sample_by.sql.golden.json +++ b/parser/testdata/ddl/output/create_table_with_sample_by.sql.golden.json @@ -136,14 +136,20 @@ "HasDistinct": false, "Items": [ { - "LiteralPos": 156, - "LiteralEnd": 203, - "Literal": "/clickhouse/tables/{layer}/{shard}/default/test" + "Expr": { + "LiteralPos": 156, + "LiteralEnd": 203, + "Literal": "/clickhouse/tables/{layer}/{shard}/default/test" + }, + "Alias": null }, { - "LiteralPos": 207, - "LiteralEnd": 216, - "Literal": "{replica}" + "Expr": { + "LiteralPos": 207, + "LiteralEnd": 216, + "Literal": "{replica}" + }, + "Alias": null } ] }, @@ -158,30 +164,36 @@ "HasDistinct": false, "Items": [ { - "Name": { - "Name": "toYYYYMM", - "QuoteType": 1, - "NamePos": 232, - "NameEnd": 240 - }, - "Params": { - "LeftParenPos": 240, - "RightParenPos": 250, - "Items": { - "ListPos": 241, - "ListEnd": 250, - "HasDistinct": false, - "Items": [ - { - "Name": "timestamp", - "QuoteType": 1, - "NamePos": 241, - "NameEnd": 250 - } - ] + "Expr": { + "Name": { + "Name": "toYYYYMM", + "QuoteType": 1, + "NamePos": 232, + "NameEnd": 240 }, - "ColumnArgList": null - } + "Params": { + "LeftParenPos": 240, + "RightParenPos": 250, + "Items": { + "ListPos": 241, + "ListEnd": 250, + "HasDistinct": false, + "Items": [ + { + "Expr": { + "Name": "timestamp", + "QuoteType": 1, + "NamePos": 241, + "NameEnd": 250 + }, + "Alias": null + } + ] + }, + "ColumnArgList": null + } + }, + "Alias": null } ] } @@ -232,47 +244,60 @@ "HasDistinct": false, "Items": [ { - "Name": "contractid", - "QuoteType": 1, - "NamePos": 262, - "NameEnd": 272 - }, - { - "Name": { - "Name": "toDate", + "Expr": { + "Name": "contractid", "QuoteType": 1, - "NamePos": 274, - "NameEnd": 280 + "NamePos": 262, + "NameEnd": 272 }, - "Params": { - "LeftParenPos": 280, - "RightParenPos": 290, - "Items": { - "ListPos": 281, - "ListEnd": 290, - "HasDistinct": false, - "Items": [ - { - "Name": "timestamp", - "QuoteType": 1, - "NamePos": 281, - "NameEnd": 290 - } - ] + "Alias": null + }, + { + "Expr": { + "Name": { + "Name": "toDate", + "QuoteType": 1, + "NamePos": 274, + "NameEnd": 280 }, - "ColumnArgList": null - } + "Params": { + "LeftParenPos": 280, + "RightParenPos": 290, + "Items": { + "ListPos": 281, + "ListEnd": 290, + "HasDistinct": false, + "Items": [ + { + "Expr": { + "Name": "timestamp", + "QuoteType": 1, + "NamePos": 281, + "NameEnd": 290 + }, + "Alias": null + } + ] + }, + "ColumnArgList": null + } + }, + "Alias": null }, { - "Name": "userid", - "QuoteType": 1, - "NamePos": 293, - "NameEnd": 299 + "Expr": { + "Name": "userid", + "QuoteType": 1, + "NamePos": 293, + "NameEnd": 299 + }, + "Alias": null } ] }, "ColumnArgList": null }, + "Alias": null, "Direction": "None" } ] diff --git a/parser/testdata/ddl/output/create_table_with_uuid.sql.golden.json b/parser/testdata/ddl/output/create_table_with_uuid.sql.golden.json index 1e26479..c67ed98 100644 --- a/parser/testdata/ddl/output/create_table_with_uuid.sql.golden.json +++ b/parser/testdata/ddl/output/create_table_with_uuid.sql.golden.json @@ -331,14 +331,20 @@ "HasDistinct": false, "Items": [ { - "LiteralPos": 271, - "LiteralEnd": 323, - "Literal": "/clickhouse/tables/{layer}-{shard}/test/events_local" + "Expr": { + "LiteralPos": 271, + "LiteralEnd": 323, + "Literal": "/clickhouse/tables/{layer}-{shard}/test/events_local" + }, + "Alias": null }, { - "LiteralPos": 327, - "LiteralEnd": 336, - "Literal": "{replica}" + "Expr": { + "LiteralPos": 327, + "LiteralEnd": 336, + "Literal": "{replica}" + }, + "Alias": null } ] }, @@ -353,30 +359,36 @@ "HasDistinct": false, "Items": [ { - "Name": { - "Name": "toYYYYMMDD", - "QuoteType": 1, - "NamePos": 378, - "NameEnd": 388 - }, - "Params": { - "LeftParenPos": 388, - "RightParenPos": 391, - "Items": { - "ListPos": 389, - "ListEnd": 391, - "HasDistinct": false, - "Items": [ - { - "Name": "f3", - "QuoteType": 1, - "NamePos": 389, - "NameEnd": 391 - } - ] + "Expr": { + "Name": { + "Name": "toYYYYMMDD", + "QuoteType": 1, + "NamePos": 378, + "NameEnd": 388 }, - "ColumnArgList": null - } + "Params": { + "LeftParenPos": 388, + "RightParenPos": 391, + "Items": { + "ListPos": 389, + "ListEnd": 391, + "HasDistinct": false, + "Items": [ + { + "Expr": { + "Name": "f3", + "QuoteType": 1, + "NamePos": 389, + "NameEnd": 391 + }, + "Alias": null + } + ] + }, + "ColumnArgList": null + } + }, + "Alias": null } ] } @@ -433,27 +445,37 @@ "HasDistinct": false, "Items": [ { - "Name": "f0", - "QuoteType": 1, - "NamePos": 403, - "NameEnd": 405 + "Expr": { + "Name": "f0", + "QuoteType": 1, + "NamePos": 403, + "NameEnd": 405 + }, + "Alias": null }, { - "Name": "f1", - "QuoteType": 1, - "NamePos": 406, - "NameEnd": 408 + "Expr": { + "Name": "f1", + "QuoteType": 1, + "NamePos": 406, + "NameEnd": 408 + }, + "Alias": null }, { - "Name": "f2", - "QuoteType": 1, - "NamePos": 409, - "NameEnd": 411 + "Expr": { + "Name": "f2", + "QuoteType": 1, + "NamePos": 409, + "NameEnd": 411 + }, + "Alias": null } ] }, "ColumnArgList": null }, + "Alias": null, "Direction": "None" } ] 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 333d47d..91fec07 100644 --- a/parser/testdata/ddl/output/create_view_basic.sql.golden.json +++ b/parser/testdata/ddl/output/create_view_basic.sql.golden.json @@ -83,7 +83,7 @@ "TableFunction": null }, "SubQuery": { - "AsPos": 60, + "HasParen": false, "Select": { "SelectPos": 63, "StatementEnd": 104, @@ -97,7 +97,8 @@ "NamePos": 74, "NameEnd": 76 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null }, { "Expr": { @@ -106,7 +107,8 @@ "NamePos": 82, "NameEnd": 86 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null } ], "From": { 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 3757f88..5f85442 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 @@ -34,7 +34,7 @@ }, "TableSchema": null, "SubQuery": { - "AsPos": 131, + "HasParen": true, "Select": { "SelectPos": 140, "StatementEnd": 199, @@ -48,7 +48,8 @@ "NamePos": 151, "NameEnd": 158 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null }, { "Expr": { @@ -57,7 +58,8 @@ "NamePos": 164, "NameEnd": 171 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null } ], "From": { diff --git a/parser/testdata/ddl/output/grant_privilege.sql.golden.json b/parser/testdata/ddl/output/grant_privilege.sql.golden.json index 6ef048a..0a6a7d2 100644 --- a/parser/testdata/ddl/output/grant_privilege.sql.golden.json +++ b/parser/testdata/ddl/output/grant_privilege.sql.golden.json @@ -19,16 +19,22 @@ "HasDistinct": false, "Items": [ { - "Name": "x", - "QuoteType": 1, - "NamePos": 13, - "NameEnd": 14 + "Expr": { + "Name": "x", + "QuoteType": 1, + "NamePos": 13, + "NameEnd": 14 + }, + "Alias": null }, { - "Name": "y", - "QuoteType": 1, - "NamePos": 15, - "NameEnd": 16 + "Expr": { + "Name": "y", + "QuoteType": 1, + "NamePos": 15, + "NameEnd": 16 + }, + "Alias": null } ] }, @@ -80,16 +86,22 @@ "HasDistinct": false, "Items": [ { - "Name": "x", - "QuoteType": 1, - "NamePos": 52, - "NameEnd": 53 + "Expr": { + "Name": "x", + "QuoteType": 1, + "NamePos": 52, + "NameEnd": 53 + }, + "Alias": null }, { - "Name": "y", - "QuoteType": 1, - "NamePos": 54, - "NameEnd": 55 + "Expr": { + "Name": "y", + "QuoteType": 1, + "NamePos": 54, + "NameEnd": 55 + }, + "Alias": null } ] }, @@ -144,16 +156,22 @@ "HasDistinct": false, "Items": [ { - "Name": "x", - "QuoteType": 1, - "NamePos": 127, - "NameEnd": 128 + "Expr": { + "Name": "x", + "QuoteType": 1, + "NamePos": 127, + "NameEnd": 128 + }, + "Alias": null }, { - "Name": "y", - "QuoteType": 1, - "NamePos": 129, - "NameEnd": 130 + "Expr": { + "Name": "y", + "QuoteType": 1, + "NamePos": 129, + "NameEnd": 130 + }, + "Alias": null } ] }, @@ -205,16 +223,22 @@ "HasDistinct": false, "Items": [ { - "Name": "x", - "QuoteType": 1, - "NamePos": 162, - "NameEnd": 163 + "Expr": { + "Name": "x", + "QuoteType": 1, + "NamePos": 162, + "NameEnd": 163 + }, + "Alias": null }, { - "Name": "y", - "QuoteType": 1, - "NamePos": 164, - "NameEnd": 165 + "Expr": { + "Name": "y", + "QuoteType": 1, + "NamePos": 164, + "NameEnd": 165 + }, + "Alias": null } ] }, @@ -266,16 +290,22 @@ "HasDistinct": false, "Items": [ { - "Name": "x", - "QuoteType": 1, - "NamePos": 200, - "NameEnd": 201 + "Expr": { + "Name": "x", + "QuoteType": 1, + "NamePos": 200, + "NameEnd": 201 + }, + "Alias": null }, { - "Name": "y", - "QuoteType": 1, - "NamePos": 202, - "NameEnd": 203 + "Expr": { + "Name": "y", + "QuoteType": 1, + "NamePos": 202, + "NameEnd": 203 + }, + "Alias": null } ] }, @@ -327,16 +357,22 @@ "HasDistinct": false, "Items": [ { - "Name": "x", - "QuoteType": 1, - "NamePos": 234, - "NameEnd": 235 + "Expr": { + "Name": "x", + "QuoteType": 1, + "NamePos": 234, + "NameEnd": 235 + }, + "Alias": null }, { - "Name": "y", - "QuoteType": 1, - "NamePos": 236, - "NameEnd": 237 + "Expr": { + "Name": "y", + "QuoteType": 1, + "NamePos": 236, + "NameEnd": 237 + }, + "Alias": null } ] }, @@ -388,16 +424,22 @@ "HasDistinct": false, "Items": [ { - "Name": "x", - "QuoteType": 1, - "NamePos": 280, - "NameEnd": 281 + "Expr": { + "Name": "x", + "QuoteType": 1, + "NamePos": 280, + "NameEnd": 281 + }, + "Alias": null }, { - "Name": "y", - "QuoteType": 1, - "NamePos": 282, - "NameEnd": 283 + "Expr": { + "Name": "y", + "QuoteType": 1, + "NamePos": 282, + "NameEnd": 283 + }, + "Alias": null } ] }, @@ -547,22 +589,31 @@ "HasDistinct": false, "Items": [ { - "Name": "x", - "QuoteType": 1, - "NamePos": 450, - "NameEnd": 451 + "Expr": { + "Name": "x", + "QuoteType": 1, + "NamePos": 450, + "NameEnd": 451 + }, + "Alias": null }, { - "Name": "y", - "QuoteType": 1, - "NamePos": 453, - "NameEnd": 454 + "Expr": { + "Name": "y", + "QuoteType": 1, + "NamePos": 453, + "NameEnd": 454 + }, + "Alias": null }, { - "Name": "z", - "QuoteType": 1, - "NamePos": 456, - "NameEnd": 457 + "Expr": { + "Name": "z", + "QuoteType": 1, + "NamePos": 456, + "NameEnd": 457 + }, + "Alias": null } ] }, diff --git a/parser/testdata/ddl/output/optimize.sql.golden.json b/parser/testdata/ddl/output/optimize.sql.golden.json index 728ae91..31a555b 100644 --- a/parser/testdata/ddl/output/optimize.sql.golden.json +++ b/parser/testdata/ddl/output/optimize.sql.golden.json @@ -43,10 +43,13 @@ "HasDistinct": false, "Items": [ { - "Name": "*", - "QuoteType": 0, - "NamePos": 85, - "NameEnd": 85 + "Expr": { + "Name": "*", + "QuoteType": 0, + "NamePos": 85, + "NameEnd": 85 + }, + "Alias": null } ] }, @@ -76,22 +79,31 @@ "HasDistinct": false, "Items": [ { - "Name": "colX", - "QuoteType": 1, - "NamePos": 167, - "NameEnd": 171 + "Expr": { + "Name": "colX", + "QuoteType": 1, + "NamePos": 167, + "NameEnd": 171 + }, + "Alias": null }, { - "Name": "colY", - "QuoteType": 1, - "NamePos": 172, - "NameEnd": 176 + "Expr": { + "Name": "colY", + "QuoteType": 1, + "NamePos": 172, + "NameEnd": 176 + }, + "Alias": null }, { - "Name": "colZ", - "QuoteType": 1, - "NamePos": 177, - "NameEnd": 181 + "Expr": { + "Name": "colZ", + "QuoteType": 1, + "NamePos": 177, + "NameEnd": 181 + }, + "Alias": null } ] }, @@ -121,10 +133,13 @@ "HasDistinct": false, "Items": [ { - "Name": "*", - "QuoteType": 0, - "NamePos": 219, - "NameEnd": 219 + "Expr": { + "Name": "*", + "QuoteType": 0, + "NamePos": 219, + "NameEnd": 219 + }, + "Alias": null } ] }, @@ -134,10 +149,13 @@ "HasDistinct": false, "Items": [ { - "Name": "colX", - "QuoteType": 1, - "NamePos": 228, - "NameEnd": 232 + "Expr": { + "Name": "colX", + "QuoteType": 1, + "NamePos": 228, + "NameEnd": 232 + }, + "Alias": null } ] } @@ -166,10 +184,13 @@ "HasDistinct": false, "Items": [ { - "Name": "*", - "QuoteType": 0, - "NamePos": 270, - "NameEnd": 270 + "Expr": { + "Name": "*", + "QuoteType": 0, + "NamePos": 270, + "NameEnd": 270 + }, + "Alias": null } ] }, @@ -179,28 +200,37 @@ "HasDistinct": false, "Items": [ { - "LeftParenPos": 279, - "RightParenPos": 290, - "Items": { - "ListPos": 280, - "ListEnd": 290, - "HasDistinct": false, - "Items": [ - { - "Name": "colX", - "QuoteType": 1, - "NamePos": 280, - "NameEnd": 284 - }, - { - "Name": "colY", - "QuoteType": 1, - "NamePos": 286, - "NameEnd": 290 - } - ] + "Expr": { + "LeftParenPos": 279, + "RightParenPos": 290, + "Items": { + "ListPos": 280, + "ListEnd": 290, + "HasDistinct": false, + "Items": [ + { + "Expr": { + "Name": "colX", + "QuoteType": 1, + "NamePos": 280, + "NameEnd": 284 + }, + "Alias": null + }, + { + "Expr": { + "Name": "colY", + "QuoteType": 1, + "NamePos": 286, + "NameEnd": 290 + }, + "Alias": null + } + ] + }, + "ColumnArgList": null }, - "ColumnArgList": null + "Alias": null } ] } @@ -229,29 +259,35 @@ "HasDistinct": false, "Items": [ { - "Name": { - "Name": "COLUMNS", - "QuoteType": 1, - "NamePos": 329, - "NameEnd": 336 - }, - "Params": { - "LeftParenPos": 336, - "RightParenPos": 362, - "Items": { - "ListPos": 338, - "ListEnd": 361, - "HasDistinct": false, - "Items": [ - { - "LiteralPos": 338, - "LiteralEnd": 361, - "Literal": "column-matched-by-regex" - } - ] + "Expr": { + "Name": { + "Name": "COLUMNS", + "QuoteType": 1, + "NamePos": 329, + "NameEnd": 336 }, - "ColumnArgList": null - } + "Params": { + "LeftParenPos": 336, + "RightParenPos": 362, + "Items": { + "ListPos": 338, + "ListEnd": 361, + "HasDistinct": false, + "Items": [ + { + "Expr": { + "LiteralPos": 338, + "LiteralEnd": 361, + "Literal": "column-matched-by-regex" + }, + "Alias": null + } + ] + }, + "ColumnArgList": null + } + }, + "Alias": null } ] }, @@ -281,29 +317,35 @@ "HasDistinct": false, "Items": [ { - "Name": { - "Name": "COLUMNS", - "QuoteType": 1, - "NamePos": 401, - "NameEnd": 408 - }, - "Params": { - "LeftParenPos": 408, - "RightParenPos": 434, - "Items": { - "ListPos": 410, - "ListEnd": 433, - "HasDistinct": false, - "Items": [ - { - "LiteralPos": 410, - "LiteralEnd": 433, - "Literal": "column-matched-by-regex" - } - ] + "Expr": { + "Name": { + "Name": "COLUMNS", + "QuoteType": 1, + "NamePos": 401, + "NameEnd": 408 }, - "ColumnArgList": null - } + "Params": { + "LeftParenPos": 408, + "RightParenPos": 434, + "Items": { + "ListPos": 410, + "ListEnd": 433, + "HasDistinct": false, + "Items": [ + { + "Expr": { + "LiteralPos": 410, + "LiteralEnd": 433, + "Literal": "column-matched-by-regex" + }, + "Alias": null + } + ] + }, + "ColumnArgList": null + } + }, + "Alias": null } ] }, @@ -313,10 +355,13 @@ "HasDistinct": false, "Items": [ { - "Name": "colX", - "QuoteType": 1, - "NamePos": 443, - "NameEnd": 447 + "Expr": { + "Name": "colX", + "QuoteType": 1, + "NamePos": 443, + "NameEnd": 447 + }, + "Alias": null } ] } @@ -345,29 +390,35 @@ "HasDistinct": false, "Items": [ { - "Name": { - "Name": "COLUMNS", - "QuoteType": 1, - "NamePos": 485, - "NameEnd": 492 - }, - "Params": { - "LeftParenPos": 492, - "RightParenPos": 518, - "Items": { - "ListPos": 494, - "ListEnd": 517, - "HasDistinct": false, - "Items": [ - { - "LiteralPos": 494, - "LiteralEnd": 517, - "Literal": "column-matched-by-regex" - } - ] + "Expr": { + "Name": { + "Name": "COLUMNS", + "QuoteType": 1, + "NamePos": 485, + "NameEnd": 492 }, - "ColumnArgList": null - } + "Params": { + "LeftParenPos": 492, + "RightParenPos": 518, + "Items": { + "ListPos": 494, + "ListEnd": 517, + "HasDistinct": false, + "Items": [ + { + "Expr": { + "LiteralPos": 494, + "LiteralEnd": 517, + "Literal": "column-matched-by-regex" + }, + "Alias": null + } + ] + }, + "ColumnArgList": null + } + }, + "Alias": null } ] }, @@ -377,28 +428,37 @@ "HasDistinct": false, "Items": [ { - "LeftParenPos": 527, - "RightParenPos": 538, - "Items": { - "ListPos": 528, - "ListEnd": 538, - "HasDistinct": false, - "Items": [ - { - "Name": "colX", - "QuoteType": 1, - "NamePos": 528, - "NameEnd": 532 - }, - { - "Name": "colY", - "QuoteType": 1, - "NamePos": 534, - "NameEnd": 538 - } - ] + "Expr": { + "LeftParenPos": 527, + "RightParenPos": 538, + "Items": { + "ListPos": 528, + "ListEnd": 538, + "HasDistinct": false, + "Items": [ + { + "Expr": { + "Name": "colX", + "QuoteType": 1, + "NamePos": 528, + "NameEnd": 532 + }, + "Alias": null + }, + { + "Expr": { + "Name": "colY", + "QuoteType": 1, + "NamePos": 534, + "NameEnd": 538 + }, + "Alias": null + } + ] + }, + "ColumnArgList": null }, - "ColumnArgList": null + "Alias": null } ] } 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 5872912..79ce55b 100644 --- a/parser/testdata/dml/output/insert_with_select.sql.golden.json +++ b/parser/testdata/dml/output/insert_with_select.sql.golden.json @@ -31,7 +31,8 @@ "NamePos": 40, "NameEnd": 49 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null }, { "Expr": { @@ -40,7 +41,8 @@ "NamePos": 55, "NameEnd": 64 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null }, { "Expr": { @@ -49,7 +51,8 @@ "NamePos": 70, "NameEnd": 74 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null }, { "Expr": { @@ -58,7 +61,8 @@ "NamePos": 80, "NameEnd": 86 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null } ], "From": { diff --git a/parser/testdata/query/format/query_with_expr_compare.sql b/parser/testdata/query/format/query_with_expr_compare.sql new file mode 100644 index 0000000..0f209df --- /dev/null +++ b/parser/testdata/query/format/query_with_expr_compare.sql @@ -0,0 +1,10 @@ +-- Origin SQL: +SELECT date, path, splitByChar('/', path)[2] AS path_b +FROM( + SELECT 'pathA/pathB/pathC' AS path, '2024-09-10' AS date + ) +WHERE toDate(date) BETWEEN '2024-09-01' AND '2024-09-30' + AND splitByChar('/', path)[1] = 'pathA' + +-- Format SQL: +SELECT date, path, splitByChar('/', path)[2] AS path_b FROM (SELECT 'pathA/pathB/pathC' AS path, '2024-09-10' AS date) WHERE toDate(date) BETWEEN '2024-09-01' AND '2024-09-30' AND splitByChar('/', path)[1] = 'pathA'; diff --git a/parser/testdata/query/output/query_with_expr_compare.sql.golden.json b/parser/testdata/query/output/query_with_expr_compare.sql.golden.json new file mode 100644 index 0000000..13209c4 --- /dev/null +++ b/parser/testdata/query/output/query_with_expr_compare.sql.golden.json @@ -0,0 +1,300 @@ +[ + { + "SelectPos": 0, + "StatementEnd": 225, + "With": null, + "Top": null, + "SelectItems": [ + { + "Expr": { + "Name": "date", + "QuoteType": 1, + "NamePos": 7, + "NameEnd": 11 + }, + "Modifiers": [], + "Alias": null + }, + { + "Expr": { + "Name": "path", + "QuoteType": 1, + "NamePos": 13, + "NameEnd": 17 + }, + "Modifiers": [], + "Alias": null + }, + { + "Expr": { + "Object": { + "Name": { + "Name": "splitByChar", + "QuoteType": 1, + "NamePos": 19, + "NameEnd": 30 + }, + "Params": { + "LeftParenPos": 30, + "RightParenPos": 40, + "Items": { + "ListPos": 32, + "ListEnd": 40, + "HasDistinct": false, + "Items": [ + { + "Expr": { + "LiteralPos": 32, + "LiteralEnd": 33, + "Literal": "/" + }, + "Alias": null + }, + { + "Expr": { + "Name": "path", + "QuoteType": 1, + "NamePos": 36, + "NameEnd": 40 + }, + "Alias": null + } + ] + }, + "ColumnArgList": null + } + }, + "Params": { + "LeftBracketPos": 41, + "RightBracketPos": 43, + "Items": { + "ListPos": 42, + "ListEnd": 43, + "HasDistinct": false, + "Items": [ + { + "Expr": { + "NumPos": 42, + "NumEnd": 43, + "Literal": "2", + "Base": 10 + }, + "Alias": null + } + ] + } + } + }, + "Modifiers": [], + "Alias": { + "Name": "path_b", + "QuoteType": 1, + "NamePos": 48, + "NameEnd": 54 + } + } + ], + "From": { + "FromPos": 55, + "Expr": { + "Table": { + "TablePos": 59, + "TableEnd": 121, + "Alias": null, + "Expr": { + "HasParen": true, + "Select": { + "SelectPos": 65, + "StatementEnd": 121, + "With": null, + "Top": null, + "SelectItems": [ + { + "Expr": { + "LiteralPos": 73, + "LiteralEnd": 90, + "Literal": "pathA/pathB/pathC" + }, + "Modifiers": [], + "Alias": { + "Name": "path", + "QuoteType": 1, + "NamePos": 95, + "NameEnd": 99 + } + }, + { + "Expr": { + "LiteralPos": 102, + "LiteralEnd": 112, + "Literal": "2024-09-10" + }, + "Modifiers": [], + "Alias": { + "Name": "date", + "QuoteType": 1, + "NamePos": 117, + "NameEnd": 121 + } + } + ], + "From": null, + "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 + } + }, + "HasFinal": false + }, + "StatementEnd": 121, + "SampleRatio": null, + "HasFinal": false + } + }, + "ArrayJoin": null, + "Window": null, + "Prewhere": null, + "Where": { + "WherePos": 128, + "Expr": { + "LeftExpr": { + "Expr": { + "Name": { + "Name": "toDate", + "QuoteType": 1, + "NamePos": 134, + "NameEnd": 140 + }, + "Params": { + "LeftParenPos": 140, + "RightParenPos": 145, + "Items": { + "ListPos": 141, + "ListEnd": 145, + "HasDistinct": false, + "Items": [ + { + "Expr": { + "Name": "date", + "QuoteType": 1, + "NamePos": 141, + "NameEnd": 145 + }, + "Alias": null + } + ] + }, + "ColumnArgList": null + } + }, + "Between": { + "LiteralPos": 156, + "LiteralEnd": 166, + "Literal": "2024-09-01" + }, + "AndPos": 168, + "And": { + "LiteralPos": 173, + "LiteralEnd": 183, + "Literal": "2024-09-30" + } + }, + "Operation": "AND", + "RightExpr": { + "LeftExpr": { + "Object": { + "Name": { + "Name": "splitByChar", + "QuoteType": 1, + "NamePos": 191, + "NameEnd": 202 + }, + "Params": { + "LeftParenPos": 202, + "RightParenPos": 212, + "Items": { + "ListPos": 204, + "ListEnd": 212, + "HasDistinct": false, + "Items": [ + { + "Expr": { + "LiteralPos": 204, + "LiteralEnd": 205, + "Literal": "/" + }, + "Alias": null + }, + { + "Expr": { + "Name": "path", + "QuoteType": 1, + "NamePos": 208, + "NameEnd": 212 + }, + "Alias": null + } + ] + }, + "ColumnArgList": null + } + }, + "Params": { + "LeftBracketPos": 213, + "RightBracketPos": 215, + "Items": { + "ListPos": 214, + "ListEnd": 215, + "HasDistinct": false, + "Items": [ + { + "Expr": { + "NumPos": 214, + "NumEnd": 215, + "Literal": "1", + "Base": 10 + }, + "Alias": null + } + ] + } + } + }, + "Operation": "=", + "RightExpr": { + "LiteralPos": 220, + "LiteralEnd": 225, + "Literal": "pathA" + }, + "HasGlobal": false, + "HasNot": false + }, + "HasGlobal": false, + "HasNot": false + } + }, + "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_cast.sql.golden.json b/parser/testdata/query/output/select_cast.sql.golden.json index 9bb5cbe..4f79f73 100644 --- a/parser/testdata/query/output/select_cast.sql.golden.json +++ b/parser/testdata/query/output/select_cast.sql.golden.json @@ -7,34 +7,31 @@ "SelectItems": [ { "Expr": { + "CastPos": 7, "Expr": { - "CastPos": 7, - "Expr": { - "NumPos": 12, - "NumEnd": 13, - "Literal": "1", - "Base": 10 - }, - "Separator": "as", - "AsPos": 14, - "AsType": { - "Name": { - "Name": "Float64", - "QuoteType": 1, - "NamePos": 17, - "NameEnd": 24 - } - } + "NumPos": 12, + "NumEnd": 13, + "Literal": "1", + "Base": 10 }, - "AliasPos": 29, - "Alias": { - "Name": "value", - "QuoteType": 1, - "NamePos": 29, - "NameEnd": 34 + "Separator": "as", + "AsPos": 14, + "AsType": { + "Name": { + "Name": "Float64", + "QuoteType": 1, + "NamePos": 17, + "NameEnd": 24 + } } }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "value", + "QuoteType": 1, + "NamePos": 29, + "NameEnd": 34 + } } ], "From": null, @@ -62,31 +59,28 @@ "SelectItems": [ { "Expr": { + "CastPos": 43, "Expr": { - "CastPos": 43, - "Expr": { - "NumPos": 48, - "NumEnd": 49, - "Literal": "1", - "Base": 10 - }, - "Separator": ",", - "AsPos": 49, - "AsType": { - "LiteralPos": 52, - "LiteralEnd": 59, - "Literal": "Float64" - } + "NumPos": 48, + "NumEnd": 49, + "Literal": "1", + "Base": 10 }, - "AliasPos": 65, - "Alias": { - "Name": "value", - "QuoteType": 1, - "NamePos": 65, - "NameEnd": 70 + "Separator": ",", + "AsPos": 49, + "AsType": { + "LiteralPos": 52, + "LiteralEnd": 59, + "Literal": "Float64" } }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "value", + "QuoteType": 1, + "NamePos": 65, + "NameEnd": 70 + } } ], "From": null, @@ -114,42 +108,38 @@ "SelectItems": [ { "Expr": { - "Expr": { - "LeftParenPos": 79, - "RightParenPos": 92, - "Items": { - "ListPos": 80, - "ListEnd": 92, - "HasDistinct": false, - "Items": [ - { - "Expr": { - "NumPos": 80, - "NumEnd": 81, - "Literal": "1", - "Base": 10 - }, - "AliasPos": 85, - "Alias": { - "Name": "Float64", - "QuoteType": 1, - "NamePos": 85, - "NameEnd": 92 - } + "LeftParenPos": 79, + "RightParenPos": 92, + "Items": { + "ListPos": 80, + "ListEnd": 92, + "HasDistinct": false, + "Items": [ + { + "Expr": { + "NumPos": 80, + "NumEnd": 81, + "Literal": "1", + "Base": 10 + }, + "Alias": { + "Name": "Float64", + "QuoteType": 1, + "NamePos": 85, + "NameEnd": 92 } - ] - }, - "ColumnArgList": null + } + ] }, - "AliasPos": 97, - "Alias": { - "Name": "value", - "QuoteType": 1, - "NamePos": 97, - "NameEnd": 102 - } + "ColumnArgList": null }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "value", + "QuoteType": 1, + "NamePos": 97, + "NameEnd": 102 + } } ], "From": null, @@ -177,32 +167,29 @@ "SelectItems": [ { "Expr": { - "Expr": { - "LeftExpr": { - "NumPos": 111, - "NumEnd": 112, - "Literal": "1", - "Base": 10 - }, - "Operation": "::", - "RightExpr": { - "Name": "Float64", - "QuoteType": 1, - "NamePos": 114, - "NameEnd": 121 - }, - "HasGlobal": false, - "HasNot": false + "LeftExpr": { + "NumPos": 111, + "NumEnd": 112, + "Literal": "1", + "Base": 10 }, - "AliasPos": 125, - "Alias": { - "Name": "value", + "Operation": "::", + "RightExpr": { + "Name": "Float64", "QuoteType": 1, - "NamePos": 125, - "NameEnd": 130 - } + "NamePos": 114, + "NameEnd": 121 + }, + "HasGlobal": false, + "HasNot": false }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "value", + "QuoteType": 1, + "NamePos": 125, + "NameEnd": 130 + } } ], "From": 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 38b505c..271bc77 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 @@ -7,20 +7,17 @@ "SelectItems": [ { "Expr": { - "Expr": { - "LiteralPos": 8, - "LiteralEnd": 11, - "Literal": "abc" - }, - "AliasPos": 17, - "Alias": { - "Name": "value2", - "QuoteType": 2, - "NamePos": 17, - "NameEnd": 23 - } + "LiteralPos": 8, + "LiteralEnd": 11, + "Literal": "abc" }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "value2", + "QuoteType": 2, + "NamePos": 17, + "NameEnd": 23 + } } ], "From": null, diff --git a/parser/testdata/query/output/select_expr.sql.golden.json b/parser/testdata/query/output/select_expr.sql.golden.json index b7583d6..4f0c3fe 100644 --- a/parser/testdata/query/output/select_expr.sql.golden.json +++ b/parser/testdata/query/output/select_expr.sql.golden.json @@ -23,7 +23,8 @@ "HasGlobal": false, "HasNot": false }, - "Modifiers": [] + "Modifiers": [], + "Alias": null } ], "From": 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 index e2a1213..69c9609 100644 --- a/parser/testdata/query/output/select_item_with_modifiers.sql.golden.json +++ b/parser/testdata/query/output/select_item_with_modifiers.sql.golden.json @@ -35,7 +35,6 @@ "NamePos": 18, "NameEnd": 20 }, - "AliasPos": 24, "Alias": { "Name": "c1", "QuoteType": 1, @@ -48,7 +47,8 @@ "ColumnArgList": null } } - ] + ], + "Alias": null } ], "From": { @@ -137,7 +137,6 @@ "HasGlobal": false, "HasNot": false }, - "AliasPos": 63, "Alias": { "Name": "i", "QuoteType": 1, @@ -150,7 +149,8 @@ "ColumnArgList": null } } - ] + ], + "Alias": null } ], "From": { @@ -239,7 +239,6 @@ "HasGlobal": false, "HasNot": false }, - "AliasPos": 101, "Alias": { "Name": "i", "QuoteType": 1, @@ -268,10 +267,13 @@ "HasDistinct": false, "Items": [ { - "Name": "j", - "QuoteType": 1, - "NamePos": 112, - "NameEnd": 113 + "Expr": { + "Name": "j", + "QuoteType": 1, + "NamePos": 112, + "NameEnd": 113 + }, + "Alias": null } ] }, @@ -294,17 +296,21 @@ "HasDistinct": false, "Items": [ { - "Name": "sum", - "QuoteType": 1, - "NamePos": 121, - "NameEnd": 124 + "Expr": { + "Name": "sum", + "QuoteType": 1, + "NamePos": 121, + "NameEnd": 124 + }, + "Alias": null } ] }, "ColumnArgList": null } } - ] + ], + "Alias": null } ], "From": { 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 fb9b0ee..f122fc0 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 @@ -12,7 +12,8 @@ "NamePos": 7, "NameEnd": 16 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null } ], "From": { @@ -57,6 +58,7 @@ "NamePos": 38, "NameEnd": 47 }, + "Alias": null, "Direction": "None" } ] diff --git a/parser/testdata/query/output/select_simple.sql.golden.json b/parser/testdata/query/output/select_simple.sql.golden.json index 780ce58..a3b88ac 100644 --- a/parser/testdata/query/output/select_simple.sql.golden.json +++ b/parser/testdata/query/output/select_simple.sql.golden.json @@ -12,122 +12,127 @@ "NamePos": 11, "NameEnd": 13 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null }, { "Expr": { - "Expr": { - "Name": { - "Name": "coalesce", - "QuoteType": 1, - "NamePos": 15, - "NameEnd": 23 - }, - "Params": { - "LeftParenPos": 23, - "RightParenPos": 30, - "Items": { - "ListPos": 24, - "ListEnd": 30, - "HasDistinct": false, - "Items": [ - { + "Name": { + "Name": "coalesce", + "QuoteType": 1, + "NamePos": 15, + "NameEnd": 23 + }, + "Params": { + "LeftParenPos": 23, + "RightParenPos": 30, + "Items": { + "ListPos": 24, + "ListEnd": 30, + "HasDistinct": false, + "Items": [ + { + "Expr": { "Name": "f1", "QuoteType": 1, "NamePos": 24, "NameEnd": 26 }, - { + "Alias": null + }, + { + "Expr": { "Name": "f2", "QuoteType": 1, "NamePos": 28, "NameEnd": 30 - } - ] - }, - "ColumnArgList": null - } - }, - "AliasPos": 35, - "Alias": { - "Name": "f3", - "QuoteType": 1, - "NamePos": 35, - "NameEnd": 37 + }, + "Alias": null + } + ] + }, + "ColumnArgList": null } }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "f3", + "QuoteType": 1, + "NamePos": 35, + "NameEnd": 37 + } }, { "Expr": { - "Expr": { - "Function": { - "Name": { - "Name": "row_number", - "QuoteType": 1, - "NamePos": 39, - "NameEnd": 49 - }, - "Params": { - "LeftParenPos": 49, - "RightParenPos": 50, - "Items": { - "ListPos": 50, - "ListEnd": 50, - "HasDistinct": false, - "Items": [] - }, - "ColumnArgList": null - } + "Function": { + "Name": { + "Name": "row_number", + "QuoteType": 1, + "NamePos": 39, + "NameEnd": 49 }, - "OverPos": 52, - "OverExpr": { - "LeftParenPos": 57, - "RightParenPos": 89, - "PartitionBy": { - "PartitionPos": 57, - "Expr": { - "ListPos": 71, - "ListEnd": 73, - "HasDistinct": false, - "Items": [ - { - "Name": "f0", - "QuoteType": 1, - "NamePos": 71, - "NameEnd": 73 - } - ] - } + "Params": { + "LeftParenPos": 49, + "RightParenPos": 50, + "Items": { + "ListPos": 50, + "ListEnd": 50, + "HasDistinct": false, + "Items": [] }, - "OrderBy": { - "OrderPos": 74, - "ListEnd": 85, + "ColumnArgList": null + } + }, + "OverPos": 52, + "OverExpr": { + "LeftParenPos": 57, + "RightParenPos": 89, + "PartitionBy": { + "PartitionPos": 57, + "Expr": { + "ListPos": 71, + "ListEnd": 73, + "HasDistinct": false, "Items": [ { - "OrderPos": 74, "Expr": { - "Name": "f1", + "Name": "f0", "QuoteType": 1, - "NamePos": 83, - "NameEnd": 85 + "NamePos": 71, + "NameEnd": 73 }, - "Direction": "ASC" + "Alias": null } ] - }, - "Frame": null - } - }, - "AliasPos": 94, - "Alias": { - "Name": "rn", - "QuoteType": 1, - "NamePos": 94, - "NameEnd": 96 + } + }, + "OrderBy": { + "OrderPos": 74, + "ListEnd": 85, + "Items": [ + { + "OrderPos": 74, + "Expr": { + "Name": "f1", + "QuoteType": 1, + "NamePos": 83, + "NameEnd": 85 + }, + "Alias": null, + "Direction": "ASC" + } + ] + }, + "Frame": null } }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "rn", + "QuoteType": 1, + "NamePos": 94, + "NameEnd": 96 + } } ], "From": { @@ -175,42 +180,54 @@ "HasDistinct": false, "Items": [ { - "LeftExpr": { - "Name": "f0", - "QuoteType": 1, - "NamePos": 127, - "NameEnd": 129 - }, - "Operation": "IN", - "RightExpr": { - "LeftParenPos": 133, - "RightParenPos": 154, - "Items": { - "ListPos": 135, - "ListEnd": 153, - "HasDistinct": false, - "Items": [ - { - "LiteralPos": 135, - "LiteralEnd": 138, - "Literal": "foo" - }, - { - "LiteralPos": 142, - "LiteralEnd": 145, - "Literal": "bar" - }, - { - "LiteralPos": 149, - "LiteralEnd": 153, - "Literal": "test" - } - ] + "Expr": { + "LeftExpr": { + "Name": "f0", + "QuoteType": 1, + "NamePos": 127, + "NameEnd": 129 + }, + "Operation": "IN", + "RightExpr": { + "LeftParenPos": 133, + "RightParenPos": 154, + "Items": { + "ListPos": 135, + "ListEnd": 153, + "HasDistinct": false, + "Items": [ + { + "Expr": { + "LiteralPos": 135, + "LiteralEnd": 138, + "Literal": "foo" + }, + "Alias": null + }, + { + "Expr": { + "LiteralPos": 142, + "LiteralEnd": 145, + "Literal": "bar" + }, + "Alias": null + }, + { + "Expr": { + "LiteralPos": 149, + "LiteralEnd": 153, + "Literal": "test" + }, + "Alias": null + } + ] + }, + "ColumnArgList": null }, - "ColumnArgList": null + "HasGlobal": false, + "HasNot": false }, - "HasGlobal": false, - "HasNot": false + "Alias": null } ] }, @@ -226,20 +243,23 @@ "HasDistinct": false, "Items": [ { - "LeftExpr": { - "Name": "f1", - "QuoteType": 1, - "NamePos": 162, - "NameEnd": 164 - }, - "Operation": "=", - "RightExpr": { - "LiteralPos": 168, - "LiteralEnd": 175, - "Literal": "testing" + "Expr": { + "LeftExpr": { + "Name": "f1", + "QuoteType": 1, + "NamePos": 162, + "NameEnd": 164 + }, + "Operation": "=", + "RightExpr": { + "LiteralPos": 168, + "LiteralEnd": 175, + "Literal": "testing" + }, + "HasGlobal": false, + "HasNot": false }, - "HasGlobal": false, - "HasNot": false + "Alias": null } ] }, @@ -258,20 +278,23 @@ "HasDistinct": false, "Items": [ { - "LeftExpr": { - "Name": "f2", - "QuoteType": 1, - "NamePos": 183, - "NameEnd": 185 - }, - "Operation": "LIKE", - "RightExpr": { - "LiteralPos": 196, - "LiteralEnd": 204, - "Literal": "testing2" + "Expr": { + "LeftExpr": { + "Name": "f2", + "QuoteType": 1, + "NamePos": 183, + "NameEnd": 185 + }, + "Operation": "NOT LIKE", + "RightExpr": { + "LiteralPos": 196, + "LiteralEnd": 204, + "Literal": "testing2" + }, + "HasGlobal": false, + "HasNot": false }, - "HasGlobal": false, - "HasNot": true + "Alias": null } ] }, @@ -288,7 +311,7 @@ "NamePos": 211, "NameEnd": 213 }, - "Operation": "IN", + "Operation": "NOT IN", "RightExpr": { "LeftParenPos": 221, "RightParenPos": 235, @@ -298,26 +321,35 @@ "HasDistinct": false, "Items": [ { - "LiteralPos": 223, - "LiteralEnd": 224, - "Literal": "a" + "Expr": { + "LiteralPos": 223, + "LiteralEnd": 224, + "Literal": "a" + }, + "Alias": null }, { - "LiteralPos": 228, - "LiteralEnd": 229, - "Literal": "b" + "Expr": { + "LiteralPos": 228, + "LiteralEnd": 229, + "Literal": "b" + }, + "Alias": null }, { - "LiteralPos": 233, - "LiteralEnd": 234, - "Literal": "c" + "Expr": { + "LiteralPos": 233, + "LiteralEnd": 234, + "Literal": "c" + }, + "Alias": null } ] }, "ColumnArgList": null }, "HasGlobal": false, - "HasNot": true + "HasNot": false }, "HasGlobal": false, "HasNot": false @@ -332,16 +364,22 @@ "HasDistinct": false, "Items": [ { - "Name": "f0", - "QuoteType": 1, - "NamePos": 248, - "NameEnd": 250 + "Expr": { + "Name": "f0", + "QuoteType": 1, + "NamePos": 248, + "NameEnd": 250 + }, + "Alias": null }, { - "Name": "f1", - "QuoteType": 1, - "NamePos": 254, - "NameEnd": 256 + "Expr": { + "Name": "f1", + "QuoteType": 1, + "NamePos": 254, + "NameEnd": 256 + }, + "Alias": null } ] }, @@ -374,10 +412,13 @@ "HasDistinct": false, "Items": [ { - "Name": "f0", - "QuoteType": 1, - "NamePos": 275, - "NameEnd": 277 + "Expr": { + "Name": "f0", + "QuoteType": 1, + "NamePos": 275, + "NameEnd": 277 + }, + "Alias": null } ] } 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 947e5ba..0734767 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 @@ -7,22 +7,22 @@ "SelectItems": [ { "Expr": { - "Expr": { - "Name": { - "Name": "arrayConcat", - "QuoteType": 1, - "NamePos": 7, - "NameEnd": 18 - }, - "Params": { - "LeftParenPos": 18, - "RightParenPos": 41, - "Items": { - "ListPos": 19, - "ListEnd": 40, - "HasDistinct": false, - "Items": [ - { + "Name": { + "Name": "arrayConcat", + "QuoteType": 1, + "NamePos": 7, + "NameEnd": 18 + }, + "Params": { + "LeftParenPos": 18, + "RightParenPos": 41, + "Items": { + "ListPos": 19, + "ListEnd": 40, + "HasDistinct": false, + "Items": [ + { + "Expr": { "LeftBracketPos": 19, "RightBracketPos": 24, "Items": { @@ -31,21 +31,30 @@ "HasDistinct": false, "Items": [ { - "NumPos": 20, - "NumEnd": 21, - "Literal": "1", - "Base": 10 + "Expr": { + "NumPos": 20, + "NumEnd": 21, + "Literal": "1", + "Base": 10 + }, + "Alias": null }, { - "NumPos": 23, - "NumEnd": 24, - "Literal": "2", - "Base": 10 + "Expr": { + "NumPos": 23, + "NumEnd": 24, + "Literal": "2", + "Base": 10 + }, + "Alias": null } ] } }, - { + "Alias": null + }, + { + "Expr": { "LeftBracketPos": 27, "RightBracketPos": 32, "Items": { @@ -54,21 +63,30 @@ "HasDistinct": false, "Items": [ { - "NumPos": 28, - "NumEnd": 29, - "Literal": "3", - "Base": 10 + "Expr": { + "NumPos": 28, + "NumEnd": 29, + "Literal": "3", + "Base": 10 + }, + "Alias": null }, { - "NumPos": 31, - "NumEnd": 32, - "Literal": "4", - "Base": 10 + "Expr": { + "NumPos": 31, + "NumEnd": 32, + "Literal": "4", + "Base": 10 + }, + "Alias": null } ] } }, - { + "Alias": null + }, + { + "Expr": { "LeftBracketPos": 35, "RightBracketPos": 40, "Items": { @@ -77,71 +95,77 @@ "HasDistinct": false, "Items": [ { - "NumPos": 36, - "NumEnd": 37, - "Literal": "5", - "Base": 10 + "Expr": { + "NumPos": 36, + "NumEnd": 37, + "Literal": "5", + "Base": 10 + }, + "Alias": null }, { - "NumPos": 39, - "NumEnd": 40, - "Literal": "6", - "Base": 10 + "Expr": { + "NumPos": 39, + "NumEnd": 40, + "Literal": "6", + "Base": 10 + }, + "Alias": null } ] } - } - ] - }, - "ColumnArgList": null - } - }, - "AliasPos": 46, - "Alias": { - "Name": "res", - "QuoteType": 1, - "NamePos": 46, - "NameEnd": 49 + }, + "Alias": null + } + ] + }, + "ColumnArgList": null } }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "res", + "QuoteType": 1, + "NamePos": 46, + "NameEnd": 49 + } }, { "Expr": { - "Expr": { - "Object": { - "Name": "f1", - "QuoteType": 1, - "NamePos": 51, - "NameEnd": 53 - }, - "Params": { - "LeftBracketPos": 53, - "RightBracketPos": 59, - "Items": { - "ListPos": 55, - "ListEnd": 58, - "HasDistinct": false, - "Items": [ - { + "Object": { + "Name": "f1", + "QuoteType": 1, + "NamePos": 51, + "NameEnd": 53 + }, + "Params": { + "LeftBracketPos": 53, + "RightBracketPos": 59, + "Items": { + "ListPos": 55, + "ListEnd": 58, + "HasDistinct": false, + "Items": [ + { + "Expr": { "Name": "abc", "QuoteType": 2, "NamePos": 55, "NameEnd": 58 - } - ] - } + }, + "Alias": null + } + ] } - }, - "AliasPos": 64, - "Alias": { - "Name": "f2", - "QuoteType": 1, - "NamePos": 64, - "NameEnd": 66 } }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "f2", + "QuoteType": 1, + "NamePos": 64, + "NameEnd": 66 + } } ], "From": 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 6ef5312..29b6a99 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 @@ -24,22 +24,31 @@ "HasDistinct": false, "Items": [ { - "Name": "f1", - "QuoteType": 1, - "NamePos": 14, - "NameEnd": 16 + "Expr": { + "Name": "f1", + "QuoteType": 1, + "NamePos": 14, + "NameEnd": 16 + }, + "Alias": null }, { - "Name": "f2", - "QuoteType": 1, - "NamePos": 18, - "NameEnd": 20 + "Expr": { + "Name": "f2", + "QuoteType": 1, + "NamePos": 18, + "NameEnd": 20 + }, + "Alias": null }, { - "Name": "f3", - "QuoteType": 1, - "NamePos": 22, - "NameEnd": 24 + "Expr": { + "Name": "f3", + "QuoteType": 1, + "NamePos": 22, + "NameEnd": 24 + }, + "Alias": null } ] }, @@ -59,7 +68,8 @@ "NamePos": 37, "NameEnd": 39 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null }, { "Expr": { @@ -68,7 +78,8 @@ "NamePos": 41, "NameEnd": 43 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null }, { "Expr": { @@ -77,7 +88,8 @@ "NamePos": 45, "NameEnd": 47 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null } ], "From": { @@ -126,57 +138,48 @@ "SelectItems": [ { "Expr": { - "Expr": { - "Name": "f1", - "QuoteType": 1, - "NamePos": 71, - "NameEnd": 73 - }, - "AliasPos": 77, - "Alias": { - "Name": "new_f1", - "QuoteType": 1, - "NamePos": 77, - "NameEnd": 83 - } + "Name": "f1", + "QuoteType": 1, + "NamePos": 71, + "NameEnd": 73 }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "new_f1", + "QuoteType": 1, + "NamePos": 77, + "NameEnd": 83 + } }, { "Expr": { - "Expr": { - "Name": "f2", - "QuoteType": 1, - "NamePos": 89, - "NameEnd": 91 - }, - "AliasPos": 95, - "Alias": { - "Name": "new_f2", - "QuoteType": 1, - "NamePos": 95, - "NameEnd": 101 - } + "Name": "f2", + "QuoteType": 1, + "NamePos": 89, + "NameEnd": 91 }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "new_f2", + "QuoteType": 1, + "NamePos": 95, + "NameEnd": 101 + } }, { "Expr": { - "Expr": { - "Name": "f3", - "QuoteType": 1, - "NamePos": 107, - "NameEnd": 109 - }, - "AliasPos": 113, - "Alias": { - "Name": "new_f3", - "QuoteType": 1, - "NamePos": 113, - "NameEnd": 119 - } + "Name": "f3", + "QuoteType": 1, + "NamePos": 107, + "NameEnd": 109 }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "new_f3", + "QuoteType": 1, + "NamePos": 113, + "NameEnd": 119 + } } ], "From": { 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 c6c2a47..00e350a 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 @@ -12,7 +12,8 @@ "NamePos": 7, "NameEnd": 8 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null }, { "Expr": { @@ -31,17 +32,21 @@ "HasDistinct": false, "Items": [ { - "Name": "b", - "QuoteType": 1, - "NamePos": 16, - "NameEnd": 17 + "Expr": { + "Name": "b", + "QuoteType": 1, + "NamePos": 16, + "NameEnd": 17 + }, + "Alias": null } ] }, "ColumnArgList": null } }, - "Modifiers": [] + "Modifiers": [], + "Alias": null } ], "From": { @@ -83,10 +88,13 @@ "HasDistinct": false, "Items": [ { - "Name": "a", - "QuoteType": 1, - "NamePos": 51, - "NameEnd": 52 + "Expr": { + "Name": "a", + "QuoteType": 1, + "NamePos": 51, + "NameEnd": 52 + }, + "Alias": null } ] }, @@ -110,6 +118,7 @@ "NamePos": 85, "NameEnd": 86 }, + "Alias": null, "Direction": "None" } ] 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 26d471d..01ee86e 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 @@ -12,7 +12,8 @@ "NamePos": 7, "NameEnd": 9 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null }, { "Expr": { @@ -21,7 +22,8 @@ "NamePos": 10, "NameEnd": 12 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null }, { "Expr": { @@ -30,25 +32,23 @@ "NamePos": 13, "NameEnd": 15 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null }, { "Expr": { - "Expr": { - "Name": "f3", - "QuoteType": 1, - "NamePos": 16, - "NameEnd": 18 - }, - "AliasPos": 22, - "Alias": { - "Name": "a0", - "QuoteType": 1, - "NamePos": 22, - "NameEnd": 24 - } + "Name": "f3", + "QuoteType": 1, + "NamePos": 16, + "NameEnd": 18 }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "a0", + "QuoteType": 1, + "NamePos": 22, + "NameEnd": 24 + } } ], "From": { @@ -96,42 +96,54 @@ "HasDistinct": false, "Items": [ { - "LeftExpr": { - "Name": "f0", - "QuoteType": 1, - "NamePos": 55, - "NameEnd": 57 - }, - "Operation": "IN", - "RightExpr": { - "LeftParenPos": 61, - "RightParenPos": 82, - "Items": { - "ListPos": 63, - "ListEnd": 81, - "HasDistinct": false, - "Items": [ - { - "LiteralPos": 63, - "LiteralEnd": 66, - "Literal": "foo" - }, - { - "LiteralPos": 70, - "LiteralEnd": 73, - "Literal": "bar" - }, - { - "LiteralPos": 77, - "LiteralEnd": 81, - "Literal": "test" - } - ] + "Expr": { + "LeftExpr": { + "Name": "f0", + "QuoteType": 1, + "NamePos": 55, + "NameEnd": 57 + }, + "Operation": "IN", + "RightExpr": { + "LeftParenPos": 61, + "RightParenPos": 82, + "Items": { + "ListPos": 63, + "ListEnd": 81, + "HasDistinct": false, + "Items": [ + { + "Expr": { + "LiteralPos": 63, + "LiteralEnd": 66, + "Literal": "foo" + }, + "Alias": null + }, + { + "Expr": { + "LiteralPos": 70, + "LiteralEnd": 73, + "Literal": "bar" + }, + "Alias": null + }, + { + "Expr": { + "LiteralPos": 77, + "LiteralEnd": 81, + "Literal": "test" + }, + "Alias": null + } + ] + }, + "ColumnArgList": null }, - "ColumnArgList": null + "HasGlobal": false, + "HasNot": false }, - "HasGlobal": false, - "HasNot": false + "Alias": null } ] }, @@ -147,20 +159,23 @@ "HasDistinct": false, "Items": [ { - "LeftExpr": { - "Name": "f1", - "QuoteType": 1, - "NamePos": 92, - "NameEnd": 94 - }, - "Operation": "=", - "RightExpr": { - "LiteralPos": 98, - "LiteralEnd": 105, - "Literal": "testing" + "Expr": { + "LeftExpr": { + "Name": "f1", + "QuoteType": 1, + "NamePos": 92, + "NameEnd": 94 + }, + "Operation": "=", + "RightExpr": { + "LiteralPos": 98, + "LiteralEnd": 105, + "Literal": "testing" + }, + "HasGlobal": false, + "HasNot": false }, - "HasGlobal": false, - "HasNot": false + "Alias": null } ] }, @@ -171,7 +186,7 @@ }, "Operation": "AND", "RightExpr": { - "IsPos": 114, + "IsPos": 127, "Expr": { "Name": "f2", "QuoteType": 1, @@ -184,7 +199,7 @@ }, "Operation": "AND", "RightExpr": { - "IsPos": 131, + "IsPos": 145, "Expr": { "Name": "f3", "QuoteType": 1, 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 ec1a135..5a57bb5 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 @@ -12,7 +12,8 @@ "NamePos": 7, "NameEnd": 9 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null }, { "Expr": { @@ -21,7 +22,8 @@ "NamePos": 10, "NameEnd": 12 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null }, { "Expr": { @@ -30,25 +32,23 @@ "NamePos": 13, "NameEnd": 15 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null }, { "Expr": { - "Expr": { - "Name": "f3", - "QuoteType": 1, - "NamePos": 16, - "NameEnd": 18 - }, - "AliasPos": 22, - "Alias": { - "Name": "a0", - "QuoteType": 1, - "NamePos": 22, - "NameEnd": 24 - } + "Name": "f3", + "QuoteType": 1, + "NamePos": 16, + "NameEnd": 18 }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "a0", + "QuoteType": 1, + "NamePos": 22, + "NameEnd": 24 + } } ], "From": { @@ -95,42 +95,54 @@ "HasDistinct": false, "Items": [ { - "LeftExpr": { - "Name": "f0", - "QuoteType": 1, - "NamePos": 55, - "NameEnd": 57 - }, - "Operation": "IN", - "RightExpr": { - "LeftParenPos": 61, - "RightParenPos": 82, - "Items": { - "ListPos": 63, - "ListEnd": 81, - "HasDistinct": false, - "Items": [ - { - "LiteralPos": 63, - "LiteralEnd": 66, - "Literal": "foo" - }, - { - "LiteralPos": 70, - "LiteralEnd": 73, - "Literal": "bar" - }, - { - "LiteralPos": 77, - "LiteralEnd": 81, - "Literal": "test" - } - ] + "Expr": { + "LeftExpr": { + "Name": "f0", + "QuoteType": 1, + "NamePos": 55, + "NameEnd": 57 + }, + "Operation": "IN", + "RightExpr": { + "LeftParenPos": 61, + "RightParenPos": 82, + "Items": { + "ListPos": 63, + "ListEnd": 81, + "HasDistinct": false, + "Items": [ + { + "Expr": { + "LiteralPos": 63, + "LiteralEnd": 66, + "Literal": "foo" + }, + "Alias": null + }, + { + "Expr": { + "LiteralPos": 70, + "LiteralEnd": 73, + "Literal": "bar" + }, + "Alias": null + }, + { + "Expr": { + "LiteralPos": 77, + "LiteralEnd": 81, + "Literal": "test" + }, + "Alias": null + } + ] + }, + "ColumnArgList": null }, - "ColumnArgList": null + "HasGlobal": false, + "HasNot": false }, - "HasGlobal": false, - "HasNot": false + "Alias": null } ] }, @@ -146,20 +158,23 @@ "HasDistinct": false, "Items": [ { - "LeftExpr": { - "Name": "f1", - "QuoteType": 1, - "NamePos": 90, - "NameEnd": 92 - }, - "Operation": "=", - "RightExpr": { - "LiteralPos": 96, - "LiteralEnd": 103, - "Literal": "testing" + "Expr": { + "LeftExpr": { + "Name": "f1", + "QuoteType": 1, + "NamePos": 90, + "NameEnd": 92 + }, + "Operation": "=", + "RightExpr": { + "LiteralPos": 96, + "LiteralEnd": 103, + "Literal": "testing" + }, + "HasGlobal": false, + "HasNot": false }, - "HasGlobal": false, - "HasNot": false + "Alias": null } ] }, @@ -170,7 +185,7 @@ }, "Operation": "AND", "RightExpr": { - "IsPos": 110, + "IsPos": 120, "Expr": { "Name": "f2", "QuoteType": 1, 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 2d79b96..caf8dc8 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 @@ -22,7 +22,8 @@ "NamePos": 14, "NameEnd": 23 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null } ], "From": { 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 b12ec1b..8f4c0ab 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 @@ -27,7 +27,8 @@ "NamePos": 25, "NameEnd": 27 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null } ], "From": { @@ -91,7 +92,8 @@ "NamePos": 58, "NameEnd": 60 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null } ], "From": { @@ -154,7 +156,8 @@ "NameEnd": 88 } }, - "Modifiers": [] + "Modifiers": [], + "Alias": null }, { "Expr": { @@ -172,7 +175,8 @@ "NameEnd": 101 } }, - "Modifiers": [] + "Modifiers": [], + "Alias": null }, { "Expr": { @@ -190,7 +194,8 @@ "NameEnd": 112 } }, - "Modifiers": [] + "Modifiers": [], + "Alias": null } ], "From": { 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 2903a11..1703ae8 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 @@ -21,7 +21,8 @@ "NameEnd": 19 } }, - "Modifiers": [] + "Modifiers": [], + "Alias": null } ], "From": { @@ -101,39 +102,42 @@ "HasDistinct": false, "Items": [ { - "LeftExpr": { - "Database": null, - "Table": { - "Name": "t1", - "QuoteType": 1, - "NamePos": 69, - "NameEnd": 71 + "Expr": { + "LeftExpr": { + "Database": null, + "Table": { + "Name": "t1", + "QuoteType": 1, + "NamePos": 69, + "NameEnd": 71 + }, + "Column": { + "Name": "a", + "QuoteType": 1, + "NamePos": 72, + "NameEnd": 73 + } }, - "Column": { - "Name": "a", - "QuoteType": 1, - "NamePos": 72, - "NameEnd": 73 - } - }, - "Operation": "=", - "RightExpr": { - "Database": null, - "Table": { - "Name": "t2", - "QuoteType": 1, - "NamePos": 74, - "NameEnd": 76 + "Operation": "=", + "RightExpr": { + "Database": null, + "Table": { + "Name": "t2", + "QuoteType": 1, + "NamePos": 74, + "NameEnd": 76 + }, + "Column": { + "Name": "b", + "QuoteType": 1, + "NamePos": 77, + "NameEnd": 78 + } }, - "Column": { - "Name": "b", - "QuoteType": 1, - "NamePos": 77, - "NameEnd": 78 - } + "HasGlobal": false, + "HasNot": false }, - "HasGlobal": false, - "HasNot": false + "Alias": null } ] } 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 efe9774..2083a77 100644 --- a/parser/testdata/query/output/select_when_condition.sql.golden.json +++ b/parser/testdata/query/output/select_when_condition.sql.golden.json @@ -36,7 +36,8 @@ "Literal": "world" } }, - "Modifiers": [] + "Modifiers": [], + "Alias": null } ], "From": 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 bbfb30c..94b4ea9 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 @@ -12,7 +12,8 @@ "NamePos": 7, "NameEnd": 7 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null } ], "From": { @@ -73,10 +74,13 @@ "HasDistinct": false, "Items": [ { - "Name": "true", - "QuoteType": 1, - "NamePos": 32, - "NameEnd": 36 + "Expr": { + "Name": "true", + "QuoteType": 1, + "NamePos": 32, + "NameEnd": 36 + }, + "Alias": null } ] } 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 5704615..2a1f5d8 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 @@ -22,21 +22,18 @@ "SelectItems": [ { "Expr": { - "Expr": { - "NumPos": 44, - "NumEnd": 45, - "Literal": "1", - "Base": 10 - }, - "AliasPos": 49, - "Alias": { - "Name": "value", - "QuoteType": 1, - "NamePos": 49, - "NameEnd": 54 - } + "NumPos": 44, + "NumEnd": 45, + "Literal": "1", + "Base": 10 }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "value", + "QuoteType": 1, + "NamePos": 49, + "NameEnd": 54 + } } ], "From": null, @@ -73,21 +70,18 @@ "SelectItems": [ { "Expr": { - "Expr": { - "NumPos": 88, - "NumEnd": 89, - "Literal": "2", - "Base": 10 - }, - "AliasPos": 93, - "Alias": { - "Name": "value", - "QuoteType": 1, - "NamePos": 93, - "NameEnd": 98 - } + "NumPos": 88, + "NumEnd": 89, + "Literal": "2", + "Base": 10 }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "value", + "QuoteType": 1, + "NamePos": 93, + "NameEnd": 98 + } } ], "From": null, @@ -119,7 +113,8 @@ "NamePos": 112, "NameEnd": 112 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null } ], "From": { @@ -181,10 +176,13 @@ "HasDistinct": false, "Items": [ { - "Name": "true", - "QuoteType": 1, - "NamePos": 147, - "NameEnd": 151 + "Expr": { + "Name": "true", + "QuoteType": 1, + "NamePos": 147, + "NameEnd": 151 + }, + "Alias": null } ] } 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 e9070ad..4115fa7 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 @@ -12,7 +12,8 @@ "NamePos": 7, "NameEnd": 17 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null } ], "From": { 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 b6d3427..e9fffb9 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 @@ -22,20 +22,17 @@ "SelectItems": [ { "Expr": { - "Expr": { - "LiteralPos": 25, - "LiteralEnd": 31, - "Literal": "value1" - }, - "AliasPos": 36, - "Alias": { - "Name": "value", - "QuoteType": 1, - "NamePos": 36, - "NameEnd": 41 - } + "LiteralPos": 25, + "LiteralEnd": 31, + "Literal": "value1" }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "value", + "QuoteType": 1, + "NamePos": 36, + "NameEnd": 41 + } } ], "From": null, @@ -72,20 +69,17 @@ "SelectItems": [ { "Expr": { - "Expr": { - "LiteralPos": 65, - "LiteralEnd": 71, - "Literal": "value2" - }, - "AliasPos": 76, - "Alias": { - "Name": "value", - "QuoteType": 1, - "NamePos": 76, - "NameEnd": 81 - } + "LiteralPos": 65, + "LiteralEnd": 71, + "Literal": "value2" }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "value", + "QuoteType": 1, + "NamePos": 76, + "NameEnd": 81 + } } ], "From": null, @@ -122,20 +116,17 @@ "SelectItems": [ { "Expr": { - "Expr": { - "LiteralPos": 105, - "LiteralEnd": 111, - "Literal": "value3" - }, - "AliasPos": 116, - "Alias": { - "Name": "value", - "QuoteType": 1, - "NamePos": 116, - "NameEnd": 121 - } + "LiteralPos": 105, + "LiteralEnd": 111, + "Literal": "value3" }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "value", + "QuoteType": 1, + "NamePos": 116, + "NameEnd": 121 + } } ], "From": null, @@ -162,84 +153,75 @@ "SelectItems": [ { "Expr": { - "Expr": { - "Database": null, - "Table": { - "Name": "t1", - "QuoteType": 1, - "NamePos": 139, - "NameEnd": 141 - }, - "Column": { - "Name": "value", - "QuoteType": 1, - "NamePos": 142, - "NameEnd": 147 - } + "Database": null, + "Table": { + "Name": "t1", + "QuoteType": 1, + "NamePos": 139, + "NameEnd": 141 }, - "AliasPos": 151, - "Alias": { - "Name": "value1", + "Column": { + "Name": "value", "QuoteType": 1, - "NamePos": 151, - "NameEnd": 157 + "NamePos": 142, + "NameEnd": 147 } }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "value1", + "QuoteType": 1, + "NamePos": 151, + "NameEnd": 157 + } }, { "Expr": { - "Expr": { - "Database": null, - "Table": { - "Name": "t2", - "QuoteType": 1, - "NamePos": 163, - "NameEnd": 165 - }, - "Column": { - "Name": "value", - "QuoteType": 1, - "NamePos": 166, - "NameEnd": 171 - } + "Database": null, + "Table": { + "Name": "t2", + "QuoteType": 1, + "NamePos": 163, + "NameEnd": 165 }, - "AliasPos": 175, - "Alias": { - "Name": "value2", + "Column": { + "Name": "value", "QuoteType": 1, - "NamePos": 175, - "NameEnd": 181 + "NamePos": 166, + "NameEnd": 171 } }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "value2", + "QuoteType": 1, + "NamePos": 175, + "NameEnd": 181 + } }, { "Expr": { - "Expr": { - "Database": null, - "Table": { - "Name": "t3", - "QuoteType": 1, - "NamePos": 187, - "NameEnd": 189 - }, - "Column": { - "Name": "value", - "QuoteType": 1, - "NamePos": 190, - "NameEnd": 195 - } + "Database": null, + "Table": { + "Name": "t3", + "QuoteType": 1, + "NamePos": 187, + "NameEnd": 189 }, - "AliasPos": 199, - "Alias": { - "Name": "value3", + "Column": { + "Name": "value", "QuoteType": 1, - "NamePos": 199, - "NameEnd": 205 + "NamePos": 190, + "NameEnd": 195 } }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "value3", + "QuoteType": 1, + "NamePos": 199, + "NameEnd": 205 + } } ], "From": { @@ -371,10 +353,13 @@ "HasDistinct": false, "Items": [ { - "Name": "true", - "QuoteType": 1, - "NamePos": 277, - "NameEnd": 281 + "Expr": { + "Name": "true", + "QuoteType": 1, + "NamePos": 277, + "NameEnd": 281 + }, + "Alias": null } ] } @@ -396,10 +381,13 @@ "HasDistinct": false, "Items": [ { - "Name": "true", - "QuoteType": 1, - "NamePos": 237, - "NameEnd": 241 + "Expr": { + "Name": "true", + "QuoteType": 1, + "NamePos": 237, + "NameEnd": 241 + }, + "Alias": null } ] } 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 1633180..54e418a 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 @@ -12,7 +12,8 @@ "NamePos": 48, "NameEnd": 48 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null } ], "From": { 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 76349ed..51b7fe9 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 @@ -7,21 +7,18 @@ "SelectItems": [ { "Expr": { - "Expr": { - "NumPos": 7, - "NumEnd": 8, - "Literal": "1", - "Base": 10 - }, - "AliasPos": 12, - "Alias": { - "Name": "v1", - "QuoteType": 1, - "NamePos": 12, - "NameEnd": 14 - } + "NumPos": 7, + "NumEnd": 8, + "Literal": "1", + "Base": 10 }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "v1", + "QuoteType": 1, + "NamePos": 12, + "NameEnd": 14 + } } ], "From": null, @@ -45,21 +42,18 @@ "SelectItems": [ { "Expr": { - "Expr": { - "NumPos": 32, - "NumEnd": 33, - "Literal": "2", - "Base": 10 - }, - "AliasPos": 37, - "Alias": { - "Name": "v2", - "QuoteType": 1, - "NamePos": 37, - "NameEnd": 39 - } + "NumPos": 32, + "NumEnd": 33, + "Literal": "2", + "Base": 10 }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "v2", + "QuoteType": 1, + "NamePos": 37, + "NameEnd": 39 + } } ], "From": null, @@ -83,21 +77,18 @@ "SelectItems": [ { "Expr": { - "Expr": { - "NumPos": 57, - "NumEnd": 58, - "Literal": "3", - "Base": 10 - }, - "AliasPos": 62, - "Alias": { - "Name": "v3", - "QuoteType": 1, - "NamePos": 62, - "NameEnd": 64 - } + "NumPos": 57, + "NumEnd": 58, + "Literal": "3", + "Base": 10 }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "v3", + "QuoteType": 1, + "NamePos": 62, + "NameEnd": 64 + } } ], "From": 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 a61d054..0a2fc5a 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 @@ -102,16 +102,22 @@ "HasDistinct": false, "Items": [ { - "NumPos": 98, - "NumEnd": 100, - "Literal": "11", - "Base": 10 + "Expr": { + "NumPos": 98, + "NumEnd": 100, + "Literal": "11", + "Base": 10 + }, + "Alias": null }, { - "NumPos": 102, - "NumEnd": 104, - "Literal": "12", - "Base": 10 + "Expr": { + "NumPos": 102, + "NumEnd": 104, + "Literal": "12", + "Base": 10 + }, + "Alias": null } ] } @@ -132,16 +138,22 @@ "HasDistinct": false, "Items": [ { - "NumPos": 114, - "NumEnd": 116, - "Literal": "14", - "Base": 10 + "Expr": { + "NumPos": 114, + "NumEnd": 116, + "Literal": "14", + "Base": 10 + }, + "Alias": null }, { - "NumPos": 118, - "NumEnd": 120, - "Literal": "15", - "Base": 10 + "Expr": { + "NumPos": 118, + "NumEnd": 120, + "Literal": "15", + "Base": 10 + }, + "Alias": null } ] } @@ -178,7 +190,8 @@ } } }, - "Modifiers": [] + "Modifiers": [], + "Alias": null }, { "Expr": { @@ -199,7 +212,8 @@ } } }, - "Modifiers": [] + "Modifiers": [], + "Alias": null }, { "Expr": { @@ -220,7 +234,8 @@ } } }, - "Modifiers": [] + "Modifiers": [], + "Alias": null }, { "Expr": { @@ -273,7 +288,8 @@ ] } }, - "Modifiers": [] + "Modifiers": [], + "Alias": null } ], "From": null, @@ -306,7 +322,8 @@ "NamePos": 229, "NameEnd": 229 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null } ], "From": { 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 9f65a73..927c682 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 @@ -22,21 +22,18 @@ "SelectItems": [ { "Expr": { - "Expr": { - "NumPos": 22, - "NumEnd": 23, - "Literal": "1", - "Base": 10 - }, - "AliasPos": 27, - "Alias": { - "Name": "a", - "QuoteType": 1, - "NamePos": 27, - "NameEnd": 28 - } + "NumPos": 22, + "NumEnd": 23, + "Literal": "1", + "Base": 10 }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "a", + "QuoteType": 1, + "NamePos": 27, + "NameEnd": 28 + } } ], "From": null, @@ -68,7 +65,8 @@ "NamePos": 37, "NameEnd": 37 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null } ], "From": { 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 979b52e..6129d74 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 @@ -12,7 +12,8 @@ "NamePos": 7, "NameEnd": 19 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null } ], "From": { @@ -69,7 +70,8 @@ "NamePos": 66, "NameEnd": 78 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null } ], "From": { 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 e87c2f1..37e3ab1 100644 --- a/parser/testdata/query/output/select_with_variable.sql.golden.json +++ b/parser/testdata/query/output/select_with_variable.sql.golden.json @@ -22,21 +22,18 @@ "SelectItems": [ { "Expr": { - "Expr": { - "NumPos": 21, - "NumEnd": 22, - "Literal": "1", - "Base": 10 - }, - "AliasPos": 26, - "Alias": { - "Name": "a", - "QuoteType": 1, - "NamePos": 26, - "NameEnd": 27 - } + "NumPos": 21, + "NumEnd": 22, + "Literal": "1", + "Base": 10 }, - "Modifiers": [] + "Modifiers": [], + "Alias": { + "Name": "a", + "QuoteType": 1, + "NamePos": 26, + "NameEnd": 27 + } } ], "From": null, @@ -68,7 +65,8 @@ "NamePos": 36, "NameEnd": 36 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null } ], "From": { 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 8cb197a..219c174 100644 --- a/parser/testdata/query/output/selelct_with_placeholder.sql.golden.json +++ b/parser/testdata/query/output/selelct_with_placeholder.sql.golden.json @@ -12,7 +12,8 @@ "NamePos": 7, "NameEnd": 7 }, - "Modifiers": [] + "Modifiers": [], + "Alias": null } ], "From": { diff --git a/parser/testdata/query/query_with_expr_compare.sql b/parser/testdata/query/query_with_expr_compare.sql new file mode 100644 index 0000000..5d114af --- /dev/null +++ b/parser/testdata/query/query_with_expr_compare.sql @@ -0,0 +1,6 @@ +SELECT date, path, splitByChar('/', path)[2] AS path_b +FROM( + SELECT 'pathA/pathB/pathC' AS path, '2024-09-10' AS date + ) +WHERE toDate(date) BETWEEN '2024-09-01' AND '2024-09-30' + AND splitByChar('/', path)[1] = 'pathA' \ No newline at end of file