Skip to content

Commit 5e2f1f1

Browse files
committed
Update flatten IT
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
1 parent 65fb63a commit 5e2f1f1

1 file changed

Lines changed: 59 additions & 9 deletions

File tree

integ-test/src/test/java/org/opensearch/sql/calcite/remote/CalciteFlattenCommandIT.java

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99

1010
import static org.opensearch.sql.legacy.SQLIntegTestCase.Index.NESTED_WITHOUT_ARRAYS;
1111
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_NESTED_TYPE_WITHOUT_ARRAYS;
12+
import static org.opensearch.sql.util.MatcherUtils.rows;
1213
import static org.opensearch.sql.util.MatcherUtils.schema;
13-
import static org.opensearch.sql.util.MatcherUtils.verifyNumOfRows;
14+
import static org.opensearch.sql.util.MatcherUtils.verifyDataRows;
1415
import static org.opensearch.sql.util.MatcherUtils.verifySchema;
1516

17+
import org.json.JSONArray;
1618
import org.json.JSONObject;
1719
import org.junit.jupiter.api.Test;
1820
import org.opensearch.sql.ppl.PPLIntegTestCase;
@@ -27,19 +29,67 @@ public void init() throws Exception {
2729
}
2830

2931
@Test
30-
public void testFlattenStruct() throws Exception {
32+
public void testFlattenNestedStruct() throws Exception {
3133
JSONObject result =
3234
executeQuery(
3335
String.format("source=%s | flatten message", TEST_INDEX_NESTED_TYPE_WITHOUT_ARRAYS));
3436
verifySchema(
3537
result,
36-
schema("message", "struct"),
37-
schema("info", "string"),
38-
schema("author", "string"),
39-
schema("dayOfWeek", "integer"),
38+
// Nested fields are retrieved as array of nested structs
4039
schema("comment", "array"),
41-
schema("myNum", "integer"),
42-
schema("someField", "string"));
43-
verifyNumOfRows(result, 5);
40+
schema("myNum", "bigint"),
41+
schema("someField", "string"),
42+
// Nested fields are retrieved as array of nested structs
43+
schema("message", "array"),
44+
schema("author", "string"),
45+
schema("dayOfWeek", "bigint"),
46+
schema("info", "string"));
47+
verifyDataRows(
48+
result,
49+
rows(
50+
new JSONArray().put(new JSONObject().put("data", "ab").put("likes", 3)),
51+
1,
52+
"b",
53+
new JSONArray()
54+
.put(new JSONObject().put("info", "a").put("author", "e").put("dayOfWeek", 1)),
55+
"e",
56+
1,
57+
"a"),
58+
rows(
59+
new JSONArray().put(new JSONObject().put("data", "aa").put("likes", 2)),
60+
2,
61+
"a",
62+
new JSONArray()
63+
.put(new JSONObject().put("info", "b").put("author", "f").put("dayOfWeek", 2)),
64+
"f",
65+
2,
66+
"b"),
67+
rows(
68+
new JSONArray().put(new JSONObject().put("data", "aa").put("likes", 3)),
69+
3,
70+
"a",
71+
new JSONArray()
72+
.put(new JSONObject().put("info", "c").put("author", "g").put("dayOfWeek", 1)),
73+
"g",
74+
1,
75+
"c"),
76+
rows(
77+
new JSONArray().put(new JSONObject().put("data", "ab").put("likes", 1)),
78+
4,
79+
"b",
80+
new JSONArray()
81+
.put(new JSONObject().put("info", "c").put("author", "h").put("dayOfWeek", 4)),
82+
"h",
83+
4,
84+
"c"),
85+
rows(
86+
new JSONArray().put(new JSONObject().put("data", "bb").put("likes", 10)),
87+
3,
88+
"a",
89+
new JSONArray()
90+
.put(new JSONObject().put("info", "zz").put("author", "zz").put("dayOfWeek", 6)),
91+
"zz",
92+
6,
93+
"zz"));
4494
}
4595
}

0 commit comments

Comments
 (0)