提交 cf3f69f5 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Extract AbstractAggregate.appendTailConditions()

上级 7d2fd6e9
...@@ -47,4 +47,14 @@ public abstract class AbstractAggregate extends Expression { ...@@ -47,4 +47,14 @@ public abstract class AbstractAggregate extends Expression {
} }
} }
protected StringBuilder appendTailConditions(StringBuilder builder) {
if (filterCondition != null) {
builder.append(" FILTER (WHERE ").append(filterCondition.getSQL()).append(')');
}
if (over != null) {
builder.append(' ').append(over.getSQL());
}
return builder;
}
} }
...@@ -626,13 +626,7 @@ public class Aggregate extends AbstractAggregate { ...@@ -626,13 +626,7 @@ public class Aggregate extends AbstractAggregate {
buff.append(" SEPARATOR ").append(groupConcatSeparator.getSQL()); buff.append(" SEPARATOR ").append(groupConcatSeparator.getSQL());
} }
buff.append(')'); buff.append(')');
if (filterCondition != null) { return appendTailConditions(buff.builder()).toString();
buff.append(" FILTER (WHERE ").append(filterCondition.getSQL()).append(')');
}
if (over != null) {
buff.append(' ').append(over.getSQL());
}
return buff.toString();
} }
private String getSQLArrayAggregate() { private String getSQLArrayAggregate() {
...@@ -650,13 +644,7 @@ public class Aggregate extends AbstractAggregate { ...@@ -650,13 +644,7 @@ public class Aggregate extends AbstractAggregate {
} }
} }
buff.append(')'); buff.append(')');
if (filterCondition != null) { return appendTailConditions(buff.builder()).toString();
buff.append(" FILTER (WHERE ").append(filterCondition.getSQL()).append(')');
}
if (over != null) {
buff.append(' ').append(over.getSQL());
}
return buff.toString();
} }
@Override @Override
...@@ -726,18 +714,13 @@ public class Aggregate extends AbstractAggregate { ...@@ -726,18 +714,13 @@ public class Aggregate extends AbstractAggregate {
default: default:
throw DbException.throwInternalError("type=" + type); throw DbException.throwInternalError("type=" + type);
} }
StringBuilder builder = new StringBuilder().append(text);
if (distinct) { if (distinct) {
text += "(DISTINCT " + on.getSQL() + ')'; builder.append("(DISTINCT ").append(on.getSQL()).append(')');
} else { } else {
text += StringUtils.enclose(on.getSQL()); builder.append(StringUtils.enclose(on.getSQL()));
}
if (filterCondition != null) {
text += " FILTER (WHERE " + filterCondition.getSQL() + ')';
}
if (over != null) {
text += ' ' + over.getSQL();
} }
return text; return appendTailConditions(builder).toString();
} }
private Index getMinMaxColumnIndex() { private Index getMinMaxColumnIndex() {
......
...@@ -83,13 +83,7 @@ public class JavaAggregate extends AbstractAggregate { ...@@ -83,13 +83,7 @@ public class JavaAggregate extends AbstractAggregate {
buff.append(e.getSQL()); buff.append(e.getSQL());
} }
buff.append(')'); buff.append(')');
if (filterCondition != null) { return appendTailConditions(buff.builder()).toString();
buff.append(" FILTER (WHERE ").append(filterCondition.getSQL()).append(')');
}
if (over != null) {
buff.append(' ').append(over.getSQL());
}
return buff.toString();
} }
@Override @Override
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论