Skip to content

Commit

Permalink
Remove the workaround for NULL ON NULL (without expression)
Browse files Browse the repository at this point in the history
  • Loading branch information
manticore-projects committed Jul 11, 2021
1 parent f36eb48 commit 5dd8b47
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
12 changes: 1 addition & 11 deletions src/main/java/net/sf/jsqlparser/expression/JsonFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,20 +182,10 @@ public StringBuilder appendObject(StringBuilder builder) {
public StringBuilder appendArray(StringBuilder builder) {
builder.append("JSON_ARRAY( ");
int i = 0;
int n = expressions.size();

// @fixme: this is a workaround for NULL ON NULL parsed as expressions
// json_array(null on null)
// json_array(null null on null)
// json_array(null, null null on null)
boolean noSeparatorsForNullOnNull =
n >= 3 && expressions.get(n - 3).toString().equalsIgnoreCase("null")
&& expressions.get(n - 2).toString().equalsIgnoreCase("on")
&& expressions.get(n - 1).toString().equalsIgnoreCase("null");

for (JsonFunctionExpression expr : expressions) {
if (i > 0) {
builder.append(noSeparatorsForNullOnNull && i >= n - 3 ? " " : ", ");
builder.append(", ");
}
expr.append(builder);
i++;
Expand Down
15 changes: 7 additions & 8 deletions src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -3723,8 +3723,13 @@ JsonFunction JsonFunction() : {
(
<K_JSON_ARRAY> { result.setType( JsonFunctionType.ARRAY ); }
"("
( LOOKAHEAD(2)
(
LOOKAHEAD(2) (
<K_NULL> <K_ON> <K_NULL> { result.setOnNullType( JsonAggregateOnNullType.NULL ); }
)
|
expression=Expression() { functionExpression = new JsonFunctionExpression( expression ); result.add( functionExpression ); }

[ LOOKAHEAD(2) <K_FORMAT> <K_JSON> { functionExpression.setUsingFormatJson( true ); } ]
(
","
Expand All @@ -3734,13 +3739,7 @@ JsonFunction JsonFunction() : {
)*

[
(
<K_NULL> <K_ON> <K_NULL> { result.setOnNullType( JsonAggregateOnNullType.NULL ); }
)
|
(
<K_ABSENT> <K_ON> <K_NULL> { result.setOnNullType( JsonAggregateOnNullType.ABSENT ); }
)
<K_ABSENT> <K_ON> <K_NULL> { result.setOnNullType( JsonAggregateOnNullType.ABSENT ); }
]

")"
Expand Down

0 comments on commit 5dd8b47

Please sign in to comment.