Uploaded image for project: 'IMPALA'
  1. IMPALA
  2. IMPALA-3436

Round(double, int) should return decimal

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Won't Fix
    • Impala 2.5.0
    • None
    • Backend

    Description

      Impala has several versions of round: round(double a), round(double a, int d), round(decimal a, int_type d)

      round(double a) returns a BIGINT, which makes sense because it rounds to the nearest int.

      round(decimal a, int_type d) returns a DECIMAL, which makes sense because it rounds to a decimal digit.

      round(double a, int d) predates DECIMAL support, so it returns a DOUBLE. It is specified to return the nearest double value.

      E.g. round(cast(1 as DOUBLE) / 10, 1) returns the binary floating point value closest to 0.1. This number has no exact decimal representation. Both 0.100000000000000000000000000 and 0.10000000000000000555 are valid decimal representations of this floating point number. I.e. if you convert them back to float, you will get the same number.

      This is correct according to floating point conversion rules and the Impala documentation, but it is confusing for two reasons:

      • round() returning a double is a little surprising, because it can't precisely represent the result
      • Impala clients can display the floating-point result in multiple valid ways. Different clients have different algorithms for converting floating-point to decimal for display, so even if Impala returns the same result it may appear as 0.1 in one client and 0.10000000000000000555. We don't specify that clients have to use a particular algorithm, so it's valid as long as it converts back to the same float as part of a round-trip.

      We should consider changing the spec of round() in Impala to always return a decimal to avoid this confusion.

      Attachments

        Issue Links

          Activity

            People

              tarasbob Taras Bobrovytsky
              tarmstrong Tim Armstrong
              Votes:
              1 Vote for this issue
              Watchers:
              10 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: