zeroflag commented on a change in pull request #2059:
URL: https://github.com/apache/hive/pull/2059#discussion_r597541167



##########
File path: hplsql/src/main/java/org/apache/hive/hplsql/Expression.java
##########
@@ -369,21 +380,32 @@ public void operatorSub(HplsqlParser.ExprContext ctx) {
     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) {
+    } 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.BIGINT && v2.type == Type.DECIMAL) {
+      exec.stackPush(new Var((new 
BigDecimal((long)v1.value)).subtract((BigDecimal)v2.value)));
+    } else if (v1.type == Type.BIGINT && v2.type == Type.DOUBLE) {
+      exec.stackPush(new Var((long)v1.value - (double)v2.value));
+    } else if (v1.type == Type.DECIMAL && v2.type == Type.DECIMAL) {
+      exec.stackPush(new Var(((BigDecimal) v1.value).subtract((BigDecimal) 
v2.value)));
+    } else if (v1.type == Type.DECIMAL && v2.type == Type.BIGINT) {
+      exec.stackPush(new Var(((BigDecimal)v1.value).subtract(new 
BigDecimal((long)v2.value))));
+    } else if (v1.type == Type.DECIMAL && v2.type == Type.DOUBLE) {
+      exec.stackPush(new Var(((BigDecimal) v1.value).subtract(new 
BigDecimal((double) v2.value))));
+    } else if (v1.type == Type.DOUBLE && v2.type == Type.DOUBLE) {
+      exec.stackPush(new Var((double) v1.value - (double) v2.value));
+    } else if (v1.type == Type.DOUBLE && v2.type == Type.DECIMAL) {
+      exec.stackPush(new Var((new BigDecimal((double) 
v1.value)).subtract((BigDecimal) v2.value)));
+    } else if (v1.type == Type.DOUBLE && v2.type == Type.BIGINT) {
+      exec.stackPush(new Var(((double) 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) {
+    } 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();
+    } else {
+      exec.signal(Signal.Type.UNSUPPORTED_OPERATION, "Unsupported data types 
in subtraction operator");

Review comment:
       good idea




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to