use of com.facebook.presto.type.MapType in project presto by prestodb.
the class TestHistogram method testArrayHistograms.
@Test
public void testArrayHistograms() throws Exception {
ArrayType arrayType = new ArrayType(VARCHAR);
MapType mapType = new MapType(arrayType, BIGINT);
InternalAggregationFunction aggregationFunction = metadata.getFunctionRegistry().getAggregateFunctionImplementation(new Signature(NAME, AGGREGATE, mapType.getTypeSignature(), arrayType.getTypeSignature()));
assertAggregation(aggregationFunction, ImmutableMap.of(ImmutableList.of("a", "b", "c"), 1L, ImmutableList.of("d", "e", "f"), 1L, ImmutableList.of("c", "b", "a"), 1L), createStringArraysBlock(ImmutableList.of(ImmutableList.of("a", "b", "c"), ImmutableList.of("d", "e", "f"), ImmutableList.of("c", "b", "a"))));
}
use of com.facebook.presto.type.MapType in project presto by prestodb.
the class TestHistogram method testMapHistograms.
@Test
public void testMapHistograms() throws Exception {
MapType innerMapType = new MapType(VARCHAR, VARCHAR);
MapType mapType = new MapType(innerMapType, BIGINT);
InternalAggregationFunction aggregationFunction = metadata.getFunctionRegistry().getAggregateFunctionImplementation(new Signature(NAME, AGGREGATE, mapType.getTypeSignature(), innerMapType.getTypeSignature()));
BlockBuilder builder = innerMapType.createBlockBuilder(new BlockBuilderStatus(), 3);
innerMapType.writeObject(builder, mapBlockOf(VARCHAR, VARCHAR, ImmutableMap.of("a", "b")));
innerMapType.writeObject(builder, mapBlockOf(VARCHAR, VARCHAR, ImmutableMap.of("c", "d")));
innerMapType.writeObject(builder, mapBlockOf(VARCHAR, VARCHAR, ImmutableMap.of("e", "f")));
assertAggregation(aggregationFunction, ImmutableMap.of(ImmutableMap.of("a", "b"), 1L, ImmutableMap.of("c", "d"), 1L, ImmutableMap.of("e", "f"), 1L), builder.build());
}
use of com.facebook.presto.type.MapType in project presto by prestodb.
the class TestHistogram method testSimpleHistograms.
@Test
public void testSimpleHistograms() throws Exception {
MapType mapType = new MapType(VARCHAR, BIGINT);
InternalAggregationFunction aggregationFunction = metadata.getFunctionRegistry().getAggregateFunctionImplementation(new Signature(NAME, AGGREGATE, mapType.getTypeSignature(), parseTypeSignature(StandardTypes.VARCHAR)));
assertAggregation(aggregationFunction, ImmutableMap.of("a", 1L, "b", 1L, "c", 1L), createStringsBlock("a", "b", "c"));
mapType = new MapType(BIGINT, BIGINT);
aggregationFunction = metadata.getFunctionRegistry().getAggregateFunctionImplementation(new Signature(NAME, AGGREGATE, mapType.getTypeSignature(), parseTypeSignature(StandardTypes.BIGINT)));
assertAggregation(aggregationFunction, ImmutableMap.of(100L, 1L, 200L, 1L, 300L, 1L), createLongsBlock(100L, 200L, 300L));
mapType = new MapType(DOUBLE, BIGINT);
aggregationFunction = metadata.getFunctionRegistry().getAggregateFunctionImplementation(new Signature(NAME, AGGREGATE, mapType.getTypeSignature(), parseTypeSignature(StandardTypes.DOUBLE)));
assertAggregation(aggregationFunction, ImmutableMap.of(0.1, 1L, 0.3, 1L, 0.2, 1L), createDoublesBlock(0.1, 0.3, 0.2));
mapType = new MapType(BOOLEAN, BIGINT);
aggregationFunction = metadata.getFunctionRegistry().getAggregateFunctionImplementation(new Signature(NAME, AGGREGATE, mapType.getTypeSignature(), parseTypeSignature(StandardTypes.BOOLEAN)));
assertAggregation(aggregationFunction, ImmutableMap.of(true, 1L, false, 1L), createBooleansBlock(true, false));
}
use of com.facebook.presto.type.MapType in project presto by prestodb.
the class TestHistogram method testRowHistograms.
@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(), innerRowType.getTypeSignature()));
BlockBuilder builder = innerRowType.createBlockBuilder(new BlockBuilderStatus(), 3);
innerRowType.writeObject(builder, toRow(ImmutableList.of(BIGINT, DOUBLE), 1L, 1.0));
innerRowType.writeObject(builder, toRow(ImmutableList.of(BIGINT, DOUBLE), 2L, 2.0));
innerRowType.writeObject(builder, toRow(ImmutableList.of(BIGINT, DOUBLE), 3L, 3.0));
assertAggregation(aggregationFunction, ImmutableMap.of(ImmutableList.of(1L, 1.0), 1L, ImmutableList.of(2L, 2.0), 1L, ImmutableList.of(3L, 3.0), 1L), builder.build());
}
use of com.facebook.presto.type.MapType in project presto by prestodb.
the class TestMapAggAggregation method testDoubleArrayMap.
@Test
public void testDoubleArrayMap() throws Exception {
ArrayType arrayType = new ArrayType(VARCHAR);
MapType mapType = new MapType(DOUBLE, arrayType);
InternalAggregationFunction aggFunc = metadata.getFunctionRegistry().getAggregateFunctionImplementation(new Signature(NAME, AGGREGATE, mapType.getTypeSignature(), parseTypeSignature(StandardTypes.DOUBLE), arrayType.getTypeSignature()));
assertAggregation(aggFunc, ImmutableMap.of(1.0, ImmutableList.of("a", "b"), 2.0, ImmutableList.of("c", "d"), 3.0, ImmutableList.of("e", "f")), createDoublesBlock(1.0, 2.0, 3.0), createStringArraysBlock(ImmutableList.of(ImmutableList.of("a", "b"), ImmutableList.of("c", "d"), ImmutableList.of("e", "f"))));
}
Aggregations