Search in sources :

Example 36 with UsedByGeneratedCode

use of io.prestosql.spi.annotation.UsedByGeneratedCode in project hetu-core by openlookeng.

the class ArrayJoin method arrayJoin.

@UsedByGeneratedCode
public static Slice arrayJoin(MethodHandle castFunction, Object state, ConnectorSession session, Block arrayBlock, Slice delimiter, Slice nullReplacement) {
    PageBuilder pageBuilder = (PageBuilder) state;
    if (pageBuilder.isFull()) {
        pageBuilder.reset();
    }
    int numElements = arrayBlock.getPositionCount();
    BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(0);
    for (int i = 0; i < numElements; i++) {
        if (arrayBlock.isNull(i)) {
            if (nullReplacement != null) {
                blockBuilder.writeBytes(nullReplacement, 0, nullReplacement.length());
            } else {
                continue;
            }
        } else {
            try {
                Slice slice = (Slice) castFunction.invokeExact(arrayBlock, i, session);
                blockBuilder.writeBytes(slice, 0, slice.length());
            } catch (Throwable throwable) {
                // Restore pageBuilder into a consistent state
                blockBuilder.closeEntry();
                pageBuilder.declarePosition();
                throw new PrestoException(GENERIC_INTERNAL_ERROR, "Error casting array element to VARCHAR", throwable);
            }
        }
        if (i != numElements - 1) {
            blockBuilder.writeBytes(delimiter, 0, delimiter.length());
        }
    }
    blockBuilder.closeEntry();
    pageBuilder.declarePosition();
    return VARCHAR.getSlice(blockBuilder, blockBuilder.getPositionCount() - 1);
}
Also used : Slice(io.airlift.slice.Slice) PrestoException(io.prestosql.spi.PrestoException) PageBuilder(io.prestosql.spi.PageBuilder) BlockBuilder(io.prestosql.spi.block.BlockBuilder) UsedByGeneratedCode(io.prestosql.spi.annotation.UsedByGeneratedCode)

Example 37 with UsedByGeneratedCode

use of io.prestosql.spi.annotation.UsedByGeneratedCode in project hetu-core by openlookeng.

the class DecimalCasts method jsonToShortDecimal.

@UsedByGeneratedCode
public static Long jsonToShortDecimal(Slice json, long precision, long scale, long tenToScale) {
    try (JsonParser parser = createJsonParser(JSON_FACTORY, json)) {
        parser.nextToken();
        Long result = currentTokenAsShortDecimal(parser, intPrecision(precision), DecimalConversions.intScale(scale));
        // check no trailing token
        checkCondition(parser.nextToken() == null, INVALID_CAST_ARGUMENT, "Cannot cast input json to DECIMAL(%s,%s)", precision, scale);
        return result;
    } catch (IOException | NumberFormatException | JsonCastException e) {
        throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast '%s' to DECIMAL(%s,%s)", json.toStringUtf8(), precision, scale), e);
    }
}
Also used : UnscaledDecimal128Arithmetic.unscaledDecimalToUnscaledLong(io.prestosql.spi.type.UnscaledDecimal128Arithmetic.unscaledDecimalToUnscaledLong) JsonCastException(io.prestosql.util.JsonCastException) PrestoException(io.prestosql.spi.PrestoException) IOException(java.io.IOException) JsonUtil.createJsonParser(io.prestosql.util.JsonUtil.createJsonParser) JsonParser(com.fasterxml.jackson.core.JsonParser) UsedByGeneratedCode(io.prestosql.spi.annotation.UsedByGeneratedCode)

Example 38 with UsedByGeneratedCode

use of io.prestosql.spi.annotation.UsedByGeneratedCode in project hetu-core by openlookeng.

the class DecimalOperators method multiplyLongLongLong.

@UsedByGeneratedCode
public static Slice multiplyLongLongLong(Slice a, Slice b) {
    try {
        Slice result = UnscaledDecimal128Arithmetic.multiply(a, b);
        throwIfOverflows(result);
        return result;
    } catch (ArithmeticException e) {
        throw new PrestoException(NUMERIC_VALUE_OUT_OF_RANGE, "Decimal overflow", e);
    }
}
Also used : Slice(io.airlift.slice.Slice) PrestoException(io.prestosql.spi.PrestoException) UsedByGeneratedCode(io.prestosql.spi.annotation.UsedByGeneratedCode)

Aggregations

UsedByGeneratedCode (io.prestosql.spi.annotation.UsedByGeneratedCode)38 BlockBuilder (io.prestosql.spi.block.BlockBuilder)20 PrestoException (io.prestosql.spi.PrestoException)12 SingleMapBlock (io.prestosql.spi.block.SingleMapBlock)10 JsonParser (com.fasterxml.jackson.core.JsonParser)5 JsonCastException (io.prestosql.util.JsonCastException)5 JsonUtil.createJsonParser (io.prestosql.util.JsonUtil.createJsonParser)5 PageBuilder (io.prestosql.spi.PageBuilder)4 Block (io.prestosql.spi.block.Block)4 IOException (java.io.IOException)4 Slice (io.airlift.slice.Slice)3 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)2 DynamicSliceOutput (io.airlift.slice.DynamicSliceOutput)2 SliceOutput (io.airlift.slice.SliceOutput)2 TypedSet (io.prestosql.operator.aggregation.TypedSet)2 Type (io.prestosql.spi.type.Type)2 JsonUtil.createJsonGenerator (io.prestosql.util.JsonUtil.createJsonGenerator)2 BigDecimal (java.math.BigDecimal)2 Slices.utf8Slice (io.airlift.slice.Slices.utf8Slice)1 QueryState (io.prestosql.execution.QueryState)1