org.apache.calcite.rel.logical.LogicalWindow Java Examples

The following examples show how to use org.apache.calcite.rel.logical.LogicalWindow. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CopyWithCluster.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
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
  );
}
 
Example #2
Source File: CopyWithCluster.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public RelNode visit(RelNode other) {
  if (other instanceof CopyToCluster) {
    return ((CopyToCluster) other).copyWith(this);
  } else if (other instanceof LogicalWindow) {
    return copyOf((LogicalWindow) other);
  }

  notSupported(other);
  return super.visit(other);
}
 
Example #3
Source File: ProjectWindowTransposeRule.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * Creates ProjectWindowTransposeRule.
 *
 * @param relBuilderFactory Builder for relational expressions
 */
public ProjectWindowTransposeRule(RelBuilderFactory relBuilderFactory) {
  super(
      operand(LogicalProject.class,
          operand(LogicalWindow.class, any())),
      relBuilderFactory, null);
}
 
Example #4
Source File: EnumerableWindowRule.java    From calcite with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #5
Source File: Bindables.java    From calcite with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #6
Source File: RelMdColumnOrigins.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@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) {
    return mq.getColumnOrigins(inputRel, iOutputColumn);
  }

  if (iOutputColumn >= window.getRowType().getFieldCount()) {
    return Collections.emptySet();
  }

  int startGroupIdx = iOutputColumn - numFieldsInInput;
  int curentIdx = 0;
  Group finalGroup = null;
  for (Group group : window.groups) {
    curentIdx += group.aggCalls.size();
    if (curentIdx > startGroupIdx) {
      // this is the group
      finalGroup = group;
      break;
    }
  }
  Preconditions.checkNotNull(finalGroup);
  // calculating index of the aggCall within a group
  // currentIdx = through idx within groups/aggCalls (max currentIdx = sum(groups size * aggCals_per_group) )
  // since currentIdx at this moment points to the end of the group substracting aggCals_per_group
  // to get to the beginning of the group and have startGroupIdx substract the diff
  final int aggCalIdx = startGroupIdx - (curentIdx - finalGroup.aggCalls.size());
  Preconditions.checkElementIndex(aggCalIdx, finalGroup.aggCalls.size());

  final Set<RelColumnOrigin> set = new HashSet<>();
  // Add aggregation column references
  final RexWinAggCall aggCall = finalGroup.aggCalls.get(aggCalIdx);
  for (RexNode operand : aggCall.operands) {
    if (operand instanceof RexInputRef) {
      final RexInputRef opInputRef = (RexInputRef) operand;
      if (opInputRef.getIndex() < numFieldsInInput) {
        Set<RelColumnOrigin> inputSet =
          mq.getColumnOrigins(inputRel, opInputRef.getIndex());
        inputSet = createDerivedColumnOrigins(inputSet);
        if (inputSet != null) {
          set.addAll(inputSet);
        }
      }
    }
  }

  return set;
}
 
Example #7
Source File: WindowRule.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
private WindowRule() {
  super(RelOptHelper.some(LogicalWindow.class, Convention.NONE, RelOptHelper.any(RelNode.class)), "WindowRule");
}
 
Example #8
Source File: EnumerableWindowRule.java    From calcite with Apache License 2.0 4 votes vote down vote up
EnumerableWindowRule() {
  super(LogicalWindow.class, Convention.NONE, EnumerableConvention.INSTANCE,
      "EnumerableWindowRule");
}
 
Example #9
Source File: Bindables.java    From calcite with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a BindableWindowRule.
 *
 * @param relBuilderFactory Builder for relational expressions
 */
public BindableWindowRule(RelBuilderFactory relBuilderFactory) {
  super(LogicalWindow.class, (Predicate<RelNode>) r -> true,
      Convention.NONE, BindableConvention.INSTANCE, relBuilderFactory,
      "BindableWindowRule");
}
 
Example #10
Source File: ProjectWindowTransposeRule.java    From Bats with Apache License 2.0 2 votes vote down vote up
/**
 * Creates ProjectWindowTransposeRule.
 *
 * @param relBuilderFactory Builder for relational expressions
 */
public ProjectWindowTransposeRule(RelBuilderFactory relBuilderFactory) {
    super(operand(LogicalProject.class, operand(LogicalWindow.class, any())), relBuilderFactory, null);
}