Search in sources :

Example 1 with BinaryRowDataKeySelector

use of org.apache.flink.table.runtime.keyselector.BinaryRowDataKeySelector in project flink by apache.

the class KeySelectorUtil method getRowDataSelector.

/**
 * Create a RowDataKeySelector to extract keys from DataStream which type is {@link
 * InternalTypeInfo} of {@link RowData}.
 *
 * @param keyFields key fields
 * @param rowType type of DataStream to extract keys
 * @return the RowDataKeySelector to extract keys from DataStream which type is {@link
 *     InternalTypeInfo} of {@link RowData}.
 */
public static RowDataKeySelector getRowDataSelector(int[] keyFields, InternalTypeInfo<RowData> rowType) {
    if (keyFields.length > 0) {
        LogicalType[] inputFieldTypes = rowType.toRowFieldTypes();
        LogicalType[] keyFieldTypes = new LogicalType[keyFields.length];
        for (int i = 0; i < keyFields.length; ++i) {
            keyFieldTypes[i] = inputFieldTypes[keyFields[i]];
        }
        // do not provide field names for the result key type,
        // because we may have duplicate key fields and the field names may conflict
        RowType returnType = RowType.of(keyFieldTypes);
        RowType inputType = rowType.toRowType();
        GeneratedProjection generatedProjection = ProjectionCodeGenerator.generateProjection(CodeGeneratorContext.apply(new TableConfig()), "KeyProjection", inputType, returnType, keyFields);
        InternalTypeInfo<RowData> keyRowType = InternalTypeInfo.of(returnType);
        return new BinaryRowDataKeySelector(keyRowType, generatedProjection);
    } else {
        return EmptyRowDataKeySelector.INSTANCE;
    }
}
Also used : RowData(org.apache.flink.table.data.RowData) GeneratedProjection(org.apache.flink.table.runtime.generated.GeneratedProjection) LogicalType(org.apache.flink.table.types.logical.LogicalType) RowType(org.apache.flink.table.types.logical.RowType) TableConfig(org.apache.flink.table.api.TableConfig) BinaryRowDataKeySelector(org.apache.flink.table.runtime.keyselector.BinaryRowDataKeySelector)

Aggregations

TableConfig (org.apache.flink.table.api.TableConfig)1 RowData (org.apache.flink.table.data.RowData)1 GeneratedProjection (org.apache.flink.table.runtime.generated.GeneratedProjection)1 BinaryRowDataKeySelector (org.apache.flink.table.runtime.keyselector.BinaryRowDataKeySelector)1 LogicalType (org.apache.flink.table.types.logical.LogicalType)1 RowType (org.apache.flink.table.types.logical.RowType)1