Search in sources :

Example 1 with UsedByGeneratedCode

use of io.trino.annotation.UsedByGeneratedCode in project trino by trinodb.

the class KillQueryProcedure method killQuery.

@UsedByGeneratedCode
public void killQuery(String queryId, String message, ConnectorSession session) {
    QueryId query = parseQueryId(queryId);
    try {
        checkState(dispatchManager.isPresent(), "No dispatch manager is set. kill_query procedure should be executed on coordinator.");
        DispatchQuery dispatchQuery = dispatchManager.get().getQuery(query);
        checkCanKillQueryOwnedBy(((FullConnectorSession) session).getSession().getIdentity(), dispatchQuery.getSession().getIdentity(), accessControl);
        // check before killing to provide the proper error message (this is racy)
        if (dispatchQuery.isDone()) {
            throw new TrinoException(NOT_SUPPORTED, "Target query is not running: " + queryId);
        }
        dispatchQuery.fail(createKillQueryException(message));
        // verify if the query was killed (if not, we lost the race)
        checkState(dispatchQuery.isDone(), "Failure to fail the query: %s", query);
        if (!ADMINISTRATIVELY_KILLED.toErrorCode().equals(dispatchQuery.getErrorCode().orElse(null))) {
            throw new TrinoException(NOT_SUPPORTED, "Target query is not running: " + queryId);
        }
    } catch (NoSuchElementException e) {
        throw new TrinoException(NOT_FOUND, "Target query not found: " + queryId);
    }
}
Also used : DispatchQuery(io.trino.dispatcher.DispatchQuery) QueryId(io.trino.spi.QueryId) TrinoException(io.trino.spi.TrinoException) NoSuchElementException(java.util.NoSuchElementException) FullConnectorSession(io.trino.FullConnectorSession) UsedByGeneratedCode(io.trino.annotation.UsedByGeneratedCode)

Example 2 with UsedByGeneratedCode

use of io.trino.annotation.UsedByGeneratedCode in project trino by trinodb.

the class ArrayConcatFunction method concat.

@UsedByGeneratedCode
public static Block concat(Type elementType, Object state, Block[] blocks) {
    int resultPositionCount = 0;
    // fast path when there is at most one non empty block
    Block nonEmptyBlock = null;
    for (int i = 0; i < blocks.length; i++) {
        resultPositionCount += blocks[i].getPositionCount();
        if (blocks[i].getPositionCount() > 0) {
            nonEmptyBlock = blocks[i];
        }
    }
    if (nonEmptyBlock == null) {
        return blocks[0];
    }
    if (resultPositionCount == nonEmptyBlock.getPositionCount()) {
        return nonEmptyBlock;
    }
    PageBuilder pageBuilder = (PageBuilder) state;
    if (pageBuilder.isFull()) {
        pageBuilder.reset();
    }
    BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(0);
    for (int blockIndex = 0; blockIndex < blocks.length; blockIndex++) {
        Block block = blocks[blockIndex];
        for (int i = 0; i < block.getPositionCount(); i++) {
            elementType.appendTo(block, i, blockBuilder);
        }
    }
    pageBuilder.declarePositions(resultPositionCount);
    return blockBuilder.getRegion(blockBuilder.getPositionCount() - resultPositionCount, resultPositionCount);
}
Also used : Block(io.trino.spi.block.Block) PageBuilder(io.trino.spi.PageBuilder) BlockBuilder(io.trino.spi.block.BlockBuilder) UsedByGeneratedCode(io.trino.annotation.UsedByGeneratedCode)

Example 3 with UsedByGeneratedCode

use of io.trino.annotation.UsedByGeneratedCode in project trino by trinodb.

the class ArrayConcatUtils method appendElement.

@UsedByGeneratedCode
public static Block appendElement(Type elementType, Block block, Object value) {
    BlockBuilder blockBuilder = elementType.createBlockBuilder(null, block.getPositionCount() + 1);
    for (int i = 0; i < block.getPositionCount(); i++) {
        elementType.appendTo(block, i, blockBuilder);
    }
    elementType.writeObject(blockBuilder, value);
    return blockBuilder.build();
}
Also used : BlockBuilder(io.trino.spi.block.BlockBuilder) UsedByGeneratedCode(io.trino.annotation.UsedByGeneratedCode)

Example 4 with UsedByGeneratedCode

use of io.trino.annotation.UsedByGeneratedCode in project trino by trinodb.

the class ArrayConcatUtils method appendElement.

@UsedByGeneratedCode
public static Block appendElement(Type elementType, Block block, boolean value) {
    BlockBuilder blockBuilder = elementType.createBlockBuilder(null, block.getPositionCount() + 1);
    for (int i = 0; i < block.getPositionCount(); i++) {
        elementType.appendTo(block, i, blockBuilder);
    }
    elementType.writeBoolean(blockBuilder, value);
    return blockBuilder.build();
}
Also used : BlockBuilder(io.trino.spi.block.BlockBuilder) UsedByGeneratedCode(io.trino.annotation.UsedByGeneratedCode)

Example 5 with UsedByGeneratedCode

use of io.trino.annotation.UsedByGeneratedCode in project trino by trinodb.

the class ArrayConcatUtils method prependElement.

// Usage of prependElement: ElementToArrayConcatFunction
@UsedByGeneratedCode
public static Block prependElement(Type elementType, Slice value, Block block) {
    BlockBuilder blockBuilder = elementType.createBlockBuilder(null, block.getPositionCount() + 1);
    elementType.writeSlice(blockBuilder, value);
    for (int i = 0; i < block.getPositionCount(); i++) {
        elementType.appendTo(block, i, blockBuilder);
    }
    return blockBuilder.build();
}
Also used : BlockBuilder(io.trino.spi.block.BlockBuilder) UsedByGeneratedCode(io.trino.annotation.UsedByGeneratedCode)

Aggregations

UsedByGeneratedCode (io.trino.annotation.UsedByGeneratedCode)35 BlockBuilder (io.trino.spi.block.BlockBuilder)19 TrinoException (io.trino.spi.TrinoException)11 SingleMapBlock (io.trino.spi.block.SingleMapBlock)8 JsonParser (com.fasterxml.jackson.core.JsonParser)5 JsonCastException (io.trino.util.JsonCastException)5 JsonUtil.createJsonParser (io.trino.util.JsonUtil.createJsonParser)5 IOException (java.io.IOException)5 PageBuilder (io.trino.spi.PageBuilder)4 Block (io.trino.spi.block.Block)4 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)3 DynamicSliceOutput (io.airlift.slice.DynamicSliceOutput)3 SliceOutput (io.airlift.slice.SliceOutput)3 JsonUtil.createJsonGenerator (io.trino.util.JsonUtil.createJsonGenerator)3 TypeVariableConstraint (io.trino.metadata.TypeVariableConstraint)2 TypedSet (io.trino.operator.aggregation.TypedSet)2 TypedSet.createEqualityTypedSet (io.trino.operator.aggregation.TypedSet.createEqualityTypedSet)2 MapType (io.trino.spi.type.MapType)2 Type (io.trino.spi.type.Type)2 TypeSignature.mapType (io.trino.spi.type.TypeSignature.mapType)2