Skip to content

Commit

Permalink
feat: Implement skyline syntax (preferring clause)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Steinhauser committed Sep 13, 2024
1 parent 60f4d74 commit c2f3305
Show file tree
Hide file tree
Showing 23 changed files with 691 additions and 283 deletions.
59 changes: 31 additions & 28 deletions src/main/java/net/sf/jsqlparser/expression/ExpressionVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,7 @@
import net.sf.jsqlparser.expression.operators.conditional.AndExpression;
import net.sf.jsqlparser.expression.operators.conditional.OrExpression;
import net.sf.jsqlparser.expression.operators.conditional.XorExpression;
import net.sf.jsqlparser.expression.operators.relational.Between;
import net.sf.jsqlparser.expression.operators.relational.ContainedBy;
import net.sf.jsqlparser.expression.operators.relational.Contains;
import net.sf.jsqlparser.expression.operators.relational.DoubleAnd;
import net.sf.jsqlparser.expression.operators.relational.EqualsTo;
import net.sf.jsqlparser.expression.operators.relational.ExcludesExpression;
import net.sf.jsqlparser.expression.operators.relational.ExistsExpression;
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
import net.sf.jsqlparser.expression.operators.relational.FullTextSearch;
import net.sf.jsqlparser.expression.operators.relational.GeometryDistance;
import net.sf.jsqlparser.expression.operators.relational.GreaterThan;
import net.sf.jsqlparser.expression.operators.relational.GreaterThanEquals;
import net.sf.jsqlparser.expression.operators.relational.InExpression;
import net.sf.jsqlparser.expression.operators.relational.IncludesExpression;
import net.sf.jsqlparser.expression.operators.relational.IsBooleanExpression;
import net.sf.jsqlparser.expression.operators.relational.IsDistinctExpression;
import net.sf.jsqlparser.expression.operators.relational.IsNullExpression;
import net.sf.jsqlparser.expression.operators.relational.JsonOperator;
import net.sf.jsqlparser.expression.operators.relational.LikeExpression;
import net.sf.jsqlparser.expression.operators.relational.Matches;
import net.sf.jsqlparser.expression.operators.relational.MemberOfExpression;
import net.sf.jsqlparser.expression.operators.relational.MinorThan;
import net.sf.jsqlparser.expression.operators.relational.MinorThanEquals;
import net.sf.jsqlparser.expression.operators.relational.NotEqualsTo;
import net.sf.jsqlparser.expression.operators.relational.RegExpMatchOperator;
import net.sf.jsqlparser.expression.operators.relational.SimilarToExpression;
import net.sf.jsqlparser.expression.operators.relational.TSQLLeftJoin;
import net.sf.jsqlparser.expression.operators.relational.TSQLRightJoin;
import net.sf.jsqlparser.expression.operators.relational.*;
import net.sf.jsqlparser.schema.Column;
import net.sf.jsqlparser.statement.select.AllColumns;
import net.sf.jsqlparser.statement.select.AllTableColumns;
Expand Down Expand Up @@ -633,4 +606,34 @@ default void visit(StructType structType) {
default void visit(LambdaExpression lambdaExpression) {
this.visit(lambdaExpression, null);
}

<S> T visit(HighExpression highExpression, S context);

default void visit(HighExpression highExpression) {
this.visit(highExpression, null);
}

<S> T visit(LowExpression lowExpression, S context);

default void visit(LowExpression lowExpression) {
this.visit(lowExpression, null);
}

<S> T visit(Plus plus, S context);

default void visit(Plus plus) {
this.visit(plus, null);
}

<S> T visit(PriorTo priorTo, S context);

default void visit(PriorTo priorTo) {
this.visit(priorTo, null);
}

<S> T visit(Inverse inverse, S context);

default void visit(Inverse inverse) {
this.visit(inverse, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -762,4 +762,29 @@ public <S> T visit(LambdaExpression lambdaExpression, S context) {
return lambdaExpression.getExpression().accept(this, context);
}

@Override
public <S> T visit(HighExpression highExpression, S context) {
return highExpression.getExpression().accept(this, context);
}

@Override
public <S> T visit(LowExpression lowExpression, S context) {
return lowExpression.getExpression().accept(this, context);
}

@Override
public <S> T visit(Plus plus, S context) {
return visitBinaryExpression(plus, context);
}

@Override
public <S> T visit(PriorTo priorTo, S context) {
return visitBinaryExpression(priorTo, context);
}

@Override
public <S> T visit(Inverse inverse, S context) {
return inverse.getExpression().accept(this, context);
}

}
42 changes: 42 additions & 0 deletions src/main/java/net/sf/jsqlparser/expression/HighExpression.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;

import net.sf.jsqlparser.parser.ASTNodeAccessImpl;

public class HighExpression extends ASTNodeAccessImpl implements Expression {
private Expression expression;

public HighExpression() {
// empty constructor
}

public HighExpression(Expression expression) {
this.expression = expression;
}

@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}

public Expression getExpression() {
return expression;
}

public void setExpression(Expression expression) {
this.expression = expression;
}

@Override
public String toString() {
return "HIGH " + expression.toString();
}
}
42 changes: 42 additions & 0 deletions src/main/java/net/sf/jsqlparser/expression/Inverse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;

import net.sf.jsqlparser.parser.ASTNodeAccessImpl;

public class Inverse extends ASTNodeAccessImpl implements Expression {
private Expression expression;

public Inverse() {
// empty constructor
}

public Inverse(Expression expression) {
this.expression = expression;
}

@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}

public Expression getExpression() {
return expression;
}

public void setExpression(Expression expression) {
this.expression = expression;
}

@Override
public String toString() {
return "INVERSE (" + expression.toString() + ")";
}
}
42 changes: 42 additions & 0 deletions src/main/java/net/sf/jsqlparser/expression/LowExpression.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;

