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

CURRENT_TIMESTAMP(P) ignores DataTypeSystem#getMaxPrecision

    XMLWordPrintableJSON

Details

    Description

      Datetime precision parameters are incorrectly validated against the DEFAULT maximum date time precision (3) instead of against the maximum date time precision configured by the DateTimeSystem#getMaxPrecision method.

      This breaks, at minimum, CURRENT_TIMESTAMP(P > 3) when precisions greater than 3 are supported by the system.

      The culprit is the following method in SqlAbstractTimeFunction

       

      @Override public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
          // REVIEW jvs 20-Feb-2005: Need to take care of time zones.
          int precision = 0;
          if (opBinding.getOperandCount() == 1) {
              RelDataType type = opBinding.getOperandType(0);
              if (SqlTypeUtil.isNumeric(type)) {
                  precision = getOperandLiteralValueOrThrow(opBinding, 0, Integer.class);
              }
          }
          assert precision >= 0;
          if (precision > SqlTypeName.MAX_DATETIME_PRECISION) {
              throw opBinding.newError(
                  RESOURCE.argumentMustBeValidPrecision(
                  opBinding.getOperator().getName(), 0,
                  SqlTypeName.MAX_DATETIME_PRECISION));
          }
          return opBinding.getTypeFactory().createSqlType(typeName, precision);
      }

       

       

      The correct value is readily accessible from

       

      opBinding.getTypeFactory().getTypeSystem().getMaxPrecision(typeName)

       

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              adamkennedy77 Adam Kennedy
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: