phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s..@apache.org
Subject [09/18] phoenix git commit: PHOENIX-3408 arithmetic/mathematical operations with Decimal columns failed in Hive with PheonixStorageHandler.
Date Wed, 02 Nov 2016 20:08:31 GMT
PHOENIX-3408 arithmetic/mathematical operations with Decimal columns failed in Hive with PheonixStorageHandler.

Signed-off-by: Sergey Soldatov <ssa@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/bebcc552
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/bebcc552
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/bebcc552

Branch: refs/heads/4.x-HBase-0.98
Commit: bebcc552fb2bc40b8fda79dc82be7fc4c61945bc
Parents: 46d4bb4
Author: Jeongdae Kim <kjd9306@gmail.com>
Authored: Wed Oct 26 19:26:06 2016 +0900
Committer: Sergey Soldatov <ssa@apache.org>
Committed: Wed Nov 2 12:58:36 2016 -0700

----------------------------------------------------------------------
 .../PhoenixDecimalObjectInspector.java           | 19 ++++++++++++++-----
 .../PhoenixObjectInspectorFactory.java           |  2 +-
 2 files changed, 15 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/bebcc552/phoenix-hive/src/main/java/org/apache/phoenix/hive/objectinspector/PhoenixDecimalObjectInspector.java
----------------------------------------------------------------------
diff --git a/phoenix-hive/src/main/java/org/apache/phoenix/hive/objectinspector/PhoenixDecimalObjectInspector.java
b/phoenix-hive/src/main/java/org/apache/phoenix/hive/objectinspector/PhoenixDecimalObjectInspector.java
index 8afe10f..3853c18 100644
--- a/phoenix-hive/src/main/java/org/apache/phoenix/hive/objectinspector/PhoenixDecimalObjectInspector.java
+++ b/phoenix-hive/src/main/java/org/apache/phoenix/hive/objectinspector/PhoenixDecimalObjectInspector.java
@@ -21,6 +21,9 @@ import org.apache.hadoop.hive.common.type.HiveDecimal;
 import org.apache.hadoop.hive.metastore.api.Decimal;
 import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable;
 import org.apache.hadoop.hive.serde2.objectinspector.primitive.HiveDecimalObjectInspector;
+import org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo;
+import org.apache.hadoop.hive.serde2.typeinfo.HiveDecimalUtils;
+import org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo;
 import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory;
 
 import java.math.BigDecimal;
@@ -30,17 +33,25 @@ public class PhoenixDecimalObjectInspector extends
         implements HiveDecimalObjectInspector {
 
     public PhoenixDecimalObjectInspector() {
-        super(TypeInfoFactory.decimalTypeInfo);
+        this(TypeInfoFactory.decimalTypeInfo);
+    }
+
+    public PhoenixDecimalObjectInspector(PrimitiveTypeInfo typeInfo) {
+        super(typeInfo);
     }
 
     @Override
     public Object copyObject(Object o) {
-        return o == null ? null : new BigDecimal(((BigDecimal)o).byteValue());
+        return o == null ? null : new BigDecimal(o.toString());
     }
 
     @Override
     public HiveDecimal getPrimitiveJavaObject(Object o) {
-        return HiveDecimal.create((BigDecimal) o);
+        if (o == null) {
+            return null;
+        }
+
+        return HiveDecimalUtils.enforcePrecisionScale(HiveDecimal.create((BigDecimal) o),(DecimalTypeInfo)typeInfo);
     }
 
     @Override
@@ -56,8 +67,6 @@ public class PhoenixDecimalObjectInspector extends
         }
 
         return value;
-
-//		return super.getPrimitiveWritableObject(o);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/bebcc552/phoenix-hive/src/main/java/org/apache/phoenix/hive/objectinspector/PhoenixObjectInspectorFactory.java
----------------------------------------------------------------------
diff --git a/phoenix-hive/src/main/java/org/apache/phoenix/hive/objectinspector/PhoenixObjectInspectorFactory.java
b/phoenix-hive/src/main/java/org/apache/phoenix/hive/objectinspector/PhoenixObjectInspectorFactory.java
index 928dede..22be0fc 100644
--- a/phoenix-hive/src/main/java/org/apache/phoenix/hive/objectinspector/PhoenixObjectInspectorFactory.java
+++ b/phoenix-hive/src/main/java/org/apache/phoenix/hive/objectinspector/PhoenixObjectInspectorFactory.java
@@ -111,7 +111,7 @@ public class PhoenixObjectInspectorFactory {
                         oi = new PhoenixTimestampObjectInspector();
                         break;
                     case DECIMAL:
-                        oi = new PhoenixDecimalObjectInspector();
+                        oi = new PhoenixDecimalObjectInspector((PrimitiveTypeInfo) type);
                         break;
                     case BINARY:
                         oi = new PhoenixBinaryObjectInspector();


Mime
View raw message