From 69fbc9fdd8e4c8da6743e90de409c65bee6e37d6 Mon Sep 17 00:00:00 2001 From: Lionel Sambuc Date: Sat, 25 Jul 2020 08:49:36 +0200 Subject: [PATCH] Set the volume in the parser for Filters When no volume is provided, create by default a volume containing the whole space. This simplifies handling later on, as there is no checks and on-the-fly generation of that value necessary. This also remove life time issues as the volume is always present with the same life time as the rest of the Filter. --- src/predictors.rs | 6 +----- src/queries.lalrpop | 22 +++++++++++++++++----- src/symbols.rs | 7 ++----- src/validators.rs | 5 +---- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/predictors.rs b/src/predictors.rs index fd99e44..e1d0109 100644 --- a/src/predictors.rs +++ b/src/predictors.rs @@ -1,4 +1,3 @@ -use mercator_db::space; use mercator_db::DataBase; use super::expressions::Predictor; @@ -18,10 +17,7 @@ impl Predictor for Bag { match self { Bag::ViewPort(bag) => bag.predict(db), Bag::Distinct(bag) => bag.predict(db), - Bag::Filter(_, bag) => match bag { - None => Ok(db.space(space::Space::universe().name())?.volume()), - Some(b) => b.predict(db), - }, + Bag::Filter(_, bag) => bag.predict(db), Bag::Complement(bag) => Ok(db.space(bag.space())?.volume() - bag.predict(db)?), Bag::Intersection(lh, rh) => { let l = lh.predict(db)?; diff --git a/src/queries.lalrpop b/src/queries.lalrpop index 1760688..0086a56 100644 --- a/src/queries.lalrpop +++ b/src/queries.lalrpop @@ -189,13 +189,25 @@ Union: symbols::Bag = { Filter: symbols::Bag = { // "filter" "(" "," ")" => "filter" "(" ")" => - symbols::Bag::Filter(None, Some(Box::new(b))), - "filter" "(" )?> ")" => + symbols::Bag::Filter(None, Box::new(b)), + "filter" "(" )?> ")" => { match b { - None => symbols::Bag::Filter(Some(p), None), - Some(b) => symbols::Bag::Filter(Some(p), Some(Box::new(b))), + None => { + let (low, high) = Space::universe().bounding_box(); + let low: Vec<_> = low.into(); + let high: Vec<_> = high.into(); + let shape = symbols::Shape::HyperRectangle( + Space::universe().name().clone(), + vec![ + symbols::LiteralPosition(low.into_iter().map(symbols::LiteralNumber::Float).collect()), + symbols::LiteralPosition(high.into_iter().map(symbols::LiteralNumber::Float).collect()), + ], + ); + symbols::Bag::Filter(Some(p), Box::new(symbols::Bag::Inside(shape))) + } + Some(b) => symbols::Bag::Filter(Some(p), Box::new(b)), } - + }, }; Predicates: symbols::Predicate = { diff --git a/src/symbols.rs b/src/symbols.rs index 33be326..bb8d7bd 100644 --- a/src/symbols.rs +++ b/src/symbols.rs @@ -61,7 +61,7 @@ pub enum Bag { ViewPort(Box), // Bags Distinct(Box), - Filter(Option, Option>), + Filter(Option, Box), Complement(Box), Intersection(Box, Box), Union(Box, Box), @@ -77,10 +77,7 @@ impl Bag { match self { Bag::ViewPort(bag) => bag.space(), Bag::Distinct(bag) => bag.space(), - Bag::Filter(_, bag) => match bag { - None => space::Space::universe().name(), - Some(b) => b.space(), - }, + Bag::Filter(_, bag) => bag.space(), Bag::Complement(bag) => bag.space(), Bag::Intersection(lh, _) => { // We are assuming lh and rh are in the same space. diff --git a/src/validators.rs b/src/validators.rs index 4c8f265..5787891 100644 --- a/src/validators.rs +++ b/src/validators.rs @@ -56,10 +56,7 @@ impl Validator for Bag { match self { Bag::ViewPort(bag) => bag.validate(), Bag::Distinct(bag) => bag.validate(), - Bag::Filter(_, bag) => match bag { - None => Ok(LiteralPosition(vec![]).get_type()), - Some(b) => b.validate(), - }, + Bag::Filter(_, bag) => bag.validate(), Bag::Complement(bag) => bag.validate(), Bag::Intersection(lh, rh) => compare_bag_types(lh, rh), Bag::Union(lh, rh) => compare_bag_types(lh, rh),