當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。