本文整理汇总了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);
}
示例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);
}
示例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());
}
示例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 );
}
示例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;
}
示例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) }));
}
示例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;
}
示例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);
}