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