Java源码示例:org.apache.calcite.rel.logical.LogicalAggregate
示例1
public RelNode convert(RelNode rel) {
final LogicalAggregate agg = (LogicalAggregate) rel;
if (!Aggregate.isSimple(agg)) {
return null;
}
final RelTraitSet inputTraits = rel.getCluster()
.traitSet().replace(EnumerableConvention.INSTANCE)
.replace(
RelCollations.of(
ImmutableIntList.copyOf(
agg.getGroupSet().asList())));
final RelTraitSet selfTraits = inputTraits.replace(
RelCollations.of(
ImmutableIntList.identity(agg.getGroupSet().cardinality())));
return new EnumerableSortedAggregate(
rel.getCluster(),
selfTraits,
convert(agg.getInput(), inputTraits),
agg.getGroupSet(),
agg.getGroupSets(),
agg.getAggCallList());
}
示例2
private boolean hasNestedAggregations(LogicalAggregate rel) {
if (node instanceof SqlSelect) {
final SqlNodeList selectList = ((SqlSelect) node).getSelectList();
if (selectList != null) {
final Set<Integer> aggregatesArgs = new HashSet<>();
for (AggregateCall aggregateCall : rel.getAggCallList()) {
aggregatesArgs.addAll(aggregateCall.getArgList());
}
for (int aggregatesArg : aggregatesArgs) {
if (selectList.get(aggregatesArg) instanceof SqlBasicCall) {
final SqlBasicCall call = (SqlBasicCall) selectList.get(aggregatesArg);
for (SqlNode operand : call.getOperands()) {
if (operand instanceof SqlCall
&& ((SqlCall) operand).getOperator() instanceof SqlAggFunction) {
return true;
}
}
}
}
}
}
return false;
}
示例3
@Override
public RelNode convert(RelNode rel) {
LogicalAggregate agg = (LogicalAggregate) rel;
// AVG() will be transformed into SUM()/COUNT() by AggregateReduceFunctionsRule.
// Here only let the transformed plan pass.
if (containsAvg(agg)) {
return null;
}
RelTraitSet traitSet = agg.getTraitSet().replace(OLAPRel.CONVENTION);
try {
return new OLAPAggregateRel(agg.getCluster(), traitSet, convert(agg.getInput(), OLAPRel.CONVENTION), agg.indicator, agg.getGroupSet(), agg.getGroupSets(), agg.getAggCallList());
} catch (InvalidRelException e) {
throw new IllegalStateException("Can't create OLAPAggregateRel!", e);
}
}
示例4
public RelNode convert(RelNode relNode) {
LogicalAggregate aggregate = (LogicalAggregate) relNode;
RelTraitSet traitSet = aggregate.getTraitSet().replace(getOutTrait());
for (AggregateCall call : aggregate.getAggCallList())
{
switch (call.getAggregation().getKind())
{
case MIN:
case MAX:
case COUNT:
case SUM:
case AVG:break;
default:return null;//doesn't match. aggregate rule doesn't fire
}
}
return new ElasticsearchAggregate(aggregate.getCluster(), traitSet,
convert(aggregate.getInput(), getOutTrait()), aggregate.indicator,
aggregate.getGroupSet(), aggregate.getGroupSets(), aggregate.getAggCallList());
}
示例5
public RelNode convert(RelNode relNode) {
LogicalAggregate aggregate = (LogicalAggregate) relNode;
RelTraitSet traitSet = aggregate.getTraitSet().replace(getOutTrait());
for (AggregateCall call : aggregate.getAggCallList())
{
switch (call.getAggregation().getKind())
{
case MIN:
case MAX:
case COUNT:
case SUM:
case AVG:break;
default:return null;//doesn't match. aggregate rule doesn't fire
}
}
return new ElasticsearchAggregate(aggregate.getCluster(), traitSet,
convert(aggregate.getInput(), getOutTrait()), aggregate.indicator,
aggregate.getGroupSet(), aggregate.getGroupSets(), aggregate.getAggCallList());
}
示例6
public void rewriteRel(LogicalAggregate rel) {
RelNode oldInput = rel.getInput();
RelDataType inputType = oldInput.getRowType();
List<RelDataTypeField> inputTypeFields = inputType.getFieldList();
if (SqlTypeUtil.isFlat(inputType) || rel.getAggCallList().stream().allMatch(
call -> call.getArgList().isEmpty()
|| call.getArgList().stream().noneMatch(idx -> inputTypeFields.get(idx)
.getType().isStruct()))) {
rewriteGeneric(rel);
} else {
// one of aggregate calls definitely refers to field with struct type from oldInput,
// let's restructure new input back and use restructured one as new input for aggregate node
RelNode restructuredInput = tryRestructure(oldInput, getNewForOldRel(oldInput));
// expected that after restructuring indexes in AggregateCalls again became relevant,
// leave it as is but with new input
RelNode newRel = rel.copy(rel.getTraitSet(), restructuredInput, rel.getGroupSet(),
rel.getGroupSets(), rel.getAggCallList());
if (!SqlTypeUtil.isFlat(rel.getRowType())) {
newRel = coverNewRelByFlatteningProjection(rel, newRel);
}
setNewForOldRel(rel, newRel);
}
}
示例7
@Override
public RelNode visit(LogicalAggregate aggregate) {
RelNode input = aggregate.getInput().accept(this);
RelDataType incomingRowType = input.getRowType();
RelDataTypeField modField = incomingRowType.getField(UPDATE_COLUMN, false, false);
if (modField == null) {
return aggregate;
}
final AggregateCall aggCall = AggregateCall.create(SqlStdOperatorTable.MAX, false, ImmutableList.of(modField.getIndex()), -1, modField.getType(), UPDATE_COLUMN);
final List<AggregateCall> aggCalls = FluentIterable.from(aggregate.getAggCallList())
.append(aggCall)
.toList();
return aggregate.copy(
aggregate.getTraitSet(),
input,
aggregate.indicator,
aggregate.getGroupSet(),
null,
aggCalls
);
}
示例8
public RelNode convert(RelNode rel) {
final LogicalAggregate agg = (LogicalAggregate) rel;
final RelTraitSet traitSet =
agg.getTraitSet().replace(out);
try {
return new MongoAggregate(
rel.getCluster(),
traitSet,
convert(agg.getInput(), traitSet.simplify()),
agg.getGroupSet(),
agg.getGroupSets(),
agg.getAggCallList());
} catch (InvalidRelException e) {
LOGGER.warn(e.toString());
return null;
}
}
示例9
protected boolean hasNestedAggregations(LogicalAggregate rel) {
List<AggregateCall> aggCallList = rel.getAggCallList();
HashSet<Integer> aggregatesArgs = new HashSet<>();
for (AggregateCall aggregateCall : aggCallList) {
aggregatesArgs.addAll(aggregateCall.getArgList());
}
for (Integer aggregatesArg : aggregatesArgs) {
SqlNode selectNode = ((SqlSelect) node).getSelectList().get(aggregatesArg);
if (!(selectNode instanceof SqlBasicCall)) {
continue;
}
for (SqlNode operand : ((SqlBasicCall) selectNode).getOperands()) {
if (operand instanceof SqlCall) {
final SqlOperator operator = ((SqlCall) operand).getOperator();
if (operator instanceof SqlAggFunction) {
return true;
}
}
}
}
return false;
}
示例10
@Override
public RelNode convert(RelNode rel) {
LogicalAggregate agg = (LogicalAggregate) rel;
// AVG() will be transformed into SUM()/COUNT() by AggregateReduceFunctionsRule.
// Here only let the transformed plan pass.
if (containsAvg(agg)) {
return null;
}
RelTraitSet traitSet = agg.getTraitSet().replace(OLAPRel.CONVENTION);
try {
return new OLAPAggregateRel(agg.getCluster(), traitSet, convert(agg.getInput(), OLAPRel.CONVENTION), agg.indicator, agg.getGroupSet(), agg.getGroupSets(), agg.getAggCallList());
} catch (InvalidRelException e) {
throw new IllegalStateException("Can't create OLAPAggregateRel!", e);
}
}
示例11
public RelNode convert(RelNode rel) {
final LogicalAggregate agg = (LogicalAggregate) rel;
final RelTraitSet traitSet = rel.getCluster()
.traitSet().replace(EnumerableConvention.INSTANCE);
try {
return new EnumerableAggregate(
rel.getCluster(),
traitSet,
convert(agg.getInput(), traitSet),
agg.getGroupSet(),
agg.getGroupSets(),
agg.getAggCallList());
} catch (InvalidRelException e) {
EnumerableRules.LOGGER.debug(e.toString());
return null;
}
}
示例12
@Override public void onMatch(RelOptRuleCall call) {
final Delta delta = call.rel(0);
Util.discard(delta);
final Aggregate aggregate = call.rel(1);
final LogicalDelta newDelta =
LogicalDelta.create(aggregate.getInput());
final LogicalAggregate newAggregate =
LogicalAggregate.create(newDelta, aggregate.getGroupSet(),
aggregate.groupSets, aggregate.getAggCallList());
call.transformTo(newAggregate);
}
示例13
@SuppressWarnings("deprecation")
public RelNode createAggregate(RelNode input, boolean indicator,
ImmutableBitSet groupSet, ImmutableList<ImmutableBitSet> groupSets,
List<AggregateCall> aggCalls) {
return LogicalAggregate.create(input, indicator,
groupSet, groupSets, aggCalls);
}
示例14
@Override
public void onMatch(RelOptRuleCall call) {
LogicalAggregate singleAggregate = call.rel(0);
LogicalProject project = call.rel(1);
LogicalAggregate aggregate = call.rel(2);
// check singleAggRel is single_value agg
if ((!singleAggregate.getGroupSet().isEmpty()) || (singleAggregate.getAggCallList().size() != 1)
|| !(singleAggregate.getAggCallList().get(0)
.getAggregation() instanceof SqlSingleValueAggFunction)) {
return;
}
// check projRel only projects one expression
// check this project only projects one expression, i.e. scalar
// sub-queries.
List<RexNode> projExprs = project.getProjects();
if (projExprs.size() != 1) {
return;
}
// check the input to project is an aggregate on the entire input
if (!aggregate.getGroupSet().isEmpty()) {
return;
}
// singleAggRel produces a nullable type, so create the new
// projection that casts proj expr to a nullable type.
final RelBuilder relBuilder = call.builder();
final RelDataType type = relBuilder.getTypeFactory().createTypeWithNullability(projExprs.get(0).getType(),
true);
final RexNode cast = relBuilder.getRexBuilder().makeCast(type, projExprs.get(0));
relBuilder.push(aggregate).project(cast);
call.transformTo(relBuilder.build());
}
示例15
RemoveCorrelationForScalarAggregateRule(RelBuilderFactory relBuilderFactory) {
super(operand(LogicalCorrelate.class, operand(RelNode.class, any()),
operand(LogicalProject.class,
operandJ(LogicalAggregate.class, null, Aggregate::isSimple,
operand(LogicalProject.class, operand(RelNode.class, any()))))),
relBuilderFactory, null);
}
示例16
AdjustProjectForCountAggregateRule(boolean flavor, RelBuilderFactory relBuilderFactory) {
super(flavor
? operand(LogicalCorrelate.class, operand(RelNode.class, any()),
operand(LogicalProject.class, operand(LogicalAggregate.class, any())))
: operand(LogicalCorrelate.class, operand(RelNode.class, any()),
operand(LogicalAggregate.class, any())),
relBuilderFactory, null);
this.flavor = flavor;
}
示例17
public void rewriteRel(LogicalAggregate rel) {
RelDataType inputType = rel.getInput().getRowType();
for (RelDataTypeField field : inputType.getFieldList()) {
if (field.getType().isStruct()) {
// TODO jvs 10-Feb-2005
throw Util.needToImplement("aggregation on structured types");
}
}
rewriteGeneric(rel);
}
示例18
public RelNode convert(RelNode rel) {
final LogicalAggregate agg = (LogicalAggregate) rel;
final RelTraitSet traitSet =
agg.getTraitSet().replace(BindableConvention.INSTANCE);
try {
return new BindableAggregate(rel.getCluster(), traitSet,
convert(agg.getInput(), traitSet), false, agg.getGroupSet(),
agg.getGroupSets(), agg.getAggCallList());
} catch (InvalidRelException e) {
RelOptPlanner.LOGGER.debug(e.toString());
return null;
}
}
示例19
private DrillAggregateRule() {
super(
RelOptHelper.some(LogicalAggregate.class,
Convention.NONE, RelOptHelper.any(RelNode.class)),
DrillRelFactories.LOGICAL_BUILDER,
"DrillAggregateRule");
}
示例20
@Override
public void onMatch(RelOptRuleCall call) {
final LogicalAggregate aggregate = call.rel(0);
final RelNode input = call.rel(1);
if (aggregate.containsDistinctCall()) {
// currently, don't use this rule if any of the aggregates contains DISTINCT
return;
}
final RelTraitSet traits = aggregate.getTraitSet().plus(DrillRel.DRILL_LOGICAL);
final RelNode convertedInput = convert(input, input.getTraitSet().plus(DrillRel.DRILL_LOGICAL).simplify());
call.transformTo(new DrillAggregateRel(aggregate.getCluster(), traits, convertedInput, aggregate.indicator,
aggregate.getGroupSet(), aggregate.getGroupSets(), aggregate.getAggCallList()));
}
示例21
RemoveSingleAggregateRule(RelBuilderFactory relBuilderFactory) {
super(
operand(
LogicalAggregate.class,
operand(
LogicalProject.class,
operand(LogicalAggregate.class, any()))),
relBuilderFactory, null);
}
示例22
public void onMatch(RelOptRuleCall call) {
LogicalAggregate singleAggregate = call.rel(0);
LogicalProject project = call.rel(1);
LogicalAggregate aggregate = call.rel(2);
// check singleAggRel is single_value agg
if ((!singleAggregate.getGroupSet().isEmpty())
|| (singleAggregate.getAggCallList().size() != 1)
|| !(singleAggregate.getAggCallList().get(0).getAggregation()
instanceof SqlSingleValueAggFunction)) {
return;
}
// check projRel only projects one expression
// check this project only projects one expression, i.e. scalar
// sub-queries.
List<RexNode> projExprs = project.getProjects();
if (projExprs.size() != 1) {
return;
}
// check the input to project is an aggregate on the entire input
if (!aggregate.getGroupSet().isEmpty()) {
return;
}
// singleAggRel produces a nullable type, so create the new
// projection that casts proj expr to a nullable type.
final RelBuilder relBuilder = call.builder();
final RelDataType type =
relBuilder.getTypeFactory()
.createTypeWithNullability(projExprs.get(0).getType(), true);
final RexNode cast =
relBuilder.getRexBuilder().makeCast(type, projExprs.get(0));
relBuilder.push(aggregate)
.project(cast);
call.transformTo(relBuilder.build());
}
示例23
RemoveCorrelationForScalarAggregateRule(RelBuilderFactory relBuilderFactory) {
super(
operand(LogicalCorrelate.class,
operand(RelNode.class, any()),
operand(LogicalProject.class,
operandJ(LogicalAggregate.class, null, Aggregate::isSimple,
operand(LogicalProject.class,
operand(RelNode.class, any()))))),
relBuilderFactory, null);
}
示例24
AdjustProjectForCountAggregateRule(boolean flavor,
RelBuilderFactory relBuilderFactory) {
super(
flavor
? operand(LogicalCorrelate.class,
operand(RelNode.class, any()),
operand(LogicalProject.class,
operand(LogicalAggregate.class, any())))
: operand(LogicalCorrelate.class,
operand(RelNode.class, any()),
operand(LogicalAggregate.class, any())),
relBuilderFactory, null);
this.flavor = flavor;
}
示例25
RemoveSingleAggregateRule(RelBuilderFactory relBuilderFactory) {
super(
operand(
LogicalAggregate.class,
operand(
LogicalProject.class,
operand(LogicalAggregate.class, any()))),
relBuilderFactory, null);
}
示例26
public void onMatch(RelOptRuleCall call) {
LogicalAggregate singleAggregate = call.rel(0);
LogicalProject project = call.rel(1);
LogicalAggregate aggregate = call.rel(2);
// check singleAggRel is single_value agg
if ((!singleAggregate.getGroupSet().isEmpty())
|| (singleAggregate.getAggCallList().size() != 1)
|| !(singleAggregate.getAggCallList().get(0).getAggregation()
instanceof SqlSingleValueAggFunction)) {
return;
}
// check projRel only projects one expression
// check this project only projects one expression, i.e. scalar
// sub-queries.
List<RexNode> projExprs = project.getProjects();
if (projExprs.size() != 1) {
return;
}
// check the input to project is an aggregate on the entire input
if (!aggregate.getGroupSet().isEmpty()) {
return;
}
// singleAggRel produces a nullable type, so create the new
// projection that casts proj expr to a nullable type.
final RelBuilder relBuilder = call.builder();
final RelDataType type =
relBuilder.getTypeFactory()
.createTypeWithNullability(projExprs.get(0).getType(), true);
final RexNode cast =
relBuilder.getRexBuilder().makeCast(type, projExprs.get(0));
relBuilder.push(aggregate)
.project(cast);
call.transformTo(relBuilder.build());
}
示例27
RemoveCorrelationForScalarProjectRule(RelBuilderFactory relBuilderFactory) {
super(
operand(LogicalCorrelate.class,
operand(RelNode.class, any()),
operand(LogicalAggregate.class,
operand(LogicalProject.class,
operand(RelNode.class, any())))),
relBuilderFactory, null);
}
示例28
RemoveCorrelationForScalarAggregateRule(RelBuilderFactory relBuilderFactory) {
super(
operand(LogicalCorrelate.class,
operand(RelNode.class, any()),
operand(LogicalProject.class,
operandJ(LogicalAggregate.class, null, Aggregate::isSimple,
operand(LogicalProject.class,
operand(RelNode.class, any()))))),
relBuilderFactory, null);
}
示例29
AdjustProjectForCountAggregateRule(boolean flavor,
RelBuilderFactory relBuilderFactory) {
super(
flavor
? operand(LogicalCorrelate.class,
operand(RelNode.class, any()),
operand(LogicalProject.class,
operand(LogicalAggregate.class, any())))
: operand(LogicalCorrelate.class,
operand(RelNode.class, any()),
operand(LogicalAggregate.class, any())),
relBuilderFactory, null);
this.flavor = flavor;
}
示例30
@Deprecated // to be removed before 2.0
public FlinkAggregateExpandDistinctAggregatesRule(
Class<? extends LogicalAggregate> clazz,
boolean useGroupingSets,
RelFactories.JoinFactory joinFactory) {
this(clazz, useGroupingSets, RelBuilder.proto(Contexts.of(joinFactory)));
}