(pos Pos)
| 955 | } |
| 956 | |
| 957 | func (p *Parser) parseOrderExpr(pos Pos) (*OrderExpr, error) { |
| 958 | // parse column expr |
| 959 | columnExpr, err := p.parseExpr(pos) |
| 960 | if err != nil { |
| 961 | return nil, err |
| 962 | } |
| 963 | |
| 964 | var alias *Ident |
| 965 | if p.matchKeyword(KeywordAs) { |
| 966 | // It should be a subquery instead of an order by alias if the `AS` is followed by `SELECT` keyword. |
| 967 | if nextToken, err := p.lexer.peekToken(); err == nil && nextToken.ToString() == KeywordSelect { |
| 968 | return &OrderExpr{ |
| 969 | OrderPos: pos, |
| 970 | Expr: columnExpr, |
| 971 | }, nil |
| 972 | } |
| 973 | // consume the `AS` keyword |
| 974 | _ = p.lexer.consumeToken() |
| 975 | alias, err = p.parseIdent() |
| 976 | if err != nil { |
| 977 | return nil, err |
| 978 | } |
| 979 | } else if p.matchKeyword(KeywordTtl) { |
| 980 | return &OrderExpr{ |
| 981 | OrderPos: pos, |
| 982 | Expr: columnExpr, |
| 983 | }, nil |
| 984 | } |
| 985 | |
| 986 | direction := OrderDirectionNone |
| 987 | switch { |
| 988 | case p.matchKeyword(KeywordAsc), p.matchKeyword(KeywordAscending): |
| 989 | direction = OrderDirectionAsc |
| 990 | _ = p.lexer.consumeToken() |
| 991 | case p.matchKeyword(KeywordDesc), p.matchKeyword(KeywordDescending): |
| 992 | direction = OrderDirectionDesc |
| 993 | _ = p.lexer.consumeToken() |
| 994 | } |
| 995 | |
| 996 | // Parse optional WITH FILL clause |
| 997 | var fill *Fill |
| 998 | if p.tryConsumeKeywords(KeywordWith, KeywordFill) { |
| 999 | fillPos := p.Pos() |
| 1000 | fill, err = p.parseFillClause(fillPos) |
| 1001 | if err != nil { |
| 1002 | return nil, err |
| 1003 | } |
| 1004 | } |
| 1005 | |
| 1006 | return &OrderExpr{ |
| 1007 | OrderPos: pos, |
| 1008 | Alias: alias, |
| 1009 | Expr: columnExpr, |
| 1010 | Direction: direction, |
| 1011 | Fill: fill, |
| 1012 | }, nil |
| 1013 | } |
| 1014 |
no test coverage detected