@Test public void testRowHistograms() throws Exception { RowType innerRowType = new RowType(ImmutableList.of(BIGINT, DOUBLE), Optional.of(ImmutableList.of("f1", "f2"))); MapType mapType = new MapType(innerRowType, BIGINT); InternalAggregationFunction aggregationFunction = metadata.getFunctionRegistry().getAggregateFunctionImplementation(new Signature(NAME, AGGREGATE, mapType.getTypeSignature().toString(), innerRowType.getTypeSignature().toString())); BlockBuilder builder = innerRowType.createBlockBuilder(new BlockBuilderStatus(), 3); innerRowType.writeObject(builder, testRowBigintBigint(1L, 1.0)); innerRowType.writeObject(builder, testRowBigintBigint(2L, 2.0)); innerRowType.writeObject(builder, testRowBigintBigint(3L, 3.0)); assertAggregation( aggregationFunction, 1.0, ImmutableMap.of(ImmutableList.of(1L, 1.0), 1L, ImmutableList.of(2L, 2.0), 1L, ImmutableList.of(3L, 3.0), 1L), builder.build()); }
@Test public void testStateDeserializer() throws Exception { String[] keys = {"loooooong string", "short string"}; double[] values = {3.14, 2.71}; MaxOrMinByStateSerializer serializer = new MaxOrMinByStateSerializer(DOUBLE, VARCHAR); BlockBuilder builder = new RowType(ImmutableList.of(VARCHAR, DOUBLE), Optional.empty()).createBlockBuilder(new BlockBuilderStatus(), 2); for (int i = 0; i < keys.length; i++) { serializer.serialize(makeState(keys[i], values[i]), builder); } Block serialized = builder.build(); for (int i = 0; i < keys.length; i++) { MaxOrMinByState deserialized = new MaxOrMinByStateFactory().createSingleState(); serializer.deserialize(serialized, i, deserialized); assertEquals(VARCHAR.getSlice(deserialized.getKey(), 0), Slices.utf8Slice(keys[i])); assertEquals(DOUBLE.getDouble(deserialized.getValue(), 0), values[i]); } }
@Test public void testDoubleRowMap() throws Exception { RowType innerRowType = new RowType(ImmutableList.of(BIGINT, DOUBLE), Optional.of(ImmutableList.of("f1", "f2"))); MapType mapType = new MapType(DOUBLE, innerRowType); InternalAggregationFunction aggFunc = metadata.getFunctionRegistry().getAggregateFunctionImplementation(new Signature(NAME, AGGREGATE, mapType.getTypeSignature().toString(), StandardTypes.DOUBLE, innerRowType.getTypeSignature().toString())); BlockBuilder builder = innerRowType.createBlockBuilder(new BlockBuilderStatus(), 3); innerRowType.writeObject(builder, testRowBigintBigint(1L, 1.0)); innerRowType.writeObject(builder, testRowBigintBigint(2L, 2.0)); innerRowType.writeObject(builder, testRowBigintBigint(3L, 3.0)); assertAggregation( aggFunc, 1.0, ImmutableMap.of(1.0, ImmutableList.of(1L, 1.0), 2.0, ImmutableList.of(2L, 2.0), 3.0, ImmutableList.of(3L, 3.0)), createDoublesBlock(1.0, 2.0, 3.0), builder.build()); }