Skip to content

Commit a132d43

Browse files
committed
Render windowing functions without arguments correctly.
Closes #1153 See #1019
1 parent 0dcf12c commit a132d43

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

spring-data-relational/src/main/java/org/springframework/data/relational/core/sql/render/SimpleFunctionVisitor.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class SimpleFunctionVisitor extends TypedSingleConditionRenderSupport<SimpleFunc
3030

3131
private final StringBuilder part = new StringBuilder();
3232
private boolean needsComma = false;
33-
private String functionName;
3433

3534
SimpleFunctionVisitor(RenderContext context) {
3635
super(context);
@@ -49,9 +48,6 @@ Delegation leaveNested(Visitable segment) {
4948
part.append(", ");
5049
}
5150

52-
if (part.length() == 0) {
53-
part.append(functionName).append("(");
54-
}
5551
part.append(consumeRenderedPart());
5652
needsComma = true;
5753
}
@@ -66,7 +62,8 @@ Delegation leaveNested(Visitable segment) {
6662
@Override
6763
Delegation enterMatched(SimpleFunction segment) {
6864

69-
functionName = segment.getFunctionName();
65+
part.append(segment.getFunctionName()).append("(");
66+
7067
return super.enterMatched(segment);
7168
}
7269

spring-data-relational/src/test/java/org/springframework/data/relational/core/sql/render/SelectRendererUnitTests.java

+15
Original file line numberDiff line numberDiff line change
@@ -663,5 +663,20 @@ void renderAnalyticFunctionWithAlias() {
663663
assertThat(rendered).isEqualTo(
664664
"SELECT MAX(employee.salary) OVER(PARTITION BY employee.department ORDER BY employee.age) AS MAX_SELECT FROM employee");
665665
}
666+
667+
@Test // GH-1153
668+
void renderAnalyticFunctionWithOutArgument() {
669+
670+
final Select select = StatementBuilder.select( //
671+
AnalyticFunction.create("ROW_NUMBER") //
672+
.partitionBy(department)) //
673+
.from(employee) //
674+
.build();
675+
676+
String rendered = SqlRenderer.toString(select);
677+
678+
assertThat(rendered).isEqualTo(
679+
"SELECT ROW_NUMBER() OVER(PARTITION BY employee.department) FROM employee");
680+
}
666681
}
667682
}

0 commit comments

Comments
 (0)