tupleDs.groupBy(2).first(1); } catch (Exception e) { Assert.fail(); tupleDs.groupBy(1, 3).first(10); } catch (Exception e) { Assert.fail(); tupleDs.groupBy(0).first(0); Assert.fail(); } catch (InvalidProgramException ipe) { tupleDs.groupBy(2).first(-1); Assert.fail(); } catch (InvalidProgramException ipe) {
@Test public void testFirstNOnGroupedDS() throws Exception { /* * First-n on grouped data set */ final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); DataSet<Tuple3<Integer, Long, String>> ds = CollectionDataSets.get3TupleDataSet(env); DataSet<Tuple2<Long, Integer>> first = ds.groupBy(1).first(4) .map(new OneMapper2()).groupBy(0).sum(1); List<Tuple2<Long, Integer>> result = first.collect(); String expected = "(1,1)\n(2,2)\n(3,3)\n(4,4)\n(5,4)\n(6,4)\n"; compareResultAsText(result, expected); }
private <K extends Tuple> void createFirstOperation(PythonOperationInfo info) { if (sets.isDataSet(info.parentID)) { DataSet<byte[]> op = sets.getDataSet(info.parentID); sets.add(info.setID, op .first(info.count).setParallelism(info.parallelism).name("First")); } else if (sets.isUnsortedGrouping(info.parentID)) { UnsortedGrouping<Tuple2<K, byte[]>> op = sets.getUnsortedGrouping(info.parentID); sets.add(info.setID, op .first(info.count).setParallelism(info.parallelism).name("First") .map(new KeyDiscarder<K>()).setParallelism(info.parallelism).name("FirstPostStep")); } else if (sets.isSortedGrouping(info.parentID)) { SortedGrouping<Tuple2<K, byte[]>> op = sets.getSortedGrouping(info.parentID); sets.add(info.setID, op .first(info.count).setParallelism(info.parallelism).name("First") .map(new KeyDiscarder<K>()).setParallelism(info.parallelism).name("FirstPostStep")); } }
@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<>()); } }