@Test public void testFirstNOnGroupedAndSortedDS() throws Exception { /* * First-n on grouped and sorted data set */ final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); DataSet<Tuple3<Integer, Long, String>> ds = CollectionDataSets.get3TupleDataSet(env); DataSet<Tuple2<Long, Integer>> first = ds.groupBy(1).sortGroup(0, Order.DESCENDING).first(3) .project(1, 0); List<Tuple2<Long, Integer>> result = first.collect(); String expected = "(1,1)\n" + "(2,3)\n(2,2)\n" + "(3,6)\n(3,5)\n(3,4)\n" + "(4,10)\n(4,9)\n(4,8)\n" + "(5,15)\n(5,14)\n(5,13)\n" + "(6,21)\n(6,20)\n(6,19)\n"; compareResultAsText(result, expected); }
@Override public DataSet<WithCount<String>> execute(LogicalGraph graph) { return graph.getEdges() .map(new ToSourceIdWithLabel<>()) .groupBy(0, 1) .first(1) .<Tuple1<String>>project(1) .map(new Tuple2FromTupleWithObjectAnd1L<>()) .groupBy(0) .sum(1) .map(new Tuple2ToWithCount<>()); }
@Override public DataSet<WithCount<String>> execute(LogicalGraph graph) { return graph.getEdges() .map(new ToTargetIdWithLabel<>()) .groupBy(0, 1) .first(1) .<Tuple1<String>>project(1) .map(new Tuple2FromTupleWithObjectAnd1L<>()) .groupBy(0) .sum(1) .map(new Tuple2ToWithCount<>()); }
@Override public DataSet<WithCount<String>> execute(LogicalGraph graph) { return graph.getEdges() .map(new ToTargetIdWithLabel<>()) .groupBy(0, 1) .first(1) .<Tuple1<String>>project(1) .map(new Tuple2FromTupleWithObjectAnd1L<>()) .groupBy(0) .sum(1) .map(new Tuple2ToWithCount<>()); } }
@Override public DataSet<WithCount<String>> execute(LogicalGraph graph) { return graph.getEdges() .map(new ToSourceIdWithLabel<>()) .groupBy(0, 1) .first(1) .<Tuple1<String>>project(1) .map(new Tuple2FromTupleWithObjectAnd1L<>()) .groupBy(0) .sum(1) .map(new Tuple2ToWithCount<>()); } }