use of com.alibaba.cobar.parser.ast.expression.Expression in project cobar by alibaba.
the class MySQLOutputASTVisitor method visit.
@Override
public void visit(BetweenAndExpression node) {
Expression comparee = node.getFirst();
boolean paren = comparee.getPrecedence() <= node.getPrecedence();
if (paren)
appendable.append('(');
comparee.accept(this);
if (paren)
appendable.append(')');
if (node.isNot())
appendable.append(" NOT BETWEEN ");
else
appendable.append(" BETWEEN ");
Expression start = node.getSecond();
paren = start.getPrecedence() < node.getPrecedence();
if (paren)
appendable.append('(');
start.accept(this);
if (paren)
appendable.append(')');
appendable.append(" AND ");
Expression end = node.getThird();
paren = end.getPrecedence() < node.getPrecedence();
if (paren)
appendable.append('(');
end.accept(this);
if (paren)
appendable.append(')');
}
use of com.alibaba.cobar.parser.ast.expression.Expression in project cobar by alibaba.
the class MySQLOutputASTVisitor method visit.
@Override
public void visit(MatchExpression node) {
appendable.append("MATCH (");
printList(node.getColumns());
appendable.append(") AGAINST (");
Expression pattern = node.getPattern();
boolean inparen = containsCompIn(pattern);
if (inparen)
appendable.append('(');
pattern.accept(this);
if (inparen)
appendable.append(')');
switch(node.getModifier()) {
case IN_BOOLEAN_MODE:
appendable.append(" IN BOOLEAN MODE");
break;
case IN_NATURAL_LANGUAGE_MODE:
appendable.append(" IN NATURAL LANGUAGE MODE");
break;
case IN_NATURAL_LANGUAGE_MODE_WITH_QUERY_EXPANSION:
appendable.append(" IN NATURAL LANGUAGE MODE WITH QUERY EXPANSION");
break;
case WITH_QUERY_EXPANSION:
appendable.append(" WITH QUERY EXPANSION");
break;
case _DEFAULT:
break;
default:
throw new IllegalArgumentException("unkown modifier for match expression: " + node.getModifier());
}
appendable.append(')');
}
use of com.alibaba.cobar.parser.ast.expression.Expression in project cobar by alibaba.
the class MySQLOutputASTVisitor method visit.
@Override
public void visit(PolyadicOperatorExpression node) {
for (int i = 0, len = node.getArity(); i < len; ++i) {
if (i > 0)
appendable.append(' ').append(node.getOperator()).append(' ');
Expression operand = node.getOperand(i);
boolean paren = operand.getPrecedence() < node.getPrecedence();
if (paren)
appendable.append('(');
operand.accept(this);
if (paren)
appendable.append(')');
}
}
use of com.alibaba.cobar.parser.ast.expression.Expression in project cobar by alibaba.
the class MySQLOutputASTVisitor method visit.
@Override
public void visit(GroupConcat node) {
String functionName = node.getFunctionName();
appendable.append(functionName).append('(');
if (node.isDistinct()) {
appendable.append("DISTINCT ");
}
printList(node.getArguments());
Expression orderBy = node.getOrderBy();
if (orderBy != null) {
appendable.append(" ORDER BY ");
orderBy.accept(this);
if (node.isDesc())
appendable.append(" DESC");
else
appendable.append(" ASC");
List<Expression> list = node.getAppendedColumnNames();
if (list != null && !list.isEmpty()) {
appendable.append(", ");
printList(list);
}
}
String sep = node.getSeparator();
if (sep != null) {
appendable.append(" SEPARATOR ").append(sep);
}
appendable.append(')');
}
use of com.alibaba.cobar.parser.ast.expression.Expression in project cobar by alibaba.
the class PartitionByString 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