Fix ExcludedKeywords parsing

This commit is contained in:
Pijus Kamandulis
2026-08-05 20:06:10 +03:00
parent c78842726b
commit 92d956e8fa
4 changed files with 1690 additions and 1605 deletions
+11
View File
@@ -99,6 +99,17 @@ func Test_Documents(t *testing.T) {
)
})
t.Run("Should query document with 'orderByItems' alias", func(t *testing.T) {
testCosmosQuery(t, collectionClient,
`SELECT c.id, c["pk"] AS orderByItems FROM c ORDER BY c.id`,
nil,
[]interface{}{
map[string]interface{}{"id": "12345", "orderByItems": "123"},
map[string]interface{}{"id": "67890", "orderByItems": "456"},
},
)
})
t.Run("Should query VALUE array", func(t *testing.T) {
testCosmosQuery(t, collectionClient,
"SELECT VALUE [c.id, c[\"pk\"]] FROM c ORDER BY c.id",
+1619 -1569
View File
File diff suppressed because it is too large Load Diff
+5 -1
View File
@@ -387,7 +387,11 @@ AsClause <- (ws As)? ws !ExcludedKeywords alias:Identifier {
return alias, nil
}
ExcludedKeywords <- Select / Top / As / From / In / Join / Exists / Where / And / Or / Not / GroupBy / OrderBy / Offset
ExcludedKeywords <- (
Select / Top / As / From / In / Join / Exists / Where / And / Or / Not / Offset /
("GROUP"i wss "BY"i) /
("ORDER"i wss "BY"i)
) ![a-zA-Z0-9_]
DotFieldAccess <- "." id:Identifier {
return id, nil
+20
View File
@@ -159,6 +159,26 @@ func Test_Parse_Select(t *testing.T) {
)
})
t.Run("Should parse SELECT with orderByItems alias", func(t *testing.T) {
testQueryParse(
t,
`SELECT c.id, c["pk"] AS orderByItems FROM c ORDER BY c.id`,
parsers.SelectStmt{
SelectItems: []parsers.SelectItem{
{Path: []string{"c", "id"}},
{Alias: "orderByItems", Path: []string{"c", "pk"}},
},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
OrderExpressions: []parsers.OrderExpression{
{
SelectItem: testutils.SelectItem_Path("c", "id"),
Direction: parsers.OrderDirectionAsc,
},
},
},
)
})
t.Run("Should parse SELECT object", func(t *testing.T) {
testQueryParse(
t,