当前位置: 首页>>代码示例>>Java>>正文


Java TypeInfoFactory.getUnionTypeInfo方法代码示例

本文整理汇总了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();
}
 
开发者ID:HotelsDotCom,项目名称:corc,代码行数:18,代码来源:DefaultConverterFactoryTest.java

示例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);
}
 
开发者ID:cloudera,项目名称:cdk,代码行数:22,代码来源:HiveUtils.java

示例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()));
}
 
开发者ID:HotelsDotCom,项目名称:corc,代码行数:15,代码来源:OrcFileTest.java

示例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;
}
 
开发者ID:ampool,项目名称:monarch,代码行数:43,代码来源:ORCColumnConverterDescriptor.java


注:本文中的org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.getUnionTypeInfo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。