@Test public void testMinVarcharArray() { InternalAggregationFunction function = METADATA.getFunctionRegistry().getAggregateFunctionImplementation( new Signature("min_by", AGGREGATE, parseTypeSignature("array(array(bigint))"), parseTypeSignature("array(bigint)"), parseTypeSignature(StandardTypes.VARCHAR), parseTypeSignature(StandardTypes.BIGINT))); assertAggregation( function, ImmutableList.of(ImmutableList.of(2L, 3L), ImmutableList.of(4L, 5L)), createArrayBigintBlock(ImmutableList.of(ImmutableList.of(1L, 2L), ImmutableList.of(2L, 3L), ImmutableList.of(3L, 4L), ImmutableList.of(4L, 5L))), createStringsBlock("z", "a", "x", "b"), createRLEBlock(2L, 4)); }
@Test public void testMaxVarcharArray() { InternalAggregationFunction function = METADATA.getFunctionRegistry().getAggregateFunctionImplementation( new Signature("max_by", AGGREGATE, parseTypeSignature("array(array(bigint))"), parseTypeSignature("array(bigint)"), parseTypeSignature(StandardTypes.VARCHAR), parseTypeSignature(StandardTypes.BIGINT))); assertAggregation( function, ImmutableList.of(ImmutableList.of(1L, 2L), ImmutableList.of(3L, 4L)), createArrayBigintBlock(ImmutableList.of(ImmutableList.of(1L, 2L), ImmutableList.of(2L, 3L), ImmutableList.of(3L, 4L), ImmutableList.of(4L, 5L))), createStringsBlock("z", "a", "x", "b"), createRLEBlock(2L, 4)); }
@Test public void testMaxArrayVarchar() { InternalAggregationFunction function = METADATA.getFunctionRegistry().getAggregateFunctionImplementation( new Signature("max_by", AGGREGATE, parseTypeSignature("array(varchar)"), parseTypeSignature(StandardTypes.VARCHAR), parseTypeSignature("array(bigint)"), parseTypeSignature(StandardTypes.BIGINT))); assertAggregation( function, ImmutableList.of("a", "z", "x"), createStringsBlock("z", "a", "x", "b"), createArrayBigintBlock(ImmutableList.of(ImmutableList.of(1L, 2L), ImmutableList.of(2L, 3L), ImmutableList.of(0L, 3L), ImmutableList.of(0L, 2L))), createRLEBlock(3L, 4)); }
createRLEBlock(1, 10), 0.01, 1, 2, 3, 4, 5); testAggregationBigint( createLongsBlock(null, null, null, null, null), createRLEBlock(1, 5), NaN); testAggregationBigint( createLongsBlock(-1, -2, -3, -4, -5, -6, -7, -8, -9, -10), createRLEBlock(1, 10), 0.01, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10); testAggregationBigint( createLongsBlock(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), createRLEBlock(1, 10), 0.01, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); testAggregationBigint( createLongsBlock(new int[] {}), createRLEBlock(1, 0), NaN); testAggregationBigint( createLongsBlock(1), createRLEBlock(1, 1), 0.01, 1); testAggregationBigint( createLongSequenceBlock(-1000, 1000), createRLEBlock(1, 2000), 0.01, LongStream.range(-1000, 1000).toArray());
@Test public void testMinArrayVarchar() { InternalAggregationFunction function = METADATA.getFunctionRegistry().getAggregateFunctionImplementation( new Signature("min_by", AGGREGATE, parseTypeSignature("array(varchar)"), parseTypeSignature(StandardTypes.VARCHAR), parseTypeSignature("array(bigint)"), parseTypeSignature(StandardTypes.BIGINT))); assertAggregation( function, ImmutableList.of("b", "x", "z"), createStringsBlock("z", "a", "x", "b"), createArrayBigintBlock(ImmutableList.of(ImmutableList.of(1L, 2L), ImmutableList.of(2L, 3L), ImmutableList.of(0L, 3L), ImmutableList.of(0L, 2L))), createRLEBlock(3L, 4)); }
createRLEBlock(1, 10), 0.01, 1.0, 2.0, 3.0, 4.0, 5.0); testAggregationDouble( createDoublesBlock(null, null, null, null, null), createRLEBlock(1, 5), NaN); testAggregationDouble( createDoublesBlock(-1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0, -10.0), createRLEBlock(1, 10), 0.01, -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0, -10.0); testAggregationDouble( createDoublesBlock(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0), createRLEBlock(1, 10), 0.01, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0); testAggregationDouble( createDoublesBlock(), createRLEBlock(1, 0), NaN); testAggregationDouble( createDoublesBlock(1.0), createRLEBlock(1, 1), 0.01, 1.0); testAggregationDouble( createDoubleSequenceBlock(-1000, 1000), createRLEBlock(1, 2000), 0.01, LongStream.range(-1000, 1000).asDoubleStream().toArray());
createRLEBlock(1, 10), 0.01, 1.0F, 2.0F, 3.0F, 4.0F, 5.0F); testAggregationReal( createBlockOfReals(null, null, null, null, null), createRLEBlock(1, 5), NaN); testAggregationReal( createBlockOfReals(-1.0F, -2.0F, -3.0F, -4.0F, -5.0F, -6.0F, -7.0F, -8.0F, -9.0F, -10.0F), createRLEBlock(1, 10), 0.01, -1.0F, -2.0F, -3.0F, -4.0F, -5.0F, -6.0F, -7.0F, -8.0F, -9.0F, -10.0F); testAggregationReal( createBlockOfReals(1.0F, 2.0F, 3.0F, 4.0F, 5.0F, 6.0F, 7.0F, 8.0F, 9.0F, 10.0F), createRLEBlock(1, 10), 0.01, 1.0F, 2.0F, 3.0F, 4.0F, 5.0F, 6.0F, 7.0F, 8.0F, 9.0F, 10.0F); testAggregationReal( createBlockOfReals(), createRLEBlock(1, 0), NaN); testAggregationReal( createBlockOfReals(1.0F), createRLEBlock(1, 1), 0.01, 1.0F); testAggregationReal( createSequenceBlockOfReal(-1000, 1000), createRLEBlock(1, 2000), 0.01, Floats.toArray(LongStream.range(-1000, 1000).mapToObj(Float::new).collect(toImmutableList())));
@Test public void testSanityFilterOnRLE() { Signature lessThan = internalOperator(LESS_THAN, BOOLEAN, ImmutableList.of(BIGINT, BIGINT)); CallExpression filter = new CallExpression(lessThan, BOOLEAN, ImmutableList.of(field(0, BIGINT), constant(10L, BIGINT))); PageProcessor processor = compiler.compilePageProcessor(Optional.of(filter), ImmutableList.of(field(0, BIGINT)), MAX_BATCH_SIZE).get(); Page page = new Page(createRLEBlock(5L, 100)); Page outputPage = getOnlyElement( processor.process( null, new DriverYieldSignal(), newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()), page)) .orElseThrow(() -> new AssertionError("page is not present")); assertEquals(outputPage.getPositionCount(), 100); assertTrue(outputPage.getBlock(0) instanceof RunLengthEncodedBlock); RunLengthEncodedBlock rle = (RunLengthEncodedBlock) outputPage.getBlock(0); assertEquals(BIGINT.getLong(rle.getValue(), 0), 5L); }
@Test public void testMinDoubleVarchar() { InternalAggregationFunction function = METADATA.getFunctionRegistry().getAggregateFunctionImplementation( new Signature("min_by", AGGREGATE, parseTypeSignature("array(varchar)"), parseTypeSignature(StandardTypes.VARCHAR), parseTypeSignature(StandardTypes.DOUBLE), parseTypeSignature(StandardTypes.BIGINT))); assertAggregation( function, ImmutableList.of("z", "a"), createStringsBlock("z", "a", "x", "b"), createDoublesBlock(1.0, 2.0, 2.0, 3.0), createRLEBlock(2L, 4)); assertAggregation( function, ImmutableList.of("a", "zz"), createStringsBlock("zz", "hi", "bb", "a"), createDoublesBlock(0.0, 1.0, 2.0, -1.0), createRLEBlock(2L, 4)); assertAggregation( function, ImmutableList.of("a", "zz"), createStringsBlock("zz", "hi", null, "a"), createDoublesBlock(0.0, 1.0, null, -1.0), createRLEBlock(2L, 4)); }
@Test public void testMaxVarcharDouble() { InternalAggregationFunction function = METADATA.getFunctionRegistry().getAggregateFunctionImplementation( new Signature("max_by", AGGREGATE, parseTypeSignature("array(double)"), parseTypeSignature(StandardTypes.DOUBLE), parseTypeSignature(StandardTypes.VARCHAR), parseTypeSignature(StandardTypes.BIGINT))); assertAggregation( function, ImmutableList.of(1.0, 2.0), createDoublesBlock(1.0, 2.0, null), createStringsBlock("z", "a", null), createRLEBlock(2L, 3)); assertAggregation( function, ImmutableList.of(0.0, 1.0), createDoublesBlock(0.0, 1.0, 2.0, -1.0), createStringsBlock("zz", "hi", "bb", "a"), createRLEBlock(2L, 4)); assertAggregation( function, ImmutableList.of(0.0, 1.0), createDoublesBlock(0.0, 1.0, null, -1.0), createStringsBlock("zz", "hi", null, "a"), createRLEBlock(2L, 4)); }
@Test public void testMaxDoubleVarchar() { InternalAggregationFunction function = METADATA.getFunctionRegistry().getAggregateFunctionImplementation( new Signature("max_by", AGGREGATE, parseTypeSignature("array(varchar)"), parseTypeSignature(StandardTypes.VARCHAR), parseTypeSignature(StandardTypes.DOUBLE), parseTypeSignature(StandardTypes.BIGINT))); assertAggregation( function, ImmutableList.of("a", "z"), createStringsBlock("z", "a", null), createDoublesBlock(1.0, 2.0, null), createRLEBlock(2L, 3)); assertAggregation( function, ImmutableList.of("bb", "hi"), createStringsBlock("zz", "hi", "bb", "a"), createDoublesBlock(0.0, 1.0, 2.0, -1.0), createRLEBlock(2L, 4)); assertAggregation( function, ImmutableList.of("hi", "zz"), createStringsBlock("zz", "hi", null, "a"), createDoublesBlock(0.0, 1.0, null, -1.0), createRLEBlock(2L, 4)); }
@Test public void testMinVarcharDouble() { InternalAggregationFunction function = METADATA.getFunctionRegistry().getAggregateFunctionImplementation( new Signature("min_by", AGGREGATE, parseTypeSignature("array(double)"), parseTypeSignature(StandardTypes.DOUBLE), parseTypeSignature(StandardTypes.VARCHAR), parseTypeSignature(StandardTypes.BIGINT))); assertAggregation( function, ImmutableList.of(2.0, 3.0), createDoublesBlock(1.0, 2.0, 2.0, 3.0), createStringsBlock("z", "a", "x", "b"), createRLEBlock(2L, 4)); assertAggregation( function, ImmutableList.of(-1.0, 2.0), createDoublesBlock(0.0, 1.0, 2.0, -1.0), createStringsBlock("zz", "hi", "bb", "a"), createRLEBlock(2L, 4)); assertAggregation( function, ImmutableList.of(-1.0, 1.0), createDoublesBlock(0.0, 1.0, null, -1.0), createStringsBlock("zz", "hi", null, "a"), createRLEBlock(2L, 4)); }
createDoublesBlock(1.0, null), createDoublesBlock(5.0, 3.0), createRLEBlock(1L, 2)); createDoublesBlock(null, null), createDoublesBlock(null, null), createRLEBlock(1L, 2)); createDoublesBlock(2.5, 2.0, 5.0, 3.0), createDoublesBlock(4.0, 1.5, 2.0, 3.0), createRLEBlock(1L, 4)); createDoublesBlock(2.5, 2.0, 5.0, 3.0), createDoublesBlock(4.0, 1.5, 2.0, 3.0), createRLEBlock(2L, 4));
createDoublesBlock(1.0, null), createDoublesBlock(3.0, 5.0), createRLEBlock(1L, 2)); createDoublesBlock(null, null), createDoublesBlock(null, null), createRLEBlock(1L, 2)); createDoublesBlock(null, 1.0, null, null), createDoublesBlock(null, 0.0, null, null), createRLEBlock(2L, 4)); createDoublesBlock(1.0), createDoublesBlock(0.0), createRLEBlock(2L, 1)); createDoublesBlock(), createDoublesBlock(), createRLEBlock(2L, 0)); createDoublesBlock(2.5, 2.0, 5.0, 3.0), createDoublesBlock(4.0, 1.5, 2.0, 3.0), createRLEBlock(1L, 4)); createDoublesBlock(2.5, 2.0, 5.0, 3.0), createDoublesBlock(4.0, 1.5, 2.0, 3.0), createRLEBlock(2L, 4));
@Test(dataProvider = "partitionCount") public void test(int partitionCount) { InternalAggregationFunction function = getFunction(); List<OGCGeometry> geometries = makeGeometries(); Block geometryBlock = makeGeometryBlock(geometries); Block partitionCountBlock = BlockAssertions.createRLEBlock(partitionCount, geometries.size()); Rectangle expectedExtent = new Rectangle(-10, -10, Math.nextUp(10.0), Math.nextUp(10.0)); String expectedValue = getSpatialPartitioning(expectedExtent, geometries, partitionCount); AccumulatorFactory accumulatorFactory = function.bind(Ints.asList(0, 1, 2), Optional.empty()); Page page = new Page(geometryBlock, partitionCountBlock); Accumulator accumulator = accumulatorFactory.createAccumulator(); accumulator.addInput(page); String aggregation = (String) BlockAssertions.getOnlyValue(accumulator.getFinalType(), getFinalBlock(accumulator)); assertEquals(aggregation, expectedValue); GroupedAccumulator groupedAggregation = accumulatorFactory.createGroupedAccumulator(); groupedAggregation.addInput(createGroupByIdBlock(0, page.getPositionCount()), page); String groupValue = (String) getGroupValue(groupedAggregation, 0); assertEquals(groupValue, expectedValue); }
private void testAggregationDouble(Block longsBlock, Block weightsBlock, double maxError, double... inputs) { // Test without weights and accuracy testAggregationDoubles( getAggregationFunction(StandardTypes.DOUBLE), new Page(longsBlock), maxError, inputs); // Test with weights and without accuracy testAggregationDoubles( getAggregationFunction(StandardTypes.DOUBLE, StandardTypes.BIGINT), new Page(longsBlock, weightsBlock), maxError, inputs); // Test with weights and accuracy testAggregationDoubles( getAggregationFunction(StandardTypes.DOUBLE, StandardTypes.BIGINT, StandardTypes.DOUBLE), new Page(longsBlock, weightsBlock, createRLEBlock(maxError, longsBlock.getPositionCount())), maxError, inputs); }
private void testAggregationReal(Block longsBlock, Block weightsBlock, double maxError, float... inputs) { // Test without weights and accuracy testAggregationReal( getAggregationFunction(StandardTypes.REAL), new Page(longsBlock), maxError, inputs); // Test with weights and without accuracy testAggregationReal( getAggregationFunction(StandardTypes.REAL, StandardTypes.BIGINT), new Page(longsBlock, weightsBlock), maxError, inputs); // Test with weights and accuracy testAggregationReal( getAggregationFunction(StandardTypes.REAL, StandardTypes.BIGINT, StandardTypes.DOUBLE), new Page(longsBlock, weightsBlock, createRLEBlock(maxError, longsBlock.getPositionCount())), maxError, inputs); }
private void testAggregationBigint(Block inputBlock, Block weightsBlock, double maxError, long... inputs) { // Test without weights and accuracy testAggregationBigints( getAggregationFunction(StandardTypes.BIGINT), new Page(inputBlock), maxError, inputs); // Test with weights and without accuracy testAggregationBigints( getAggregationFunction(StandardTypes.BIGINT, StandardTypes.BIGINT), new Page(inputBlock, weightsBlock), maxError, inputs); // Test with weights and accuracy testAggregationBigints( getAggregationFunction(StandardTypes.BIGINT, StandardTypes.BIGINT, StandardTypes.DOUBLE), new Page(inputBlock, weightsBlock, createRLEBlock(maxError, inputBlock.getPositionCount())), maxError, inputs); }
@Test public void testMinVarcharArray() { InternalAggregationFunction function = METADATA.getFunctionRegistry().getAggregateFunctionImplementation(new Signature("min_by", AGGREGATE, "array(array(bigint))", "array(bigint)", StandardTypes.VARCHAR, StandardTypes.BIGINT)); assertAggregation( function, 1.0, ImmutableList.of(ImmutableList.of(2L, 3L), ImmutableList.of(4L, 5L)), createArrayBigintBlock(ImmutableList.of(ImmutableList.of(1L, 2L), ImmutableList.of(2L, 3L), ImmutableList.of(3L, 4L), ImmutableList.of(4L, 5L))), createStringsBlock("z", "a", "x", "b"), createRLEBlock(2L, 4)); }
@Test public void testMinArrayVarchar() { InternalAggregationFunction function = METADATA.getFunctionRegistry().getAggregateFunctionImplementation(new Signature("min_by", AGGREGATE, "array(varchar)", StandardTypes.VARCHAR, "array(bigint)", StandardTypes.BIGINT)); assertAggregation( function, 1.0, ImmutableList.of("b", "x", "z"), createStringsBlock("z", "a", "x", "b"), createArrayBigintBlock(ImmutableList.of(ImmutableList.of(1L, 2L), ImmutableList.of(2L, 3L), ImmutableList.of(0L, 3L), ImmutableList.of(0L, 2L))), createRLEBlock(3L, 4)); }