Search in sources :

Example 1 with FunctionExpression

use of com.alibaba.cobar.parser.ast.expression.primary.function.FunctionExpression in project cobar by alibaba.

the class MySQLFunctionManager method createFunctionExpression.

/**
 * @return null if
 */
public FunctionExpression createFunctionExpression(String funcNameUpcase, List<Expression> arguments) {
    FunctionExpression prototype = functionPrototype.get(funcNameUpcase);
    if (prototype == null)
        return null;
    FunctionExpression func = prototype.constructFunction(arguments);
    func.init();
    return func;
}
Also used : FunctionExpression(com.alibaba.cobar.parser.ast.expression.primary.function.FunctionExpression)

Example 2 with FunctionExpression

use of com.alibaba.cobar.parser.ast.expression.primary.function.FunctionExpression in project cobar by alibaba.

the class MySQLFunctionManager method addExtendFunction.

/**
 * @param extFuncPrototypeMap funcName -&gt; extFunctionPrototype. funcName
 *            MUST NOT be the same as predefined function of MySQL 5.5
 * @throws IllegalArgumentException
 */
public synchronized void addExtendFunction(Map<String, FunctionExpression> extFuncPrototypeMap) {
    if (extFuncPrototypeMap == null || extFuncPrototypeMap.isEmpty()) {
        return;
    }
    if (!allowFuncDefChange) {
        throw new UnsupportedOperationException("function define is not allowed to be changed");
    }
    Map<String, FunctionExpression> toPut = new HashMap<String, FunctionExpression>();
    // check extFuncPrototypeMap
    for (Entry<String, FunctionExpression> en : extFuncPrototypeMap.entrySet()) {
        String funcName = en.getKey();
        if (funcName == null)
            continue;
        String funcNameUp = funcName.toUpperCase();
        if (functionPrototype.containsKey(funcNameUp)) {
            throw new IllegalArgumentException("ext-function '" + funcName + "' is MySQL's predefined function!");
        }
        FunctionExpression func = en.getValue();
        if (func == null) {
            throw new IllegalArgumentException("ext-function '" + funcName + "' is null!");
        }
        toPut.put(funcNameUp, func);
    }
    functionPrototype.putAll(toPut);
}
Also used : FunctionExpression(com.alibaba.cobar.parser.ast.expression.primary.function.FunctionExpression) HashMap(java.util.HashMap)

Example 3 with FunctionExpression

use of com.alibaba.cobar.parser.ast.expression.primary.function.FunctionExpression in project cobar by alibaba.

the class MySQLExprParser method ordinaryFunction.

/**
 * id has been consumed. id must be a function name. current token must be
 * {@link MySQLToken#PUNC_LEFT_PAREN}
 *
 * @param idUpper must be name of a function
 * @return never null
 */
private FunctionExpression ordinaryFunction(String id, String idUpper) throws SQLSyntaxErrorException {
    idUpper = Identifier.unescapeName(idUpper);
    match(PUNC_LEFT_PAREN);
    FunctionExpression funcExpr;
    if (lexer.token() == PUNC_RIGHT_PAREN) {
        lexer.nextToken();
        funcExpr = functionManager.createFunctionExpression(idUpper, null);
    } else {
        List<Expression> args = expressionList(new LinkedList<Expression>());
        funcExpr = functionManager.createFunctionExpression(idUpper, args);
    }
    if (funcExpr == null) {
        throw new SQLSyntaxErrorException(id + "() is not a function");
    }
    funcExpr.setCacheEvalRst(cacheEvalRst);
    return funcExpr;
}
Also used : FunctionExpression(com.alibaba.cobar.parser.ast.expression.primary.function.FunctionExpression) SubqueryAllExpression(com.alibaba.cobar.parser.ast.expression.misc.SubqueryAllExpression) MinusExpression(com.alibaba.cobar.parser.ast.expression.arithmeic.MinusExpression) BetweenAndExpression(com.alibaba.cobar.parser.ast.expression.comparison.BetweenAndExpression) BitAndExpression(com.alibaba.cobar.parser.ast.expression.bit.BitAndExpression) ComparisionEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionEqualsExpression) NegativeValueExpression(com.alibaba.cobar.parser.ast.expression.logical.NegativeValueExpression) QueryExpression(com.alibaba.cobar.parser.ast.expression.misc.QueryExpression) CastBinaryExpression(com.alibaba.cobar.parser.ast.expression.type.CastBinaryExpression) InExpression(com.alibaba.cobar.parser.ast.expression.comparison.InExpression) BitInvertExpression(com.alibaba.cobar.parser.ast.expression.bit.BitInvertExpression) BitXORExpression(com.alibaba.cobar.parser.ast.expression.bit.BitXORExpression) FunctionExpression(com.alibaba.cobar.parser.ast.expression.primary.function.FunctionExpression) BitShiftExpression(com.alibaba.cobar.parser.ast.expression.bit.BitShiftExpression) BitOrExpression(com.alibaba.cobar.parser.ast.expression.bit.BitOrExpression) ComparisionGreaterThanOrEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionGreaterThanOrEqualsExpression) MatchExpression(com.alibaba.cobar.parser.ast.expression.primary.MatchExpression) ComparisionIsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionIsExpression) LogicalOrExpression(com.alibaba.cobar.parser.ast.expression.logical.LogicalOrExpression) ComparisionGreaterThanExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionGreaterThanExpression) ComparisionLessOrGreaterThanExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionLessOrGreaterThanExpression) SubqueryAnyExpression(com.alibaba.cobar.parser.ast.expression.misc.SubqueryAnyExpression) RegexpExpression(com.alibaba.cobar.parser.ast.expression.string.RegexpExpression) LogicalAndExpression(com.alibaba.cobar.parser.ast.expression.logical.LogicalAndExpression) ArithmeticMultiplyExpression(com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticMultiplyExpression) ComparisionLessThanOrEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionLessThanOrEqualsExpression) ComparisionNullSafeEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionNullSafeEqualsExpression) LikeExpression(com.alibaba.cobar.parser.ast.expression.string.LikeExpression) ArithmeticSubtractExpression(com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticSubtractExpression) SoundsLikeExpression(com.alibaba.cobar.parser.ast.expression.string.SoundsLikeExpression) ArithmeticIntegerDivideExpression(com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticIntegerDivideExpression) CollateExpression(com.alibaba.cobar.parser.ast.expression.type.CollateExpression) LogicalNotExpression(com.alibaba.cobar.parser.ast.expression.logical.LogicalNotExpression) Expression(com.alibaba.cobar.parser.ast.expression.Expression) AssignmentExpression(com.alibaba.cobar.parser.ast.expression.misc.AssignmentExpression) CaseWhenOperatorExpression(com.alibaba.cobar.parser.ast.expression.primary.CaseWhenOperatorExpression) LogicalXORExpression(com.alibaba.cobar.parser.ast.expression.logical.LogicalXORExpression) UserExpression(com.alibaba.cobar.parser.ast.expression.misc.UserExpression) ArithmeticAddExpression(com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticAddExpression) ComparisionNotEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionNotEqualsExpression) RowExpression(com.alibaba.cobar.parser.ast.expression.primary.RowExpression) ComparisionLessThanExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionLessThanExpression) ArithmeticModExpression(com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticModExpression) ArithmeticDivideExpression(com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticDivideExpression) SQLSyntaxErrorException(java.sql.SQLSyntaxErrorException)

