Search in sources :

Example 1 with InterpretedFunctionInvoker

use of com.facebook.presto.sql.InterpretedFunctionInvoker in project presto by prestodb.

the class PlanPrinter method castToVarchar.

private static String castToVarchar(Type type, Object value, FunctionAndTypeManager functionAndTypeManager, Session session) {
    if (value == null) {
        return "NULL";
    }
    try {
        FunctionHandle cast = functionAndTypeManager.lookupCast(CAST, type.getTypeSignature(), VARCHAR.getTypeSignature());
        Slice coerced = (Slice) new InterpretedFunctionInvoker(functionAndTypeManager).invoke(cast, session.getSqlFunctionProperties(), value);
        return "\"" + coerced.toStringUtf8().replace("\"", "\\\"") + "\"";
    } catch (OperatorNotFoundException e) {
        return "<UNREPRESENTABLE VALUE>";
    }
}
Also used : InterpretedFunctionInvoker(com.facebook.presto.sql.InterpretedFunctionInvoker) OperatorNotFoundException(com.facebook.presto.metadata.OperatorNotFoundException) Slice(io.airlift.slice.Slice) FunctionHandle(com.facebook.presto.spi.function.FunctionHandle)

Example 2 with InterpretedFunctionInvoker

use of com.facebook.presto.sql.InterpretedFunctionInvoker in project presto by prestodb.

the class StatsUtil method toStatsRepresentation.

static OptionalDouble toStatsRepresentation(FunctionAndTypeManager functionAndTypeManager, ConnectorSession session, Type type, Object value) {
    requireNonNull(value, "value is null");
    if (convertibleToDoubleWithCast(type)) {
        InterpretedFunctionInvoker functionInvoker = new InterpretedFunctionInvoker(functionAndTypeManager);
        FunctionHandle cast = functionAndTypeManager.lookupCast(CAST, type.getTypeSignature(), DoubleType.DOUBLE.getTypeSignature());
        return OptionalDouble.of((double) functionInvoker.invoke(cast, session.getSqlFunctionProperties(), singletonList(value)));
    }
    if (DateType.DATE.equals(type)) {
        return OptionalDouble.of(((Long) value).doubleValue());
    }
    return OptionalDouble.empty();
}
Also used : InterpretedFunctionInvoker(com.facebook.presto.sql.InterpretedFunctionInvoker) FunctionHandle(com.facebook.presto.spi.function.FunctionHandle)

Aggregations

FunctionHandle (com.facebook.presto.spi.function.FunctionHandle)2 InterpretedFunctionInvoker (com.facebook.presto.sql.InterpretedFunctionInvoker)2 OperatorNotFoundException (com.facebook.presto.metadata.OperatorNotFoundException)1 Slice (io.airlift.slice.Slice)1