diff --git a/zion/src/main/scala/edu/uci/ics/cloudberry/zion/model/impl/QueryPlanner.scala b/zion/src/main/scala/edu/uci/ics/cloudberry/zion/model/impl/QueryPlanner.scala index f4908ff14..93c69cf98 100644 --- a/zion/src/main/scala/edu/uci/ics/cloudberry/zion/model/impl/QueryPlanner.scala +++ b/zion/src/main/scala/edu/uci/ics/cloudberry/zion/model/impl/QueryPlanner.scala @@ -56,7 +56,9 @@ class QueryPlanner { //TODO if select project fields from groupby results, postpone the project to the merge stage. //TODO here is a very simple assumption that the schema is the same, what if the schema are different? - seqBuilder += query.copy(dataset = view.name) + val viewFilters = view.createQueryOpt.get.filter + val newFilter = query.filter.filterNot(qf => viewFilters.exists(vf => qf.covers(vf, source.schema.fieldMap(qf.fieldName).dataType))) + seqBuilder += query.copy(dataset = view.name, filter = newFilter) for (interval <- unCovered) { seqBuilder += query.setInterval(source.schema.timeField, interval) } diff --git a/zion/src/test/scala/edu/uci/ics/cloudberry/zion/model/impl/QueryPlannerTest.scala b/zion/src/test/scala/edu/uci/ics/cloudberry/zion/model/impl/QueryPlannerTest.scala index 42ddd35b0..94787fec5 100644 --- a/zion/src/test/scala/edu/uci/ics/cloudberry/zion/model/impl/QueryPlannerTest.scala +++ b/zion/src/test/scala/edu/uci/ics/cloudberry/zion/model/impl/QueryPlannerTest.scala @@ -47,6 +47,12 @@ class QueryPlannerTest extends Specification { queries.size must_== 1 queries.head must_== queryCount.copy(dataset = zikaFullYearViewInfo.name) } + "makePlan should omit the redundant filter from query if it covers view.createQuery" in { + val queryZika = Query(dataset = TwitterDataSet, filter = Seq(FilterStatement("text", None, Relation.contains, Seq("zika"))), groups = Some(group)) + val (queries, _) = planner.makePlan(queryZika, sourceInfo, Seq(zikaFullYearViewInfo)) + queries.size must_== 1 + queries.head must_== Query(dataset = zikaFullYearViewInfo.name, groups = Some(group)) + } "makePlan should ask the view and the source if view can not cover the query" in { val (queries, _) = planner.makePlan(queryCount, sourceInfo, Seq(zikaHalfYearViewInfo)) queries.size must_== 2