@Override public Logic visitPatternFieldRef(RexPatternFieldRef ref, Logic arg) { return end(ref, arg); } }
/** Finds a suitable logic for evaluating {@code seek} within a list of * expressions. * * <p>Chooses a logic that is safe (that is, gives the right * answer) with the fewest possibilities (that is, we prefer one that * returns [true as true, false as false, unknown as false] over one that * distinguishes false from unknown). */ public static Logic find(Logic logic, List<RexNode> nodes, RexNode seek) { final Set<Logic> set = EnumSet.noneOf(Logic.class); final LogicVisitor visitor = new LogicVisitor(seek, set); for (RexNode node : nodes) { node.accept(visitor, logic); } // Convert FALSE (which can only exist within LogicVisitor) to // UNKNOWN_AS_TRUE. if (set.remove(Logic.FALSE)) { set.add(Logic.UNKNOWN_AS_TRUE); } switch (set.size()) { case 0: throw new IllegalArgumentException("not found: " + seek); case 1: return Iterables.getOnlyElement(set); default: return Logic.TRUE_FALSE_UNKNOWN; } }
private Logic deduceLogic(RexNode root, RexNode seek, Logic logic) { final List<Logic> list = new ArrayList<>(); LogicVisitor.collect(root, seek, logic, list); assertThat(list.size(), is(1)); return list.get(0); } }
/** Finds a suitable logic for evaluating {@code seek} within a list of * expressions. * * <p>Chooses a logic that is safe (that is, gives the right * answer) with the fewest possibilities (that is, we prefer one that * returns [true as true, false as false, unknown as false] over one that * distinguishes false from unknown). */ public static Logic find(Logic logic, List<RexNode> nodes, RexNode seek) { final Set<Logic> set = EnumSet.noneOf(Logic.class); final LogicVisitor visitor = new LogicVisitor(seek, set); for (RexNode node : nodes) { node.accept(visitor, logic); } // Convert FALSE (which can only exist within LogicVisitor) to // UNKNOWN_AS_TRUE. if (set.remove(Logic.FALSE)) { set.add(Logic.UNKNOWN_AS_TRUE); } switch (set.size()) { case 0: throw new IllegalArgumentException("not found: " + seek); case 1: return Iterables.getOnlyElement(set); default: return Logic.TRUE_FALSE_UNKNOWN; } }
private Logic deduceLogic(RexNode root, RexNode seek, Logic logic) { final List<Logic> list = new ArrayList<>(); LogicVisitor.collect(root, seek, logic, list); assertThat(list.size(), is(1)); return list.get(0); } }
public void onMatch(RelOptRuleCall call) { final Filter filter = call.rel(0); //final RelBuilder builder = call.builder(); //TODO: replace HiveSubQRemoveRelBuilder with calcite's once calcite 1.11.0 is released final HiveSubQRemoveRelBuilder builder = new HiveSubQRemoveRelBuilder(null, call.rel(0).getCluster(), null); final RexSubQuery e = RexUtil.SubQueryFinder.find(filter.getCondition()); assert e != null; final RelOptUtil.Logic logic = LogicVisitor.find(RelOptUtil.Logic.TRUE, ImmutableList.of(filter.getCondition()), e); builder.push(filter.getInput()); final int fieldCount = builder.peek().getRowType().getFieldCount(); assert(filter instanceof HiveFilter); Set<RelNode> corrScalarQueries = filter.getCluster().getPlanner().getContext().unwrap(Set.class); boolean isCorrScalarQuery = corrScalarQueries.contains(e.rel); final RexNode target = apply(e, HiveFilter.getVariablesSet(e), logic, builder, 1, fieldCount, isCorrScalarQuery); final RexShuttle shuttle = new ReplaceSubQueryShuttle(e, target); builder.filter(shuttle.apply(filter.getCondition())); builder.project(fields(builder, filter.getRowType().getFieldCount())); call.transformTo(builder.build()); } };
public Logic visitCorrelVariable(RexCorrelVariable correlVariable, Logic arg) { return end(correlVariable, arg); }
public static void collect(RexNode node, RexNode seek, Logic logic, List<Logic> logicList) { node.accept(new LogicVisitor(seek, logicList), logic); // Convert FALSE (which can only exist within LogicVisitor) to // UNKNOWN_AS_TRUE. Collections.replaceAll(logicList, Logic.FALSE, Logic.UNKNOWN_AS_TRUE); }
public void onMatch(RelOptRuleCall call) { final Project project = call.rel(0); //TODO: replace HiveSubQRemoveRelBuilder with calcite's once calcite 1.11.0 is released final HiveSubQRemoveRelBuilder builder = new HiveSubQRemoveRelBuilder(null, call.rel(0).getCluster(), null); final RexSubQuery e = RexUtil.SubQueryFinder.find(project.getProjects()); assert e != null; final RelOptUtil.Logic logic = LogicVisitor.find(RelOptUtil.Logic.TRUE_FALSE_UNKNOWN, project.getProjects(), e); builder.push(project.getInput()); final int fieldCount = builder.peek().getRowType().getFieldCount(); final RexNode target = apply(e, HiveFilter.getVariablesSet(e), logic, builder, 1, fieldCount, false); final RexShuttle shuttle = new ReplaceSubQueryShuttle(e, target); builder.project(shuttle.apply(project.getProjects()), project.getRowType().getFieldNames()); call.transformTo(builder.build()); } };
@Override public Logic visitPatternFieldRef(RexPatternFieldRef ref, Logic arg) { return end(ref, arg); } }
public static void collect(RexNode node, RexNode seek, Logic logic, List<Logic> logicList) { node.accept(new LogicVisitor(seek, logicList), logic); // Convert FALSE (which can only exist within LogicVisitor) to // UNKNOWN_AS_TRUE. Collections.replaceAll(logicList, Logic.FALSE, Logic.UNKNOWN_AS_TRUE); }
public void onMatch(RelOptRuleCall call) { final Join join = call.rel(0); final RelBuilder builder = call.builder(); final RexSubQuery e = RexUtil.SubQueryFinder.find(join.getCondition()); assert e != null; final RelOptUtil.Logic logic = LogicVisitor.find(RelOptUtil.Logic.TRUE, ImmutableList.of(join.getCondition()), e); builder.push(join.getLeft()); builder.push(join.getRight()); final int fieldCount = join.getRowType().getFieldCount(); final RexNode target = apply(e, ImmutableSet.of(), logic, builder, 2, fieldCount); final RexShuttle shuttle = new ReplaceSubQueryShuttle(e, target); builder.join(join.getJoinType(), shuttle.apply(join.getCondition())); builder.project(fields(builder, join.getRowType().getFieldCount())); call.transformTo(builder.build()); } }
public Logic visitCorrelVariable(RexCorrelVariable correlVariable, Logic arg) { return end(correlVariable, arg); }
public void onMatch(RelOptRuleCall call) { final Join join = call.rel(0); final RelBuilder builder = call.builder(); final RexSubQuery e = RexUtil.SubQueryFinder.find(join.getCondition()); assert e != null; final RelOptUtil.Logic logic = LogicVisitor.find(RelOptUtil.Logic.TRUE, ImmutableList.of(join.getCondition()), e); builder.push(join.getLeft()); builder.push(join.getRight()); final int fieldCount = join.getRowType().getFieldCount(); final RexNode target = apply(e, ImmutableSet.of(), logic, builder, 2, fieldCount); final RexShuttle shuttle = new ReplaceSubQueryShuttle(e, target); builder.join(join.getJoinType(), shuttle.apply(join.getCondition())); builder.project(fields(builder, join.getRowType().getFieldCount())); call.transformTo(builder.build()); } }
public Logic visitLiteral(RexLiteral literal, Logic arg) { return end(literal, arg); }
public void onMatch(RelOptRuleCall call) { final Project project = call.rel(0); final RelBuilder builder = call.builder(); final RexSubQuery e = RexUtil.SubQueryFinder.find(project.getProjects()); assert e != null; final RelOptUtil.Logic logic = LogicVisitor.find(RelOptUtil.Logic.TRUE_FALSE_UNKNOWN, project.getProjects(), e); builder.push(project.getInput()); final int fieldCount = builder.peek().getRowType().getFieldCount(); final RexNode target = apply(e, ImmutableSet.of(), logic, builder, 1, fieldCount); final RexShuttle shuttle = new ReplaceSubQueryShuttle(e, target); builder.project(shuttle.apply(project.getProjects()), project.getRowType().getFieldNames()); call.transformTo(builder.build()); } }
public Logic visitDynamicParam(RexDynamicParam dynamicParam, Logic arg) { return end(dynamicParam, arg); }
public void onMatch(RelOptRuleCall call) { final Project project = call.rel(0); final RelBuilder builder = call.builder(); final RexSubQuery e = RexUtil.SubQueryFinder.find(project.getProjects()); assert e != null; final RelOptUtil.Logic logic = LogicVisitor.find(RelOptUtil.Logic.TRUE_FALSE_UNKNOWN, project.getProjects(), e); builder.push(project.getInput()); final int fieldCount = builder.peek().getRowType().getFieldCount(); final RexNode target = apply(e, ImmutableSet.of(), logic, builder, 1, fieldCount); final RexShuttle shuttle = new ReplaceSubQueryShuttle(e, target); builder.project(shuttle.apply(project.getProjects()), project.getRowType().getFieldNames()); call.transformTo(builder.build()); } }
@Override public Logic visitTableInputRef(RexTableInputRef ref, Logic arg) { return end(ref, arg); }