org.apache.flink.api.common.functions.GroupCombineFunction Java Examples

The following examples show how to use org.apache.flink.api.common.functions.GroupCombineFunction. 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: GroupCombineOperator.java    From flink with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private static <IN, OUT, K1, K2> PlanUnwrappingSortedGroupCombineOperator<IN, OUT, K1, K2> translateSelectorFunctionSortedReducer(
		SelectorFunctionKeys<IN, ?> rawGroupingKey,
		SelectorFunctionKeys<IN, ?> rawSortingKeys,
		Ordering groupOrder,
		GroupCombineFunction<IN, OUT> function,
		TypeInformation<OUT> outputType,
		String name,
		Operator<IN> input) {
	final SelectorFunctionKeys<IN, K1> groupingKey = (SelectorFunctionKeys<IN, K1>) rawGroupingKey;
	final SelectorFunctionKeys<IN, K2> sortingKey = (SelectorFunctionKeys<IN, K2>) rawSortingKeys;
	TypeInformation<Tuple3<K1, K2, IN>> typeInfoWithKey = KeyFunctions.createTypeWithKey(groupingKey, sortingKey);

	Operator<Tuple3<K1, K2, IN>> inputWithKey = KeyFunctions.appendKeyExtractor(input, groupingKey, sortingKey);

	PlanUnwrappingSortedGroupCombineOperator<IN, OUT, K1, K2> reducer =
		new PlanUnwrappingSortedGroupCombineOperator<>(function, groupingKey, sortingKey, name, outputType, typeInfoWithKey);
	reducer.setInput(inputWithKey);
	reducer.setGroupOrder(groupOrder);

	return reducer;
}
 
Example #2
Source File: GroupCombineOperator.java    From flink with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private static <IN, OUT, K1, K2> PlanUnwrappingSortedGroupCombineOperator<IN, OUT, K1, K2> translateSelectorFunctionSortedReducer(
		SelectorFunctionKeys<IN, ?> rawGroupingKey,
		SelectorFunctionKeys<IN, ?> rawSortingKeys,
		Ordering groupOrder,
		GroupCombineFunction<IN, OUT> function,
		TypeInformation<OUT> outputType,
		String name,
		Operator<IN> input) {
	final SelectorFunctionKeys<IN, K1> groupingKey = (SelectorFunctionKeys<IN, K1>) rawGroupingKey;
	final SelectorFunctionKeys<IN, K2> sortingKey = (SelectorFunctionKeys<IN, K2>) rawSortingKeys;
	TypeInformation<Tuple3<K1, K2, IN>> typeInfoWithKey = KeyFunctions.createTypeWithKey(groupingKey, sortingKey);

	Operator<Tuple3<K1, K2, IN>> inputWithKey = KeyFunctions.appendKeyExtractor(input, groupingKey, sortingKey);

	PlanUnwrappingSortedGroupCombineOperator<IN, OUT, K1, K2> reducer =
		new PlanUnwrappingSortedGroupCombineOperator<>(function, groupingKey, sortingKey, name, outputType, typeInfoWithKey);
	reducer.setInput(inputWithKey);
	reducer.setGroupOrder(groupOrder);

	return reducer;
}
 
Example #3
Source File: GroupCombineOperator.java    From flink with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private static <IN, OUT, K> PlanUnwrappingGroupCombineOperator<IN, OUT, K> translateSelectorFunctionReducer(
		SelectorFunctionKeys<IN, ?> rawKeys,
		GroupCombineFunction<IN, OUT> function,
		TypeInformation<OUT> outputType,
		String name,
		Operator<IN> input) {
	final SelectorFunctionKeys<IN, K> keys = (SelectorFunctionKeys<IN, K>) rawKeys;

	TypeInformation<Tuple2<K, IN>> typeInfoWithKey = KeyFunctions.createTypeWithKey(keys);
	Operator<Tuple2<K, IN>> keyedInput = KeyFunctions.appendKeyExtractor(input, keys);

	PlanUnwrappingGroupCombineOperator<IN, OUT, K> reducer =
		new PlanUnwrappingGroupCombineOperator<>(function, keys, name, outputType, typeInfoWithKey);
	reducer.setInput(keyedInput);

	return reducer;
}
 
