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>";
}
}
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();
}
Aggregations