public TPreptimeValue evaluateConstant(QueryContext context) {
List<TPreptimeValue> values = new ArrayList<>(inputs.size());
boolean allConstant = true, anyNull = false;
ValueSource constantSource = null;
for (TPreparedExpression input : inputs) {
TPreptimeValue value = input.evaluateConstant(context);
values.add(value);
if (value.value() == null) {
allConstant = false;
}
else if (value.value().isNull()) {
anyNull = true;
}
if (allConstant && routine.isDeterministic()) {
ValueRoutineInvocation invocation = new TPreptimeValueRoutineInvocation(routine, values);
ServerJavaRoutine javaRoutine = javaRoutine((ServerQueryContext)context, null, invocation);
evaluate(javaRoutine);
constantSource = invocation.getReturnValue();
}
if (anyNull && !routine.isCalledOnNullInput()) {
constantSource = ValueSources.getNullSource(resultType());
}
}
return new TPreptimeValue(resultType(), constantSource);
}