public static Object groupedAggregation(InternalAggregationFunction function, Page... pages) { return groupedAggregation(Objects::equals, function, pages); }
private long estimateGroupByCount(List<?> values, double maxStandardError) { Object result = AggregationTestUtils.groupedAggregation(getAggregationFunction(), createPage(values, maxStandardError)); return (long) result; }
public static Object groupedAggregation(BiFunction<Object, Object, Boolean> isEqual, InternalAggregationFunction function, Page... pages) { // execute with args in positions: arg0, arg1, arg2 Object aggregation = groupedAggregation(function, createArgs(function), pages); // execute with args in reverse order: arg2, arg1, arg0 if (function.getParameterTypes().size() > 1) { Object aggregationWithOffset = groupedAggregation(function, reverseArgs(function), reverseColumns(pages)); assertFunctionEquals(isEqual, "Inconsistent results with reversed channels", aggregationWithOffset, aggregation); } // execute with args at an offset (and possibly reversed): null, null, null, arg2, arg1, arg0 Object aggregationWithOffset = groupedAggregation(function, offsetArgs(function, 3), offsetColumns(pages, 3)); assertFunctionEquals(isEqual, "Consistent results with channel offset", aggregationWithOffset, aggregation); return aggregation; }
@Test public void testOutOfBound() { InternalAggregationFunction function = METADATA.getFunctionRegistry().getAggregateFunctionImplementation( new Signature("max_by", AGGREGATE, parseTypeSignature("array(varchar)"), parseTypeSignature(StandardTypes.VARCHAR), parseTypeSignature(StandardTypes.BIGINT), parseTypeSignature(StandardTypes.BIGINT))); try { groupedAggregation(function, new Page(createStringsBlock("z"), createLongsBlock(0), createLongsBlock(10001))); } catch (PrestoException e) { assertEquals(e.getMessage(), "third argument of max_by/min_by must be less than or equal to 10000; found 10001"); } } }
private static void assertAggregationInternal(InternalAggregationFunction function, BiFunction<Object, Object, Boolean> isEqual, String testDescription, Object expectedValue, Page... pages) { // This assertAggregation does not try to split up the page to test the correctness of combine function. // Do not use this directly. Always use the other assertAggregation. assertFunctionEquals(isEqual, testDescription, aggregation(function, pages), expectedValue); assertFunctionEquals(isEqual, testDescription, partialAggregation(function, pages), expectedValue); if (pages.length > 0) { assertFunctionEquals(isEqual, testDescription, groupedAggregation(isEqual, function, pages), expectedValue); assertFunctionEquals(isEqual, testDescription, groupedPartialAggregation(isEqual, function, pages), expectedValue); assertFunctionEquals(isEqual, testDescription, distinctAggregation(function, pages), expectedValue); } }
public static Object groupedAggregation(InternalAggregationFunction function, double confidence, Page... pages) { // execute with args in positions: arg0, arg1, arg2 Object aggregation = groupedAggregation(function, confidence, createArgs(function), pages); // execute with args in reverse order: arg2, arg1, arg0 if (function.getParameterTypes().size() > 1) { Object aggregationWithOffset = groupedAggregation(function, confidence, reverseArgs(function), reverseColumns(pages)); assertEquals(aggregationWithOffset, aggregation, "Inconsistent results with reversed channels"); } // execute with args at an offset (and possibly reversed): null, null, null, arg2, arg1, arg0 Object aggregationWithOffset = groupedAggregation(function, confidence, offsetArgs(function, 3), offsetColumns(pages, 3)); assertEquals(aggregationWithOffset, aggregation, "Inconsistent results with channel offset"); return aggregation; }
private long estimateGroupByCount(List<Object> values, double maxStandardError) { Object result = AggregationTestUtils.groupedAggregation(getAggregationFunction(), 1.0, createPage(values, maxStandardError)); return (long) result; }
private static void assertAggregation(InternalAggregationFunction function, double confidence, Object expectedValue, Page... pages) { BiConsumer<Object, Object> equalAssertion = (actual, expected) -> { assertEquals(actual, expected); }; if (isFloatingNumber(expectedValue) && !isNan(expectedValue)) { equalAssertion = (actual, expected) -> { assertEquals((double) actual, (double) expected, 1e-10); }; } // This assertAggregation does not try to split up the page to test the correctness of combine function. // Do not use this directly. Always use the other assertAggregation. equalAssertion.accept(aggregation(function, confidence, pages), expectedValue); equalAssertion.accept(partialAggregation(function, confidence, pages), expectedValue); if (pages.length > 0) { equalAssertion.accept(groupedAggregation(function, confidence, pages), expectedValue); equalAssertion.accept(groupedPartialAggregation(function, confidence, pages), expectedValue); equalAssertion.accept(distinctAggregation(function, confidence, pages), expectedValue); } }