Skip to content

Commit

Permalink
Fix panic while the query with order by Timestamp keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
git-hulk committed Jul 24, 2024
1 parent 2d5d5a4 commit b56bd6f
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 1 deletion.
2 changes: 1 addition & 1 deletion parser/parser_column.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func (p *Parser) parseColumnExpr(pos Pos) (Expr, error) { //nolint:funlen
if err != nil {
return nil, err
}
if nextToken.Kind == TokenString {
if nextToken != nil && nextToken.Kind == TokenString {
return p.parseString(pos)
}
return p.parseIdentOrFunction(pos)
Expand Down
10 changes: 10 additions & 0 deletions parser/testdata/query/format/select_order_by_timestamp.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- Origin SQL:
SELECT Timestamp FROM events ORDER BY Timestamp;

-- Format SQL:

SELECT
Timestamp
FROM
events
ORDER BY Timestamp;
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
[
{
"SelectPos": 0,
"StatementEnd": 47,
"With": null,
"Top": null,
"SelectColumns": {
"ListPos": 7,
"ListEnd": 16,
"HasDistinct": false,
"Items": [
{
"Name": "Timestamp",
"QuoteType": 1,
"NamePos": 7,
"NameEnd": 16
}
]
},
"From": {
"FromPos": 17,
"Expr": {
"Table": {
"TablePos": 22,
"TableEnd": 28,
"Alias": null,
"Expr": {
"Database": null,
"Table": {
"Name": "events",
"QuoteType": 1,
"NamePos": 22,
"NameEnd": 28
}
},
"HasFinal": false
},
"StatementEnd": 28,
"SampleRatio": null,
"HasFinal": false
}
},
"ArrayJoin": null,
"Window": null,
"Prewhere": null,
"Where": null,
"GroupBy": null,
"WithTotal": false,
"Having": null,
"OrderBy": {
"OrderPos": 29,
"ListEnd": 47,
"Items": [
{
"OrderPos": 29,
"Expr": {
"Name": "Timestamp",
"QuoteType": 1,
"NamePos": 38,
"NameEnd": 47
},
"Direction": "None"
}
]
},
"LimitBy": null,
"Limit": null,
"Settings": null,
"Format": null,
"UnionAll": null,
"UnionDistinct": null,
"Except": null
}
]
1 change: 1 addition & 0 deletions parser/testdata/query/select_order_by_timestamp.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT Timestamp FROM events ORDER BY Timestamp;

0 comments on commit b56bd6f

Please sign in to comment.