/** * This test cases checks when two tuples only differ in one value. */ @Test public void testMaxByComparisonSpecialCase2() { SelectByMaxFunction<Tuple5<Integer, Long, String, Long, Integer>> maxByTuple = new SelectByMaxFunction<Tuple5<Integer, Long, String, Long, Integer>>(tupleTypeInfo, new int[] {0, 2, 1, 4, 3}); try { Assert.assertSame("SelectByMax must return bigger tuple", bigger, maxByTuple.reduce(specialCaseBigger, bigger)); Assert.assertSame("SelectByMax must return bigger tuple", bigger, maxByTuple.reduce(bigger, specialCaseBigger)); } catch (Exception e) { Assert.fail("No exception should be thrown while comparing both tuples"); } }
/** * Applies a special case of a reduce transformation (maxBy) 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> maxBy(int... fields) { // Check for using a tuple if (!this.inputDataSet.getType().isTupleType()) { throw new InvalidProgramException("Method maxBy(int) only works on tuples."); } return new ReduceOperator<T>(this, new SelectByMaxFunction( (TupleTypeInfo) this.inputDataSet.getType(), fields), Utils.getCallLocationName()); } // --------------------------------------------------------------------------------------------
return new ReduceOperator<>(this, new SelectByMaxFunction( (TupleTypeInfo) getType(), fields), Utils.getCallLocationName());
/** * Checks whether reduce does behave as expected if both values are the same object. */ @Test public void testMaxByComparisonMustReturnATuple() { SelectByMaxFunction<Tuple5<Integer, Long, String, Long, Integer>> maxByTuple = new SelectByMaxFunction<Tuple5<Integer, Long, String, Long, Integer>>(tupleTypeInfo, new int[] {0}); try { Assert.assertSame("SelectByMax must return bigger tuple", bigger, maxByTuple.reduce(bigger, bigger)); Assert.assertSame("SelectByMax must return smaller tuple", smaller, maxByTuple.reduce(smaller, smaller)); } catch (Exception e) { Assert.fail("No exception should be thrown while comparing both tuples"); } }
/** * Applies a special case of a reduce transformation (maxBy) 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> maxBy(int... fields) { // Check for using a tuple if (!this.inputDataSet.getType().isTupleType()) { throw new InvalidProgramException("Method maxBy(int) only works on tuples."); } return new ReduceOperator<T>(this, new SelectByMaxFunction( (TupleTypeInfo) this.inputDataSet.getType(), fields), Utils.getCallLocationName()); } // --------------------------------------------------------------------------------------------
/** * This test validates that equality is independent of the amount of used indices. */ @Test public void testMaxByComparisonMultiple() { SelectByMaxFunction<Tuple5<Integer, Long, String, Long, Integer>> maxByTuple = new SelectByMaxFunction<Tuple5<Integer, Long, String, Long, Integer>>(tupleTypeInfo, new int[] {0, 1, 2, 3, 4}); try { Assert.assertSame("SelectByMax must return bigger tuple", bigger, maxByTuple.reduce(smaller, bigger)); Assert.assertSame("SelectByMax must return bigger tuple", bigger, maxByTuple.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 (maxBy) 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> maxBy(int... fields) { // Check for using a tuple if (!this.inputDataSet.getType().isTupleType()) { throw new InvalidProgramException("Method maxBy(int) only works on tuples."); } return new ReduceOperator<T>(this, new SelectByMaxFunction( (TupleTypeInfo) this.inputDataSet.getType(), fields), Utils.getCallLocationName()); } // --------------------------------------------------------------------------------------------
/** * This test validates whether the order of tuples has any impact on the outcome and if the bigger tuple is returned. */ @Test public void testMaxByComparison() { SelectByMaxFunction<Tuple5<Integer, Long, String, Long, Integer>> maxByTuple = new SelectByMaxFunction<Tuple5<Integer, Long, String, Long, Integer>>(tupleTypeInfo, new int[] {0}); try { Assert.assertSame("SelectByMax must return bigger tuple", bigger, maxByTuple.reduce(smaller, bigger)); Assert.assertSame("SelectByMax must return bigger tuple", bigger, maxByTuple.reduce(bigger, smaller)); } catch (Exception e) { Assert.fail("No exception should be thrown while comparing both tuples"); } }
return new ReduceOperator<>(this, new SelectByMaxFunction( (TupleTypeInfo) 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 testMaxByComparisonSpecialCase1() { SelectByMaxFunction<Tuple5<Integer, Long, String, Long, Integer>> maxByTuple = new SelectByMaxFunction<Tuple5<Integer, Long, String, Long, Integer>>(tupleTypeInfo, new int[] {0, 3}); try { Assert.assertSame("SelectByMax must return the first given tuple", specialCaseBigger, maxByTuple.reduce(specialCaseBigger, bigger)); Assert.assertSame("SelectByMax must return the first given tuple", bigger, maxByTuple.reduce(bigger, specialCaseBigger)); } catch (Exception e) { Assert.fail("No exception should be thrown while comparing both tuples"); } }
return new ReduceOperator<>(this, new SelectByMaxFunction( (TupleTypeInfo) getType(), fields), Utils.getCallLocationName());