Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PPL: Add json function and cast(x as json) function #344

Closed
wants to merge 4 commits into from
Closed
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
spotless
Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com>
acarbonetto committed Jan 9, 2025
commit 37e1128b09bb33fcacede5a7a5bbac31b8ec9984
Original file line number Diff line number Diff line change
@@ -59,13 +59,14 @@ public void test_cast_json() throws IOException {
JSONObject result =
executeQuery(
String.format(
"source=%s | where json_valid(json_string) | eval casted=cast(json_string as json) | fields test_name, casted",
"source=%s | where json_valid(json_string) | eval casted=cast(json_string as json)"
+ " | fields test_name, casted",
TEST_INDEX_JSON_TEST));
verifySchema(result, schema("test_name", null, "string"), schema("casted", null, "undefined"));
verifyDataRows(
result,
rows("json object", Map.of("a", "1", "b", "2")),
rows("json array", List.of(1,2,3,4)),
rows("json array", List.of(1, 2, 3, 4)),
rows("json scalar string", "abc"),
rows("json empty string", null));
}
@@ -77,12 +78,14 @@ public void test_json() throws IOException {
result =
executeQuery(
String.format(
"source=%s | where json_valid(json_string) | eval casted=json(json_string) | fields test_name, casted", TEST_INDEX_JSON_TEST));
"source=%s | where json_valid(json_string) | eval casted=json(json_string) | fields"
+ " test_name, casted",
TEST_INDEX_JSON_TEST));
verifySchema(result, schema("test_name", null, "string"), schema("casted", null, "undefined"));
verifyDataRows(
result,
rows("json object", Map.of("a", "1", "b", "2")),
rows("json array", List.of(1,2,3,4)),
rows("json array", List.of(1, 2, 3, 4)),
rows("json scalar string", "abc"),
rows("json empty string", null));
}