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