Search in sources :

Example 11 with NotSupportedException

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);
}
Also used : MapType(com.facebook.presto.common.type.MapType) Type(com.facebook.presto.common.type.Type) OperatorType(com.facebook.presto.common.function.OperatorType) PrestoException(com.facebook.presto.spi.PrestoException) SingleMapBlock(com.facebook.presto.common.block.SingleMapBlock) NotSupportedException(com.facebook.presto.common.NotSupportedException) BlockBuilder(com.facebook.presto.common.block.BlockBuilder)

Example 12 with NotSupportedException

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);
    }
}
Also used : PrestoException(com.facebook.presto.spi.PrestoException) NotSupportedException(com.facebook.presto.common.NotSupportedException)

Example 13 with NotSupportedException

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);
}
Also used : PrestoException(com.facebook.presto.spi.PrestoException) NotSupportedException(com.facebook.presto.common.NotSupportedException)

Example 14 with NotSupportedException

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);
        }
    }
}
Also used : PrestoException(com.facebook.presto.spi.PrestoException) NotSupportedException(com.facebook.presto.common.NotSupportedException)

Example 15 with NotSupportedException

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;
}
Also used : PrestoException(com.facebook.presto.spi.PrestoException) SingleMapBlock(com.facebook.presto.common.block.SingleMapBlock) NotSupportedException(com.facebook.presto.common.NotSupportedException)

Aggregations

NotSupportedException (com.facebook.presto.common.NotSupportedException)25 PrestoException (com.facebook.presto.spi.PrestoException)24 SingleMapBlock (com.facebook.presto.common.block.SingleMapBlock)12 UsedByGeneratedCode (com.facebook.presto.annotation.UsedByGeneratedCode)11 Block (com.facebook.presto.common.block.Block)9 Type (com.facebook.presto.common.type.Type)9 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)3 SortOrder (com.facebook.presto.common.block.SortOrder)3 JsonCodec (com.facebook.airlift.json.JsonCodec)1 JsonCodec.jsonCodec (com.facebook.airlift.json.JsonCodec.jsonCodec)1 Logger (com.facebook.airlift.log.Logger)1 Page (com.facebook.presto.common.Page)1 RuntimeStats (com.facebook.presto.common.RuntimeStats)1 AdaptiveLongBigArray (com.facebook.presto.common.array.AdaptiveLongBigArray)1 DuplicateMapKeyException (com.facebook.presto.common.block.DuplicateMapKeyException)1 MapBlockBuilder (com.facebook.presto.common.block.MapBlockBuilder)1 OperatorType (com.facebook.presto.common.function.OperatorType)1 CharType (com.facebook.presto.common.type.CharType)1 DecimalType (com.facebook.presto.common.type.DecimalType)1 MapType (com.facebook.presto.common.type.MapType)1