Skip to content

Commit d1373c5

Browse files
ssteinhauserStefan Steinhauser
and
Stefan Steinhauser
authored
Skyline syntax (preferring clause) (#2078)
* feat: Implement skyline syntax (preferring clause) * fix: Fix codacy errors * style: Execute :spotlessApply * fix: Remove unused import * refactor: Replace wildcard imports * refactor: Remove redundant imports --------- Co-authored-by: Stefan Steinhauser <stefan.steinhauser@arz.at>
1 parent 60f4d74 commit d1373c5

File tree

23 files changed

+712
-6
lines changed

23 files changed

+712
-6
lines changed

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

+32
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
import net.sf.jsqlparser.expression.operators.relational.MinorThan;
4949
import net.sf.jsqlparser.expression.operators.relational.MinorThanEquals;
5050
import net.sf.jsqlparser.expression.operators.relational.NotEqualsTo;
51+
import net.sf.jsqlparser.expression.operators.relational.Plus;
52+
import net.sf.jsqlparser.expression.operators.relational.PriorTo;
5153
import net.sf.jsqlparser.expression.operators.relational.RegExpMatchOperator;
5254
import net.sf.jsqlparser.expression.operators.relational.SimilarToExpression;
5355
import net.sf.jsqlparser.expression.operators.relational.TSQLLeftJoin;
@@ -633,4 +635,34 @@ default void visit(StructType structType) {
633635
default void visit(LambdaExpression lambdaExpression) {
634636
this.visit(lambdaExpression, null);
635637
}
638+
639+
<S> T visit(HighExpression highExpression, S context);
640+
641+
default void visit(HighExpression highExpression) {
642+
this.visit(highExpression, null);
643+
}
644+
645+
<S> T visit(LowExpression lowExpression, S context);
646+
647+
default void visit(LowExpression lowExpression) {
648+
this.visit(lowExpression, null);
649+
}
650+
651+
<S> T visit(Plus plus, S context);
652+
653+
default void visit(Plus plus) {
654+
this.visit(plus, null);
655+
}
656+
657+
<S> T visit(PriorTo priorTo, S context);
658+
659+
default void visit(PriorTo priorTo) {
660+
this.visit(priorTo, null);
661+
}
662+
663+
<S> T visit(Inverse inverse, S context);
664+
665+
default void visit(Inverse inverse) {
666+
this.visit(inverse, null);
667+
}
636668
}

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

+31-1
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@
2929
import net.sf.jsqlparser.expression.operators.relational.Contains;
3030
import net.sf.jsqlparser.expression.operators.relational.DoubleAnd;
3131
import net.sf.jsqlparser.expression.operators.relational.EqualsTo;
32+
import net.sf.jsqlparser.expression.operators.relational.ExcludesExpression;
3233
import net.sf.jsqlparser.expression.operators.relational.ExistsExpression;
3334
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
3435
import net.sf.jsqlparser.expression.operators.relational.FullTextSearch;
3536
import net.sf.jsqlparser.expression.operators.relational.GeometryDistance;
3637
import net.sf.jsqlparser.expression.operators.relational.GreaterThan;
3738
import net.sf.jsqlparser.expression.operators.relational.GreaterThanEquals;
3839
import net.sf.jsqlparser.expression.operators.relational.InExpression;
40+
import net.sf.jsqlparser.expression.operators.relational.IncludesExpression;
3941
import net.sf.jsqlparser.expression.operators.relational.IsBooleanExpression;
4042
import net.sf.jsqlparser.expression.operators.relational.IsDistinctExpression;
4143
import net.sf.jsqlparser.expression.operators.relational.IsNullExpression;
@@ -46,9 +48,12 @@
4648
import net.sf.jsqlparser.expression.operators.relational.MinorThan;
4749
import net.sf.jsqlparser.expression.operators.relational.MinorThanEquals;
4850
import net.sf.jsqlparser.expression.operators.relational.NotEqualsTo;
51+
import net.sf.jsqlparser.expression.operators.relational.Plus;
52+
import net.sf.jsqlparser.expression.operators.relational.PriorTo;
4953
import net.sf.jsqlparser.expression.operators.relational.RegExpMatchOperator;
5054
import net.sf.jsqlparser.expression.operators.relational.SimilarToExpression;
51-
import net.sf.jsqlparser.expression.operators.relational.*;
55+
import net.sf.jsqlparser.expression.operators.relational.TSQLLeftJoin;
56+
import net.sf.jsqlparser.expression.operators.relational.TSQLRightJoin;
5257
import net.sf.jsqlparser.schema.Column;
5358
import net.sf.jsqlparser.statement.select.AllColumns;
5459
import net.sf.jsqlparser.statement.select.AllTableColumns;
@@ -762,4 +767,29 @@ public <S> T visit(LambdaExpression lambdaExpression, S context) {
762767
return lambdaExpression.getExpression().accept(this, context);
763768
}
764769

770+
@Override
771+
public <S> T visit(HighExpression highExpression, S context) {
772+
return highExpression.getExpression().accept(this, context);
773+
}
774+
775+
@Override
776+
public <S> T visit(LowExpression lowExpression, S context) {
777+
return lowExpression.getExpression().accept(this, context);
778+
}
779+
780+
@Override
781+
public <S> T visit(Plus plus, S context) {
782+
return visitBinaryExpression(plus, context);
783+
}
784+
785+
@Override
786+
public <S> T visit(PriorTo priorTo, S context) {
787+
return visitBinaryExpression(priorTo, context);
788+
}
789+
790+
@Override
791+
public <S> T visit(Inverse inverse, S context) {
792+
return inverse.getExpression().accept(this, context);
793+
}
794+
765795
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*-
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2019 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+
public class HighExpression extends ASTNodeAccessImpl implements Expression {
15+
private Expression expression;
16+
17+
public HighExpression() {
18+
// empty constructor
19+
}
20+
21+
public HighExpression(Expression expression) {
22+
this.expression = expression;
23+
}
24+
25+
@Override
26+
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
27+
return expressionVisitor.visit(this, context);
28+
}
29+
30+
public Expression getExpression() {
31+
return expression;
32+
}
33+
34+
public void setExpression(Expression expression) {
35+
this.expression = expression;
36+
}
37+
38+
@Override
39+
public String toString() {
40+
return "HIGH " + expression.toString();
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*-
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2019 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+
public class Inverse extends ASTNodeAccessImpl implements Expression {
15+
private Expression expression;
16+
17+
public Inverse() {
18+
// empty constructor
19+
}
20+
21+
public Inverse(Expression expression) {
22+
this.expression = expression;
23+
}
24+
25+
@Override
26+
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
27+
return expressionVisitor.visit(this, context);
28+
}
29+
30+
public Expression getExpression() {
31+
return expression;
32+
}
33+
34+
public void setExpression(Expression expression) {
35+
this.expression = expression;
36+
}
37+
38+
@Override
39+
public String toString() {
40+
return "INVERSE (" + expression.toString() + ")";
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*-
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2019 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+
public class LowExpression extends ASTNodeAccessImpl implements Expression {
15+
private Expression expression;
16+
17+
public LowExpression() {
18+
// empty constructor
19+
}
20+
21+
public LowExpression(Expression expression) {
22+
this.expression = expression;
23+
}
24+
25+
@Override
26+
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
27+
return expressionVisitor.visit(this, context);
28+
}
29+
30+
public Expression getExpression() {
31+
return expression;
32+
}
33+
34+
public void setExpression(Expression expression) {
35+
this.expression = expression;
36+
}
37+
38+
@Override
39+
public String toString() {
40+
return "LOW " + expression.toString();
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*-
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2019 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.expression.operators.relational.ExpressionList;
13+
14+
import java.io.Serializable;
15+
16+
public class PreferringClause implements Serializable {
17+
private Expression preferring;
18+
private PartitionByClause partitionBy;
19+
20+
public PreferringClause(Expression preferring) {
21+
this.preferring = preferring;
22+
}
23+
24+
public void setPartitionExpressionList(ExpressionList expressionList,
25+
boolean brackets) {
26+
if (this.partitionBy == null) {
27+
this.partitionBy = new PartitionByClause();
28+
}
29+
partitionBy.setPartitionExpressionList(expressionList, brackets);
30+
}
31+
32+
public void toStringPreferring(StringBuilder b) {
33+
b.append("PREFERRING ");
34+
b.append(preferring.toString());
35+
36+
if (partitionBy != null) {
37+
b.append(" ");
38+
partitionBy.toStringPartitionBy(b);
39+
}
40+
}
41+
42+
@Override
43+
public String toString() {
44+
StringBuilder sb = new StringBuilder();
45+
toStringPreferring(sb);
46+
return sb.toString();
47+
}
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*-
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2019 JSQLParser
6+
* %%
7+
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
8+
* #L%
9+
*/
10+
package net.sf.jsqlparser.expression.operators.relational;
11+
12+
import net.sf.jsqlparser.expression.BinaryExpression;
13+
import net.sf.jsqlparser.expression.Expression;
14+
import net.sf.jsqlparser.expression.ExpressionVisitor;
15+
16+
public class Plus extends BinaryExpression {
17+
public Plus(Expression leftExpression, Expression rightExpression) {
18+
super(leftExpression, rightExpression);
19+
}
20+
21+
@Override
22+
public String getStringExpression() {
23+
return "PLUS";
24+
}
25+
26+
@Override
27+
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
28+
return expressionVisitor.visit(this, context);
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*-
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2019 JSQLParser
6+
* %%
7+
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
8+
* #L%
9+
*/
10+
package net.sf.jsqlparser.expression.operators.relational;
11+
12+
import net.sf.jsqlparser.expression.BinaryExpression;
13+
import net.sf.jsqlparser.expression.Expression;
14+
import net.sf.jsqlparser.expression.ExpressionVisitor;
15+
16+
public class PriorTo extends BinaryExpression {
17+
public PriorTo(Expression leftExpression, Expression rightExpression) {
18+
super(leftExpression, rightExpression);
19+
}
20+
21+
@Override
22+
public String getStringExpression() {
23+
return "PRIOR TO";
24+
}
25+
26+
@Override
27+
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
28+
return expressionVisitor.visit(this, context);
29+
}
30+
}

0 commit comments

Comments
 (0)