use of com.alibaba.druid.sql.ast.statement.SQLSelectItem in project sharding-jdbc by dangdangdotcom.
the class MySQLSelectVisitor method visit.
@Override
public boolean visit(final SQLAggregateExpr x) {
if (!(x.getParent() instanceof SQLSelectItem)) {
return super.visit(x);
}
AggregationType aggregationType;
try {
aggregationType = AggregationType.valueOf(x.getMethodName().toUpperCase());
} catch (final IllegalArgumentException ex) {
return super.visit(x);
}
StringBuilder expression = new StringBuilder();
x.accept(new MySqlOutputVisitor(expression));
// TODO index获取不准,考虑使用别名替换
AggregationColumn column = new AggregationColumn(expression.toString(), aggregationType, Optional.fromNullable(((SQLSelectItem) x.getParent()).getAlias()), null == x.getOption() ? Optional.<String>absent() : Optional.of(x.getOption().toString()), getParseContext().getItemIndex());
getParseContext().getParsedResult().getMergeContext().getAggregationColumns().add(column);
if (AggregationType.AVG.equals(aggregationType)) {
getParseContext().addDerivedColumnsForAvgColumn(column);
// TODO 将AVG列替换成常数,避免数据库再计算无用的AVG函数
}
return super.visit(x);
}
use of com.alibaba.druid.sql.ast.statement.SQLSelectItem in project druid by alibaba.
the class SQLUtils method addSelectItem.
public static void addSelectItem(SQLSelectQueryBlock queryBlock, SQLExpr expr, String alias, boolean first) {
SQLSelectItem selectItem = new SQLSelectItem(expr, alias);
queryBlock.getSelectList().add(selectItem);
selectItem.setParent(selectItem);
}
use of com.alibaba.druid.sql.ast.statement.SQLSelectItem in project druid by alibaba.
the class SQLSelectBuilderImpl method select.
public SQLSelectBuilderImpl select(String... columns) {
SQLSelectQueryBlock queryBlock = getQueryBlock();
for (String column : columns) {
SQLSelectItem selectItem = SQLUtils.toSelectItem(column, dbType);
queryBlock.addSelectItem(selectItem);
}
return this;
}
use of com.alibaba.druid.sql.ast.statement.SQLSelectItem in project druid by alibaba.
the class SQLSelectParser method parseSelectList.
protected void parseSelectList(SQLSelectQueryBlock queryBlock) {
final List<SQLSelectItem> selectList = queryBlock.getSelectList();
for (; ; ) {
final SQLSelectItem selectItem = this.exprParser.parseSelectItem();
selectList.add(selectItem);
selectItem.setParent(queryBlock);
if (lexer.token() != Token.COMMA) {
break;
}
lexer.nextToken();
}
}
use of com.alibaba.druid.sql.ast.statement.SQLSelectItem in project druid by alibaba.
the class PagerUtils method createCountItem.
private static SQLSelectItem createCountItem(String dbType) {
SQLAggregateExpr countExpr = new SQLAggregateExpr("COUNT");
countExpr.addArgument(new SQLAllColumnExpr());
SQLSelectItem countItem = new SQLSelectItem(countExpr);
return countItem;
}
Aggregations