Skip to content

Commit 4dd86eb

Browse files
authored
Resolve parser conformance tests (initial PR) (#116)
* Resolve parser conformance tests (initial PR) The changes involve are: - Creation of Distinct keyword. - Creation of SetQuantifierStrategy for making statements with SetQuantifier parsable. - Fixes parsing of general function calls (excluding functions like substring for now). Conformance test report: https://paste.debian.net/1239858/
1 parent 559de71 commit 4dd86eb

File tree

3 files changed

+60
-12
lines changed

3 files changed

+60
-12
lines changed

partiql-ast/src/ast.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,12 +481,14 @@ pub struct Path {
481481
#[derive(Clone, Debug, PartialEq)]
482482
pub struct Call {
483483
pub func_name: SymbolPrimitive,
484+
pub setq: Option<SetQuantifier>,
484485
pub args: Vec<Box<Expr>>,
485486
}
486487

487488
#[derive(Clone, Debug, PartialEq)]
488489
pub struct CallAgg {
489490
pub func_name: SymbolPrimitive,
491+
pub setq: Option<SetQuantifier>,
490492
pub args: Vec<Box<Expr>>,
491493
}
492494

@@ -521,7 +523,6 @@ pub struct Coalesce {
521523

522524
#[derive(Clone, Debug, PartialEq)]
523525
pub struct Select {
524-
pub setq: Option<SetQuantifier>,
525526
pub project: ProjectionAst,
526527
pub from: Option<FromClauseAst>,
527528
pub from_let: Option<LetAst>,
@@ -565,9 +566,15 @@ pub enum CaseSensitivity {
565566
CaseInsensitive,
566567
}
567568

569+
#[derive(Clone, Debug, PartialEq)]
570+
pub struct Projection {
571+
pub kind: ProjectionKind,
572+
pub setq: Option<SetQuantifier>,
573+
}
574+
568575
/// Indicates the type of projection in a SFW query.
569576
#[derive(Clone, Debug, PartialEq)]
570-
pub enum Projection {
577+
pub enum ProjectionKind {
571578
ProjectStar,
572579
ProjectList(Vec<ProjectItemAst>),
573580
ProjectPivot { key: Box<Expr>, value: Box<Expr> },

partiql-parser/src/lexer.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,8 @@ pub enum Token<'input> {
514514
Cross,
515515
#[regex("(?i:Desc)")]
516516
Desc,
517+
#[regex("(?i:Distinct)")]
518+
Distinct,
517519
#[regex("(?i:Escape)")]
518520
Escape,
519521
#[regex("(?i:Except)")]
@@ -649,6 +651,7 @@ impl<'input> fmt::Display for Token<'input> {
649651
| Token::By
650652
| Token::Cross
651653
| Token::Desc
654+
| Token::Distinct
652655
| Token::Escape
653656
| Token::Except
654657
| Token::False

partiql-parser/src/parse/partiql.lalrpop

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ SfwClauses: ast::Select = {
4242
<limit:LimitClause?>
4343
<offset:OffsetByClause?> => {
4444
ast::Select {
45-
setq: None,
4645
project,
4746
from,
4847
from_let: None,
@@ -69,7 +68,6 @@ FwsClauses: ast::Select = {
6968
<offset:OffsetByClause?>
7069
<project:SelectClause> => {
7170
ast::Select {
72-
setq: None,
7371
project,
7472
from: Some(from),
7573
from_let: None,
@@ -93,12 +91,33 @@ WithClause: () = {}
9391
// SELECT //
9492
// ------------------------------------------------------------------------------ //
9593
SelectClause: ast::ProjectionAst = {
96-
<lo:@L> "SELECT" "*" <hi:@R> => ast::Projection::ProjectStar.ast(lo..hi),
97-
<lo:@L> "SELECT" <project_items:CommaSepPlus<Projection>> <hi:@R> => ast::Projection::ProjectList(project_items).ast(lo..hi),
98-
<lo:@L> "SELECT" "VALUE" <value:ExprQuery> <hi:@R> => ast::Projection::ProjectValue(value).ast(lo..hi),
99-
<lo:@L> "PIVOT" <value:ExprQuery> "AT" <key:ExprQuery> <hi:@R> => {
100-
ast::Projection::ProjectPivot { key, value }.ast(lo..hi)
101-
},
94+
<lo:@L> "SELECT" <strategy: SetQuantifierStrategy> "*" <hi:@R> => ast::Projection {
95+
kind: ast::ProjectionKind::ProjectStar,
96+
setq: Some(strategy)
97+
}.ast(lo..hi),
98+
<lo:@L> "SELECT" <strategy: SetQuantifierStrategy> <project_items:CommaSepPlus<Projection>> <hi:@R> => ast::Projection {
99+
kind: ast::ProjectionKind::ProjectList(project_items),
100+
setq: Some(strategy),
101+
}.ast(lo..hi),
102+
<lo:@L> "SELECT" <strategy: SetQuantifierStrategy> "VALUE" <value:ExprQuery> <hi:@R> => ast::Projection {
103+
kind: ast::ProjectionKind::ProjectValue(value),
104+
setq: Some(strategy),
105+
}.ast(lo..hi),
106+
<lo:@L> "PIVOT" <value:ExprQuery> "AT" <key:ExprQuery> <hi:@R> => ast::Projection {
107+
kind: ast::ProjectionKind::ProjectPivot { key, value },
108+
setq: None
109+
}.ast(lo..hi),
110+
}
111+
112+
#[inline]
113+
SetQuantifierStrategy: ast::SetQuantifier = {
114+
"ALL" => ast::SetQuantifier::All,
115+
<distinct: "DISTINCT"?> => {
116+
match distinct {
117+
Some(_) => ast::SetQuantifier::Distinct,
118+
None => ast::SetQuantifier::All,
119+
}
120+
}
102121
}
103122

104123
#[inline]
@@ -137,10 +156,12 @@ FromClause: ast::FromClauseAst = {
137156
.unwrap() // safe, because we know there's at least 1 input
138157
}
139158
}
159+
140160
TableReference: ast::FromClauseAst = {
141161
<TableNonJoin>,
142162
<TableJoined>,
143163
}
164+
144165
TableNonJoin: ast::FromClauseAst = {
145166
<lo:@L> <t:TableBaseReference> <hi:@R> => ast::FromClause::FromLet( t ).ast(lo..hi),
146167
<lo:@L> <t:TableUnpivot> <hi:@R> => ast::FromClause::FromLet( t ).ast(lo..hi),
@@ -669,8 +690,24 @@ ExprPair: ast::ExprPair = {
669690

670691
#[inline]
671692
FunctionCall: ast::Call = {
672-
<func_name:"Identifier"> "(" <args:CommaSepPlus<ExprQuery>> ")" =>
673-
ast::Call{ func_name: ast::SymbolPrimitive{ value: func_name.to_owned() }, args }
693+
<func_name:"Identifier"> "(" <strategy: SetQuantifierStrategy> ")" =>
694+
ast::Call {
695+
func_name: ast::SymbolPrimitive{ value: func_name.to_owned() },
696+
args: Vec::new(),
697+
setq: Some(strategy)
698+
},
699+
<func_name:"Identifier"> "(" <strategy: SetQuantifierStrategy> "*" ")" =>
700+
ast::Call {
701+
func_name: ast::SymbolPrimitive{ value: func_name.to_owned() },
702+
args: Vec::new(),
703+
setq: Some(strategy)
704+
},
705+
<func_name:"Identifier"> "(" <strategy: SetQuantifierStrategy> <args:CommaSepPlus<ExprQuery>> ")" =>
706+
ast::Call {
707+
func_name: ast::SymbolPrimitive{ value: func_name.to_owned() },
708+
args,
709+
setq: Some(strategy)
710+
},
674711
}
675712

676713
PathExpr: ast::Path = {
@@ -901,6 +938,7 @@ extern {
901938
"BY" => lexer::Token::By,
902939
"CROSS" => lexer::Token::Cross,
903940
"DESC" => lexer::Token::Desc,
941+
"DISTINCT" => lexer::Token::Distinct,
904942
"ESCAPE" => lexer::Token::Escape,
905943
"EXCEPT" => lexer::Token::Except,
906944
"FALSE" => lexer::Token::False,

0 commit comments

Comments
 (0)