Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import net.sf.jsqlparser.expression.operators.relational.Intersects;
import net.sf.jsqlparser.expression.operators.relational.IsBooleanExpression;
import net.sf.jsqlparser.expression.operators.relational.IsDistinctExpression;
import net.sf.jsqlparser.expression.operators.relational.IsNormalizedExpression;
import net.sf.jsqlparser.expression.operators.relational.IsNullExpression;
import net.sf.jsqlparser.expression.operators.relational.IsUnknownExpression;
import net.sf.jsqlparser.expression.operators.relational.IsJsonExpression;
Expand Down Expand Up @@ -395,6 +396,14 @@ default void visit(IsUnknownExpression isUnknownExpression) {
this.visit(isUnknownExpression, null);
}

default <S> T visit(IsNormalizedExpression isNormalizedExpression, S context) {
return isNormalizedExpression.getLeftExpression().accept(this, context);
}

default void visit(IsNormalizedExpression isNormalizedExpression) {
this.visit(isNormalizedExpression, null);
}

<S> T visit(LikeExpression likeExpression, S context);

default void visit(LikeExpression likeExpression) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import net.sf.jsqlparser.expression.operators.relational.Intersects;
import net.sf.jsqlparser.expression.operators.relational.IsBooleanExpression;
import net.sf.jsqlparser.expression.operators.relational.IsDistinctExpression;
import net.sf.jsqlparser.expression.operators.relational.IsNormalizedExpression;
import net.sf.jsqlparser.expression.operators.relational.IsNullExpression;
import net.sf.jsqlparser.expression.operators.relational.IsUnknownExpression;
import net.sf.jsqlparser.expression.operators.relational.JsonOperator;
Expand Down Expand Up @@ -296,6 +297,11 @@ public <S> T visit(IsUnknownExpression isUnknownExpression, S context) {
return isUnknownExpression.getLeftExpression().accept(this, context);
}

@Override
public <S> T visit(IsNormalizedExpression isNormalizedExpression, S context) {
return isNormalizedExpression.getLeftExpression().accept(this, context);
}

