Skip to content

Commit a8dd18c

Browse files
committed
Add integration test for rex in subsearch + simplify unit-test javadoc
Adds CalcitePPLAppendcolIT.testAppendColWithRexInSubsearch to cover the end-to-end execution path against a real cluster. Trims the existing unit-test javadoc to a single line describing what is being verified, not the historical bug shape. Signed-off-by: Jialiang Liang <jiallian@amazon.com>
1 parent d69b029 commit a8dd18c

2 files changed

Lines changed: 16 additions & 13 deletions

File tree

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,18 @@ public void testAppendColOverride() throws IOException {
8181
rows("F", "DE", 101, null),
8282
rows("F", "FL", 310, null));
8383
}
84+
85+
/** Verifies that rex can be used as the first command of an appendcol subsearch. */
86+
@Test
87+
public void testAppendColWithRexInSubsearch() throws IOException {
88+
JSONObject actual =
89+
executeQuery(
90+
String.format(
91+
"source=%s | stats count() as cnt by gender"
92+
+ " | appendcol [ rex field=email '^(?<user>[^@]+)@.*' | fields user ]"
93+
+ " | head 2",
94+
TEST_INDEX_ACCOUNT));
95+
verifySchema(
96+
actual, schema("gender", "string"), schema("cnt", "bigint"), schema("user", "string"));
97+
}
8498
}

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -307,24 +307,13 @@ public void testRexWithMaxMatchAndOffsetField() {
307307
verifyPPLToSparkSQL(root, expectedSparkSql);
308308
}
309309

310-
/**
311-
* Regression for the rex-inside-appendcol NPE. The subsearch starts with rex (no upstream
312-
* source), so the parsed Rex node has a null {@code child} until {@link
313-
* org.opensearch.sql.calcite.utils.PlanUtils#transformPlanToAttachChild} walks the subsearch tree
314-
* to attach the main relation. That walker calls {@code getChild()} on every node it crosses.
315-
* {@code Rex.getChild()} previously returned {@code ImmutableList.of(child)} which throws NPE
316-
* when {@code child} is null; sibling AST nodes (Project / Filter / Eval / Aggregation) all guard
317-
* with {@code child == null ? ImmutableList.of() : ...}. This test ensures the rex-in-appendcol
318-
* pipeline plans without NPE.
319-
*/
310+
/** Verifies that rex plans correctly when it appears as the first command of a subsearch. */
320311
@Test
321-
public void testRexInsideAppendCol() {
312+
public void testRexInsideSubsearch() {
322313
String ppl =
323314
"source=EMP | stats count() as base_c by JOB"
324315
+ " | appendcol [ rex field=ENAME '^(?<first>[A-Z])' | fields ENAME, first ]";
325316
RelNode root = getRelNode(ppl);
326-
// Just verify planning succeeds (does not throw). Plan-shape assertions for AppendCol's join
327-
// shape live in CalcitePPLAppendColumnsTest; this regression only covers the NPE.
328317
org.junit.Assert.assertNotNull(root);
329318
}
330319
}

0 commit comments

Comments
 (0)