Java Code Examples for org.apache.calcite.util.Util#range()

The following examples show how to use org.apache.calcite.util.Util#range() . 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: RelBuilder.java    From Bats with Apache License 2.0 5 votes vote down vote up
/** Returns references to the fields of a given input. */
public ImmutableList<RexNode> fields(int inputCount, int inputOrdinal) {
    final RelNode input = peek(inputCount, inputOrdinal);
    final RelDataType rowType = input.getRowType();
    final ImmutableList.Builder<RexNode> nodes = ImmutableList.builder();
    for (int fieldOrdinal : Util.range(rowType.getFieldCount())) {
        nodes.add(field(inputCount, inputOrdinal, fieldOrdinal));
    }
    return nodes.build();
}
 
Example 2
Source File: RelBuilder.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Returns references to the fields of a given input. */
public ImmutableList<RexNode> fields(int inputCount, int inputOrdinal) {
  final RelNode input = peek(inputCount, inputOrdinal);
  final RelDataType rowType = input.getRowType();
  final ImmutableList.Builder<RexNode> nodes = ImmutableList.builder();
  for (int fieldOrdinal : Util.range(rowType.getFieldCount())) {
    nodes.add(field(inputCount, inputOrdinal, fieldOrdinal));
  }
  return nodes.build();
}
 
Example 3
Source File: PigRelBuilder.java    From calcite with Apache License 2.0 5 votes vote down vote up
public PigRelBuilder group(GroupOption option, Partitioner partitioner,
    int parallel, Iterable<? extends GroupKey> groupKeys) {
  @SuppressWarnings("unchecked") final List<GroupKeyImpl> groupKeyList =
      ImmutableList.copyOf((Iterable) groupKeys);
  validateGroupList(groupKeyList);

  final int groupCount = groupKeyList.get(0).nodes.size();
  final int n = groupKeyList.size();
  for (Ord<GroupKeyImpl> groupKey : Ord.reverse(groupKeyList)) {
    RelNode r = null;
    if (groupKey.i < n - 1) {
      r = build();
    }
    // Create a ROW to pass to COLLECT. Interestingly, this is not allowed
    // by standard SQL; see [CALCITE-877] Allow ROW as argument to COLLECT.
    final RexNode row =
        cluster.getRexBuilder().makeCall(peek(1, 0).getRowType(),
            SqlStdOperatorTable.ROW, fields());
    aggregate(groupKey.e,
        aggregateCall(SqlStdOperatorTable.COLLECT, row).as(getAlias()));
    if (groupKey.i < n - 1) {
      push(r);
      List<RexNode> predicates = new ArrayList<>();
      for (int key : Util.range(groupCount)) {
        predicates.add(equals(field(2, 0, key), field(2, 1, key)));
      }
      join(JoinRelType.INNER, and(predicates));
    }
  }
  return this;
}
 
Example 4
Source File: SameOperandTypeChecker.java    From Bats with Apache License 2.0 4 votes vote down vote up
protected List<Integer> getOperandList(int operandCount) {
  return nOperands == -1
      ? Util.range(0, operandCount)
      : Util.range(0, nOperands);
}
 
Example 5
Source File: SameOperandTypeChecker.java    From calcite with Apache License 2.0 4 votes vote down vote up
protected List<Integer> getOperandList(int operandCount) {
  return nOperands == -1
      ? Util.range(0, operandCount)
      : Util.range(0, nOperands);
}