use of com.alibaba.cobar.parser.ast.expression.type.CollateExpression in project cobar by alibaba.
the class MySQLExprParser method collateExpression.
private Expression collateExpression(String consumed, String consumedUp) throws SQLSyntaxErrorException {
for (Expression expr = userExpression(consumed, consumedUp); ; ) {
if (lexer.token() == KW_COLLATE) {
lexer.nextToken();
String collateName = lexer.stringValue();
match(IDENTIFIER);
expr = new CollateExpression(expr, collateName).setCacheEvalRst(cacheEvalRst);
continue;
}
return expr;
}
}
use of com.alibaba.cobar.parser.ast.expression.type.CollateExpression in project cobar by alibaba.
the class MySQLExprParserTest method testUnary.
public void testUnary() throws Exception {
String sql = "!-~ binary a collate latin1_danish_ci";
MySQLExprParser parser = new MySQLExprParser(new MySQLLexer(sql));
Expression expr = parser.expression();
String output = output2MySQL(expr, sql);
Assert.assertEquals("! - ~ BINARY a COLLATE latin1_danish_ci", output);
NegativeValueExpression neg = (NegativeValueExpression) expr;
MinusExpression mi = (MinusExpression) neg.getOperand();
BitInvertExpression bi = (BitInvertExpression) mi.getOperand();
CastBinaryExpression bin = (CastBinaryExpression) bi.getOperand();
CollateExpression col = (CollateExpression) bin.getOperand();
Assert.assertEquals("a", ((Identifier) col.getString()).getIdText());
}
use of com.alibaba.cobar.parser.ast.expression.type.CollateExpression in project cobar by alibaba.
the class MySQLExprParser method unaryOpExpression.
/**
* <code>('+'|'-'|'~'|'!'|'BINARY')* higherExpr</code><br/>
* '!' has higher precedence
*/
private Expression unaryOpExpression(String consumed, String consumedUp) throws SQLSyntaxErrorException {
if (consumed == null) {
Expression expr;
switch(lexer.token()) {
case OP_EXCLAMATION:
lexer.nextToken();
expr = unaryOpExpression(null, null);
return new NegativeValueExpression(expr).setCacheEvalRst(cacheEvalRst);
case OP_PLUS:
lexer.nextToken();
return unaryOpExpression(null, null);
case OP_MINUS:
lexer.nextToken();
expr = unaryOpExpression(null, null);
return new MinusExpression(expr).setCacheEvalRst(cacheEvalRst);
case OP_TILDE:
lexer.nextToken();
expr = unaryOpExpression(null, null);
return new BitInvertExpression(expr).setCacheEvalRst(cacheEvalRst);
case KW_BINARY:
lexer.nextToken();
expr = unaryOpExpression(null, null);
return new CastBinaryExpression(expr).setCacheEvalRst(cacheEvalRst);
}
}
return collateExpression(consumed, consumedUp);
}
use of com.alibaba.cobar.parser.ast.expression.type.CollateExpression in project cobar by alibaba.
the class MySQLOutputASTVisitor method visit.
@Override
public void visit(CollateExpression node) {
Expression string = node.getString();
boolean paren = string.getPrecedence() < node.getPrecedence();
if (paren)
appendable.append('(');
string.accept(this);
if (paren)
appendable.append(')');
appendable.append(" COLLATE ").append(node.getCollateName());
}
Aggregations