use of com.alibaba.cobar.parser.ast.fragment.Limit in project cobar by alibaba.
the class MySQLDALParser method show.
public DALShowStatement show() throws SQLSyntaxErrorException {
match(KW_SHOW);
String tempStr;
String tempStrUp;
Expression tempExpr;
Identifier tempId;
SpecialIdentifier tempSi;
Limit tempLimit;
switch(lexer.token()) {
case KW_BINARY:
lexer.nextToken();
matchIdentifier("LOGS");
return new ShowBinaryLog();
case KW_CHARACTER:
lexer.nextToken();
match(KW_SET);
switch(lexer.token()) {
case KW_LIKE:
tempStr = like();
return new ShowCharaterSet(tempStr);
case KW_WHERE:
tempExpr = where();
return new ShowCharaterSet(tempExpr);
default:
return new ShowCharaterSet();
}
case KW_CREATE:
ShowCreate.Type showCreateType;
switch1: switch(lexer.nextToken()) {
case KW_DATABASE:
showCreateType = ShowCreate.Type.DATABASE;
break;
case KW_PROCEDURE:
showCreateType = ShowCreate.Type.PROCEDURE;
break;
case KW_TABLE:
showCreateType = ShowCreate.Type.TABLE;
break;
case KW_TRIGGER:
showCreateType = ShowCreate.Type.TRIGGER;
break;
case IDENTIFIER:
tempSi = specialIdentifiers.get(lexer.stringValueUppercase());
if (tempSi != null) {
switch(tempSi) {
case EVENT:
showCreateType = ShowCreate.Type.EVENT;
break switch1;
case FUNCTION:
showCreateType = ShowCreate.Type.FUNCTION;
break switch1;
case VIEW:
showCreateType = ShowCreate.Type.VIEW;
break switch1;
}
}
default:
throw err("unexpect token for SHOW CREATE");
}
lexer.nextToken();
tempId = identifier();
return new ShowCreate(showCreateType, tempId);
case KW_SCHEMAS:
case KW_DATABASES:
lexer.nextToken();
switch(lexer.token()) {
case KW_LIKE:
tempStr = like();
return new ShowDatabases(tempStr);
case KW_WHERE:
tempExpr = where();
return new ShowDatabases(tempExpr);
}
return new ShowDatabases();
case KW_KEYS:
return showIndex(ShowIndex.Type.KEYS);
case KW_INDEX:
return showIndex(ShowIndex.Type.INDEX);
case KW_PROCEDURE:
lexer.nextToken();
tempStrUp = lexer.stringValueUppercase();
tempSi = specialIdentifiers.get(tempStrUp);
if (tempSi != null) {
switch(tempSi) {
case CODE:
lexer.nextToken();
tempId = identifier();
return new ShowProcedureCode(tempId);
case STATUS:
switch(lexer.nextToken()) {
case KW_LIKE:
tempStr = like();
return new ShowProcedureStatus(tempStr);
case KW_WHERE:
tempExpr = where();
return new ShowProcedureStatus(tempExpr);
default:
return new ShowProcedureStatus();
}
}
}
throw err("unexpect token for SHOW PROCEDURE");
case KW_TABLE:
lexer.nextToken();
matchIdentifier("STATUS");
tempId = null;
if (lexer.token() == KW_FROM || lexer.token() == KW_IN) {
lexer.nextToken();
tempId = identifier();
}
switch(lexer.token()) {
case KW_LIKE:
tempStr = like();
return new ShowTableStatus(tempId, tempStr);
case KW_WHERE:
tempExpr = where();
return new ShowTableStatus(tempId, tempExpr);
}
return new ShowTableStatus(tempId);
case IDENTIFIER:
tempStrUp = lexer.stringValueUppercase();
tempSi = specialIdentifiers.get(tempStrUp);
if (tempSi == null) {
break;
}
switch(tempSi) {
case INDEXES:
return showIndex(ShowIndex.Type.INDEXES);
case GRANTS:
if (lexer.nextToken() == KW_FOR) {
lexer.nextToken();
tempExpr = exprParser.expression();
return new ShowGrants(tempExpr);
}
return new ShowGrants();
case AUTHORS:
lexer.nextToken();
return new ShowAuthors();
case BINLOG:
lexer.nextToken();
matchIdentifier("EVENTS");
tempStr = null;
tempExpr = null;
tempLimit = null;
if (lexer.token() == KW_IN) {
lexer.nextToken();
tempStr = lexer.stringValue();
lexer.nextToken();
}
if (lexer.token() == KW_FROM) {
lexer.nextToken();
tempExpr = exprParser.expression();
}
if (lexer.token() == KW_LIMIT) {
tempLimit = limit();
}
return new ShowBinLogEvent(tempStr, tempExpr, tempLimit);
case COLLATION:
switch(lexer.nextToken()) {
case KW_LIKE:
tempStr = like();
return new ShowCollation(tempStr);
case KW_WHERE:
tempExpr = where();
return new ShowCollation(tempExpr);
}
return new ShowCollation();
case COLUMNS:
return showColumns(false);
case CONTRIBUTORS:
lexer.nextToken();
return new ShowContributors();
case ENGINE:
switch(lexer.nextToken()) {
case IDENTIFIER:
tempStrUp = lexer.stringValueUppercase();
tempSi = specialIdentifiers.get(tempStrUp);
if (tempSi != null) {
switch(tempSi) {
case INNODB:
lexer.nextToken();
tempStrUp = lexer.stringValueUppercase();
tempSi = specialIdentifiers.get(tempStrUp);
if (tempSi != null) {
switch(tempSi) {
case STATUS:
lexer.nextToken();
return new ShowEngine(ShowEngine.Type.INNODB_STATUS);
case MUTEX:
lexer.nextToken();
return new ShowEngine(ShowEngine.Type.INNODB_MUTEX);
}
}
case PERFORMANCE_SCHEMA:
lexer.nextToken();
matchIdentifier("STATUS");
return new ShowEngine(ShowEngine.Type.PERFORMANCE_SCHEMA_STATUS);
}
}
default:
throw err("unexpect token for SHOW ENGINE");
}
case ENGINES:
lexer.nextToken();
return new ShowEngines();
case ERRORS:
lexer.nextToken();
tempLimit = limit();
return new ShowErrors(false, tempLimit);
case COUNT:
lexer.nextToken();
match(PUNC_LEFT_PAREN);
match(OP_ASTERISK);
match(PUNC_RIGHT_PAREN);
switch(matchIdentifier("ERRORS", "WARNINGS")) {
case 0:
return new ShowErrors(true, null);
case 1:
return new ShowWarnings(true, null);
}
case EVENTS:
tempId = null;
switch(lexer.nextToken()) {
case KW_IN:
case KW_FROM:
lexer.nextToken();
tempId = identifier();
}
switch(lexer.token()) {
case KW_LIKE:
tempStr = like();
return new ShowEvents(tempId, tempStr);
case KW_WHERE:
tempExpr = where();
return new ShowEvents(tempId, tempExpr);
default:
return new ShowEvents(tempId);
}
case FULL:
lexer.nextToken();
tempStrUp = lexer.stringValueUppercase();
tempSi = specialIdentifiers.get(tempStrUp);
if (tempSi != null) {
switch(tempSi) {
case COLUMNS:
return showColumns(true);
case PROCESSLIST:
lexer.nextToken();
return new ShowProcesslist(true);
case TABLES:
tempId = null;
switch(lexer.nextToken()) {
case KW_IN:
case KW_FROM:
lexer.nextToken();
tempId = identifier();
}
switch(lexer.token()) {
case KW_LIKE:
tempStr = like();
return new ShowTables(true, tempId, tempStr);
case KW_WHERE:
tempExpr = where();
return new ShowTables(true, tempId, tempExpr);
default:
return new ShowTables(true, tempId);
}
}
}
throw err("unexpected token for SHOW FULL");
case FUNCTION:
lexer.nextToken();
tempStrUp = lexer.stringValueUppercase();
tempSi = specialIdentifiers.get(tempStrUp);
if (tempSi != null) {
switch(tempSi) {
case CODE:
lexer.nextToken();
tempId = identifier();
return new ShowFunctionCode(tempId);
case STATUS:
switch(lexer.nextToken()) {
case KW_LIKE:
tempStr = like();
return new ShowFunctionStatus(tempStr);
case KW_WHERE:
tempExpr = where();
return new ShowFunctionStatus(tempExpr);
default:
return new ShowFunctionStatus();
}
}
}
throw err("unexpected token for SHOW FUNCTION");
case GLOBAL:
lexer.nextToken();
tempStrUp = lexer.stringValueUppercase();
tempSi = specialIdentifiers.get(tempStrUp);
if (tempSi != null) {
switch(tempSi) {
case STATUS:
switch(lexer.nextToken()) {
case KW_LIKE:
tempStr = like();
return new ShowStatus(VariableScope.GLOBAL, tempStr);
case KW_WHERE:
tempExpr = where();
return new ShowStatus(VariableScope.GLOBAL, tempExpr);
default:
return new ShowStatus(VariableScope.GLOBAL);
}
case VARIABLES:
switch(lexer.nextToken()) {
case KW_LIKE:
tempStr = like();
return new ShowVariables(VariableScope.GLOBAL, tempStr);
case KW_WHERE:
tempExpr = where();
return new ShowVariables(VariableScope.GLOBAL, tempExpr);
default:
return new ShowVariables(VariableScope.GLOBAL);
}
}
}
throw err("unexpected token for SHOW GLOBAL");
case MASTER:
lexer.nextToken();
tempStrUp = lexer.stringValueUppercase();
tempSi = specialIdentifiers.get(tempStrUp);
if (tempSi != null && tempSi == SpecialIdentifier.STATUS) {
lexer.nextToken();
return new ShowMasterStatus();
}
matchIdentifier("LOGS");
return new ShowBinaryLog();
case OPEN:
lexer.nextToken();
matchIdentifier("TABLES");
tempId = null;
switch(lexer.token()) {
case KW_IN:
case KW_FROM:
lexer.nextToken();
tempId = identifier();
}
switch(lexer.token()) {
case KW_LIKE:
tempStr = like();
return new ShowOpenTables(tempId, tempStr);
case KW_WHERE:
tempExpr = where();
return new ShowOpenTables(tempId, tempExpr);
default:
return new ShowOpenTables(tempId);
}
case PLUGINS:
lexer.nextToken();
return new ShowPlugins();
case PRIVILEGES:
lexer.nextToken();
return new ShowPrivileges();
case PROCESSLIST:
lexer.nextToken();
return new ShowProcesslist(false);
case PROFILE:
return showProfile();
case PROFILES:
lexer.nextToken();
return new ShowProfiles();
case LOCAL:
case SESSION:
lexer.nextToken();
tempStrUp = lexer.stringValueUppercase();
tempSi = specialIdentifiers.get(tempStrUp);
if (tempSi != null) {
switch(tempSi) {
case STATUS:
switch(lexer.nextToken()) {
case KW_LIKE:
tempStr = like();
return new ShowStatus(VariableScope.SESSION, tempStr);
case KW_WHERE:
tempExpr = where();
return new ShowStatus(VariableScope.SESSION, tempExpr);
default:
return new ShowStatus(VariableScope.SESSION);
}
case VARIABLES:
switch(lexer.nextToken()) {
case KW_LIKE:
tempStr = like();
return new ShowVariables(VariableScope.SESSION, tempStr);
case KW_WHERE:
tempExpr = where();
return new ShowVariables(VariableScope.SESSION, tempExpr);
default:
return new ShowVariables(VariableScope.SESSION);
}
}
}
throw err("unexpected token for SHOW SESSION");
case SLAVE:
lexer.nextToken();
tempStrUp = lexer.stringValueUppercase();
tempSi = specialIdentifiers.get(tempStrUp);
if (tempSi != null) {
switch(tempSi) {
case HOSTS:
lexer.nextToken();
return new ShowSlaveHosts();
case STATUS:
lexer.nextToken();
return new ShowSlaveStatus();
}
}
throw err("unexpected token for SHOW SLAVE");
case STATUS:
switch(lexer.nextToken()) {
case KW_LIKE:
tempStr = like();
return new ShowStatus(VariableScope.SESSION, tempStr);
case KW_WHERE:
tempExpr = where();
return new ShowStatus(VariableScope.SESSION, tempExpr);
default:
return new ShowStatus(VariableScope.SESSION);
}
case STORAGE:
lexer.nextToken();
matchIdentifier("ENGINES");
return new ShowEngines();
case TABLES:
tempId = null;
switch(lexer.nextToken()) {
case KW_IN:
case KW_FROM:
lexer.nextToken();
tempId = identifier();
}
switch(lexer.token()) {
case KW_LIKE:
tempStr = like();
return new ShowTables(false, tempId, tempStr);
case KW_WHERE:
tempExpr = where();
return new ShowTables(false, tempId, tempExpr);
default:
return new ShowTables(false, tempId);
}
case TRIGGERS:
tempId = null;
switch(lexer.nextToken()) {
case KW_IN:
case KW_FROM:
lexer.nextToken();
tempId = identifier();
}
switch(lexer.token()) {
case KW_LIKE:
tempStr = like();
return new ShowTriggers(tempId, tempStr);
case KW_WHERE:
tempExpr = where();
return new ShowTriggers(tempId, tempExpr);
default:
return new ShowTriggers(tempId);
}
case VARIABLES:
switch(lexer.nextToken()) {
case KW_LIKE:
tempStr = like();
return new ShowVariables(VariableScope.SESSION, tempStr);
case KW_WHERE:
tempExpr = where();
return new ShowVariables(VariableScope.SESSION, tempExpr);
default:
return new ShowVariables(VariableScope.SESSION);
}
case WARNINGS:
lexer.nextToken();
tempLimit = limit();
return new ShowWarnings(false, tempLimit);
}
break;
}
throw err("unexpect token for SHOW");
}
use of com.alibaba.cobar.parser.ast.fragment.Limit in project cobar by alibaba.
the class MySQLDALParser method showProfile.
private ShowProfile showProfile() throws SQLSyntaxErrorException {
lexer.nextToken();
List<ShowProfile.Type> types = new LinkedList<ShowProfile.Type>();
ShowProfile.Type type = showPrifileType();
if (type == null) {
types = Collections.emptyList();
} else if (lexer.token() == PUNC_COMMA) {
types = new LinkedList<ShowProfile.Type>();
types.add(type);
for (; lexer.token() == PUNC_COMMA; ) {
lexer.nextToken();
type = showPrifileType();
types.add(type);
}
} else {
types = new ArrayList<ShowProfile.Type>();
types.add(type);
}
Expression forQuery = null;
if (lexer.token() == KW_FOR) {
lexer.nextToken();
matchIdentifier("QUERY");
forQuery = exprParser.expression();
}
Limit limit = limit();
return new ShowProfile(types, forQuery, limit);
}
use of com.alibaba.cobar.parser.ast.fragment.Limit in project cobar by alibaba.
the class MySQLDMLUpdateParser method update.
/**
* nothing has been pre-consumed <code><pre>
* 'UPDATE' 'LOW_PRIORITY'? 'IGNORE'? table_reference
* 'SET' colName ('='|':=') (expr|'DEFAULT') (',' colName ('='|':=') (expr|'DEFAULT'))*
* ('WHERE' cond)?
* {singleTable}? => ('ORDER' 'BY' orderBy)? ('LIMIT' count)?
* </pre></code>
*/
public DMLUpdateStatement update() throws SQLSyntaxErrorException {
match(KW_UPDATE);
boolean lowPriority = false;
boolean ignore = false;
if (lexer.token() == KW_LOW_PRIORITY) {
lexer.nextToken();
lowPriority = true;
}
if (lexer.token() == KW_IGNORE) {
lexer.nextToken();
ignore = true;
}
TableReferences tableRefs = tableRefs();
match(KW_SET);
List<Pair<Identifier, Expression>> values;
Identifier col = identifier();
match(OP_EQUALS, OP_ASSIGN);
Expression expr = exprParser.expression();
if (lexer.token() == PUNC_COMMA) {
values = new LinkedList<Pair<Identifier, Expression>>();
values.add(new Pair<Identifier, Expression>(col, expr));
for (; lexer.token() == PUNC_COMMA; ) {
lexer.nextToken();
col = identifier();
match(OP_EQUALS, OP_ASSIGN);
expr = exprParser.expression();
values.add(new Pair<Identifier, Expression>(col, expr));
}
} else {
values = new ArrayList<Pair<Identifier, Expression>>(1);
values.add(new Pair<Identifier, Expression>(col, expr));
}
Expression where = null;
if (lexer.token() == KW_WHERE) {
lexer.nextToken();
where = exprParser.expression();
}
OrderBy orderBy = null;
Limit limit = null;
if (tableRefs.isSingleTable()) {
orderBy = orderBy();
limit = limit();
}
return new DMLUpdateStatement(lowPriority, ignore, tableRefs, values, where, orderBy, limit);
}
use of com.alibaba.cobar.parser.ast.fragment.Limit in project cobar by alibaba.
the class MySQLOutputASTVisitor method visit.
@Override
public void visit(ShowErrors node) {
appendable.append("SHOW ");
if (node.isCount()) {
appendable.append("COUNT(*) ERRORS");
} else {
appendable.append("ERRORS");
Limit limit = node.getLimit();
if (node.getLimit() != null) {
appendable.append(' ');
limit.accept(this);
}
}
}
use of com.alibaba.cobar.parser.ast.fragment.Limit in project cobar by alibaba.
the class MySQLOutputASTVisitor method visit.
@Override
public void visit(DMLSelectStatement node) {
appendable.append("SELECT ");
final DMLSelectStatement.SelectOption option = node.getOption();
switch(option.resultDup) {
case ALL:
break;
case DISTINCT:
appendable.append("DISTINCT ");
break;
case DISTINCTROW:
appendable.append("DISTINCTROW ");
break;
default:
throw new IllegalArgumentException("unknown option for SELECT: " + option);
}
if (option.highPriority) {
appendable.append("HIGH_PRIORITY ");
}
if (option.straightJoin) {
appendable.append("STRAIGHT_JOIN ");
}
switch(option.resultSize) {
case SQL_BIG_RESULT:
appendable.append("SQL_BIG_RESULT ");
break;
case SQL_SMALL_RESULT:
appendable.append("SQL_SMALL_RESULT ");
break;
case UNDEF:
break;
default:
throw new IllegalArgumentException("unknown option for SELECT: " + option);
}
if (option.sqlBufferResult) {
appendable.append("SQL_BUFFER_RESULT ");
}
switch(option.queryCache) {
case SQL_CACHE:
appendable.append("SQL_CACHE ");
break;
case SQL_NO_CACHE:
appendable.append("SQL_NO_CACHE ");
break;
case UNDEF:
break;
default:
throw new IllegalArgumentException("unknown option for SELECT: " + option);
}
if (option.sqlCalcFoundRows) {
appendable.append("SQL_CALC_FOUND_ROWS ");
}
boolean isFst = true;
List<Pair<Expression, String>> exprList = node.getSelectExprList();
for (Pair<Expression, String> p : exprList) {
if (isFst)
isFst = false;
else
appendable.append(", ");
p.getKey().accept(this);
String alias = p.getValue();
if (alias != null) {
appendable.append(" AS ").append(alias);
}
}
TableReferences from = node.getTables();
if (from != null) {
appendable.append(" FROM ");
from.accept(this);
}
Expression where = node.getWhere();
if (where != null) {
appendable.append(" WHERE ");
where.accept(this);
}
GroupBy group = node.getGroup();
if (group != null) {
appendable.append(' ');
group.accept(this);
}
Expression having = node.getHaving();
if (having != null) {
appendable.append(" HAVING ");
having.accept(this);
}
OrderBy order = node.getOrder();
if (order != null) {
appendable.append(' ');
order.accept(this);
}
Limit limit = node.getLimit();
if (limit != null) {
appendable.append(' ');
limit.accept(this);
}
switch(option.lockMode) {
case FOR_UPDATE:
appendable.append(" FOR UPDATE");
break;
case LOCK_IN_SHARE_MODE:
appendable.append(" LOCK IN SHARE MODE");
break;
case UNDEF:
break;
default:
throw new IllegalArgumentException("unknown option for SELECT: " + option);
}
}
Aggregations