@Override
public <S> T visit(LikeExpression likeExpression, S context) {
return visitExpressions(likeExpression, context, likeExpression.getLeftExpression(),
Expand Down
36 changes: 31 additions & 5 deletions src/main/java/net/sf/jsqlparser/expression/TimezoneExpression.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@

import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;

public class TimezoneExpression extends ASTNodeAccessImpl implements Expression {

private final ExpressionList<Expression> timezoneExpressions = new ExpressionList<>();
private Expression leftExpression;
private boolean atLocal;

public TimezoneExpression() {
leftExpression = null;
Expand Down Expand Up @@ -51,13 +53,37 @@ public void addTimezoneExpression(Expression... timezoneExpr) {
this.timezoneExpressions.addAll(Arrays.asList(timezoneExpr));
}

@Override
public String toString() {
StringBuilder returnValue = new StringBuilder(leftExpression.toString());
/**
* Whether the expression ends with {@code AT LOCAL}, which converts to the session time zone.
* It follows the {@code AT TIME ZONE} conversions of this expression, if there are any.
*/
public boolean isAtLocal() {
return atLocal;
}

public TimezoneExpression setAtLocal(boolean atLocal) {
this.atLocal = atLocal;
return this;
}

/**
* Appends the expression, rendering the operand and each time zone through the renderer.
*/
public StringBuilder appendTo(StringBuilder builder, Consumer<Expression> expressionRenderer) {
expressionRenderer.accept(leftExpression);
for (Expression expr : timezoneExpressions) {
returnValue.append(" AT TIME ZONE ").append(expr.toString());
builder.append(" AT TIME ZONE ");
expressionRenderer.accept(expr);
}
if (atLocal) {
builder.append(" AT LOCAL");
}
return builder;
}

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

import java.util.function.Consumer;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.ExpressionVisitor;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;

/**
* The Unicode normalization test {@code expression IS [NOT] [NFC | NFD | NFKC | NFKD] NORMALIZED}.
*/
public class IsNormalizedExpression extends ASTNodeAccessImpl implements Expression {
/** The Unicode normalization forms. */
public enum NormalForm {
NFC, NFD, NFKC, NFKD;

/** Whether the word names a normalization form, in any case. */
public static boolean isNormalForm(String word) {
for (NormalForm form : values()) {
if (form.name().equalsIgnoreCase(word)) {
return true;
}
}
return false;
}
}

private Expression leftExpression;
private boolean not;
private NormalForm normalForm;

public IsNormalizedExpression() {
// empty constructor
}

public IsNormalizedExpression(Expression leftExpression) {
this.leftExpression = leftExpression;
}

public Expression getLeftExpression() {
return leftExpression;
}

public void setLeftExpression(Expression leftExpression) {
this.leftExpression = leftExpression;
}

public IsNormalizedExpression withLeftExpression(Expression leftExpression) {
this.setLeftExpression(leftExpression);
return this;
}

public <E extends Expression> E getLeftExpression(Class<E> type) {
return type.cast(getLeftExpression());
}

public boolean isNot() {
return not;
}

public void setNot(boolean not) {
this.not = not;
}

public IsNormalizedExpression withNot(boolean not) {
this.setNot(not);
return this;
}

/** The normalization form as written, or null when it is omitted (the server tests NFC). */
public NormalForm getNormalForm() {
return normalForm;
}

public void setNormalForm(NormalForm normalForm) {
this.normalForm = normalForm;
}

public IsNormalizedExpression withNormalForm(NormalForm normalForm) {
this.setNormalForm(normalForm);
return this;
}

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

/** Appends the test, rendering the operand through the renderer. */
public StringBuilder appendTo(StringBuilder builder, Consumer<Expression> expressionRenderer) {
expressionRenderer.accept(leftExpression);
builder.append(not ? " IS NOT " : " IS ");
if (normalForm != null) {
builder.append(normalForm).append(' ');
}
return builder.append("NORMALIZED");
}

@Override
public String toString() {
StringBuilder builder = new StringBuilder();
return appendTo(builder, builder::append).toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1101,9 +1101,8 @@ public <S> Void visit(PlainSelect plainSelect, S context) {

// SELECT .. INTO <table> materialises rows instead of returning them, so the
// RETURNS_RESULT_SET claimed by the statement visit has to be withdrawn
boolean into = plainSelect.getIntoTables() != null
&& !plainSelect.getIntoTables().isEmpty()
|| plainSelect.getIntoTempTable() != null;
boolean into = plainSelect.getIntoClause() != null
&& !plainSelect.getIntoClause().getTables().isEmpty();
if (into) {
analysis.certain(StmtFeature.MODIFIES_DATA, StmtFeature.MODIFIES_SCHEMA);
analysis.certain.remove(StmtFeature.RETURNS_RESULT_SET);
Expand Down
35 changes: 33 additions & 2 deletions src/main/java/net/sf/jsqlparser/statement/select/Join.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
package net.sf.jsqlparser.statement.select;

import net.sf.jsqlparser.expression.Alias;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
import net.sf.jsqlparser.schema.Column;
Expand All @@ -25,6 +26,7 @@ public class Join extends ASTNodeAccessImpl {

private final LinkedList<Expression> onExpressions = new LinkedList<>();
private final LinkedList<Column> usingColumns = new LinkedList<>();
private Alias usingAlias;
private boolean asOf = false;
private boolean outer = false;
private boolean right = false;
Expand Down Expand Up @@ -494,6 +496,23 @@ public Join withUsingColumns(List<Column> list) {
return this;
}

/**
* The alias of the USING columns, as in PostgreSQL's {@code a JOIN b USING (id) AS j}: a table
* alias that exposes only the columns listed in USING. Null when there is none.
*/
public Alias getUsingAlias() {
return usingAlias;
}

public void setUsingAlias(Alias usingAlias) {
this.usingAlias = usingAlias;
}

public Join withUsingAlias(Alias usingAlias) {
this.setUsingAlias(usingAlias);
return this;
}

public boolean isWindowJoin() {
return joinWindow != null;
}
Expand Down Expand Up @@ -617,11 +636,23 @@ public String toString() {
for (Expression onExpression : onExpressions) {
builder.append(" ON ").append(onExpression);
}
appendUsingTo(builder);

return builder.toString();
}

/**
* Appends {@code USING (columns) [AS alias]} with a leading space, or nothing when the join has
* no USING columns.
*/
public StringBuilder appendUsingTo(StringBuilder builder) {
if (!usingColumns.isEmpty()) {
builder.append(PlainSelect.getFormattedList(usingColumns, "USING", true, true));
if (usingAlias != null) {
builder.append(" AS ").append(usingAlias.getName());
}
}

return builder.toString();
return builder;
}

public Join addUsingColumns(Column... usingColumns) {
Expand Down
Loading
Loading