Class AttributeBasedJoinKeyExtractor

  • All Implemented Interfaces:
    Serializable, JoinKeyExtractor

    public class AttributeBasedJoinKeyExtractor
    extends Object
    implements JoinKeyExtractor, Serializable
    A JoinKeyExtractor that derives keys from AttributeBasedJoinKeyExtractor.AttributeRef mappings in joinAttributeMap. It describes how attributes from different inputs are equated via equi-join conditions. Input 0 is the base; each subsequent input joins to one of the preceding inputs.

    Example used throughout the comments: t1.id1 = t2.user_id2 and t3.user_id3 = t2.user_id2. All three attributes (t1.id1, t2.user_id2, t3.user_id3) represent the same conceptual key.

    The joinAttributeMap for this example would be structured as follows:

    • Key `1` (for t2): A list containing one element `ConditionAttributeRef(leftInputId=0, leftFieldIndex=id1_idx, rightInputId=1, rightFieldIndex=user_id2_idx)`.
    • Key `2` (for t3): A list containing one element `ConditionAttributeRef(leftInputId=1, leftFieldIndex=user_id2_idx, rightInputId=2, rightFieldIndex=user_id3_idx)`.
    See Also:
    Serialized Form
    • Constructor Detail

      • AttributeBasedJoinKeyExtractor

        public AttributeBasedJoinKeyExtractor​(Map<Integer,​List<AttributeBasedJoinKeyExtractor.ConditionAttributeRef>> joinAttributeMap,
                                              List<org.apache.flink.table.types.logical.RowType> inputTypes)
        Creates an AttributeBasedJoinKeyExtractor.
        Parameters:
        joinAttributeMap - Map defining equi-join conditions. Outer key: inputId (>= 1). The value is a list of AttributeBasedJoinKeyExtractor.ConditionAttributeRef where each element defines an equi-join condition between a previous input (`leftInputId`, `leftFieldIndex`) and the current input (`rightInputId`, `rightFieldIndex`).
        inputTypes - Type information for all input streams (indexed 0 to N-1).
    • Method Detail

      • getJoinKey

        public org.apache.flink.table.data.RowData getJoinKey​(org.apache.flink.table.data.RowData row,
                                                              int inputId)
        Description copied from interface: JoinKeyExtractor
        Extracts the key used for storing the input record in its corresponding state view.

        This key determines how records from a specific input stream are organized within their state.

        Specified by:
        getJoinKey in interface JoinKeyExtractor
        Parameters:
        row - The input row for which to extract the storage key.
        inputId - The ID (0-based index) of the input stream this row belongs to.
        Returns:
        A RowData representing the state storage key. Can be null if no key can be derived (e.g., missing configuration).
      • getLeftSideJoinKey

        public org.apache.flink.table.data.RowData getLeftSideJoinKey​(int depth,
                                                                      org.apache.flink.table.data.RowData joinedRowData)
        Description copied from interface: JoinKeyExtractor
        Extracts the key used for looking up matching records in the state of a specific input depth, based on the rows accumulated from previous inputs.

        When processing the join recursively at a certain `depth`, this key is used to query the state associated with that `depth` (i.e., the state for input `depth`) to find potential join partners.

        Specified by:
        getLeftSideJoinKey in interface JoinKeyExtractor
        Parameters:
        depth - The current processing depth (0-based index), representing the target input ID for state lookup.
        joinedRowData - JoinedRowData with rows accumulated so far in the current recursive join path.
        Returns:
        A RowData representing the state lookup key. Can be null if no key can be derived (e.g., missing configuration, or a required row in `joinedRowData` is null).
      • getJoinKeyType

        @Nullable
        public org.apache.flink.table.types.logical.RowType getJoinKeyType​(int inputId)
        Description copied from interface: JoinKeyExtractor
        Returns the type of the join key for a given input.
        Specified by:
        getJoinKeyType in interface JoinKeyExtractor
        Parameters:
        inputId - The ID of the input stream.
        Returns:
        The RowType of the join key.
      • getJoinKeyIndices

        public int[] getJoinKeyIndices​(int inputId)
        Description copied from interface: JoinKeyExtractor
        Gets the field indices in the source row that make up the join key for a given input.
        Specified by:
        getJoinKeyIndices in interface JoinKeyExtractor
        Parameters:
        inputId - The ID of the input stream.
        Returns:
        An array of integers representing the field indices in the source row that form the join key.
      • getCommonJoinKeyType

        public org.apache.flink.table.types.logical.RowType getCommonJoinKeyType()
        Description copied from interface: JoinKeyExtractor
        Gets the type information for the common join key.
        Specified by:
        getCommonJoinKeyType in interface JoinKeyExtractor
        Returns:
        The RowType for the common key join type.
      • getCommonJoinKey

        @Nullable
        public org.apache.flink.table.data.RowData getCommonJoinKey​(org.apache.flink.table.data.RowData row,
                                                                    int inputId)
        Description copied from interface: JoinKeyExtractor
        Extracts the common key from an input row. The common key consists of attributes that are part of all equi-join conditions in the multi-join sequence.
        Specified by:
        getCommonJoinKey in interface JoinKeyExtractor
        Parameters:
        row - The input row.
        inputId - The ID of the input stream this row belongs to.
        Returns:
        A RowData representing the common key, or a default key if no common attributes exist or cannot be determined for this input.
      • getCommonJoinKeyIndices

        public int[] getCommonJoinKeyIndices​(int inputId)
        Description copied from interface: JoinKeyExtractor
        Gets the field indices in the source row that make up the common join key for a given input.
        Specified by:
        getCommonJoinKeyIndices in interface JoinKeyExtractor
        Parameters:
        inputId - The ID of the input stream.
        Returns:
        An array of integers representing the field indices in the source row that form the common join key.
      • validateKeyStructures

        public void validateKeyStructures()
        Validates internal key structures for consistency:
        1. For every input id, the number of left-side extractors equals the number of right-side key-field indices.
        2. If a common join key is defined, then for every input id the number of common key extractors equals the number of fields in commonJoinKeyType.
        3. If a common join key is defined, each extractor's logical type matches the corresponding field type in commonJoinKeyType.

        Throws IllegalStateException if any inconsistency is found.