/** * This test validates whether the order of tuples has any impact on the outcome and if the smaller tuple is returned. */ @Test public void testMinByComparison() { SelectByMinFunction<Tuple5<Integer, Long, String, Long, Integer>> minByTuple = new SelectByMinFunction<Tuple5<Integer, Long, String, Long, Integer>>(tupleTypeInfo, new int[] {0}); try { Assert.assertSame("SelectByMin must return smaller tuple", smaller, minByTuple.reduce(smaller, bigger)); Assert.assertSame("SelectByMin must return smaller tuple", smaller, minByTuple.reduce(bigger, smaller)); } catch (Exception e) { Assert.fail("No exception should be thrown while comparing both tuples"); } }
/** * Applies a special case of a reduce transformation (minBy) on a grouped {@link DataSet}. * * <p>The transformation consecutively calls a {@link ReduceFunction} * until only a single element remains which is the result of the transformation. * A ReduceFunction combines two elements into one new element of the same type. * * @param fields Keys taken into account for finding the minimum. * @return A {@link ReduceOperator} representing the minimum. */ @SuppressWarnings({ "unchecked", "rawtypes" }) public ReduceOperator<T> minBy(int... fields) { // Check for using a tuple if (!this.inputDataSet.getType().isTupleType()) { throw new InvalidProgramException("Method minBy(int) only works on tuples."); } return new ReduceOperator<T>(this, new SelectByMinFunction( (TupleTypeInfo) this.inputDataSet.getType(), fields), Utils.getCallLocationName()); }
return new ReduceOperator<>(this, new SelectByMinFunction( (TupleTypeInfo) getType(), fields), Utils.getCallLocationName());
/** * Checks whether reduce does behave as expected if both values are the same object. */ @Test public void testMinByComparisonMultiple() { SelectByMinFunction<Tuple5<Integer, Long, String, Long, Integer>> minByTuple = new SelectByMinFunction<Tuple5<Integer, Long, String, Long, Integer>>(tupleTypeInfo, new int[] {0, 1, 2, 3, 4}); try { Assert.assertSame("SelectByMin must return smaller tuple", smaller, minByTuple.reduce(smaller, bigger)); Assert.assertSame("SelectByMin must return smaller tuple", smaller, minByTuple.reduce(bigger, smaller)); } catch (Exception e) { Assert.fail("No exception should be thrown while comparing both tuples"); } }
/** * Applies a special case of a reduce transformation (minBy) on a grouped {@link DataSet}. * * <p>The transformation consecutively calls a {@link ReduceFunction} * until only a single element remains which is the result of the transformation. * A ReduceFunction combines two elements into one new element of the same type. * * @param fields Keys taken into account for finding the minimum. * @return A {@link ReduceOperator} representing the minimum. */ @SuppressWarnings({ "unchecked", "rawtypes" }) public ReduceOperator<T> minBy(int... fields) { // Check for using a tuple if (!this.inputDataSet.getType().isTupleType()) { throw new InvalidProgramException("Method minBy(int) only works on tuples."); } return new ReduceOperator<T>(this, new SelectByMinFunction( (TupleTypeInfo) this.inputDataSet.getType(), fields), Utils.getCallLocationName()); }
/** * This test validates that when two tuples only differ in one value and that value's index is given * at construction time. The smaller tuple must be returned then. */ @Test public void testMinByComparisonSpecialCase2() { SelectByMinFunction<Tuple5<Integer, Long, String, Long, Integer>> minByTuple = new SelectByMinFunction<Tuple5<Integer, Long, String, Long, Integer>>(tupleTypeInfo, new int[] {0, 2, 1, 4, 3}); try { Assert.assertSame("SelectByMin must return smaller tuple", smaller, minByTuple.reduce(specialCaseSmaller, smaller)); Assert.assertSame("SelectByMin must return smaller tuple", smaller, minByTuple.reduce(smaller, specialCaseSmaller)); } catch (Exception e) { Assert.fail("No exception should be thrown while comparing both tuples"); } }
/** * Applies a special case of a reduce transformation (minBy) on a grouped {@link DataSet}. * * <p>The transformation consecutively calls a {@link ReduceFunction} * until only a single element remains which is the result of the transformation. * A ReduceFunction combines two elements into one new element of the same type. * * @param fields Keys taken into account for finding the minimum. * @return A {@link ReduceOperator} representing the minimum. */ @SuppressWarnings({ "unchecked", "rawtypes" }) public ReduceOperator<T> minBy(int... fields) { // Check for using a tuple if (!this.inputDataSet.getType().isTupleType()) { throw new InvalidProgramException("Method minBy(int) only works on tuples."); } return new ReduceOperator<T>(this, new SelectByMinFunction( (TupleTypeInfo) this.inputDataSet.getType(), fields), Utils.getCallLocationName()); }
/** * This test cases checks when two tuples only differ in one value, but this value is not * in the fields list. In that case it should be seen as equal and then the first given tuple (value1) should be returned by reduce(). */ @Test public void testMinByComparisonSpecialCase1() { SelectByMinFunction<Tuple5<Integer, Long, String, Long, Integer>> minByTuple = new SelectByMinFunction<Tuple5<Integer, Long, String, Long, Integer>>(tupleTypeInfo, new int[] {0, 3}); try { Assert.assertSame("SelectByMin must return the first given tuple", specialCaseBigger, minByTuple.reduce(specialCaseBigger, bigger)); Assert.assertSame("SelectByMin must return the first given tuple", bigger, minByTuple.reduce(bigger, specialCaseBigger)); } catch (Exception e) { Assert.fail("No exception should be thrown while comparing both tuples"); } }
return new ReduceOperator<>(this, new SelectByMinFunction( (TupleTypeInfo) getType(), fields), Utils.getCallLocationName());
return new ReduceOperator<>(this, new SelectByMinFunction( (TupleTypeInfo) getType(), fields), Utils.getCallLocationName());