diff --git a/docs/dev/ppl-commands.md b/docs/dev/ppl-commands.md index 5c3538883a..617f787045 100644 --- a/docs/dev/ppl-commands.md +++ b/docs/dev/ppl-commands.md @@ -52,7 +52,7 @@ If you are working on contributing a new PPL command, please read this guide and - Add a test in `PPLQueryDataAnonymizerTest` - [ ] **Cross-cluster Tests (optional, nice to have):** - - Add a test in `CrossClusterSearchIT` + - Add a test in `CrossClusterSearchIT`, or in `CalciteCrossClusterSearchIT` if the command requires Calcite. - [ ] **User doc:** - Add a xxx.md under `docs/user/ppl/cmd` and link the new doc to `docs/user/ppl/index.md` diff --git a/integ-test/src/test/java/org/opensearch/sql/security/CalciteCrossClusterSearchIT.java b/integ-test/src/test/java/org/opensearch/sql/security/CalciteCrossClusterSearchIT.java index 1cbd019eca..4ce012b11c 100644 --- a/integ-test/src/test/java/org/opensearch/sql/security/CalciteCrossClusterSearchIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/security/CalciteCrossClusterSearchIT.java @@ -349,4 +349,74 @@ public void testCrossClusterRexWithOffsetField() throws IOException { verifyDataRows( result, rows("Duke Willmington", "u", "vowel=1-1"), rows("Bond", "o", "vowel=1-1")); } + + @Test + public void testCrossClusterAddTotals() throws IOException { + JSONObject result = + executeQuery( + String.format( + "search source=%s| sort 1 age | fields firstname, age | addtotals age", + TEST_INDEX_BANK_REMOTE)); + verifyDataRows(result, rows("Nanette", 28, 28)); + } + + /** CrossClusterSearchIT Test for addcoltotals. */ + @Test + public void testCrossClusterAddColTotals() throws IOException { + JSONObject result = + executeQuery( + String.format( + "search source=%s | where firstname='Hattie' or firstname ='Nanette'|fields" + + " firstname,age,balance | addcoltotals age balance", + TEST_INDEX_BANK_REMOTE)); + verifyDataRows( + result, rows("Hattie", 36, 5686), rows("Nanette", 28, 32838), rows(null, 64, 38524)); + } + + @Test + public void testCrossClusterTranspose() throws IOException { + JSONObject result = + executeQuery( + String.format( + "search source=%s | where firstname='Hattie' or firstname ='Nanette' or" + + " firstname='Dale'|sort firstname desc |fields firstname,age,balance |" + + " transpose 3 column_name='column_names'", + TEST_INDEX_BANK_REMOTE)); + + verifyDataRows( + result, + rows("firstname", "Nanette", "Hattie", "Dale"), + rows("balance", "32838", "5686", "4180"), + rows("age", "28", "36", "33")); + } + + @Test + public void testCrossClusterAppend() throws IOException { + JSONObject result = + executeQuery( + String.format( + "search source=%s | stats count() as cnt by gender | append [ search source=%s |" + + " stats count() as cnt ]", + TEST_INDEX_BANK_REMOTE, TEST_INDEX_BANK_REMOTE)); + verifyDataRows(result, rows(3, "F"), rows(4, "M"), rows(7, null)); + } + + /** CrossClusterSearchIT Test for mvcombine. */ + @Test + public void testCrossClusterMvcombine() throws IOException { + + JSONObject result = + executeQuery( + String.format( + "search source=%s | where firstname='Hattie' or firstname='Nanette' " + + "| fields firstname, age | mvcombine age", + TEST_INDEX_BANK_REMOTE)); + + verifyColumn(result, columnName("firstname"), columnName("age")); + + verifyDataRows( + result, + rows("Hattie", new org.json.JSONArray().put(36)), + rows("Nanette", new org.json.JSONArray().put(28))); + } } diff --git a/integ-test/src/test/java/org/opensearch/sql/security/CrossClusterSearchIT.java b/integ-test/src/test/java/org/opensearch/sql/security/CrossClusterSearchIT.java index 5ea2648fae..af1c08e861 100644 --- a/integ-test/src/test/java/org/opensearch/sql/security/CrossClusterSearchIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/security/CrossClusterSearchIT.java @@ -246,82 +246,4 @@ public void testCrossClusterQueryStringWithoutFields() throws IOException { TEST_INDEX_BANK_REMOTE)); verifyDataRows(result, rows("Hattie")); } - - @Test - public void testCrossClusterAddTotals() throws IOException { - try { - enableCalcite(); - - // Test query_string without fields parameter on remote cluster - JSONObject result = - executeQuery( - String.format( - "search source=%s| sort 1 age | fields firstname, age | addtotals age", - TEST_INDEX_BANK_REMOTE)); - verifyDataRows(result, rows("Nanette", 28, 28)); - } finally { - disableCalcite(); - } - } - - /** CrossClusterSearchIT Test for addcoltotals. */ - @Test - public void testCrossClusterAddColTotals() throws IOException { - try { - enableCalcite(); - - // Test query_string without fields parameter on remote cluster - JSONObject result = - executeQuery( - String.format( - "search source=%s | where firstname='Hattie' or firstname ='Nanette'|fields" - + " firstname,age,balance | addcoltotals age balance", - TEST_INDEX_BANK_REMOTE)); - verifyDataRows( - result, rows("Hattie", 36, 5686), rows("Nanette", 28, 32838), rows(null, 64, 38524)); - } finally { - disableCalcite(); - } - } - - @Test - public void testCrossClusterTranspose() throws IOException { - try { - enableCalcite(); - - // Test query_string without fields parameter on remote cluster - JSONObject result = - executeQuery( - String.format( - "search source=%s | where firstname='Hattie' or firstname ='Nanette' or" - + " firstname='Dale'|sort firstname desc |fields firstname,age,balance |" - + " transpose 3 column_name='column_names'", - TEST_INDEX_BANK_REMOTE)); - - verifyDataRows( - result, - rows("firstname", "Nanette", "Hattie", "Dale"), - rows("balance", "32838", "5686", "4180"), - rows("age", "28", "36", "33")); - } finally { - disableCalcite(); - } - } - - @Test - public void testCrossClusterAppend() throws IOException { - try { - enableCalcite(); - - JSONObject result = - executeQuery( - String.format( - "search source=%s | stats count() as cnt by gender | append [ search source=%s |" - + " stats count() as cnt ]", - TEST_INDEX_BANK_REMOTE, TEST_INDEX_BANK_REMOTE)); - verifyDataRows(result, rows(3, "F"), rows(4, "M"), rows(7, null)); - } finally { - disableCalcite(); - } - } }