Search in sources :

Example 1 with Keys

use of org.apache.flink.api.common.operators.Keys in project flink by apache.

the class SortPartitionOperator method translateToDataFlowWithKeyExtractor.

private <K> org.apache.flink.api.common.operators.SingleInputOperator<?, T, ?> translateToDataFlowWithKeyExtractor(Operator<T> input, Keys.SelectorFunctionKeys<T, K> keys, Order order, String name) {
    TypeInformation<Tuple2<K, T>> typeInfoWithKey = KeyFunctions.createTypeWithKey(keys);
    Keys.ExpressionKeys<Tuple2<K, T>> newKey = new Keys.ExpressionKeys<>(0, typeInfoWithKey);
    Operator<Tuple2<K, T>> keyedInput = KeyFunctions.appendKeyExtractor(input, keys);
    int[] sortKeyPositions = newKey.computeLogicalKeyPositions();
    Ordering partitionOrdering = new Ordering();
    for (int keyPosition : sortKeyPositions) {
        partitionOrdering.appendOrdering(keyPosition, null, order);
    }
    // distinguish between partition types
    UnaryOperatorInformation<Tuple2<K, T>, Tuple2<K, T>> operatorInfo = new UnaryOperatorInformation<>(typeInfoWithKey, typeInfoWithKey);
    SortPartitionOperatorBase<Tuple2<K, T>> noop = new SortPartitionOperatorBase<>(operatorInfo, partitionOrdering, name);
    noop.setInput(keyedInput);
    if (this.getParallelism() < 0) {
        // use parallelism of input if not explicitly specified
        noop.setParallelism(input.getParallelism());
    } else {
        // use explicitly specified parallelism
        noop.setParallelism(this.getParallelism());
    }
    return KeyFunctions.appendKeyRemover(noop, keys);
}
Also used : SortPartitionOperatorBase(org.apache.flink.api.common.operators.base.SortPartitionOperatorBase) UnaryOperatorInformation(org.apache.flink.api.common.operators.UnaryOperatorInformation) Tuple2(org.apache.flink.api.java.tuple.Tuple2) Keys(org.apache.flink.api.common.operators.Keys) Ordering(org.apache.flink.api.common.operators.Ordering)

Aggregations

Keys (org.apache.flink.api.common.operators.Keys)1 Ordering (org.apache.flink.api.common.operators.Ordering)1 UnaryOperatorInformation (org.apache.flink.api.common.operators.UnaryOperatorInformation)1 SortPartitionOperatorBase (org.apache.flink.api.common.operators.base.SortPartitionOperatorBase)1 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)1