use of org.apache.hadoop.hive.accumulo.columns.HiveAccumuloMapColumnMapping in project hive by apache.
the class TestLazyAccumuloMap method testIntMap.
@Test
public void testIntMap() throws SerDeException, IOException {
AccumuloHiveRow row = new AccumuloHiveRow("row");
row.add(new Text("cf1"), new Text("1"), "2".getBytes());
row.add(new Text("cf1"), new Text("2"), "4".getBytes());
row.add(new Text("cf1"), new Text("3"), "6".getBytes());
HiveAccumuloMapColumnMapping mapping = new HiveAccumuloMapColumnMapping("cf1", null, ColumnEncoding.STRING, ColumnEncoding.STRING, "column", TypeInfoFactory.getMapTypeInfo(TypeInfoFactory.intTypeInfo, TypeInfoFactory.intTypeInfo).toString());
// Map of Integer to Integer
Text nullSequence = new Text("\\N");
ObjectInspector oi = LazyFactory.createLazyObjectInspector(TypeInfoUtils.getTypeInfosFromTypeString("map<int,int>").get(0), new byte[] { (byte) 1, (byte) 2 }, 0, nullSequence, false, (byte) 0);
LazyAccumuloMap map = new LazyAccumuloMap((LazyMapObjectInspector) oi);
map.init(row, mapping);
Assert.assertEquals(3, map.getMapSize());
Object o = map.getMapValueElement(new IntWritable(1));
Assert.assertNotNull(o);
Assert.assertEquals(new IntWritable(2), ((LazyInteger) o).getWritableObject());
o = map.getMapValueElement(new IntWritable(2));
Assert.assertNotNull(o);
Assert.assertEquals(new IntWritable(4), ((LazyInteger) o).getWritableObject());
o = map.getMapValueElement(new IntWritable(3));
Assert.assertNotNull(o);
Assert.assertEquals(new IntWritable(6), ((LazyInteger) o).getWritableObject());
}
use of org.apache.hadoop.hive.accumulo.columns.HiveAccumuloMapColumnMapping 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();
}
Aggregations