Search in sources :

Example 26 with MapType

use of io.prestosql.spi.type.MapType in project hetu-core by openlookeng.

the class TestMapUnionAggregation method testStructural.

@Test
public void testStructural() {
    MapType mapType = mapType(DOUBLE, new ArrayType(VARCHAR));
    InternalAggregationFunction aggFunc = metadata.getFunctionAndTypeManager().getAggregateFunctionImplementation(new Signature(QualifiedObjectName.valueOfDefaultFunction(NAME), AGGREGATE, mapType.getTypeSignature(), mapType.getTypeSignature()));
    assertAggregation(aggFunc, ImmutableMap.of(1.0, ImmutableList.of("a", "b"), 2.0, ImmutableList.of("c", "d"), 3.0, ImmutableList.of("e", "f"), 4.0, ImmutableList.of("r", "s")), arrayBlockOf(mapType, mapBlockOf(DOUBLE, new ArrayType(VARCHAR), ImmutableMap.of(1.0, ImmutableList.of("a", "b"), 2.0, ImmutableList.of("c", "d"), 3.0, ImmutableList.of("e", "f"))), mapBlockOf(DOUBLE, new ArrayType(VARCHAR), ImmutableMap.of(1.0, ImmutableList.of("x", "y"), 4.0, ImmutableList.of("r", "s"), 3.0, ImmutableList.of("w", "z")))));
    mapType = mapType(DOUBLE, mapType(VARCHAR, VARCHAR));
    aggFunc = metadata.getFunctionAndTypeManager().getAggregateFunctionImplementation(new Signature(QualifiedObjectName.valueOfDefaultFunction(NAME), AGGREGATE, mapType.getTypeSignature(), mapType.getTypeSignature()));
    assertAggregation(aggFunc, ImmutableMap.of(1.0, ImmutableMap.of("a", "b"), 2.0, ImmutableMap.of("c", "d"), 3.0, ImmutableMap.of("e", "f")), arrayBlockOf(mapType, mapBlockOf(DOUBLE, mapType(VARCHAR, VARCHAR), ImmutableMap.of(1.0, ImmutableMap.of("a", "b"), 2.0, ImmutableMap.of("c", "d"))), mapBlockOf(DOUBLE, mapType(VARCHAR, VARCHAR), ImmutableMap.of(3.0, ImmutableMap.of("e", "f")))));
    mapType = mapType(new ArrayType(VARCHAR), DOUBLE);
    aggFunc = metadata.getFunctionAndTypeManager().getAggregateFunctionImplementation(new Signature(QualifiedObjectName.valueOfDefaultFunction(NAME), AGGREGATE, mapType.getTypeSignature(), mapType.getTypeSignature()));
    assertAggregation(aggFunc, ImmutableMap.of(ImmutableList.of("a", "b"), 1.0, ImmutableList.of("c", "d"), 2.0, ImmutableList.of("e", "f"), 3.0), arrayBlockOf(mapType, mapBlockOf(new ArrayType(VARCHAR), DOUBLE, ImmutableMap.of(ImmutableList.of("a", "b"), 1.0, ImmutableList.of("e", "f"), 3.0)), mapBlockOf(new ArrayType(VARCHAR), DOUBLE, ImmutableMap.of(ImmutableList.of("c", "d"), 2.0))));
}
Also used : ArrayType(io.prestosql.spi.type.ArrayType) Signature(io.prestosql.spi.function.Signature) MapType(io.prestosql.spi.type.MapType) Test(org.testng.annotations.Test)

Example 27 with MapType

use of io.prestosql.spi.type.MapType in project hetu-core by openlookeng.

the class TestTypedHistogram method testMassive.

@Test
public void testMassive() {
    BlockBuilder inputBlockBuilder = BIGINT.createBlockBuilder(null, 5000);
    TypedHistogram typedHistogram = new SingleTypedHistogram(BIGINT, 1000);
    IntStream.range(1, 2000).flatMap(i -> IntStream.iterate(i, IntUnaryOperator.identity()).limit(i)).forEach(j -> BIGINT.writeLong(inputBlockBuilder, j));
    Block inputBlock = inputBlockBuilder.build();
    for (int i = 0; i < inputBlock.getPositionCount(); i++) {
        typedHistogram.add(i, inputBlock, 1);
    }
    MapType mapType = mapType(BIGINT, BIGINT);
    BlockBuilder out = mapType.createBlockBuilder(null, 1);
    typedHistogram.serialize(out);
    Block outputBlock = mapType.getObject(out, 0);
    for (int i = 0; i < outputBlock.getPositionCount(); i += 2) {
        assertEquals(BIGINT.getLong(outputBlock, i + 1), BIGINT.getLong(outputBlock, i));
    }
}
Also used : SingleTypedHistogram(io.prestosql.operator.aggregation.histogram.SingleTypedHistogram) MapType(io.prestosql.spi.type.MapType) IntStream(java.util.stream.IntStream) IntUnaryOperator(java.util.function.IntUnaryOperator) TypedHistogram(io.prestosql.operator.aggregation.histogram.TypedHistogram) BlockBuilder(io.prestosql.spi.block.BlockBuilder) StructuralTestUtil.mapType(io.prestosql.util.StructuralTestUtil.mapType) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) Block(io.prestosql.spi.block.Block) SingleTypedHistogram(io.prestosql.operator.aggregation.histogram.SingleTypedHistogram) TypedHistogram(io.prestosql.operator.aggregation.histogram.TypedHistogram) SingleTypedHistogram(io.prestosql.operator.aggregation.histogram.SingleTypedHistogram) Block(io.prestosql.spi.block.Block) MapType(io.prestosql.spi.type.MapType) BlockBuilder(io.prestosql.spi.block.BlockBuilder) Test(org.testng.annotations.Test)

