@Override public boolean matches(RelOptRuleCall call) { if (!super.matches(call)) { return false; } Aggregate oldAggRel = (Aggregate) call.rels[0]; return containsAvgStddevVarCall(oldAggRel.getAggCallList()); }
@Override public DruidUnionRel asBindable() { return new DruidUnionRel( getCluster(), getTraitSet().replace(BindableConvention.INSTANCE), getQueryMaker(), rowType, rels.stream().map(rel -> RelOptRule.convert(rel, BindableConvention.INSTANCE)).collect(Collectors.toList()), limit ); }
public FilterIntoJoinRule(boolean smart, RelBuilderFactory relBuilderFactory, Predicate predicate) { super( operand(Filter.class, operand(Join.class, RelOptRule.any())), "FilterJoinRule:filter", smart, relBuilderFactory, predicate); }
public HiveInsertExchange4JoinRule(Class<? extends RelNode> clazz) { // match multijoin or join super(RelOptRule.operand(clazz, any())); }
@Test public void testAggregateExtractProjectRuleWithFilter() { final String sql = "select sum(sal) filter (where empno = 40)\n" + "from emp"; HepProgram pre = new HepProgramBuilder() .addRuleInstance(AggregateProjectMergeRule.INSTANCE) .build(); // AggregateProjectMergeRule does not merges Project with Filter. // Force match Aggregate on top of Project once explicitly in unit test. final AggregateExtractProjectRule rule = new AggregateExtractProjectRule( operand(Aggregate.class, operandJ(Project.class, null, new Predicate<Project>() { int matchCount = 0; public boolean test(Project project) { return matchCount++ == 0; } }, none())), RelFactories.LOGICAL_BUILDER); sql(sql).withPre(pre).withRule(rule).checkUnchanged(); }
List<RelNode> bindings = new ArrayList<RelNode>(); if (match( rule.getOperand(), rel, bindings)) { new MockRuleCall( this, rule.getOperand(), bindings.toArray(new RelNode[0])); if (rule.matches(call)) { rule.onMatch(call);
boolean match = matchOperands( rule.getOperand(), vertex.getCurrentRel(), bindings, new HepRuleCall( this, rule.getOperand(), bindings.toArray(new RelNode[0]), nodeChildren, if (!rule.matches(call)) { return null;
/** * Creates an operand that matches a relational expression that has no * children. * * @param clazz Class of relational expression to match (must not be null) * @param trait Trait to match, or null to match any trait * @param predicate Additional match predicate * @param first First operand * @param rest Rest operands * @param <R> Class of relational expression to match * @return Operand */ public static <R extends RelNode> RelOptRuleOperand operandJ( Class<R> clazz, RelTrait trait, Predicate<? super R> predicate, RelOptRuleOperand first, RelOptRuleOperand... rest) { return operandJ(clazz, trait, predicate, some(first, rest)); }
/** * Creates a rule with an explicit description. * * @param operand root operand, must not be null * @param description Description, or null to guess description * @param relBuilderFactory Builder for relational expressions */ public RelOptRule(RelOptRuleOperand operand, RelBuilderFactory relBuilderFactory, String description) { this.operand = Objects.requireNonNull(operand); this.relBuilderFactory = Objects.requireNonNull(relBuilderFactory); if (description == null) { description = guessDescription(getClass().getName()); } if (!description.matches("[A-Za-z][-A-Za-z0-9_.():]*")) { throw new RuntimeException("Rule description '" + description + "' is not valid"); } this.description = description; this.operands = flattenOperands(operand); assignSolveOrder(); }
@SuppressWarnings("Guava") @Deprecated // to be removed before 2.0 public static <R extends RelNode> RelOptRuleOperand operand( Class<R> clazz, RelTrait trait, com.google.common.base.Predicate<? super R> predicate, RelOptRuleOperand first, RelOptRuleOperand... rest) { return operandJ(clazz, trait, (Predicate<? super R>) predicate::apply, first, rest); }
/** * Tests the rules for how we name rules. */ @Test public void testRuleGuessDescription() { assertEquals("Bar", RelOptRule.guessDescription("com.foo.Bar")); assertEquals("Baz", RelOptRule.guessDescription("com.flatten.Bar$Baz")); // yields "1" (which as an integer is an invalid try { Util.discard(RelOptRule.guessDescription("com.foo.Bar$1")); fail("expected exception"); } catch (RuntimeException e) { assertEquals("Derived description of rule class com.foo.Bar$1 is an " + "integer, not valid. Supply a description manually.", e.getMessage()); } }
/** Returns whether to skip a match. This happens if any of the * {@link RelNode}s have importance zero. */ private boolean skipMatch(VolcanoRuleMatch match) { for (RelNode rel : match.rels) { Double importance = planner.relImportances.get(rel); if (importance != null && importance == 0d) { return true; } } // If the same subset appears more than once along any path from root // operand to a leaf operand, we have matched a cycle. A relational // expression that consumes its own output can never be implemented, and // furthermore, if we fire rules on it we may generate lots of garbage. // For example, if // Project(A, X = X + 0) // is in the same subset as A, then we would generate // Project(A, X = X + 0 + 0) // Project(A, X = X + 0 + 0 + 0) // also in the same subset. They are valid but useless. final Deque<RelSubset> subsets = new ArrayDeque<>(); try { checkDuplicateSubsets(subsets, match.rule.getOperand(), match.rels); } catch (Util.FoundOne e) { return true; } return false; }
/** * Creates a FilterCorrelateRule. */ public FilterCorrelateRule(RelBuilderFactory builderFactory) { super( operand(Filter.class, operand(Correlate.class, RelOptRule.any())), builderFactory, "FilterCorrelateRule"); }
public HiveInsertExchange4JoinRule(Class<? extends RelNode> clazz) { // match multijoin or join super(RelOptRule.operand(clazz, any())); }
@Test public void testAggregateExtractProjectRuleWithFilter() { final String sql = "select sum(sal) filter (where empno = 40)\n" + "from emp"; HepProgram pre = new HepProgramBuilder() .addRuleInstance(AggregateProjectMergeRule.INSTANCE) .build(); // AggregateProjectMergeRule does not merges Project with Filter. // Force match Aggregate on top of Project once explicitly in unit test. final AggregateExtractProjectRule rule = new AggregateExtractProjectRule( operand(Aggregate.class, operandJ(Project.class, null, new Predicate<Project>() { int matchCount = 0; public boolean test(Project project) { return matchCount++ == 0; } }, none())), RelFactories.LOGICAL_BUILDER); sql(sql).withPre(pre).withRule(rule).checkUnchanged(); }