Class TableSchema.Builder

java.lang.Object
org.apache.flink.table.legacy.api.TableSchema.Builder
Enclosing class:
TableSchema

@Internal public static class TableSchema.Builder extends Object
Builder for creating a TableSchema.
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • field

      public TableSchema.Builder field(String name, DataType dataType)
      Add a field with name and data type.

      The call order of this method determines the order of fields in the schema.

    • field

      public TableSchema.Builder field(String name, DataType dataType, String expression)
      Add a computed field which is generated by the given expression. This also defines the field name and the data type.

      The call order of this method determines the order of fields in the schema.

      The returned expression should be a SQL-style expression whose identifiers should be all quoted and expanded.

      It should be expanded because this expression may be persisted then deserialized from the catalog, an expanded identifier would avoid the ambiguity if there are same name UDF referenced from different paths. For example, if there is a UDF named "my_udf" from path "my_catalog.my_database", you could pass in an expression like "`my_catalog`.`my_database`.`my_udf`(`f0`) + 1";

      It should be quoted because user could use a reserved keyword as the identifier, and we have no idea if it is quoted when deserialize from the catalog, so we force to use quoted identifier here. But framework will not check whether it is qualified and quoted or not.

      Parameters:
      name - Field name
      dataType - Field data type
      expression - Computed column expression.
    • add

      public TableSchema.Builder add(TableColumn column)
      Adds a TableColumn to this builder.

      The call order of this method determines the order of fields in the schema.

    • fields

      public TableSchema.Builder fields(String[] names, DataType[] dataTypes)
      Add an array of fields with names and data types.

      The call order of this method determines the order of fields in the schema.

    • field

      @Deprecated public TableSchema.Builder field(String name, org.apache.flink.api.common.typeinfo.TypeInformation<?> typeInfo)
      Deprecated.
      This method will be removed in future versions as it uses the old type system. It is recommended to use field(String, DataType) instead which uses the new type system based on DataTypes. Please make sure to use either the old or the new type system consistently to avoid unintended behavior. See the website documentation for more information.
    • watermark

      public TableSchema.Builder watermark(String rowtimeAttribute, String watermarkExpressionString, DataType watermarkExprOutputType)
      Specifies the previously defined field as an event-time attribute and specifies the watermark strategy.
      Parameters:
      rowtimeAttribute - the field name as a rowtime attribute, can be a nested field using dot separator.
      watermarkExpressionString - the string representation of watermark generation expression, e.g. "ts - INTERVAL '5' SECOND". The string is a qualified SQL expression string (UDFs are expanded) but will not be validated by TableSchema.
      watermarkExprOutputType - the data type of the computation result of watermark generation expression. Whether the data type equals to the output type of expression will also not be validated by TableSchema.
    • watermark

      public TableSchema.Builder watermark(WatermarkSpec watermarkSpec)
      Adds the given WatermarkSpec to this builder.
    • primaryKey

      public TableSchema.Builder primaryKey(String... columns)
      Creates a primary key constraint for a set of given columns. The primary key is informational only. It will not be enforced. It can be used for optimizations. It is the owner's of the data responsibility to ensure uniqueness of the data.

      The primary key will be assigned a random name.

      Parameters:
      columns - array of columns that form a unique primary key
    • primaryKey

      public TableSchema.Builder primaryKey(String name, String[] columns)
      Creates a primary key constraint for a set of given columns. The primary key is informational only. It will not be enforced. It can be used for optimizations. It is the owner's of the data responsibility to ensure
      Parameters:
      columns - array of columns that form a unique primary key
      name - name for the primary key, can be used to reference the constraint
    • build

      public TableSchema build()
      Returns a TableSchema instance.