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