提交 2a755298 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Store GROUP_CONCAT separator as second argument

上级 eef18e96
...@@ -3055,25 +3055,31 @@ public class Parser { ...@@ -3055,25 +3055,31 @@ public class Parser {
break; break;
case GROUP_CONCAT: { case GROUP_CONCAT: {
boolean distinct = readDistinctAgg(); boolean distinct = readDistinctAgg();
r = new Aggregate(AggregateType.GROUP_CONCAT, new Expression[] { readExpression() }, currentSelect, Expression arg = readExpression(), separator = null;
distinct); ArrayList<SelectOrderBy> orderByList = null;
if (equalsToken("STRING_AGG", aggregateName)) { if (equalsToken("STRING_AGG", aggregateName)) {
// PostgreSQL compatibility: string_agg(expression, delimiter) // PostgreSQL compatibility: string_agg(expression, delimiter)
read(COMMA); read(COMMA);
r.setGroupConcatSeparator(readExpression()); separator = readExpression();
if (readIf(ORDER)) { if (readIf(ORDER)) {
read("BY"); read("BY");
r.setOrderByList(parseSimpleOrderList()); orderByList = parseSimpleOrderList();
} }
} else { } else {
if (readIf(ORDER)) { if (readIf(ORDER)) {
read("BY"); read("BY");
r.setOrderByList(parseSimpleOrderList()); orderByList = parseSimpleOrderList();
} }
if (readIf("SEPARATOR")) { if (readIf("SEPARATOR")) {
r.setGroupConcatSeparator(readExpression()); separator = readExpression();
} }
} }
r = new Aggregate(AggregateType.GROUP_CONCAT,
separator == null ? new Expression[] { arg } : new Expression[] { arg, separator },
currentSelect, distinct);
if (orderByList != null) {
r.setOrderByList(orderByList);
}
break; break;
} }
case ARRAY_AGG: { case ARRAY_AGG: {
......
...@@ -54,7 +54,6 @@ public class Aggregate extends AbstractAggregate { ...@@ -54,7 +54,6 @@ public class Aggregate extends AbstractAggregate {
private final AggregateType aggregateType; private final AggregateType aggregateType;
private final Expression[] args; private final Expression[] args;
private Expression groupConcatSeparator;
private ArrayList<SelectOrderBy> orderByList; private ArrayList<SelectOrderBy> orderByList;
private SortOrder orderBySort; private SortOrder orderBySort;
private TypeInfo type; private TypeInfo type;
...@@ -149,16 +148,6 @@ public class Aggregate extends AbstractAggregate { ...@@ -149,16 +148,6 @@ public class Aggregate extends AbstractAggregate {
this.orderByList = orderByList; this.orderByList = orderByList;
} }
/**
* Set the separator for the GROUP_CONCAT() aggregate.
*
* @param separator
* the separator expression
*/
public void setGroupConcatSeparator(Expression separator) {
this.groupConcatSeparator = separator;
}
/** /**
* Returns the type of this aggregate. * Returns the type of this aggregate.
* *
...@@ -437,7 +426,7 @@ public class Aggregate extends AbstractAggregate { ...@@ -437,7 +426,7 @@ public class Aggregate extends AbstractAggregate {
sortWithOrderBy(array); sortWithOrderBy(array);
} }
StatementBuilder buff = new StatementBuilder(); StatementBuilder buff = new StatementBuilder();
String sep = groupConcatSeparator == null ? "," : groupConcatSeparator.getValue(session).getString(); String sep = args.length < 2 ? "," : args[1].getValue(session).getString();
for (Value val : array) { for (Value val : array) {
String s; String s;
if (val.getValueType() == Value.ARRAY) { if (val.getValueType() == Value.ARRAY) {
...@@ -536,9 +525,6 @@ public class Aggregate extends AbstractAggregate { ...@@ -536,9 +525,6 @@ public class Aggregate extends AbstractAggregate {
o.expression.mapColumns(resolver, level, innerState); o.expression.mapColumns(resolver, level, innerState);
} }
} }
if (groupConcatSeparator != null) {
groupConcatSeparator.mapColumns(resolver, level, innerState);
}
super.mapColumnsAnalysis(resolver, level, innerState); super.mapColumnsAnalysis(resolver, level, innerState);
} }
...@@ -557,9 +543,6 @@ public class Aggregate extends AbstractAggregate { ...@@ -557,9 +543,6 @@ public class Aggregate extends AbstractAggregate {
} }
orderBySort = createOrder(session, orderByList, 1); orderBySort = createOrder(session, orderByList, 1);
} }
if (groupConcatSeparator != null) {
groupConcatSeparator = groupConcatSeparator.optimize(session);
}
switch (aggregateType) { switch (aggregateType) {
case GROUP_CONCAT: case GROUP_CONCAT:
type = TypeInfo.TYPE_STRING_DEFAULT; type = TypeInfo.TYPE_STRING_DEFAULT;
...@@ -652,9 +635,6 @@ public class Aggregate extends AbstractAggregate { ...@@ -652,9 +635,6 @@ public class Aggregate extends AbstractAggregate {
o.expression.setEvaluatable(tableFilter, b); o.expression.setEvaluatable(tableFilter, b);
} }
} }
if (groupConcatSeparator != null) {
groupConcatSeparator.setEvaluatable(tableFilter, b);
}
super.setEvaluatable(tableFilter, b); super.setEvaluatable(tableFilter, b);
} }
...@@ -665,9 +645,9 @@ public class Aggregate extends AbstractAggregate { ...@@ -665,9 +645,9 @@ public class Aggregate extends AbstractAggregate {
} }
args[0].getSQL(builder); args[0].getSQL(builder);
Window.appendOrderBy(builder, orderByList); Window.appendOrderBy(builder, orderByList);
if (groupConcatSeparator != null) { if (args.length >= 2) {
builder.append(" SEPARATOR "); builder.append(" SEPARATOR ");
groupConcatSeparator.getSQL(builder); args[1].getSQL(builder);
} }
builder.append(')'); builder.append(')');
return appendTailConditions(builder); return appendTailConditions(builder);
...@@ -834,9 +814,6 @@ public class Aggregate extends AbstractAggregate { ...@@ -834,9 +814,6 @@ public class Aggregate extends AbstractAggregate {
return false; return false;
} }
} }
if (groupConcatSeparator != null && !groupConcatSeparator.isEverything(visitor)) {
return false;
}
if (orderByList != null) { if (orderByList != null) {
for (SelectOrderBy o : orderByList) { for (SelectOrderBy o : orderByList) {
if (!o.expression.isEverything(visitor)) { if (!o.expression.isEverything(visitor)) {
...@@ -853,9 +830,6 @@ public class Aggregate extends AbstractAggregate { ...@@ -853,9 +830,6 @@ public class Aggregate extends AbstractAggregate {
for (Expression arg : args) { for (Expression arg : args) {
cost += arg.getCost(); cost += arg.getCost();
} }
if (groupConcatSeparator != null) {
cost += groupConcatSeparator.getCost();
}
if (orderByList != null) { if (orderByList != null) {
for (SelectOrderBy o : orderByList) { for (SelectOrderBy o : orderByList) {
cost += o.expression.getCost(); cost += o.expression.getCost();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论