Example #4
Source File: GroupCombineOperator.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private static <IN, OUT, K> PlanUnwrappingGroupCombineOperator<IN, OUT, K> translateSelectorFunctionReducer(
		SelectorFunctionKeys<IN, ?> rawKeys,
		GroupCombineFunction<IN, OUT> function,
		TypeInformation<OUT> outputType,
		String name,
		Operator<IN> input) {
	final SelectorFunctionKeys<IN, K> keys = (SelectorFunctionKeys<IN, K>) rawKeys;

	TypeInformation<Tuple2<K, IN>> typeInfoWithKey = KeyFunctions.createTypeWithKey(keys);
	Operator<Tuple2<K, IN>> keyedInput = KeyFunctions.appendKeyExtractor(input, keys);

	PlanUnwrappingGroupCombineOperator<IN, OUT, K> reducer =
		new PlanUnwrappingGroupCombineOperator<>(function, keys, name, outputType, typeInfoWithKey);
	reducer.setInput(keyedInput);

	return reducer;
}
 
Example #5
Source File: GroupCombineOperator.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private static <IN, OUT, K1, K2> PlanUnwrappingSortedGroupCombineOperator<IN, OUT, K1, K2> translateSelectorFunctionSortedReducer(
		SelectorFunctionKeys<IN, ?> rawGroupingKey,
		SelectorFunctionKeys<IN, ?> rawSortingKeys,
		Ordering groupOrder,
		GroupCombineFunction<IN, OUT> function,
		TypeInformation<OUT> outputType,
		String name,
		Operator<IN> input) {
	final SelectorFunctionKeys<IN, K1> groupingKey = (SelectorFunctionKeys<IN, K1>) rawGroupingKey;
	final SelectorFunctionKeys<IN, K2> sortingKey = (SelectorFunctionKeys<IN, K2>) rawSortingKeys;
	TypeInformation<Tuple3<K1, K2, IN>> typeInfoWithKey = KeyFunctions.createTypeWithKey(groupingKey, sortingKey);

	Operator<Tuple3<K1, K2, IN>> inputWithKey = KeyFunctions.appendKeyExtractor(input, groupingKey, sortingKey);

	PlanUnwrappingSortedGroupCombineOperator<IN, OUT, K1, K2> reducer =
		new PlanUnwrappingSortedGroupCombineOperator<>(function, groupingKey, sortingKey, name, outputType, typeInfoWithKey);
	reducer.setInput(inputWithKey);
	reducer.setGroupOrder(groupOrder);

	return reducer;
}
 
Example #6
Source File: PlanUnwrappingReduceGroupOperator.java    From flink with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void combine(Iterable<Tuple2<K, IN>> values, Collector<Tuple2<K, IN>> out) throws Exception {

	iter.set(values.iterator());
	coll.set(out);
	((GroupCombineFunction<IN, IN>) this.wrappedFunction).combine(iter, coll);
}
 
Example #7
Source File: SynchronousChainedCombineDriver.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void setup(AbstractInvokable parent) {
	this.parent = parent;

	@SuppressWarnings("unchecked")
	final GroupCombineFunction<IN, OUT> combiner =
		BatchTask.instantiateUserCode(this.config, userCodeClassLoader, GroupCombineFunction.class);
	this.combiner = combiner;
	FunctionUtils.setFunctionRuntimeContext(combiner, getUdfRuntimeContext());
}
 
Example #8
Source File: PlanUnwrappingReduceGroupOperator.java    From flink with Apache License 2.0 5 votes vote down vote up
private TupleUnwrappingGroupCombinableGroupReducer(GroupReduceFunction<IN, OUT> wrapped) {
	super(wrapped);

	if (!GroupCombineFunction.class.isAssignableFrom(wrappedFunction.getClass())) {
		throw new IllegalArgumentException("Wrapped reduce function does not implement the GroupCombineFunction interface.");
	}

	this.iter = new TupleUnwrappingIterator<>();
	this.coll = new TupleWrappingCollector<>(this.iter);
}
 
Example #9
Source File: GroupCombineOperator.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor for a grouped reduce.
 *
 * @param input The grouped input to be processed group-wise by the groupReduce function.
 * @param function The user-defined GroupReduce function.
 */
