public final class AggregateExpandDistinctAggregatesRule extends RelOptRule
COUNT(DISTINCT x)) from a
Aggregate.
How this is done depends upon the arguments to the function. If all
functions have the same argument
(e.g. COUNT(DISTINCT x), SUM(DISTINCT x) both have the argument
x) then one extra Aggregate is
sufficient.
If there are multiple arguments
(e.g. COUNT(DISTINCT x), COUNT(DISTINCT y))
the rule creates separate Aggregates and combines using a
Join.
| Modifier and Type | Field and Description |
|---|---|
static AggregateExpandDistinctAggregatesRule |
INSTANCE
The default instance of the rule; operates only on logical expressions.
|
static AggregateExpandDistinctAggregatesRule |
JOIN
Instance of the rule that operates only on logical expressions and
generates a join.
|
boolean |
useGroupingSets |
description, operands, relBuilderFactory| Constructor and Description |
|---|
AggregateExpandDistinctAggregatesRule(Class<? extends Aggregate> clazz,
boolean useGroupingSets,
RelBuilderFactory relBuilderFactory) |
AggregateExpandDistinctAggregatesRule(Class<? extends LogicalAggregate> clazz,
boolean useGroupingSets,
RelFactories.JoinFactory joinFactory)
Deprecated.
|
AggregateExpandDistinctAggregatesRule(Class<? extends LogicalAggregate> clazz,
RelFactories.JoinFactory joinFactory)
Deprecated.
|
| Modifier and Type | Method and Description |
|---|---|
private RelBuilder |
convertMonopole(RelBuilder relBuilder,
Aggregate aggregate,
List<Integer> argList,
int filterArg)
Converts an aggregate relational expression that contains just one
distinct aggregate function (or perhaps several over the same arguments)
and no non-distinct aggregate functions.
|
private RelBuilder |
convertSingletonDistinct(RelBuilder relBuilder,
Aggregate aggregate,
Set<Pair<List<Integer>,Integer>> argLists)
Converts an aggregate with one distinct aggregate and one or more
non-distinct aggregates to multi-phase aggregates (see reference example
below).
|
private RelBuilder |
createSelectDistinct(RelBuilder relBuilder,
Aggregate aggregate,
List<Integer> argList,
int filterArg,
Map<Integer,Integer> sourceOf)
Given an
Aggregate
and the ordinals of the arguments to a
particular call to an aggregate function, creates a 'select distinct'
relational expression which projects the group columns and those
arguments but nothing else. |
private void |
doRewrite(RelBuilder relBuilder,
Aggregate aggregate,
int n,
List<Integer> argList,
int filterArg,
List<RexInputRef> refs)
Converts all distinct aggregate calls to a given set of arguments.
|
private static long |
groupValue(ImmutableBitSet fullGroupSet,
ImmutableBitSet groupSet) |
void |
onMatch(RelOptRuleCall call)
Receives notification about a rule match.
|
private static ImmutableBitSet |
remap(ImmutableBitSet groupSet,
ImmutableBitSet bitSet) |
private static int |
remap(ImmutableBitSet groupSet,
int arg) |
private static com.google.common.collect.ImmutableList<ImmutableBitSet> |
remap(ImmutableBitSet groupSet,
Iterable<ImmutableBitSet> bitSets) |
private static List<Integer> |
remap(ImmutableBitSet groupSet,
List<Integer> argList) |
private static void |
rewriteAggCalls(List<AggregateCall> newAggCalls,
List<Integer> argList,
Map<Integer,Integer> sourceOf) |
private void |
rewriteUsingGroupingSets(RelOptRuleCall call,
Aggregate aggregate) |
any, convert, convert, convertList, convertOperand, equals, equals, getOperand, getOperands, getOutConvention, getOutTrait, hashCode, matches, none, operand, operand, operand, operand, operand, some, toString, unorderedpublic static final AggregateExpandDistinctAggregatesRule INSTANCE
public static final AggregateExpandDistinctAggregatesRule JOIN
public final boolean useGroupingSets
public AggregateExpandDistinctAggregatesRule(Class<? extends Aggregate> clazz, boolean useGroupingSets, RelBuilderFactory relBuilderFactory)
@Deprecated public AggregateExpandDistinctAggregatesRule(Class<? extends LogicalAggregate> clazz, boolean useGroupingSets, RelFactories.JoinFactory joinFactory)
@Deprecated public AggregateExpandDistinctAggregatesRule(Class<? extends LogicalAggregate> clazz, RelFactories.JoinFactory joinFactory)
public void onMatch(RelOptRuleCall call)
RelOptRulecall.rels holds the set of relational
expressions which match the operands to the rule;
call.rels[0] is the root expression.
Typically a rule would check that the nodes are valid matches, creates
a new expression, then calls back RelOptRuleCall.transformTo(org.apache.calcite.rel.RelNode, java.util.Map<org.apache.calcite.rel.RelNode, org.apache.calcite.rel.RelNode>) to
register the expression.
onMatch in class RelOptRulecall - Rule callRelOptRule.matches(RelOptRuleCall)private RelBuilder convertSingletonDistinct(RelBuilder relBuilder, Aggregate aggregate, Set<Pair<List<Integer>,Integer>> argLists)
relBuilder - Contains the input relational expressionaggregate - Original aggregateargLists - Arguments and filters to the distinct aggregate functionprivate void rewriteUsingGroupingSets(RelOptRuleCall call, Aggregate aggregate)
private static long groupValue(ImmutableBitSet fullGroupSet, ImmutableBitSet groupSet)
private static ImmutableBitSet remap(ImmutableBitSet groupSet, ImmutableBitSet bitSet)
private static com.google.common.collect.ImmutableList<ImmutableBitSet> remap(ImmutableBitSet groupSet, Iterable<ImmutableBitSet> bitSets)
private static List<Integer> remap(ImmutableBitSet groupSet, List<Integer> argList)
private static int remap(ImmutableBitSet groupSet, int arg)
private RelBuilder convertMonopole(RelBuilder relBuilder, Aggregate aggregate, List<Integer> argList, int filterArg)
private void doRewrite(RelBuilder relBuilder, Aggregate aggregate, int n, List<Integer> argList, int filterArg, List<RexInputRef> refs)
This method is called several times, one for each set of arguments. Each time it is called, it generates a JOIN to a new SELECT DISTINCT relational expression, and modifies the set of top-level calls.
aggregate - Original aggregaten - Ordinal of this in a join. relBuilder contains the
input relational expression (either the original
aggregate, the output from the previous call to this
method. n is 0 if we're converting the
first distinct aggregate in a query with no non-distinct
aggregates)argList - Arguments to the distinct aggregate functionfilterArg - Argument that filters input to aggregate function, or -1refs - Array of expressions which will be the projected by the
result of this rule. Those relating to this arg list will
be modified @return Relational expressionprivate static void rewriteAggCalls(List<AggregateCall> newAggCalls, List<Integer> argList, Map<Integer,Integer> sourceOf)
private RelBuilder createSelectDistinct(RelBuilder relBuilder, Aggregate aggregate, List<Integer> argList, int filterArg, Map<Integer,Integer> sourceOf)
Aggregate
and the ordinals of the arguments to a
particular call to an aggregate function, creates a 'select distinct'
relational expression which projects the group columns and those
arguments but nothing else.
For example, given
select f0, count(distinct f1), count(distinct f2) from t group by f0
and the argument list
{2}
returns
select distinct f0, f2 from t
The sourceOf map is populated with the source of each
column; in this case sourceOf.get(0) = 0, and sourceOf.get(1) = 2.
relBuilder - Relational expression builderaggregate - Aggregate relational expressionargList - Ordinals of columns to make distinctfilterArg - Ordinal of column to filter on, or -1sourceOf - Out parameter, is populated with a map of where each
output field came fromCopyright © 2012–2018 The Apache Software Foundation. All rights reserved.