Uploaded image for project: 'IMPALA'
  1. IMPALA
  2. IMPALA-999 Casting (legally) to decimal is broken.
  3. IMPALA-974

cast(float/double to Decimal(x,y)) yields unexpected results.

    XMLWordPrintableJSON

Details

    • Sub-task
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • Impala 1.4
    • Impala 1.4
    • None

    Description

      Consider the following sequence:

      [localhost:21000] > describe foo;
      Query: describe foo
      +------+----------------+---------+
      | name | type           | comment |
      +------+----------------+---------+
      | d    | decimal(38,38) |         |
      +------+----------------+---------+
      Returned 1 row(s) in 1.00s
      [localhost:21000] > insert into foo values(cast(0.1 as Decimal(38,38)));
      Query: insert into foo values(cast(0.1 as Decimal(38,38)))
      Inserted 1 rows in 0.38s
      [localhost:21000] > select * from foo;
      Query: select * from foo
      +------------------------------------------+
      | d                                        |
      +------------------------------------------+
      | 0.09999999999999998358171037484709838848 |
      +------------------------------------------+
      Returned 1 row(s) in 0.44s
      [localhost:21000] > insert into foo values(cast("0.1" as Decimal(38,38)));
      Query: insert into foo values(cast("0.1" as Decimal(38,38)))
      Inserted 1 rows in 0.38s
      [localhost:21000] > select * from foo;
      Query: select * from foo
      +------------------------------------------+
      | d                                        |
      +------------------------------------------+
      | 0.09999999999999998358171037484709838848 |
      | 0.10000000000000000000000000000000000000 |
      +------------------------------------------+
      Returned 2 row(s) in 0.44s
      

      Nong told me that in the frontend, we first cast the the number in the query string to a double, and then recast it to decimal. Since the second cast is on Java's encoding of double, we get a very odd result when reading the column value as a Decimal. I'm not sure if it's possible to not do the cast when we're recasting it anyways, but that would be ideal.

      Attachments

        Activity

          People

            nong_impala_60e1 Nong Li
            ishaan Ishaan Joshi
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: