@Test public void testMergeToInClause1() { TupleFilter originFilter = getMockFilter1(); TupleFilter resultFilter = TupleFilterVisitor.mergeToInClause(originFilter); Assert.assertNotNull(resultFilter); Assert.assertEquals(2, resultFilter.getChildren().size()); }
@VisibleForTesting static TupleFilter mergeToInClause(TupleFilter filter) { List<? extends TupleFilter> children = filter.getChildren(); if (children.isEmpty()) { return filter; } Map<TblColRef, Pair<Set<Object>, Map<String, Object>>> inColumnMap = Maps.newHashMap(); List<TupleFilter> extraFilters = Lists.newLinkedList(); for (TupleFilter child : children) { if (child.getOperator() == TupleFilter.FilterOperatorEnum.EQ) { CompareTupleFilter compFilter = (CompareTupleFilter) child; TblColRef column = compFilter.getColumn(); if (column != null) { Pair<Set<Object>, Map<String, Object>> tmpValue = inColumnMap.get(column); if (tmpValue == null) { Set<Object> inValues = Sets.newHashSet(); Map<String, Object> dynamicVariables = Maps.newHashMap(); tmpValue = new Pair<>(inValues, dynamicVariables); inColumnMap.put(column, tmpValue); } tmpValue.getFirst().addAll(compFilter.getValues()); tmpValue.getSecond().putAll(compFilter.getVariables()); continue; } } extraFilters.add(child); } children.clear(); TupleFilter ret = new LogicalTupleFilter(TupleFilter.FilterOperatorEnum.OR); ret.addChildren(extraFilters); for (Map.Entry<TblColRef, Pair<Set<Object>, Map<String, Object>>> entry : inColumnMap.entrySet()) { CompareTupleFilter inFilter = new CompareTupleFilter(TupleFilter.FilterOperatorEnum.IN); inFilter.addChild(new ColumnTupleFilter(entry.getKey())); inFilter.addChild(new ConstantTupleFilter(entry.getValue().getFirst())); inFilter.getVariables().putAll(entry.getValue().getSecond()); ret.addChild(inFilter); } return ret.getChildren().size() == 1 ? ret.getChildren().get(0) : ret; }
TupleFilterVisitor extends RexVisitorImpl<TupleFilter> { @VisibleForTesting static TupleFilter mergeToInClause(TupleFilter filter) { List<? extends TupleFilter> children = filter.getChildren(); if (children.isEmpty()) { return filter; } Map<TblColRef, Pair<Set<Object>, Map<String, Object>>> inColumnMap = Maps.newHashMap(); List<TupleFilter> extraFilters = Lists.newLinkedList(); for (TupleFilter child : children) { if (child.getOperator() == TupleFilter.FilterOperatorEnum.EQ) { CompareTupleFilter compFilter = (CompareTupleFilter) child; TblColRef column = compFilter.getColumn(); if (column != null) { Pair<Set<Object>, Map<String, Object>> tmpValue = inColumnMap.get(column); if (tmpValue == null) { Set<Object> inValues = Sets.newHashSet(); Map<String, Object> dynamicVariables = Maps.newHashMap(); tmpValue = new Pair<>(inValues, dynamicVariables); inColumnMap.put(column, tmpValue); } tmpValue.getFirst().addAll(compFilter.getValues()); tmpValue.getSecond().putAll(compFilter.getVariables()); continue; } } extraFilters.add(child); } children.clear(); TupleFilter ret = new LogicalTupleFilter(TupleFilter.FilterOperatorEnum.OR); ret.addChildren(extraFilters); for (Map.Entry<TblColRef, Pair<Set<Object>, Map<String, Object>>> entry : inColumnMap.entrySet()) { CompareTupleFilter inFilter = new CompareTupleFilter(TupleFilter.FilterOperatorEnum.IN); inFilter.addChild(new ColumnTupleFilter(entry.getKey())); inFilter.addChild(new ConstantTupleFilter(entry.getValue().getFirst())); inFilter.getVariables().putAll(entry.getValue().getSecond()); ret.addChild(inFilter); } return ret.getChildren().size() == 1 ? ret.getChildren().get(0) : ret; } }
TupleFilterVisitor extends RexVisitorImpl<TupleFilter> { @VisibleForTesting static TupleFilter mergeToInClause(TupleFilter filter) { List<? extends TupleFilter> children = filter.getChildren(); if (children.isEmpty()) { return filter; } Map<TblColRef, Pair<Set<Object>, Map<String, Object>>> inColumnMap = Maps.newHashMap(); List<TupleFilter> extraFilters = Lists.newLinkedList(); for (TupleFilter child : children) { if (child.getOperator() == TupleFilter.FilterOperatorEnum.EQ) { CompareTupleFilter compFilter = (CompareTupleFilter) child; TblColRef column = compFilter.getColumn(); if (column != null) { Pair<Set<Object>, Map<String, Object>> tmpValue = inColumnMap.get(column); if (tmpValue == null) { Set<Object> inValues = Sets.newHashSet(); Map<String, Object> dynamicVariables = Maps.newHashMap(); tmpValue = new Pair<>(inValues, dynamicVariables); inColumnMap.put(column, tmpValue); } tmpValue.getFirst().addAll(compFilter.getValues()); tmpValue.getSecond().putAll(compFilter.getVariables()); continue; } } extraFilters.add(child); } children.clear(); TupleFilter ret = new LogicalTupleFilter(TupleFilter.FilterOperatorEnum.OR); ret.addChildren(extraFilters); for (Map.Entry<TblColRef, Pair<Set<Object>, Map<String, Object>>> entry : inColumnMap.entrySet()) { CompareTupleFilter inFilter = new CompareTupleFilter(TupleFilter.FilterOperatorEnum.IN); inFilter.addChild(new ColumnTupleFilter(entry.getKey())); inFilter.addChild(new ConstantTupleFilter(entry.getValue().getFirst())); inFilter.getVariables().putAll(entry.getValue().getSecond()); ret.addChild(inFilter); } return ret.getChildren().size() == 1 ? ret.getChildren().get(0) : ret; } TupleFilterVisitor(ColumnRowType inputRowType); }
TupleFilterVisitor extends RexVisitorImpl<TupleFilter> { @VisibleForTesting static TupleFilter mergeToInClause(TupleFilter filter) { List<? extends TupleFilter> children = filter.getChildren(); if (children.isEmpty()) { return filter; } Map<TblColRef, Pair<Set<Object>, Map<String, Object>>> inColumnMap = Maps.newHashMap(); List<TupleFilter> extraFilters = Lists.newLinkedList(); for (TupleFilter child : children) { if (child.getOperator() == TupleFilter.FilterOperatorEnum.EQ) { CompareTupleFilter compFilter = (CompareTupleFilter) child; TblColRef column = compFilter.getColumn(); if (column != null) { Pair<Set<Object>, Map<String, Object>> tmpValue = inColumnMap.get(column); if (tmpValue == null) { Set<Object> inValues = Sets.newHashSet(); Map<String, Object> dynamicVariables = Maps.newHashMap(); tmpValue = new Pair<>(inValues, dynamicVariables); inColumnMap.put(column, tmpValue); } tmpValue.getFirst().addAll(compFilter.getValues()); tmpValue.getSecond().putAll(compFilter.getVariables()); continue; } } extraFilters.add(child); } children.clear(); TupleFilter ret = new LogicalTupleFilter(TupleFilter.FilterOperatorEnum.OR); ret.addChildren(extraFilters); for (Map.Entry<TblColRef, Pair<Set<Object>, Map<String, Object>>> entry : inColumnMap.entrySet()) { CompareTupleFilter inFilter = new CompareTupleFilter(TupleFilter.FilterOperatorEnum.IN); inFilter.addChild(new ColumnTupleFilter(entry.getKey())); inFilter.addChild(new ConstantTupleFilter(entry.getValue().getFirst())); inFilter.getVariables().putAll(entry.getValue().getSecond()); ret.addChild(inFilter); } return ret.getChildren().size() == 1 ? ret.getChildren().get(0) : ret; } TupleFilterVisitor(ColumnRowType inputRowType); @Override TupleFilter visitCall(RexCall call); @Override TupleFilter visitLocalRef(RexLocalRef localRef); @Override TupleFilter visitInputRef(RexInputRef inputRef); @Override TupleFilter visitLiteral(RexLiteral literal); @Override TupleFilter visitDynamicParam(RexDynamicParam dynamicParam); void setAutoJustByTimezone(boolean autoJustByTimezone); }
TupleFilterVisitor extends RexVisitorImpl<TupleFilter> { @VisibleForTesting static TupleFilter mergeToInClause(TupleFilter filter) { List<? extends TupleFilter> children = filter.getChildren(); if (children.isEmpty()) { return filter; } Map<TblColRef, Pair<Set<Object>, Map<String, Object>>> inColumnMap = Maps.newHashMap(); List<TupleFilter> extraFilters = Lists.newLinkedList(); for (TupleFilter child : children) { if (child.getOperator() == TupleFilter.FilterOperatorEnum.EQ) { CompareTupleFilter compFilter = (CompareTupleFilter) child; TblColRef column = compFilter.getColumn(); if (column != null) { Pair<Set<Object>, Map<String, Object>> tmpValue = inColumnMap.get(column); if (tmpValue == null) { Set<Object> inValues = Sets.newHashSet(); Map<String, Object> dynamicVariables = Maps.newHashMap(); tmpValue = new Pair<>(inValues, dynamicVariables); inColumnMap.put(column, tmpValue); } tmpValue.getFirst().addAll(compFilter.getValues()); tmpValue.getSecond().putAll(compFilter.getVariables()); continue; } } extraFilters.add(child); } children.clear(); TupleFilter ret = new LogicalTupleFilter(TupleFilter.FilterOperatorEnum.OR); ret.addChildren(extraFilters); for (Map.Entry<TblColRef, Pair<Set<Object>, Map<String, Object>>> entry : inColumnMap.entrySet()) { CompareTupleFilter inFilter = new CompareTupleFilter(TupleFilter.FilterOperatorEnum.IN); inFilter.addChild(new ColumnTupleFilter(entry.getKey())); inFilter.addChild(new ConstantTupleFilter(entry.getValue().getFirst())); inFilter.getVariables().putAll(entry.getValue().getSecond()); ret.addChild(inFilter); } return ret.getChildren().size() == 1 ? ret.getChildren().get(0) : ret; } TupleFilterVisitor(ColumnRowType inputRowType); @Override TupleFilter visitCall(RexCall call); @Override TupleFilter visitLocalRef(RexLocalRef localRef); @Override TupleFilter visitInputRef(RexInputRef inputRef); @Override TupleFilter visitLiteral(RexLiteral literal); @Override TupleFilter visitDynamicParam(RexDynamicParam dynamicParam); void setAutoJustByTimezone(boolean autoJustByTimezone);  }