Search in sources :

Example 1 with BlockBuilderAppender

use of io.trino.util.JsonUtil.BlockBuilderAppender in project trino by trinodb.

the class JsonToArrayCast method specialize.

@Override
protected ScalarFunctionImplementation specialize(BoundSignature boundSignature) {
    checkArgument(boundSignature.getArity() == 1, "Expected arity to be 1");
    ArrayType arrayType = (ArrayType) boundSignature.getReturnType();
    checkCondition(canCastFromJson(arrayType), INVALID_CAST_ARGUMENT, "Cannot cast JSON to %s", arrayType);
    BlockBuilderAppender arrayAppender = BlockBuilderAppender.createBlockBuilderAppender(arrayType);
    MethodHandle methodHandle = METHOD_HANDLE.bindTo(arrayType).bindTo(arrayAppender);
    return new ChoicesScalarFunctionImplementation(boundSignature, NULLABLE_RETURN, ImmutableList.of(NEVER_NULL), methodHandle);
}
Also used : ArrayType(io.trino.spi.type.ArrayType) BlockBuilderAppender(io.trino.util.JsonUtil.BlockBuilderAppender) MethodHandle(java.lang.invoke.MethodHandle)

Example 2 with BlockBuilderAppender

use of io.trino.util.JsonUtil.BlockBuilderAppender in project trino by trinodb.

the class JsonToMapCast method specialize.

@Override
protected ScalarFunctionImplementation specialize(BoundSignature boundSignature) {
    checkArgument(boundSignature.getArity() == 1, "Expected arity to be 1");
    MapType mapType = (MapType) boundSignature.getReturnType();
    checkCondition(canCastFromJson(mapType), INVALID_CAST_ARGUMENT, "Cannot cast JSON to %s", mapType);
    BlockBuilderAppender mapAppender = createBlockBuilderAppender(mapType);
    MethodHandle methodHandle = METHOD_HANDLE.bindTo(mapType).bindTo(mapAppender);
    return new ChoicesScalarFunctionImplementation(boundSignature, NULLABLE_RETURN, ImmutableList.of(NEVER_NULL), methodHandle);
}
Also used : BlockBuilderAppender.createBlockBuilderAppender(io.trino.util.JsonUtil.BlockBuilderAppender.createBlockBuilderAppender) BlockBuilderAppender(io.trino.util.JsonUtil.BlockBuilderAppender) MapType(io.trino.spi.type.MapType) MethodHandle(java.lang.invoke.MethodHandle)

Example 3 with BlockBuilderAppender

use of io.trino.util.JsonUtil.BlockBuilderAppender in project trino by trinodb.

the class JsonToRowCast method specialize.

@Override
protected ScalarFunctionImplementation specialize(BoundSignature boundSignature) {
    RowType rowType = (RowType) boundSignature.getReturnType();
    checkCondition(canCastFromJson(rowType), INVALID_CAST_ARGUMENT, "Cannot cast JSON to %s", rowType);
    BlockBuilderAppender fieldAppender = createBlockBuilderAppender(rowType);
    MethodHandle methodHandle = METHOD_HANDLE.bindTo(rowType).bindTo(fieldAppender);
    return new ChoicesScalarFunctionImplementation(boundSignature, NULLABLE_RETURN, ImmutableList.of(NEVER_NULL), methodHandle);
}
Also used : BlockBuilderAppender.createBlockBuilderAppender(io.trino.util.JsonUtil.BlockBuilderAppender.createBlockBuilderAppender) BlockBuilderAppender(io.trino.util.JsonUtil.BlockBuilderAppender) RowType(io.trino.spi.type.RowType) MethodHandle(java.lang.invoke.MethodHandle)

Aggregations

BlockBuilderAppender (io.trino.util.JsonUtil.BlockBuilderAppender)3 MethodHandle (java.lang.invoke.MethodHandle)3 BlockBuilderAppender.createBlockBuilderAppender (io.trino.util.JsonUtil.BlockBuilderAppender.createBlockBuilderAppender)2 ArrayType (io.trino.spi.type.ArrayType)1 MapType (io.trino.spi.type.MapType)1 RowType (io.trino.spi.type.RowType)1