Repository: hive Updated Branches: refs/heads/master fe4bd0404 -> 8f1335d6d
HIVE-15883 HBase mapped table in Hive insert fail for decimal (Naveen Gangam reviewed by Ashutosh Chauhan and Aihua Xu) Project: http://git-wip-us.apache.org/repos/asf/hive/repo Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/8f1335d6 Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/8f1335d6 Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/8f1335d6 Branch: refs/heads/master Commit: 8f1335d6d2d9a0e313f04d46d2dcc7a01dec9bce Parents: fe4bd04 Author: Naveen Gangam <[email protected]> Authored: Tue Dec 12 17:14:56 2017 -0500 Committer: Naveen Gangam <[email protected]> Committed: Tue Dec 12 17:14:56 2017 -0500 ---------------------------------------------------------------------- .../queries/positive/hbase_decimal_decimal.q | 14 +++++ .../positive/hbase_decimal_decimal.q.out | Bin 0 -> 1667 bytes .../hadoop/hive/serde2/lazy/LazyFactory.java | 3 ++ .../hadoop/hive/serde2/lazy/LazyUtils.java | 7 +++ .../hive/serde2/lazydio/LazyDioHiveDecimal.java | 51 +++++++++++++++++++ 5 files changed, 75 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hive/blob/8f1335d6/hbase-handler/src/test/queries/positive/hbase_decimal_decimal.q ---------------------------------------------------------------------- diff --git a/hbase-handler/src/test/queries/positive/hbase_decimal_decimal.q b/hbase-handler/src/test/queries/positive/hbase_decimal_decimal.q new file mode 100644 index 0000000..d943fbd --- /dev/null +++ b/hbase-handler/src/test/queries/positive/hbase_decimal_decimal.q @@ -0,0 +1,14 @@ +CREATE TABLE testhbase_decimal ( +id int, +balance decimal(15,2)) +ROW FORMAT DELIMITED +COLLECTION ITEMS TERMINATED BY '~' +STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' +WITH SERDEPROPERTIES ( +"hbase.columns.mapping"=":key,cf:balance#b"); + +insert into testhbase_decimal values (1,1), (2, 2.2), (3, 33.33); + +select * from testhbase_decimal; + +drop table testhbase_decimal; http://git-wip-us.apache.org/repos/asf/hive/blob/8f1335d6/hbase-handler/src/test/results/positive/hbase_decimal_decimal.q.out ---------------------------------------------------------------------- diff --git a/hbase-handler/src/test/results/positive/hbase_decimal_decimal.q.out b/hbase-handler/src/test/results/positive/hbase_decimal_decimal.q.out new file mode 100644 index 0000000..f719e95 Binary files /dev/null and b/hbase-handler/src/test/results/positive/hbase_decimal_decimal.q.out differ http://git-wip-us.apache.org/repos/asf/hive/blob/8f1335d6/serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyFactory.java ---------------------------------------------------------------------- diff --git a/serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyFactory.java b/serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyFactory.java index 3ed5b33..eec9de0 100644 --- a/serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyFactory.java +++ b/serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyFactory.java @@ -53,6 +53,7 @@ import org.apache.hadoop.hive.serde2.lazydio.LazyDioBoolean; import org.apache.hadoop.hive.serde2.lazydio.LazyDioByte; import org.apache.hadoop.hive.serde2.lazydio.LazyDioDouble; import org.apache.hadoop.hive.serde2.lazydio.LazyDioFloat; +import org.apache.hadoop.hive.serde2.lazydio.LazyDioHiveDecimal; import org.apache.hadoop.hive.serde2.lazydio.LazyDioInteger; import org.apache.hadoop.hive.serde2.lazydio.LazyDioLong; import org.apache.hadoop.hive.serde2.lazydio.LazyDioShort; @@ -168,6 +169,8 @@ public final class LazyFactory { return new LazyDioDouble((LazyDoubleObjectInspector) poi); case BINARY: return new LazyDioBinary((LazyBinaryObjectInspector) poi); + case DECIMAL: + return new LazyDioHiveDecimal((LazyHiveDecimalObjectInspector) poi); default: throw new RuntimeException("Hive Internal Error: no LazyObject for " + poi); } http://git-wip-us.apache.org/repos/asf/hive/blob/8f1335d6/serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyUtils.java ---------------------------------------------------------------------- diff --git a/serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyUtils.java b/serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyUtils.java index 80b3de2..0e1f045 100644 --- a/serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyUtils.java +++ b/serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyUtils.java @@ -29,6 +29,7 @@ import java.util.Map; import org.apache.commons.codec.binary.Base64; import org.apache.hadoop.hive.serde2.SerDeException; import org.apache.hadoop.hive.serde2.io.HiveCharWritable; +import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable; import org.apache.hadoop.hive.serde2.io.HiveVarcharWritable; import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.primitive.BinaryObjectInspector; @@ -393,6 +394,12 @@ public final class LazyUtils { break; } + case DECIMAL: { + HiveDecimalWritable hdw = ((HiveDecimalObjectInspector) oi).getPrimitiveWritableObject(o); + hdw.write(dos); + break; + } + default: throw new RuntimeException("Hive internal error."); } http://git-wip-us.apache.org/repos/asf/hive/blob/8f1335d6/serde/src/java/org/apache/hadoop/hive/serde2/lazydio/LazyDioHiveDecimal.java ---------------------------------------------------------------------- diff --git a/serde/src/java/org/apache/hadoop/hive/serde2/lazydio/LazyDioHiveDecimal.java b/serde/src/java/org/apache/hadoop/hive/serde2/lazydio/LazyDioHiveDecimal.java new file mode 100644 index 0000000..29cc924 --- /dev/null +++ b/serde/src/java/org/apache/hadoop/hive/serde2/lazydio/LazyDioHiveDecimal.java @@ -0,0 +1,51 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hive.serde2.lazydio; + +import org.apache.hadoop.hive.serde2.lazy.ByteArrayRef; +import org.apache.hadoop.hive.serde2.lazy.LazyHiveDecimal; +import org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyHiveDecimalObjectInspector; + +public class LazyDioHiveDecimal extends LazyHiveDecimal { + + public LazyDioHiveDecimal(LazyHiveDecimalObjectInspector oi) { + super(oi); + } + + LazyDioHiveDecimal(LazyDioHiveDecimal copy) { + super(copy); + } + + /* (non-Javadoc) + * This provides a LazyHiveDecimal like class which can be initialized from data stored in a + * binary format. + * + * @see org.apache.hadoop.hive.serde2.lazy.LazyObject#init + * (org.apache.hadoop.hive.serde2.lazy.ByteArrayRef, int, int) + */ + @Override + public void init(ByteArrayRef bytes, int start, int length) { + if (bytes == null) { + throw new RuntimeException("bytes cannot be null!"); + } + isNull = false; + byte[] recv = new byte[length]; + System.arraycopy(bytes.getData(), start, recv, 0, length); + data.setFromBytes(recv, 0, length); + } +}
