Class AttributeBasedJoinKeyExtractor
- java.lang.Object
-
- org.apache.flink.table.runtime.operators.join.stream.keyselector.AttributeBasedJoinKeyExtractor
-
- All Implemented Interfaces:
Serializable,JoinKeyExtractor
public class AttributeBasedJoinKeyExtractor extends Object implements JoinKeyExtractor, Serializable
AJoinKeyExtractorthat derives keys fromAttributeBasedJoinKeyExtractor.AttributeRefmappings injoinAttributeMap. 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
joinAttributeMapfor 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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAttributeBasedJoinKeyExtractor.AttributeRefReference to a specific field (fieldIndex) within a specific input stream (inputId).static classAttributeBasedJoinKeyExtractor.ConditionAttributeRefReference to a specific field (fieldIndex) within a specific input stream (inputId).
-
Constructor Summary
Constructors Constructor Description AttributeBasedJoinKeyExtractor(Map<Integer,List<AttributeBasedJoinKeyExtractor.ConditionAttributeRef>> joinAttributeMap, List<org.apache.flink.table.types.logical.RowType> inputTypes)Creates an AttributeBasedJoinKeyExtractor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.apache.flink.table.data.RowDatagetCommonJoinKey(org.apache.flink.table.data.RowData row, int inputId)Extracts the common key from an input row.int[]getCommonJoinKeyIndices(int inputId)Gets the field indices in the source row that make up the common join key for a given input.org.apache.flink.table.types.logical.RowTypegetCommonJoinKeyType()Gets the type information for the common join key.org.apache.flink.table.data.RowDatagetJoinKey(org.apache.flink.table.data.RowData row, int inputId)Extracts the key used for storing the input record in its corresponding state view.int[]getJoinKeyIndices(int inputId)Gets the field indices in the source row that make up the join key for a given input.org.apache.flink.table.types.logical.RowTypegetJoinKeyType(int inputId)Returns the type of the join key for a given input.org.apache.flink.table.data.RowDatagetLeftSideJoinKey(int depth, org.apache.flink.table.data.RowData joinedRowData)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.voidrequiresKeyDeepCopy()Enables copying of row data.voidvalidateKeyStructures()Validates internal key structures for consistency: For every input id, the number of left-side extractors equals the number of right-side key-field indices.
-
-
-
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 ofAttributeBasedJoinKeyExtractor.ConditionAttributeRefwhere 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:JoinKeyExtractorExtracts 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:
getJoinKeyin interfaceJoinKeyExtractor- 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
RowDatarepresenting 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:JoinKeyExtractorExtracts 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:
getLeftSideJoinKeyin interfaceJoinKeyExtractor- 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
RowDatarepresenting 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:JoinKeyExtractorReturns the type of the join key for a given input.- Specified by:
getJoinKeyTypein interfaceJoinKeyExtractor- Parameters:
inputId- The ID of the input stream.- Returns:
- The
RowTypeof the join key.
-
getJoinKeyIndices
public int[] getJoinKeyIndices(int inputId)
Description copied from interface:JoinKeyExtractorGets the field indices in the source row that make up the join key for a given input.- Specified by:
getJoinKeyIndicesin interfaceJoinKeyExtractor- 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:JoinKeyExtractorGets the type information for the common join key.- Specified by:
getCommonJoinKeyTypein interfaceJoinKeyExtractor- Returns:
- The
RowTypefor 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:JoinKeyExtractorExtracts 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:
getCommonJoinKeyin interfaceJoinKeyExtractor- Parameters:
row- The input row.inputId- The ID of the input stream this row belongs to.- Returns:
- A
RowDatarepresenting 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:JoinKeyExtractorGets the field indices in the source row that make up the common join key for a given input.- Specified by:
getCommonJoinKeyIndicesin interfaceJoinKeyExtractor- 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.
-
requiresKeyDeepCopy
public void requiresKeyDeepCopy()
Description copied from interface:JoinKeyExtractorEnables copying of row data.- Specified by:
requiresKeyDeepCopyin interfaceJoinKeyExtractor
-
validateKeyStructures
public void validateKeyStructures()
Validates internal key structures for consistency:- For every input id, the number of left-side extractors equals the number of right-side key-field indices.
- 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. - If a common join key is defined, each extractor's logical type matches the
corresponding field type in
commonJoinKeyType.
Throws
IllegalStateExceptionif any inconsistency is found.
-
-