Search in sources :

Example 6 with BuiltInFunctionInfo

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);
        }
    }
}
Also used : TypeMismatchException(org.apache.phoenix.schema.TypeMismatchException) SQLException(java.sql.SQLException) BuiltInFunctionInfo(org.apache.phoenix.parse.FunctionParseNode.BuiltInFunctionInfo)

Example 7 with BuiltInFunctionInfo

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;
}
Also used : BuiltInFunctionInfo(org.apache.phoenix.parse.FunctionParseNode.BuiltInFunctionInfo)

Example 8 with BuiltInFunctionInfo

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;
}
Also used : UDFParseNode(org.apache.phoenix.parse.UDFParseNode) ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) PFunction(org.apache.phoenix.parse.PFunction) DecimalAddExpression(org.apache.phoenix.expression.DecimalAddExpression) TimestampSubtractExpression(org.apache.phoenix.expression.TimestampSubtractExpression) ArrayConstructorExpression(org.apache.phoenix.expression.ArrayConstructorExpression) Expression(org.apache.phoenix.expression.Expression) LikeExpression(org.apache.phoenix.expression.LikeExpression) ByteBasedLikeExpression(org.apache.phoenix.expression.ByteBasedLikeExpression) DoubleSubtractExpression(org.apache.phoenix.expression.DoubleSubtractExpression) LiteralExpression(org.apache.phoenix.expression.LiteralExpression) InListExpression(org.apache.phoenix.expression.InListExpression) DateSubtractExpression(org.apache.phoenix.expression.DateSubtractExpression) ArrayElemRefExpression(org.apache.phoenix.expression.function.ArrayElemRefExpression) CaseExpression(org.apache.phoenix.expression.CaseExpression) DoubleDivideExpression(org.apache.phoenix.expression.DoubleDivideExpression) NotExpression(org.apache.phoenix.expression.NotExpression) DoubleAddExpression(org.apache.phoenix.expression.DoubleAddExpression) DecimalDivideExpression(org.apache.phoenix.expression.DecimalDivideExpression) RowKeyColumnExpression(org.apache.phoenix.expression.RowKeyColumnExpression) RowValueConstructorExpression(org.apache.phoenix.expression.RowValueConstructorExpression) RoundTimestampExpression(org.apache.phoenix.expression.function.RoundTimestampExpression) StringConcatExpression(org.apache.phoenix.expression.StringConcatExpression) ComparisonExpression(org.apache.phoenix.expression.ComparisonExpression) TimestampAddExpression(org.apache.phoenix.expression.TimestampAddExpression) CoerceExpression(org.apache.phoenix.expression.CoerceExpression) StringBasedLikeExpression(org.apache.phoenix.expression.StringBasedLikeExpression) ArrayAnyComparisonExpression(org.apache.phoenix.expression.function.ArrayAnyComparisonExpression) DecimalSubtractExpression(org.apache.phoenix.expression.DecimalSubtractExpression) ModulusExpression(org.apache.phoenix.expression.ModulusExpression) DoubleMultiplyExpression(org.apache.phoenix.expression.DoubleMultiplyExpression) DecimalMultiplyExpression(org.apache.phoenix.expression.DecimalMultiplyExpression) DateAddExpression(org.apache.phoenix.expression.DateAddExpression) RoundDecimalExpression(org.apache.phoenix.expression.function.RoundDecimalExpression) LongAddExpression(org.apache.phoenix.expression.LongAddExpression) LongSubtractExpression(org.apache.phoenix.expression.LongSubtractExpression) IsNullExpression(org.apache.phoenix.expression.IsNullExpression) AndExpression(org.apache.phoenix.expression.AndExpression) LongMultiplyExpression(org.apache.phoenix.expression.LongMultiplyExpression) ArrayAllComparisonExpression(org.apache.phoenix.expression.function.ArrayAllComparisonExpression) OrExpression(org.apache.phoenix.expression.OrExpression) LongDivideExpression(org.apache.phoenix.expression.LongDivideExpression) BuiltInFunctionInfo(org.apache.phoenix.parse.FunctionParseNode.BuiltInFunctionInfo)

Aggregations

BuiltInFunctionInfo (org.apache.phoenix.parse.FunctionParseNode.BuiltInFunctionInfo)8 Test (org.junit.Test)3 SQLException (java.sql.SQLException)2 ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)1 AndExpression (org.apache.phoenix.expression.AndExpression)1 ArrayConstructorExpression (org.apache.phoenix.expression.ArrayConstructorExpression)1 ByteBasedLikeExpression (org.apache.phoenix.expression.ByteBasedLikeExpression)1 CaseExpression (org.apache.phoenix.expression.CaseExpression)1 CoerceExpression (org.apache.phoenix.expression.CoerceExpression)1 ComparisonExpression (org.apache.phoenix.expression.ComparisonExpression)1 DateAddExpression (org.apache.phoenix.expression.DateAddExpression)1 DateSubtractExpression (org.apache.phoenix.expression.DateSubtractExpression)1 DecimalAddExpression (org.apache.phoenix.expression.DecimalAddExpression)1 DecimalDivideExpression (org.apache.phoenix.expression.DecimalDivideExpression)1 DecimalMultiplyExpression (org.apache.phoenix.expression.DecimalMultiplyExpression)1 DecimalSubtractExpression (org.apache.phoenix.expression.DecimalSubtractExpression)1 DoubleAddExpression (org.apache.phoenix.expression.DoubleAddExpression)1 DoubleDivideExpression (org.apache.phoenix.expression.DoubleDivideExpression)1 DoubleMultiplyExpression (org.apache.phoenix.expression.DoubleMultiplyExpression)1 DoubleSubtractExpression (org.apache.phoenix.expression.DoubleSubtractExpression)1