You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by fh...@apache.org on 2014/09/24 18:22:26 UTC

[3/3] git commit: Added documentation for first-n operator.

Added documentation for first-n operator.


Project: http://git-wip-us.apache.org/repos/asf/incubator-flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-flink/commit/a3b02840
Tree: http://git-wip-us.apache.org/repos/asf/incubator-flink/tree/a3b02840
Diff: http://git-wip-us.apache.org/repos/asf/incubator-flink/diff/a3b02840

Branch: refs/heads/master
Commit: a3b02840dcbfb8ea2f1c448c06b8a9fbb1e3f65d
Parents: 141946a
Author: Fabian Hueske <fh...@apache.org>
Authored: Wed Sep 24 16:34:36 2014 +0200
Committer: Fabian Hueske <fh...@apache.org>
Committed: Wed Sep 24 18:21:22 2014 +0200

----------------------------------------------------------------------
 docs/dataset_transformations.md | 23 +++++++++++++++++++++--
 docs/programming_guide.md       | 22 ++++++++++++++++++++--
 2 files changed, 41 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-flink/blob/a3b02840/docs/dataset_transformations.md
----------------------------------------------------------------------
diff --git a/docs/dataset_transformations.md b/docs/dataset_transformations.md
index a490a26..ec038a7 100644
--- a/docs/dataset_transformations.md
+++ b/docs/dataset_transformations.md
@@ -1134,6 +1134,25 @@ Only Map-like transformations may follow a hash-partition transformation, i.e.,
 ~~~java
 DataSet<Tuple2<String, Integer>> in = // [...]
 // hash-partition DataSet by String value and apply a MapPartition transformation.
-DataSet<Tuple2<String, String>> links = in.partitionByHash(0)
-                                          .mapPartition(new PartitionMapper());
+DataSet<Tuple2<String, String>> out = in.partitionByHash(0)
+                                        .mapPartition(new PartitionMapper());
+~~~
+
+### First-n (Java API Only)
+
+Returns the first n (arbitrary) elements of a DataSet. First-n can be applied on a regular DataSet, a grouped DataSet, or a grouped-sorted DataSet. Grouping keys can be specified as key-selector functions or field position keys (see [Reduce examples](#reduce-on-grouped-dataset) for how to specify keys).
+
+~~~java
+DataSet<Tuple2<String, Integer>> in = // [...]
+// Return the first five (arbitrary) elements of the DataSet
+DataSet<Tuple2<String, Integer>> out1 = in.first(5);
+
+// Return the first two (arbitrary) elements of each String group
+DataSet<Tuple2<String, Integer>> out2 = in.groupBy(0)
+                                          .first(2);
+
+// Return the first three elements of each String group ordered by the Integer field
+DataSet<Tuple2<String, Integer>> out3 = in.groupBy(0)
+                                          .sortGroup(1, Order.ASCENDING)
+                                          .first(3);
 ~~~
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-flink/blob/a3b02840/docs/programming_guide.md
----------------------------------------------------------------------
diff --git a/docs/programming_guide.md b/docs/programming_guide.md
index 99fc6d8..6e174ac 100644
--- a/docs/programming_guide.md
+++ b/docs/programming_guide.md
@@ -601,7 +601,7 @@ DataSet<String> result = data1.union(data2);
 {% highlight java %}
 DataSet<String> in = // [...]
 DataSet<String> result = in.rebalance()
-                           .map(new Mapper())
+                           .map(new Mapper());
 {% endhighlight %}
       </td>
     </tr>
@@ -612,7 +612,25 @@ DataSet<String> result = in.rebalance()
 {% highlight java %}
 DataSet<Tuple2<String,Integer>> in = // [...]
 DataSet<Integer> result = in.partitionByHash(0)
-                            .mapPartition(new PartitionMapper())
+                            .mapPartition(new PartitionMapper());
+{% endhighlight %}
+      </td>
+    </tr>
+    <tr>
+      <td><strong>First-n</strong></td>
+      <td>
+        <p>Returns the first n (arbitrary) elements of a data set. First-n can be applied on a regular data set, a grouped data set, or a grouped-sorted data set. Grouping keys can be specified as key-selector functions or field position keys.</p>
+{% highlight java %}
+DataSet<Tuple2<String,Integer>> in = // [...]
+// regular data set
+DataSet<Tuple2<String,Integer>> result1 = in.first(3);
+// grouped data set
+DataSet<Tuple2<String,Integer>> result2 = in.groupBy(0)
+                                            .first(3);
+// grouped-sorted data set
+DataSet<Tuple2<String,Integer>> result3 = in.groupBy(0)
+                                            .sortGroup(1, Order.ASCENDING)
+                                            .first(3);
 {% endhighlight %}
       </td>
     </tr>