use of com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem in project druid by alibaba.
the class SQLASTParameterizedVisitor method visit.
@Override
public boolean visit(SQLIntegerExpr x) {
SQLObject parent = x.getParent();
if (parent instanceof SQLSelectGroupByClause || parent instanceof SQLSelectOrderByItem) {
return false;
}
parameterizeAndExportPara(x);
return false;
}
use of com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem in project sharding-jdbc by dangdangdotcom.
the class MySQLSelectVisitor method visit.
public boolean visit(final SQLOrderBy x) {
for (SQLSelectOrderByItem each : x.getItems()) {
SQLExpr expr = each.getExpr();
OrderByType orderByType = null == each.getType() ? OrderByType.ASC : OrderByType.valueOf(each.getType());
if (expr instanceof SQLIntegerExpr) {
getParseContext().addOrderByColumn(((SQLIntegerExpr) expr).getNumber().intValue(), orderByType);
} else if (expr instanceof SQLIdentifierExpr) {
getParseContext().addOrderByColumn(Optional.<String>absent(), ((SQLIdentifierExpr) expr).getName(), orderByType);
} else if (expr instanceof SQLPropertyExpr) {
SQLPropertyExpr sqlPropertyExpr = (SQLPropertyExpr) expr;
getParseContext().addOrderByColumn(Optional.of(sqlPropertyExpr.getOwner().toString()), sqlPropertyExpr.getName(), orderByType);
}
}
return super.visit(x);
}
use of com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem in project Mycat_plus by coderczp.
the class JoinParser method parserOrderBy.
private void parserOrderBy(SQLOrderBy orderby) {
if (orderby != null) {
for (int i = 0; i < orderby.getItems().size(); i++) {
SQLSelectOrderByItem orderitem = orderby.getItems().get(i);
tableFilter.addOrders(orderitem.getExpr().toString(), getSQLExprToAsc(orderitem.getType()));
}
}
}
use of com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem in project Mycat_plus by coderczp.
the class DruidSelectParser method parseOrderAggGroupMysql.
protected void parseOrderAggGroupMysql(SchemaConfig schema, SQLStatement stmt, RouteResultset rrs, MySqlSelectQueryBlock mysqlSelectQuery) {
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
stmt.accept(visitor);
// rrs.setGroupByCols((String[])visitor.getGroupByColumns().toArray());
if (!isNeedParseOrderAgg) {
return;
}
Map<String, String> aliaColumns = parseAggGroupCommon(schema, stmt, rrs, mysqlSelectQuery);
// setOrderByCols
if (mysqlSelectQuery.getOrderBy() != null) {
List<SQLSelectOrderByItem> orderByItems = mysqlSelectQuery.getOrderBy().getItems();
rrs.setOrderByCols(buildOrderByCols(orderByItems, aliaColumns));
}
isNeedParseOrderAgg = false;
}
use of com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem in project Mycat_plus by coderczp.
the class SQLQueryResultHandler method dohandler.
@Override
public String dohandler(SQLStatement statement, SQLSelect sqlselect, SQLObject parent, List param) {
if (parent.getParent() instanceof SQLBinaryOpExpr) {
SQLBinaryOpExpr pp = (SQLBinaryOpExpr) parent.getParent();
SQLExprImpl listExpr = null;
if (null == param || param.isEmpty()) {
listExpr = new SQLNullExpr();
} else {
listExpr = new SQLListExpr();
((SQLListExpr) listExpr).getItems().addAll(param);
}
if (pp.getLeft().equals(parent)) {
pp.setLeft(listExpr);
} else if (pp.getRight().equals(parent)) {
pp.setRight(listExpr);
}
} else if (parent.getParent() instanceof SQLSelectItem) {
SQLSelectItem pp = (SQLSelectItem) parent.getParent();
SQLExprImpl listExpr = null;
if (null == param || param.isEmpty()) {
listExpr = new SQLNullExpr();
} else {
listExpr = new SQLListExpr();
((SQLListExpr) listExpr).getItems().addAll(param);
}
pp.setExpr(listExpr);
} else if (parent.getParent() instanceof SQLSelectGroupByClause) {
SQLSelectGroupByClause pp = (SQLSelectGroupByClause) parent.getParent();
List<SQLExpr> items = pp.getItems();
for (int i = 0; i < items.size(); i++) {
SQLExpr expr = items.get(i);
if (expr instanceof SQLQueryExpr && ((SQLQueryExpr) expr).getSubQuery().equals(sqlselect)) {
SQLExprImpl listExpr = null;
if (null == param || param.isEmpty()) {
listExpr = new SQLNullExpr();
} else {
listExpr = new SQLListExpr();
((SQLListExpr) listExpr).getItems().addAll(param);
}
items.set(i, listExpr);
}
}
} else if (parent.getParent() instanceof SQLSelectOrderByItem) {
SQLSelectOrderByItem orderItem = (SQLSelectOrderByItem) parent.getParent();
SQLExprImpl listExpr = null;
if (null == param || param.isEmpty()) {
listExpr = new SQLNullExpr();
} else {
listExpr = new SQLListExpr();
((SQLListExpr) listExpr).getItems().addAll(param);
}
listExpr.setParent(orderItem);
orderItem.setExpr(listExpr);
} else if (parent.getParent() instanceof MySqlSelectQueryBlock) {
MySqlSelectQueryBlock query = (MySqlSelectQueryBlock) parent.getParent();
// select * from subtest1 a where (select 1 from subtest3); 这种情况会进入到当前分支.
// 改写为 select * from subtest1 a where (1); 或 select * from subtest1 a where (null);
SQLExprImpl listExpr = null;
if (null == param || param.isEmpty()) {
listExpr = new SQLNullExpr();
} else {
listExpr = new SQLListExpr();
((SQLListExpr) listExpr).getItems().addAll(param);
}
listExpr.setParent(query);
query.setWhere(listExpr);
}
return statement.toString();
}
Aggregations