You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ss...@apache.org on 2016/11/02 20:08:25 UTC

[03/18] phoenix git commit: PHOENIX-3408 arithmetic/mathematical operations with Decimal columns failed in Hive with PheonixStorageHandler.

PHOENIX-3408 arithmetic/mathematical operations with Decimal columns failed in Hive with PheonixStorageHandler.

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


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

Branch: refs/heads/master
Commit: c83d272b565447d39c42a4a8d3b0687bb2b5a16c
Parents: e1afbcc
Author: Jeongdae Kim <kj...@gmail.com>
Authored: Wed Oct 26 19:26:06 2016 +0900
Committer: Sergey Soldatov <ss...@apache.org>
Committed: Wed Nov 2 12:37:12 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/c83d272b/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/c83d272b/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();