Search in sources :

Example 11 with SingleMapBlock

use of io.trino.spi.block.SingleMapBlock in project trino by trinodb.

the class MapSubscriptOperator method subscript.

@UsedByGeneratedCode
public static Object subscript(MissingKeyExceptionFactory missingKeyExceptionFactory, Type keyType, Type valueType, ConnectorSession session, Block map, Object key) {
    SingleMapBlock mapBlock = (SingleMapBlock) map;
    int valuePosition = mapBlock.seekKeyExact(key);
    if (valuePosition == -1) {
        throw missingKeyExceptionFactory.create(session, key);
    }
    return readNativeValue(valueType, mapBlock, valuePosition);
}
Also used : SingleMapBlock(io.trino.spi.block.SingleMapBlock) UsedByGeneratedCode(io.trino.annotation.UsedByGeneratedCode)

Example 12 with SingleMapBlock

use of io.trino.spi.block.SingleMapBlock in project trino by trinodb.

the class MapSubscriptOperator method subscript.

@UsedByGeneratedCode
public static Object subscript(MissingKeyExceptionFactory missingKeyExceptionFactory, Type keyType, Type valueType, ConnectorSession session, Block map, double key) {
    SingleMapBlock mapBlock = (SingleMapBlock) map;
    int valuePosition = mapBlock.seekKeyExact(key);
    if (valuePosition == -1) {
        throw missingKeyExceptionFactory.create(session, key);
    }
    return readNativeValue(valueType, mapBlock, valuePosition);
}
Also used : SingleMapBlock(io.trino.spi.block.SingleMapBlock) UsedByGeneratedCode(io.trino.annotation.UsedByGeneratedCode)

Example 13 with SingleMapBlock

use of io.trino.spi.block.SingleMapBlock in project trino by trinodb.

the class MapSubscriptOperator method subscript.

@UsedByGeneratedCode
public static Object subscript(MissingKeyExceptionFactory missingKeyExceptionFactory, Type keyType, Type valueType, ConnectorSession session, Block map, long key) {
    SingleMapBlock mapBlock = (SingleMapBlock) map;
    int valuePosition = mapBlock.seekKeyExact(key);
    if (valuePosition == -1) {
        throw missingKeyExceptionFactory.create(session, key);
    }
    return readNativeValue(valueType, mapBlock, valuePosition);
}
Also used : SingleMapBlock(io.trino.spi.block.SingleMapBlock) UsedByGeneratedCode(io.trino.annotation.UsedByGeneratedCode)

Example 14 with SingleMapBlock

use of io.trino.spi.block.SingleMapBlock in project trino by trinodb.

the class MapType method writeObject.

@Override
public void writeObject(BlockBuilder blockBuilder, Object value) {
    if (!(value instanceof SingleMapBlock)) {
        throw new IllegalArgumentException("Maps must be represented with SingleMapBlock");
    }
    SingleMapBlock singleMapBlock = (SingleMapBlock) value;
    BlockBuilder entryBuilder = blockBuilder.beginBlockEntry();
    for (int i = 0; i < singleMapBlock.getPositionCount(); i += 2) {
        keyType.appendTo(singleMapBlock, i, entryBuilder);
        valueType.appendTo(singleMapBlock, i + 1, entryBuilder);
    }
    blockBuilder.closeEntry();
}
Also used : SingleMapBlock(io.trino.spi.block.SingleMapBlock) MapBlockBuilder(io.trino.spi.block.MapBlockBuilder) BlockBuilder(io.trino.spi.block.BlockBuilder)

Example 15 with SingleMapBlock

use of io.trino.spi.block.SingleMapBlock in project trino by trinodb.

the class MapType method getObjectValue.

@Override
public Object getObjectValue(ConnectorSession session, Block block, int position) {
    if (block.isNull(position)) {
        return null;
    }
    Block singleMapBlock = block.getObject(position, Block.class);
    if (!(singleMapBlock instanceof SingleMapBlock)) {
        throw new UnsupportedOperationException("Map is encoded with legacy block representation");
    }
    Map<Object, Object> map = new HashMap<>();
    for (int i = 0; i < singleMapBlock.getPositionCount(); i += 2) {
        map.put(keyType.getObjectValue(session, singleMapBlock, i), valueType.getObjectValue(session, singleMapBlock, i + 1));
    }
    return Collections.unmodifiableMap(map);
}
Also used : HashMap(java.util.HashMap) MapBlock(io.trino.spi.block.MapBlock) Block(io.trino.spi.block.Block) SingleMapBlock(io.trino.spi.block.SingleMapBlock) SingleMapBlock(io.trino.spi.block.SingleMapBlock)

Aggregations

SingleMapBlock (io.trino.spi.block.SingleMapBlock)16 UsedByGeneratedCode (io.trino.annotation.UsedByGeneratedCode)8 Block (io.trino.spi.block.Block)4 MapBlock (io.trino.spi.block.MapBlock)3 MapType (io.trino.spi.type.MapType)3 HashMap (java.util.HashMap)3 BlockBuilder (io.trino.spi.block.BlockBuilder)2 ImplementAvgFloatingPoint (io.trino.plugin.jdbc.aggregation.ImplementAvgFloatingPoint)1 PageBuilder (io.trino.spi.PageBuilder)1 MapBlockBuilder (io.trino.spi.block.MapBlockBuilder)1 Type (io.trino.spi.type.Type)1 TypeOperators (io.trino.spi.type.TypeOperators)1 TypeSignature.functionType (io.trino.spi.type.TypeSignature.functionType)1 TypeSignature.mapType (io.trino.spi.type.TypeSignature.mapType)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Test (org.testng.annotations.Test)1