Search in sources :

Example 1 with ObjectKeyProvider

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

the class MapToJsonCast method specialize.

@Override
public ScalarFunctionImplementation specialize(BoundSignature boundSignature) {
    MapType mapType = (MapType) boundSignature.getArgumentType(0);
    Type keyType = mapType.getKeyType();
    Type valueType = mapType.getValueType();
    checkCondition(canCastToJson(mapType), INVALID_CAST_ARGUMENT, "Cannot cast %s to JSON", mapType);
    ObjectKeyProvider provider = ObjectKeyProvider.createObjectKeyProvider(keyType);
    JsonGeneratorWriter writer = JsonGeneratorWriter.createJsonGeneratorWriter(valueType, legacyRowToJson);
    MethodHandle methodHandle = METHOD_HANDLE.bindTo(provider).bindTo(writer);
    return new ChoicesScalarFunctionImplementation(boundSignature, FAIL_ON_NULL, ImmutableList.of(NEVER_NULL), methodHandle);
}
Also used : JsonGeneratorWriter(io.trino.util.JsonUtil.JsonGeneratorWriter) Type(io.trino.spi.type.Type) MapType(io.trino.spi.type.MapType) OperatorType(io.trino.spi.function.OperatorType) TypeSignature.mapType(io.trino.spi.type.TypeSignature.mapType) ObjectKeyProvider(io.trino.util.JsonUtil.ObjectKeyProvider) MapType(io.trino.spi.type.MapType) MethodHandle(java.lang.invoke.MethodHandle)

Aggregations

OperatorType (io.trino.spi.function.OperatorType)1 MapType (io.trino.spi.type.MapType)1 Type (io.trino.spi.type.Type)1 TypeSignature.mapType (io.trino.spi.type.TypeSignature.mapType)1 JsonGeneratorWriter (io.trino.util.JsonUtil.JsonGeneratorWriter)1 ObjectKeyProvider (io.trino.util.JsonUtil.ObjectKeyProvider)1 MethodHandle (java.lang.invoke.MethodHandle)1