Uploaded image for project: 'Hive'
  1. Hive
  2. HIVE-22877

Fix decimal boundary check for casting to Decimal64

    XMLWordPrintableJSON

    Details

      Description

      During vectorization, decimal fields that are obtained via generic udfs are cast to Decimal64 in some circumstances. For decimal to decimal64 cast, hive compares the source column's `scale + precision` to 18(maximum number of digits that can be represented by a long). A decimal can fit in a long as long as its `precision` is smaller than or equal to 18. Scale is irrelevant.

      Since vectorized generic udf expression takes scale into account, it computes wrong output column vector: Decimal instead of Decimal64. This in turn causes ClassCastException down the operator chain.

      Below query fails with class cast exception:

       

      create table mini_store
      (
       s_store_sk int,
       s_store_id string
      )
      row format delimited fields terminated by '\t'
      STORED AS ORC;
      
      create table mini_sales
      (
       ss_store_sk int,
       ss_quantity int,
       ss_sales_price decimal(7,2)
      )
      row format delimited fields terminated by '\t'
      STORED AS ORC;
      insert into mini_store values (1, 'store');
      insert into mini_sales values (1, 2, 1.2);
      select s_store_id, coalesce(ss_sales_price*ss_quantity,0) sumsales
      from mini_sales, mini_store where ss_store_sk = s_store_sk
      

       

       

        Attachments

        1. HIVE-22877.1.patch
          24 kB
          Mustafa İman
        2. HIVE-22877.1.patch
          24 kB
          Mustafa İman
        3. HIVE-22877.1.patch
          24 kB
          Mustafa İman
        4. HIVE-22877.patch
          17 kB
          Mustafa İman

          Issue Links

            Activity

              People

              • Assignee:
                mustafaiman Mustafa İman
                Reporter:
                mustafaiman Mustafa İman
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 20m
                  20m