Skip to content

Commit 871d683

Browse files
Merge branch 'master' into manticore
2 parents bb1df4f + 7c52e7f commit 871d683

File tree

19 files changed

+333
-15
lines changed

19 files changed

+333
-15
lines changed

.github/dependabot.yml

Lines changed: 0 additions & 9 deletions
This file was deleted.

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,4 +781,10 @@ default void visit(Inverse inverse) {
781781
<S> T visit(FromQuery fromQuery, S context);
782782

783783
<S> T visit(DateUnitExpression dateUnitExpression, S context);
784+
785+
<S> T visit(PostgresNamedFunctionParameter postgresNamedFunctionParameter, S context);
786+
787+
default void visit(PostgresNamedFunctionParameter postgresNamedFunctionParameter) {
788+
this.visit(postgresNamedFunctionParameter, null);
789+
}
784790
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,11 @@ public <S> T visit(OracleNamedFunctionParameter oracleNamedFunctionParameter, S
743743
return oracleNamedFunctionParameter.getExpression().accept(this, context);
744744
}
745745

746+
@Override
747+
public <S> T visit(PostgresNamedFunctionParameter postgresNamedFunctionParameter, S context) {
748+
return postgresNamedFunctionParameter.getExpression().accept(this, context);
749+
}
750+
746751
@Override
747752
public <S> T visit(GeometryDistance geometryDistance, S context) {
748753
return visitBinaryExpression(geometryDistance, context);
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*-
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2021 JSQLParser
6+
* %%
7+
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
8+
* #L%
9+
*/
10+
package net.sf.jsqlparser.expression;
11+
12+
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
13+
14+
import java.util.Objects;
15+
16+
/**
17+
* @author <a href="mailto:andreas@manticore-projects.com">Andreas Reichel</a>
18+
*/
19+
public class PostgresNamedFunctionParameter extends ASTNodeAccessImpl implements Expression {
20+
private final String name;
21+
private final Expression expression;
22+
23+
public PostgresNamedFunctionParameter(String name, Expression expression) {
24+
this.name = Objects.requireNonNull(name,
25+
"The NAME of the PostgresNamedFunctionParameter must not be null.");
26+
this.expression = Objects.requireNonNull(expression,
27+
"The EXPRESSION of the PostgresNamedFunctionParameter must not be null.");
28+
}
29+
30+
public String getName() {
31+
return name;
32+
}
33+
34+
public Expression getExpression() {
35+
return expression;
36+
}
37+
38+
@Override
39+
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
40+
return expressionVisitor.visit(this, context);
41+
}
42+
43+
public StringBuilder appendTo(StringBuilder builder) {
44+
builder.append(name)
45+
.append(" := ")
46+
.append(expression);
47+
48+
return builder;
49+
}
50+
51+
@Override
52+
public String toString() {
53+
return appendTo(new StringBuilder()).toString();
54+
}
55+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ public class ParserKeywordsUtils {
121121
{"OVERWRITE ", RESTRICTED_JSQLPARSER},
122122
{"PIVOT", RESTRICTED_JSQLPARSER},
123123
{"PREFERRING", RESTRICTED_JSQLPARSER},
124+
{"PREWHERE", RESTRICTED_JSQLPARSER},
124125
{"PRIOR", RESTRICTED_ALIAS},
125126
{"PROCEDURE", RESTRICTED_ALIAS},
126127
{"PUBLIC", RESTRICTED_ALIAS},

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class Join extends ASTNodeAccessImpl {
3737
private boolean semi = false;
3838
private boolean straight = false;
3939
private boolean apply = false;
40+
private boolean fetch = false;
4041
private FromItem fromItem;
4142
private KSQLJoinWindow joinWindow;
4243

@@ -149,6 +150,24 @@ public Join withApply(boolean apply) {
149150
return this;
150151
}
151152

153+
/**
154+
* Whether is a "FETCH" join (JPQL/HQL)
155+
*
156+
* @return true if is a "FETCH" join
157+
*/
158+
public boolean isFetch() {
159+
return fetch;
160+
}
161+
162+
public void setFetch(boolean b) {
163+
fetch = b;
164+
}
165+
166+
public Join withFetch(boolean b) {
167+
this.setFetch(b);
168+
return this;
169+
}
170+
152171
/**
153172
* Whether is a "SEMI" join
154173
*
@@ -277,10 +296,12 @@ public Join withCross(boolean cross) {
277296
/**
278297
* Returns the right item of the join
279298
*/
299+
@Deprecated
280300
public FromItem getRightItem() {
281301
return fromItem;
282302
}
283303

304+
@Deprecated
284305
public void setRightItem(FromItem item) {
285306
fromItem = item;
286307
}
@@ -427,6 +448,9 @@ public String toString() {
427448
builder.append(joinHint).append(" ");
428449
}
429450
builder.append("JOIN ");
451+
if (fetch) {
452+
builder.append("FETCH ");
453+
}
430454
}
431455

432456
builder.append(fromItem).append((joinWindow != null) ? " WITHIN " + joinWindow : "");

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class PlainSelect extends Select {
3737
private FromItem fromItem;
3838
private List<LateralView> lateralViews;
3939
private List<Join> joins;
40+
private Expression preWhere;
4041
private Expression where;
4142
private GroupByElement groupBy;
4243
private Expression having;
@@ -160,6 +161,14 @@ public void setWhere(Expression where) {
160161
this.where = where;
161162
}
162163

164+
public Expression getPreWhere() {
165+
return preWhere;
166+
}
167+
168+
public void setPreWhere(Expression preWhere) {
169+
this.preWhere = preWhere;
170+
}
171+
163172
public PlainSelect withFromItem(FromItem item) {
164173
this.setFromItem(item);
165174
return this;
@@ -569,6 +578,9 @@ public StringBuilder appendSelectBodyTo(StringBuilder builder) {
569578
if (ksqlWindow != null) {
570579
builder.append(" WINDOW ").append(ksqlWindow);
571580
}
581+
if (preWhere != null) {
582+
builder.append(" PREWHERE ").append(preWhere);
583+
}
572584
if (where != null) {
573585
builder.append(" WHERE ").append(where);
574586
}
@@ -597,6 +609,9 @@ public StringBuilder appendSelectBodyTo(StringBuilder builder) {
597609
}
598610
} else {
599611
// without from
612+
if (preWhere != null) {
613+
builder.append(" PREWHERE ").append(preWhere);
614+
}
600615
if (where != null) {
601616
builder.append(" WHERE ").append(where);
602617
}
@@ -669,6 +684,11 @@ public PlainSelect withWhere(Expression where) {
669684
return this;
670685
}
671686

687+
public PlainSelect withPreWhere(Expression preWhere) {
688+
this.setPreWhere(preWhere);
689+
return this;
690+
}
691+
672692
public PlainSelect withOptimizeFor(OptimizeFor optimizeFor) {
673693
this.setOptimizeFor(optimizeFor);
674694
return this;
@@ -767,6 +787,10 @@ public <E extends Expression> E getWhere(Class<E> type) {
767787
return type.cast(getWhere());
768788
}
769789

790+
public <E extends Expression> E getPreWhere(Class<E> type) {
791+
return type.cast(getPreWhere());
792+
}
793+
770794
public <E extends Expression> E getHaving(Class<E> type) {
771795
return type.cast(getHaving());
772796
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ public <S> T visit(PlainSelect plainSelect, S context) {
151151
// //@todo: implement
152152
// }
153153

154+
expressionVisitor.visitExpression(plainSelect.getPreWhere(), context);
154155
expressionVisitor.visitExpression(plainSelect.getWhere(), context);
155156

156157
// if (plainSelect.getOracleHierarchical() != null) {

src/main/java/net/sf/jsqlparser/util/TablesNamesFinder.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,9 @@ public <S> Void visit(PlainSelect plainSelect, S context) {
317317
}
318318

319319
visitJoins(plainSelect.getJoins(), context);
320+
if (plainSelect.getPreWhere() != null) {
321+
plainSelect.getPreWhere().accept(this, context);
322+
}
320323
if (plainSelect.getWhere() != null) {
321324
plainSelect.getWhere().accept(this, context);
322325
}
@@ -1379,7 +1382,6 @@ private <S> void visitJoins(List<Join> joins, S context) {
13791382
}
13801383
for (Join join : joins) {
13811384
join.getFromItem().accept(this, context);
1382-
join.getRightItem().accept(this, context);
13831385
for (Expression expression : join.getOnExpressions()) {
13841386
expression.accept(this, context);
13851387
}
@@ -1759,6 +1761,13 @@ public <S> Void visit(OracleNamedFunctionParameter oracleNamedFunctionParameter,
17591761
return null;
17601762
}
17611763

1764+
@Override
1765+
public <S> Void visit(PostgresNamedFunctionParameter postgresNamedFunctionParameter,
1766+
S context) {
1767+
postgresNamedFunctionParameter.getExpression().accept(this, context);
1768+
return null;
1769+
}
1770+
17621771
@Override
17631772
public <S> Void visit(RenameTableStatement renameTableStatement, S context) {
17641773
for (Map.Entry<Table, Table> e : renameTableStatement.getTableNames()) {

src/main/java/net/sf/jsqlparser/util/deparser/ExpressionDeParser.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import net.sf.jsqlparser.expression.OracleHint;
5353
import net.sf.jsqlparser.expression.OracleNamedFunctionParameter;
5454
import net.sf.jsqlparser.expression.OverlapsCondition;
55+
import net.sf.jsqlparser.expression.PostgresNamedFunctionParameter;
5556
import net.sf.jsqlparser.expression.RangeExpression;
5657
import net.sf.jsqlparser.expression.RowConstructor;
5758
import net.sf.jsqlparser.expression.RowGetExpression;
@@ -1835,4 +1836,13 @@ public <S> StringBuilder visit(FromQuery fromQuery, S context) {
18351836
public <S> StringBuilder visit(DateUnitExpression dateUnitExpression, S context) {
18361837
return builder.append(dateUnitExpression.toString());
18371838
}
1839+
1840+
@Override
1841+
public <S> StringBuilder visit(PostgresNamedFunctionParameter postgresNamedFunctionParameter,
1842+
S context) {
1843+
builder.append(postgresNamedFunctionParameter.getName()).append(" := ");
1844+
1845+
postgresNamedFunctionParameter.getExpression().accept(this, context);
1846+
return builder;
1847+
}
18381848
}

0 commit comments

Comments
 (0)