public static Block createLongsBlock(Long... values) { requireNonNull(values, "varargs 'values' is null"); return createLongsBlock(Arrays.asList(values)); }
@Test public void testNulls() { testAggregation(1L, createLongsBlock(1L, null)); testAggregation(1L, createLongsBlock(null, 1L)); } }
public static Page createPage(int i) { return new Page(BlockAssertions.createLongsBlock(i)); }
@Test public void testNulls() { testAggregation(1L, createLongsBlock(1L, null)); testAggregation(1L, createLongsBlock(null, 1L)); } }
private void testCustomAggregation(Long[] values, int n) { PriorityQueue<Long> heap = new PriorityQueue<>(n); Arrays.stream(values).filter(x -> x != null).forEach(heap::add); Long[] expected = new Long[heap.size()]; for (int i = heap.size() - 1; i >= 0; i--) { expected[i] = heap.remove(); } testAggregation(Arrays.asList(expected), createLongsBlock(values), createLongRepeatBlock(n, values.length)); } }
@Test public void testMemoryExceeded() { try { TypedSet typedSet = new TypedSet(BIGINT, 10, FUNCTION_NAME); for (int i = 0; i <= TypedSet.FOUR_MEGABYTES + 1; i++) { Block block = createLongsBlock(nCopies(1, (long) i)); typedSet.add(block, 0); } fail("expected exception"); } catch (PrestoException e) { assertEquals(e.getErrorCode(), EXCEEDED_FUNCTION_MEMORY_LIMIT.toErrorCode()); } }
@Test public void testMaxLongLongArray() { InternalAggregationFunction function = METADATA.getFunctionRegistry().getAggregateFunctionImplementation( new Signature("max_by", AGGREGATE, parseTypeSignature("array(bigint)"), parseTypeSignature("array(bigint)"), parseTypeSignature(StandardTypes.BIGINT))); assertAggregation( function, ImmutableList.of(1L, 2L), createArrayBigintBlock(asList(asList(3L, 4L), asList(1L, 2L), null)), createLongsBlock(1L, 2L, null)); assertAggregation( function, ImmutableList.of(2L, 3L), createArrayBigintBlock(asList(asList(3L, 4L), asList(2L, 3L), null, asList(1L, 2L))), createLongsBlock(0L, 1L, null, -1L)); }
@Test public void testMaxLongArrayLong() { InternalAggregationFunction function = METADATA.getFunctionRegistry().getAggregateFunctionImplementation( new Signature("max_by", AGGREGATE, parseTypeSignature(StandardTypes.BIGINT), parseTypeSignature(StandardTypes.BIGINT), parseTypeSignature("array(bigint)"))); assertAggregation( function, 1L, createLongsBlock(1L, 2L, 2L, 3L), createArrayBigintBlock(ImmutableList.of(ImmutableList.of(8L, 9L), ImmutableList.of(1L, 2L), ImmutableList.of(6L, 7L), ImmutableList.of(1L, 1L)))); assertAggregation( function, 2L, createLongsBlock(0L, 1L, 2L, -1L), createArrayBigintBlock(ImmutableList.of(ImmutableList.of(-8L, 9L), ImmutableList.of(-6L, 7L), ImmutableList.of(-1L, -3L), ImmutableList.of(-1L)))); }
@Test public void testBigInt() { InternalAggregationFunction bigIntAgg = metadata.getFunctionRegistry().getAggregateFunctionImplementation( new Signature("array_agg", AGGREGATE, parseTypeSignature("array(bigint)"), parseTypeSignature(StandardTypes.BIGINT))); assertAggregation( bigIntAgg, Arrays.asList(2L, 1L, 2L), createLongsBlock(new Long[] {2L, 1L, 2L})); }
@Test public void testNullPartial() { InternalAggregationFunction bigIntAgg = metadata.getFunctionRegistry().getAggregateFunctionImplementation( new Signature("array_agg", AGGREGATE, parseTypeSignature("array(bigint)"), parseTypeSignature(StandardTypes.BIGINT))); assertAggregation( bigIntAgg, Arrays.asList(null, 2L, null, 3L, null), createLongsBlock(new Long[] {null, 2L, null, 3L, null})); }
@Test public void testNullOnly() { InternalAggregationFunction bigIntAgg = metadata.getFunctionRegistry().getAggregateFunctionImplementation( new Signature("array_agg", AGGREGATE, parseTypeSignature("array(bigint)"), parseTypeSignature(StandardTypes.BIGINT))); assertAggregation( bigIntAgg, Arrays.asList(null, null, null), createLongsBlock(new Long[] {null, null, null})); }
private void testInvalidAggregation(Long[] x, int n) { try { testAggregation(new long[] {}, createLongsBlock(x), createLongRepeatBlock(n, x.length)); } catch (PrestoException e) { assertEquals(e.getErrorCode().getName(), INVALID_FUNCTION_ARGUMENT.name()); } }
@Test public void testEmpty() { InternalAggregationFunction bigIntAgg = metadata.getFunctionRegistry().getAggregateFunctionImplementation( new Signature("array_agg", AGGREGATE, parseTypeSignature("array(bigint)"), parseTypeSignature(StandardTypes.BIGINT))); assertAggregation( bigIntAgg, null, createLongsBlock(new Long[] {})); }
@Test public void testDictionaryBlockProcessingWithUnusedFailure() { // match some testFilter(createDictionaryBlockWithUnusedEntries(20, 100), DictionaryBlock.class); // match none testFilter(createDictionaryBlockWithUnusedEntries(20, 0), DictionaryBlock.class); // match all testFilter(new DictionaryBlock(createLongsBlock(4, 5, -1), new int[100]), DictionaryBlock.class); }
@Test public void testValidLong() { InternalAggregationFunction longAgg = metadata.getFunctionRegistry().getAggregateFunctionImplementation( new Signature("arbitrary", AGGREGATE, parseTypeSignature(StandardTypes.BIGINT), parseTypeSignature(StandardTypes.BIGINT))); assertAggregation( longAgg, 1L, createLongsBlock(1L, null)); }
@Test public void testNullLong() { InternalAggregationFunction longAgg = metadata.getFunctionRegistry().getAggregateFunctionImplementation( new Signature("arbitrary", AGGREGATE, parseTypeSignature(StandardTypes.BIGINT), parseTypeSignature(StandardTypes.BIGINT))); assertAggregation( longAgg, null, createLongsBlock(null, null)); }
public static Block createArrayBigintBlock(Iterable<? extends Iterable<Long>> values) { ArrayType arrayType = new ArrayType(BIGINT); BlockBuilder builder = arrayType.createBlockBuilder(null, 100); for (Iterable<Long> value : values) { if (value == null) { builder.appendNull(); } else { arrayType.writeObject(builder, createLongsBlock(value)); } } return builder.build(); }
@Test public void testLong() { InternalAggregationFunction longAgg = metadata.getFunctionRegistry().getAggregateFunctionImplementation( new Signature("checksum", AGGREGATE, parseTypeSignature(VARBINARY), parseTypeSignature(BIGINT))); Block block = createLongsBlock(null, 1L, 2L, 100L, null, Long.MAX_VALUE, Long.MIN_VALUE); assertAggregation(longAgg, expectedChecksum(BigintType.BIGINT, block), block); }
@Test public void testMaxLongVarchar() { InternalAggregationFunction function = METADATA.getFunctionRegistry().getAggregateFunctionImplementation(new Signature("max_by", AGGREGATE, parseTypeSignature(StandardTypes.VARCHAR), parseTypeSignature(StandardTypes.VARCHAR), parseTypeSignature(StandardTypes.BIGINT))); assertAggregation( function, "c", createStringsBlock("a", "b", "c"), createLongsBlock(1, 2, 3)); }
@Test public void testMinLongVarchar() { InternalAggregationFunction function = METADATA.getFunctionRegistry().getAggregateFunctionImplementation(new Signature("min_by", AGGREGATE, parseTypeSignature(StandardTypes.VARCHAR), parseTypeSignature(StandardTypes.VARCHAR), parseTypeSignature(StandardTypes.BIGINT))); assertAggregation( function, "a", createStringsBlock("a", "b", "c"), createLongsBlock(1, 2, 3)); }