use of com.alibaba.cobar.parser.ast.expression.Expression 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.Expression in project cobar by alibaba.
the class RouteRuleInitializer method initRouteRule.
public static void initRouteRule(SchemaLoader loader) throws SQLSyntaxErrorException {
Map<String, RuleAlgorithm> functions = loader.getFunctions();
MySQLFunctionManager functionManager = new MySQLFunctionManager(true);
buildFuncManager(functionManager, functions);
for (RuleConfig conf : loader.listRuleConfig()) {
String algorithmString = conf.getAlgorithm();
MySQLLexer lexer = new MySQLLexer(algorithmString);
MySQLExprParser parser = new MySQLExprParser(lexer, functionManager, false, MySQLParser.DEFAULT_CHARSET);
Expression expression = parser.expression();
if (lexer.token() != MySQLToken.EOF) {
throw new ConfigException("route algorithm not end with EOF: " + algorithmString);
}
RuleAlgorithm algorithm;
if (expression instanceof RuleAlgorithm) {
algorithm = (RuleAlgorithm) expression;
} else {
algorithm = new ExpressionAdapter(expression);
}
conf.setRuleAlgorithm(algorithm);
}
}
use of com.alibaba.cobar.parser.ast.expression.Expression in project cobar by alibaba.
the class PartitionKeyVisitor method visit.
@Override
public void visit(ComparisionIsExpression node) {
Expression operand = node.getOperand();
visitChild(2, false, false, operand);
if (verdictColumn && (operand instanceof Identifier)) {
Identifier col = (Identifier) operand;
String table = tableAlias.get(col.getLevelUnescapeUpName(2));
if (isRuledColumn(table, col.getIdTextUpUnescape())) {
switch(node.getMode()) {
case ComparisionIsExpression.IS_FALSE:
addColumnValue(table, col.getIdTextUpUnescape(), LiteralBoolean.FALSE, node, null);
break;
case ComparisionIsExpression.IS_TRUE:
addColumnValue(table, col.getIdTextUpUnescape(), LiteralBoolean.TRUE, node, null);
break;
case ComparisionIsExpression.IS_NULL:
addColumnValue(table, col.getIdTextUpUnescape(), null, node, null);
break;
}
}
}
}
use of com.alibaba.cobar.parser.ast.expression.Expression in project cobar by alibaba.
the class PartitionKeyVisitor method visit.
@Override
public void visit(BetweenAndExpression node) {
Expression fst = node.getFirst();
Expression snd = node.getSecond();
Expression trd = node.getThird();
visitChild(2, false, false, fst, snd, trd);
if (verdictColumn && !node.isNot() && fst instanceof Identifier) {
Identifier col = (Identifier) fst;
String table = tableAlias.get(col.getLevelUnescapeUpName(2));
if (isRuledColumn(table, col.getIdTextUpUnescape())) {
Object e1 = snd.evaluation(evaluationParameter);
Object e2 = trd.evaluation(evaluationParameter);
if (e1 != Expression.UNEVALUATABLE && e2 != Expression.UNEVALUATABLE && e1 != null && e2 != null) {
if (compareEvaluatedValue(e1, e2)) {
addColumnValue(table, col.getIdTextUpUnescape(), e1, node, null);
}
}
}
}
}
use of com.alibaba.cobar.parser.ast.expression.Expression in project cobar by alibaba.
the class PartitionKeyVisitor method visit.
@Override
public void visit(LogicalOrExpression node) {
for (int i = 0, len = node.getArity(); i < len; ++i) {
Expression oprand = node.getOperand(i);
visitChild(2, verdictColumn && isVerdictPassthroughWhere(oprand), false, oprand);
}
}
Aggregations