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


Java Schema.createUnion方法代码示例

本文整理汇总了Java中org.apache.avro.Schema.createUnion方法的典型用法代码示例。如果您正苦于以下问题:Java Schema.createUnion方法的具体用法?Java Schema.createUnion怎么用?Java Schema.createUnion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.avro.Schema的用法示例。


在下文中一共展示了Schema.createUnion方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testNullableField

import org.apache.avro.Schema; //导入方法依赖的package包/类
public void testNullableField() throws IOException, SQLException {
  String[] argv = {};
  final int TOTAL_RECORDS = 1 * 10;

  List<Schema> childSchemas = new ArrayList<Schema>();
  childSchemas.add(Schema.create(Schema.Type.NULL));
  childSchemas.add(Schema.create(Schema.Type.STRING));
  Schema schema =  Schema.createUnion(childSchemas);
  ColumnGenerator gen0 = colGenerator(null, schema, null, "VARCHAR(64)");
  ColumnGenerator gen1 = colGenerator("s", schema, "s", "VARCHAR(64)");
  createParquetFile(0, TOTAL_RECORDS, gen0, gen1);
  createTable(gen0, gen1);
  runExport(getArgv(true, 10, 10, newStrArray(argv, "-m", "" + 1)));
  verifyExport(TOTAL_RECORDS);
  assertColMinAndMax(forIdx(0), gen0);
  assertColMinAndMax(forIdx(1), gen1);
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:18,代码来源:TestParquetExport.java

示例2: testNullableField

import org.apache.avro.Schema; //导入方法依赖的package包/类
public void testNullableField() throws IOException, SQLException {
  String[] argv = {};
  final int TOTAL_RECORDS = 1 * 10;

  List<Schema> childSchemas = new ArrayList<Schema>();
  childSchemas.add(Schema.create(Schema.Type.NULL));
  childSchemas.add(Schema.create(Schema.Type.STRING));
  Schema schema =  Schema.createUnion(childSchemas);
  ColumnGenerator gen0 = colGenerator(null, schema, null, "VARCHAR(64)");
  ColumnGenerator gen1 = colGenerator("s", schema, "s", "VARCHAR(64)");
  createAvroFile(0, TOTAL_RECORDS, gen0, gen1);
  createTable(gen0, gen1);
  runExport(getArgv(true, 10, 10, newStrArray(argv, "-m", "" + 1)));
  verifyExport(TOTAL_RECORDS);
  assertColMinAndMax(forIdx(0), gen0);
  assertColMinAndMax(forIdx(1), gen1);
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:18,代码来源:TestAvroExport.java

示例3: testUnionReaderWriterSubsetIncompatibility

import org.apache.avro.Schema; //导入方法依赖的package包/类
/** Reader union schema must contain all writer union branches. */
@Test
public void testUnionReaderWriterSubsetIncompatibility() {
  final Schema unionWriter = Schema.createUnion(list(INT_SCHEMA, STRING_SCHEMA, LONG_SCHEMA));
  final Schema unionReader = Schema.createUnion(list(INT_SCHEMA, STRING_SCHEMA));
  final SchemaPairCompatibility result =
      checkReaderWriterCompatibility(unionReader, unionWriter);
  assertEquals(SchemaCompatibilityType.INCOMPATIBLE, result.getType());
}
 
开发者ID:HotelsDotCom,项目名称:avro-compatibility,代码行数:10,代码来源:TestSchemaCompatibility.java

示例4: AvroUnionSchema

import org.apache.avro.Schema; //导入方法依赖的package包/类
public AvroUnionSchema( final UnionField schema ) throws IOException{
  this.schema = schema;

  List<Schema> childList = new ArrayList<Schema>();
  for( String key : schema.getKeys() ){
    childList.add( AvroSchemaFactory.getAvroSchema( schema.get( key ) , false ) );
  }

  avroSchema = Schema.createUnion( childList );
}
 
开发者ID:yahoojapan,项目名称:dataplatform-schema-lib,代码行数:11,代码来源:AvroUnionSchema.java

示例5: getComplexTypeDesc

import org.apache.avro.Schema; //导入方法依赖的package包/类
private Schema getComplexTypeDesc(DataType type) {
  Schema resultTypeInfo = null;
  switch (type.getCategory()) {
    case Basic:
      resultTypeInfo = parquetAvroSchemaMap.get(type.toString());
      break;
    case Struct:
      // create record here
      StructType structObjectType = (StructType) type;

      List<DataType> dataTypes = Arrays.asList(structObjectType.getColumnTypes());
      Schema[] schemas = dataTypes.stream().map(dataType -> getComplexTypeDesc(dataType))
          .toArray(size -> new Schema[size]);

      resultTypeInfo = ParquetUtils.createAvroRecordSchema(columnName,
          structObjectType.getColumnNames(), schemas);
      break;
    case List:
      resultTypeInfo =
          Schema.createArray(getComplexTypeDesc(((ListType) type).getTypeOfElement()));
      break;
    case Union:
      final UnionType unionObjectType = (UnionType) type;
      final DataType[] columnTypes1 = unionObjectType.getColumnTypes();
      List<Schema> colTypes = new ArrayList<>();
      for (int i = 0; i < columnTypes1.length; i++) {
        colTypes.add(getComplexTypeDesc(columnTypes1[i]));
      }
      resultTypeInfo = Schema.createUnion(colTypes);
      break;
    case Map:
      MapType mapObjectType = (MapType) type;
      resultTypeInfo = Schema.createMap(getComplexTypeDesc(mapObjectType.getTypeOfValue()));
      break;
    default:
      break;

  }
  return resultTypeInfo;
}
 
开发者ID:ampool,项目名称:monarch,代码行数:41,代码来源:ParquetColumnConverterDescriptor.java

示例6: createOptional

import org.apache.avro.Schema; //导入方法依赖的package包/类
private Schema createOptional(Schema schema) {
  return Schema.createUnion(Arrays.asList(
      new Schema[] { schema, Schema.create(Type.NULL) }));
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:5,代码来源:TwitterSource.java

示例7: getAvroSchema

import org.apache.avro.Schema; //导入方法依赖的package包/类
private Schema getAvroSchema() {
  List<Schema.Field> fields = new ArrayList<>();
  for (int i = 0; i < FILE_HEADER.length; i++) {

    Schema.Field field = new Schema.Field(FILE_HEADER[i],
        Schema.createUnion(
            Arrays.asList(Schema.create(Schema.Type.STRING), Schema.create(Schema.Type.NULL))),
        null, null);

    if (FILE_HEADER[i].equals("RowKey")) {
      field = new Schema.Field(FILE_HEADER[i],
          Schema.createUnion(
              Arrays.asList(Schema.create(Schema.Type.BYTES), Schema.create(Schema.Type.NULL))),
          null, null);
    }

    if (FILE_HEADER[i].equals("ID")) {
      field = new Schema.Field(FILE_HEADER[i],
          Schema.createUnion(
              Arrays.asList(Schema.create(Schema.Type.INT), Schema.create(Schema.Type.NULL))),
          null, null);
    }

    if (FILE_HEADER[i].equals("AGE")) {
      field = new Schema.Field(FILE_HEADER[i],
          Schema.createUnion(
              Arrays.asList(Schema.create(Schema.Type.INT), Schema.create(Schema.Type.NULL))),
          null, null);
    }

    if (FILE_HEADER[i].equals("SALARY")) {
      field = new Schema.Field(FILE_HEADER[i],
          Schema.createUnion(
              Arrays.asList(Schema.create(Schema.Type.DOUBLE), Schema.create(Schema.Type.NULL))),
          null, null);
    }

    if (FILE_HEADER[i].equals("VersionID")) {
      field = new Schema.Field(FILE_HEADER[i],
          Schema.createUnion(
              Arrays.asList(Schema.create(Schema.Type.LONG), Schema.create(Schema.Type.NULL))),
          null, null);
    }

    fields.add(field);
  }
  Schema avrorecord = Schema.createRecord("CDCRecord", null, null, false);
  avrorecord.setFields(fields);
  return avrorecord;
}
 
开发者ID:ampool,项目名称:monarch,代码行数:51,代码来源:MTableCDCParquetListener.java

示例8: toAvroSchema

import org.apache.avro.Schema; //导入方法依赖的package包/类
/**
 * Will create union, because each type is assumed to be nullable.
 *
 * @param sqlType Original SQL type (might be overridden by user)
 * @param columnName Column name from the query
 * @return Schema
 */
public Schema toAvroSchema(int sqlType, String columnName) {
  List<Schema> childSchemas = new ArrayList<Schema>();
  childSchemas.add(Schema.create(Schema.Type.NULL));
  childSchemas.add(Schema.create(toAvroType(columnName, sqlType)));
  return Schema.createUnion(childSchemas);
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:14,代码来源:AvroSchemaGenerator.java


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