/** * This test validates that an InvalidProgramException is thrown when minBy * is used on a custom data type. */ @Test(expected = InvalidProgramException.class) public void testCustomKeyFieldsGrouping() { final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); this.customTypeData.add(new CustomType()); UnsortedGrouping<CustomType> groupDs = env.fromCollection(customTypeData).groupBy(0); // should not work: groups on custom type groupDs.minBy(0); }
/** * This test validates that an index which is out of bounds throws an * IndexOutOfBoundsException. */ @Test(expected = IndexOutOfBoundsException.class) public void testOutOfTupleBoundsGrouping1() { final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); UnsortedGrouping<Tuple5<Integer, Long, String, Long, Integer>> groupDs = env.fromCollection(emptyTupleData, tupleTypeInfo).groupBy(0); // should not work, key out of tuple bounds groupDs.minBy(5); }
/** * This test validates that an index which is out of bounds throws an * IndexOutOfBoundsException. */ @Test(expected = IndexOutOfBoundsException.class) public void testOutOfTupleBoundsGrouping2() { final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); UnsortedGrouping<Tuple5<Integer, Long, String, Long, Integer>> groupDs = env.fromCollection(emptyTupleData, tupleTypeInfo).groupBy(0); // should not work, key out of tuple bounds groupDs.minBy(-1); }
/** * This test validates that an index which is out of bounds throws an * IndexOutOfBoundsException. */ @Test(expected = IndexOutOfBoundsException.class) public void testOutOfTupleBoundsGrouping3() { final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); UnsortedGrouping<Tuple5<Integer, Long, String, Long, Integer>> groupDs = env.fromCollection(emptyTupleData, tupleTypeInfo).groupBy(0); // should not work, key out of tuple bounds groupDs.minBy(1, 2, 3, 4, -1); }
/** * This test validates that no exceptions is thrown when an empty grouping * calls minBy(). */ @Test public void testMinByKeyFieldsGrouping() { final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); UnsortedGrouping<Tuple5<Integer, Long, String, Long, Integer>> groupDs = env.fromCollection(emptyTupleData, tupleTypeInfo).groupBy(0); // should work try { groupDs.minBy(4, 0, 1, 2, 3); } catch (Exception e) { Assert.fail(); } }
private static DataSet<String> analyze(DataSet<String> input, DataSet<String> stats, int branches) { for (int i = 0; i < branches; i++) { final int ii = i; if (stats != null) { input = input.map( new RichMapFunction<String, String>() { @Override public String map(String value) { return value; } }).withBroadcastSet(stats.map(s -> "(" + s + ").map"), "stats"); } DataSet<String> branch = input .map(s -> new Tuple2<>(0, s + ii)).returns(Types.TUPLE(Types.STRING, Types.INT)) .groupBy(0) .minBy(1) .map(kv -> kv.f1).returns(Types.STRING); if (stats == null) { stats = branch; } else { stats = stats.union(branch); } } return stats.map(s -> "(" + s + ").stats"); } }