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
@@ -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>