提交 b2e5b90f authored 作者: noelgrandin's avatar noelgrandin

make some field names in Aggregate more obvious, to distinguish the special case…

make some field names in Aggregate more obvious, to distinguish the special case GROUP_CONCAT fields from the normal fields
上级 6d3ad065
...@@ -2110,10 +2110,10 @@ public class Parser { ...@@ -2110,10 +2110,10 @@ public class Parser {
Aggregate agg = new Aggregate(Aggregate.GROUP_CONCAT, readExpression(), currentSelect, distinct); Aggregate agg = new Aggregate(Aggregate.GROUP_CONCAT, readExpression(), currentSelect, distinct);
if (readIf("ORDER")) { if (readIf("ORDER")) {
read("BY"); read("BY");
agg.setOrder(parseSimpleOrderList()); agg.setGroupConcatOrder(parseSimpleOrderList());
} }
if (readIf("SEPARATOR")) { if (readIf("SEPARATOR")) {
agg.setSeparator(readExpression()); agg.setGroupConcatSeparator(readExpression());
} }
r = agg; r = agg;
} else { } else {
......
...@@ -123,9 +123,9 @@ public class Aggregate extends Expression { ...@@ -123,9 +123,9 @@ public class Aggregate extends Expression {
private final boolean distinct; private final boolean distinct;
private Expression on; private Expression on;
private Expression separator; private Expression groupConcatSeparator;
private ArrayList<SelectOrderBy> orderList; private ArrayList<SelectOrderBy> groupConcatOrderList;
private SortOrder sort; private SortOrder groupConcatSort;
private int dataType, scale; private int dataType, scale;
private long precision; private long precision;
private int displaySize; private int displaySize;
...@@ -189,29 +189,29 @@ public class Aggregate extends Expression { ...@@ -189,29 +189,29 @@ public class Aggregate extends Expression {
} }
/** /**
* Set the order for GROUP_CONCAT. * Set the order for GROUP_CONCAT() aggregate.
* *
* @param orderBy the order by list * @param orderBy the order by list
*/ */
public void setOrder(ArrayList<SelectOrderBy> orderBy) { public void setGroupConcatOrder(ArrayList<SelectOrderBy> orderBy) {
this.orderList = orderBy; this.groupConcatOrderList = orderBy;
} }
/** /**
* Set the separator for GROUP_CONCAT. * Set the separator for the GROUP_CONCAT() aggregate.
* *
* @param separator the separator expression * @param separator the separator expression
*/ */
public void setSeparator(Expression separator) { public void setGroupConcatSeparator(Expression separator) {
this.separator = separator; this.groupConcatSeparator = separator;
} }
private SortOrder initOrder(Session session) { private SortOrder initOrder(Session session) {
int size = orderList.size(); int size = groupConcatOrderList.size();
int[] index = new int[size]; int[] index = new int[size];
int[] sortType = new int[size]; int[] sortType = new int[size];
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
SelectOrderBy o = orderList.get(i); SelectOrderBy o = groupConcatOrderList.get(i);
index[i] = i + 1; index[i] = i + 1;
int order = o.descending ? SortOrder.DESCENDING : SortOrder.ASCENDING; int order = o.descending ? SortOrder.DESCENDING : SortOrder.ASCENDING;
sortType[i] = order; sortType[i] = order;
...@@ -247,12 +247,12 @@ public class Aggregate extends Expression { ...@@ -247,12 +247,12 @@ public class Aggregate extends Expression {
if (type == GROUP_CONCAT) { if (type == GROUP_CONCAT) {
if (v != ValueNull.INSTANCE) { if (v != ValueNull.INSTANCE) {
v = v.convertTo(Value.STRING); v = v.convertTo(Value.STRING);
if (orderList != null) { if (groupConcatOrderList != null) {
int size = orderList.size(); int size = groupConcatOrderList.size();
Value[] array = new Value[1 + size]; Value[] array = new Value[1 + size];
array[0] = v; array[0] = v;
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
SelectOrderBy o = orderList.get(i); SelectOrderBy o = groupConcatOrderList.get(i);
array[i + 1] = o.expression.getValue(session); array[i + 1] = o.expression.getValue(session);
} }
v = ValueArray.get(array); v = ValueArray.get(array);
...@@ -305,8 +305,8 @@ public class Aggregate extends Expression { ...@@ -305,8 +305,8 @@ public class Aggregate extends Expression {
if (list == null || list.size() == 0) { if (list == null || list.size() == 0) {
return ValueNull.INSTANCE; return ValueNull.INSTANCE;
} }
if (orderList != null) { if (groupConcatOrderList != null) {
final SortOrder sortOrder = sort; final SortOrder sortOrder = groupConcatSort;
Collections.sort(list, new Comparator<Value>() { Collections.sort(list, new Comparator<Value>() {
@Override @Override
public int compare(Value v1, Value v2) { public int compare(Value v1, Value v2) {
...@@ -317,7 +317,7 @@ public class Aggregate extends Expression { ...@@ -317,7 +317,7 @@ public class Aggregate extends Expression {
}); });
} }
StatementBuilder buff = new StatementBuilder(); StatementBuilder buff = new StatementBuilder();
String sep = separator == null ? "," : separator.getValue(session).getString(); String sep = groupConcatSeparator == null ? "," : groupConcatSeparator.getValue(session).getString();
for (Value val : list) { for (Value val : list) {
String s; String s;
if (val.getType() == Value.ARRAY) { if (val.getType() == Value.ARRAY) {
...@@ -348,13 +348,13 @@ public class Aggregate extends Expression { ...@@ -348,13 +348,13 @@ public class Aggregate extends Expression {
if (on != null) { if (on != null) {
on.mapColumns(resolver, level); on.mapColumns(resolver, level);
} }
if (orderList != null) { if (groupConcatOrderList != null) {
for (SelectOrderBy o : orderList) { for (SelectOrderBy o : groupConcatOrderList) {
o.expression.mapColumns(resolver, level); o.expression.mapColumns(resolver, level);
} }
} }
if (separator != null) { if (groupConcatSeparator != null) {
separator.mapColumns(resolver, level); groupConcatSeparator.mapColumns(resolver, level);
} }
} }
...@@ -367,14 +367,14 @@ public class Aggregate extends Expression { ...@@ -367,14 +367,14 @@ public class Aggregate extends Expression {
precision = on.getPrecision(); precision = on.getPrecision();
displaySize = on.getDisplaySize(); displaySize = on.getDisplaySize();
} }
if (orderList != null) { if (groupConcatOrderList != null) {
for (SelectOrderBy o : orderList) { for (SelectOrderBy o : groupConcatOrderList) {
o.expression = o.expression.optimize(session); o.expression = o.expression.optimize(session);
} }
sort = initOrder(session); groupConcatSort = initOrder(session);
} }
if (separator != null) { if (groupConcatSeparator != null) {
separator = separator.optimize(session); groupConcatSeparator = groupConcatSeparator.optimize(session);
} }
switch (type) { switch (type) {
case GROUP_CONCAT: case GROUP_CONCAT:
...@@ -445,13 +445,13 @@ public class Aggregate extends Expression { ...@@ -445,13 +445,13 @@ public class Aggregate extends Expression {
if (on != null) { if (on != null) {
on.setEvaluatable(tableFilter, b); on.setEvaluatable(tableFilter, b);
} }
if (orderList != null) { if (groupConcatOrderList != null) {
for (SelectOrderBy o : orderList) { for (SelectOrderBy o : groupConcatOrderList) {
o.expression.setEvaluatable(tableFilter, b); o.expression.setEvaluatable(tableFilter, b);
} }
} }
if (separator != null) { if (groupConcatSeparator != null) {
separator.setEvaluatable(tableFilter, b); groupConcatSeparator.setEvaluatable(tableFilter, b);
} }
} }
...@@ -476,9 +476,9 @@ public class Aggregate extends Expression { ...@@ -476,9 +476,9 @@ public class Aggregate extends Expression {
buff.append("DISTINCT "); buff.append("DISTINCT ");
} }
buff.append(on.getSQL()); buff.append(on.getSQL());
if (orderList != null) { if (groupConcatOrderList != null) {
buff.append(" ORDER BY "); buff.append(" ORDER BY ");
for (SelectOrderBy o : orderList) { for (SelectOrderBy o : groupConcatOrderList) {
buff.appendExceptFirst(", "); buff.appendExceptFirst(", ");
buff.append(o.expression.getSQL()); buff.append(o.expression.getSQL());
if (o.descending) { if (o.descending) {
...@@ -486,8 +486,8 @@ public class Aggregate extends Expression { ...@@ -486,8 +486,8 @@ public class Aggregate extends Expression {
} }
} }
} }
if (separator != null) { if (groupConcatSeparator != null) {
buff.append(" SEPARATOR ").append(separator.getSQL()); buff.append(" SEPARATOR ").append(groupConcatSeparator.getSQL());
} }
return buff.append(')').toString(); return buff.append(')').toString();
} }
...@@ -584,12 +584,12 @@ public class Aggregate extends Expression { ...@@ -584,12 +584,12 @@ public class Aggregate extends Expression {
if (on != null && !on.isEverything(visitor)) { if (on != null && !on.isEverything(visitor)) {
return false; return false;
} }
if (separator != null && !separator.isEverything(visitor)) { if (groupConcatSeparator != null && !groupConcatSeparator.isEverything(visitor)) {
return false; return false;
} }
if (orderList != null) { if (groupConcatOrderList != null) {
for (int i = 0, size = orderList.size(); i < size; i++) { for (int i = 0, size = groupConcatOrderList.size(); i < size; i++) {
SelectOrderBy o = orderList.get(i); SelectOrderBy o = groupConcatOrderList.get(i);
if (!o.expression.isEverything(visitor)) { if (!o.expression.isEverything(visitor)) {
return false; return false;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论