@Override public void init(HBaseSerDeParameters hbaseParam, Properties properties) throws SerDeException { super.init(hbaseParam, properties); this.serdeParams = hbaseParam.getSerdeParams(); this.serializer = new HBaseRowSerializer(hbaseParam); }
@Override public Writable serialize(Object obj, ObjectInspector objInspector) throws SerDeException { try { return serializer.serialize(obj, objInspector); } catch (SerDeException e) { throw e; } catch (Exception e) { throw new SerDeException(e); } }
@Override public byte[] serializeKey(Object object, StructField field) throws IOException { return serializer.serializeKeyField(object, field, keyMapping); }
serializeField(value, field, columnMappings[i], put);
serializeField(value, field, columnMappings[i], put);
byte[] serializeKeyField(Object keyValue, StructField keyField, ColumnMapping keyMapping) throws IOException { if (keyValue == null) { throw new IOException("HBase row key cannot be NULL"); } ObjectInspector keyFieldOI = keyField.getFieldObjectInspector(); if (!keyFieldOI.getCategory().equals(ObjectInspector.Category.PRIMITIVE) && keyMapping.isCategory(ObjectInspector.Category.PRIMITIVE)) { // we always serialize the String type using the escaped algorithm for LazyString return serialize(SerDeUtils.getJSONString(keyValue, keyFieldOI), PrimitiveObjectInspectorFactory.javaStringObjectInspector, 1, false); } // 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 boolean writeBinary = keyMapping.binaryStorage.get(0); return serialize(keyValue, keyFieldOI, 1, writeBinary); }
/** * Initialize the SerDe given parameters. * @see AbstractSerDe#initialize(Configuration, Properties) */ @Override public void initialize(Configuration conf, Properties tbl) throws SerDeException { serdeParams = new HBaseSerDeParameters(conf, tbl, getClass().getName()); cachedObjectInspector = HBaseLazyObjectFactory.createLazyHBaseStructInspector(serdeParams, tbl); cachedHBaseRow = new LazyHBaseRow( (LazySimpleStructObjectInspector) cachedObjectInspector, serdeParams); serializer = new HBaseRowSerializer(serdeParams); if (LOG.isDebugEnabled()) { LOG.debug("HBaseSerDe initialized with : " + serdeParams); } }
@Override public byte[] serializeKey(Object object, StructField field) throws IOException { return serializer.serializeKeyField(object, field, keyMapping); }
byte[] columnQualifierBytes = serialize(entry.getKey(), koi, 3, colMap.binaryStorage.get(0)); if (columnQualifierBytes == null) { continue; byte[] bytes = serialize(entry.getValue(), voi, 3, colMap.binaryStorage.get(1)); if (bytes == null) { continue; && colMap.isCategory(ObjectInspector.Category.PRIMITIVE)) { bytes = serialize(SerDeUtils.getJSONString(value, foi), PrimitiveObjectInspectorFactory.javaStringObjectInspector, 1, false); } else { bytes = serialize(value, foi, 1, colMap.binaryStorage.get(0));
@Override public void init(HBaseSerDeParameters hbaseParam, Properties properties) throws SerDeException { super.init(hbaseParam, properties); this.serdeParams = hbaseParam.getSerdeParams(); this.serializer = new HBaseRowSerializer(hbaseParam); }
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(); }
/** * Initialize the SerDe given parameters. * @see SerDe#initialize(Configuration, Properties) */ @Override public void initialize(Configuration conf, Properties tbl) throws SerDeException { serdeParams = new HBaseSerDeParameters(conf, tbl, getClass().getName()); cachedObjectInspector = HBaseLazyObjectFactory .createLazyHBaseStructInspector(serdeParams.getSerdeParams(), serdeParams.getKeyIndex(), serdeParams.getKeyFactory(), serdeParams.getValueFactories()); cachedHBaseRow = new LazyHBaseRow( (LazySimpleStructObjectInspector) cachedObjectInspector, serdeParams); serializer = new HBaseRowSerializer(serdeParams); if (LOG.isDebugEnabled()) { LOG.debug("HBaseSerDe initialized with : " + serdeParams); } }
serialize(currentItem, eoi, level + 1, ss); ss.write(sep); serialize(entry.getKey(), koi, level + 2, ss); Object currentValue = entry.getValue(); if (currentValue != null) { ss.write(keyValueSeparator); serialize(currentValue, voi, level + 2, ss); serialize(currentItem, fields.get(i).getFieldObjectInspector(), level + 1, ss);
@Override public Writable serialize(Object obj, ObjectInspector objInspector) throws SerDeException { try { return serializer.serialize(obj, objInspector); } catch (SerDeException e) { throw e; } catch (Exception e) { throw new SerDeException(e); } }
byte[] serializeKeyField(Object keyValue, StructField keyField, ColumnMapping keyMapping) throws IOException { if (keyValue == null) { throw new IOException("HBase row key cannot be NULL"); } ObjectInspector keyFieldOI = keyField.getFieldObjectInspector(); if (!keyFieldOI.getCategory().equals(ObjectInspector.Category.PRIMITIVE) && keyMapping.isCategory(ObjectInspector.Category.PRIMITIVE)) { // we always serialize the String type using the escaped algorithm for LazyString return serialize(SerDeUtils.getJSONString(keyValue, keyFieldOI), PrimitiveObjectInspectorFactory.javaStringObjectInspector, 1, false); } // 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 boolean writeBinary = keyMapping.binaryStorage.get(0); return serialize(keyValue, keyFieldOI, 1, writeBinary); }
byte[] columnQualifierBytes = serialize(entry.getKey(), koi, 3, colMap.binaryStorage.get(0)); if (columnQualifierBytes == null) { continue; byte[] bytes = serialize(entry.getValue(), voi, 3, colMap.binaryStorage.get(1)); if (bytes == null) { continue; && colMap.isCategory(ObjectInspector.Category.PRIMITIVE)) { bytes = serialize(SerDeUtils.getJSONString(value, foi), PrimitiveObjectInspectorFactory.javaStringObjectInspector, 1, false); } else { bytes = serialize(value, foi, 1, colMap.binaryStorage.get(0));
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(); }