use of com.alibaba.cobar.parser.ast.expression.primary.Identifier 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.primary.Identifier in project cobar by alibaba.
the class PartitionKeyVisitor method visit.
@Override
public void visit(DDLDropTableStatement node) {
visitChild(1, false, false, node.getTableNames());
List<Identifier> tbs = node.getTableNames();
if (tbs != null) {
for (Identifier tb : tbs) {
addTable(tb.getIdTextUpUnescape());
}
}
}
use of com.alibaba.cobar.parser.ast.expression.primary.Identifier in project cobar by alibaba.
the class PartitionKeyVisitor method visit.
@Override
public void visit(DMLDeleteStatement node) {
TableReference tr = node.getTableRefs();
List<Identifier> tbs = node.getTableNames();
if (tr == null) {
Identifier table = tbs.get(0);
tableAsTableFactor(table);
} else {
visitChild(1, verdictColumn, false, tr);
for (Identifier tb : tbs) {
if (tb instanceof Wildcard) {
int trim = tb.trimParent(2, trimSchema);
schemaTrimmed = schemaTrimmed || trim == Identifier.PARENT_TRIMED;
customedSchema = customedSchema || trim == Identifier.PARENT_IGNORED;
} else {
int trim = tb.trimParent(1, trimSchema);
schemaTrimmed = schemaTrimmed || trim == Identifier.PARENT_TRIMED;
customedSchema = customedSchema || trim == Identifier.PARENT_IGNORED;
}
}
}
Expression where = node.getWhereCondition();
visitChild(2, verdictColumn, false, where);
if (tr == null) {
OrderBy order = node.getOrderBy();
visitChild(2, false, false, order);
}
}
use of com.alibaba.cobar.parser.ast.expression.primary.Identifier 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.primary.Identifier in project cobar by alibaba.
the class MySQLDMLParserTest method testGroupBy.
public void testGroupBy() throws SQLSyntaxErrorException {
String sql = "group by c1 asc, c2 desc , c3 with rollup";
MySQLLexer lexer = new MySQLLexer(sql);
MySQLDMLParser parser = getDMLParser(lexer);
GroupBy groupBy = parser.groupBy();
String output = output2MySQL(groupBy, sql);
ListUtil.isEquals(ListUtil.createList(new Pair<Expression, SortOrder>(new Identifier(null, "c1"), SortOrder.ASC), new Pair<Expression, SortOrder>(new Identifier(null, "c2"), SortOrder.DESC), new Pair<Expression, SortOrder>(new Identifier(null, "c3"), SortOrder.ASC)), groupBy.getOrderByList());
Assert.assertEquals("GROUP BY c1, c2 DESC, c3 WITH ROLLUP", output);
sql = "group by c1 asc, c2 desc , c3 ";
lexer = new MySQLLexer(sql);
parser = getDMLParser(lexer);
groupBy = parser.groupBy();
output = output2MySQL(groupBy, sql);
ListUtil.isEquals(ListUtil.createList(new Pair<Expression, SortOrder>(new Identifier(null, "c1"), SortOrder.ASC), new Pair<Expression, SortOrder>(new Identifier(null, "c2"), SortOrder.DESC), new Pair<Expression, SortOrder>(new Identifier(null, "c3"), SortOrder.ASC)), groupBy.getOrderByList());
Assert.assertEquals("GROUP BY c1, c2 DESC, c3", output);
sql = "group by c1 ";
lexer = new MySQLLexer(sql);
parser = getDMLParser(lexer);
groupBy = parser.groupBy();
output = output2MySQL(groupBy, sql);
ListUtil.isEquals(ListUtil.createList(new Pair<Expression, SortOrder>(new Identifier(null, "c1"), SortOrder.ASC)), groupBy.getOrderByList());
Assert.assertEquals("GROUP BY c1", output);
sql = "group by c1 asc ";
lexer = new MySQLLexer(sql);
parser = getDMLParser(lexer);
groupBy = parser.groupBy();
output = output2MySQL(groupBy, sql);
ListUtil.isEquals(ListUtil.createList(new Pair<Expression, SortOrder>(new Identifier(null, "c1"), SortOrder.ASC)), groupBy.getOrderByList());
Assert.assertEquals("GROUP BY c1", output);
sql = "group by c1 desc ";
lexer = new MySQLLexer(sql);
parser = getDMLParser(lexer);
groupBy = parser.groupBy();
output = output2MySQL(groupBy, sql);
ListUtil.isEquals(ListUtil.createList(new Pair<Expression, SortOrder>(new Identifier(null, "c1"), SortOrder.DESC)), groupBy.getOrderByList());
Assert.assertEquals("GROUP BY c1 DESC", output);
sql = "group by c1 with rollup ";
lexer = new MySQLLexer(sql);
parser = getDMLParser(lexer);
groupBy = parser.groupBy();
output = output2MySQL(groupBy, sql);
ListUtil.isEquals(ListUtil.createList(new Pair<Expression, SortOrder>(new Identifier(null, "c1"), SortOrder.ASC)), groupBy.getOrderByList());
Assert.assertEquals("GROUP BY c1 WITH ROLLUP", output);
}
Aggregations