tupleDs.groupBy(2).sortGroup(4, Order.ASCENDING).first(1); } catch (Exception e) { Assert.fail(); tupleDs.groupBy(1, 3).sortGroup(4, Order.ASCENDING).first(10); } catch (Exception e) { Assert.fail(); tupleDs.groupBy(0).sortGroup(4, Order.ASCENDING).first(0); Assert.fail(); } catch (InvalidProgramException ipe) { tupleDs.groupBy(2).sortGroup(4, Order.ASCENDING).first(-1); Assert.fail(); } catch (InvalidProgramException ipe) {
/** * Test for FLINK-2135. */ @Test public void testFaultyCast() throws Exception { ExecutionEnvironment ee = ExecutionEnvironment.getExecutionEnvironment(); DataSet<String> b = ee.fromElements("a", "b"); GroupReduceOperator<String, String> a = b.groupBy(new KeySelector<String, Long>() { @Override public Long getKey(String value) throws Exception { return 1L; } }).sortGroup(new KeySelector<String, Double>() { @Override public Double getKey(String value) throws Exception { return 1.0; } }, Order.DESCENDING).first(1); List<String> result = b.collect(); String expected = "a\nb"; compareResultAsText(result, expected); }
@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); }
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")); } }