Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements OUTER bag operators #400

Merged
merged 8 commits into from
Jul 12, 2023
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
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- *BREAKING:* partiql-logical-planner: moves `NameResolver` to `partiql-ast-passes`
- *BREAKING:* partiql-values: removes `partiql` from value macro_rules; e.g. `partiql_bag` renames to `bag`.
- *BREAKING:* partiql-ast: changed modeling of `Query` and `SetExpr` nodes to support `ORDER BY`, `LIMIT`, `OFFSET` in children of set operators
- Also affects the `Visitor` trait
- Affects the AST and visitor
- *BREAKING:* partiql-ast: rename of `SetExpr` to `BagOpExpr` and `SetOp` to `BagOp`
- Affects the AST and visitor
- *BREAKING:* partiql-parser: `Parsed` struct's `ast` field is now an `ast::AstNode<ast::TopLevelQuery>`
- *BREAKING:* partiql-eval: `Evaluable` trait's `update_input` fn now also takes in an `EvalContext`

### Added
- Add ability for partiql-extension-ion extension encoding/decoding of `Value` to/from Ion `Element`
- Add `partiql-types` crate that includes data models for PartiQL Types.
- Add `partiql_ast_passes::static_typer` for type annotating the AST.
- Add ability to parse `ORDER BY`, `LIMIT`, `OFFSET` in children of set operators
- Add `OUTER` bag operator (`OUTER UNION`, `OUTER INTERSECT`, `OUTER EXCEPT`) implementation

### Fixes
- Fixes parsing of multiple consecutive path wildcards (e.g. `a[*][*][*]`), unpivot (e.g. `a.*.*.*`), and path expressions (e.g. `a[1 + 2][3 + 4][5 + 6]`)—previously these would not parse correctly.
- partiql-parser set quantifier for bag operators fixed to `DISTINCT`
- partiql-parser set quantifier for bag operators fixed to be `DISTINCT` when unspecified

## [0.5.0] - 2023-06-06
### Changed
Expand Down
2 changes: 1 addition & 1 deletion partiql-ast-passes/src/name_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub struct NameResolver {
impl NameResolver {
pub fn resolve(
&mut self,
query: &ast::AstNode<ast::Query>,
query: &ast::AstNode<ast::TopLevelQuery>,
) -> Result<KeyRegistry, AstTransformationError> {
query.visit(self);
if !self.errors.is_empty() {
Expand Down
14 changes: 5 additions & 9 deletions partiql-ast-passes/src/partiql_typer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::error::{AstTransformError, AstTransformationError};
use partiql_ast::ast::{
AstNode, AstTypeMap, Bag, Expr, List, Lit, NodeId, Query, QuerySet, Struct,
AstNode, AstTypeMap, Bag, Expr, List, Lit, NodeId, Query, QuerySet, Struct, TopLevelQuery,
};
use partiql_ast::visit::{Traverse, Visit, Visitor};
use partiql_catalog::Catalog;
Expand Down Expand Up @@ -29,7 +29,7 @@ impl<'c> AstPartiqlTyper<'c> {

pub fn type_nodes(
mut self,
query: &AstNode<Query>,
query: &AstNode<TopLevelQuery>,
) -> Result<AstTypeMap<PartiqlType>, AstTransformationError> {
query.visit(&mut self);
if self.errors.is_empty() {
Expand Down Expand Up @@ -68,7 +68,7 @@ impl<'c, 'ast> Visitor<'ast> for AstPartiqlTyper<'c> {

fn enter_query_set(&mut self, _query_set: &'ast QuerySet) -> Traverse {
match _query_set {
QuerySet::SetOp(_) => {
QuerySet::BagOp(_) => {
todo!()
}
QuerySet::Select(_) => {}
Expand Down Expand Up @@ -220,7 +220,6 @@ impl<'c, 'ast> Visitor<'ast> for AstPartiqlTyper<'c> {
mod tests {
use super::*;
use assert_matches::assert_matches;
use partiql_ast::ast;
use partiql_catalog::PartiqlCatalog;
use partiql_types::{PartiqlType, TypeKind};

Expand Down Expand Up @@ -262,10 +261,7 @@ mod tests {
.expect("Expect successful parse");

let typer = AstPartiqlTyper::new(catalog);
if let ast::Expr::Query(q) = parsed.ast.as_ref() {
typer.type_nodes(q)
} else {
panic!("Typing statement other than `Query` are unsupported")
}
let q = &parsed.ast;
typer.type_nodes(q)
}
}
8 changes: 4 additions & 4 deletions partiql-ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ pub struct WithElement {
#[derive(Visit, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum QuerySet {
SetOp(Box<AstNode<SetExpr>>),
BagOp(Box<AstNode<BagOpExpr>>),
Select(Box<AstNode<Select>>),
Expr(Box<Expr>),
Values(Vec<Box<Expr>>),
Expand All @@ -279,9 +279,9 @@ pub enum QuerySet {

#[derive(Visit, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct SetExpr {
pub struct BagOpExpr {
#[visit(skip)]
pub setop: SetOperator,
pub bag_op: BagOperator,
#[visit(skip)]
pub setq: SetQuantifier,
pub lhs: Box<AstNode<Query>>,
Expand All @@ -290,7 +290,7 @@ pub struct SetExpr {

#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum SetOperator {
pub enum BagOperator {
Union,
Except,
Intersect,
Expand Down
4 changes: 2 additions & 2 deletions partiql-ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,10 @@ pub trait Visitor<'ast> {
fn exit_query_set(&mut self, _query_set: &'ast ast::QuerySet) -> Traverse {
Traverse::Continue
}
fn enter_set_expr(&mut self, _set_expr: &'ast ast::SetExpr) -> Traverse {
fn enter_bag_op_expr(&mut self, _set_expr: &'ast ast::BagOpExpr) -> Traverse {
Traverse::Continue
}
fn exit_set_expr(&mut self, _set_expr: &'ast ast::SetExpr) -> Traverse {
fn exit_bag_op_expr(&mut self, _set_expr: &'ast ast::BagOpExpr) -> Traverse {
Traverse::Continue
}
fn enter_select(&mut self, _select: &'ast ast::Select) -> Traverse {
Expand Down
2 changes: 1 addition & 1 deletion partiql-eval/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl Evaluable for ErrorNode {
panic!("ErrorNode will not be evaluated")
}

fn update_input(&mut self, _input: Value, _branch_num: u8) {
fn update_input(&mut self, _input: Value, _branch_num: u8, _ctx: &dyn EvalContext) {
panic!("ErrorNode will not be evaluated")
}
}
Expand Down
Loading