use of org.apache.phoenix.parse.FunctionParseNode.BuiltInFunctionInfo in project phoenix by apache.
the class ParseNodeFactory method function.
public FunctionParseNode function(String name, List<ParseNode> args) {
BuiltInFunctionInfo info = getInfo(name, args);
if (info == null) {
return new UDFParseNode(name, args, info);
}
Constructor<? extends FunctionParseNode> ctor = info.getNodeCtor();
if (ctor == null) {
return info.isAggregate() ? new AggregateFunctionParseNode(name, args, info) : new FunctionParseNode(name, args, info);
} else {
try {
return ctor.newInstance(name, args, info);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
use of org.apache.phoenix.parse.FunctionParseNode.BuiltInFunctionInfo in project phoenix by apache.
the class ParseNodeFactory method get.
public static BuiltInFunctionInfo get(String normalizedName, List<ParseNode> children) {
initBuiltInFunctionMap();
BuiltInFunctionInfo info = BUILT_IN_FUNCTION_MAP.get(new BuiltInFunctionKey(normalizedName, children.size()));
return info;
}
use of org.apache.phoenix.parse.FunctionParseNode.BuiltInFunctionInfo in project phoenix by apache.
the class ExpressionCompiler method visitLeave.
@Override
public /**
* @param node a function expression node
* @param children the child expression arguments to the function expression node.
*/
Expression visitLeave(FunctionParseNode node, List<Expression> children) throws SQLException {
PFunction function = null;
if (node instanceof UDFParseNode) {
function = context.getResolver().resolveFunction(node.getName());
BuiltInFunctionInfo info = new BuiltInFunctionInfo(function);
node = new UDFParseNode(node.getName(), node.getChildren(), info);
}
children = node.validate(children, context);
Expression expression = null;
if (function == null) {
expression = node.create(children, context);
} else {
expression = node.create(children, function, context);
}
ImmutableBytesWritable ptr = context.getTempPtr();
BuiltInFunctionInfo info = node.getInfo();
for (int i = 0; i < info.getRequiredArgCount(); i++) {
// we can get the proper type to use.
if (node.evalToNullIfParamIsNull(context, i)) {
Expression child = children.get(i);
if (ExpressionUtil.isNull(child, ptr)) {
return ExpressionUtil.getNullExpression(expression);
}
}
}
if (ExpressionUtil.isConstant(expression)) {
return ExpressionUtil.getConstantExpression(expression, ptr);
}
expression = addExpression(expression);
expression = wrapGroupByExpression(expression);
if (aggregateFunction == node) {
// Turn back off on the way out
aggregateFunction = null;
}
return expression;
}
Aggregations