Example 28 with MapType

use of io.prestosql.spi.type.MapType in project hetu-core by openlookeng.

the class TestMultimapAggAggregation method testDoubleMapMultimap.

@Test
public void testDoubleMapMultimap() {
    Type mapType = mapType(VARCHAR, BIGINT);
    List<Double> expectedKeys = ImmutableList.of(1.0, 2.0, 3.0);
    List<Map<String, Long>> expectedValues = ImmutableList.of(ImmutableMap.of("a", 1L), ImmutableMap.of("b", 2L, "c", 3L, "d", 4L), ImmutableMap.of("a", 1L));
    testMultimapAgg(DOUBLE, expectedKeys, mapType, expectedValues);
}
Also used : MapType(io.prestosql.spi.type.MapType) RowType(io.prestosql.spi.type.RowType) Type(io.prestosql.spi.type.Type) ArrayType(io.prestosql.spi.type.ArrayType) StructuralTestUtil.mapType(io.prestosql.util.StructuralTestUtil.mapType) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.testng.annotations.Test)

Example 29 with MapType

use of io.prestosql.spi.type.MapType in project hetu-core by openlookeng.

the class TestHistogram method testSimpleHistograms.

@Test
public void testSimpleHistograms() {
    MapType mapType = mapType(VARCHAR, BIGINT);
    InternalAggregationFunction aggregationFunction = getAggregation(mapType.getTypeSignature(), parseTypeSignature(StandardTypes.VARCHAR));
    assertAggregation(aggregationFunction, ImmutableMap.of("a", 1L, "b", 1L, "c", 1L), createStringsBlock("a", "b", "c"));
    mapType = mapType(BIGINT, BIGINT);
    aggregationFunction = getMetadata().getFunctionAndTypeManager().getAggregateFunctionImplementation(new Signature(QualifiedObjectName.valueOfDefaultFunction(NAME), AGGREGATE, mapType.getTypeSignature(), parseTypeSignature(StandardTypes.BIGINT)));
    assertAggregation(aggregationFunction, ImmutableMap.of(100L, 1L, 200L, 1L, 300L, 1L), createLongsBlock(100L, 200L, 300L));
    mapType = mapType(DOUBLE, BIGINT);
    aggregationFunction = getMetadata().getFunctionAndTypeManager().getAggregateFunctionImplementation(new Signature(QualifiedObjectName.valueOfDefaultFunction(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 = mapType(BOOLEAN, BIGINT);
    aggregationFunction = getMetadata().getFunctionAndTypeManager().getAggregateFunctionImplementation(new Signature(QualifiedObjectName.valueOfDefaultFunction(NAME), AGGREGATE, mapType.getTypeSignature(), parseTypeSignature(StandardTypes.BOOLEAN)));
    assertAggregation(aggregationFunction, ImmutableMap.of(true, 1L, false, 1L), createBooleansBlock(true, false));
}
Also used : TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) TypeSignature(io.prestosql.spi.type.TypeSignature) Signature(io.prestosql.spi.function.Signature) MapType(io.prestosql.spi.type.MapType) Test(org.testng.annotations.Test)

Example 30 with MapType

use of io.prestosql.spi.type.MapType in project hetu-core by openlookeng.

the class TestHistogram method testArrayHistograms.

@Test
public void testArrayHistograms() {
    ArrayType arrayType = new ArrayType(VARCHAR);
    MapType mapType = mapType(arrayType, BIGINT);
    InternalAggregationFunction aggregationFunction = getAggregation(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"))));
}
Also used : ArrayType(io.prestosql.spi.type.ArrayType) MapType(io.prestosql.spi.type.MapType) Test(org.testng.annotations.Test)

Aggregations

MapType (io.prestosql.spi.type.MapType)80 Type (io.prestosql.spi.type.Type)39 ArrayType (io.prestosql.spi.type.ArrayType)31 RowType (io.prestosql.spi.type.RowType)27 Test (org.testng.annotations.Test)27 BlockBuilder (io.prestosql.spi.block.BlockBuilder)17 Block (io.prestosql.spi.block.Block)15 Signature (io.prestosql.spi.function.Signature)14 VarcharType (io.prestosql.spi.type.VarcharType)11 List (java.util.List)11 BigintType (io.prestosql.spi.type.BigintType)10 BooleanType (io.prestosql.spi.type.BooleanType)10 DoubleType (io.prestosql.spi.type.DoubleType)10 IntegerType (io.prestosql.spi.type.IntegerType)10 TypeSignature.parseTypeSignature (io.prestosql.spi.type.TypeSignature.parseTypeSignature)10 RealType (io.prestosql.spi.type.RealType)9 SmallintType (io.prestosql.spi.type.SmallintType)9 TimestampType (io.prestosql.spi.type.TimestampType)9 TinyintType (io.prestosql.spi.type.TinyintType)9 VarbinaryType (io.prestosql.spi.type.VarbinaryType)9