use of com.dangdang.ddframe.rdb.sharding.parser.result.merger.AggregationColumn.AggregationType 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);
}
Aggregations