Class FlinkSchemaUtil

java.lang.Object
org.apache.iceberg.flink.FlinkSchemaUtil

public class FlinkSchemaUtil extends Object
Converter between Flink types and Iceberg type. The conversion is not a 1:1 mapping that not allows back-and-forth conversion. So some information might get lost during the back-and-forth conversion.

This inconsistent types:

  • map Iceberg UUID type to Flink BinaryType(16)
  • map Flink VarCharType(_) and CharType(_) to Iceberg String type
  • map Flink VarBinaryType(_) to Iceberg Binary type
  • map Flink TimeType(_) to Iceberg Time type (microseconds)
  • map Flink TimestampType(_) to Iceberg Timestamp without zone type (microseconds)
  • map Flink LocalZonedTimestampType(_) to Iceberg Timestamp with zone type (microseconds)
  • map Flink MultiSetType to Iceberg Map type(element, int)

  • Method Summary

    Modifier and Type
    Method
    Description
    static Schema
    convert(org.apache.flink.table.catalog.ResolvedSchema flinkSchema)
    Convert the flink table schema to apache iceberg schema with column comment.
    static Schema
    convert(org.apache.flink.table.legacy.api.TableSchema schema)
    Deprecated.
    will be removed in 2.0.0; use convert(ResolvedSchema) instead.
    static Type
    convert(org.apache.flink.table.types.logical.LogicalType flinkType)
    Convert a Flink type to a Type.
    static org.apache.flink.table.types.logical.RowType
    convert(Schema schema)
    Convert a Schema to a Flink type.
    static Schema
    convert(Schema baseSchema, org.apache.flink.table.catalog.ResolvedSchema flinkSchema)
    Convert a Flink ResolvedSchema to a Schema based on the given schema.
    static Schema
    convert(Schema baseSchema, org.apache.flink.table.legacy.api.TableSchema flinkSchema)
    Deprecated.
    since 1.10.0, will be removed in 2.0.0.
    static org.apache.flink.table.types.logical.LogicalType
    convert(Type type)
    Convert a Type to a Flink type.
    static org.apache.flink.table.catalog.ResolvedSchema
    toResolvedSchema(org.apache.flink.table.types.logical.RowType rowType)
    Convert a RowType to a ResolvedSchema.
    static org.apache.flink.table.catalog.ResolvedSchema
    Convert a Schema to a ResolvedSchema.
    static org.apache.flink.table.legacy.api.TableSchema
    toSchema(org.apache.flink.table.types.logical.RowType rowType)
    Deprecated.
    since 1.10.0, will be removed in 2.0.0.
    static org.apache.flink.table.legacy.api.TableSchema
    toSchema(Schema schema)
    Deprecated.
    since 1.10.0, will be removed in 2.0.0.

    Methods inherited from class java.lang.Object

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

    • convert

      @Deprecated public static Schema convert(org.apache.flink.table.legacy.api.TableSchema schema)
      Deprecated.
      will be removed in 2.0.0; use convert(ResolvedSchema) instead.
    • convert

      public static Schema convert(org.apache.flink.table.catalog.ResolvedSchema flinkSchema)
      Convert the flink table schema to apache iceberg schema with column comment.
    • convert

      @Deprecated public static Schema convert(Schema baseSchema, org.apache.flink.table.legacy.api.TableSchema flinkSchema)
      Deprecated.
      since 1.10.0, will be removed in 2.0.0. Use convert(Schema, ResolvedSchema) instead.
      Convert a Flink TableSchema to a Schema based on the given schema.

      This conversion does not assign new ids; it uses ids from the base schema.

      Data types, field order, and nullability will match the Flink type. This conversion may return a schema that is not compatible with base schema.

      Parameters:
      baseSchema - a Schema on which conversion is based
      flinkSchema - a Flink TableSchema
      Returns:
      the equivalent Schema
      Throws:
      IllegalArgumentException - if the type cannot be converted or there are missing ids
    • convert

      public static Schema convert(Schema baseSchema, org.apache.flink.table.catalog.ResolvedSchema flinkSchema)
      Convert a Flink ResolvedSchema to a Schema based on the given schema.

      This conversion does not assign new ids; it uses ids from the base schema.

      Data types, field order, and nullability will match the Flink type. This conversion may return a schema that is not compatible with base schema.

      Parameters:
      baseSchema - a Schema on which conversion is based
      flinkSchema - a Flink ResolvedSchema
      Returns:
      the equivalent Schema
      Throws:
      IllegalArgumentException - if the type cannot be converted or there are missing ids
    • convert

      public static org.apache.flink.table.types.logical.RowType convert(Schema schema)
      Convert a Schema to a Flink type.
      Parameters:
      schema - a Schema
      Returns:
      the equivalent Flink type
      Throws:
      IllegalArgumentException - if the type cannot be converted to Flink
    • convert

      public static org.apache.flink.table.types.logical.LogicalType convert(Type type)
      Convert a Type to a Flink type.
      Parameters:
      type - a Type
      Returns:
      the equivalent Flink type
      Throws:
      IllegalArgumentException - if the type cannot be converted to Flink
    • convert

      public static Type convert(org.apache.flink.table.types.logical.LogicalType flinkType)
      Convert a Flink type to a Type.
      Parameters:
      flinkType - a FlinkType
      Returns:
      the equivalent Iceberg type
    • toSchema

      @Deprecated public static org.apache.flink.table.legacy.api.TableSchema toSchema(org.apache.flink.table.types.logical.RowType rowType)
      Deprecated.
      since 1.10.0, will be removed in 2.0.0. Use toResolvedSchema(RowType) instead
      Convert a RowType to a TableSchema.
      Parameters:
      rowType - a RowType
      Returns:
      Flink TableSchema
    • toResolvedSchema

      public static org.apache.flink.table.catalog.ResolvedSchema toResolvedSchema(org.apache.flink.table.types.logical.RowType rowType)
      Convert a RowType to a ResolvedSchema.
      Parameters:
      rowType - a RowType
      Returns:
      Flink ResolvedSchema
    • toSchema

      @Deprecated public static org.apache.flink.table.legacy.api.TableSchema toSchema(Schema schema)
      Deprecated.
      since 1.10.0, will be removed in 2.0.0. Use toResolvedSchema(Schema) instead
      Convert a Schema to a TableSchema.
      Parameters:
      schema - iceberg schema to convert.
      Returns:
      Flink TableSchema.
    • toResolvedSchema

      public static org.apache.flink.table.catalog.ResolvedSchema toResolvedSchema(Schema schema)
      Convert a Schema to a ResolvedSchema.
      Parameters:
      schema - iceberg schema to convert.
      Returns:
      Flink ResolvedSchema.