public GroupCombineOperator(Grouping<IN> input, TypeInformation<OUT> resultType, GroupCombineFunction<IN, OUT> function, String defaultName) {
	super(input != null ? input.getInputDataSet() : null, resultType);

	this.function = function;
	this.grouper = input;
	this.defaultName = defaultName;
}
 
Example #10
Source File: GroupCombineITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
// check if parallelism of 1 results in the same data like a shuffle
public void testCheckPartitionShuffleDOP1() throws Exception {

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	env.setParallelism(1);

	// data
	DataSet<Tuple3<Integer, Long, String>> ds = CollectionDataSets.get3TupleDataSet(env);

	// partition and group data
	UnsortedGrouping<Tuple3<Integer, Long, String>> partitionedDS = ds.partitionByHash(0).groupBy(1);

	List<Tuple2<Long, Integer>> result = partitionedDS
			.combineGroup(
			new GroupCombineFunction<Tuple3<Integer, Long, String>, Tuple2<Long, Integer>>() {
				@Override
				public void combine(Iterable<Tuple3<Integer, Long, String>> values, Collector<Tuple2<Long, Integer>> out) throws Exception {
					int count = 0;
					long key = 0;
					for (Tuple3<Integer, Long, String> value : values) {
						key = value.f1;
						count++;
					}
					out.collect(new Tuple2<>(key, count));
				}
			}).collect();

	String expected = "6,6\n" +
			"5,5\n" +
			"4,4\n" +
			"3,3\n" +
			"2,2\n" +
			"1,1\n";

	compareResultAsTuples(result, expected);
}
 
Example #11
Source File: GroupCombineITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
// check if no shuffle is being executed
public void testCheckPartitionShuffleGroupBy() throws Exception {

	org.junit.Assume.assumeTrue(mode != TestExecutionMode.COLLECTION);

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	// data
	DataSet<Tuple3<Integer, Long, String>> ds = CollectionDataSets.get3TupleDataSet(env);

	// partition and group data
	UnsortedGrouping<Tuple3<Integer, Long, String>> partitionedDS = ds.partitionByHash(0).groupBy(1);

	List<Tuple2<Long, Integer>> result = partitionedDS
			.combineGroup(
					new GroupCombineFunction<Tuple3<Integer, Long, String>, Tuple2<Long, Integer>>() {
		@Override
		public void combine(Iterable<Tuple3<Integer, Long, String>> values, Collector<Tuple2<Long, Integer>> out) throws Exception {
			int count = 0;
			long key = 0;
			for (Tuple3<Integer, Long, String> value : values) {
				key = value.f1;
				count++;
			}
			out.collect(new Tuple2<>(key, count));
		}
	}).collect();

	String[] localExpected = new String[] { "(6,6)", "(5,5)" + "(4,4)", "(3,3)", "(2,2)", "(1,1)" };

	String[] resultAsStringArray = new String[result.size()];
	for (int i = 0; i < resultAsStringArray.length; ++i) {
		resultAsStringArray[i] = result.get(i).toString();
	}
	Arrays.sort(resultAsStringArray);

	Assert.assertEquals("The two arrays were identical.", false, Arrays.equals(localExpected, resultAsStringArray));
}
 
Example #12
Source File: SynchronousChainedCombineDriver.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void setup(AbstractInvokable parent) {
	this.parent = parent;

	@SuppressWarnings("unchecked")
	final GroupCombineFunction<IN, OUT> combiner =
		BatchTask.instantiateUserCode(this.config, userCodeClassLoader, GroupCombineFunction.class);
	this.combiner = combiner;
	FunctionUtils.setFunctionRuntimeContext(combiner, getUdfRuntimeContext());
}
 
Example #13
Source File: PlanUnwrappingReduceGroupOperator.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private TupleUnwrappingGroupCombinableGroupReducer(GroupReduceFunction<IN, OUT> wrapped) {
	super(wrapped);

	if (!GroupCombineFunction.class.isAssignableFrom(wrappedFunction.getClass())) {
		throw new IllegalArgumentException("Wrapped reduce function does not implement the GroupCombineFunction interface.");
	}

	this.iter = new TupleUnwrappingIterator<>();
	this.coll = new TupleWrappingCollector<>(this.iter);
}
 
