Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-3411

Incorrect code generated for BigDecimal ConstantExpression

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.21.0
    • Fix Version/s: 1.22.0
    • Component/s: None

      Description

      In current implementation

      Expressions.constant("104", BigDecimal.class) -> new java.math.BigDecimal(104L)
      Expressions.constant("1000", BigDecimal.class) -> new java.math.BigDecimal(1L, -3)

      However, in java.math.BigDecimal, there is no constructor:

      java.math.BigDecimal(long exact, int scale) 

      Instead we should call method

       java.math.BigDecimal.valueOf(long exact, int scale)

      Why this issue did not exposed before?

      BlockBuilder conducts optimizations that can bury this issue.
      For example, when we disable the optimization. MaterializationTest#testAggregateMaterializationAggregateFuncs11 will produce the code below. However, it can't pass the compilation.

      final long v = org.apache.calcite.runtime.SqlFunctions.floor(853763696000L, ((Long) new java.math.BigDecimal(1L, -3)).longValue());

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                donnyzone Feng Zhu
                Reporter:
                donnyzone Feng Zhu
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h
                  1h