use of com.facebook.presto.common.type.MapType in project presto by prestodb.
the class TestBlockEncodingBuffers method buildMapBlockStatus.
private BlockStatus buildMapBlockStatus(MapType mapType, int positionCount, boolean isView, Optional<boolean[]> isNull, int[] offsets, float primitiveNullRate, float nestedNullRate, List<Encoding> wrappings) {
BlockStatus blockStatus;
BlockStatus keyBlockStatus = buildBlockStatusWithType(mapType.getKeyType(), offsets[positionCount], isView, 0.0f, 0.0f, wrappings);
BlockStatus valueBlockStatus = buildBlockStatusWithType(mapType.getValueType(), offsets[positionCount], isView, primitiveNullRate, nestedNullRate, wrappings);
int[] expectedKeySizes = keyBlockStatus.expectedRowSizes;
int[] expectedValueSizes = valueBlockStatus.expectedRowSizes;
// Use expectedKeySizes for the total size for both key and values
Arrays.setAll(expectedKeySizes, i -> expectedKeySizes[i] + expectedValueSizes[i]);
int[] expectedRowSizes = IntStream.range(0, positionCount).map(i -> MapBlockEncodingBuffer.POSITION_SIZE + Arrays.stream(expectedKeySizes, offsets[i], offsets[i + 1]).sum()).toArray();
Type keyType = mapType.getKeyType();
blockStatus = new BlockStatus(fromKeyValueBlock(positionCount, isNull, offsets, keyBlockStatus.block, valueBlockStatus.block), expectedRowSizes);
return blockStatus;
}
use of com.facebook.presto.common.type.MapType in project presto by prestodb.
the class TestHistogram method testMapHistograms.
@Test
public void testMapHistograms() {
MapType innerMapType = mapType(VARCHAR, VARCHAR);
InternalAggregationFunction aggregationFunction = getAggregation(innerMapType);
BlockBuilder builder = innerMapType.createBlockBuilder(null, 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.common.type.MapType in project presto by prestodb.
the class TestMapUnionAggregation method testSimpleWithNulls.
@Test
public void testSimpleWithNulls() {
MapType mapType = mapType(DOUBLE, VARCHAR);
FunctionHandle functionHandle = FUNCTION_AND_TYPE_MANAGER.lookupFunction(NAME, fromTypes(mapType));
InternalAggregationFunction aggFunc = FUNCTION_AND_TYPE_MANAGER.getAggregateFunctionImplementation(functionHandle);
Map<Object, Object> expected = mapOf(23.0, "aaa", 33.0, null, 43.0, "ccc", 53.0, "ddd");
assertAggregation(aggFunc, expected, arrayBlockOf(mapType, mapBlockOf(DOUBLE, VARCHAR, mapOf(23.0, "aaa", 33.0, null, 53.0, "ddd")), null, mapBlockOf(DOUBLE, VARCHAR, mapOf(43.0, "ccc", 53.0, "ddd"))));
}
use of com.facebook.presto.common.type.MapType in project presto by prestodb.
the class TestMapUnionAggregation method testStructural.
@Test
public void testStructural() {
MapType mapType = mapType(DOUBLE, new ArrayType(VARCHAR));
FunctionHandle functionHandle = FUNCTION_AND_TYPE_MANAGER.lookupFunction(NAME, fromTypes(mapType));
InternalAggregationFunction aggFunc = FUNCTION_AND_TYPE_MANAGER.getAggregateFunctionImplementation(functionHandle);
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));
functionHandle = FUNCTION_AND_TYPE_MANAGER.lookupFunction(NAME, fromTypes(mapType));
aggFunc = FUNCTION_AND_TYPE_MANAGER.getAggregateFunctionImplementation(functionHandle);
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);
functionHandle = FUNCTION_AND_TYPE_MANAGER.lookupFunction(NAME, fromTypes(mapType));
aggFunc = FUNCTION_AND_TYPE_MANAGER.getAggregateFunctionImplementation(functionHandle);
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))));
}
use of com.facebook.presto.common.type.MapType in project presto by prestodb.
the class TestBlockEncodingBuffers method buildBlockStatusWithType.
private BlockStatus buildBlockStatusWithType(Type type, int positionCount, boolean isView, float primitiveNullRate, float nestedNullRate, List<Encoding> wrappings) {
BlockStatus blockStatus = null;
if (isView) {
positionCount *= 2;
}
if (type == BIGINT) {
blockStatus = buildBigintBlockStatus(positionCount, primitiveNullRate);
} else if (type instanceof DecimalType) {
if (!((DecimalType) type).isShort()) {
blockStatus = buildLongDecimalBlockStatus(positionCount, primitiveNullRate);
} else {
blockStatus = buildShortDecimalBlockStatus(positionCount, primitiveNullRate);
}
} else if (type == INTEGER) {
blockStatus = buildIntegerBlockStatus(positionCount, primitiveNullRate);
} else if (type == SMALLINT) {
blockStatus = buildSmallintBlockStatus(positionCount, primitiveNullRate);
} else if (type == BOOLEAN) {
blockStatus = buildBooleanBlockStatus(positionCount, primitiveNullRate);
} else if (type == VARCHAR) {
blockStatus = buildVarcharBlockStatus(positionCount, primitiveNullRate, 10);
} else {
// Nested types
// Build isNull and offsets of size positionCount
boolean[] isNull = null;
if (nestedNullRate > 0) {
isNull = new boolean[positionCount];
}
int[] offsets = new int[positionCount + 1];
for (int position = 0; position < positionCount; position++) {
if (nestedNullRate > 0 && ThreadLocalRandom.current().nextDouble(1) < nestedNullRate) {
isNull[position] = true;
offsets[position + 1] = offsets[position];
} else {
offsets[position + 1] = offsets[position] + (type instanceof RowType ? 1 : ThreadLocalRandom.current().nextInt(10) + 1);
}
}
// Build the nested block of size offsets[positionCount].
if (type instanceof ArrayType) {
blockStatus = buildArrayBlockStatus((ArrayType) type, positionCount, isView, Optional.ofNullable(isNull), offsets, primitiveNullRate, nestedNullRate, wrappings);
} else if (type instanceof MapType) {
blockStatus = buildMapBlockStatus((MapType) type, positionCount, isView, Optional.ofNullable(isNull), offsets, primitiveNullRate, nestedNullRate, wrappings);
} else if (type instanceof RowType) {
blockStatus = buildRowBlockStatus((RowType) type, positionCount, isView, Optional.ofNullable(isNull), offsets, primitiveNullRate, nestedNullRate, wrappings);
} else {
throw new UnsupportedOperationException(format("type %s is not supported.", type));
}
}
if (isView) {
positionCount /= 2;
int offset = positionCount / 2;
Block blockView = blockStatus.block.getRegion(offset, positionCount);
int[] expectedRowSizesView = Arrays.stream(blockStatus.expectedRowSizes, offset, offset + positionCount).toArray();
blockStatus = new BlockStatus(blockView, expectedRowSizesView);
}
blockStatus = buildDictRleBlockStatus(blockStatus, positionCount, wrappings);
return blockStatus;
}
Aggregations