Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
[chore] Started to add oracle JSON_TABLE features
  • Loading branch information
ANeumann82 committed Mar 15, 2026
commit d39df7fc01be69a86342c083588fc88b9ef5c797
19 changes: 18 additions & 1 deletion src/main/java/net/sf/jsqlparser/expression/JsonFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
public class JsonFunction extends ASTNodeAccessImpl implements Expression {
public enum JsonOnResponseBehaviorType {
ERROR, NULL, DEFAULT, EMPTY_ARRAY, EMPTY_OBJECT, TRUE, FALSE, UNKNOWN
ERROR, NULL, DEFAULT, EMPTY, EMPTY_ARRAY, EMPTY_OBJECT, TRUE, FALSE, UNKNOWN
}

public enum JsonWrapperType {
Expand All @@ -42,6 +42,10 @@ public enum JsonQuotesType {
KEEP, OMIT
}

public enum ScalarsType {
ALLOW, DISALLOW
}

public static class JsonOnResponseBehavior {
private JsonOnResponseBehaviorType type;
private Expression expression;
Expand Down Expand Up @@ -82,6 +86,9 @@ public StringBuilder append(StringBuilder builder) {
case DEFAULT:
builder.append("DEFAULT ").append(expression);
break;
case EMPTY:
builder.append("EMPTY ");
break;
case EMPTY_ARRAY:
builder.append("EMPTY ARRAY");
break;
Expand All @@ -98,6 +105,7 @@ public StringBuilder append(StringBuilder builder) {
builder.append("UNKNOWN");
break;
default:
throw new IllegalStateException("Unhandled JsonOnResponseBehavior: " + type );
// this should never happen
}
return builder;
Expand Down Expand Up @@ -130,6 +138,7 @@ public String toString() {
private boolean wrapperArray;
private JsonQuotesType quotesType;
private boolean quotesOnScalarString;
private ScalarsType scalarsType;

public JsonFunction() {}

Expand Down Expand Up @@ -294,6 +303,14 @@ public void setQuotesOnScalarString(boolean quotesOnScalarString) {
this.quotesOnScalarString = quotesOnScalarString;
}

public ScalarsType getScalarsType() {
return scalarsType;
}

public void setScalarsType(ScalarsType type) {
this.scalarsType = type;
}

public boolean isEmpty() {
return keyValuePairs.isEmpty();
}
Expand Down
26 changes: 22 additions & 4 deletions src/main/java/net/sf/jsqlparser/expression/JsonTableFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public String getDisplay() {
}

public enum JsonTableOnErrorType {
ERROR, EMPTY
ERROR, NULL, EMPTY
}

public static class JsonTablePassingClause extends ASTNodeAccessImpl implements Serializable {
Expand Down Expand Up @@ -395,6 +395,7 @@ public static class JsonTableValueColumnDefinition extends JsonTableColumnDefini
private JsonTableQuotesClause quotesClause;
private JsonFunction.JsonOnResponseBehavior onEmptyBehavior;
private JsonFunction.JsonOnResponseBehavior onErrorBehavior;
private JsonFunction.ScalarsType scalarsType;

public String getColumnName() {
return columnName;
Expand Down Expand Up @@ -489,6 +490,14 @@ public JsonTableValueColumnDefinition setOnErrorBehavior(
return this;
}

public void setScalarsType(JsonFunction.ScalarsType scalarsType) {
this.scalarsType = scalarsType;
}

public JsonFunction.ScalarsType getScalarsType() {
return scalarsType;
}

@Override
public void collectExpressions(List<Expression> expressions) {
if (pathExpression != null) {
Expand All @@ -509,14 +518,20 @@ public String toString() {
builder.append(" FOR ORDINALITY");
return builder.toString();
}

builder.append(" ").append(dataType);
if (dataType != null) {
builder.append(" ").append(dataType);
}
if (formatJson) {
builder.append(" FORMAT JSON");
if (encoding != null) {
builder.append(" ENCODING ").append(encoding);
}
}
if (scalarsType != null) {
builder.append(" ");
builder.append(scalarsType);
builder.append(" SCALARS");
}
if (pathExpression != null) {
builder.append(" PATH ").append(pathExpression);
}
Expand Down Expand Up @@ -676,7 +691,10 @@ public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
@Override
public String toString() {
StringBuilder builder = new StringBuilder("JSON_TABLE(");
builder.append(jsonInputExpression).append(", ").append(jsonPathExpression);
builder.append(jsonInputExpression);
if (jsonPathExpression != null) {
builder.append(", ").append(jsonPathExpression);
}
if (pathName != null) {
builder.append(" AS ").append(pathName);
}
Expand Down
Loading
Loading