Search in sources :

Example 6 with UsedByGeneratedCode

use of com.facebook.presto.annotation.UsedByGeneratedCode in project presto by prestodb.

the class RowHashCodeOperator method hash.

@UsedByGeneratedCode
public static long hash(Type rowType, Block block) {
    BlockBuilder blockBuilder = rowType.createBlockBuilder(new BlockBuilderStatus(), 1);
    blockBuilder.writeObject(block).closeEntry();
    return rowType.hash(blockBuilder.build(), 0);
}
Also used : BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus) UsedByGeneratedCode(com.facebook.presto.annotation.UsedByGeneratedCode)

Example 7 with UsedByGeneratedCode

use of com.facebook.presto.annotation.UsedByGeneratedCode in project presto by prestodb.

the class MapConstructor method createMap.

@UsedByGeneratedCode
public static Block createMap(MapType mapType, Block keyBlock, Block valueBlock) {
    BlockBuilder blockBuilder = new InterleavedBlockBuilder(mapType.getTypeParameters(), new BlockBuilderStatus(), keyBlock.getPositionCount() * 2);
    checkCondition(keyBlock.getPositionCount() == valueBlock.getPositionCount(), INVALID_FUNCTION_ARGUMENT, "Key and value arrays must be the same length");
    for (int i = 0; i < keyBlock.getPositionCount(); i++) {
        if (keyBlock.isNull(i)) {
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "map key cannot be null");
        }
        mapType.getKeyType().appendTo(keyBlock, i, blockBuilder);
        mapType.getValueType().appendTo(valueBlock, i, blockBuilder);
    }
    return blockBuilder.build();
}
Also used : PrestoException(com.facebook.presto.spi.PrestoException) InterleavedBlockBuilder(com.facebook.presto.spi.block.InterleavedBlockBuilder) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) InterleavedBlockBuilder(com.facebook.presto.spi.block.InterleavedBlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus) UsedByGeneratedCode(com.facebook.presto.annotation.UsedByGeneratedCode)

Example 8 with UsedByGeneratedCode

use of com.facebook.presto.annotation.UsedByGeneratedCode in project presto by prestodb.

the class DecimalCasts method doubleToShortDecimal.

@UsedByGeneratedCode
public static long doubleToShortDecimal(double value, long precision, long scale, long tenToScale) {
    // TODO: implement specialized version for short decimals
    Slice decimal = internalDoubleToLongDecimal(value, precision, scale);
    long low = UnscaledDecimal128Arithmetic.getLong(decimal, 0);
    long high = UnscaledDecimal128Arithmetic.getLong(decimal, 1);
    checkState(high == 0 && low >= 0, "Unexpected long decimal");
    if (UnscaledDecimal128Arithmetic.isNegative(decimal)) {
        return -low;
    } else {
        return low;
    }
}
Also used : Slice(io.airlift.slice.Slice) UsedByGeneratedCode(com.facebook.presto.annotation.UsedByGeneratedCode)

Example 9 with UsedByGeneratedCode

use of com.facebook.presto.annotation.UsedByGeneratedCode in project presto by prestodb.

the class DecimalCasts method realToShortDecimal.

@UsedByGeneratedCode
public static long realToShortDecimal(long value, long precision, long scale, long tenToScale) {
    // TODO: implement specialized version for short decimals
    Slice decimal = realToLongDecimal(value, precision, scale);
    long low = UnscaledDecimal128Arithmetic.getLong(decimal, 0);
    long high = UnscaledDecimal128Arithmetic.getLong(decimal, 1);
    checkState(high == 0 && low >= 0, "Unexpected long decimal");
    if (UnscaledDecimal128Arithmetic.isNegative(decimal)) {
        return -low;
    } else {
        return low;
    }
}
Also used : Slice(io.airlift.slice.Slice) UsedByGeneratedCode(com.facebook.presto.annotation.UsedByGeneratedCode)

Example 10 with UsedByGeneratedCode

use of com.facebook.presto.annotation.UsedByGeneratedCode in project presto by prestodb.

the class ArrayConcatUtils method appendElement.

@UsedByGeneratedCode
public static Block appendElement(Type elementType, Block block, Slice value) {
    BlockBuilder blockBuilder = elementType.createBlockBuilder(new BlockBuilderStatus(), block.getPositionCount() + 1);
    for (int i = 0; i < block.getPositionCount(); i++) {
        elementType.appendTo(block, i, blockBuilder);
    }
    elementType.writeSlice(blockBuilder, value);
    return blockBuilder.build();
}
Also used : BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus) UsedByGeneratedCode(com.facebook.presto.annotation.UsedByGeneratedCode)

Aggregations

UsedByGeneratedCode (com.facebook.presto.annotation.UsedByGeneratedCode)23 BlockBuilder (com.facebook.presto.spi.block.BlockBuilder)17 BlockBuilderStatus (com.facebook.presto.spi.block.BlockBuilderStatus)15 PrestoException (com.facebook.presto.spi.PrestoException)7 Block (com.facebook.presto.spi.block.Block)3 Slice (io.airlift.slice.Slice)3 PageBuilder (com.facebook.presto.spi.PageBuilder)2 InterleavedBlockBuilder (com.facebook.presto.spi.block.InterleavedBlockBuilder)2 OperatorType (com.facebook.presto.spi.function.OperatorType)2 Type (com.facebook.presto.spi.type.Type)2 TypeJsonUtils.appendToBlockBuilder (com.facebook.presto.type.TypeJsonUtils.appendToBlockBuilder)2 BigDecimal (java.math.BigDecimal)2 TypedSet (com.facebook.presto.operator.aggregation.TypedSet)1 InterleavedBlock (com.facebook.presto.spi.block.InterleavedBlock)1 ArrayType (com.facebook.presto.type.ArrayType)1 MapType (com.facebook.presto.type.MapType)1 RowType (com.facebook.presto.type.RowType)1 TypeJsonUtils.stackRepresentationToObject (com.facebook.presto.type.TypeJsonUtils.stackRepresentationToObject)1 ImmutableList (com.google.common.collect.ImmutableList)1 DynamicSliceOutput (io.airlift.slice.DynamicSliceOutput)1