beam-sdks-java-core and
will be eventually removed. Please, migrate to a new module
beam-sdks-java-extensions-avro by importing
org.apache.beam.sdk.extensions.avro.schemas.utils.AvroUtils instead of this one.@Experimental(value=SCHEMAS) @Deprecated public class AvroUtils extends java.lang.Object
Avro Beam Field Type
INT <-----> INT32
LONG <-----> INT64
FLOAT <-----> FLOAT
DOUBLE <-----> DOUBLE
BOOLEAN <-----> BOOLEAN
STRING <-----> STRING
BYTES <-----> BYTES
<------ LogicalType(urn="beam:logical_type:var_bytes:v1")
FIXED <-----> LogicalType(urn="beam:logical_type:fixed_bytes:v1")
ARRAY <-----> ARRAY
ENUM <-----> LogicalType(EnumerationType)
MAP <-----> MAP
RECORD <-----> ROW
UNION <-----> LogicalType(OneOfType)
LogicalTypes.Date <-----> LogicalType(DATE)
<------ LogicalType(urn="beam:logical_type:date:v1")
LogicalTypes.TimestampMillis <-----> DATETIME
LogicalTypes.Decimal <-----> DECIMAL
For SQL CHAR/VARCHAR types, an Avro schema
LogicalType({"type":"string","logicalType":"char","maxLength":MAX_LENGTH}) or
LogicalType({"type":"string","logicalType":"varchar","maxLength":MAX_LENGTH})
is used.| Modifier and Type | Class and Description |
|---|---|
static class |
AvroUtils.AvroConvertType
Deprecated.
|
static class |
AvroUtils.AvroConvertValueForGetter
Deprecated.
|
static class |
AvroUtils.AvroConvertValueForSetter
Deprecated.
|
static class |
AvroUtils.FixedBytesField
Deprecated.
Wrapper for fixed byte fields.
|
static class |
AvroUtils.TypeWithNullability
Deprecated.
Unwrap an AVRO schema into the base type an whether it is nullable.
|
| Modifier and Type | Method and Description |
|---|---|
static @Nullable java.lang.Object |
convertAvroFieldStrict(@Nullable java.lang.Object value,
Schema avroSchema,
Schema.FieldType fieldType)
Deprecated.
Strict conversion from AVRO to Beam, strict because it doesn't do widening or narrowing during
conversion.
|
static SimpleFunction<byte[],Row> |
getAvroBytesToRowFunction(Schema beamSchema)
Deprecated.
Returns a function mapping encoded AVRO
GenericRecords to Beam Rows. |
static <T> SchemaUserTypeCreator |
getCreator(java.lang.Class<T> clazz,
Schema schema)
Deprecated.
Get an object creator for an AVRO-generated SpecificRecord.
|
static <T> java.util.List<FieldValueTypeInformation> |
getFieldTypes(java.lang.Class<T> clazz,
Schema schema)
Deprecated.
Get field types for an AVRO-generated SpecificRecord or a POJO.
|
static <T> SerializableFunction<Row,T> |
getFromRowFunction(java.lang.Class<T> clazz)
Deprecated.
|
static SerializableFunction<GenericRecord,Row> |
getGenericRecordToRowFunction(@Nullable Schema schema)
Deprecated.
Returns a function mapping AVRO
GenericRecords to Beam Rows for use in PCollection.setSchema(org.apache.beam.sdk.schemas.Schema, org.apache.beam.sdk.values.TypeDescriptor<T>, 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)
Deprecated.
Get generated getters for an AVRO-generated SpecificRecord or a POJO.
|
static SimpleFunction<Row,byte[]> |
getRowToAvroBytesFunction(Schema beamSchema)
Deprecated.
Returns a function mapping Beam
Rows to encoded AVRO GenericRecords. |
static SerializableFunction<Row,GenericRecord> |
getRowToGenericRecordFunction(Schema avroSchema)
Deprecated.
Returns a function mapping Beam
Rows to AVRO GenericRecords for use in PCollection.setSchema(org.apache.beam.sdk.schemas.Schema, org.apache.beam.sdk.values.TypeDescriptor<T>, 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> @Nullable Schema |
getSchema(java.lang.Class<T> clazz,
Schema schema)
Deprecated.
|
static <T> SerializableFunction<T,Row> |
getToRowFunction(java.lang.Class<T> clazz,
Schema schema)
Deprecated.
|
static <T> SchemaCoder<T> |
schemaCoder(AvroCoder<T> avroCoder)
Deprecated.
Returns an
SchemaCoder instance based on the provided AvroCoder for the element type. |
static <T> SchemaCoder<T> |
schemaCoder(java.lang.Class<T> clazz)
Deprecated.
Returns an
SchemaCoder instance for the provided element class. |
static <T> SchemaCoder<T> |
schemaCoder(java.lang.Class<T> clazz,
Schema schema)
Deprecated.
Returns an
SchemaCoder instance for the provided element type using the provided Avro
schema. |
static SchemaCoder<GenericRecord> |
schemaCoder(Schema schema)
Deprecated.
Returns an
SchemaCoder instance for the Avro schema. |
static <T> SchemaCoder<T> |
schemaCoder(TypeDescriptor<T> type)
Deprecated.
Returns an
SchemaCoder instance for the provided element type. |
static Schema.Field |
toAvroField(Schema.Field field,
java.lang.String namespace)
Deprecated.
Get Avro Field from Beam Field.
|
static Schema |
toAvroSchema(Schema beamSchema)
Deprecated.
|
static Schema |
toAvroSchema(Schema beamSchema,
@Nullable java.lang.String name,
@Nullable java.lang.String namespace)
Deprecated.
Converts a Beam Schema into an AVRO schema.
|
static Schema.Field |
toBeamField(Schema.Field field)
Deprecated.
Get Beam Field from avro Field.
|
static Row |
toBeamRowStrict(GenericRecord record,
@Nullable Schema schema)
Deprecated.
Strict conversion from AVRO to Beam, strict because it doesn't do widening or narrowing during
conversion.
|
static Schema |
toBeamSchema(Schema schema)
Deprecated.
Converts AVRO schema to Beam row schema.
|
static GenericRecord |
toGenericRecord(Row row)
Deprecated.
Convert from a Beam Row to an AVRO GenericRecord.
|
static GenericRecord |
toGenericRecord(Row row,
Schema avroSchema)
Deprecated.
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, java.lang.String namespace)
public static Schema toBeamSchema(Schema schema)
schema - schema of type RECORDpublic static Schema toAvroSchema(Schema beamSchema, @Nullable java.lang.String name, @Nullable java.lang.String namespace)
public static Row toBeamRowStrict(GenericRecord record, @Nullable Schema schema)
public static GenericRecord toGenericRecord(Row row)
public static GenericRecord toGenericRecord(Row row, Schema avroSchema)
public static <T> SerializableFunction<T,Row> getToRowFunction(java.lang.Class<T> clazz, Schema schema)
public static <T> SerializableFunction<Row,T> getFromRowFunction(java.lang.Class<T> clazz)
public static <T> @Nullable Schema getSchema(java.lang.Class<T> clazz, Schema schema)
public static SimpleFunction<byte[],Row> getAvroBytesToRowFunction(Schema beamSchema)
GenericRecords to Beam Rows.public static SimpleFunction<Row,byte[]> getRowToAvroBytesFunction(Schema beamSchema)
Rows to encoded AVRO GenericRecords.public static SerializableFunction<GenericRecord,Row> getGenericRecordToRowFunction(@Nullable Schema schema)
GenericRecords to Beam Rows for use in PCollection.setSchema(org.apache.beam.sdk.schemas.Schema, org.apache.beam.sdk.values.TypeDescriptor<T>, 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(Schema avroSchema)
Rows to AVRO GenericRecords for use in PCollection.setSchema(org.apache.beam.sdk.schemas.Schema, org.apache.beam.sdk.values.TypeDescriptor<T>, 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> SchemaCoder<T> schemaCoder(TypeDescriptor<T> type)
SchemaCoder instance for the provided element type.T - the element typepublic static <T> SchemaCoder<T> schemaCoder(java.lang.Class<T> clazz)
SchemaCoder instance for the provided element class.T - the element typepublic static SchemaCoder<GenericRecord> schemaCoder(Schema schema)
SchemaCoder instance for the Avro schema. The implicit type is
GenericRecord.public static <T> SchemaCoder<T> schemaCoder(java.lang.Class<T> clazz, Schema schema)
SchemaCoder instance for the provided element type using the provided Avro
schema.
If the type argument is GenericRecord, the schema may be arbitrary. Otherwise, the schema must correspond to the type provided.
T - the element typepublic static <T> SchemaCoder<T> schemaCoder(AvroCoder<T> avroCoder)
SchemaCoder instance based on the provided AvroCoder for the element type.T - the element typepublic 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)
public static @Nullable 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