public static TupleFilter convertFilterColumnsAndConstants(TupleFilter rootFilter, GTInfo info, // Map<TblColRef, Integer> colMapping, Set<TblColRef> unevaluatableColumnCollector) { TupleFilter filter = convertFilter(rootFilter, info, colMapping, true, unevaluatableColumnCollector); // optimize the filter: after translating with dictionary, some filters become determined // e.g. // ( a = 'value_in_dict' OR a = 'value_not_in_dict') will become (a = 'value_in_dict' OR ConstantTupleFilter.FALSE) // use the following to further trim the filter to (a = 'value_in_dict') // The goal is to avoid too many children after flatten filter step filter = new FilterOptimizeTransformer().transform(filter); return filter; }
@Override public TupleFilter acceptOptimizeTransformer(FilterOptimizeTransformer transformer) { return transformer.visit(this); }
void translateFilter(OLAPContext context) { if (this.condition == null) { return; } TupleFilterVisitor visitor = new TupleFilterVisitor(this.columnRowType); TupleFilter filter = this.condition.accept(visitor); // optimize the filter, the optimization has to be segment-irrelevant filter = new FilterOptimizeTransformer().transform(filter); Set<TblColRef> filterColumns = Sets.newHashSet(); TupleFilter.collectColumns(filter, filterColumns); for (TblColRef tblColRef : filterColumns) { if (!tblColRef.isInnerColumn() && context.belongToContextTables(tblColRef)) { context.allColumns.add(tblColRef); context.filterColumns.add(tblColRef); } } context.filter = and(context.filter, filter); }
@Override public TupleFilter acceptOptimizeTransformer(FilterOptimizeTransformer transformer) { List<TupleFilter> newChildren = Lists.newArrayList(); for (TupleFilter child : this.getChildren()) { if (child instanceof IOptimizeableTupleFilter) { newChildren.add(((IOptimizeableTupleFilter) child).acceptOptimizeTransformer(transformer)); } else { newChildren.add(child); } } this.reinitWithChildren(newChildren); return transformer.visit(this); }
whenFilter = new FilterOptimizeTransformer().transform(whenFilter);
@Override public TupleFilter acceptOptimizeTransformer(FilterOptimizeTransformer transformer) { List<TupleFilter> newChildren = Lists.newArrayList(); for (TupleFilter child : this.getChildren()) { if (child instanceof IOptimizeableTupleFilter) { newChildren.add(((IOptimizeableTupleFilter) child).acceptOptimizeTransformer(transformer)); } else { newChildren.add(child); } } this.reinit(); this.addChildren(newChildren); return transformer.visit(this); }
@Test public void transformTest4() throws Exception { TupleFilter or = new LogicalTupleFilter(TupleFilter.FilterOperatorEnum.AND); TupleFilter a = ConstantTupleFilter.FALSE; TupleFilter b = ConstantTupleFilter.FALSE; or.addChild(a); or.addChild(b); or = new FilterOptimizeTransformer().transform(or); Assert.assertEquals(ConstantTupleFilter.FALSE, or); }
@Override public TupleFilter acceptOptimizeTransformer(FilterOptimizeTransformer transformer) { return transformer.visit(this); }
@Test public void transformTest5() throws Exception { TupleFilter or = new LogicalTupleFilter(TupleFilter.FilterOperatorEnum.AND); TupleFilter a = ConstantTupleFilter.TRUE; TupleFilter b = ConstantTupleFilter.TRUE; or.addChild(a); or.addChild(b); or = new FilterOptimizeTransformer().transform(or); Assert.assertEquals(ConstantTupleFilter.TRUE, or); }
@Override public TupleFilter acceptOptimizeTransformer(FilterOptimizeTransformer transformer) { List<TupleFilter> newChildren = Lists.newArrayList(); for (TupleFilter child : this.getChildren()) { if (child instanceof IOptimizeableTupleFilter) { newChildren.add(((IOptimizeableTupleFilter) child).acceptOptimizeTransformer(transformer)); } else { newChildren.add(child); } } this.reinitWithChildren(newChildren); return transformer.visit(this); }
@Test public void transformTest3() throws Exception { TupleFilter or = new LogicalTupleFilter(TupleFilter.FilterOperatorEnum.OR); TupleFilter a = ConstantTupleFilter.TRUE; TupleFilter b = ConstantTupleFilter.TRUE; or.addChild(a); or.addChild(b); or = new FilterOptimizeTransformer().transform(or); Assert.assertEquals(ConstantTupleFilter.TRUE, or); }
@Override public TupleFilter acceptOptimizeTransformer(FilterOptimizeTransformer transformer) { List<TupleFilter> newChildren = Lists.newArrayList(); for (TupleFilter child : this.getChildren()) { if (child instanceof IOptimizeableTupleFilter) { newChildren.add(((IOptimizeableTupleFilter) child).acceptOptimizeTransformer(transformer)); } else { newChildren.add(child); } } this.reinit(); this.addChildren(newChildren); return transformer.visit(this); }
@Test public void transformTest7() throws Exception { TupleFilter or = new LogicalTupleFilter(TupleFilter.FilterOperatorEnum.OR); TupleFilter a = ConstantTupleFilter.FALSE; TupleFilter b = ConstantTupleFilter.TRUE; or.addChild(a); or.addChild(b); or = new FilterOptimizeTransformer().transform(or); Assert.assertEquals(ConstantTupleFilter.TRUE, or); } }
@Test public void transformTest2() throws Exception { TupleFilter or = new LogicalTupleFilter(TupleFilter.FilterOperatorEnum.OR); TupleFilter a = ConstantTupleFilter.FALSE; TupleFilter b = ConstantTupleFilter.FALSE; or.addChild(a); or.addChild(b); or = new FilterOptimizeTransformer().transform(or); Assert.assertEquals(ConstantTupleFilter.FALSE, or); }
@Test public void transformTest6() throws Exception { TupleFilter or = new LogicalTupleFilter(TupleFilter.FilterOperatorEnum.AND); TupleFilter a = ConstantTupleFilter.FALSE; TupleFilter b = ConstantTupleFilter.TRUE; or.addChild(a); or.addChild(b); or = new FilterOptimizeTransformer().transform(or); Assert.assertEquals(ConstantTupleFilter.FALSE, or); }
@Test public void transformTest0() throws Exception { TupleFilter or = new LogicalTupleFilter(TupleFilter.FilterOperatorEnum.AND); TupleFilter a = new CompareTupleFilter(TupleFilter.FilterOperatorEnum.EQ); TupleFilter b = ConstantTupleFilter.TRUE; or.addChild(a); or.addChild(b); or = new FilterOptimizeTransformer().transform(or); Assert.assertEquals(1, or.children.size()); }
@Test public void transformTest1() throws Exception { TupleFilter or = new LogicalTupleFilter(TupleFilter.FilterOperatorEnum.OR); TupleFilter a = new CompareTupleFilter(TupleFilter.FilterOperatorEnum.EQ); TupleFilter b = ConstantTupleFilter.FALSE; or.addChild(a); or.addChild(b); or = new FilterOptimizeTransformer().transform(or); Assert.assertEquals(1, or.children.size()); }
public static TupleFilter convertFilterColumnsAndConstants(TupleFilter rootFilter, GTInfo info, // Map<TblColRef, Integer> colMapping, Set<TblColRef> unevaluatableColumnCollector) { TupleFilter filter = convertFilter(rootFilter, info, colMapping, true, unevaluatableColumnCollector); // optimize the filter: after translating with dictionary, some filters become determined // e.g. // ( a = 'value_in_dict' OR a = 'value_not_in_dict') will become (a = 'value_in_dict' OR ConstantTupleFilter.FALSE) // use the following to further trim the filter to (a = 'value_in_dict') // The goal is to avoid too many children after flatten filter step filter = new FilterOptimizeTransformer().transform(filter); return filter; }
void translateFilter(OLAPContext context) { if (this.condition == null) { return; } TupleFilterVisitor visitor = new TupleFilterVisitor(this.columnRowType); TupleFilter filter = this.condition.accept(visitor); // optimize the filter, the optimization has to be segment-irrelevant filter = new FilterOptimizeTransformer().transform(filter); Set<TblColRef> filterColumns = Sets.newHashSet(); TupleFilter.collectColumns(filter, filterColumns); for (TblColRef tblColRef : filterColumns) { if (!tblColRef.isInnerColumn() && context.belongToContextTables(tblColRef)) { context.allColumns.add(tblColRef); context.filterColumns.add(tblColRef); } } context.filter = and(context.filter, filter); }
whenFilter = new FilterOptimizeTransformer().transform(whenFilter);