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

HPL/SQL Addition/Subtraction only supported on integers, datetimes and intervals

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Patch Available
    • Priority: Critical
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: hpl/sql
    • Labels:
      None

      Description

      This bug is part of a series of issues and surprising behavior I encountered writing a reporting script that would aggregate values and give rows different classifications based on an the aggregate. Addressing some or all of these issues would make HPL/SQL more accessible to newcomers.

      In Expression.java:

        public void operatorSub(HplsqlParser.ExprContext ctx) {
          Var v1 = evalPop(ctx.expr(0));
          Var v2 = evalPop(ctx.expr(1));
          if (v1.value == null || v2.value == null) {
            evalNull();
          }
          else if (v1.type == Type.BIGINT && v2.type == Type.BIGINT) {
            exec.stackPush(new Var((Long)v1.value - (Long)v2.value));
          }
          else if (v1.type == Type.DATE && v2.type == Type.BIGINT) {
            exec.stackPush(changeDateByInt((Date)v1.value, (Long)v2.value, false /*subtract*/));
          }
          else if (v1.type == Type.DATE && v2.type == Type.INTERVAL) {
            exec.stackPush(new Var(((Interval)v2.value).dateChange((Date)v1.value, false /*subtract*/)));
          }
          else if (v1.type == Type.TIMESTAMP && v2.type == Type.INTERVAL) {
            exec.stackPush(new Var(((Interval)v2.value).timestampChange((Timestamp)v1.value, false /*subtract*/), v1.scale));
          }
          else {
            evalNull();
          }
        }
      

      So decimals and floating points are not considered. To be fair the docs don't mention this as supported, but it is surprising.

      Need: Test case for comparisons and equality, including nulls

      Version = 3.0.0-SNAPSHOT r71f52d8ad512904b3f2c4f04fe39a33f2834f1f2

        Attachments

        1. HIVE-17031.1.patch
          5 kB
          Dmitry Tolpeko

          Activity

            People

            • Assignee:
              dmtolpeko Dmitry Tolpeko
              Reporter:
              cartershanklin Carter Shanklin
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: