Search in sources :

Example 1 with InterpretedFunctionInvoker

use of io.prestosql.sql.InterpretedFunctionInvoker in project hetu-core by openlookeng.

the class ValuePrinter method castToVarcharOrFail.

public String castToVarcharOrFail(Type type, Object value) throws OperatorNotFoundException {
    if (value == null) {
        return "NULL";
    }
    FunctionHandle coercion = metadata.getFunctionAndTypeManager().lookupCast(CAST, type.getTypeSignature(), VARCHAR.getTypeSignature());
    Slice coerced = (Slice) new InterpretedFunctionInvoker(metadata.getFunctionAndTypeManager()).invoke(coercion, session.toConnectorSession(), value);
    return coerced.toStringUtf8();
}
Also used : InterpretedFunctionInvoker(io.prestosql.sql.InterpretedFunctionInvoker) Slice(io.airlift.slice.Slice) FunctionHandle(io.prestosql.spi.function.FunctionHandle)

Example 2 with InterpretedFunctionInvoker

use of io.prestosql.sql.InterpretedFunctionInvoker in project hetu-core by openlookeng.

the class StatsUtil method toStatsRepresentation.

static OptionalDouble toStatsRepresentation(Metadata metadata, ConnectorSession session, Type type, Object value) {
    if (convertibleToDoubleWithCast(type)) {
        InterpretedFunctionInvoker functionInvoker = new InterpretedFunctionInvoker(metadata.getFunctionAndTypeManager());
        FunctionHandle cast = metadata.getFunctionAndTypeManager().lookupCast(CAST, type.getTypeSignature(), DoubleType.DOUBLE.getTypeSignature());
        return OptionalDouble.of((double) functionInvoker.invoke(cast, session, singletonList(value)));
    }
    if (DateType.DATE.equals(type)) {
        return OptionalDouble.of(((Long) value).doubleValue());
    }
    return OptionalDouble.empty();
}
Also used : InterpretedFunctionInvoker(io.prestosql.sql.InterpretedFunctionInvoker) FunctionHandle(io.prestosql.spi.function.FunctionHandle)

Aggregations

FunctionHandle (io.prestosql.spi.function.FunctionHandle)2 InterpretedFunctionInvoker (io.prestosql.sql.InterpretedFunctionInvoker)2 Slice (io.airlift.slice.Slice)1