Skip to content

Commit b940e04

Browse files
authored
fix: allow ident in order and group by clauses (#31)
1 parent 914fb46 commit b940e04

7 files changed

Lines changed: 122 additions & 4 deletions

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22

33
name = "eventql-parser"
4-
version = "0.1.14"
4+
version = "0.1.15"
55
authors = ["Yorick Laupa <yo.eight@gmail.com>"]
66
description = "EventQL Lexer and Parser"
77
homepage = "https://github.com/YoEight/eventql-parser"

src/tests/analysis.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,3 +430,27 @@ fn test_accept_valid_having_clause() {
430430
}))
431431
});
432432
}
433+
434+
#[test]
435+
fn test_ids_in_order_by_should_pass() {
436+
let mut session = Session::builder().use_stdlib().build();
437+
let query = session.parse(include_str!("./resources/ids_in_order_by_should_pass.eql"));
438+
439+
insta::assert_yaml_snapshot!(query.and_then(|q| {
440+
session
441+
.run_static_analysis(q)
442+
.map(|q| q.view(&session.arena))
443+
}));
444+
}
445+
446+
#[test]
447+
fn test_ids_in_group_by_should_pass() {
448+
let mut session = Session::builder().use_stdlib().build();
449+
let query = session.parse(include_str!("./resources/ids_in_group_by_should_pass.eql"));
450+
451+
insta::assert_yaml_snapshot!(query.and_then(|q| {
452+
session
453+
.run_static_analysis(q)
454+
.map(|q| q.view(&session.arena))
455+
}));
456+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM event_type IN eventtypes
2+
GROUP BY event_type
3+
PROJECT INTO unique(event_type)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM event_type IN eventtypes
2+
ORDER BY event_type
3+
PROJECT INTO event_type
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
source: src/tests/analysis.rs
3+
expression: "query.and_then(|q|\n{ session.run_static_analysis(q).map(|q| q.view(&session.arena)) })"
4+
---
5+
Ok:
6+
attrs:
7+
pos:
8+
line: 1
9+
col: 1
10+
sources:
11+
- binding:
12+
name: event_type
13+
pos:
14+
line: 1
15+
col: 6
16+
kind:
17+
Name: eventtypes
18+
predicate: ~
19+
group_by:
20+
expr:
21+
attrs:
22+
pos:
23+
line: 2
24+
col: 10
25+
value:
26+
Id: event_type
27+
predicate: ~
28+
order_by: ~
29+
limit: ~
30+
projection:
31+
attrs:
32+
pos:
33+
line: 3
34+
col: 14
35+
value:
36+
App:
37+
func: unique
38+
args:
39+
- attrs:
40+
pos:
41+
line: 3
42+
col: 21
43+
value:
44+
Id: event_type
45+
distinct: false
46+
meta:
47+
project: Unspecified
48+
aggregate: true
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
source: src/tests/analysis.rs
3+
expression: "query.and_then(|q|\n{ session.run_static_analysis(q).map(|q| q.view(&session.arena)) })"
4+
---
5+
Ok:
6+
attrs:
7+
pos:
8+
line: 1
9+
col: 1
10+
sources:
11+
- binding:
12+
name: event_type
13+
pos:
14+
line: 1
15+
col: 6
16+
kind:
17+
Name: eventtypes
18+
predicate: ~
19+
group_by: ~
20+
order_by:
21+
expr:
22+
attrs:
23+
pos:
24+
line: 2
25+
col: 10
26+
value:
27+
Id: event_type
28+
order: Asc
29+
limit: ~
30+
projection:
31+
attrs:
32+
pos:
33+
line: 3
34+
col: 14
35+
value:
36+
Id: event_type
37+
distinct: false
38+
meta:
39+
project: String
40+
aggregate: false

src/typing/analysis.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ impl<'a> Analysis<'a> {
249249

250250
if let Some(group_by) = &query.group_by {
251251
let node = self.arena.exprs.get(group_by.expr);
252-
if !matches!(node.value, Value::Access(_)) {
252+
if !matches!(node.value, Value::Access(_) | Value::Id(_)) {
253253
return Err(AnalysisError::ExpectFieldLiteral(
254254
node.attrs.pos.line,
255255
node.attrs.pos.col,
@@ -258,7 +258,7 @@ impl<'a> Analysis<'a> {
258258

259259
self.analyze_expr(&mut ctx, group_by.expr, Type::Unspecified)?;
260260

261-
if let Some(expr) = group_by.predicate.as_ref().copied() {
261+
if let Some(expr) = group_by.predicate {
262262
ctx.allow_agg_func = true;
263263
ctx.use_agg_funcs = true;
264264

@@ -282,7 +282,7 @@ impl<'a> Analysis<'a> {
282282
if let Some(order_by) = &query.order_by {
283283
self.analyze_expr(&mut ctx, order_by.expr, Type::Unspecified)?;
284284
let node = self.arena.exprs.get(order_by.expr);
285-
if query.group_by.is_none() && !matches!(node.value, Value::Access(_)) {
285+
if query.group_by.is_none() && !matches!(node.value, Value::Access(_) | Value::Id(_)) {
286286
return Err(AnalysisError::ExpectFieldLiteral(
287287
node.attrs.pos.line,
288288
node.attrs.pos.col,

0 commit comments

Comments
 (0)