* @param node a function expression node
* @param children the child expression arguments to the function expression node.
*/
public Expression visitLeave(FunctionParseNode node, List<Expression> children) throws SQLException {
children = node.validate(children, context);
FunctionExpression func = node.create(children, context);
if (node.isConstant()) {
ImmutableBytesWritable ptr = context.getTempPtr();
Object value = null;
PDataType type = func.getDataType();
if (func.evaluate(null, ptr)) {
value = type.toObject(ptr);
}
return LiteralExpression.newConstant(value, type);
}
BuiltInFunctionInfo info = node.getInfo();
for (int i = 0; i < info.getRequiredArgCount(); i++) {
// Optimization to catch cases where a required argument is null resulting in the function
// returning null. We have to wait until after we create the function expression so that
// we can get the proper type to use.
if (node.evalToNullIfParamIsNull(context, i)) {
Expression child = children.get(i);
if (child instanceof LiteralExpression
&& ((LiteralExpression)child).getValue() == null) {
return LiteralExpression.newConstant(null, func.getDataType());
}
}
}
Expression expression = addFunction(func);
expression = wrapGroupByExpression(expression);