Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

name = "eventql-parser"
version = "0.1.14"
version = "0.1.15"
authors = ["Yorick Laupa <yo.eight@gmail.com>"]
description = "EventQL Lexer and Parser"
homepage = "https://github.com/YoEight/eventql-parser"
Expand Down
24 changes: 24 additions & 0 deletions src/tests/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,3 +430,27 @@ fn test_accept_valid_having_clause() {
}))
});
}

#[test]
fn test_ids_in_order_by_should_pass() {
let mut session = Session::builder().use_stdlib().build();
let query = session.parse(include_str!("./resources/ids_in_order_by_should_pass.eql"));

insta::assert_yaml_snapshot!(query.and_then(|q| {
session
.run_static_analysis(q)
.map(|q| q.view(&session.arena))
}));
}

#[test]
fn test_ids_in_group_by_should_pass() {
let mut session = Session::builder().use_stdlib().build();
let query = session.parse(include_str!("./resources/ids_in_group_by_should_pass.eql"));

insta::assert_yaml_snapshot!(query.and_then(|q| {
session
.run_static_analysis(q)
.map(|q| q.view(&session.arena))
}));
}
3 changes: 3 additions & 0 deletions src/tests/resources/ids_in_group_by_should_pass.eql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM event_type IN eventtypes
GROUP BY event_type
PROJECT INTO unique(event_type)
3 changes: 3 additions & 0 deletions src/tests/resources/ids_in_order_by_should_pass.eql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM event_type IN eventtypes
ORDER BY event_type
PROJECT INTO event_type
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
source: src/tests/analysis.rs
expression: "query.and_then(|q|\n{ session.run_static_analysis(q).map(|q| q.view(&session.arena)) })"
---
Ok:
attrs:
pos:
line: 1
col: 1
sources:
- binding:
name: event_type
pos:
line: 1
col: 6
kind:
Name: eventtypes
predicate: ~
group_by:
expr:
attrs:
pos:
line: 2
col: 10
value:
Id: event_type
predicate: ~
order_by: ~
limit: ~
projection:
attrs:
pos:
line: 3
col: 14
value:
App:
func: unique
args:
- attrs:
pos:
line: 3
col: 21
value:
Id: event_type
distinct: false
meta:
project: Unspecified
aggregate: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
source: src/tests/analysis.rs
expression: "query.and_then(|q|\n{ session.run_static_analysis(q).map(|q| q.view(&session.arena)) })"
---
Ok:
attrs:
pos:
line: 1
col: 1
sources:
- binding:
name: event_type
pos:
line: 1
col: 6
kind:
Name: eventtypes
predicate: ~
group_by: ~
order_by:
expr:
attrs:
pos:
line: 2
col: 10
value:
Id: event_type
order: Asc
limit: ~
projection:
attrs:
pos:
line: 3
col: 14
value:
Id: event_type
distinct: false
meta:
project: String
aggregate: false
6 changes: 3 additions & 3 deletions src/typing/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ impl<'a> Analysis<'a> {

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

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

if let Some(expr) = group_by.predicate.as_ref().copied() {
if let Some(expr) = group_by.predicate {
ctx.allow_agg_func = true;
ctx.use_agg_funcs = true;

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