Skip to content

Commit

Permalink
Update style
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Kwok <[email protected]>
  • Loading branch information
andy-k-improving committed Feb 5, 2025
1 parent 7da0dec commit 24eec27
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
11 changes: 8 additions & 3 deletions core/src/main/java/org/opensearch/sql/utils/JsonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,20 @@ public static ExprValue setJson(ExprValue json, ExprValue path, ExprValue valueT
if (((List<?>) readResult).isEmpty()) {
docContext.add(pathUnquoted, valueUnquoted).jsonString();
} else {
// New element in the array.
docContext.set(pathUnquoted, valueUnquoted).jsonString();
}
}
return new ExprStringValue(docContext.jsonString());

} catch (InvalidPathException e) {
final String errorFormat = "JSON path '%s' is not valid. Error details: %s";
throw new SemanticCheckException(String.format(errorFormat, path, e.getMessage()), e);

} catch (InvalidJsonException e) {
final String errorFormat = "JSON object '%s' is not valid. Error details: %s";
throw new SemanticCheckException(String.format(errorFormat, json, e.getMessage()), e);

} catch (InvalidModificationException
| InvalidJsonException
| InvalidPathException
| IllegalArgumentException
| UnsupportedOperationException ex) {
return LITERAL_NULL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,14 @@ void json_set_insert_invalid_path() {
DSL.literal("{\"members\":[{\"name\":\"alice\"}]}"),
DSL.literal("$$$$$$$$$"),
DSL.literal("18"));
assertThrows(SemanticCheckException.class, () -> functionExpression.valueOf());
}

assertEquals(LITERAL_NULL, functionExpression.valueOf());
@Test
void json_set_insert_invalid_jsonObject() {
FunctionExpression functionExpression =
DSL.jsonSet(DSL.literal("[xxxx}}}}}"), DSL.literal("$"), DSL.literal("18"));
assertThrows(SemanticCheckException.class, () -> functionExpression.valueOf());
}

@Test
Expand Down

0 comments on commit 24eec27

Please sign in to comment.