@Experimental(value=SCHEMAS) public class AvroUtils extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
AvroUtils.FixedBytesField
Wrapper for fixed byte fields.
|
Modifier and Type | Method and Description |
---|---|
static java.lang.Object |
convertAvroFieldStrict(java.lang.Object value,
Schema avroSchema,
Schema.FieldType fieldType)
Strict conversion from AVRO to Beam, strict because it doesn't do widening or narrowing during
conversion.
|
static <T> SchemaUserTypeCreator |
getCreator(java.lang.Class<T> clazz,
Schema schema)
Get an object creator for an AVRO-generated SpecificRecord.
|
static <T> java.util.List<FieldValueTypeInformation> |
getFieldTypes(java.lang.Class<T> clazz,
Schema schema)
Get field types for an AVRO-generated SpecificRecord or a POJO.
|
static <T> SerializableFunction<Row,T> |
getFromRowFunction(java.lang.Class<T> clazz) |
static SerializableFunction<GenericRecord,Row> |
getGenericRecordToRowFunction(Schema schema)
Returns a function mapping AVRO
GenericRecord s to Beam Row s for use in PCollection.setSchema(org.apache.beam.sdk.schemas.Schema, org.apache.beam.sdk.transforms.SerializableFunction<T, org.apache.beam.sdk.values.Row>, org.apache.beam.sdk.transforms.SerializableFunction<org.apache.beam.sdk.values.Row, T>) . |
static <T> java.util.List<FieldValueGetter> |
getGetters(java.lang.Class<T> clazz,
Schema schema)
Get generated getters for an AVRO-generated SpecificRecord or a POJO.
|
static SerializableFunction<Row,GenericRecord> |
getRowToGenericRecordFunction(Schema avroSchema)
Returns a function mapping Beam
Row s to AVRO GenericRecord s for use in PCollection.setSchema(org.apache.beam.sdk.schemas.Schema, org.apache.beam.sdk.transforms.SerializableFunction<T, org.apache.beam.sdk.values.Row>, org.apache.beam.sdk.transforms.SerializableFunction<org.apache.beam.sdk.values.Row, T>) . |
static <T> Schema |
getSchema(java.lang.Class<T> clazz,
Schema schema) |
static <T> SerializableFunction<T,Row> |
getToRowFunction(java.lang.Class<T> clazz,
Schema schema) |
static Schema.Field |
toAvroField(Schema.Field field)
Get Avro Field from Beam Field.
|
static Schema |
toAvroSchema(Schema beamSchema)
Converts a Beam Schema into an AVRO schema.
|
static Schema.Field |
toBeamField(Schema.Field field)
Get Beam Field from avro Field.
|
static Row |
toBeamRowStrict(GenericRecord record,
Schema schema)
Strict conversion from AVRO to Beam, strict because it doesn't do widening or narrowing during
conversion.
|
static Schema |
toBeamSchema(Schema schema)
Converts AVRO schema to Beam row schema.
|
static GenericRecord |
toGenericRecord(Row row,
Schema avroSchema)
Convert from a Beam Row to an AVRO GenericRecord.
|
public static Schema.Field toBeamField(Schema.Field field)
public static Schema.Field toAvroField(Schema.Field field)
public static Schema toBeamSchema(Schema schema)
schema
- schema of type RECORDpublic static Schema toAvroSchema(Schema beamSchema)
public static Row toBeamRowStrict(GenericRecord record, @Nullable Schema schema)
public static GenericRecord toGenericRecord(Row row, @Nullable Schema avroSchema)
public static <T> SerializableFunction<T,Row> getToRowFunction(java.lang.Class<T> clazz, @Nullable Schema schema)
public static <T> SerializableFunction<Row,T> getFromRowFunction(java.lang.Class<T> clazz)
@Nullable public static <T> Schema getSchema(java.lang.Class<T> clazz, @Nullable Schema schema)
public static SerializableFunction<GenericRecord,Row> getGenericRecordToRowFunction(@Nullable Schema schema)
GenericRecord
s to Beam Row
s for use in PCollection.setSchema(org.apache.beam.sdk.schemas.Schema, org.apache.beam.sdk.transforms.SerializableFunction<T, org.apache.beam.sdk.values.Row>, org.apache.beam.sdk.transforms.SerializableFunction<org.apache.beam.sdk.values.Row, T>)
.public static SerializableFunction<Row,GenericRecord> getRowToGenericRecordFunction(@Nullable Schema avroSchema)
Row
s to AVRO GenericRecord
s for use in PCollection.setSchema(org.apache.beam.sdk.schemas.Schema, org.apache.beam.sdk.transforms.SerializableFunction<T, org.apache.beam.sdk.values.Row>, org.apache.beam.sdk.transforms.SerializableFunction<org.apache.beam.sdk.values.Row, T>)
.public static <T> java.util.List<FieldValueTypeInformation> getFieldTypes(java.lang.Class<T> clazz, Schema schema)
public static <T> java.util.List<FieldValueGetter> getGetters(java.lang.Class<T> clazz, Schema schema)
public static <T> SchemaUserTypeCreator getCreator(java.lang.Class<T> clazz, Schema schema)
@Nullable public static java.lang.Object convertAvroFieldStrict(@Nullable java.lang.Object value, @Nonnull Schema avroSchema, @Nonnull Schema.FieldType fieldType)
value
- GenericRecord
or any nested valueavroSchema
- schema for valuefieldType
- target beam field typeRow