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] spotless
  • Loading branch information
ANeumann82 committed Apr 1, 2026
commit 96c40e10ed723f3882c19cfceebd49db95d190e4
4 changes: 2 additions & 2 deletions src/main/java/net/sf/jsqlparser/expression/JsonFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ public StringBuilder append(StringBuilder builder) {
builder.append("UNKNOWN");
break;
default:
throw new IllegalStateException("Unhandled JsonOnResponseBehavior: " + type );
// this should never happen
throw new IllegalStateException("Unhandled JsonOnResponseBehavior: " + type);
// this should never happen
}
return builder;
}
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/net/sf/jsqlparser/expression/JsonTableFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,15 @@ public static class JsonTableWrapperClause extends ASTNodeAccessImpl implements
private boolean array;

/**
* Creates a wrapper clause. Depending on the dialect, this clause can come before or after the PATH expression.
* Creates a wrapper clause. Depending on the dialect, this clause can come before or after
* the PATH expression.
* <ul>
* <li>Trino: after PATH</li>
* <li>Oracle: before PATH</li>
* <li>Trino: after PATH</li>
* <li>Oracle: before PATH</li>
* </ul>
*
* @param beforePathExpression A flag to determine wether the clause is rendered before or after the PATH expression
* @param beforePathExpression A flag to determine wether the clause is rendered before or
* after the PATH expression
*/
public JsonTableWrapperClause(boolean beforePathExpression) {
this.beforePathExpression = beforePathExpression;
Expand Down Expand Up @@ -213,8 +215,7 @@ public String toString() {
public static class JsonTableOnEmptyClause extends ASTNodeAccessImpl implements Serializable {
private JsonTableOnEmptyType type;

public JsonTableOnEmptyClause() {
}
public JsonTableOnEmptyClause() {}

public JsonTableOnEmptyType getType() {
return type;
Expand All @@ -231,11 +232,11 @@ public String toString() {
}
}

public static class JsonTableParsingTypeClause extends ASTNodeAccessImpl implements Serializable {
public static class JsonTableParsingTypeClause extends ASTNodeAccessImpl
implements Serializable {
private JsonTableParsingType type;

public JsonTableParsingTypeClause() {
}
public JsonTableParsingTypeClause() {}

public JsonTableParsingType getType() {
return type;
Expand Down
228 changes: 119 additions & 109 deletions src/test/java/net/sf/jsqlparser/statement/from/JsonTableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ void testExistsColumns(String jsonTableStr) throws JSQLParserException {
"JSON_TABLE(document COLUMNS( val VARCHAR2(240) FORMAT JSON PATH '$.pathTest'))",

// These would require adapting ColDataType in Line 10176
// "JSON_TABLE(document COLUMNS( val VARCHAR2(500 BYTE) PATH '$.pathTest'))",
// "JSON_TABLE(document COLUMNS( val VARCHAR2(100 CHAR) PATH '$.pathTest'))",
// "JSON_TABLE(document COLUMNS( val VARCHAR2(500 BYTE) PATH '$.pathTest'))",
// "JSON_TABLE(document COLUMNS( val VARCHAR2(100 CHAR) PATH '$.pathTest'))",
"JSON_TABLE(document COLUMNS( val VARCHAR2 FORMAT JSON DISALLOW SCALARS WITH UNCONDITIONAL ARRAY WRAPPER PATH '$.pathTest' EMPTY OBJECT ON ERROR))",
})
void testQueryColumns(String jsonTableStr) throws JSQLParserException {
Expand Down Expand Up @@ -130,148 +130,158 @@ void testNullOnError() throws JSQLParserException {
String expression = "JSON_TABLE(document NULL ON ERROR COLUMNS( id FOR ORDINALITY))";
JsonTableFunction table = parseTable(expression);

assertThat(table.getOnErrorClause().getType()).isEqualTo(JsonTableFunction.JsonTableOnErrorType.NULL);
assertThat(table.getOnErrorClause().getType())
.isEqualTo(JsonTableFunction.JsonTableOnErrorType.NULL);
}

@Test
void testErrorOnError() throws JSQLParserException {
String expression = "JSON_TABLE(document ERROR ON ERROR COLUMNS( id FOR ORDINALITY))";
JsonTableFunction table = parseTable(expression);
JsonTableFunction table = parseTable(expression);

assertThat(table.getOnErrorClause().getType()).isEqualTo(JsonTableFunction.JsonTableOnErrorType.ERROR);
assertThat(table.getOnErrorClause().getType())
.isEqualTo(JsonTableFunction.JsonTableOnErrorType.ERROR);
}

@Test
void testNullOnEmpty() throws JSQLParserException {
String expression = "JSON_TABLE(document NULL ON EMPTY COLUMNS( id FOR ORDINALITY))";
JsonTableFunction table = parseTable(expression);
JsonTableFunction table = parseTable(expression);

assertThat(table.getOnEmptyClause().getType()).isEqualTo(JsonTableFunction.JsonTableOnEmptyType.NULL);
assertThat(table.getOnEmptyClause().getType())
.isEqualTo(JsonTableFunction.JsonTableOnEmptyType.NULL);
}

@Test
void testErrorOnEmpty() throws JSQLParserException {
String expression = "JSON_TABLE(document ERROR ON EMPTY COLUMNS( id FOR ORDINALITY))";
JsonTableFunction table = parseTable(expression);

assertThat(table.getOnEmptyClause().getType()).isEqualTo(JsonTableFunction.JsonTableOnEmptyType.ERROR);
assertThat(table.getOnEmptyClause().getType())
.isEqualTo(JsonTableFunction.JsonTableOnEmptyType.ERROR);
}

@Test
void testParsingTypeLax() throws JSQLParserException {
String expression = "JSON_TABLE(document TYPE(LAX) COLUMNS( id FOR ORDINALITY))";
JsonTableFunction table = parseTable(expression);

assertThat(table.getParsingTypeClause().getType()).isEqualTo(JsonTableFunction.JsonTableParsingType.LAX);
assertThat(table.getParsingTypeClause().getType())
.isEqualTo(JsonTableFunction.JsonTableParsingType.LAX);
}

@Test
void testParsingTypeStrict() throws JSQLParserException {
String expression = "JSON_TABLE(document TYPE(STRICT) COLUMNS( id FOR ORDINALITY))";
JsonTableFunction table = parseTable(expression);

assertThat(table.getParsingTypeClause().getType()).isEqualTo(JsonTableFunction.JsonTableParsingType.STRICT);
assertThat(table.getParsingTypeClause().getType())
.isEqualTo(JsonTableFunction.JsonTableParsingType.STRICT);
}

// @Test
// void testColumnTypeExists() throws JSQLParserException {
// String expression = "JSON_TABLE(document COLUMNS( hasValue EXISTS PATH '$.pathTest'))";
// JsonTableFunction table = parseTable(expression);
//
// assertThat(table.getColumnsClause().getColumnDefinitions()).hasSize(1);
//
// JsonTableFunction.JsonTableColumnDefinition col = table.getColumnsClause().getColumnDefinitions().get(0);
// assertThat(col.getType()).isEqualTo(JsonTableColumnType.JSON_EXISTS);
// }

// @Test
// void testBuilder() {
// Column c = new Column("document");
//
// JsonTable table = new JsonTable().withExpression(c)
// .withPathExpression("$.subPath")
// .withFormatJson(true)
// .withType(JsonTableType.STRICT)
// .withOnEmptyType(JsonOnEmptyType.NULL)
// .withOnErrorType(JsonOnErrorType.ERROR)
// .withColumn(new JsonTableColumn().withName("id")
// .withType(JsonTableColumnType.ORDINALITY));
//
// assertThat(table.toString()).isEqualTo(
// "JSON_TABLE(document FORMAT JSON, '$.subPath' ERROR ON ERROR TYPE(STRICT) NULL ON EMPTY COLUMNS(id FOR ORDINALITY))");
// }

// @Test
// void testValidSetters() {
// JsonTableFunction table = new JsonTableFunction();
//
// JsonTableFunction.JsonTableOnEmptyClause onEmptyClause = new JsonTableFunction.JsonTableOnEmptyClause();
// JsonTableFunction.JsonTableOnErrorClause onErrorClause = new JsonTableFunction.JsonTableOnErrorClause(true);
//
// assertThatNoException().isThrownBy(() -> {
// table.setOnEmptyClause(null);
// onEmptyClause.setType(JsonTableFunction.JsonTableOnEmptyType.NULL);
// onEmptyClause.setType(JsonTableFunction.JsonTableOnEmptyType.ERROR);
//
// onErrorClause.setOnErrorType(null);
// onErrorClause.setOnErrorType(JsonTableFunction.JsonTableOnErrorType);
// onErrorClause.setOnErrorType(JsonOnErrorType.ERROR);
//
// table.setType(null);
// table.setType(JsonTableType.LAX);
// table.setType(JsonTableType.STRICT);
// });
// }

// @Test
// void testInvalidSetters() {
// JsonTableFunction table = new JsonTable();
//
// assertThatThrownBy(() -> table.setOnEmptyType(JsonOnEmptyType.EMPTY))
// .isInstanceOf(IllegalArgumentException.class);
// assertThatThrownBy(() -> table.setOnEmptyType(JsonOnEmptyType.EMPTY_ARRAY))
// .isInstanceOf(IllegalArgumentException.class);
// assertThatThrownBy(() -> table.setOnEmptyType(JsonOnEmptyType.EMPTY_OBJECT))
// .isInstanceOf(IllegalArgumentException.class);
// assertThatThrownBy(() -> table.setOnEmptyType(JsonOnEmptyType.FALSE))
// .isInstanceOf(IllegalArgumentException.class);
// assertThatThrownBy(() -> table.setOnEmptyType(JsonOnEmptyType.TRUE))
// .isInstanceOf(IllegalArgumentException.class);
// assertThatThrownBy(() -> table.setOnEmptyType(JsonOnEmptyType.DEFAULT))
// .isInstanceOf(IllegalArgumentException.class);
//
// assertThatThrownBy(() -> table.setOnErrorType(JsonOnErrorType.EMPTY))
// .isInstanceOf(IllegalArgumentException.class);
// assertThatThrownBy(() -> table.setOnErrorType(JsonOnErrorType.EMPTY_ARRAY))
// .isInstanceOf(IllegalArgumentException.class);
// assertThatThrownBy(() -> table.setOnErrorType(JsonOnErrorType.EMPTY_OBJECT))
// .isInstanceOf(IllegalArgumentException.class);
// assertThatThrownBy(() -> table.setOnErrorType(JsonOnErrorType.FALSE))
// .isInstanceOf(IllegalArgumentException.class);
// assertThatThrownBy(() -> table.setOnErrorType(JsonOnErrorType.TRUE))
// .isInstanceOf(IllegalArgumentException.class);
// assertThatThrownBy(() -> table.setOnErrorType(JsonOnErrorType.DEFAULT))
// .isInstanceOf(IllegalArgumentException.class);
//
// JsonTableColumn column = new JsonTableColumn();
//
// assertThatThrownBy(() -> {
// column.setType(JsonTableColumnType.JSON_EXISTS);
// column.setFormatJson(true);
// }).isInstanceOf(IllegalArgumentException.class);
// assertThatThrownBy(() -> {
// column.setType(JsonTableColumnType.JSON_VALUE);
// column.setFormatJson(true);
// }).isInstanceOf(IllegalArgumentException.class);
// assertThatThrownBy(() -> {
// column.setType(JsonTableColumnType.ORDINALITY);
// column.setFormatJson(true);
// }).isInstanceOf(IllegalArgumentException.class);
// assertThatThrownBy(() -> {
// column.setType(JsonTableColumnType.JSON_NESTED_PATH);
// column.setFormatJson(true);
// }).isInstanceOf(IllegalArgumentException.class);
// }
// @Test
// void testColumnTypeExists() throws JSQLParserException {
// String expression = "JSON_TABLE(document COLUMNS( hasValue EXISTS PATH '$.pathTest'))";
// JsonTableFunction table = parseTable(expression);
//
// assertThat(table.getColumnsClause().getColumnDefinitions()).hasSize(1);
//
// JsonTableFunction.JsonTableColumnDefinition col =
// table.getColumnsClause().getColumnDefinitions().get(0);
// assertThat(col.getType()).isEqualTo(JsonTableColumnType.JSON_EXISTS);
// }

// @Test
// void testBuilder() {
// Column c = new Column("document");
//
// JsonTable table = new JsonTable().withExpression(c)
// .withPathExpression("$.subPath")
// .withFormatJson(true)
// .withType(JsonTableType.STRICT)
// .withOnEmptyType(JsonOnEmptyType.NULL)
// .withOnErrorType(JsonOnErrorType.ERROR)
// .withColumn(new JsonTableColumn().withName("id")
// .withType(JsonTableColumnType.ORDINALITY));
//
// assertThat(table.toString()).isEqualTo(
// "JSON_TABLE(document FORMAT JSON, '$.subPath' ERROR ON ERROR TYPE(STRICT) NULL ON EMPTY
// COLUMNS(id FOR ORDINALITY))");
// }

// @Test
// void testValidSetters() {
// JsonTableFunction table = new JsonTableFunction();
//
// JsonTableFunction.JsonTableOnEmptyClause onEmptyClause = new
// JsonTableFunction.JsonTableOnEmptyClause();
// JsonTableFunction.JsonTableOnErrorClause onErrorClause = new
// JsonTableFunction.JsonTableOnErrorClause(true);
//
// assertThatNoException().isThrownBy(() -> {
// table.setOnEmptyClause(null);
// onEmptyClause.setType(JsonTableFunction.JsonTableOnEmptyType.NULL);
// onEmptyClause.setType(JsonTableFunction.JsonTableOnEmptyType.ERROR);
//
// onErrorClause.setOnErrorType(null);
// onErrorClause.setOnErrorType(JsonTableFunction.JsonTableOnErrorType);
// onErrorClause.setOnErrorType(JsonOnErrorType.ERROR);
//
// table.setType(null);
// table.setType(JsonTableType.LAX);
// table.setType(JsonTableType.STRICT);
// });
// }

// @Test
// void testInvalidSetters() {
// JsonTableFunction table = new JsonTable();
//
// assertThatThrownBy(() -> table.setOnEmptyType(JsonOnEmptyType.EMPTY))
// .isInstanceOf(IllegalArgumentException.class);
// assertThatThrownBy(() -> table.setOnEmptyType(JsonOnEmptyType.EMPTY_ARRAY))
// .isInstanceOf(IllegalArgumentException.class);
// assertThatThrownBy(() -> table.setOnEmptyType(JsonOnEmptyType.EMPTY_OBJECT))
// .isInstanceOf(IllegalArgumentException.class);
// assertThatThrownBy(() -> table.setOnEmptyType(JsonOnEmptyType.FALSE))
// .isInstanceOf(IllegalArgumentException.class);
// assertThatThrownBy(() -> table.setOnEmptyType(JsonOnEmptyType.TRUE))
// .isInstanceOf(IllegalArgumentException.class);
// assertThatThrownBy(() -> table.setOnEmptyType(JsonOnEmptyType.DEFAULT))
// .isInstanceOf(IllegalArgumentException.class);
//
// assertThatThrownBy(() -> table.setOnErrorType(JsonOnErrorType.EMPTY))
// .isInstanceOf(IllegalArgumentException.class);
// assertThatThrownBy(() -> table.setOnErrorType(JsonOnErrorType.EMPTY_ARRAY))
// .isInstanceOf(IllegalArgumentException.class);
// assertThatThrownBy(() -> table.setOnErrorType(JsonOnErrorType.EMPTY_OBJECT))
// .isInstanceOf(IllegalArgumentException.class);
// assertThatThrownBy(() -> table.setOnErrorType(JsonOnErrorType.FALSE))
// .isInstanceOf(IllegalArgumentException.class);
// assertThatThrownBy(() -> table.setOnErrorType(JsonOnErrorType.TRUE))
// .isInstanceOf(IllegalArgumentException.class);
// assertThatThrownBy(() -> table.setOnErrorType(JsonOnErrorType.DEFAULT))
// .isInstanceOf(IllegalArgumentException.class);
//
// JsonTableColumn column = new JsonTableColumn();
//
// assertThatThrownBy(() -> {
// column.setType(JsonTableColumnType.JSON_EXISTS);
// column.setFormatJson(true);
// }).isInstanceOf(IllegalArgumentException.class);
// assertThatThrownBy(() -> {
// column.setType(JsonTableColumnType.JSON_VALUE);
// column.setFormatJson(true);
// }).isInstanceOf(IllegalArgumentException.class);
// assertThatThrownBy(() -> {
// column.setType(JsonTableColumnType.ORDINALITY);
// column.setFormatJson(true);
// }).isInstanceOf(IllegalArgumentException.class);
// assertThatThrownBy(() -> {
// column.setType(JsonTableColumnType.JSON_NESTED_PATH);
// column.setFormatJson(true);
// }).isInstanceOf(IllegalArgumentException.class);
// }

private JsonTableFunction parseTable(String jsonTableStr) throws JSQLParserException {
String sql = "SELECT * FROM " + jsonTableStr;
Expand Down
Loading