public class SubstitutionVisitor extends Object
The call new SubstitutionVisitor(target, query).go(replacement))
will return query with every occurrence of target replaced
by replacement.
The following example shows how SubstitutionVisitor can be used
for materialized view recognition.
Note that result uses the materialized view table mv and a
simplified condition b = 4.
Uses a bottom-up matching algorithm. Nodes do not need to be identical. At each level, returns the residue.
The inputs must only include the core relational operators:
LogicalTableScan,
LogicalFilter,
LogicalProject,
LogicalJoin,
LogicalUnion,
LogicalAggregate.
| Modifier and Type | Class and Description |
|---|---|
static class |
SubstitutionVisitor.FilterOnProjectRule
Rule that converts a
LogicalFilter
on top of a LogicalProject into a
trivial filter (on a boolean column). |
| Modifier and Type | Field and Description |
|---|---|
protected org.apache.calcite.plan.SubstitutionVisitor.MutableRel[] |
slots
Workspace while rule is being matched.
|
| Constructor and Description |
|---|
SubstitutionVisitor(RelNode target_,
RelNode query_) |
| Modifier and Type | Method and Description |
|---|---|
static SqlAggFunction |
getRollup(SqlAggFunction aggregation) |
RelNode |
go(RelNode replacement_) |
RelNode |
go0(RelNode replacement_) |
static boolean |
mayBeSatisfiable(RexNode e)
Returns whether a boolean expression ever returns true.
|
static com.google.common.base.Function<RexNode,RexNode> |
not(RexBuilder rexBuilder)
Returns a function that applies NOT to its argument.
|
static org.apache.calcite.plan.SubstitutionVisitor.MutableAggregate |
permute(org.apache.calcite.plan.SubstitutionVisitor.MutableAggregate aggregate,
org.apache.calcite.plan.SubstitutionVisitor.MutableRel input,
Mapping mapping) |
static RexNode |
simplify(RexBuilder rexBuilder,
RexNode e)
Simplifies a boolean expression.
|
static RexNode |
splitFilter(RexBuilder rexBuilder,
RexNode condition,
RexNode target)
Maps a condition onto a target.
|
static org.apache.calcite.plan.SubstitutionVisitor.MutableRel |
unifyAggregates(org.apache.calcite.plan.SubstitutionVisitor.MutableAggregate query,
org.apache.calcite.plan.SubstitutionVisitor.MutableAggregate target) |
protected final org.apache.calcite.plan.SubstitutionVisitor.MutableRel[] slots
public static RexNode splitFilter(RexBuilder rexBuilder, RexNode condition, RexNode target)
If condition is stronger than target, returns the residue.
If it is equal to target, returns the expression that evaluates to
the constant true. If it is weaker than target, returns
null.
The terms satisfy the relation
condition = target AND residue
and residue must be as weak as possible.
Example #1: condition stronger than target
Note that residue x > 0 AND y = 2 would also satisfy the
relation condition = target AND residue but is stronger than
necessary, so we prefer y = 2.
Example #2: target weaker than condition (valid, but not currently implemented)
Example #3: condition and target are equivalent
Example #4: condition weaker than target
There are many other possible examples. It amounts to solving
whether condition AND NOT target can ever evaluate to
true, and therefore is a form of the NP-complete
Satisfiability
problem.
public static com.google.common.base.Function<RexNode,RexNode> not(RexBuilder rexBuilder)
public static boolean mayBeSatisfiable(RexNode e)
This method may give false positives. For instance, it will say
that x = 5 AND x > 10 is satisfiable, because at present it
cannot prove that it is not.
public static RexNode simplify(RexBuilder rexBuilder, RexNode e)
In particular:
simplify(x = 1 AND y = 2 AND NOT x = 1)
returns y = 2simplify(x = 1 AND FALSE)
returns FALSEpublic static org.apache.calcite.plan.SubstitutionVisitor.MutableAggregate permute(org.apache.calcite.plan.SubstitutionVisitor.MutableAggregate aggregate,
org.apache.calcite.plan.SubstitutionVisitor.MutableRel input,
Mapping mapping)
public static org.apache.calcite.plan.SubstitutionVisitor.MutableRel unifyAggregates(org.apache.calcite.plan.SubstitutionVisitor.MutableAggregate query,
org.apache.calcite.plan.SubstitutionVisitor.MutableAggregate target)
public static SqlAggFunction getRollup(SqlAggFunction aggregation)
Copyright © 2012–2015 The Apache Software Foundation. All rights reserved.