use of org.apache.hadoop.hive.serde2.objectinspector.StandardListObjectInspector in project cdap by caskdata.
the class StandardObjectInspectorsTest method testCollectionObjectInspector.
@Test
public void testCollectionObjectInspector() throws Throwable {
// Test with sets
ObjectInspector oi = ObjectInspectorFactory.getReflectionObjectInspector(new TypeToken<Set<String>>() {
}.getType());
Assert.assertTrue(oi instanceof StandardListObjectInspector);
StandardListObjectInspector loi = (StandardListObjectInspector) oi;
Set<String> set = Sets.newHashSet("foo", "bar", "foobar");
List<?> inspectedSet = loi.getList(set);
Assert.assertTrue(inspectedSet.contains("foo"));
Assert.assertTrue(inspectedSet.contains("bar"));
Assert.assertTrue(inspectedSet.contains("foobar"));
// Test with queues
oi = ObjectInspectorFactory.getReflectionObjectInspector(new TypeToken<Queue<String>>() {
}.getType());
Assert.assertTrue(oi instanceof StandardListObjectInspector);
loi = (StandardListObjectInspector) oi;
Queue<String> queue = new LinkedList<>();
queue.add("foo");
queue.add("bar");
List<?> inspectedQueue = loi.getList(set);
Assert.assertEquals("bar", inspectedQueue.get(0));
Assert.assertEquals("foo", inspectedQueue.get(1));
}
use of org.apache.hadoop.hive.serde2.objectinspector.StandardListObjectInspector in project hive by apache.
the class TestGenericUDFMapValues method testNullMap.
@Test
public void testNullMap() throws HiveException, IOException {
ObjectInspector[] inputOIs = { ObjectInspectorFactory.getStandardMapObjectInspector(PrimitiveObjectInspectorFactory.writableStringObjectInspector, PrimitiveObjectInspectorFactory.writableStringObjectInspector) };
Map<String, String> input = null;
DeferredObject[] args = { new DeferredJavaObject(input) };
GenericUDFMapValues udf = new GenericUDFMapValues();
StandardListObjectInspector oi = (StandardListObjectInspector) udf.initialize(inputOIs);
Object res = udf.evaluate(args);
Assert.assertTrue(oi.getList(res).isEmpty());
udf.close();
}
use of org.apache.hadoop.hive.serde2.objectinspector.StandardListObjectInspector in project hive by apache.
the class MatchPath method createSelectListRR.
/*
* add array<struct> to the list of columns
*/
protected static RowResolver createSelectListRR(MatchPath evaluator, PTFInputDef inpDef) throws SemanticException {
RowResolver rr = new RowResolver();
RowResolver inputRR = inpDef.getOutputShape().getRr();
evaluator.inputColumnNamesMap = new HashMap<String, String>();
ArrayList<String> inputColumnNames = new ArrayList<String>();
ArrayList<ObjectInspector> inpColOIs = new ArrayList<ObjectInspector>();
for (ColumnInfo inpCInfo : inputRR.getColumnInfos()) {
ColumnInfo cInfo = new ColumnInfo(inpCInfo);
String colAlias = cInfo.getAlias();
String[] tabColAlias = inputRR.reverseLookup(inpCInfo.getInternalName());
if (tabColAlias != null) {
colAlias = tabColAlias[1];
}
ASTNode inExpr = null;
inExpr = PTFTranslator.getASTNode(inpCInfo, inputRR);
if (inExpr != null) {
rr.putExpression(inExpr, cInfo);
colAlias = inExpr.toStringTree().toLowerCase();
} else {
colAlias = colAlias == null ? cInfo.getInternalName() : colAlias;
rr.put(cInfo.getTabAlias(), colAlias, cInfo);
}
evaluator.inputColumnNamesMap.put(cInfo.getInternalName(), colAlias);
inputColumnNames.add(colAlias);
inpColOIs.add(cInfo.getObjectInspector());
}
StandardListObjectInspector pathAttrOI = ObjectInspectorFactory.getStandardListObjectInspector(ObjectInspectorFactory.getStandardStructObjectInspector(inputColumnNames, inpColOIs));
ColumnInfo pathColumn = new ColumnInfo(PATHATTR_NAME, TypeInfoUtils.getTypeInfoFromObjectInspector(pathAttrOI), null, false, false);
rr.put(null, PATHATTR_NAME, pathColumn);
return rr;
}
use of org.apache.hadoop.hive.serde2.objectinspector.StandardListObjectInspector in project SQLWindowing by hbutani.
the class NPathUtils method createSelectListInputOI.
/*
* add array<struct> to the list of columns
*/
public static ObjectInspector createSelectListInputOI(StructObjectInspector inputOI) {
List<? extends StructField> fields = inputOI.getAllStructFieldRefs();
ArrayList<ObjectInspector> selectListFieldOIs = new ArrayList<ObjectInspector>();
ArrayList<String> selectListFieldNames = new ArrayList<String>();
StandardListObjectInspector pathAttrOI = ObjectInspectorFactory.getStandardListObjectInspector(ObjectInspectorUtils.getStandardObjectInspector(inputOI));
for (StructField f : fields) {
selectListFieldOIs.add(ObjectInspectorUtils.getStandardObjectInspector(f.getFieldObjectInspector()));
selectListFieldNames.add(f.getFieldName());
}
selectListFieldOIs.add(pathAttrOI);
selectListFieldNames.add(PATHATTR_NAME);
return ObjectInspectorFactory.getStandardStructObjectInspector(selectListFieldNames, selectListFieldOIs);
}
use of org.apache.hadoop.hive.serde2.objectinspector.StandardListObjectInspector in project haivvreo by jghoman.
the class TestAvroDeserializer method canDeserializeArrays.
@Test
public void canDeserializeArrays() throws SerDeException, IOException {
Schema s = Schema.parse(TestAvroObjectInspectorGenerator.ARRAY_WITH_PRIMITIVE_ELEMENT_TYPE);
GenericData.Record record = new GenericData.Record(s);
List<String> list = new ArrayList<String>();
list.add("Eccleston");
list.add("Tennant");
list.add("Smith");
record.put("anArray", list);
assertTrue(GENERIC_DATA.validate(s, record));
System.out.println("Array-backed record = " + record);
AvroGenericRecordWritable garw = Utils.serializeAndDeserializeRecord(record);
AvroObjectInspectorGenerator aoig = new AvroObjectInspectorGenerator(s);
AvroDeserializer de = new AvroDeserializer();
ArrayList<Object> row = (ArrayList<Object>) de.deserialize(aoig.getColumnNames(), aoig.getColumnTypes(), garw, s);
assertEquals(1, row.size());
Object theArrayObject = row.get(0);
assertTrue(theArrayObject instanceof List);
List theList = (List) theArrayObject;
// Verify the raw object that's been created
assertEquals("Eccleston", theList.get(0));
assertEquals("Tennant", theList.get(1));
assertEquals("Smith", theList.get(2));
// Now go the correct way, through objectinspectors
StandardStructObjectInspector oi = (StandardStructObjectInspector) aoig.getObjectInspector();
StructField fieldRefToArray = oi.getStructFieldRef("anArray");
Object anArrayData = oi.getStructFieldData(row, fieldRefToArray);
StandardListObjectInspector anArrayOI = (StandardListObjectInspector) fieldRefToArray.getFieldObjectInspector();
assertEquals(3, anArrayOI.getListLength(anArrayData));
JavaStringObjectInspector elementOI = (JavaStringObjectInspector) anArrayOI.getListElementObjectInspector();
Object firstElement = anArrayOI.getListElement(anArrayData, 0);
assertEquals("Eccleston", elementOI.getPrimitiveJavaObject(firstElement));
assertTrue(firstElement instanceof String);
Object secondElement = anArrayOI.getListElement(anArrayData, 1);
assertEquals("Tennant", elementOI.getPrimitiveJavaObject(secondElement));
assertTrue(secondElement instanceof String);
Object thirdElement = anArrayOI.getListElement(anArrayData, 2);
assertEquals("Smith", elementOI.getPrimitiveJavaObject(thirdElement));
assertTrue(thirdElement instanceof String);
}
Aggregations