Skip to content

Commit cd78ddd

Browse files
committed
fixed integ tests
Signed-off-by: Kenrick Yap <[email protected]>
1 parent 2cd10a2 commit cd78ddd

File tree

3 files changed

+5
-13
lines changed

3 files changed

+5
-13
lines changed

core/src/main/java/org/opensearch/sql/expression/json/JsonFunctions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ private DefaultFunctionResolver jsonFunction() {
4040
private DefaultFunctionResolver jsonExtract() {
4141
return define(
4242
BuiltinFunctionName.JSON_EXTRACT.getName(),
43-
impl(nullMissingHandling(JsonUtils::extractJson), UNDEFINED, STRING, STRING));
43+
impl(JsonUtils::extractJson, UNDEFINED, STRING, STRING));
4444
}
4545
}

core/src/main/java/org/opensearch/sql/utils/JsonUtils.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,9 @@ public static ExprValue extractJson(ExprValue json, ExprValue path) {
7272
List<String> resultPaths = JsonPath.using(config).parse(jsonString).read(jsonPath);
7373

7474
List<ExprValue> elements = new LinkedList<>();
75-
7675
for (String resultPath : resultPaths) {
7776
Object result = JsonPath.parse(jsonString).read(resultPath);
78-
String resultJsonString = new ObjectMapper().writeValueAsString(result);
79-
try {
80-
elements.add(processJsonNode(jsonStringToNode(resultJsonString)));
81-
} catch (SemanticCheckException e) {
82-
elements.add(new ExprStringValue(resultJsonString));
83-
}
77+
elements.add(ExprValueUtils.fromObjectValue(result));
8478
}
8579

8680
if (elements.size() == 1) {
@@ -90,7 +84,7 @@ public static ExprValue extractJson(ExprValue json, ExprValue path) {
9084
}
9185
} catch (PathNotFoundException e) {
9286
return LITERAL_NULL;
93-
} catch (InvalidJsonException | JsonProcessingException e) {
87+
} catch (InvalidJsonException e) {
9488
final String errorFormat = "JSON string '%s' is not valid. Error details: %s";
9589
throw new SemanticCheckException(String.format(errorFormat, json, e.getMessage()), e);
9690
}

integ-test/src/test/java/org/opensearch/sql/ppl/JsonFunctionsIT.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,12 @@ public void test_json() throws IOException {
110110
@Test
111111
public void test_json_extract() throws IOException {
112112
JSONObject result;
113-
114113
result =
115114
executeQuery(
116115
String.format(
117-
"source=%s | where json_valid(json_string) | eval json_extract=json_extract(json_string, '$.b') | fields"
118-
+ " test_name, json_extract",
116+
"source=%s | where json_valid(json_string) | eval extracted=json_extract(json_string, '$.b') | fields test_name, extracted",
119117
TEST_INDEX_JSON_TEST));
120-
verifySchema(result, schema("test_name", null, "string"), schema("json_extract", null, "undefined"));
118+
verifySchema(result, schema("test_name", null, "string"), schema("extracted", null, "undefined"));
121119
verifyDataRows(
122120
result,
123121
rows("json nested object", new JSONObject(Map.of("c", "3"))),

0 commit comments

Comments
 (0)