Skip to content

Commit eff1d35

Browse files
Merge branch 'master' into manticore
2 parents 962a3f6 + f47a8b3 commit eff1d35

34 files changed

+1496
-190
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![CI](https://github.com/JSQLParser/JSqlParser/actions/workflows/ci.yml/badge.svg)](https://github.com/JSQLParser/JSqlParser/actions/workflows/ci.yml)
44
[![Coverage Status](https://coveralls.io/repos/JSQLParser/JSqlParser/badge.svg?branch=master)](https://coveralls.io/r/JSQLParser/JSqlParser?branch=master)
55
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/6f9a2d7eb98f45969749e101322634a1)](https://www.codacy.com/gh/JSQLParser/JSqlParser/dashboard?utm_source=github.com&utm_medium=referral&utm_content=JSQLParser/JSqlParser&utm_campaign=Badge_Grade)
6-
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.jsqlparser/jsqlparser/badge.svg)](http://maven-badges.herokuapp.com/maven-central/com.github.jsqlparser/jsqlparser) [![Javadocs](https://www.javadoc.io/badge/com.github.jsqlparser/jsqlparser.svg)](https://www.javadoc.io/doc/com.github.jsqlparser/jsqlparser)
6+
[![Maven Central](https://img.shields.io/maven-central/v/com.github.jsqlparser/jsqlparser.svg?label=maven-central)](https://central.sonatype.com/artifact/com.github.jsqlparser/jsqlparser) [![Javadocs](https://www.javadoc.io/badge/com.github.jsqlparser/jsqlparser.svg)](https://www.javadoc.io/doc/com.github.jsqlparser/jsqlparser)
77
[![Gitter](https://badges.gitter.im/JSQLParser/JSqlParser.svg)](https://gitter.im/JSQLParser/JSqlParser?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
88

99
A huge thank you to our sponsor, [Starlake.ai](https://starlake.ai/) who simplifies data ingestion, transformation, and orchestration, enabling faster delivery of high-quality data. Starlake has been instrumental in providing Piped SQL and numerous test cases for BigQuery, Redshift, DataBricks, and DuckDB. Show your support for ongoing development by visiting Starlake.ai and giving us a star!

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ public <S> T visit(Function function, S context) {
112112
if (function.getParameters() != null) {
113113
subExpressions.addAll(function.getParameters());
114114
}
115+
if (function.getChainedParameters() != null) {
116+
subExpressions.addAll(function.getChainedParameters());
117+
}
115118
if (function.getKeep() != null) {
116119
subExpressions.add(function.getKeep());
117120
}

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
public class Function extends ASTNodeAccessImpl implements Expression {
2727
private List<String> nameparts;
2828
private ExpressionList<?> parameters;
29+
private ExpressionList<?> chainedParameters;
2930
private NamedExpressionList<?> namedParameters;
3031
private boolean allColumns = false;
3132
private boolean distinct = false;
@@ -192,6 +193,20 @@ public void setParameters(ExpressionList<?> list) {
192193
parameters = list;
193194
}
194195

196+
/**
197+
* Additional function-call parameters for dialects that support chained function calls, e.g.
198+
* quantile(0.95)(cost) in ClickHouse.
199+
*
200+
* @return the chained parameters of the function (if any, else null)
201+
*/
202+
public ExpressionList<?> getChainedParameters() {
203+
return chainedParameters;
204+
}
205+
206+
public void setChainedParameters(ExpressionList<?> chainedParameters) {
207+
this.chainedParameters = chainedParameters;
208+
}
209+
195210
/**
196211
* the parameters might be named parameters, e.g. substring('foobar' from 2 for 3)
197212
*
@@ -335,6 +350,10 @@ public String toString() {
335350

336351
String ans = getName() + params;
337352

353+
if (chainedParameters != null) {
354+
ans += "(" + chainedParameters + ")";
355+
}
356+
338357
if (nullHandling != null && isIgnoreNullsOutside()) {
339358
switch (nullHandling) {
340359
case IGNORE_NULLS:
@@ -393,6 +412,11 @@ public Function withParameters(Expression... parameters) {
393412
return withParameters(new ExpressionList<>(parameters));
394413
}
395414

415+
public Function withChainedParameters(ExpressionList<?> chainedParameters) {
416+
this.setChainedParameters(chainedParameters);
417+
return this;
418+
}
419+
396420
public Function withNamedParameters(NamedExpressionList<?> namedParameters) {
397421
this.setNamedParameters(namedParameters);
398422
return this;

src/main/java/net/sf/jsqlparser/parser/ParserKeywordsUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ public class ParserKeywordsUtils {
134134
{"SELECT", RESTRICTED_ALIAS},
135135
{"SEMI", RESTRICTED_JSQLPARSER},
136136
{"SET", RESTRICTED_JSQLPARSER},
137+
{"SETTINGS", RESTRICTED_JSQLPARSER},
137138
{"SOME", RESTRICTED_JSQLPARSER},
138139
{"START", RESTRICTED_JSQLPARSER},
139140
{"STATEMENT", RESTRICTED_JSQLPARSER},

src/main/java/net/sf/jsqlparser/schema/Column.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
import java.util.ArrayList;
1313
import java.util.Collections;
1414
import java.util.List;
15-
1615
import net.sf.jsqlparser.expression.ArrayConstructor;
1716
import net.sf.jsqlparser.expression.Expression;
1817
import net.sf.jsqlparser.expression.ExpressionVisitor;
1918
import net.sf.jsqlparser.expression.operators.relational.SupportsOldOracleJoinSyntax;
2019
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
20+
import net.sf.jsqlparser.statement.ReturningReferenceType;
2121

2222
/**
2323
* A column. It can have the table name it belongs to.
@@ -30,6 +30,8 @@ public class Column extends ASTNodeAccessImpl implements Expression, MultiPartNa
3030
private ArrayConstructor arrayConstructor;
3131
private String tableDelimiter = ".";
3232
private int oldOracleJoinSyntax = SupportsOldOracleJoinSyntax.NO_ORACLE_JOIN;
33+
private ReturningReferenceType returningReferenceType = null;
34+
private String returningQualifier = null;
3335

3436
// holds the physical table when resolved against an actual schema information
3537
private Table resolvedTable = null;
@@ -215,7 +217,9 @@ public String getUnquotedName() {
215217
public String getFullyQualifiedName(boolean aliases) {
216218
StringBuilder fqn = new StringBuilder();
217219

218-
if (table != null) {
220+
if (returningQualifier != null) {
221+
fqn.append(returningQualifier);
222+
} else if (table != null) {
219223
if (table.getAlias() != null && aliases) {
220224
fqn.append(table.getAlias().getName());
221225
} else {
@@ -284,6 +288,31 @@ public Column withOldOracleJoinSyntax(int oldOracleJoinSyntax) {
284288
return this;
285289
}
286290

291+
public ReturningReferenceType getReturningReferenceType() {
292+
return returningReferenceType;
293+
}
294+
295+
public Column setReturningReferenceType(ReturningReferenceType returningReferenceType) {
296+
this.returningReferenceType = returningReferenceType;
297+
return this;
298+
}
299+
300+
public String getReturningQualifier() {
301+
return returningQualifier;
302+
}
303+
304+
public Column setReturningQualifier(String returningQualifier) {
305+
this.returningQualifier = returningQualifier;
306+
return this;
307+
}
308+
309+
public Column withReturningReference(ReturningReferenceType returningReferenceType,
310+
String returningQualifier) {
311+
this.returningReferenceType = returningReferenceType;
312+
this.returningQualifier = returningQualifier;
313+
return this;
314+
}
315+
287316
public String getCommentText() {
288317
return commentText;
289318
}

src/main/java/net/sf/jsqlparser/statement/ExplainStatement.java

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,14 @@
1313
import java.util.LinkedHashMap;
1414
import java.util.List;
1515
import java.util.stream.Collectors;
16-
1716
import net.sf.jsqlparser.schema.Table;
18-
import net.sf.jsqlparser.statement.select.Select;
1917

2018
/**
2119
* An {@code EXPLAIN} statement
2220
*/
2321
public class ExplainStatement implements Statement {
2422
private String keyword;
25-
private Select select;
23+
private Statement statement;
2624
private LinkedHashMap<OptionType, Option> options;
2725
private Table table;
2826

@@ -37,24 +35,17 @@ public ExplainStatement() {
3735
public ExplainStatement(String keyword, Table table) {
3836
this.keyword = keyword;
3937
this.table = table;
40-
this.select = null;
4138
}
4239

43-
public ExplainStatement(String keyword, Select select, List<Option> optionList) {
40+
public ExplainStatement(String keyword, Statement statement, List<Option> optionList) {
4441
this.keyword = keyword;
45-
this.select = select;
46-
this.table = null;
42+
setStatement(statement);
4743

48-
if (optionList != null && !optionList.isEmpty()) {
49-
options = new LinkedHashMap<>();
50-
for (Option o : optionList) {
51-
options.put(o.getType(), o);
52-
}
53-
}
44+
initializeOptions(optionList);
5445
}
5546

56-
public ExplainStatement(Select select) {
57-
this("EXPLAIN", select, null);
47+
public ExplainStatement(Statement statement) {
48+
this("EXPLAIN", statement, null);
5849
}
5950

6051
public Table getTable() {
@@ -63,15 +54,20 @@ public Table getTable() {
6354

6455
public ExplainStatement setTable(Table table) {
6556
this.table = table;
57+
if (table != null) {
58+
this.statement = null;
59+
}
6660
return this;
6761
}
6862

69-
public Select getStatement() {
70-
return select;
63+
public Statement getStatement() {
64+
return statement;
7165
}
7266

73-
public void setStatement(Select select) {
74-
this.select = select;
67+
public ExplainStatement setStatement(Statement statement) {
68+
this.table = null;
69+
this.statement = statement;
70+
return this;
7571
}
7672

7773
public LinkedHashMap<OptionType, Option> getOptions() {
@@ -122,8 +118,8 @@ public String toString() {
122118
}
123119

124120
builder.append(" ");
125-
if (select != null) {
126-
select.appendTo(builder);
121+
if (statement != null) {
122+
builder.append(statement);
127123
}
128124
}
129125

@@ -135,6 +131,15 @@ public <T, S> T accept(StatementVisitor<T> statementVisitor, S context) {
135131
return statementVisitor.visit(this, context);
136132
}
137133

134+
private void initializeOptions(List<Option> optionList) {
135+
if (optionList != null && !optionList.isEmpty()) {
136+
options = new LinkedHashMap<>();
137+
for (Option o : optionList) {
138+
options.put(o.getType(), o);
139+
}
140+
}
141+
}
142+
138143
public enum OptionType {
139144
ANALYZE, VERBOSE, COSTS, BUFFERS, FORMAT, PLAN, PLAN_FOR;
140145

0 commit comments

Comments
 (0)