This is an automated email from the ASF dual-hosted git repository. dmollitor pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/hive.git
The following commit(s) were added to refs/heads/master by this push: new 0a9f3bb HIVE-20771: LazyBinarySerDe fails on empty structs (Clemens Valiente via David Mollitor, reviewed by Jesús Rodríguez) 0a9f3bb is described below commit 0a9f3bb9a18043dbafb0ac218b6721f3260be781 Author: Hunter Logan <hunterlo...@outlook.com> AuthorDate: Fri Jul 24 09:13:21 2020 -0400 HIVE-20771: LazyBinarySerDe fails on empty structs (Clemens Valiente via David Mollitor, reviewed by Jesús Rodríguez) --- .../serde2/lazybinary/LazyBinaryNonPrimitive.java | 4 +- .../serde2/lazybinary/TestLazyBinaryStruct.java | 67 ++++++++++++++++++++++ 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/serde/src/java/org/apache/hadoop/hive/serde2/lazybinary/LazyBinaryNonPrimitive.java b/serde/src/java/org/apache/hadoop/hive/serde2/lazybinary/LazyBinaryNonPrimitive.java index 05d05c6..82946d3 100644 --- a/serde/src/java/org/apache/hadoop/hive/serde2/lazybinary/LazyBinaryNonPrimitive.java +++ b/serde/src/java/org/apache/hadoop/hive/serde2/lazybinary/LazyBinaryNonPrimitive.java @@ -50,8 +50,8 @@ public abstract class LazyBinaryNonPrimitive<OI extends ObjectInspector> if (null == bytes) { throw new RuntimeException("bytes cannot be null!"); } - if (length <= 0) { - throw new RuntimeException("length should be positive!"); + if (length < 0) { + throw new RuntimeException("length should be non-negative!"); } this.bytes = bytes; this.start = start; diff --git a/serde/src/test/org/apache/hadoop/hive/serde2/lazybinary/TestLazyBinaryStruct.java b/serde/src/test/org/apache/hadoop/hive/serde2/lazybinary/TestLazyBinaryStruct.java new file mode 100644 index 0000000..aa6b823 --- /dev/null +++ b/serde/src/test/org/apache/hadoop/hive/serde2/lazybinary/TestLazyBinaryStruct.java @@ -0,0 +1,67 @@ +/* + * 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.lazybinary; + +import java.util.ArrayList; +import java.util.Properties; +import junit.framework.TestCase; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hive.serde.serdeConstants; +import org.apache.hadoop.hive.serde2.SerDeException; +import org.apache.hadoop.hive.serde2.SerDeUtils; +import org.apache.hadoop.hive.serde2.lazy.ByteArrayRef; +import org.apache.hadoop.hive.serde2.lazybinary.objectinspector.LazyBinaryObjectInspectorFactory; +import org.apache.hadoop.hive.serde2.lazybinary.objectinspector.LazyBinaryStructObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory; +import org.apache.hadoop.hive.serde2.objectinspector.StandardStructObjectInspector; +import org.apache.hadoop.io.Writable; +import org.junit.Test; + +public class TestLazyBinaryStruct extends TestCase { + + @Test + public void testEmptyStruct() { + LazyBinaryStructObjectInspector oi = LazyBinaryObjectInspectorFactory + .getLazyBinaryStructObjectInspector(new ArrayList<>(), new ArrayList<>()); + + ByteArrayRef byteRef = new ByteArrayRef(); + byteRef.setData(new byte[]{0}); + + LazyBinaryStruct data = (LazyBinaryStruct) LazyBinaryFactory.createLazyBinaryObject(oi); + data.init(byteRef, 0, 0); + + assertEquals(data.getRawDataSerializedSize(), 0); + } + + @Test + public void testEmptyStructWithSerde() throws SerDeException { + LazyBinaryStructObjectInspector oi = LazyBinaryObjectInspectorFactory + .getLazyBinaryStructObjectInspector(new ArrayList<>(), new ArrayList<>()); + StandardStructObjectInspector standardOI = ObjectInspectorFactory + .getStandardStructObjectInspector(new ArrayList<>(), new ArrayList<>()); + Properties schema = new Properties(); + schema.setProperty(serdeConstants.LIST_COLUMNS, "col0"); + schema.setProperty(serdeConstants.LIST_COLUMN_TYPES, "struct<>"); + + LazyBinarySerDe serde = new LazyBinarySerDe(); + SerDeUtils.initializeSerDe(serde, new Configuration(), schema, null); + Writable writable = serde.serialize(standardOI.create(), standardOI); + Object out = serde.deserialize(writable); + assertNull(oi.getStructFieldsDataAsList(out)); + } +} \ No newline at end of file