Java Code Examples for org.apache.flink.api.common.typeutils.CompositeType#createComparator()

The following examples show how to use org.apache.flink.api.common.typeutils.CompositeType#createComparator() . 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 Project: Flink-CEPplus   File: KeySelectorUtil.java    License: Apache License 2.0 6 votes vote down vote up
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 2
Source Project: Flink-CEPplus   File: KeySelectorUtil.java    License: Apache License 2.0 6 votes vote down vote up
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 3
Source Project: flink   File: KeySelectorUtil.java    License: Apache License 2.0 6 votes vote down vote up
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 4
Source Project: flink   File: KeySelectorUtil.java    License: Apache License 2.0 6 votes vote down vote up
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 5
Source Project: flink   File: KeySelectorUtil.java    License: Apache License 2.0 6 votes vote down vote up
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 Project: flink   File: KeySelectorUtil.java    License: Apache License 2.0 6 votes vote down vote up
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
@Override
protected TypeComparator<PojoContainingTuple> createComparator(boolean ascending) {
	Assert.assertTrue(type instanceof CompositeType);
	CompositeType<PojoContainingTuple> cType = (CompositeType<PojoContainingTuple>) type;
	ExpressionKeys<PojoContainingTuple> keys = new ExpressionKeys<PojoContainingTuple>(new String[] {"theTuple.*"}, cType);
	boolean[] orders = new boolean[keys.getNumberOfKeyFields()];
	Arrays.fill(orders, ascending);
	return cType.createComparator(keys.computeLogicalKeyPositions(), orders, 0, new ExecutionConfig());
}
 
Example 8
@Override
protected TypeComparator<PojoContainingTuple> createComparator(boolean ascending) {
	Assert.assertTrue(type instanceof CompositeType);
	CompositeType<PojoContainingTuple> cType = (CompositeType<PojoContainingTuple>) type;
	ExpressionKeys<PojoContainingTuple> keys = new ExpressionKeys<PojoContainingTuple>(new String[] {"theTuple.*"}, cType);
	boolean[] orders = new boolean[keys.getNumberOfKeyFields()];
	Arrays.fill(orders, ascending);
	return cType.createComparator(keys.computeLogicalKeyPositions(), orders, 0, new ExecutionConfig());
}
 
Example 9
@Override
protected TypeComparator<PojoContainingTuple> createComparator(boolean ascending) {
	Assert.assertTrue(type instanceof CompositeType);
	CompositeType<PojoContainingTuple> cType = (CompositeType<PojoContainingTuple>) type;
	ExpressionKeys<PojoContainingTuple> keys = new ExpressionKeys<PojoContainingTuple>(new String[] {"theTuple.*"}, cType);
	boolean[] orders = new boolean[keys.getNumberOfKeyFields()];
	Arrays.fill(orders, ascending);
	return cType.createComparator(keys.computeLogicalKeyPositions(), orders, 0, new ExecutionConfig());
}
 
Example 10
Source Project: flink   File: PojoComparatorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected TypeComparator<PojoContainingTuple> createComparator(boolean ascending) {
	Assert.assertTrue(type instanceof CompositeType);
	CompositeType<PojoContainingTuple> cType = (CompositeType<PojoContainingTuple>) type;
	ExpressionKeys<PojoContainingTuple> keys = new ExpressionKeys<PojoContainingTuple>(new String[] {"theTuple.*"}, cType);
	boolean[] orders = new boolean[keys.getNumberOfKeyFields()];
	Arrays.fill(orders, ascending);
	return cType.createComparator(keys.computeLogicalKeyPositions(), orders, 0, new ExecutionConfig());
}
 
Example 11
@Override
protected TypeComparator<PojoContainingTuple> createComparator(boolean ascending) {
	Assert.assertTrue(type instanceof CompositeType);
	CompositeType<PojoContainingTuple> cType = (CompositeType<PojoContainingTuple>) type;
	ExpressionKeys<PojoContainingTuple> keys = new ExpressionKeys<PojoContainingTuple>(new String[] {"theTuple.*"}, cType);
	boolean[] orders = new boolean[keys.getNumberOfKeyFields()];
	Arrays.fill(orders, ascending);
	return cType.createComparator(keys.computeLogicalKeyPositions(), orders, 0, new ExecutionConfig());
}
 
Example 12
Source Project: flink   File: PojoComparatorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected TypeComparator<PojoContainingTuple> createComparator(boolean ascending) {
	Assert.assertTrue(type instanceof CompositeType);
	CompositeType<PojoContainingTuple> cType = (CompositeType<PojoContainingTuple>) type;
	ExpressionKeys<PojoContainingTuple> keys = new ExpressionKeys<PojoContainingTuple>(new String[] {"theTuple.*"}, cType);
	boolean[] orders = new boolean[keys.getNumberOfKeyFields()];
	Arrays.fill(orders, ascending);
	return cType.createComparator(keys.computeLogicalKeyPositions(), orders, 0, new ExecutionConfig());
}