Skip to content

Commit b0b0f4d

Browse files
feat: functions with extra keywords, like BigQuery Timeseries functions
- fixes #2120 Signed-off-by: Andreas Reichel <[email protected]> Signed-off-by: manticore-projects <[email protected]>
1 parent 92bbd90 commit b0b0f4d

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

src/main/java/net/sf/jsqlparser/expression/Function.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public class Function extends ASTNodeAccessImpl implements Expression {
3939
private Limit limit = null;
4040
private KeepExpression keep = null;
4141
private String onOverflowTruncate = null;
42+
private String extraKeyword = null;
4243

4344
public Function() {}
4445

@@ -255,6 +256,15 @@ public void setKeep(KeepExpression keep) {
255256
this.keep = keep;
256257
}
257258

259+
public String getExtraKeyword() {
260+
return extraKeyword;
261+
}
262+
263+
public Function setExtraKeyword(String extraKeyword) {
264+
this.extraKeyword = extraKeyword;
265+
return this;
266+
}
267+
258268
@Override
259269
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
260270
public String toString() {
@@ -272,6 +282,11 @@ public String toString() {
272282
if (isAllColumns()) {
273283
b.append("ALL ");
274284
}
285+
286+
if (extraKeyword != null) {
287+
b.append(extraKeyword).append(" ");
288+
}
289+
275290
b.append(parameters);
276291

277292
if (havingClause != null) {

src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5903,6 +5903,7 @@ Function InternalFunction(boolean escaped):
59035903
String onOverflowTruncate = null;
59045904
Token overflowToken = null;
59055905
Limit limit;
5906+
Token extraKeywordToken;
59065907
}
59075908
{
59085909
[ LOOKAHEAD(2) prefixToken = <K_APPROXIMATE> ]
@@ -5922,7 +5923,8 @@ Function InternalFunction(boolean escaped):
59225923
|
59235924
LOOKAHEAD( AllTableColumns() ) expr=AllTableColumns() { expressionList = new ExpressionList(expr); }
59245925
|
5925-
LOOKAHEAD(3) expressionList=ExpressionList()
5926+
LOOKAHEAD(3) [ LOOKAHEAD(2) extraKeywordToken = <K_TABLE> { retval.setExtraKeyword(extraKeywordToken.image); } ]
5927+
expressionList=ExpressionList()
59265928
[ orderByList = OrderByElements() { retval.setOrderByElements(orderByList); } ]
59275929

59285930
// https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/LISTAGG.html

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import net.sf.jsqlparser.JSQLParserException;
1313
import net.sf.jsqlparser.test.TestUtils;
14+
import org.junit.jupiter.api.Assertions;
1415
import org.junit.jupiter.api.Disabled;
1516
import org.junit.jupiter.api.Test;
1617

@@ -92,4 +93,21 @@ void testAsValue() throws JSQLParserException {
9293
String sqlStr = "SELECT AS VALUE STRUCT(1 AS a, 2 AS b) xyz";
9394
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
9495
}
96+
97+
@Test
98+
void testTimeSeriesFunction() throws JSQLParserException {
99+
String sqlStr = "with raw_data as (\n"
100+
+ " select timestamp('2024-12-01') zetime\n"
101+
+ " union all \n"
102+
+ " select timestamp('2024-12-04')\n"
103+
+ " )\n"
104+
+ "select zetime from GAP_FILL(\n"
105+
+ " TABLE raw_data,\n"
106+
+ " ts_column => 'zetime',\n"
107+
+ " bucket_width => INTERVAL 4 HOUR\n"
108+
+ ")";
109+
PlainSelect select = (PlainSelect) TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
110+
TableFunction function = select.getFromItem(TableFunction.class);
111+
Assertions.assertEquals("TABLE", function.getFunction().getExtraKeyword());
112+
}
95113
}

0 commit comments

Comments
 (0)