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 23dbe6a..f812425 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 @@ -52,6 +52,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; @@ -165,6 +166,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 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 73c72e1..a6cbff2 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 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; @@ -386,6 +387,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 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); + } +}