From e8ff9fb98d299dce82922291ec347a1e5e19e356 Mon Sep 17 00:00:00 2001 From: manticore-projects Date: Sun, 8 Dec 2024 15:27:44 +0700 Subject: [PATCH] feat: syntax sugar for table functions Signed-off-by: Andreas Reichel Signed-off-by: manticore-projects --- .../java/net/sf/jsqlparser/expression/Function.java | 3 ++- .../sf/jsqlparser/statement/select/TableFunction.java | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/sf/jsqlparser/expression/Function.java b/src/main/java/net/sf/jsqlparser/expression/Function.java index e3a5156ec..d8ef6cb2e 100644 --- a/src/main/java/net/sf/jsqlparser/expression/Function.java +++ b/src/main/java/net/sf/jsqlparser/expression/Function.java @@ -17,6 +17,7 @@ import net.sf.jsqlparser.statement.select.OrderByElement; import java.util.Arrays; +import java.util.Collections; import java.util.List; /** @@ -44,7 +45,7 @@ public class Function extends ASTNodeAccessImpl implements Expression { public Function() {} public Function(String name, Expression... parameters) { - this.nameparts = Arrays.asList(name); + this.nameparts = Collections.singletonList(name); this.parameters = new ExpressionList<>(parameters); } diff --git a/src/main/java/net/sf/jsqlparser/statement/select/TableFunction.java b/src/main/java/net/sf/jsqlparser/statement/select/TableFunction.java index 4f51179fc..7d3a5242a 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/TableFunction.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/TableFunction.java @@ -10,6 +10,7 @@ package net.sf.jsqlparser.statement.select; import net.sf.jsqlparser.expression.Alias; +import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.expression.Function; @SuppressWarnings({"PMD.UncommentedEmptyMethodBody"}) @@ -29,6 +30,15 @@ public TableFunction(String prefix, Function function) { this.function = function; } + public TableFunction(String prefix, String name, Expression... parameters) { + this.prefix = prefix; + this.function = new Function(name, parameters); + } + + public TableFunction(String name, Expression... parameters) { + this(null, name, parameters); + } + public Function getFunction() { return function; }