Skip to content

Commit 398be70

Browse files
author
David Hayes
committed
Fix[2306] - Adds support for Trino UDF
Trino SQL allows you to specify User Defined functions in the WITH clause ahead of a statement. This adds support for this type of statement.
1 parent 668adea commit 398be70

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

src/main/java/net/sf/jsqlparser/statement/select/WithFunctionDeclaration.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ public class WithFunctionDeclaration implements Serializable {
2020
private String returnType;
2121
private Expression returnExpression;
2222

23-
public WithFunctionDeclaration() {
24-
}
23+
public WithFunctionDeclaration() {}
2524

26-
public WithFunctionDeclaration(String functionName, List<WithFunctionParameter> parameters, String returnType, Expression returnExpression) {
25+
public WithFunctionDeclaration(String functionName, List<WithFunctionParameter> parameters,
26+
String returnType, Expression returnExpression) {
2727
this.functionName = functionName;
2828
this.parameters = parameters;
2929
this.returnType = returnType;

src/main/java/net/sf/jsqlparser/statement/select/WithFunctionParameter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ public class WithFunctionParameter implements Serializable {
1515
private String name;
1616
private String type; // e.g., INT
1717

18-
public WithFunctionParameter() {
19-
}
18+
public WithFunctionParameter() {}
2019

2120
public WithFunctionParameter(String name, String type) {
2221
this.name = name;

src/main/java/net/sf/jsqlparser/statement/select/WithItem.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ public void setWithFunctionDeclaration(WithFunctionDeclaration withFunctionDecla
130130
this.withFunctionDeclaration = withFunctionDeclaration;
131131
}
132132

133-
public WithItem<K> withWithFunctionDeclaration(WithFunctionDeclaration withFunctionDeclaration) {
133+
public WithItem<K> withWithFunctionDeclaration(
134+
WithFunctionDeclaration withFunctionDeclaration) {
134135
this.setWithFunctionDeclaration(withFunctionDeclaration);
135136
return this;
136137
}

src/test/java/net/sf/jsqlparser/statement/select/WithFunctionDeclarationTest.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ void fullConstructorAndGetters() {
4141
void defaultConstructorAndSetters() {
4242
withFunctionDeclaration = new WithFunctionDeclaration();
4343
withFunctionDeclaration.setFunctionName(FUNCTION_NAME);
44-
withFunctionDeclaration.setParameters(List.of(withFunctionParameter1, withFunctionParameter2));
44+
withFunctionDeclaration
45+
.setParameters(List.of(withFunctionParameter1, withFunctionParameter2));
4546
withFunctionDeclaration.setReturnType(RETURN_TYPE);
4647
withFunctionDeclaration.setReturnExpression(expression);
4748
assertThat(withFunctionDeclaration.getFunctionName()).isEqualTo(FUNCTION_NAME);
@@ -79,14 +80,17 @@ void toStringTestWithParameters() {
7980
withFunctionDeclaration = new WithFunctionDeclaration(FUNCTION_NAME,
8081
List.of(withFunctionParameter1, withFunctionParameter2), RETURN_TYPE, expression);
8182

82-
assertThat(withFunctionDeclaration.toString()).isEqualTo("FUNCTION func1(param1 bigint, param2 double) RETURNS integer RETURN 1 + 1");
83+
assertThat(withFunctionDeclaration.toString()).isEqualTo(
84+
"FUNCTION func1(param1 bigint, param2 double) RETURNS integer RETURN 1 + 1");
8385
}
8486

8587
@Test
8688
void toStringTestWithNoParameters() {
8789
when(expression.toString()).thenReturn("1 + 1");
88-
withFunctionDeclaration = new WithFunctionDeclaration(FUNCTION_NAME, List.of(), RETURN_TYPE, expression);
90+
withFunctionDeclaration =
91+
new WithFunctionDeclaration(FUNCTION_NAME, List.of(), RETURN_TYPE, expression);
8992

90-
assertThat(withFunctionDeclaration.toString()).isEqualTo("FUNCTION func1() RETURNS integer RETURN 1 + 1");
93+
assertThat(withFunctionDeclaration.toString())
94+
.isEqualTo("FUNCTION func1() RETURNS integer RETURN 1 + 1");
9195
}
9296
}

0 commit comments

Comments
 (0)