use of io.trino.spi.type.MapType in project trino by trinodb.
the class RaptorStorageManager method toOrcFileType.
static Type toOrcFileType(Type raptorType, TypeManager typeManager) {
// TIMESTAMPS are stored as BIGINT to void the poor encoding in ORC
if (raptorType.equals(TIMESTAMP_MILLIS)) {
return BIGINT;
}
if (raptorType instanceof ArrayType) {
Type elementType = toOrcFileType(((ArrayType) raptorType).getElementType(), typeManager);
return new ArrayType(elementType);
}
if (raptorType instanceof MapType) {
TypeSignature keyType = toOrcFileType(((MapType) raptorType).getKeyType(), typeManager).getTypeSignature();
TypeSignature valueType = toOrcFileType(((MapType) raptorType).getValueType(), typeManager).getTypeSignature();
return typeManager.getParameterizedType(StandardTypes.MAP, ImmutableList.of(TypeSignatureParameter.typeParameter(keyType), TypeSignatureParameter.typeParameter(valueType)));
}
if (raptorType instanceof RowType) {
List<Field> fields = ((RowType) raptorType).getFields().stream().map(field -> new Field(field.getName(), toOrcFileType(field.getType(), typeManager))).collect(toImmutableList());
return RowType.from(fields);
}
return raptorType;
}
use of io.trino.spi.type.MapType in project trino by trinodb.
the class StructuralTestUtil method mapBlockOf.
public static Block mapBlockOf(Type keyType, Type valueType, Object key, Object value) {
MapType mapType = mapType(keyType, valueType);
BlockBuilder blockBuilder = mapType.createBlockBuilder(null, 10);
BlockBuilder singleMapBlockWriter = blockBuilder.beginBlockEntry();
appendToBlockBuilder(keyType, key, singleMapBlockWriter);
appendToBlockBuilder(valueType, value, singleMapBlockWriter);
blockBuilder.closeEntry();
return mapType.getObject(blockBuilder, 0);
}
use of io.trino.spi.type.MapType in project trino by trinodb.
the class KafkaRecordSet method headerMapValueProvider.
public static FieldValueProvider headerMapValueProvider(MapType varcharMapType, Headers headers) {
Type keyType = varcharMapType.getTypeParameters().get(0);
Type valueArrayType = varcharMapType.getTypeParameters().get(1);
Type valueType = valueArrayType.getTypeParameters().get(0);
BlockBuilder mapBlockBuilder = varcharMapType.createBlockBuilder(null, 1);
BlockBuilder builder = mapBlockBuilder.beginBlockEntry();
// Group by keys and collect values as array.
Multimap<String, byte[]> headerMap = ArrayListMultimap.create();
for (Header header : headers) {
headerMap.put(header.key(), header.value());
}
for (String headerKey : headerMap.keySet()) {
writeNativeValue(keyType, builder, headerKey);
BlockBuilder arrayBuilder = builder.beginBlockEntry();
for (byte[] value : headerMap.get(headerKey)) {
writeNativeValue(valueType, arrayBuilder, value);
}
builder.closeEntry();
}
mapBlockBuilder.closeEntry();
return new FieldValueProvider() {
@Override
public boolean isNull() {
return false;
}
@Override
public Block getBlock() {
return varcharMapType.getObject(mapBlockBuilder, 0);
}
};
}
use of io.trino.spi.type.MapType in project trino by trinodb.
the class PrometheusRecordCursor method getBlockFromMap.
static Block getBlockFromMap(Type mapType, Map<?, ?> map) {
// on functions like COUNT() the Type won't be a MapType
if (!(mapType instanceof MapType)) {
return null;
}
Type keyType = mapType.getTypeParameters().get(0);
Type valueType = mapType.getTypeParameters().get(1);
BlockBuilder mapBlockBuilder = mapType.createBlockBuilder(null, 1);
BlockBuilder builder = mapBlockBuilder.beginBlockEntry();
for (Map.Entry<?, ?> entry : map.entrySet()) {
writeObject(builder, keyType, entry.getKey());
writeObject(builder, valueType, entry.getValue());
}
mapBlockBuilder.closeEntry();
return (Block) mapType.getObject(mapBlockBuilder, 0);
}
use of io.trino.spi.type.MapType in project trino by trinodb.
the class PrometheusRecordCursor method getMapFromBlock.
static Map<Object, Object> getMapFromBlock(Type type, Block block) {
MapType mapType = (MapType) type;
Type keyType = mapType.getKeyType();
Type valueType = mapType.getValueType();
Map<Object, Object> map = new HashMap<>(block.getPositionCount() / 2);
for (int i = 0; i < block.getPositionCount(); i += 2) {
map.put(readObject(keyType, block, i), readObject(valueType, block, i + 1));
}
return map;
}
Aggregations