Java Code Examples for org.apache.calcite.linq4j.tree.Expressions#add()

The following examples show how to use org.apache.calcite.linq4j.tree.Expressions#add() . 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: RexImpTable.java    From calcite with Apache License 2.0 6 votes vote down vote up
public Expression implementResult(AggContext info,
    AggResultContext result) {
  WinAggResultContext winResult = (WinAggResultContext) result;

  List<RexNode> rexArgs = winResult.rexArguments();

  Expression tiles =
      winResult.rowTranslator(winResult.index()).translate(
          rexArgs.get(0), int.class);

  Expression ntile =
      Expressions.add(Expressions.constant(1),
          Expressions.divide(
              Expressions.multiply(
                  tiles,
                  Expressions.subtract(
                      winResult.index(), winResult.startIndex())),
              winResult.getPartitionRowCount()));

  return ntile;
}
 
Example 2
Source File: RexImpTable.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override public void implementNotNullAdd(AggContext info,
    AggAddContext add) {
  Expression acc = add.accumulator().get(0);
  Expression next;
  if (info.returnType() == BigDecimal.class) {
    next = Expressions.call(acc, "add", add.arguments().get(0));
  } else {
    next = Expressions.add(acc,
        EnumUtils.convert(add.arguments().get(0), acc.type));
  }
  accAdvance(add, acc, next);
}
 
Example 3
Source File: RexImpTable.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override protected Expression implementNotNullResult(
    WinAggContext info, WinAggResultContext result) {
  // Window cannot be empty since ROWS/RANGE is not possible for ROW_NUMBER
  return Expressions.add(
      Expressions.subtract(result.index(), result.startIndex()),
      Expressions.constant(1));
}
 
Example 4
Source File: ExpressionTest.java    From calcite with Apache License 2.0 4 votes vote down vote up
@Test void testEvaluate() {
  Expression x = Expressions.add(ONE, TWO);
  Object value = Expressions.evaluate(x);
  assertThat(value, is(3));
}
 
Example 5
Source File: RexImpTable.java    From calcite with Apache License 2.0 4 votes vote down vote up
@Override protected Expression implementNotNullResult(
    WinAggContext info, WinAggResultContext result) {
  // Rank is 1-based
  return Expressions.add(super.implementNotNullResult(info, result),
      Expressions.constant(1));
}
 
Example 6
Source File: RexImpTable.java    From calcite with Apache License 2.0 4 votes vote down vote up
@Override protected Expression computeNewRank(Expression acc,
    WinAggAddContext add) {
  return Expressions.add(acc, Expressions.constant(1));
}