Search in sources :

Example 1 with SettableMapObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.SettableMapObjectInspector in project hive by apache.

the class VectorDeserializeRow method convertMapRowColumn.

private Object convertMapRowColumn(ColumnVector colVector, int batchIndex, Field field) throws IOException {
    final SettableMapObjectInspector mapOI = (SettableMapObjectInspector) field.objectInspector;
    final MapComplexTypeHelper mapHelper = (MapComplexTypeHelper) field.getComplexHelper();
    final Field keyField = mapHelper.getKeyField();
    final Field valueField = mapHelper.getValueField();
    final MapColumnVector mapColumnVector = (MapColumnVector) colVector;
    final Object map = mapOI.create();
    while (deserializeRead.isNextComplexMultiValue()) {
        final Object key = convertComplexFieldRowColumn(mapColumnVector.keys, batchIndex, keyField);
        final Object value = convertComplexFieldRowColumn(mapColumnVector.values, batchIndex, valueField);
        mapOI.put(map, key, value);
    }
    return map;
}
Also used : StructField(org.apache.hadoop.hive.serde2.objectinspector.StructField) SettableMapObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.SettableMapObjectInspector)

Example 2 with SettableMapObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.SettableMapObjectInspector in project hive by apache.

the class TestVectorExpressionWriters method testMapLong.

@SuppressWarnings("unchecked")
private void testMapLong() throws HiveException {
    LongColumnVector kcv = VectorizedRowGroupGenUtil.generateLongColumnVector(true, false, 5, new Random(10));
    LongColumnVector vcv = VectorizedRowGroupGenUtil.generateLongColumnVector(true, false, 5, new Random(10));
    MapColumnVector cv = new MapColumnVector(3, kcv, vcv);
    cv.init();
    // set the offset and length for the two elements
    cv.offsets[0] = 0;
    cv.lengths[0] = 2;
    cv.offsets[1] = 2;
    cv.lengths[1] = 3;
    // initialize the keys and values
    for (int i = 0; i < 5; i++) {
        kcv.vector[i] = i;
        kcv.isNull[i] = false;
    }
    kcv.noNulls = true;
    for (int i = 0; i < 5; i++) {
        vcv.vector[i] = 5 + i;
        vcv.isNull[i] = false;
    }
    vcv.noNulls = true;
    cv.isNull[0] = false;
    cv.isNull[1] = false;
    cv.isNull[2] = true;
    cv.noNulls = false;
    SettableMapObjectInspector mapOI = ObjectInspectorFactory.getStandardMapObjectInspector(PrimitiveObjectInspectorFactory.writableIntObjectInspector, PrimitiveObjectInspectorFactory.writableIntObjectInspector);
    VectorExpressionWriter vew = VectorExpressionWriterFactory.genVectorExpressionWritable(mapOI);
    Map<Object, Object> values1 = (Map<Object, Object>) mapOI.create();
    vew.setValue(values1, cv, 0);
    Map<Object, Object> values2 = (Map<Object, Object>) mapOI.create();
    vew.setValue(values2, cv, 1);
    TestCase.assertEquals(2, values1.size());
    TestCase.assertEquals(3, values2.size());
    for (int i = 0; i < values1.size(); i++) {
        IntWritable key = new IntWritable(i);
        IntWritable w = (IntWritable) values1.get(key);
        TestCase.assertEquals(5 + i, w.get());
    }
    for (int i = 0; i < values2.size(); i++) {
        IntWritable key = new IntWritable(2 + i);
        IntWritable w = (IntWritable) values2.get(key);
        TestCase.assertEquals(5 + 2 + i, w.get());
    }
    Map<Object, Object> values3 = (Map<Object, Object>) vew.writeValue(cv, 0);
    TestCase.assertEquals(2, values3.size());
    for (int i = 0; i < values1.size(); i++) {
        IntWritable key = new IntWritable(i);
        IntWritable w = (IntWritable) values1.get(key);
        TestCase.assertEquals(5 + i, w.get());
    }
    Map<Object, Object> values4 = (Map<Object, Object>) vew.writeValue(cv, 1);
    TestCase.assertEquals(3, values4.size());
    for (int i = 0; i < values2.size(); i++) {
        IntWritable key = new IntWritable(2 + i);
        IntWritable w = (IntWritable) values2.get(key);
        TestCase.assertEquals(5 + 2 + i, w.get());
    }
    Map<Object, Object> values5 = (Map<Object, Object>) vew.writeValue(cv, 2);
    TestCase.assertNull(values5);
}
Also used : Random(java.util.Random) MapColumnVector(org.apache.hadoop.hive.ql.exec.vector.MapColumnVector) SettableMapObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.SettableMapObjectInspector) Map(java.util.Map) LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector) IntWritable(org.apache.hadoop.io.IntWritable)

Aggregations

SettableMapObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.SettableMapObjectInspector)2 Map (java.util.Map)1 Random (java.util.Random)1 LongColumnVector (org.apache.hadoop.hive.ql.exec.vector.LongColumnVector)1 MapColumnVector (org.apache.hadoop.hive.ql.exec.vector.MapColumnVector)1 StructField (org.apache.hadoop.hive.serde2.objectinspector.StructField)1 IntWritable (org.apache.hadoop.io.IntWritable)1