Search in sources :

Example 56 with MapType

use of com.facebook.presto.common.type.MapType in project presto by prestodb.

the class TestArraySqlFunctions method testArrayFrequencyBigint.

@Test
public void testArrayFrequencyBigint() {
    FunctionAndTypeManager functionAndTypeManager = createTestFunctionAndTypeManager();
    MapType type = new MapType(BIGINT, INTEGER, methodHandle(TestRowType.class, "throwUnsupportedOperation"), methodHandle(TestRowType.class, "throwUnsupportedOperation"));
    TypeSignature typeSignature = TypeSignature.parseTypeSignature(type.getDisplayName());
    assertFunction("array_frequency(cast(null as array(bigint)))", functionAndTypeManager.getType(typeSignature), null);
    assertFunction("array_frequency(cast(array[] as array(bigint)))", functionAndTypeManager.getType(typeSignature), ImmutableMap.of());
    assertFunction("array_frequency(array[cast(null as bigint), cast(null as bigint), cast(null as bigint)])", functionAndTypeManager.getType(typeSignature), ImmutableMap.of());
    assertFunction("array_frequency(array[cast(null as bigint), bigint '1'])", functionAndTypeManager.getType(typeSignature), ImmutableMap.of(1L, 1));
    assertFunction("array_frequency(array[cast(null as bigint), bigint '1', bigint '3', cast(null as bigint), bigint '1', bigint '3', cast(null as bigint)])", functionAndTypeManager.getType(typeSignature), ImmutableMap.of(1L, 2, 3L, 2));
    assertFunction("array_frequency(array[bigint '1', bigint '1', bigint '2', bigint '2', bigint '3', bigint '1', bigint '3', bigint '2'])", functionAndTypeManager.getType(typeSignature), ImmutableMap.of(1L, 3, 2L, 3, 3L, 2));
    assertFunction("array_frequency(array[bigint '45'])", functionAndTypeManager.getType(typeSignature), ImmutableMap.of(45L, 1));
    assertFunction("array_frequency(array[bigint '-45'])", functionAndTypeManager.getType(typeSignature), ImmutableMap.of(-45L, 1));
    assertFunction("array_frequency(array[bigint '1', bigint '3', bigint '1', bigint '3'])", functionAndTypeManager.getType(typeSignature), ImmutableMap.of(1L, 2, 3L, 2));
    assertFunction("array_frequency(array[bigint '3', bigint '1', bigint '3',bigint '1'])", functionAndTypeManager.getType(typeSignature), ImmutableMap.of(1L, 2, 3L, 2));
    assertFunction("array_frequency(array[bigint '4',bigint '3',bigint '3',bigint '2',bigint '2',bigint '2',bigint '1',bigint '1',bigint '1',bigint '1'])", functionAndTypeManager.getType(typeSignature), ImmutableMap.of(1L, 4, 2L, 3, 3L, 2, 4L, 1));
    assertFunction("array_frequency(array[bigint '3', bigint '3', bigint '2', bigint '2', bigint '5', bigint '5', bigint '1', bigint '1'])", functionAndTypeManager.getType(typeSignature), ImmutableMap.of(1L, 2, 2L, 2, 3L, 2, 5L, 2));
}
Also used : TypeSignature(com.facebook.presto.common.type.TypeSignature) FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) FunctionAndTypeManager.createTestFunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager) TestRowType(com.facebook.presto.common.type.TestRowType) MapType(com.facebook.presto.common.type.MapType) Test(org.testng.annotations.Test)

Example 57 with MapType

use of com.facebook.presto.common.type.MapType in project presto by prestodb.

the class TestArrayOperators method testArrayHashOperator.

@Test
public void testArrayHashOperator() {
    assertArrayHashOperator("ARRAY[1, 2]", INTEGER, ImmutableList.of(1, 2));
    assertArrayHashOperator("ARRAY[true, false]", BOOLEAN, ImmutableList.of(true, false));
    // test with ARRAY[ MAP( ARRAY[1], ARRAY[2] ) ]
    MapType mapType = mapType(INTEGER, INTEGER);
    assertArrayHashOperator("ARRAY[MAP(ARRAY[1], ARRAY[2])]", mapType, ImmutableList.of(mapBlockOf(INTEGER, INTEGER, ImmutableMap.of(1L, 2L))));
}
Also used : MapType(com.facebook.presto.common.type.MapType) Test(org.testng.annotations.Test)

Example 58 with MapType

use of com.facebook.presto.common.type.MapType in project presto by prestodb.

the class TestOrcMapNullKey method testMapTypeWithNullsWithBatchReader.

