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

The size of REAL, DOUBLE, and FLOAT is not consistent

    XMLWordPrintableJSON

Details

    Description

      This stems from the review of CALCITE-6052

      Which one is 8 bytes and which one is 4 bytes?

      The intent seems to be that DOUBLE and FLOAT are synonyms, both using 8 bytes, (which is very weird for Java users), and REAL is 4 bytes.

      But an audit of the code shows that:

      In AggregateNode.maxMinClass:

          case FLOAT:
            return max ? MaxFloat.class : MinFloat.class;
          case DOUBLE:
          case REAL:
            return max ? MaxDouble.class : MinDouble.class;
      

      In VisitorDataContext:

           case DOUBLE:
              return Pair.of(index, rexLiteral.getValueAs(Double.class));
            case REAL:
              return Pair.of(index, rexLiteral.getValueAs(Float.class));
      

      (no case for FLOAT)

      In RelMdSize:

         case FLOAT:
          case REAL:
         ....
            return 4d;
      

      in RelDataTypeFactoryImpl:

          case REAL:
            return createSqlType(SqlTypeName.DECIMAL, 14, 7);
          case FLOAT:
            return createSqlType(SqlTypeName.DECIMAL, 14, 7);
          case DOUBLE:
            // the default max precision is 19, so this is actually DECIMAL(19, 15)
            // but derived system can override the max precision/scale.
            return createSqlType(SqlTypeName.DECIMAL, 30, 15);
      

      The reference.md itself seems to be wrong:

      | REAL, FLOAT | 4 byte floating point     | 6 decimal digits precision.  
      | DOUBLE      | 8 byte floating point     | 15 decimal digits precision.
      

      and there are many more I haven't even checked!

      Attachments

        Issue Links

          Activity

            People

              mbudiu Mihai Budiu
              mbudiu Mihai Budiu
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: