Skip to content

Commit 0898f7d

Browse files
committed
Add an ignored test case and limitation explainations for flatten after fields
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
1 parent 2613ac7 commit 0898f7d

3 files changed

Lines changed: 38 additions & 4 deletions

File tree

docs/user/ppl/cmd/flatten.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ PPL query::
106106

107107
Limitations
108108
===========
109+
* ``flatten`` after ``fields`` is not supported under the current
110+
implementation.
111+
| E.g. ``source=my-index | fields message | flatten message`` will not work.
112+
This is because the current implementation relies on the flattened fields
113+
like ``message.info``, ``message.author``, etc. to be present in the read
114+
result.
109115
* The command works only with Calcite enabled. This can be set with the
110116
following command:
111117

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.hamcrest.Matcher;
2020
import org.json.JSONArray;
2121
import org.json.JSONObject;
22+
import org.junit.Ignore;
2223
import org.junit.jupiter.api.Test;
2324
import org.opensearch.client.Request;
2425
import org.opensearch.sql.ppl.PPLIntegTestCase;
@@ -124,6 +125,33 @@ public void testFlattenNullField() throws IOException {
124125
client().performRequest(deleteRequest);
125126
}
126127

128+
// TODO: Enable after fixing issue #3459 and #3751
129+
// https://github.com/opensearch-project/sql/issues/3459
130+
// https://github.com/opensearch-project/sql/issues/3751
131+
@Ignore
132+
@Test
133+
public void testFlattenAfterFields() throws IOException {
134+
JSONObject result =
135+
executeQuery(
136+
String.format(
137+
"source=%s | where myNum=1 | fields message | flatten message",
138+
TEST_INDEX_NESTED_TYPE_WITHOUT_ARRAYS));
139+
verifySchema(
140+
result,
141+
schema("message", "array"),
142+
schema("author", "string"),
143+
schema("dayOfWeek", "bigint"),
144+
schema("info", "string"));
145+
verifyDataRows(
146+
result,
147+
rows(
148+
new JSONArray()
149+
.put(new JSONObject().put("info", "a").put("author", "e").put("dayOfWeek", 1)),
150+
"e",
151+
1,
152+
"a"));
153+
}
154+
127155
@SuppressWarnings("unchecked")
128156
private static Matcher<JSONArray>[] getExpectedRows() {
129157
return new org.hamcrest.TypeSafeMatcher[] {

ppl/src/test/java/org/opensearch/sql/ppl/calcite/CalcitePPLFlattenTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ protected Frameworks.ConfigBuilder config(CalciteAssert.SchemaSpec... schemaSpec
4949
// Add an empty table with name DEPT for test purpose
5050
ImmutableList<Object[]> rows =
5151
ImmutableList.of(
52-
new Object[] {10, ImmutableList.of(7369, "ALLEN"), "SMITH", 7369},
52+
new Object[] {10, ImmutableList.of(7369, "SMITH"), "SMITH", 7369},
5353
new Object[] {20, ImmutableList.of(7499, "ALLEN"), "ALLEN", 7499},
5454
new Object[] {30, ImmutableList.of(7521, "WARD"), "WARD", 7521});
5555
schema.add("DEPT", new TableWithStruct(rows));
@@ -73,7 +73,7 @@ public void testFlatten() {
7373
"SELECT `DEPTNO`, `EMP`, `EMP.EMPNAME` `EMPNAME`, `EMP.EMPNO` `EMPNO`\nFROM `scott`.`DEPT`";
7474
verifyPPLToSparkSQL(root, expectedSparkSql);
7575
String expectedResult =
76-
"DEPTNO=10; EMP={7369, ALLEN}; EMPNAME=SMITH; EMPNO=7369\n"
76+
"DEPTNO=10; EMP={7369, SMITH}; EMPNAME=SMITH; EMPNO=7369\n"
7777
+ "DEPTNO=20; EMP={7499, ALLEN}; EMPNAME=ALLEN; EMPNO=7499\n"
7878
+ "DEPTNO=30; EMP={7521, WARD}; EMPNAME=WARD; EMPNO=7521\n";
7979
verifyResult(root, expectedResult);
@@ -91,7 +91,7 @@ public void testFlattenWithAliases() {
9191
"SELECT `DEPTNO`, `EMP`, `EMP.EMPNAME` `name`, `EMP.EMPNO` `number`\nFROM `scott`.`DEPT`";
9292
verifyPPLToSparkSQL(root, expectedSparkSql);
9393
String expectedResult =
94-
"DEPTNO=10; EMP={7369, ALLEN}; name=SMITH; number=7369\n"
94+
"DEPTNO=10; EMP={7369, SMITH}; name=SMITH; number=7369\n"
9595
+ "DEPTNO=20; EMP={7499, ALLEN}; name=ALLEN; number=7499\n"
9696
+ "DEPTNO=30; EMP={7521, WARD}; name=WARD; number=7521\n";
9797
verifyResult(root, expectedResult);
@@ -109,7 +109,7 @@ public void testProject() {
109109
"LogicalProject(DEPTNO=[$0], EMP=[$1])\n LogicalTableScan(table=[[scott, DEPT]])\n";
110110
verifyLogical(root, expectedLogical);
111111
String expectedResult =
112-
"DEPTNO=10; EMP={7369, ALLEN}\n"
112+
"DEPTNO=10; EMP={7369, SMITH}\n"
113113
+ "DEPTNO=20; EMP={7499, ALLEN}\n"
114114
+ "DEPTNO=30; EMP={7521, WARD}\n";
115115
verifyResult(root, expectedResult);

0 commit comments

Comments
 (0)