import net.sf.jsqlparser.parser.ASTNodeAccessImpl;

public class LowExpression extends ASTNodeAccessImpl implements Expression {
private Expression expression;

public LowExpression() {
// empty constructor
}

public LowExpression(Expression expression) {
this.expression = expression;
}

@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}

public Expression getExpression() {
return expression;
}

public void setExpression(Expression expression) {
this.expression = expression;
}

@Override
public String toString() {
return "LOW " + expression.toString();
}
}
48 changes: 48 additions & 0 deletions src/main/java/net/sf/jsqlparser/expression/PreferringClause.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;

import net.sf.jsqlparser.expression.operators.relational.ExpressionList;

import java.io.Serializable;

public class PreferringClause implements Serializable {
private Expression preferring;
private PartitionByClause partitionBy;

public PreferringClause(Expression preferring) {
this.preferring = preferring;
}

public void setPartitionExpressionList(ExpressionList expressionList,
boolean brackets) {
if (this.partitionBy == null) {
this.partitionBy = new PartitionByClause();
}
partitionBy.setPartitionExpressionList(expressionList, brackets);
}

public void toStringPreferring(StringBuilder b) {
b.append("PREFERRING ");
b.append(preferring.toString());

if (partitionBy != null) {
b.append(" ");
partitionBy.toStringPartitionBy(b);
}
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
toStringPreferring(sb);
return sb.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression.operators.relational;

import net.sf.jsqlparser.expression.BinaryExpression;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.ExpressionVisitor;

public class Plus extends BinaryExpression {
public Plus(Expression leftExpression, Expression rightExpression) {
super(leftExpression, rightExpression);
}

@Override
public String getStringExpression() {
return "PLUS";
}

@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression.operators.relational;

import net.sf.jsqlparser.expression.BinaryExpression;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.ExpressionVisitor;

public class PriorTo extends BinaryExpression {
public PriorTo(Expression leftExpression, Expression rightExpression) {
super(leftExpression, rightExpression);
}

@Override
public String getStringExpression() {
return "PRIOR TO";
}

@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public class ParserKeywordsUtils {
{"GROUPING", RESTRICTED_ALIAS},
{"QUALIFY", RESTRICTED_ALIAS},
{"HAVING", RESTRICTED_SQL2016},
{"HIGH", RESTRICTED_JSQLPARSER},
{"IF", RESTRICTED_SQL2016},
{"IIF", RESTRICTED_ALIAS},
{"IGNORE", RESTRICTED_ALIAS},
Expand All @@ -89,12 +90,14 @@ public class ParserKeywordsUtils {
{"INTERSECT", RESTRICTED_SQL2016},
{"INTERVAL", RESTRICTED_SQL2016},
{"INTO", RESTRICTED_JSQLPARSER},
{"INVERSE", RESTRICTED_JSQLPARSER},
{"IS", RESTRICTED_SQL2016},
{"JOIN", RESTRICTED_JSQLPARSER},
{"LATERAL", RESTRICTED_SQL2016},
{"LEFT", RESTRICTED_SQL2016},
{"LIKE", RESTRICTED_SQL2016},
{"LIMIT", RESTRICTED_SQL2016},
{"LOW", RESTRICTED_JSQLPARSER},
{"MINUS", RESTRICTED_SQL2016},
{"NATURAL", RESTRICTED_SQL2016},
{"NOCYCLE", RESTRICTED_JSQLPARSER},
Expand All @@ -110,6 +113,8 @@ public class ParserKeywordsUtils {
{"OUTPUT", RESTRICTED_JSQLPARSER},
{"OPTIMIZE ", RESTRICTED_JSQLPARSER},
{"PIVOT", RESTRICTED_JSQLPARSER},
{"PLUS", RESTRICTED_JSQLPARSER},
{"PREFERRING", RESTRICTED_JSQLPARSER},
{"PROCEDURE", RESTRICTED_ALIAS},
{"PUBLIC", RESTRICTED_ALIAS},
{"RETURNING", RESTRICTED_JSQLPARSER},
Expand Down
Loading

0 comments on commit c2f3305

Please sign in to comment.