Search in sources :

Example 6 with HiveAccumuloMapColumnMapping

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());
}
Also used : LazyMapObjectInspector(org.apache.hadoop.hive.serde2.lazy.objectinspector.LazyMapObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) HiveAccumuloMapColumnMapping(org.apache.hadoop.hive.accumulo.columns.HiveAccumuloMapColumnMapping) Text(org.apache.hadoop.io.Text) IntWritable(org.apache.hadoop.io.IntWritable) Test(org.junit.Test)

Example 7 with HiveAccumuloMapColumnMapping

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();
}
Also used : ByteArrayRef(org.apache.hadoop.hive.serde2.lazy.ByteArrayRef) HiveAccumuloRowIdColumnMapping(org.apache.hadoop.hive.accumulo.columns.HiveAccumuloRowIdColumnMapping) HiveAccumuloMapColumnMapping(org.apache.hadoop.hive.accumulo.columns.HiveAccumuloMapColumnMapping) LazyObjectBase(org.apache.hadoop.hive.serde2.lazy.LazyObjectBase) Text(org.apache.hadoop.io.Text) HiveAccumuloColumnMapping(org.apache.hadoop.hive.accumulo.columns.HiveAccumuloColumnMapping) HiveAccumuloMapColumnMapping(org.apache.hadoop.hive.accumulo.columns.HiveAccumuloMapColumnMapping) HiveAccumuloColumnMapping(org.apache.hadoop.hive.accumulo.columns.HiveAccumuloColumnMapping) HiveAccumuloRowIdColumnMapping(org.apache.hadoop.hive.accumulo.columns.HiveAccumuloRowIdColumnMapping) ColumnMapping(org.apache.hadoop.hive.accumulo.columns.ColumnMapping)

Aggregations

HiveAccumuloMapColumnMapping (org.apache.hadoop.hive.accumulo.columns.HiveAccumuloMapColumnMapping)7 Text (org.apache.hadoop.io.Text)6 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)5 LazyMapObjectInspector (org.apache.hadoop.hive.serde2.lazy.objectinspector.LazyMapObjectInspector)4 Test (org.junit.Test)4 ColumnMapping (org.apache.hadoop.hive.accumulo.columns.ColumnMapping)3 HiveAccumuloColumnMapping (org.apache.hadoop.hive.accumulo.columns.HiveAccumuloColumnMapping)3 IntWritable (org.apache.hadoop.io.IntWritable)3 HashSet (java.util.HashSet)1 Mutation (org.apache.accumulo.core.data.Mutation)1 Pair (org.apache.accumulo.core.util.Pair)1 HiveAccumuloRowIdColumnMapping (org.apache.hadoop.hive.accumulo.columns.HiveAccumuloRowIdColumnMapping)1 SerDeException (org.apache.hadoop.hive.serde2.SerDeException)1 ByteArrayRef (org.apache.hadoop.hive.serde2.lazy.ByteArrayRef)1 LazyObjectBase (org.apache.hadoop.hive.serde2.lazy.LazyObjectBase)1 ListObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector)1 MapObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector)1 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)1 StructField (org.apache.hadoop.hive.serde2.objectinspector.StructField)1 StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)1