@@ -0,0 +1,3758 @@
+/*%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage org.apache.hadoop.hive.serde2.columnar;%0A%0Aimport org.apache.hadoop.hive.serde2.SerDeException;%0Aimport org.apache.hadoop.hive.serde2.lazybinary.LazyBinarySerDe;%0Aimport org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;%0Aimport org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;%0Aimport org.apache.hadoop.hive.serde2.objectinspector.StructField;%0Aimport org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector;%0Aimport org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector;%0Aimport org.apache.hadoop.io.Writable;%0A%0Aimport java.util.List;%0A%0A/**%0A * This is a variant of %7B@link LazyBinaryColumnarSerDe%7D that avoids a call to%0A * %7B@code StringObjectInspector.getPrimitiveJavaObject()%7D in %7B@code serialize()%7D%0A * to check whether the string is empty (it calls %7B@code getPrimitiveWritableObject()%7D%0A * instead). This improves CPU efficiency by avoiding turning the underlying bytes into%0A * a Java String.%0A */%0Apublic class OptimizedLazyBinaryColumnarSerde%0A        extends LazyBinaryColumnarSerDe%0A%7B%0A    @Override%0A    public Writable serialize(Object obj, ObjectInspector objInspector)%0A            throws SerDeException%0A    %7B%0A        if (objInspector.getCategory() != ObjectInspector.Category.STRUCT) %7B%0A            throw new SerDeException(getClass().toString()%0A                    + %22 can only serialize struct types, but we got: %22%0A                    + objInspector.getTypeName());%0A        %7D%0A%0A        StructObjectInspector soi = (StructObjectInspector) objInspector;%0A        List%3C? extends StructField%3E fields = soi.getAllStructFieldRefs();%0A        List%3CObject%3E list = soi.getStructFieldsDataAsList(obj);%0A%0A        LazyBinarySerDe.BooleanRef warnedOnceNullMapKey = new LazyBinarySerDe.BooleanRef(false);%0A        serializeStream.reset();%0A        serializedSize = 0;%0A        int streamOffset = 0;%0A        // Serialize each field%0A        for (int i = 0; i %3C fields.size(); i++) %7B%0A            // Get the field objectInspector and the field object.%0A            ObjectInspector foi = fields.get(i).getFieldObjectInspector();%0A            Object f = (list == null ? null : list.get(i));%0A            //empty strings are marked by an invalid utf single byte sequence. A valid utf stream cannot%0A            //produce this sequence%0A            if ((f != null) && (foi.getCategory().equals(ObjectInspector.Category.PRIMITIVE))%0A                    && ((PrimitiveObjectInspector) foi).getPrimitiveCategory().equals(%0A                    PrimitiveObjectInspector.PrimitiveCategory.STRING)%0A                    && ((StringObjectInspector) foi).getPrimitiveWritableObject(f).getLength() == 0) %7B%0A                serializeStream.write(INVALID_UTF__SINGLE_BYTE, 0, 1);%0A            %7D%0A            else %7B%0A                LazyBinarySerDe.serialize(serializeStream, f, foi, true, warnedOnceNullMapKey);%0A            %7D%0A            field%5Bi%5D.set(serializeStream.getData(), streamOffset, serializeStream.getLength() - streamOffset);%0A            streamOffset = serializeStream.getLength();%0A        %7D%0A        serializedSize = serializeStream.getLength();%0A        lastOperationSerialize = true;%0A        lastOperationDeserialize = false;%0A        return serializeCache;%0A    %7D%0A%7D%0A

Add optimized binary column serde