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));
}
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))));
}
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);
}
}
}
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);
}
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());
}
}
}
Aggregations