@Override public byte[] serializeKey(Object object, StructField field) throws IOException { ObjectInspector inspector = field.getFieldObjectInspector(); if (inspector.getCategory() != ObjectInspector.Category.STRUCT) { throw new IllegalStateException("invalid type value " + inspector.getTypeName()); } output.reset(); for (Object element : ((StructObjectInspector)inspector).getStructFieldsDataAsList(object)) { output.write(toBinary(String.valueOf(element).getBytes(), FIXED_LENGTH, false, false)); } return output.getLength() > 0 ? output.toByteArray() : null; }
@Override public byte[] serializeKey(Object object, StructField field) throws IOException { ObjectInspector inspector = field.getFieldObjectInspector(); if (inspector.getCategory() != ObjectInspector.Category.STRUCT) { throw new IllegalStateException("invalid type value " + inspector.getTypeName()); } output.reset(); for (Object element : ((StructObjectInspector)inspector).getStructFieldsDataAsList(object)) { if (output.getLength() > 0) { output.write(DELIMITER_BINARY); } output.write(String.valueOf(element).getBytes()); } return output.getLength() > 0 ? output.toByteArray() : null; }
cqBytes = output.toByteArray(); valueBytes = output.toByteArray();
cqBytes = output.toByteArray(); valueBytes = output.toByteArray();
/** * Compute the serialized value from the given element and object inspectors. Based on the Hive * types, represented through the ObjectInspectors for the whole object and column within the * object, serialize the object appropriately. * * @param fieldObjectInspector * ObjectInspector for the column value being serialized * @param value * The Object itself being serialized * @param output * A temporary buffer to reduce object creation * @return The serialized bytes from the provided value. * @throws IOException * An error occurred when performing IO to serialize the data */ protected byte[] getSerializedValue(ObjectInspector fieldObjectInspector, Object value, ByteStream.Output output, ColumnMapping mapping) throws IOException { // Reset the buffer we're going to use output.reset(); // Start by only serializing primitives as-is if (fieldObjectInspector.getCategory() == ObjectInspector.Category.PRIMITIVE) { writeSerializedPrimitive((PrimitiveObjectInspector) fieldObjectInspector, output, value, mapping.getEncoding()); } else { // We only accept a struct, which means that we're already nested one level deep writeWithLevel(fieldObjectInspector, value, output, mapping, 2); } return output.toByteArray(); }
/** * Serialize an Accumulo rowid */ protected byte[] serializeRowId(Object rowId, StructField rowIdField, ColumnMapping rowIdMapping) throws IOException { if (rowId == null) { throw new IOException("Accumulo rowId cannot be NULL"); } // Reset the buffer we're going to use output.reset(); ObjectInspector rowIdFieldOI = rowIdField.getFieldObjectInspector(); String rowIdMappingType = rowIdMapping.getColumnType(); TypeInfo rowIdTypeInfo = TypeInfoUtils.getTypeInfoFromTypeString(rowIdMappingType); if (!rowIdFieldOI.getCategory().equals(ObjectInspector.Category.PRIMITIVE) && rowIdTypeInfo.getCategory() == ObjectInspector.Category.PRIMITIVE) { // we always serialize the String type using the escaped algorithm for LazyString writeString(output, SerDeUtils.getJSONString(rowId, rowIdFieldOI), PrimitiveObjectInspectorFactory.javaStringObjectInspector); return output.toByteArray(); } // use the serialization option switch to write primitive values as either a variable // length UTF8 string or a fixed width bytes if serializing in binary format getSerializedValue(rowIdFieldOI, rowId, output, rowIdMapping); return output.toByteArray(); }
/** * Serialize an Accumulo rowid */ protected byte[] serializeRowId(Object rowId, StructField rowIdField, ColumnMapping rowIdMapping) throws IOException { if (rowId == null) { throw new IOException("Accumulo rowId cannot be NULL"); } // Reset the buffer we're going to use output.reset(); ObjectInspector rowIdFieldOI = rowIdField.getFieldObjectInspector(); String rowIdMappingType = rowIdMapping.getColumnType(); TypeInfo rowIdTypeInfo = TypeInfoUtils.getTypeInfoFromTypeString(rowIdMappingType); if (!rowIdFieldOI.getCategory().equals(ObjectInspector.Category.PRIMITIVE) && rowIdTypeInfo.getCategory() == ObjectInspector.Category.PRIMITIVE) { // we always serialize the String type using the escaped algorithm for LazyString writeString(output, SerDeUtils.getJSONString(rowId, rowIdFieldOI), PrimitiveObjectInspectorFactory.javaStringObjectInspector); return output.toByteArray(); } // use the serialization option switch to write primitive values as either a variable // length UTF8 string or a fixed width bytes if serializing in binary format getSerializedValue(rowIdFieldOI, rowId, output, rowIdMapping); return output.toByteArray(); }
/** * Compute the serialized value from the given element and object inspectors. Based on the Hive * types, represented through the ObjectInspectors for the whole object and column within the * object, serialize the object appropriately. * * @param fieldObjectInspector * ObjectInspector for the column value being serialized * @param value * The Object itself being serialized * @param output * A temporary buffer to reduce object creation * @return The serialized bytes from the provided value. * @throws IOException * An error occurred when performing IO to serialize the data */ protected byte[] getSerializedValue(ObjectInspector fieldObjectInspector, Object value, ByteStream.Output output, ColumnMapping mapping) throws IOException { // Reset the buffer we're going to use output.reset(); // Start by only serializing primitives as-is if (fieldObjectInspector.getCategory() == ObjectInspector.Category.PRIMITIVE) { writeSerializedPrimitive((PrimitiveObjectInspector) fieldObjectInspector, output, value, mapping.getEncoding()); } else { // We only accept a struct, which means that we're already nested one level deep writeWithLevel(fieldObjectInspector, value, output, mapping, 2); } return output.toByteArray(); }
private byte[] serialize(Object obj, ObjectInspector objInspector, int level, boolean writeBinary) throws IOException { output.reset(); if (objInspector.getCategory() == ObjectInspector.Category.PRIMITIVE && writeBinary) { LazyUtils.writePrimitive(output, obj, (PrimitiveObjectInspector) objInspector); } else { if (!serialize(obj, objInspector, level, output)) { return null; } } return output.toByteArray(); }
private byte[] serialize(Object obj, ObjectInspector objInspector, int level, boolean writeBinary) throws IOException { output.reset(); if (objInspector.getCategory() == ObjectInspector.Category.PRIMITIVE && writeBinary) { LazyUtils.writePrimitive(output, obj, (PrimitiveObjectInspector) objInspector); } else { if (!serialize(obj, objInspector, level, output)) { return null; } } return output.toByteArray(); }