use of org.apache.hadoop.hive.serde2.lazy.LazyObjectBase in project hive by apache.
the class DelimitedAccumuloRowIdFactory method createRowId.
@Override
public LazyObjectBase createRowId(ObjectInspector inspector) throws SerDeException {
LazyObjectBase lazyObj = LazyFactory.createLazyObject(inspector, ColumnEncoding.BINARY == rowIdMapping.getEncoding());
log.info("Created " + lazyObj.getClass() + " for rowId with inspector " + inspector.getClass());
return lazyObj;
}
use of org.apache.hadoop.hive.serde2.lazy.LazyObjectBase in project hive by apache.
the class LazyAccumuloRow method uncheckedGetField.
/*
* split pairs by delimiter.
*/
private Object uncheckedGetField(int id) {
if (getFieldInited()[id]) {
return getFields()[id].getObject();
}
getFieldInited()[id] = true;
ColumnMapping columnMapping = columnMappings.get(id);
LazyObjectBase field = getFields()[id];
if (columnMapping instanceof HiveAccumuloMapColumnMapping) {
HiveAccumuloMapColumnMapping mapColumnMapping = (HiveAccumuloMapColumnMapping) columnMapping;
LazyAccumuloMap map = (LazyAccumuloMap) field;
map.init(row, mapColumnMapping);
} else {
byte[] value;
if (columnMapping instanceof HiveAccumuloRowIdColumnMapping) {
// Use the rowID directly
value = row.getRowId().getBytes();
} else if (columnMapping instanceof HiveAccumuloColumnMapping) {
HiveAccumuloColumnMapping accumuloColumnMapping = (HiveAccumuloColumnMapping) columnMapping;
// Use the colfam and colqual to get the value
value = row.getValue(new Text(accumuloColumnMapping.getColumnFamilyBytes()), new Text(accumuloColumnMapping.getColumnQualifierBytes()));
} else {
log.error("Could not process ColumnMapping of type " + columnMapping.getClass() + " at offset " + id + " in column mapping: " + columnMapping.getMappingSpec());
throw new IllegalArgumentException("Cannot process ColumnMapping of type " + columnMapping.getClass());
}
if (value == null || isNull(oi.getNullSequence(), value, 0, value.length)) {
field.setNull();
} else {
ByteArrayRef ref = new ByteArrayRef();
ref.setData(value);
field.init(ref, 0, value.length);
}
}
return field.getObject();
}
use of org.apache.hadoop.hive.serde2.lazy.LazyObjectBase in project hive by apache.
the class LazyHBaseRow method uncheckedGetField.
/**
* Get the field out of the row without checking whether parsing is needed.
* This is called by both getField and getFieldsAsList.
* @param fieldID The id of the field starting from 0.
* @return The value of the field
*/
private Object uncheckedGetField(int fieldID) {
LazyObjectBase[] fields = getFields();
boolean[] fieldsInited = getFieldInited();
if (!fieldsInited[fieldID]) {
fieldsInited[fieldID] = true;
ColumnMapping colMap = columnsMapping[fieldID];
if (!colMap.hbaseRowKey && !colMap.hbaseTimestamp && colMap.qualifierName == null) {
// it is a column family
// primitive type for Map<Key, Value> can be stored in binary format. Pass in the
// qualifier prefix to cherry pick the qualifiers that match the prefix instead of picking
// up everything
((LazyHBaseCellMap) fields[fieldID]).init(result, colMap.familyNameBytes, colMap.binaryStorage, colMap.qualifierPrefixBytes, colMap.isDoPrefixCut());
return fields[fieldID].getObject();
}
if (colMap.hbaseTimestamp) {
// Get the latest timestamp of all the cells as the row timestamp
// from hbase-0.96.0
long timestamp = result.rawCells()[0].getTimestamp();
for (int i = 1; i < result.rawCells().length; i++) {
timestamp = Math.max(timestamp, result.rawCells()[i].getTimestamp());
}
LazyObjectBase lz = fields[fieldID];
if (lz instanceof LazyTimestamp) {
((LazyTimestamp) lz).getWritableObject().set(Timestamp.ofEpochMilli(timestamp));
} else {
((LazyLong) lz).getWritableObject().set(timestamp);
}
return lz.getObject();
}
byte[] bytes;
if (colMap.hbaseRowKey) {
bytes = result.getRow();
} else {
// it is a column i.e. a column-family with column-qualifier
bytes = result.getValue(colMap.familyNameBytes, colMap.qualifierNameBytes);
}
if (bytes == null || isNull(oi.getNullSequence(), bytes, 0, bytes.length)) {
fields[fieldID].setNull();
} else {
ByteArrayRef ref = new ByteArrayRef();
ref.setData(bytes);
fields[fieldID].init(ref, 0, bytes.length);
}
}
return fields[fieldID].getObject();
}
use of org.apache.hadoop.hive.serde2.lazy.LazyObjectBase in project hive by apache.
the class TestDefaultAccumuloRowIdFactory method testBinaryStringRowId.
@Test
public void testBinaryStringRowId() throws SerDeException {
AccumuloSerDe accumuloSerDe = new AccumuloSerDe();
Properties properties = new Properties();
Configuration conf = new Configuration();
properties.setProperty(AccumuloSerDeParameters.COLUMN_MAPPINGS, ":rowID,cf:cq");
properties.setProperty(serdeConstants.LIST_COLUMNS, "row,col");
properties.setProperty(serdeConstants.LIST_COLUMN_TYPES, "string,string");
properties.setProperty(AccumuloSerDeParameters.DEFAULT_STORAGE_TYPE, ColumnEncoding.BINARY.getName());
accumuloSerDe.initialize(conf, properties, null);
DefaultAccumuloRowIdFactory rowIdFactory = new DefaultAccumuloRowIdFactory();
rowIdFactory.init(accumuloSerDe.getParams(), properties);
LazyStringObjectInspector oi = LazyPrimitiveObjectInspectorFactory.getLazyStringObjectInspector(false, (byte) '\\');
LazyObjectBase lazyObj = rowIdFactory.createRowId(oi);
Assert.assertNotNull(lazyObj);
Assert.assertTrue(LazyString.class.isAssignableFrom(lazyObj.getClass()));
}
Aggregations