flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chesnay Schepler (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (FLINK-970) Implement a first(n) operator
Date Sun, 29 Jun 2014 13:42:24 GMT

    [ https://issues.apache.org/jira/browse/FLINK-970?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14047120#comment-14047120
] 

Chesnay Schepler commented on FLINK-970:
----------------------------------------

would it be enough the add the following code to the DataSet/UnsortedGrouping/SortedGrouping
classes?

{code:java}
public ReduceGroupOperator<T, T> first(final int n) {
		return new ReduceGroupOperator<T, T>(this, new GroupReduceFunction<T, T>() {
			@Override
			public void reduce(Iterator<T> values, Collector<T> out) throws Exception {
				for (int x=0; x < n && values.hasNext(); x++) {
					out.collect(values.next());
				}}});
	}
{code}

> Implement a first(n) operator
> -----------------------------
>
>                 Key: FLINK-970
>                 URL: https://issues.apache.org/jira/browse/FLINK-970
>             Project: Flink
>          Issue Type: New Feature
>            Reporter: Timo Walther
>            Priority: Minor
>
> It is only syntactic sugar, but I had many cases where I just needed the first element
 or the first 2 elements in a GroupReduce.
> E.g. Instead of
> {code:java}
> .reduceGroup(new GroupReduceFunction<String, String>() {
> 					@Override
> 					public void reduce(Iterator<String> values, Collector<String> out) throws
Exception {
> 						out.collect(values.next());
> 					}
> 				})
> {code}
> {code:java}
> .first()
> {code}



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Mime
View raw message