Class AvroSchemaConverter

java.lang.Object
org.apache.flink.formats.avro.typeutils.AvroSchemaConverter

public class AvroSchemaConverter extends Object
Converts an Avro schema into Flink's type information. It uses RowTypeInfo for representing objects and converts Avro types into types that are compatible with Flink's Table & SQL API.

Note: Changes in this class need to be kept in sync with the corresponding runtime classes AvroRowDataDeserializationSchema and AvroRowDataSerializationSchema.

  • Method Summary

    Modifier and Type
    Method
    Description
    static org.apache.flink.table.types.DataType
    convertToDataType(String avroSchemaString)
    Converts an Avro schema string into a nested row structure with deterministic field order and data types that are compatible with Flink's Table & SQL API.
    static org.apache.flink.table.types.DataType
    convertToDataType(String avroSchemaString, boolean legacyTimestampMapping)
    Converts an Avro schema string into a nested row structure with deterministic field order and data types that are compatible with Flink's Table & SQL API.
    static org.apache.avro.Schema
    convertToSchema(org.apache.flink.table.types.logical.LogicalType schema)
    Converts Flink SQL LogicalType (can be nested) into an Avro schema.
    static org.apache.avro.Schema
    convertToSchema(org.apache.flink.table.types.logical.LogicalType schema, boolean legacyTimestampMapping)
    Converts Flink SQL LogicalType (can be nested) into an Avro schema.
    static org.apache.avro.Schema
    convertToSchema(org.apache.flink.table.types.logical.LogicalType logicalType, String rowName)
    Converts Flink SQL LogicalType (can be nested) into an Avro schema.
    static org.apache.avro.Schema
    convertToSchema(org.apache.flink.table.types.logical.LogicalType logicalType, String rowName, boolean legacyTimestampMapping)
    Converts Flink SQL LogicalType (can be nested) into an Avro schema.
    static <T extends org.apache.avro.specific.SpecificRecord>
    org.apache.flink.api.common.typeinfo.TypeInformation<org.apache.flink.types.Row>
    convertToTypeInfo(Class<T> avroClass)
    Converts an Avro class into a nested row structure with deterministic field order and data types that are compatible with Flink's Table & SQL API.
    static <T extends org.apache.avro.specific.SpecificRecord>
    org.apache.flink.api.common.typeinfo.TypeInformation<org.apache.flink.types.Row>
    convertToTypeInfo(Class<T> avroClass, boolean legacyTimestampMapping)
    Converts an Avro class into a nested row structure with deterministic field order and data types that are compatible with Flink's Table & SQL API.
    static <T> org.apache.flink.api.common.typeinfo.TypeInformation<T>
    convertToTypeInfo(String avroSchemaString)
    Converts an Avro schema string into a nested row structure with deterministic field order and data types that are compatible with Flink's Table & SQL API.
    static <T> org.apache.flink.api.common.typeinfo.TypeInformation<T>
    convertToTypeInfo(String avroSchemaString, boolean legacyTimestampMapping)
    Converts an Avro schema string into a nested row structure with deterministic field order and data types that are compatible with Flink's Table & SQL API.
    static org.apache.flink.table.types.logical.LogicalType
    extractValueTypeToAvroMap(org.apache.flink.table.types.logical.LogicalType type)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • convertToTypeInfo

      public static <T extends org.apache.avro.specific.SpecificRecord> org.apache.flink.api.common.typeinfo.TypeInformation<org.apache.flink.types.Row> convertToTypeInfo(Class<T> avroClass)
      Converts an Avro class into a nested row structure with deterministic field order and data types that are compatible with Flink's Table & SQL API.
      Parameters:
      avroClass - Avro specific record that contains schema information
      Returns:
      type information matching the schema
    • convertToTypeInfo

      public static <T extends org.apache.avro.specific.SpecificRecord> org.apache.flink.api.common.typeinfo.TypeInformation<org.apache.flink.types.Row> convertToTypeInfo(Class<T> avroClass, boolean legacyTimestampMapping)
      Converts an Avro class into a nested row structure with deterministic field order and data types that are compatible with Flink's Table & SQL API.
      Parameters:
      avroClass - Avro specific record that contains schema information
      legacyTimestampMapping - legacy mapping of timestamp types
      Returns:
      type information matching the schema
    • convertToTypeInfo

      public static <T> org.apache.flink.api.common.typeinfo.TypeInformation<T> convertToTypeInfo(String avroSchemaString)
      Converts an Avro schema string into a nested row structure with deterministic field order and data types that are compatible with Flink's Table & SQL API.
      Parameters:
      avroSchemaString - Avro schema definition string
      Returns:
      type information matching the schema
    • convertToTypeInfo

      public static <T> org.apache.flink.api.common.typeinfo.TypeInformation<T> convertToTypeInfo(String avroSchemaString, boolean legacyTimestampMapping)
      Converts an Avro schema string into a nested row structure with deterministic field order and data types that are compatible with Flink's Table & SQL API.
      Parameters:
      avroSchemaString - Avro schema definition string
      legacyTimestampMapping - legacy mapping of timestamp types
      Returns:
      type information matching the schema
    • convertToDataType

      public static org.apache.flink.table.types.DataType convertToDataType(String avroSchemaString)
      Converts an Avro schema string into a nested row structure with deterministic field order and data types that are compatible with Flink's Table & SQL API.
      Parameters:
      avroSchemaString - Avro schema definition string
      Returns:
      data type matching the schema
    • convertToDataType

      public static org.apache.flink.table.types.DataType convertToDataType(String avroSchemaString, boolean legacyTimestampMapping)
      Converts an Avro schema string into a nested row structure with deterministic field order and data types that are compatible with Flink's Table & SQL API.
      Parameters:
      avroSchemaString - Avro schema definition string
      legacyTimestampMapping - legacy mapping of local timestamps
      Returns:
      data type matching the schema
    • convertToSchema

      public static org.apache.avro.Schema convertToSchema(org.apache.flink.table.types.logical.LogicalType schema)
      Converts Flink SQL LogicalType (can be nested) into an Avro schema.

      Use "org.apache.flink.avro.generated.record" as the type name.

      Parameters:
      schema - the schema type, usually it should be the top level record type, e.g. not a nested type
      Returns:
      Avro's Schema matching this logical type.
    • convertToSchema

      public static org.apache.avro.Schema convertToSchema(org.apache.flink.table.types.logical.LogicalType schema, boolean legacyTimestampMapping)
      Converts Flink SQL LogicalType (can be nested) into an Avro schema.

      Use "org.apache.flink.avro.generated.record" as the type name.

      Parameters:
      schema - the schema type, usually it should be the top level record type, e.g. not a nested type
      legacyTimestampMapping - whether to use the legacy timestamp mapping
      Returns:
      Avro's Schema matching this logical type.
    • convertToSchema

      public static org.apache.avro.Schema convertToSchema(org.apache.flink.table.types.logical.LogicalType logicalType, String rowName)
      Converts Flink SQL LogicalType (can be nested) into an Avro schema.

      The "{rowName}_" is used as the nested row type name prefix in order to generate the right schema. Nested record type that only differs with type name is still compatible.

      Parameters:
      logicalType - logical type
      rowName - the record name
      Returns:
      Avro's Schema matching this logical type.
    • convertToSchema

      public static org.apache.avro.Schema convertToSchema(org.apache.flink.table.types.logical.LogicalType logicalType, String rowName, boolean legacyTimestampMapping)
      Converts Flink SQL LogicalType (can be nested) into an Avro schema.

      The "{rowName}_" is used as the nested row type name prefix in order to generate the right schema. Nested record type that only differs with type name is still compatible.

      Parameters:
      logicalType - logical type
      rowName - the record name
      legacyTimestampMapping - whether to use legal timestamp mapping
      Returns:
      Avro's Schema matching this logical type.
    • extractValueTypeToAvroMap

      public static org.apache.flink.table.types.logical.LogicalType extractValueTypeToAvroMap(org.apache.flink.table.types.logical.LogicalType type)