本文整理匯總了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);
}