org.apache.calcite.rel.type.RelDataTypeFactory.useDoubleMultiplication()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(2.3k)|赞(0)|评价(0)|浏览(102)

本文整理了Java中org.apache.calcite.rel.type.RelDataTypeFactory.useDoubleMultiplication方法的一些代码示例,展示了RelDataTypeFactory.useDoubleMultiplication的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RelDataTypeFactory.useDoubleMultiplication方法的具体详情如下:
包路径:org.apache.calcite.rel.type.RelDataTypeFactory
类名称:RelDataTypeFactory
方法名:useDoubleMultiplication

RelDataTypeFactory.useDoubleMultiplication介绍

[英]Returns whether a decimal multiplication should be implemented by casting arguments to double values.

Pre-condition: createDecimalProduct(type1, type2) != null
[中]

代码示例

代码示例来源:origin: Qihoo360/Quicksql

private RexNode expandTimes(RexCall call, List<RexNode> operands) {
 // Multiplying the internal values of the two arguments leads to
 // a number with scale = scaleA + scaleB. If the result type has
 // a lower scale, then the number should be scaled down.
 int divisor = scaleA + scaleB - call.getType().getScale();
 if (builder.getTypeFactory().useDoubleMultiplication(
   typeA,
   typeB)) {
  // Approximate implementation:
  // cast (a as double) * cast (b as double)
  //     / 10^divisor
  RexNode division =
    makeDivide(
      makeMultiply(
        ensureType(real8, accessValue(operands.get(0))),
        ensureType(real8, accessValue(operands.get(1)))),
      makeApproxLiteral(BigDecimal.TEN.pow(divisor)));
  return encodeValue(division, call.getType(), true);
 } else {
  // Exact implementation: scaleDown(a * b)
  return encodeValue(
    scaleDown(
      builder.makeCall(
        call.getOperator(),
        accessValue(operands.get(0)),
        accessValue(operands.get(1))),
      divisor),
    call.getType());
 }
}

代码示例来源:origin: org.apache.calcite/calcite-core

private RexNode expandTimes(RexCall call, List<RexNode> operands) {
 // Multiplying the internal values of the two arguments leads to
 // a number with scale = scaleA + scaleB. If the result type has
 // a lower scale, then the number should be scaled down.
 int divisor = scaleA + scaleB - call.getType().getScale();
 if (builder.getTypeFactory().useDoubleMultiplication(
   typeA,
   typeB)) {
  // Approximate implementation:
  // cast (a as double) * cast (b as double)
  //     / 10^divisor
  RexNode division =
    makeDivide(
      makeMultiply(
        ensureType(real8, accessValue(operands.get(0))),
        ensureType(real8, accessValue(operands.get(1)))),
      makeApproxLiteral(BigDecimal.TEN.pow(divisor)));
  return encodeValue(division, call.getType(), true);
 } else {
  // Exact implementation: scaleDown(a * b)
  return encodeValue(
    scaleDown(
      builder.makeCall(
        call.getOperator(),
        accessValue(operands.get(0)),
        accessValue(operands.get(1))),
      divisor),
    call.getType());
 }
}

相关文章