本文整理汇总了Java中org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.getUnionTypeInfo方法的典型用法代码示例。如果您正苦于以下问题:Java TypeInfoFactory.getUnionTypeInfo方法的具体用法?Java TypeInfoFactory.getUnionTypeInfo怎么用?Java TypeInfoFactory.getUnionTypeInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory
的用法示例。
在下文中一共展示了TypeInfoFactory.getUnionTypeInfo方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: unionStringLongJava
import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory; //导入方法依赖的package包/类
@Test
public void unionStringLongJava() throws UnexpectedTypeException {
List<TypeInfo> typeInfos = Arrays.asList((TypeInfo) TypeInfoFactory.stringTypeInfo, TypeInfoFactory.longTypeInfo);
TypeInfo typeInfo = TypeInfoFactory.getUnionTypeInfo(typeInfos);
Converter converter = getConverter(typeInfo);
assertThat(converter.toJavaObject(null), is(nullValue()));
assertThat(converter.toJavaObject(new StandardUnion((byte) 0, new Text("a"))), is((Object) "a"));
assertThat(converter.toJavaObject(new StandardUnion((byte) 1, new LongWritable(1L))), is((Object) 1L));
try {
converter.toJavaObject(new StandardUnion((byte) 1, new IntWritable(1)));
} catch (UnexpectedTypeException e) {
return;
}
fail();
}
示例2: convertUnion
import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory; //导入方法依赖的package包/类
static TypeInfo convertUnion(Schema avroUnion) {
Preconditions.checkArgument(
Schema.Type.UNION.equals(avroUnion.getType()),
"Avro Schema must be a Union");
final List<TypeInfo> nonNullTypes = Lists.newArrayList();
for (Schema schema : avroUnion.getTypes()) {
if (!Schema.Type.NULL.equals(schema.getType())) {
nonNullTypes.add(convert(schema));
}
}
// check for a single, possible nullable field
if (nonNullTypes.size() == 1) {
// TODO: where does nullability get passed?
// nullable if avroUnion.getTypes().size() == 2
return nonNullTypes.get(0);
}
return TypeInfoFactory.getUnionTypeInfo(nonNullTypes);
}
示例3: readUnionString
import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory; //导入方法依赖的package包/类
@Test
public void readUnionString() throws IOException {
TypeInfo typeInfo = TypeInfoFactory.getUnionTypeInfo(Arrays.asList((TypeInfo) TypeInfoFactory.stringTypeInfo));
try (OrcWriter writer = getOrcWriter(typeInfo)) {
writer.addRow(new StandardUnion((byte) 0, "hello"));
writer.addRow((Object) null);
}
List<Tuple> list = read(typeInfo);
assertThat(list.size(), is(2));
assertThat(list.get(0).getObject(0), is((Object) "hello"));
assertThat(list.get(1).getObject(0), is(nullValue()));
}
示例4: getComplexTypeDesc
import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory; //导入方法依赖的package包/类
private static TypeInfo getComplexTypeDesc(DataType type) {
TypeInfo resultTypeInfo = null;
switch (type.getCategory()) {
case Basic:
resultTypeInfo = ConverterUtils.ORCTYpeInfoMap.get(type.toString());
break;
case Struct:
StructType structObjectType = (StructType) type;
final DataType[] columnTypes = structObjectType.getColumnTypes();
List<TypeInfo> typeInfos = new ArrayList<>();
for (int i = 0; i < columnTypes.length; i++) {
typeInfos.add(getComplexTypeDesc(columnTypes[i]));
}
resultTypeInfo = TypeInfoFactory
.getStructTypeInfo(Arrays.asList(structObjectType.getColumnNames()), typeInfos);;
break;
case List:
ListType listObjectType = (ListType) type;
resultTypeInfo =
TypeInfoFactory.getListTypeInfo(getComplexTypeDesc(listObjectType.getTypeOfElement()));
break;
case Union:
final UnionType unionObjectType = (UnionType) type;
final DataType[] columnTypes1 = unionObjectType.getColumnTypes();
List<TypeInfo> unionTypeInfos = new ArrayList<>();
for (int i = 0; i < columnTypes1.length; i++) {
unionTypeInfos.add(getComplexTypeDesc(columnTypes1[i]));
}
resultTypeInfo = TypeInfoFactory.getUnionTypeInfo(unionTypeInfos);
break;
case Map:
MapType mapObjectType = (MapType) type;
resultTypeInfo =
TypeInfoFactory.getMapTypeInfo(getComplexTypeDesc(mapObjectType.getTypeOfKey()),
getComplexTypeDesc(mapObjectType.getTypeOfValue()));
break;
default:
break;
}
return resultTypeInfo;
}