Java Code Examples for org.apache.calcite.sql.SqlWindow#setUpperBound()

The following examples show how to use org.apache.calcite.sql.SqlWindow#setUpperBound() . 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: SqlImplementor.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
public List<SqlNode> toSql(Window.Group group, ImmutableList<RexLiteral> constants,
                           int inputFieldCount) {
  final List<SqlNode> rexOvers = new ArrayList<>();
  final List<SqlNode> partitionKeys = new ArrayList<>();
  final List<SqlNode> orderByKeys = new ArrayList<>();
  for (int partition : group.keys) {
    partitionKeys.add(this.field(partition));
  }
  for (RelFieldCollation collation : group.orderKeys.getFieldCollations()) {
    this.addOrderItem(orderByKeys, collation);
  }
  SqlLiteral isRows = SqlLiteral.createBoolean(group.isRows, POS);
  SqlNode lowerBound = null;
  SqlNode upperBound = null;

  final SqlLiteral allowPartial = null;

  for (Window.RexWinAggCall winAggCall : group.aggCalls) {
    SqlAggFunction aggFunction = (SqlAggFunction) winAggCall.getOperator();
    final SqlWindow sqlWindow = SqlWindow.create(null, null,
      new SqlNodeList(partitionKeys, POS), new SqlNodeList(orderByKeys, POS),
      isRows, lowerBound, upperBound, allowPartial, POS);
    if (aggFunction.allowsFraming()) {
      lowerBound = createSqlWindowBound(group.lowerBound);
      upperBound = createSqlWindowBound(group.upperBound);
      sqlWindow.setLowerBound(lowerBound);
      sqlWindow.setUpperBound(upperBound);
    }

    RexShuttle replaceConstants = new RexShuttle() {
      @Override
      public RexNode visitInputRef(RexInputRef inputRef) {
        int index = inputRef.getIndex();
        RexNode ref;
        if (index > inputFieldCount - 1) {
          ref = constants.get(index - inputFieldCount);
        } else {
          ref = inputRef;
        }
        return ref;
      }
    };
    RexCall aggCall = (RexCall) winAggCall.accept(replaceConstants);
    List<SqlNode> operands = toSql(null, aggCall.operands);
    rexOvers.add(createOverCall(aggFunction, operands, sqlWindow));
  }
  return rexOvers;
}
 
Example 2
Source File: SqlImplementor.java    From calcite with Apache License 2.0 4 votes vote down vote up
public List<SqlNode> toSql(Window.Group group, ImmutableList<RexLiteral> constants,
    int inputFieldCount) {
  final List<SqlNode> rexOvers = new ArrayList<>();
  final List<SqlNode> partitionKeys = new ArrayList<>();
  final List<SqlNode> orderByKeys = new ArrayList<>();
  for (int partition: group.keys) {
    partitionKeys.add(this.field(partition));
  }
  for (RelFieldCollation collation: group.orderKeys.getFieldCollations()) {
    this.addOrderItem(orderByKeys, collation);
  }
  SqlLiteral isRows = SqlLiteral.createBoolean(group.isRows, POS);
  SqlNode lowerBound = null;
  SqlNode upperBound = null;

  final SqlLiteral allowPartial = null;

  for (Window.RexWinAggCall winAggCall: group.aggCalls) {
    SqlAggFunction aggFunction = (SqlAggFunction) winAggCall.getOperator();
    final SqlWindow sqlWindow = SqlWindow.create(null, null,
            new SqlNodeList(partitionKeys, POS), new SqlNodeList(orderByKeys, POS),
            isRows, lowerBound, upperBound, allowPartial, POS);
    if (aggFunction.allowsFraming()) {
      lowerBound = createSqlWindowBound(group.lowerBound);
      upperBound = createSqlWindowBound(group.upperBound);
      sqlWindow.setLowerBound(lowerBound);
      sqlWindow.setUpperBound(upperBound);
    }

    RexShuttle replaceConstants = new RexShuttle() {
      @Override public RexNode visitInputRef(RexInputRef inputRef) {
        int index = inputRef.getIndex();
        RexNode ref;
        if (index > inputFieldCount - 1) {
          ref = constants.get(index - inputFieldCount);
        } else {
          ref = inputRef;
        }
        return ref;
      }
    };
    RexCall aggCall = (RexCall) winAggCall.accept(replaceConstants);
    List<SqlNode> operands = toSql(null, aggCall.operands);
    rexOvers.add(createOverCall(aggFunction, operands, sqlWindow));
  }
  return rexOvers;
}