diff --git hbase-handler/src/test/queries/positive/hbase_decimal_decimal.q hbase-handler/src/test/queries/positive/hbase_decimal_decimal.q new file mode 100644 index 0000000..d943fbd --- /dev/null +++ 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; diff --git hbase-handler/src/test/results/positive/hbase_decimal_decimal.q.out hbase-handler/src/test/results/positive/hbase_decimal_decimal.q.out new file mode 100644 index 0000000..f719e95 --- /dev/null +++ hbase-handler/src/test/results/positive/hbase_decimal_decimal.q.out @@ -0,0 +1,47 @@ +PREHOOK: query: 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") +PREHOOK: type: CREATETABLE +PREHOOK: Output: database:default +PREHOOK: Output: default@testhbase_decimal +POSTHOOK: query: 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") +POSTHOOK: type: CREATETABLE +POSTHOOK: Output: database:default +POSTHOOK: Output: default@testhbase_decimal +PREHOOK: query: insert into testhbase_decimal values (1,1), (2, 2.2), (3, 33.33) +PREHOOK: type: QUERY +PREHOOK: Output: default@testhbase_decimal +POSTHOOK: query: insert into testhbase_decimal values (1,1), (2, 2.2), (3, 33.33) +POSTHOOK: type: QUERY +POSTHOOK: Output: default@testhbase_decimal +PREHOOK: query: select * from testhbase_decimal +PREHOOK: type: QUERY +PREHOOK: Input: default@testhbase_decimal +#### A masked pattern was here #### +POSTHOOK: query: select * from testhbase_decimal +POSTHOOK: type: QUERY +POSTHOOK: Input: default@testhbase_decimal +#### A masked pattern was here #### +1 +2 +3 +PREHOOK: query: drop table testhbase_decimal +PREHOOK: type: DROPTABLE +PREHOOK: Input: default@testhbase_decimal +PREHOOK: Output: default@testhbase_decimal +POSTHOOK: query: drop table testhbase_decimal +POSTHOOK: type: DROPTABLE +POSTHOOK: Input: default@testhbase_decimal +POSTHOOK: Output: default@testhbase_decimal diff --git serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyFactory.java serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyFactory.java index 3ed5b33..eec9de0 100644 --- serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyFactory.java +++ serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyFactory.java @@ -53,6 +53,7 @@ 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 @@ 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); } diff --git serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyUtils.java serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyUtils.java index 80b3de2..0e1f045 100644 --- serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyUtils.java +++ serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyUtils.java @@ -29,6 +29,7 @@ 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 static void writePrimitive( break; } + case DECIMAL: { + HiveDecimalWritable hdw = ((HiveDecimalObjectInspector) oi).getPrimitiveWritableObject(o); + hdw.write(dos); + break; + } + default: throw new RuntimeException("Hive internal error."); } diff --git serde/src/java/org/apache/hadoop/hive/serde2/lazydio/LazyDioHiveDecimal.java serde/src/java/org/apache/hadoop/hive/serde2/lazydio/LazyDioHiveDecimal.java new file mode 100644 index 0000000..29cc924 --- /dev/null +++ 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); + } +}