Render windowing functions without arguments correctly.

Closes #1153
See #1019
This commit is contained in:
Jens Schauder
2022-02-02 15:29:57 +01:00
parent 0dcf12c83c
commit a132d432e8
2 changed files with 17 additions and 5 deletions

View File

@@ -30,7 +30,6 @@ class SimpleFunctionVisitor extends TypedSingleConditionRenderSupport<SimpleFunc
private final StringBuilder part = new StringBuilder();
private boolean needsComma = false;
private String functionName;
SimpleFunctionVisitor(RenderContext context) {
super(context);
@@ -49,9 +48,6 @@ class SimpleFunctionVisitor extends TypedSingleConditionRenderSupport<SimpleFunc
part.append(", ");
}
if (part.length() == 0) {
part.append(functionName).append("(");
}
part.append(consumeRenderedPart());
needsComma = true;
}
@@ -66,7 +62,8 @@ class SimpleFunctionVisitor extends TypedSingleConditionRenderSupport<SimpleFunc
@Override
Delegation enterMatched(SimpleFunction segment) {
functionName = segment.getFunctionName();
part.append(segment.getFunctionName()).append("(");
return super.enterMatched(segment);
}

View File

@@ -663,5 +663,20 @@ class SelectRendererUnitTests {
assertThat(rendered).isEqualTo(
"SELECT MAX(employee.salary) OVER(PARTITION BY employee.department ORDER BY employee.age) AS MAX_SELECT FROM employee");
}
@Test // GH-1153
void renderAnalyticFunctionWithOutArgument() {
final Select select = StatementBuilder.select( //
AnalyticFunction.create("ROW_NUMBER") //
.partitionBy(department)) //
.from(employee) //
.build();
String rendered = SqlRenderer.toString(select);
assertThat(rendered).isEqualTo(
"SELECT ROW_NUMBER() OVER(PARTITION BY employee.department) FROM employee");
}
}
}