Search in sources :

Example 1 with MethodHandleAndConstructor

use of io.trino.sql.gen.VarArgsToArrayAdapterGenerator.MethodHandleAndConstructor in project trino by trinodb.

the class MapConcatFunction method specialize.

@Override
protected ScalarFunctionImplementation specialize(BoundSignature boundSignature) {
    if (boundSignature.getArity() < 2) {
        throw new TrinoException(INVALID_FUNCTION_ARGUMENT, "There must be two or more concatenation arguments to " + FUNCTION_NAME);
    }
    MapType mapType = (MapType) boundSignature.getReturnType();
    Type keyType = mapType.getKeyType();
    BlockPositionEqual keyEqual = blockTypeOperators.getEqualOperator(keyType);
    BlockPositionHashCode keyHashCode = blockTypeOperators.getHashCodeOperator(keyType);
    MethodHandleAndConstructor methodHandleAndConstructor = generateVarArgsToArrayAdapter(Block.class, Block.class, boundSignature.getArity(), MethodHandles.insertArguments(METHOD_HANDLE, 0, mapType, keyEqual, keyHashCode), USER_STATE_FACTORY.bindTo(mapType));
    return new ChoicesScalarFunctionImplementation(boundSignature, FAIL_ON_NULL, nCopies(boundSignature.getArity(), NEVER_NULL), methodHandleAndConstructor.getMethodHandle(), Optional.of(methodHandleAndConstructor.getConstructor()));
}
Also used : BlockPositionEqual(io.trino.type.BlockTypeOperators.BlockPositionEqual) Type(io.trino.spi.type.Type) MapType(io.trino.spi.type.MapType) TypeSignature.mapType(io.trino.spi.type.TypeSignature.mapType) MethodHandleAndConstructor(io.trino.sql.gen.VarArgsToArrayAdapterGenerator.MethodHandleAndConstructor) TrinoException(io.trino.spi.TrinoException) BlockPositionHashCode(io.trino.type.BlockTypeOperators.BlockPositionHashCode) MapType(io.trino.spi.type.MapType)

Aggregations

TrinoException (io.trino.spi.TrinoException)1 MapType (io.trino.spi.type.MapType)1 Type (io.trino.spi.type.Type)1 TypeSignature.mapType (io.trino.spi.type.TypeSignature.mapType)1 MethodHandleAndConstructor (io.trino.sql.gen.VarArgsToArrayAdapterGenerator.MethodHandleAndConstructor)1 BlockPositionEqual (io.trino.type.BlockTypeOperators.BlockPositionEqual)1 BlockPositionHashCode (io.trino.type.BlockTypeOperators.BlockPositionHashCode)1