ColumnRowType buildColumnRowType() { OLAPRel olapChild = (OLAPRel) getInput(0); ColumnRowType inputColumnRowType = olapChild.getColumnRowType(); List<TblColRef> columns = new ArrayList<>(); // the input col always be collected by left columns.addAll(inputColumnRowType.getAllColumns()); // add window aggregate calls column for (Group group : groups) { for (AggregateCall aggrCall : group.getAggregateCalls(this)) { TblColRef aggrCallCol = TblColRef.newInnerColumn(aggrCall.getName(), TblColRef.InnerDataTypeEnum.LITERAL); columns.add(aggrCallCol); } } return new ColumnRowType(columns); }
for(RelFieldCollation fieldCollation: group.collation().getFieldCollations()) { inputFinder.inputBitSet.set(fieldCollation.getFieldIndex()); for(RelFieldCollation fieldCollation: group.collation().getFieldCollations()) { newFieldCollations.add(fieldCollation.copy(inputAndConstantsMapping.getTarget(fieldCollation.getFieldIndex()))); final Window.Group newGroup = new Window.Group(newKeys, group.isRows, newLowerBound, newUpperBound, RelCollations.of(newFieldCollations), newCalls); newGroups.add(newGroup);
"comparator", inputPhysType.generateComparator( group.collation())); List<AggregateCall> aggregateCalls = group.getAggregateCalls(this); for (int aggIdx = 0; aggIdx < aggregateCalls.size(); aggIdx++) { AggregateCall call = aggregateCalls.get(aggIdx); final Expression endX; final Expression hasRows; if (group.isAlwaysNonEmpty()) { startX = startUnchecked; endX = endUnchecked;
"comparator", inputPhysType.generateComparator( group.collation())); List<AggregateCall> aggregateCalls = group.getAggregateCalls(this); for (int aggIdx = 0; aggIdx < aggregateCalls.size(); aggIdx++) { AggregateCall call = aggregateCalls.get(aggIdx); final Expression endX; final Expression hasRows; if (group.isAlwaysNonEmpty()) { startX = startUnchecked; endX = endUnchecked;
new Group( windowKey.groupSet, windowKey.isRows,
new Group( windowKey.groupSet, windowKey.isRows,
new Window.Group(keys.build(), group.isRows, group.lowerBound, group.upperBound, RelCollations.of(orderKeys), aggCalls));
traits = traits.plus(DrillDistributionTrait.SINGLETON); convertedInput = new SingleMergeExchangePrel(window.getCluster(), traits, convertedInput, windowBase.collation()); windowBase = new Window.Group( windowBase.keys, windowBase.isRows,
new Window.Group(keys.build(), group.isRows, group.lowerBound, group.upperBound, RelCollations.of(orderKeys), aggCalls));
traits = traits.plus(DistributionTrait.SINGLETON); convertedInput = new SingleMergeExchangePrel(window.getCluster(), traits, convertedInput, windowBase.collation()); windowBase = new Window.Group( windowBase.keys, windowBase.isRows,
final Window.Group newGroup = new Window.Group( group.keys, group.isRows,
for (AggregateCall aggCall : window.getAggregateCalls(this)) { FieldReference ref = new FieldReference(aggCall.getName()); LogicalExpression expr = toDrill(aggCall, childFields);
for (AggregateCall aggCall : window.getAggregateCalls(this)) { FieldReference ref = new FieldReference(aggCall.getName()); LogicalExpression expr = toExpr(aggCall, childFields);
@Override public LogicalOperator implement(DrillImplementor implementor) { final LogicalOperator inputOp = implementor.visitChild(this, 0, getInput()); org.apache.drill.common.logical.data.Window.Builder builder = new org.apache.drill.common.logical.data.Window.Builder(); final List<String> fields = getRowType().getFieldNames(); final List<String> childFields = getInput().getRowType().getFieldNames(); for (Group window : groups) { for(RelFieldCollation orderKey : window.orderKeys.getFieldCollations()) { builder.addOrdering(new Order.Ordering(orderKey.getDirection(), new FieldReference(fields.get(orderKey.getFieldIndex())))); } for (int group : BitSets.toIter(window.keys)) { FieldReference fr = new FieldReference(childFields.get(group), ExpressionPosition.UNKNOWN); builder.addWithin(fr, fr); } int groupCardinality = window.keys.cardinality(); for (Ord<AggregateCall> aggCall : Ord.zip(window.getAggregateCalls(this))) { FieldReference ref = new FieldReference(fields.get(groupCardinality + aggCall.i)); LogicalExpression expr = toDrill(aggCall.e, childFields); builder.addAggregation(ref, expr); } } builder.setInput(inputOp); org.apache.drill.common.logical.data.Window frame = builder.build(); return frame; }
@Override public LogicalOperator implement(LogicalPlanImplementor implementor) { final LogicalOperator inputOp = implementor.visitChild(this, 0, getInput()); com.dremio.common.logical.data.Window.Builder builder = new com.dremio.common.logical.data.Window.Builder(); final List<String> fields = getRowType().getFieldNames(); final List<String> childFields = getInput().getRowType().getFieldNames(); for (Group window : groups) { for(RelFieldCollation orderKey : window.orderKeys.getFieldCollations()) { builder.addOrdering(new Order.Ordering(orderKey.getDirection(), new FieldReference(fields.get(orderKey.getFieldIndex())))); } for (int group : BitSets.toIter(window.keys)) { FieldReference fr = new FieldReference(childFields.get(group)); builder.addWithin(fr, fr); } int groupCardinality = window.keys.cardinality(); for (Ord<AggregateCall> aggCall : Ord.zip(window.getAggregateCalls(this))) { FieldReference ref = new FieldReference(fields.get(groupCardinality + aggCall.i)); LogicalExpression expr = toExpr(aggCall.e, childFields); builder.addAggregation(ref, expr); } } builder.setInput(inputOp); com.dremio.common.logical.data.Window frame = builder.build(); return frame; }
public Group( ImmutableBitSet keys, boolean isRows, RexWindowBound lowerBound, RexWindowBound upperBound, RelCollation orderKeys, List<RexWinAggCall> aggCalls) { assert orderKeys != null : "precondition: ordinals != null"; assert keys != null; this.keys = keys; this.isRows = isRows; this.lowerBound = lowerBound; this.upperBound = upperBound; this.orderKeys = orderKeys; this.aggCalls = ImmutableList.copyOf(aggCalls); this.digest = computeString(); }
public Group( ImmutableBitSet keys, boolean isRows, RexWindowBound lowerBound, RexWindowBound upperBound, RelCollation orderKeys, List<RexWinAggCall> aggCalls) { assert orderKeys != null : "precondition: ordinals != null"; assert keys != null; this.keys = keys; this.isRows = isRows; this.lowerBound = lowerBound; this.upperBound = upperBound; this.orderKeys = orderKeys; this.aggCalls = ImmutableList.copyOf(aggCalls); this.digest = computeString(); }
private Pair<Expression, Expression> getRowCollationKey( BlockBuilder builder, PhysType inputPhysType, Group group, int windowIdx) { if (!(group.isRows || (group.upperBound.isUnbounded() && group.lowerBound.isUnbounded()))) { Pair<Expression, Expression> pair = inputPhysType.generateCollationKey( group.collation().getFieldCollations()); // optimize=false to prevent inlining of object create into for-loops return Pair.of( builder.append("keySelector" + windowIdx, pair.left, false), builder.append("keyComparator" + windowIdx, pair.right, false)); } else { return Pair.of(null, null); } }