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

Move arithmatic UDFs to generic UDF implementations

    XMLWordPrintableJSON

Details

    • Task
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 0.11.0
    • 0.13.0
    • UDF
    • None
    • Incompatible change

    Description

      Currently, all of the arithmetic operators, such as add/sub/mult/div, are implemented as old-style UDFs and java reflection is used to determine the return type TypeInfos/ObjectInspectors, based on the return type of the evaluate() method chosen for the expression. This works fine for types that don't have type params.

      Hive decimal type participates in these operations just like int or double. Different from double or int, however, decimal has precision and scale, which cannot be determined by just looking at the return type (decimal) of the UDF evaluate() method, even though the operands have certain precision/scale. With the default of "decimal" without precision/scale, then (10, 0) will be the type params. This is certainly not desirable.

      To solve this problem, all of the arithmetic operators would need to be implemented as GenericUDFs, which allow returning ObjectInspector during the initialize() method. The object inspectors returned can carry type params, from which the "exact" return type can be determined.

      It's worth mentioning that, for user UDF implemented in non-generic way, if the return type of the chosen evaluate() method is decimal, the return type actually has (10,0) as precision/scale, which might not be desirable. This needs to be documented.

      This JIRA will cover minus, plus, divide, multiply, mod, and pmod, to limit the scope of review. The remaining ones will be covered under HIVE-5706.

      Attachments

        1. HIVE-5356.1.patch
          126 kB
          Xuefu Zhang
        2. HIVE-5356.10.patch
          1.22 MB
          Xuefu Zhang
        3. HIVE-5356.11.patch
          1.22 MB
          Xuefu Zhang
        4. HIVE-5356.12.patch
          1.22 MB
          Xuefu Zhang
        5. HIVE-5356.2.patch
          161 kB
          Xuefu Zhang
        6. HIVE-5356.3.patch
          1.22 MB
          Xuefu Zhang
        7. HIVE-5356.4.patch
          1.20 MB
          Xuefu Zhang
        8. HIVE-5356.5.patch
          1.21 MB
          Xuefu Zhang
        9. HIVE-5356.6.patch
          1.21 MB
          Xuefu Zhang
        10. HIVE-5356.7.patch
          1.22 MB
          Xuefu Zhang
        11. HIVE-5356.8.patch
          1.22 MB
          Xuefu Zhang
        12. HIVE-5356.9.patch
          1.22 MB
          Xuefu Zhang

        Issue Links

          Activity

            People

              xuefuz Xuefu Zhang
              xuefuz Xuefu Zhang
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: