Search in sources :

Example 6 with SingleMapBlock

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

the class MapType method equalOperator.

private static Boolean equalOperator(MethodHandle seekKey, MethodHandle valueEqualOperator, Block leftBlock, Block rightBlock) throws Throwable {
    if (leftBlock.getPositionCount() != rightBlock.getPositionCount()) {
        return false;
    }
    SingleMapBlock leftSingleMapLeftBlock = (SingleMapBlock) leftBlock;
    SingleMapBlock rightSingleMapBlock = (SingleMapBlock) rightBlock;
    boolean unknown = false;
    for (int position = 0; position < leftSingleMapLeftBlock.getPositionCount(); position += 2) {
        int leftPosition = position + 1;
        int rightPosition = (int) seekKey.invokeExact(rightSingleMapBlock, leftBlock, position);
        if (rightPosition == -1) {
            return false;
        }
        if (leftBlock.isNull(leftPosition) || rightBlock.isNull(rightPosition)) {
            unknown = true;
        } else {
            Boolean result = (Boolean) valueEqualOperator.invokeExact((Block) leftSingleMapLeftBlock, leftPosition, (Block) rightSingleMapBlock, rightPosition);
            if (result == null) {
                unknown = true;
            } else if (!result) {
                return false;
            }
        }
    }
    if (unknown) {
        return null;
    }
    return true;
}
Also used : MapBlock(io.trino.spi.block.MapBlock) Block(io.trino.spi.block.Block) SingleMapBlock(io.trino.spi.block.SingleMapBlock) SingleMapBlock(io.trino.spi.block.SingleMapBlock)

Example 7 with SingleMapBlock

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

the class MapType method distinctFromOperator.

private static boolean distinctFromOperator(MethodHandle seekKey, MethodHandle valueDistinctFromOperator, Block leftBlock, Block rightBlock) throws Throwable {
    boolean leftIsNull = leftBlock == null;
    boolean rightIsNull = rightBlock == null;
    if (leftIsNull || rightIsNull) {
        return leftIsNull != rightIsNull;
    }
    if (leftBlock.getPositionCount() != rightBlock.getPositionCount()) {
        return true;
    }
    SingleMapBlock leftSingleMapLeftBlock = (SingleMapBlock) leftBlock;
    SingleMapBlock rightSingleMapBlock = (SingleMapBlock) rightBlock;
    for (int position = 0; position < leftSingleMapLeftBlock.getPositionCount(); position += 2) {
        int leftPosition = position + 1;
        int rightPosition = (int) seekKey.invokeExact(rightSingleMapBlock, leftBlock, position);
        if (rightPosition == -1) {
            return true;
        }
        boolean result = (boolean) valueDistinctFromOperator.invokeExact((Block) leftSingleMapLeftBlock, leftPosition, (Block) rightSingleMapBlock, rightPosition);
        if (result) {
            return true;
        }
    }
    return false;
}
Also used : MapBlock(io.trino.spi.block.MapBlock) Block(io.trino.spi.block.Block) SingleMapBlock(io.trino.spi.block.SingleMapBlock) SingleMapBlock(io.trino.spi.block.SingleMapBlock)

Example 8 with SingleMapBlock

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

the class PostgreSqlClient method hstoreWriteFunction.

private ObjectWriteFunction hstoreWriteFunction(ConnectorSession session) {
    return ObjectWriteFunction.of(Block.class, (statement, index, block) -> {
        checkArgument(block instanceof SingleMapBlock, "wrong block type: %s. expected SingleMapBlock", block.getClass().getSimpleName());
        Map<Object, Object> map = new HashMap<>();
        for (int i = 0; i < block.getPositionCount(); i += 2) {
            map.put(varcharMapType.getKeyType().getObjectValue(session, block, i), varcharMapType.getValueType().getObjectValue(session, block, i + 1));
        }
        statement.setObject(index, Collections.unmodifiableMap(map));
    });
}
Also used : HashMap(java.util.HashMap) SingleMapBlock(io.trino.spi.block.SingleMapBlock) ImplementAvgFloatingPoint(io.trino.plugin.jdbc.aggregation.ImplementAvgFloatingPoint)

Example 9 with SingleMapBlock

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

the class MapElementAtFunction method elementAt.

@UsedByGeneratedCode
public static Object elementAt(Type valueType, Block map, long key) {
    SingleMapBlock mapBlock = (SingleMapBlock) map;
    int valuePosition = mapBlock.seekKeyExact(key);
    if (valuePosition == -1) {
        return null;
    }
    return readNativeValue(valueType, mapBlock, valuePosition);
}
Also used : SingleMapBlock(io.trino.spi.block.SingleMapBlock) UsedByGeneratedCode(io.trino.annotation.UsedByGeneratedCode)

Example 10 with SingleMapBlock

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

the class MapElementAtFunction method elementAt.

@UsedByGeneratedCode
public static Object elementAt(Type valueType, Block map, Object key) {
    SingleMapBlock mapBlock = (SingleMapBlock) map;
    int valuePosition = mapBlock.seekKeyExact(key);
    if (valuePosition == -1) {
        return null;
    }
    return readNativeValue(valueType, mapBlock, valuePosition);
}
Also used : SingleMapBlock(io.trino.spi.block.SingleMapBlock) UsedByGeneratedCode(io.trino.annotation.UsedByGeneratedCode)

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