Example 4 with FunctionExpression

use of com.alibaba.cobar.parser.ast.expression.primary.function.FunctionExpression in project cobar by alibaba.

the class PartitionByFileMap method constructFunction.

@Override
public FunctionExpression constructFunction(List<Expression> arguments) {
    if (arguments == null || arguments.size() != 1)
        throw new IllegalArgumentException("function " + getFunctionName() + " must have 1 arguments but is " + arguments);
    Object[] args = new Object[arguments.size()];
    int i = -1;
    for (Expression arg : arguments) {
        args[++i] = arg;
    }
    return (FunctionExpression) constructMe(args);
}
Also used : FunctionExpression(com.alibaba.cobar.parser.ast.expression.primary.function.FunctionExpression) FunctionExpression(com.alibaba.cobar.parser.ast.expression.primary.function.FunctionExpression) Expression(com.alibaba.cobar.parser.ast.expression.Expression)

Example 5 with FunctionExpression

use of com.alibaba.cobar.parser.ast.expression.primary.function.FunctionExpression in project cobar by alibaba.

the class PartitionByLong method constructFunction.

@Override
public FunctionExpression constructFunction(List<Expression> arguments) {
    if (arguments == null || arguments.size() != 1)
        throw new IllegalArgumentException("function " + getFunctionName() + " must have 1 argument but is " + arguments);
    Object[] args = new Object[arguments.size()];
    int i = -1;
    for (Expression arg : arguments) {
        args[++i] = arg;
    }
    return (FunctionExpression) constructMe(args);
}
Also used : FunctionExpression(com.alibaba.cobar.parser.ast.expression.primary.function.FunctionExpression) FunctionExpression(com.alibaba.cobar.parser.ast.expression.primary.function.FunctionExpression) Expression(com.alibaba.cobar.parser.ast.expression.Expression)

Aggregations

FunctionExpression (com.alibaba.cobar.parser.ast.expression.primary.function.FunctionExpression)7 Expression (com.alibaba.cobar.parser.ast.expression.Expression)5 ArithmeticAddExpression (com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticAddExpression)1 ArithmeticDivideExpression (com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticDivideExpression)1 ArithmeticIntegerDivideExpression (com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticIntegerDivideExpression)1 ArithmeticModExpression (com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticModExpression)1 ArithmeticMultiplyExpression (com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticMultiplyExpression)1 ArithmeticSubtractExpression (com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticSubtractExpression)1 MinusExpression (com.alibaba.cobar.parser.ast.expression.arithmeic.MinusExpression)1 BitAndExpression (com.alibaba.cobar.parser.ast.expression.bit.BitAndExpression)1 BitInvertExpression (com.alibaba.cobar.parser.ast.expression.bit.BitInvertExpression)1 BitOrExpression (com.alibaba.cobar.parser.ast.expression.bit.BitOrExpression)1 BitShiftExpression (com.alibaba.cobar.parser.ast.expression.bit.BitShiftExpression)1 BitXORExpression (com.alibaba.cobar.parser.ast.expression.bit.BitXORExpression)1 BetweenAndExpression (com.alibaba.cobar.parser.ast.expression.comparison.BetweenAndExpression)1 ComparisionEqualsExpression (com.alibaba.cobar.parser.ast.expression.comparison.ComparisionEqualsExpression)1 ComparisionGreaterThanExpression (com.alibaba.cobar.parser.ast.expression.comparison.ComparisionGreaterThanExpression)1 ComparisionGreaterThanOrEqualsExpression (com.alibaba.cobar.parser.ast.expression.comparison.ComparisionGreaterThanOrEqualsExpression)1 ComparisionIsExpression (com.alibaba.cobar.parser.ast.expression.comparison.ComparisionIsExpression)1 ComparisionLessOrGreaterThanExpression (com.alibaba.cobar.parser.ast.expression.comparison.ComparisionLessOrGreaterThanExpression)1