Example #14
Source File: GroupCombineOperator.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor for a grouped reduce.
 *
 * @param input The grouped input to be processed group-wise by the groupReduce function.
 * @param function The user-defined GroupReduce function.
 */
public GroupCombineOperator(Grouping<IN> input, TypeInformation<OUT> resultType, GroupCombineFunction<IN, OUT> function, String defaultName) {
	super(input != null ? input.getInputDataSet() : null, resultType);

	this.function = function;
	this.grouper = input;
	this.defaultName = defaultName;
}
 
Example #15
Source File: PlanUnwrappingSortedGroupCombineOperator.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public PlanUnwrappingSortedGroupCombineOperator(GroupCombineFunction<IN, OUT> udf, Keys.SelectorFunctionKeys<IN, K1> groupingKey, Keys.SelectorFunctionKeys<IN, K2> sortingKey, String name,
												TypeInformation<OUT> outType, TypeInformation<Tuple3<K1, K2, IN>> typeInfoWithKey) {
	super(new TupleUnwrappingGroupReducer<IN, OUT, K1, K2>(udf),
			new UnaryOperatorInformation<Tuple3<K1, K2, IN>, OUT>(typeInfoWithKey, outType),
			groupingKey.computeLogicalKeyPositions(),
			name);

}
 
Example #16
Source File: GroupReduceOperatorBase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Marks the group reduce operation as combinable. Combinable operations may pre-reduce the
 * data before the actual group reduce operations. Combinable user-defined functions
 * must implement the interface {@link GroupCombineFunction}.
 * 
 * @param combinable Flag to mark the group reduce operation as combinable.
 */
public void setCombinable(boolean combinable) {
	// sanity check
	if (combinable && !GroupCombineFunction.class.isAssignableFrom(this.userFunction.getUserCodeClass())) {
		throw new IllegalArgumentException("Cannot set a UDF as combinable if it does not implement the interface " +
				GroupCombineFunction.class.getName());
	} else {
		this.combinable = combinable;
	}
}
 
Example #17
Source File: TypeExtractor.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@PublicEvolving
public static <IN, OUT> TypeInformation<OUT> getGroupCombineReturnTypes(GroupCombineFunction<IN, OUT> combineInterface, TypeInformation<IN> inType,
																		String functionName, boolean allowMissing)
{
	return getUnaryOperatorReturnType(
		(Function) combineInterface,
		GroupCombineFunction.class,
		0,
		1,
		new int[]{1, 0},
		inType,
		functionName,
		allowMissing);
}
 
Example #18
Source File: PlanUnwrappingSortedReduceGroupOperator.java    From flink with Apache License 2.0 5 votes vote down vote up
private TupleUnwrappingGroupCombinableGroupReducer(GroupReduceFunction<IN, OUT> wrapped) {
	super(wrapped);

	if (!GroupCombineFunction.class.isAssignableFrom(wrappedFunction.getClass())) {
		throw new IllegalArgumentException("Wrapped reduce function does not implement the GroupCombineFunction interface.");
	}

	this.iter = new Tuple3UnwrappingIterator<>();
	this.coll = new Tuple3WrappingCollector<>(this.iter);
}
 
Example #19
Source File: PlanUnwrappingSortedReduceGroupOperator.java    From flink with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void combine(Iterable<Tuple3<K1, K2, IN>> values, Collector<Tuple3<K1, K2, IN>> out) throws Exception {
	iter.set(values.iterator());
	coll.set(out);
	((GroupCombineFunction<IN, IN>) this.wrappedFunction).combine(iter, coll);
}
 
Example #20
Source File: GroupCombineITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
// check if parallelism of 1 results in the same data like a shuffle
public void testCheckPartitionShuffleDOP1() throws Exception {

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	env.setParallelism(1);

	// data
	DataSet<Tuple3<Integer, Long, String>> ds = CollectionDataSets.get3TupleDataSet(env);

	// partition and group data
	UnsortedGrouping<Tuple3<Integer, Long, String>> partitionedDS = ds.partitionByHash(0).groupBy(1);

	List<Tuple2<Long, Integer>> result = partitionedDS
			.combineGroup(
			new GroupCombineFunction<Tuple3<Integer, Long, String>, Tuple2<Long, Integer>>() {
				@Override
				public void combine(Iterable<Tuple3<Integer, Long, String>> values, Collector<Tuple2<Long, Integer>> out) throws Exception {
					int count = 0;
					long key = 0;
					for (Tuple3<Integer, Long, String> value : values) {
						key = value.f1;
						count++;
					}
					out.collect(new Tuple2<>(key, count));
				}
			}).collect();

	String expected = "6,6\n" +
			"5,5\n" +
			"4,4\n" +
			"3,3\n" +
			"2,2\n" +
			"1,1\n";

	compareResultAsTuples(result, expected);
}
 
