use of com.facebook.presto.common.NotSupportedException in project presto by prestodb.
the class MapZipWithFunction method mapZipWith.
public static Block mapZipWith(Type keyType, Type leftValueType, Type rightValueType, MapType outputMapType, MethodHandle keyNativeHashCode, MethodHandle keyBlockNativeEquals, MethodHandle keyBlockHashCode, Block leftBlock, Block rightBlock, MapZipWithLambda function) {
SingleMapBlock leftMapBlock = (SingleMapBlock) leftBlock;
SingleMapBlock rightMapBlock = (SingleMapBlock) rightBlock;
Type outputValueType = outputMapType.getValueType();
BlockBuilder mapBlockBuilder = outputMapType.createBlockBuilder(null, max(leftMapBlock.getPositionCount(), rightMapBlock.getPositionCount()) / 2);
BlockBuilder blockBuilder = mapBlockBuilder.beginBlockEntry();
// seekKey() can take non-trivial time when key is complicated value, such as a long VARCHAR or ROW.
boolean[] keyFound = new boolean[rightMapBlock.getPositionCount()];
for (int leftKeyPosition = 0; leftKeyPosition < leftMapBlock.getPositionCount(); leftKeyPosition += 2) {
Object key = readNativeValue(keyType, leftMapBlock, leftKeyPosition);
Object leftValue = readNativeValue(leftValueType, leftMapBlock, leftKeyPosition + 1);
int rightValuePosition;
try {
rightValuePosition = rightMapBlock.seekKey(key, keyNativeHashCode, keyBlockNativeEquals, keyBlockHashCode);
} catch (NotSupportedException e) {
throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e);
}
Object rightValue = null;
if (rightValuePosition != -1) {
rightValue = readNativeValue(rightValueType, rightMapBlock, rightValuePosition);
keyFound[rightValuePosition / 2] = true;
}
Object outputValue;
try {
outputValue = function.apply(key, leftValue, rightValue);
} catch (Throwable throwable) {
// Restore pageBuilder into a consistent state.
mapBlockBuilder.closeEntry();
throwIfUnchecked(throwable);
throw new RuntimeException(throwable);
}
keyType.appendTo(leftMapBlock, leftKeyPosition, blockBuilder);
writeNativeValue(outputValueType, blockBuilder, outputValue);
}
// iterate over keys that only exists in rightMapBlock
for (int rightKeyPosition = 0; rightKeyPosition < rightMapBlock.getPositionCount(); rightKeyPosition += 2) {
if (!keyFound[rightKeyPosition / 2]) {
Object key = readNativeValue(keyType, rightMapBlock, rightKeyPosition);
Object rightValue = readNativeValue(rightValueType, rightMapBlock, rightKeyPosition + 1);
Object outputValue;
try {
outputValue = function.apply(key, null, rightValue);
} catch (Throwable throwable) {
// Restore pageBuilder into a consistent state.
mapBlockBuilder.closeEntry();
throwIfUnchecked(throwable);
throw new RuntimeException(throwable);
}
keyType.appendTo(rightMapBlock, rightKeyPosition, blockBuilder);
writeNativeValue(outputValueType, blockBuilder, outputValue);
}
}
mapBlockBuilder.closeEntry();
return outputMapType.getObject(mapBlockBuilder, mapBlockBuilder.getPositionCount() - 1);
}
use of com.facebook.presto.common.NotSupportedException in project presto by prestodb.
the class TypeUtils method positionEqualsPosition.
public static boolean positionEqualsPosition(Type type, Block leftBlock, int leftPosition, Block rightBlock, int rightPosition) {
boolean leftIsNull = leftBlock.isNull(leftPosition);
boolean rightIsNull = rightBlock.isNull(rightPosition);
if (leftIsNull || rightIsNull) {
return leftIsNull && rightIsNull;
}
try {
return type.equalTo(leftBlock, leftPosition, rightBlock, rightPosition);
} catch (NotSupportedException e) {
throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e);
}
}
use of com.facebook.presto.common.NotSupportedException in project presto by prestodb.
the class SingleTypedHistogram method add.
@Override
public void add(int position, Block block, long count) {
int hashPosition = getBucketId(TypeUtils.hashPosition(type, block, position), mask);
// look for an empty slot or a slot containing this key
while (true) {
if (hashPositions.get(hashPosition) == -1) {
break;
}
try {
if (type.equalTo(block, position, values, hashPositions.get(hashPosition))) {
counts.add(hashPositions.get(hashPosition), count);
return;
}
} catch (NotSupportedException e) {
throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e);
}
// increment position and mask to handle wrap around
hashPosition = (hashPosition + 1) & mask;
}
addNewGroup(hashPosition, position, block, count);
}
use of com.facebook.presto.common.NotSupportedException in project presto by prestodb.
the class ValueStore method addAndGetPosition.
/**
* This will add an item if not already in the system. It returns a pointer that is unique for multiple instances of the value. If item present,
* returns the pointer into the system
*/
public int addAndGetPosition(Type type, Block block, int position, long valueHash) {
if (values.getPositionCount() >= maxFill) {
rehash();
}
int bucketId = getBucketId(valueHash, mask);
int valuePointer;
// look for an empty slot or a slot containing this key
int probeCount = 1;
int originalBucketId = bucketId;
while (true) {
checkState(probeCount < bucketCount, "could not find match for value nor empty slot in %s buckets", bucketCount);
valuePointer = buckets.get(bucketId);
try {
if (valuePointer == EMPTY_BUCKET) {
valuePointer = values.getPositionCount();
valueHashes.set(valuePointer, (int) valueHash);
type.appendTo(block, position, values);
buckets.set(bucketId, valuePointer);
return valuePointer;
} else if (type.equalTo(block, position, values, valuePointer)) {
// value at position
return valuePointer;
} else {
int probe = nextProbe(probeCount);
bucketId = nextBucketId(originalBucketId, mask, probe);
probeCount++;
}
} catch (NotSupportedException e) {
throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e);
}
}
}
use of com.facebook.presto.common.NotSupportedException 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;
}
Aggregations