private RelNode copyOf(LogicalWindow window) { final RelNode input = window.getInput().accept(this); return new LogicalWindow( cluster, copyOf(window.getTraitSet()), input, Lists.transform(window.constants, COPY_REX_LITERAL), copyOf(window.getRowType()), window.groups ); }
protected RelNode makeRel(RelOptCluster cluster, RelTraitSet traitSet, RelBuilder relBuilder, RelNode input, RexProgram program) { Preconditions.checkArgument(program.getCondition() == null, "WindowedAggregateRel cannot accept a condition"); return LogicalWindow.create(cluster, traitSet, relBuilder, input, program); } }
@Override public LogicalWindow copy(RelTraitSet traitSet, List<RelNode> inputs) { return new LogicalWindow(getCluster(), traitSet, sole(inputs), constants, rowType, groups); }
public RelNode convert(RelNode rel) { final LogicalWindow winAgg = (LogicalWindow) rel; final RelTraitSet traitSet = winAgg.getTraitSet().replace(BindableConvention.INSTANCE); final RelNode input = winAgg.getInput(); final RelNode convertedInput = convert(input, input.getTraitSet().replace(BindableConvention.INSTANCE)); return new BindableWindow(rel.getCluster(), traitSet, convertedInput, winAgg.getConstants(), winAgg.getRowType(), winAgg.groups); } }
@Override public void onMatch(RelOptRuleCall call) { final LogicalProject project = call.rel(0); final LogicalWindow window = call.rel(1); final RelOptCluster cluster = window.getCluster(); final List<RelDataTypeField> rowTypeWindowInput = window.getInput().getRowType().getFieldList(); final int windowInputColumn = rowTypeWindowInput.size(); new LogicalProject(cluster, window.getTraitSet(), window.getInput(), exps, builder.build()); window.getRowType().getFieldList().get(aggCallIndex); outputBuilder.add(relDataTypeField); ++aggCallIndex; LogicalWindow.create(window.getTraitSet(), projectBelowWindow, window.constants, outputBuilder.build(), groups); newLogicalWindow.getTraitSet(), newLogicalWindow, topProjExps,
final RexOver newOver = (RexOver) origOver.accept(replaceConstants); origToNewOver.put(origOver, newOver); addWindows(windowMap, newOver, inputFieldCount); over.getAggOperator(), over.getType(), toInputRefs(over.operands), aggMap.size(), over.isDistinct()); LogicalWindow.create(traitSet, child, constants, intermediateRowType, groups); rexNodesWindow.add(rexNode.accept(shuttle)); final List<RexNode> refToWindow = toInputRefs(rexNodesWindow);
@SuppressWarnings("unused") // Called through reflection public Set<RelColumnOrigin> getColumnOrigins(LogicalWindow window, RelMetadataQuery mq, int iOutputColumn) { final RelNode inputRel = window.getInput(); final int numFieldsInInput = inputRel.getRowType().getFieldCount(); if (iOutputColumn < numFieldsInInput) { if (iOutputColumn >= window.getRowType().getFieldCount()) { return Collections.emptySet();
private static void addWindows( Multimap<WindowKey, RexOver> windowMap, RexOver over, final int inputFieldCount) { final RexWindow aggWindow = over.getWindow(); // Look up or create a window. RelCollation orderKeys = getCollation( Lists.newArrayList( Util.filter(aggWindow.orderKeys, rexFieldCollation -> // If ORDER BY references constant (i.e. RexInputRef), // then we can ignore such ORDER BY key. rexFieldCollation.left instanceof RexLocalRef))); ImmutableBitSet groupSet = ImmutableBitSet.of(getProjectOrdinals(aggWindow.partitionKeys)); final int groupLength = groupSet.length(); if (inputFieldCount < groupLength) { // If PARTITION BY references constant, we can ignore such partition key. // All the inputs after inputFieldCount are literals, thus we can clear. groupSet = groupSet.except(ImmutableBitSet.range(inputFieldCount, groupLength)); } WindowKey windowKey = new WindowKey( groupSet, orderKeys, aggWindow.isRows(), aggWindow.getLowerBound(), aggWindow.getUpperBound()); windowMap.put(windowKey, over); } }
/** * Creates a LogicalWindow. * * @param input Input relational expression * @param traitSet Trait set * @param constants List of constants that are additional inputs * @param rowType Output row type * @param groups Window groups */ public static LogicalWindow create(RelTraitSet traitSet, RelNode input, List<RexLiteral> constants, RelDataType rowType, List<Group> groups) { return new LogicalWindow(input.getCluster(), traitSet, input, constants, rowType, groups); }
private ImmutableBitSet findReference(final LogicalProject project, final LogicalWindow window) { final int windowInputColumn = window.getInput().getRowType().getFieldCount(); final ImmutableBitSet.Builder beReferred = ImmutableBitSet.builder();
@Override public void onMatch(RelOptRuleCall call) { final LogicalProject project = call.rel(0); final LogicalWindow window = call.rel(1); final RelOptCluster cluster = window.getCluster(); final List<RelDataTypeField> rowTypeWindowInput = window.getInput().getRowType().getFieldList(); final int windowInputColumn = rowTypeWindowInput.size(); new LogicalProject(cluster, window.getTraitSet(), window.getInput(), exps, builder.build()); window.getRowType().getFieldList().get(aggCallIndex); outputBuilder.add(relDataTypeField); ++aggCallIndex; LogicalWindow.create(window.getTraitSet(), projectBelowWindow, window.constants, outputBuilder.build(), groups); newLogicalWindow.getTraitSet(), newLogicalWindow, topProjExps,
public RelNode convert(RelNode rel) { final LogicalWindow winAgg = (LogicalWindow) rel; final RelTraitSet traitSet = winAgg.getTraitSet().replace(EnumerableConvention.INSTANCE); final RelNode child = winAgg.getInput(); final RelNode convertedChild = convert(child, child.getTraitSet().replace(EnumerableConvention.INSTANCE)); return new EnumerableWindow(rel.getCluster(), traitSet, convertedChild, winAgg.getConstants(), winAgg.getRowType(), winAgg.groups); } }
final RexOver newOver = (RexOver) origOver.accept(replaceConstants); origToNewOver.put(origOver, newOver); addWindows(windowMap, newOver, inputFieldCount); over.getAggOperator(), over.getType(), toInputRefs(over.operands), aggMap.size(), over.isDistinct()); LogicalWindow.create(traitSet, child, constants, intermediateRowType, groups); rexNodesWindow.add(rexNode.accept(shuttle)); final List<RexNode> refToWindow = toInputRefs(rexNodesWindow);
private static void addWindows( Multimap<WindowKey, RexOver> windowMap, RexOver over, final int inputFieldCount) { final RexWindow aggWindow = over.getWindow(); // Look up or create a window. RelCollation orderKeys = getCollation( Lists.newArrayList( Util.filter(aggWindow.orderKeys, rexFieldCollation -> // If ORDER BY references constant (i.e. RexInputRef), // then we can ignore such ORDER BY key. rexFieldCollation.left instanceof RexLocalRef))); ImmutableBitSet groupSet = ImmutableBitSet.of(getProjectOrdinals(aggWindow.partitionKeys)); final int groupLength = groupSet.length(); if (inputFieldCount < groupLength) { // If PARTITION BY references constant, we can ignore such partition key. // All the inputs after inputFieldCount are literals, thus we can clear. groupSet = groupSet.except(ImmutableBitSet.range(inputFieldCount, groupLength)); } WindowKey windowKey = new WindowKey( groupSet, orderKeys, aggWindow.isRows(), aggWindow.getLowerBound(), aggWindow.getUpperBound()); windowMap.put(windowKey, over); } }
/** * Creates a LogicalWindow. * * @param input Input relational expression * @param traitSet Trait set * @param constants List of constants that are additional inputs * @param rowType Output row type * @param groups Window groups */ public static LogicalWindow create(RelTraitSet traitSet, RelNode input, List<RexLiteral> constants, RelDataType rowType, List<Group> groups) { return new LogicalWindow(input.getCluster(), traitSet, input, constants, rowType, groups); }
private ImmutableBitSet findReference(final LogicalProject project, final LogicalWindow window) { final int windowInputColumn = window.getInput().getRowType().getFieldCount(); final ImmutableBitSet.Builder beReferred = ImmutableBitSet.builder();
final RelDataType rowType = window.getRowType(); final int fieldCount = rowType.getFieldCount(); final RelNode input = window.getInput(); final int inputFieldCount = input.getRowType().getFieldCount(); final RelDataType newRowType = RelOptUtil.permute(window.getCluster().getTypeFactory(), rowType, permutationMapping); final LogicalWindow newWindow = LogicalWindow.create(window.getTraitSet(), newInput, newConstants, newRowType, newGroups); return result(newWindow, mapping);
public RelNode convert(RelNode rel) { final LogicalWindow winAgg = (LogicalWindow) rel; final RelTraitSet traitSet = winAgg.getTraitSet().replace(EnumerableConvention.INSTANCE); final RelNode child = winAgg.getInput(); final RelNode convertedChild = convert(child, child.getTraitSet().replace(EnumerableConvention.INSTANCE)); return new EnumerableWindow(rel.getCluster(), traitSet, convertedChild, winAgg.getConstants(), winAgg.getRowType(), winAgg.groups); } }
@Override public LogicalWindow copy(RelTraitSet traitSet, List<RelNode> inputs) { return new LogicalWindow(getCluster(), traitSet, sole(inputs), constants, rowType, groups); }
protected RelNode makeRel(RelOptCluster cluster, RelTraitSet traitSet, RelBuilder relBuilder, RelNode input, RexProgram program) { Preconditions.checkArgument(program.getCondition() == null, "WindowedAggregateRel cannot accept a condition"); return LogicalWindow.create(cluster, traitSet, relBuilder, input, program); } }