Example #21
Source File: GroupReduceOperatorBase.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Marks the group reduce operation as combinable. Combinable operations may pre-reduce the
 * data before the actual group reduce operations. Combinable user-defined functions
 * must implement the interface {@link GroupCombineFunction}.
 * 
 * @param combinable Flag to mark the group reduce operation as combinable.
 */
public void setCombinable(boolean combinable) {
	// sanity check
	if (combinable && !GroupCombineFunction.class.isAssignableFrom(this.userFunction.getUserCodeClass())) {
		throw new IllegalArgumentException("Cannot set a UDF as combinable if it does not implement the interface " +
				GroupCombineFunction.class.getName());
	} else {
		this.combinable = combinable;
	}
}
 
Example #22
Source File: AllGroupReduceDriver.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void prepare() throws Exception {
	final TaskConfig config = this.taskContext.getTaskConfig();
	this.strategy = config.getDriverStrategy();

	switch (this.strategy) {
		case ALL_GROUP_REDUCE_COMBINE:
			if (!(this.taskContext.getStub() instanceof GroupCombineFunction)) {
				throw new Exception("Using combiner on a UDF that does not implement the combiner interface " + GroupCombineFunction.class.getName());
			}
		case ALL_GROUP_REDUCE:
		case ALL_GROUP_COMBINE:
			break;
		default:
			throw new Exception("Unrecognized driver strategy for AllGroupReduce driver: " + this.strategy.name());
	}

	this.serializer = this.taskContext.<IT>getInputSerializer(0).getSerializer();
	this.input = this.taskContext.getInput(0);

	ExecutionConfig executionConfig = taskContext.getExecutionConfig();
	this.objectReuseEnabled = executionConfig.isObjectReuseEnabled();

	if (LOG.isDebugEnabled()) {
		LOG.debug("AllGroupReduceDriver object reuse: " + (this.objectReuseEnabled ? "ENABLED" : "DISABLED") + ".");
	}
}
 
Example #23
Source File: SynchronousChainedCombineDriver.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void setup(AbstractInvokable parent) {
	this.parent = parent;

	@SuppressWarnings("unchecked")
	final GroupCombineFunction<IN, OUT> combiner =
		BatchTask.instantiateUserCode(this.config, userCodeClassLoader, GroupCombineFunction.class);
	this.combiner = combiner;
	FunctionUtils.setFunctionRuntimeContext(combiner, getUdfRuntimeContext());
}
 
Example #24
Source File: GroupCombineITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
// check if no shuffle is being executed
public void testCheckPartitionShuffleGroupBy() throws Exception {

	org.junit.Assume.assumeTrue(mode != TestExecutionMode.COLLECTION);

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	// data
	DataSet<Tuple3<Integer, Long, String>> ds = CollectionDataSets.get3TupleDataSet(env);

	// partition and group data
	UnsortedGrouping<Tuple3<Integer, Long, String>> partitionedDS = ds.partitionByHash(0).groupBy(1);

	List<Tuple2<Long, Integer>> result = partitionedDS
			.combineGroup(
					new GroupCombineFunction<Tuple3<Integer, Long, String>, Tuple2<Long, Integer>>() {
		@Override
		public void combine(Iterable<Tuple3<Integer, Long, String>> values, Collector<Tuple2<Long, Integer>> out) throws Exception {
			int count = 0;
			long key = 0;
			for (Tuple3<Integer, Long, String> value : values) {
				key = value.f1;
				count++;
			}
			out.collect(new Tuple2<>(key, count));
		}
	}).collect();

	String[] localExpected = new String[] { "(6,6)", "(5,5)" + "(4,4)", "(3,3)", "(2,2)", "(1,1)" };

	String[] resultAsStringArray = new String[result.size()];
	for (int i = 0; i < resultAsStringArray.length; ++i) {
		resultAsStringArray[i] = result.get(i).toString();
	}
	Arrays.sort(resultAsStringArray);

	Assert.assertEquals("The two arrays were identical.", false, Arrays.equals(localExpected, resultAsStringArray));
}
 
