Skip to content

Commit

Permalink
Update integ and doc tests to add another example of original field b…
Browse files Browse the repository at this point in the history
…eing preserved.

Signed-off-by: currantw <[email protected]>
  • Loading branch information
currantw committed Feb 6, 2025
1 parent 5d20575 commit 74cba04
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
18 changes: 9 additions & 9 deletions docs/user/ppl/cmd/flatten.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ Example 2: Flatten multiple object fields

PPL query::

os> source=flatten | flatten location | flatten coordinates | fields name, country, province, state, latitude, longitude
os> source=flatten | flatten location | flatten coordinates | fields name, location, latitude, longitude
fetched rows / total rows = 4/4
+------------------+---------------+------------------+------------+----------+-----------+
| name | country | province | state | latitude | longitude |
|------------------+---------------+------------------+------------+----------+-----------|
| Seattle | United States | null | Washington | 47.6061 | -122.3328 |
| Vancouver | Canada | British Columbia | null | 49.2827 | -123.1207 |
| Null Location | null | null | null | null | null |
| Null Coordinates | Australia | null | Victoria | null | null |
+------------------+---------------+------------------+------------+----------+-----------+
+------------------+---------------------------------------------------------------------------------------------------------------------+----------+-----------+
| name | location | latitude | longitude |
|------------------+---------------------------------------------------------------------------------------------------------------------+----------+-----------|
| Seattle | {'state': 'Washington', 'country': 'United States', 'coordinates': {'latitude': 47.6061, 'longitude': -122.3328}} | 47.6061 | -122.3328 |
| Vancouver | {'province': 'British Columbia', 'country': 'Canada', 'coordinates': {'latitude': 49.2827, 'longitude': -123.1207}} | 49.2827 | -123.1207 |
| Null Location | null | null | null |
| Null Coordinates | {'state': 'Victoria', 'country': 'Australia'} | null | null |
+------------------+---------------------------------------------------------------------------------------------------------------------+----------+-----------+

Example 3: Flatten a nested object field
========================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ public void testBasic() throws IOException {
"Seattle",
"United States",
null,
Map.ofEntries(Map.entry("latitude", 47.6061), Map.entry("longitude", -122.3328)),
Map.of("latitude", 47.6061, "longitude", -122.3328),
"Washington"),
rows(
"Vancouver",
"Canada",
"British Columbia",
Map.ofEntries(Map.entry("latitude", 49.2827), Map.entry("longitude", -123.1207)),
Map.of("latitude", 49.2827, "longitude", -123.1207),
null),
rows("Null Location", null, null, null, null),
rows("Null Coordinates", "Australia", null, null, "Victoria"));
Expand All @@ -61,25 +61,37 @@ public void testBasic() throws IOException {
public void testMultiple() throws IOException {
String query =
StringUtils.format(
"source=%s | flatten location | flatten coordinates | fields name, country, province,"
+ " state, latitude, longitude",
"source=%s | flatten location | flatten coordinates | fields name, location, latitude,"
+ " longitude",
TEST_INDEX_FLATTEN);
JSONObject result = executeQuery(query);

verifySchema(
result,
schema("name", "string"),
schema("country", "string"),
schema("province", "string"),
schema("state", "string"),
schema("location", "struct"),
schema("latitude", "double"),
schema("longitude", "double"));
verifyDataRows(
result,
rows("Seattle", "United States", null, "Washington", 47.6061, -122.3328),
rows("Vancouver", "Canada", "British Columbia", null, 49.2827, -123.1207),
rows("Null Location", null, null, null, null, null),
rows("Null Coordinates", "Australia", null, "Victoria", null, null));
rows(
"Seattle",
Map.ofEntries(
Map.entry("state", "Washington"),
Map.entry("country", "United States"),
Map.entry("coordinates", Map.of("latitude", 47.6061, "longitude", -122.3328))),
47.6061,
-122.3328),
rows(
"Vancouver",
Map.ofEntries(
Map.entry("country", "Canada"),
Map.entry("province", "British Columbia"),
Map.entry("coordinates", Map.of("latitude", 49.2827, "longitude", -123.1207))),
49.2827,
-123.1207),
rows("Null Location", null, null, null),
rows("Null Coordinates", Map.of("state", "Victoria", "country", "Australia"), null, null));
}

@Test
Expand Down

0 comments on commit 74cba04

Please sign in to comment.