@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); } }
if (rel.getGroupType() != Aggregate.Group.SIMPLE) { throw new AssertionError(Bug.CALCITE_461_FIXED); final RelNode oldInput = rel.getInput(); final Frame frame = getInvoke(oldInput, rel); if (frame == null) { final int oldGroupKeyCount = rel.getGroupSet().cardinality(); List<AggregateCall> oldAggCalls = rel.getAggCallList(); int oldInputOutputFieldCount = rel.getGroupSet().cardinality(); int newInputOutputFieldCount = newGroupSet.cardinality(); LogicalAggregate.create(newProject, false, newGroupSet,
@Override public void onMatch(RelOptRuleCall call) { LogicalAggregate aggr = (LogicalAggregate) call.getRelList().get(0); RelNode input = aggr.getInput(); RelBuilder relBuilder = call.builder(); RexBuilder rexBuilder = aggr.getCluster().getRexBuilder(); for (ImmutableBitSet groupSet : aggr.getGroupSets()) { relBuilder.push(aggr.copy(aggr.getTraitSet(), input, false, groupSet, asList(groupSet), aggr.getAggCallList())); Iterator<Integer> groupSetIter = aggr.getGroupSet().iterator(); Iterator<RelDataTypeField> typeIterator = aggr.getRowType().getFieldList().iterator(); Iterator<Integer> groupKeyIter = groupSet.iterator(); int groupKey = groupKeyIter.next(); RelNode unionAggr = relBuilder.union(true, aggr.getGroupSets().size()).build();
if ((!singleAggregate.getGroupSet().isEmpty()) || (singleAggregate.getAggCallList().size() != 1) || !(singleAggregate.getAggCallList().get(0).getAggregation() instanceof SqlSingleValueAggFunction)) { return; if (!aggregate.getGroupSet().isEmpty()) { return;
if (!aggregate.getGroupSet().isEmpty()) { return; final List<AggregateCall> aggCalls = aggregate.getAggCallList(); final Set<Integer> isCountStar = Sets.newHashSet(); newAggCalls.add( aggCall.adaptTo(joinOutputProject, argList, filterArg, aggregate.getGroupCount(), groupCount)); ImmutableBitSet.range(groupCount); LogicalAggregate newAggregate = LogicalAggregate.create(joinOutputProject, false, groupSet,
@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())); } }
@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 ); } }
case AGGREGATE: final MutableAggregate aggregate = (MutableAggregate) node; return LogicalAggregate.create(fromMutable(aggregate.input), aggregate.indicator, aggregate.groupSet, aggregate.groupSets, aggregate.aggCalls);
public RelNode visit(LogicalAggregate aggregate) { return visitChild(aggregate, 0, aggregate.getInput()); }
@Override public RelNode visit(LogicalAggregate aggregate) { for(AggregateCall aggregateCall : aggregate.getAggCallList()) { if(aggregateCall.getAggregation() instanceof SqlSingleValueAggFunction) { // see DRILL-1937 unsupportedOperatorCollector.setException(SqlUnsupportedException.ExceptionType.FUNCTION, "Dremio doesn't currently support non-scalar sub-queries used in an expression"); throw new UnsupportedOperationException(); } } return visitChild(aggregate, 0, aggregate.getInput()); }
private boolean containsAvg(LogicalAggregate agg) { for (AggregateCall call : agg.getAggCallList()) { SqlAggFunction func = call.getAggregation(); if (func instanceof SqlAvgAggFunction) return true; } return false; }
void translate(final LogicalAggregate aggregate, final TranslatorContext context) { validateAggregateFunctions(aggregate); MessageStream<SamzaSqlRelMessage> inputStream = context.getMessageStream(aggregate.getInput().getId()); // At this point, the assumption is that only count function is supported. SupplierFunction<Long> initialValue = () -> (long) 0; FoldLeftFunction<SamzaSqlRelMessage, Long> foldCountFn = (m, c) -> c + 1; final ArrayList<String> aggFieldNames = getAggFieldNames(aggregate); MessageStream<SamzaSqlRelMessage> outputStream = inputStream .window(Windows.keyedTumblingWindow(m -> m, Duration.ofMillis(context.getExecutionContext().getSamzaSqlApplicationConfig().getWindowDurationMs()), initialValue, foldCountFn, new SamzaSqlRelMessageSerdeFactory.SamzaSqlRelMessageSerde(), new LongSerde()) .setAccumulationMode(AccumulationMode.DISCARDING), "tumblingWindow_" + windowId) .map(windowPane -> { List<String> fieldNames = windowPane.getKey().getKey().getSamzaSqlRelRecord().getFieldNames(); List<Object> fieldValues = windowPane.getKey().getKey().getSamzaSqlRelRecord().getFieldValues(); fieldNames.add(aggFieldNames.get(0)); fieldValues.add(windowPane.getMessage()); return new SamzaSqlRelMessage(fieldNames, fieldValues); }); context.registerMessageStream(aggregate.getId(), outputStream); }
@Override public LogicalAggregate copy(RelTraitSet traitSet, RelNode input, boolean indicator, ImmutableBitSet groupSet, List<ImmutableBitSet> groupSets, List<AggregateCall> aggCalls) { assert traitSet.containsIfApplicable(Convention.NONE); return new LogicalAggregate(getCluster(), traitSet, input, indicator, groupSet, groupSets, aggCalls); }
cluster.getTypeFactory().createSqlType(SqlTypeName.BIGINT); LogicalAggregate aggregate = LogicalAggregate.create(filter, ImmutableBitSet.of(0), null, ImmutableList.of( AggregateCall.create(SqlStdOperatorTable.COUNT, false, false, ImmutableList.of(), -1, RelCollations.EMPTY, bigIntType, "d"))); aggregate.explain(writer); return writer.asString(); });
private static LogicalAggregate create_(final RelNode input, boolean indicator, ImmutableBitSet groupSet, List<ImmutableBitSet> groupSets, List<AggregateCall> aggCalls) { final RelOptCluster cluster = input.getCluster(); final RelTraitSet traitSet = cluster.traitSetOf(Convention.NONE); return new LogicalAggregate(cluster, traitSet, input, indicator, groupSet, groupSets, aggCalls); }
public void onMatch(RelOptRuleCall call) { final LogicalCorrelate correlate = call.rel(0); final RelNode left = call.rel(1); final LogicalProject aggOutputProject; final LogicalAggregate aggregate; if (flavor) { aggOutputProject = call.rel(2); aggregate = call.rel(3); } else { aggregate = call.rel(2); // Create identity projection final List<Pair<RexNode, String>> projects = Lists.newArrayList(); final List<RelDataTypeField> fields = aggregate.getRowType().getFieldList(); for (int i = 0; i < fields.size(); i++) { projects.add(RexInputRef.of2(projects.size(), fields)); } aggOutputProject = (LogicalProject) RelOptUtil.createProject( aggregate, projects, false); } onMatch2(call, correlate, left, aggOutputProject, aggregate); }
List<Pair<RexNode, String>> newProjects = new ArrayList<>(); Map<Integer, Integer> mapping = new HashMap<>(); for (int key : aggr.getGroupSet()) { mappingKeys(key, projects.get(key), newProjects, mapping); final ImmutableBitSet newGroupSet = aggr.getGroupSet().permute(mapping); for (AggregateCall aggrCall : aggr.getAggCallList()) { final ImmutableList.Builder<Integer> newArgs = ImmutableList.builder(); for (int key : aggrCall.getArgList()) {
if (!aggregate.getGroupSet().isEmpty()) { return; final List<AggregateCall> aggCalls = aggregate.getAggCallList(); final Set<Integer> isCountStar = new HashSet<>(); newAggCalls.add( aggCall.adaptTo(joinOutputProject, argList, filterArg, aggregate.getGroupCount(), groupCount)); ImmutableBitSet.range(groupCount); LogicalAggregate newAggregate = LogicalAggregate.create(joinOutputProject, groupSet, null, newAggCalls); List<RexNode> newAggOutputProjectList = new ArrayList<>();
@Override public void onMatch(RelOptRuleCall call) { final LogicalAggregate aggregate = (LogicalAggregate) 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(Rel.LOGICAL); final RelNode convertedInput = convert(input, input.getTraitSet().plus(Rel.LOGICAL).simplify()); call.transformTo(new AggregateRel(aggregate.getCluster(), traits, convertedInput, aggregate.indicator, aggregate.getGroupSet(), aggregate.getGroupSets(), aggregate.getAggCallList())); } }
@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); } }