Example #25
Source File: GroupCombineITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
// check if parallelism of 1 results in the same data like a shuffle
public void testCheckPartitionShuffleDOP1() throws Exception {

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	env.setParallelism(1);

	// data
	DataSet<Tuple3<Integer, Long, String>> ds = CollectionDataSets.get3TupleDataSet(env);

	// partition and group data
	UnsortedGrouping<Tuple3<Integer, Long, String>> partitionedDS = ds.partitionByHash(0).groupBy(1);

	List<Tuple2<Long, Integer>> result = partitionedDS
			.combineGroup(
			new GroupCombineFunction<Tuple3<Integer, Long, String>, Tuple2<Long, Integer>>() {
				@Override
				public void combine(Iterable<Tuple3<Integer, Long, String>> values, Collector<Tuple2<Long, Integer>> out) throws Exception {
					int count = 0;
					long key = 0;
					for (Tuple3<Integer, Long, String> value : values) {
						key = value.f1;
						count++;
					}
					out.collect(new Tuple2<>(key, count));
				}
			}).collect();

	String expected = "6,6\n" +
			"5,5\n" +
			"4,4\n" +
			"3,3\n" +
			"2,2\n" +
			"1,1\n";

	compareResultAsTuples(result, expected);
}
 
Example #26
Source File: GroupCombineOperator.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor for a grouped reduce.
 *
 * @param input The grouped input to be processed group-wise by the groupReduce function.
 * @param function The user-defined GroupReduce function.
 */
public GroupCombineOperator(Grouping<IN> input, TypeInformation<OUT> resultType, GroupCombineFunction<IN, OUT> function, String defaultName) {
	super(input != null ? input.getInputDataSet() : null, resultType);

	this.function = function;
	this.grouper = input;
	this.defaultName = defaultName;
}
 
Example #27
Source File: GroupReduceOperatorBase.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Marks the group reduce operation as combinable. Combinable operations may pre-reduce the
 * data before the actual group reduce operations. Combinable user-defined functions
 * must implement the interface {@link GroupCombineFunction}.
 * 
 * @param combinable Flag to mark the group reduce operation as combinable.
 */
public void setCombinable(boolean combinable) {
	// sanity check
	if (combinable && !GroupCombineFunction.class.isAssignableFrom(this.userFunction.getUserCodeClass())) {
		throw new IllegalArgumentException("Cannot set a UDF as combinable if it does not implement the interface " +
				GroupCombineFunction.class.getName());
	} else {
		this.combinable = combinable;
	}
}
 
Example #28
Source File: PlanUnwrappingReduceGroupOperator.java    From flink with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void combine(Iterable<Tuple2<K, IN>> values, Collector<Tuple2<K, IN>> out) throws Exception {

	iter.set(values.iterator());
	coll.set(out);
	((GroupCombineFunction<IN, IN>) this.wrappedFunction).combine(iter, coll);
}
 
Example #29
Source File: PlanUnwrappingSortedReduceGroupOperator.java    From flink with Apache License 2.0 5 votes vote down vote up
private TupleUnwrappingGroupCombinableGroupReducer(GroupReduceFunction<IN, OUT> wrapped) {
	super(wrapped);

	if (!GroupCombineFunction.class.isAssignableFrom(wrappedFunction.getClass())) {
		throw new IllegalArgumentException("Wrapped reduce function does not implement the GroupCombineFunction interface.");
	}

	this.iter = new Tuple3UnwrappingIterator<>();
	this.coll = new Tuple3WrappingCollector<>(this.iter);
}
 
Example #30
Source File: PlanUnwrappingSortedReduceGroupOperator.java    From flink with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void combine(Iterable<Tuple3<K1, K2, IN>> values, Collector<Tuple3<K1, K2, IN>> out) throws Exception {
	iter.set(values.iterator());
	coll.set(out);
	((GroupCombineFunction<IN, IN>) this.wrappedFunction).combine(iter, coll);
}