flink git commit: [hotfix] [docs] Fix errors in streaming docs for fold()
Repository: flink Updated Branches: refs/heads/release-0.10 789728ce2 -> 2afe60094 [hotfix] [docs] Fix errors in streaming docs for fold() Project: http://git-wip-us.apache.org/repos/asf/flink/repo Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/2afe6009 Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/2afe6009 Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/2afe6009 Branch: refs/heads/release-0.10 Commit: 2afe60094999201ec98a9061aa458cdc2d6b2fe0 Parents: 789728c Author: Stephan EwenAuthored: Thu Nov 19 20:33:17 2015 +0100 Committer: Maximilian Michels Committed: Fri Dec 4 11:50:25 2015 +0100 -- docs/apis/streaming_guide.md | 46 +++ 1 file changed, 27 insertions(+), 19 deletions(-) -- http://git-wip-us.apache.org/repos/asf/flink/blob/2afe6009/docs/apis/streaming_guide.md -- diff --git a/docs/apis/streaming_guide.md b/docs/apis/streaming_guide.md index 170c7c6..6bb8961 100644 --- a/docs/apis/streaming_guide.md +++ b/docs/apis/streaming_guide.md @@ -526,15 +526,16 @@ keyedStream.reduce(new ReduceFunction() { emits the new value. - A fold function that creates a stream of partial sums: + A fold function that, when applied on the sequence (1,2,3,4,5), + emits the sequence "start-1", "start-1-2", "start-1-2-3", ... {% highlight java %} -keyedStream.fold(0, new ReduceFunction() { - @Override - public Integer fold(Integer accumulator, Integer value) - throws Exception { - return accumulator + value; - } -}); +DataStream result = + keyedStream.fold("start", new FoldFunction () { +@Override +public String fold(String current, Integer value) { +return current + "-" + value; +} + }); {% endhighlight %} @@ -621,11 +622,13 @@ windowedStream.reduce (new ReduceFunction () { Window FoldWindowedStream DataStream -Applies a functional fold function to the window and returns the folded value. +Applies a functional fold function to the window and returns the folded value. + The example function, when applied on the sequence (1,2,3,4,5), + folds the sequence into the string "start-1-2-3-4-5": {% highlight java %} -windowedStream.fold (new Tuple2 ("Sum of all", 0), new FoldFunction () { -public Tuple2 fold(Tuple2 acc, Tuple2 value) throws Exception { -return new Tuple2 (acc.f0, acc.f1 + value.f1); +windowedStream.fold("start-", new FoldFunction () { +public String fold(String current, Integer value) { +return current + "-" + value; } }; {% endhighlight %} @@ -884,16 +887,18 @@ keyedStream.reduce { _ + _ } - FoldDataStream DataStream + FoldKeyedStream DataStream A "rolling" fold on a keyed data stream with an initial value. Combines the current element with the last folded value and emits the new value. - A fold function that creates a stream of partial sums: + A fold function that, when applied on the sequence (1,2,3,4,5), + emits the sequence "start-1", "start-1-2", "start-1-2-3", ... {% highlight scala %} -keyedStream.fold { 0, _ + _ } +val result: DataStream[String] = +keyedStream.fold("start", (str, i) => { str + "-" + i }) {% endhighlight %} @@ -965,10 +970,13 @@ windowedStream.reduce { _ + _ } Window FoldWindowedStream DataStream -Applies a functional fold function to the window and returns the folded value. -{% highlight java %} -windowedStream.fold { 0, _ + _ } -{% endhighlight %} +Applies a functional fold function to the window and returns the folded value. + The example function, when applied on the sequence (1,2,3,4,5), + folds the sequence into the string "start-1-2-3-4-5": + {% highlight scala %} +val result: DataStream[String] = +windowedStream.fold("start", (str, i) => { str + "-" + i }) + {% endhighlight %}
flink git commit: [hotfix] [docs] Fix errors in streaming docs for fold()
Repository: flink Updated Branches: refs/heads/master 38cf0c610 -> 2f013a204 [hotfix] [docs] Fix errors in streaming docs for fold() Project: http://git-wip-us.apache.org/repos/asf/flink/repo Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/2f013a20 Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/2f013a20 Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/2f013a20 Branch: refs/heads/master Commit: 2f013a20414a825bb6fc31dfc96ff562141e209b Parents: 38cf0c6 Author: Stephan EwenAuthored: Thu Nov 19 20:33:17 2015 +0100 Committer: Stephan Ewen Committed: Thu Nov 19 20:33:17 2015 +0100 -- docs/apis/streaming_guide.md | 48 +++ 1 file changed, 28 insertions(+), 20 deletions(-) -- http://git-wip-us.apache.org/repos/asf/flink/blob/2f013a20/docs/apis/streaming_guide.md -- diff --git a/docs/apis/streaming_guide.md b/docs/apis/streaming_guide.md index fb6d86a..db1f3a7 100644 --- a/docs/apis/streaming_guide.md +++ b/docs/apis/streaming_guide.md @@ -519,22 +519,23 @@ keyedStream.reduce(new ReduceFunction() { - FoldDataStream DataStream + FoldKeyedStream DataStream A "rolling" fold on a keyed data stream with an initial value. Combines the current element with the last folded value and emits the new value. - A fold function that creates a stream of partial sums: + A fold function that, when applied on the sequence (1,2,3,4,5), + emits the sequence "start-1", "start-1-2", "start-1-2-3", ... {% highlight java %} -keyedStream.fold(0, new ReduceFunction() { - @Override - public Integer fold(Integer accumulator, Integer value) - throws Exception { - return accumulator + value; - } -}); +DataStream result = + keyedStream.fold("start", new FoldFunction () { +@Override +public String fold(String current, Integer value) { +return current + "-" + value; +} + }); {% endhighlight %} @@ -621,11 +622,13 @@ windowedStream.reduce (new ReduceFunction () { Window FoldWindowedStream DataStream -Applies a functional fold function to the window and returns the folded value. +Applies a functional fold function to the window and returns the folded value. + The example function, when applied on the sequence (1,2,3,4,5), + folds the sequence into the string "start-1-2-3-4-5": {% highlight java %} -windowedStream.fold (new Tuple2 ("Sum of all", 0), new FoldFunction () { -public Tuple2 fold(Tuple2 acc, Tuple2 value) throws Exception { -return new Tuple2 (acc.f0, acc.f1 + value.f1); +windowedStream.fold("start-", new FoldFunction () { +public String fold(String current, Integer value) { +return current + "-" + value; } }; {% endhighlight %} @@ -884,16 +887,18 @@ keyedStream.reduce { _ + _ } - FoldDataStream DataStream + FoldKeyedStream DataStream A "rolling" fold on a keyed data stream with an initial value. Combines the current element with the last folded value and emits the new value. - A fold function that creates a stream of partial sums: + A fold function that, when applied on the sequence (1,2,3,4,5), + emits the sequence "start-1", "start-1-2", "start-1-2-3", ... {% highlight scala %} -keyedStream.fold { 0, _ + _ } +val result: DataStream[String] = +keyedStream.fold("start", (str, i) => { str + "-" + i }) {% endhighlight %} @@ -965,10 +970,13 @@ windowedStream.reduce { _ + _ } Window FoldWindowedStream DataStream -Applies a functional fold function to the window and returns the folded value. -{% highlight java %} -windowedStream.fold { 0, _ + _ } -{% endhighlight %} +Applies a functional fold function to the window and returns the folded value. + The example function, when applied on the sequence (1,2,3,4,5), + folds the sequence into the string "start-1-2-3-4-5": + {% highlight scala %} +val result: DataStream[String] = +windowedStream.fold("start", (str, i) => { str + "-" + i }) + {% endhighlight %}