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

The following examples show how to use org.apache.calcite.linq4j.tree.Expressions#multiply() . 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
/** Multiplies an expression by a constant and divides by another constant,
 * optimizing appropriately.
 *
 * <p>For example, {@code multiplyDivide(e, 10, 1000)} returns
 * {@code e / 100}. */
public static Expression multiplyDivide(Expression e, BigDecimal multiplier,
    BigDecimal divider) {
  if (multiplier.equals(BigDecimal.ONE)) {
    if (divider.equals(BigDecimal.ONE)) {
      return e;
    }
    return Expressions.divide(e,
        Expressions.constant(divider.intValueExact()));
  }
  final BigDecimal x =
      multiplier.divide(divider, RoundingMode.UNNECESSARY);
  switch (x.compareTo(BigDecimal.ONE)) {
  case 0:
    return e;
  case 1:
    return Expressions.multiply(e, Expressions.constant(x.intValueExact()));
  case -1:
    return multiplyDivide(e, BigDecimal.ONE, x);
  default:
    throw new AssertionError();
  }
}
 
Example 2
Source File: RexToLixTranslator.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * For {@code PREV} operator, the offset of {@code inputGetter}
 * should be set first
 */
private Result implementPrev(RexCall call) {
  final RexNode node = call.getOperands().get(0);
  final RexNode offset = call.getOperands().get(1);
  final Expression offs = Expressions.multiply(translate(offset),
          Expressions.constant(-1));
  ((EnumerableMatch.PrevInputGetter) inputGetter).setOffset(offs);
  return node.accept(this);
}