Interface TableSemantics


@PublicEvolving public interface TableSemantics
Provides call information about the table that has been passed to a table argument.

This class is only available for table arguments (i.e. arguments of a ProcessTableFunction that are annotated with @ArgumentHint(SET_SEMANTIC_TABLE) or @ArgumentHint(ROW_SEMANTIC_TABLE)).

  • Method Details

    • dataType

      DataType dataType()
      Data type of the passed table.

      The returned data type might be the one that has been explicitly defined for the argument or a DataTypes.ROW(org.apache.flink.table.api.DataTypes.Field...) data type for polymorphic arguments that accept any type of row.

      For example:

      
       // Function with explicit table argument type of row
       class MyPTF extends ProcessTableFunction<String> {
         public void eval(Context ctx, @ArgumentHint(value = ArgumentTrait.SET_SEMANTIC_TABLE, type = "ROW < s STRING >") Row t) {
           TableSemantics semantics = ctx.tableSemanticsFor("t");
           // Always returns "ROW < s STRING >"
           semantics.dataType();
           ...
         }
       }
      
       // Function with explicit table argument type of structured type "Customer"
       class MyPTF extends ProcessTableFunction<String> {
         public void eval(Context ctx, @ArgumentHint(value = ArgumentTrait.SET_SEMANTIC_TABLE) Customer c) {
           TableSemantics semantics = ctx.tableSemanticsFor("c");
           // Always returns structured type of "Customer"
           semantics.dataType();
           ...
         }
       }
      
       // Function with polymorphic table argument
       class MyPTF extends ProcessTableFunction<String> {
         public void eval(Context ctx, @ArgumentHint(value = ArgumentTrait.SET_SEMANTIC_TABLE) Row t) {
           TableSemantics semantics = ctx.tableSemanticsFor("t");
           // Always returns "ROW" but content depends on the table that is passed into the call
           semantics.dataType();
           ...
         }
       }
       
    • partitionByColumns

      int[] partitionByColumns()
      Returns information about how the passed table is partitioned. Applies only to table arguments with set semantics.
      Returns:
      An array of indexes (0-based) that specify the PARTITION BY columns.
    • orderByColumns

      int[] orderByColumns()
      Returns information about how the passed table is ordered. Applies only to table arguments with set semantics.
      Returns:
      An array of indexes (0-based) that specify the ORDER BY columns.
    • orderByDirections

      TableSemantics.SortDirection[] orderByDirections()
      Returns information about the sort direction for each ORDER BY column. Applies only to table arguments with set semantics.

      The returned array has the same length as orderByColumns() and each element corresponds to the sort direction of the column at the same index.

      Returns:
      An array of TableSemantics.SortDirection values corresponding to the ORDER BY columns.
    • timeColumn

      int timeColumn()
      Returns information about the time attribute of the passed table. The time attribute column powers the concept of rowtime and timers. Applies to both table arguments with row and set semantics.
      Returns:
      Position of the "ON_TIME" column. Returns -1 in case no time attribute has been passed. Returns an actual value when called during runtime. Returns empty during type inference phase as the time attribute is still unknown.
    • changelogMode

      Optional<ChangelogMode> changelogMode()
      Actual changelog mode for the passed table. By default, table arguments take only ChangelogMode.insertOnly(). They are able to take tables of other changelog modes, if specified to do so (e.g. via an ArgumentTrait). This method returns the final changelog mode determined by the planner.
      Returns:
      The definitive changelog mode expected for the passed table after physical optimization. Returns an actual value when called during runtime. Returns empty during type inference phase as the changelog mode is still unknown.