use of com.facebook.presto.common.block.SingleMapBlock in project presto by prestodb.
the class MapGenericEquality method genericEqual.
public static Boolean genericEqual(Type keyType, MethodHandle keyNativeHashCode, MethodHandle keyBlockNativeEquals, MethodHandle keyBlockHashCode, Block leftBlock, Block rightBlock, EqualityPredicate predicate) {
if (leftBlock.getPositionCount() != rightBlock.getPositionCount()) {
return false;
}
SingleMapBlock leftSingleMapLeftBlock = (SingleMapBlock) leftBlock;
SingleMapBlock rightSingleMapBlock = (SingleMapBlock) rightBlock;
boolean indeterminate = false;
for (int position = 0; position < leftSingleMapLeftBlock.getPositionCount(); position += 2) {
Object key = readNativeValue(keyType, leftBlock, position);
int leftPosition = position + 1;
int rightPosition;
try {
rightPosition = rightSingleMapBlock.seekKey(key, keyNativeHashCode, keyBlockNativeEquals, keyBlockHashCode);
} catch (NotSupportedException e) {
throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e);
}
if (rightPosition == -1) {
return false;
}
try {
Boolean result = predicate.equals(leftPosition, rightPosition);
if (result == null) {
indeterminate = true;
} else if (!result) {
return false;
}
} catch (Throwable t) {
throw internalError(t);
}
}
if (indeterminate) {
return null;
}
return true;
}
use of com.facebook.presto.common.block.SingleMapBlock in project presto by prestodb.
the class MapElementAtFunction method elementAt.
@UsedByGeneratedCode
public static Object elementAt(MethodHandle keyNativeHashCode, MethodHandle keyBlockNativeEquals, MethodHandle keyBlockHashCode, Type valueType, Block map, double key) {
SingleMapBlock mapBlock = (SingleMapBlock) map;
int valuePosition;
try {
valuePosition = mapBlock.seekKeyExact(key, keyNativeHashCode, keyBlockNativeEquals, keyBlockHashCode);
} catch (NotSupportedException e) {
throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e);
}
if (valuePosition == -1) {
return null;
}
return readNativeValue(valueType, mapBlock, valuePosition);
}
use of com.facebook.presto.common.block.SingleMapBlock in project presto by prestodb.
the class MapElementAtFunction method elementAt.
@UsedByGeneratedCode
public static Object elementAt(MethodHandle keyNativeHashCode, MethodHandle keyBlockNativeEquals, MethodHandle keyBlockHashCode, Type valueType, Block map, Object key) {
SingleMapBlock mapBlock = (SingleMapBlock) map;
int valuePosition;
try {
valuePosition = mapBlock.seekKeyExact((Block) key, keyNativeHashCode, keyBlockNativeEquals, keyBlockHashCode);
} catch (NotSupportedException e) {
throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e);
}
if (valuePosition == -1) {
return null;
}
return readNativeValue(valueType, mapBlock, valuePosition);
}
use of com.facebook.presto.common.block.SingleMapBlock in project presto by prestodb.
the class MapElementAtFunction method elementAt.
@UsedByGeneratedCode
public static Object elementAt(MethodHandle keyNativeHashCode, MethodHandle keyBlockNativeEquals, MethodHandle keyBlockHashCode, Type valueType, Block map, Slice key) {
SingleMapBlock mapBlock = (SingleMapBlock) map;
int valuePosition;
try {
valuePosition = mapBlock.seekKeyExact(key, keyNativeHashCode, keyBlockNativeEquals, keyBlockHashCode);
} catch (NotSupportedException e) {
throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e);
}
if (valuePosition == -1) {
return null;
}
return readNativeValue(valueType, mapBlock, valuePosition);
}
use of com.facebook.presto.common.block.SingleMapBlock in project presto by prestodb.
the class MapType method getObjectValue.
@Override
public Object getObjectValue(SqlFunctionProperties properties, Block block, int position) {
if (block.isNull(position)) {
return null;
}
Block singleMapBlock = block.getBlock(position);
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(properties, singleMapBlock, i), valueType.getObjectValue(properties, singleMapBlock, i + 1));
}
return Collections.unmodifiableMap(map);
}
Aggregations