Search in sources :

Example 51 with ArrayType

use of com.facebook.presto.type.ArrayType in project presto by prestodb.

the class TestChecksumAggregation method testArray.

@Test
public void testArray() throws Exception {
    ArrayType arrayType = new ArrayType(BigintType.BIGINT);
    InternalAggregationFunction stringAgg = metadata.getFunctionRegistry().getAggregateFunctionImplementation(new Signature("checksum", AGGREGATE, VarbinaryType.VARBINARY.getTypeSignature(), arrayType.getTypeSignature()));
    Block block = createArrayBigintBlock(asList(null, asList(1L, 2L), asList(3L, 4L), asList(5L, 6L)));
    assertAggregation(stringAgg, expectedChecksum(arrayType, block), block);
}
Also used : ArrayType(com.facebook.presto.type.ArrayType) Signature(com.facebook.presto.metadata.Signature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) Block(com.facebook.presto.spi.block.Block) BlockAssertions.createLongsBlock(com.facebook.presto.block.BlockAssertions.createLongsBlock) BlockAssertions.createShortDecimalsBlock(com.facebook.presto.block.BlockAssertions.createShortDecimalsBlock) BlockAssertions.createLongDecimalsBlock(com.facebook.presto.block.BlockAssertions.createLongDecimalsBlock) BlockAssertions.createStringsBlock(com.facebook.presto.block.BlockAssertions.createStringsBlock) BlockAssertions.createArrayBigintBlock(com.facebook.presto.block.BlockAssertions.createArrayBigintBlock) BlockAssertions.createBooleansBlock(com.facebook.presto.block.BlockAssertions.createBooleansBlock) BlockAssertions.createDoublesBlock(com.facebook.presto.block.BlockAssertions.createDoublesBlock) Test(org.testng.annotations.Test)

Example 52 with ArrayType

use of com.facebook.presto.type.ArrayType 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"))));
}
Also used : ArrayType(com.facebook.presto.type.ArrayType) Signature(com.facebook.presto.metadata.Signature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) MapType(com.facebook.presto.type.MapType) Test(org.testng.annotations.Test)

Example 53 with ArrayType

use of com.facebook.presto.type.ArrayType 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"))));
}
Also used : ArrayType(com.facebook.presto.type.ArrayType) Signature(com.facebook.presto.metadata.Signature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) MapType(com.facebook.presto.type.MapType) Test(org.testng.annotations.Test)

Example 54 with ArrayType

use of com.facebook.presto.type.ArrayType in project presto by prestodb.

the class TestMultimapAggAggregation method testDoubleArrayMultimap.

@Test
public void testDoubleArrayMultimap() throws Exception {
    Type arrayType = new ArrayType(VARCHAR);
    List<Double> expectedKeys = ImmutableList.of(1.0, 2.0, 3.0);
    List<List<String>> expectedValues = ImmutableList.of(ImmutableList.of("a", "b"), ImmutableList.of("c"), ImmutableList.of("d", "e", "f"));
    testMultimapAgg(DOUBLE, expectedKeys, arrayType, expectedValues);
}
Also used : ArrayType(com.facebook.presto.type.ArrayType) ArrayType(com.facebook.presto.type.ArrayType) MapType(com.facebook.presto.type.MapType) RowType(com.facebook.presto.type.RowType) Type(com.facebook.presto.spi.type.Type) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Test(org.testng.annotations.Test)

Example 55 with ArrayType

use of com.facebook.presto.type.ArrayType in project presto by prestodb.

the class TestMapUnionAggregation method testStructural.

@Test
public void testStructural() throws Exception {
    MapType mapType = new MapType(DOUBLE, new ArrayType(VARCHAR));
    InternalAggregationFunction aggFunc = metadata.getFunctionRegistry().getAggregateFunctionImplementation(new Signature(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 = new MapType(DOUBLE, new MapType(VARCHAR, VARCHAR));
    aggFunc = metadata.getFunctionRegistry().getAggregateFunctionImplementation(new Signature(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, new MapType(VARCHAR, VARCHAR), ImmutableMap.of(1.0, ImmutableMap.of("a", "b"), 2.0, ImmutableMap.of("c", "d"))), mapBlockOf(DOUBLE, new MapType(VARCHAR, VARCHAR), ImmutableMap.of(3.0, ImmutableMap.of("e", "f")))));
    mapType = new MapType(new ArrayType(VARCHAR), DOUBLE);
    aggFunc = metadata.getFunctionRegistry().getAggregateFunctionImplementation(new Signature(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(com.facebook.presto.type.ArrayType) Signature(com.facebook.presto.metadata.Signature) MapType(com.facebook.presto.type.MapType) Test(org.testng.annotations.Test)

Aggregations

ArrayType (com.facebook.presto.type.ArrayType)71 Test (org.testng.annotations.Test)45 MapType (com.facebook.presto.type.MapType)27 Type (com.facebook.presto.spi.type.Type)26 BlockBuilder (com.facebook.presto.spi.block.BlockBuilder)15 Block (com.facebook.presto.spi.block.Block)13 BlockBuilderStatus (com.facebook.presto.spi.block.BlockBuilderStatus)13 RowType (com.facebook.presto.type.RowType)12 ImmutableList (com.google.common.collect.ImmutableList)11 Signature (com.facebook.presto.metadata.Signature)7 ArrayList (java.util.ArrayList)7 List (java.util.List)7 DynamicClassLoader (com.facebook.presto.bytecode.DynamicClassLoader)6 MetadataManager (com.facebook.presto.metadata.MetadataManager)6 MetadataManager.createTestMetadataManager (com.facebook.presto.metadata.MetadataManager.createTestMetadataManager)5 Page (com.facebook.presto.spi.Page)5 InterleavedBlockBuilder (com.facebook.presto.spi.block.InterleavedBlockBuilder)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 TypeSignature.parseTypeSignature (com.facebook.presto.spi.type.TypeSignature.parseTypeSignature)4 MaterializedResult (com.facebook.presto.testing.MaterializedResult)4