Java Code Examples for org.apache.flink.api.common.operators.Keys#computeLogicalKeyPositions()
The following examples show how to use
org.apache.flink.api.common.operators.Keys#computeLogicalKeyPositions() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PartitionOperator.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
private static <T> Ordering computeOrdering(Keys<T> pKeys, Order[] orders) { Ordering ordering = new Ordering(); final int[] logicalKeyPositions = pKeys.computeLogicalKeyPositions(); if (orders == null) { for (int key : logicalKeyPositions) { ordering.appendOrdering(key, null, Order.ASCENDING); } } else { final TypeInformation<?>[] originalKeyFieldTypes = pKeys.getOriginalKeyFieldTypes(); int index = 0; for (int i = 0; i < originalKeyFieldTypes.length; i++) { final int typeTotalFields = originalKeyFieldTypes[i].getTotalFields(); for (int j = index; j < index + typeTotalFields; j++) { ordering.appendOrdering(logicalKeyPositions[j], null, orders[i]); } index += typeTotalFields; } } return ordering; }
Example 2
Source File: KeySelectorUtil.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
public static <X> KeySelector<X, Tuple> getSelectorForKeys(Keys<X> keys, TypeInformation<X> typeInfo, ExecutionConfig executionConfig) { if (!(typeInfo instanceof CompositeType)) { throw new InvalidTypesException( "This key operation requires a composite type such as Tuples, POJOs, or Case Classes."); } CompositeType<X> compositeType = (CompositeType<X>) typeInfo; int[] logicalKeyPositions = keys.computeLogicalKeyPositions(); int numKeyFields = logicalKeyPositions.length; TypeInformation<?>[] typeInfos = keys.getKeyFieldTypes(); // use ascending order here, the code paths for that are usually a slight bit faster boolean[] orders = new boolean[numKeyFields]; for (int i = 0; i < numKeyFields; i++) { orders[i] = true; } TypeComparator<X> comparator = compositeType.createComparator(logicalKeyPositions, orders, 0, executionConfig); return new ComparableKeySelector<>(comparator, numKeyFields, new TupleTypeInfo<>(typeInfos)); }
Example 3
Source File: KeySelectorUtil.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
public static <X, K> KeySelector<X, K> getSelectorForOneKey( Keys<X> keys, Partitioner<K> partitioner, TypeInformation<X> typeInfo, ExecutionConfig executionConfig) { if (!(typeInfo instanceof CompositeType)) { throw new InvalidTypesException( "This key operation requires a composite type such as Tuples, POJOs, case classes, etc"); } if (partitioner != null) { keys.validateCustomPartitioner(partitioner, null); } CompositeType<X> compositeType = (CompositeType<X>) typeInfo; int[] logicalKeyPositions = keys.computeLogicalKeyPositions(); if (logicalKeyPositions.length != 1) { throw new IllegalArgumentException("There must be exactly 1 key specified"); } TypeComparator<X> comparator = compositeType.createComparator( logicalKeyPositions, new boolean[] { true }, 0, executionConfig); return new OneKeySelector<>(comparator); }
Example 4
Source File: PartitionOperator.java From flink with Apache License 2.0 | 6 votes |
private static <T> Ordering computeOrdering(Keys<T> pKeys, Order[] orders) { Ordering ordering = new Ordering(); final int[] logicalKeyPositions = pKeys.computeLogicalKeyPositions(); if (orders == null) { for (int key : logicalKeyPositions) { ordering.appendOrdering(key, null, Order.ASCENDING); } } else { final TypeInformation<?>[] originalKeyFieldTypes = pKeys.getOriginalKeyFieldTypes(); int index = 0; for (int i = 0; i < originalKeyFieldTypes.length; i++) { final int typeTotalFields = originalKeyFieldTypes[i].getTotalFields(); for (int j = index; j < index + typeTotalFields; j++) { ordering.appendOrdering(logicalKeyPositions[j], null, orders[i]); } index += typeTotalFields; } } return ordering; }
Example 5
Source File: KeySelectorUtil.java From flink with Apache License 2.0 | 6 votes |
public static <X> KeySelector<X, Tuple> getSelectorForKeys(Keys<X> keys, TypeInformation<X> typeInfo, ExecutionConfig executionConfig) { if (!(typeInfo instanceof CompositeType)) { throw new InvalidTypesException( "This key operation requires a composite type such as Tuples, POJOs, or Case Classes."); } CompositeType<X> compositeType = (CompositeType<X>) typeInfo; int[] logicalKeyPositions = keys.computeLogicalKeyPositions(); int numKeyFields = logicalKeyPositions.length; TypeInformation<?>[] typeInfos = keys.getKeyFieldTypes(); // use ascending order here, the code paths for that are usually a slight bit faster boolean[] orders = new boolean[numKeyFields]; for (int i = 0; i < numKeyFields; i++) { orders[i] = true; } TypeComparator<X> comparator = compositeType.createComparator(logicalKeyPositions, orders, 0, executionConfig); return new ComparableKeySelector<>(comparator, numKeyFields, new TupleTypeInfo<>(typeInfos)); }
Example 6
Source File: KeySelectorUtil.java From flink with Apache License 2.0 | 6 votes |
public static <X, K> KeySelector<X, K> getSelectorForOneKey( Keys<X> keys, Partitioner<K> partitioner, TypeInformation<X> typeInfo, ExecutionConfig executionConfig) { if (!(typeInfo instanceof CompositeType)) { throw new InvalidTypesException( "This key operation requires a composite type such as Tuples, POJOs, case classes, etc"); } if (partitioner != null) { keys.validateCustomPartitioner(partitioner, null); } CompositeType<X> compositeType = (CompositeType<X>) typeInfo; int[] logicalKeyPositions = keys.computeLogicalKeyPositions(); if (logicalKeyPositions.length != 1) { throw new IllegalArgumentException("There must be exactly 1 key specified"); } TypeComparator<X> comparator = compositeType.createComparator( logicalKeyPositions, new boolean[] { true }, 0, executionConfig); return new OneKeySelector<>(comparator); }
Example 7
Source File: PartitionOperator.java From flink with Apache License 2.0 | 6 votes |
private static <T> Ordering computeOrdering(Keys<T> pKeys, Order[] orders) { Ordering ordering = new Ordering(); final int[] logicalKeyPositions = pKeys.computeLogicalKeyPositions(); if (orders == null) { for (int key : logicalKeyPositions) { ordering.appendOrdering(key, null, Order.ASCENDING); } } else { final TypeInformation<?>[] originalKeyFieldTypes = pKeys.getOriginalKeyFieldTypes(); int index = 0; for (int i = 0; i < originalKeyFieldTypes.length; i++) { final int typeTotalFields = originalKeyFieldTypes[i].getTotalFields(); for (int j = index; j < index + typeTotalFields; j++) { ordering.appendOrdering(logicalKeyPositions[j], null, orders[i]); } index += typeTotalFields; } } return ordering; }
Example 8
Source File: KeySelectorUtil.java From flink with Apache License 2.0 | 6 votes |
public static <X> KeySelector<X, Tuple> getSelectorForKeys(Keys<X> keys, TypeInformation<X> typeInfo, ExecutionConfig executionConfig) { if (!(typeInfo instanceof CompositeType)) { throw new InvalidTypesException( "This key operation requires a composite type such as Tuples, POJOs, or Case Classes."); } CompositeType<X> compositeType = (CompositeType<X>) typeInfo; int[] logicalKeyPositions = keys.computeLogicalKeyPositions(); int numKeyFields = logicalKeyPositions.length; TypeInformation<?>[] typeInfos = keys.getKeyFieldTypes(); // use ascending order here, the code paths for that are usually a slight bit faster boolean[] orders = new boolean[numKeyFields]; for (int i = 0; i < numKeyFields; i++) { orders[i] = true; } TypeComparator<X> comparator = compositeType.createComparator(logicalKeyPositions, orders, 0, executionConfig); return new ComparableKeySelector<>(comparator, numKeyFields, new TupleTypeInfo<>(typeInfos)); }
Example 9
Source File: KeySelectorUtil.java From flink with Apache License 2.0 | 6 votes |
public static <X, K> KeySelector<X, K> getSelectorForOneKey( Keys<X> keys, Partitioner<K> partitioner, TypeInformation<X> typeInfo, ExecutionConfig executionConfig) { if (!(typeInfo instanceof CompositeType)) { throw new InvalidTypesException( "This key operation requires a composite type such as Tuples, POJOs, case classes, etc"); } if (partitioner != null) { keys.validateCustomPartitioner(partitioner, null); } CompositeType<X> compositeType = (CompositeType<X>) typeInfo; int[] logicalKeyPositions = keys.computeLogicalKeyPositions(); if (logicalKeyPositions.length != 1) { throw new IllegalArgumentException("There must be exactly 1 key specified"); } TypeComparator<X> comparator = compositeType.createComparator( logicalKeyPositions, new boolean[] { true }, 0, executionConfig); return new OneKeySelector<>(comparator); }