Uploaded image for project: 'Apache Drill'
  1. Apache Drill
  2. DRILL-6376

Doc: Return type of ROUND(x, y), TRUNC(x, y), TO_NUMBER is wrong

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 1.13.0
    • None
    • None

    Description

      The documentation for math functions claims that the return value of ROUND(x, y) and TRUNC(x, y) is DECIMAL. A test shows that this is not true:

      SELECT typeof(ROUND(a, 2)) FROM (VALUES (1.2345)) AS T(a);
      +---------+
      | EXPR$0  |
      +---------+
      | FLOAT8  |
      +---------+
      SELECT typeof(TRUNC(a, 2)) FROM (VALUES (1.2345)) AS T(a);
      +---------+
      | EXPR$0  |
      +---------+
      | FLOAT8  |
      +---------+
      

      Maybe it is DECIMAL only if we enable decimal type? Let's try:

      ALTER SESSION SET `planner.enable_decimal_data_type` = true;
      SELECT typeof(TRUNC(a, 2)) FROM (VALUES (1.2345)) AS T(a);
      +---------+
      | EXPR$0  |
      +---------+
      | FLOAT8  |
      +---------+
      

      So, ROUND() and TRUNC() actually return DOUBLE.

      The type convertion documentation says that TO_NUMBER(str, fmt) returns DECIMAL. Let's try:

      ALTER SESSION SET `planner.enable_decimal_data_type` = true;
      SELECT typeof(TO_NUMBER(a, '0')) FROM (VALUES ('1')) AS T(a);
      +---------+
      | EXPR$0  |
      +---------+
      | FLOAT8  |
      +---------+
      

      So, TO_NUMBER() actually returns DOUBLE.

      Attachments

        Activity

          People

            bbevens Bridget Bevens
            paul-rogers Paul Rogers
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: