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:37 UTC
[15/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/d5f73930
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/d5f73930
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/d5f73930
Branch: refs/heads/4.x-HBase-1.1
Commit: d5f73930a0f11f9d49b5e5b9f0a15e1fe5f58b9f
Parents: 8463d3d
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 13:01:37 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/d5f73930/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/d5f73930/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();