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;
}
use of com.alibaba.cobar.parser.ast.expression.primary.function.FunctionExpression in project cobar by alibaba.
the class MySQLFunctionManager method addExtendFunction.
/**
* @param extFuncPrototypeMap funcName -> 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);
}
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;
}
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);
}
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);
}
Aggregations