@Test(dataProvider = "mapNullKeysEnabled")
public void testMapTypeWithNullsWithBatchReader(boolean mapNullKeysEnabled) throws Exception {
    MapType mapType = createMapType(BIGINT, BIGINT);
    Map<Long, Long> map = generateMap();
    Map<Long, Long> expectedToRead = new HashMap<>(map);
    if (!mapNullKeysEnabled) {
        expectedToRead.remove(null);
    }
    try (TempFile tempFile = createSingleColumnMapFileWithNullValues(mapType, map)) {
        try (OrcBatchRecordReader reader = createCustomOrcRecordReader(tempFile, ORC, OrcPredicate.TRUE, mapType, INITIAL_BATCH_SIZE, false, mapNullKeysEnabled)) {
            int batchSize = reader.nextBatch();
            assertEquals(batchSize, 1);
            assertEquals(readMap(reader.readBlock(0), 0), expectedToRead);
            assertEquals(reader.nextBatch(), -1);
        }
    }
}
Also used : HashMap(java.util.HashMap) MapType(com.facebook.presto.common.type.MapType) Test(org.testng.annotations.Test)

Example 59 with MapType

use of com.facebook.presto.common.type.MapType in project presto by prestodb.

the class TestOrcMapNullKey method createMapType.

public static MapType createMapType(Type keyType, Type valueType) {
    MethodHandle keyNativeEquals = getOperatorMethodHandle(OperatorType.EQUAL, keyType, keyType);
    MethodHandle keyBlockEquals = compose(keyNativeEquals, nativeValueGetter(keyType), nativeValueGetter(keyType));
    MethodHandle keyNativeHashCode = getOperatorMethodHandle(OperatorType.HASH_CODE, keyType);
    MethodHandle keyBlockHashCode = compose(keyNativeHashCode, nativeValueGetter(keyType));
    return new MapType(keyType, valueType, keyBlockEquals, keyBlockHashCode);
}
Also used : MapType(com.facebook.presto.common.type.MapType) MethodHandle(java.lang.invoke.MethodHandle) TestingEnvironment.getOperatorMethodHandle(com.facebook.presto.testing.TestingEnvironment.getOperatorMethodHandle)

Example 60 with MapType

use of com.facebook.presto.common.type.MapType in project presto by prestodb.

the class TestOrcMapNullKey method testMapTypeWithNullsWithSelectiveReader.

@Test(dataProvider = "mapNullKeysEnabled")
public void testMapTypeWithNullsWithSelectiveReader(boolean mapNullKeysEnabled) throws Exception {
    MapType mapType = createMapType(BIGINT, BIGINT);
    Map<Long, Long> map = generateMap();
    Map<Long, Long> expectedToRead = new HashMap<>(map);
    if (!mapNullKeysEnabled) {
        expectedToRead.remove(null);
    }
    try (TempFile tempFile = createSingleColumnMapFileWithNullValues(mapType, map)) {
        try (OrcSelectiveRecordReader reader = createCustomOrcSelectiveRecordReader(tempFile, ORC, OrcPredicate.TRUE, mapType, INITIAL_BATCH_SIZE, mapNullKeysEnabled, false)) {
            assertEquals(readMap(reader.getNextPage().getBlock(0).getLoadedBlock(), 0), expectedToRead);
            assertNull(reader.getNextPage());
        }
    }
}
Also used : OrcTester.createCustomOrcSelectiveRecordReader(com.facebook.presto.orc.OrcTester.createCustomOrcSelectiveRecordReader) HashMap(java.util.HashMap) MapType(com.facebook.presto.common.type.MapType) Test(org.testng.annotations.Test)

Aggregations

MapType (com.facebook.presto.common.type.MapType)92 Type (com.facebook.presto.common.type.Type)49 ArrayType (com.facebook.presto.common.type.ArrayType)40 Test (org.testng.annotations.Test)32 RowType (com.facebook.presto.common.type.RowType)30 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)24 Block (com.facebook.presto.common.block.Block)21 HashMap (java.util.HashMap)12 DecimalType (com.facebook.presto.common.type.DecimalType)11 ImmutableList (com.google.common.collect.ImmutableList)11 List (java.util.List)11 Map (java.util.Map)11 VarcharType (com.facebook.presto.common.type.VarcharType)9 MethodHandle (java.lang.invoke.MethodHandle)9 ArrayList (java.util.ArrayList)9 ImmutableMap (com.google.common.collect.ImmutableMap)8 SingleMapBlock (com.facebook.presto.common.block.SingleMapBlock)7 PrestoException (com.facebook.presto.spi.PrestoException)7 OperatorType (com.facebook.presto.common.function.OperatorType)6 MapBlockBuilder (com.facebook.presto.common.block.MapBlockBuilder)5