forked from opensearch-project/sql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Tests] IT tests and test utils update to fix failing tests for serve…
…rless Signed-off-by: Manasvini B S <[email protected]>
- Loading branch information
1 parent
7e73f12
commit a1f9746
Showing
11 changed files
with
428 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,13 @@ | |
package org.opensearch.sql.ppl; | ||
|
||
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_BANK; | ||
import static org.opensearch.sql.util.MatcherUtils.rows; | ||
import static org.opensearch.sql.util.MatcherUtils.verifyOrder; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.json.JSONArray; | ||
import org.json.JSONObject; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class ParseCommandIT extends PPLIntegTestCase { | ||
|
@@ -26,15 +28,38 @@ public void testParseCommand() throws IOException { | |
executeQuery( | ||
String.format( | ||
"source=%s | parse email '.+@(?<host>.+)' | fields email, host", TEST_INDEX_BANK)); | ||
verifyOrder( | ||
result, | ||
rows("[email protected]", "pyrami.com"), | ||
rows("[email protected]", "netagy.com"), | ||
rows("[email protected]", "quility.com"), | ||
rows("[email protected]", "boink.com"), | ||
rows("[email protected]", "scentric.com"), | ||
rows("[email protected]", "filodyne.com"), | ||
rows("[email protected]", "quailcom.com")); | ||
|
||
// Create the expected rows | ||
List<Object[]> expectedRows = | ||
new ArrayList<>( | ||
List.of( | ||
new Object[] {"[email protected]", "pyrami.com"}, | ||
new Object[] {"[email protected]", "netagy.com"}, | ||
new Object[] {"[email protected]", "quility.com"}, | ||
new Object[] {"[email protected]", "boink.com"}, | ||
new Object[] {"[email protected]", "scentric.com"}, | ||
new Object[] {"[email protected]", "filodyne.com"}, | ||
new Object[] {"[email protected]", "quailcom.com"})); | ||
|
||
// Actual rows from the response | ||
JSONArray dataRows = result.getJSONArray("datarows"); | ||
List<Object[]> actualRows = new ArrayList<>(); | ||
for (int i = 0; i < dataRows.length(); i++) { | ||
JSONArray row = dataRows.getJSONArray(i); | ||
actualRows.add(new Object[] {row.getString(0), row.getString(1)}); | ||
} | ||
|
||
if (expectedRows.size() != actualRows.size()) { | ||
Assert.fail("Row count is different " + expectedRows + " " + actualRows); | ||
} | ||
// Sort the lists before compare | ||
expectedRows.sort((a, b) -> ((String) a[0]).compareTo((String) b[0])); | ||
actualRows.sort((a, b) -> ((String) a[0]).compareTo((String) b[0])); | ||
|
||
// Compare the sorted lists by iterating over elements and using assertArrayEquals | ||
for (int i = 0; i < expectedRows.size(); i++) { | ||
assertArrayEquals(expectedRows.get(i), actualRows.get(i)); | ||
} | ||
} | ||
|
||
@Test | ||
|
@@ -43,15 +68,39 @@ public void testParseCommandReplaceOriginalField() throws IOException { | |
executeQuery( | ||
String.format( | ||
"source=%s | parse email '.+@(?<email>.+)' | fields email", TEST_INDEX_BANK)); | ||
verifyOrder( | ||
result, | ||
rows("pyrami.com"), | ||
rows("netagy.com"), | ||
rows("quility.com"), | ||
rows("boink.com"), | ||
rows("scentric.com"), | ||
rows("filodyne.com"), | ||
rows("quailcom.com")); | ||
|
||
// Create the expected rows | ||
List<Object[]> expectedRows = | ||
new ArrayList<>( | ||
List.of( | ||
new Object[] {"pyrami.com"}, | ||
new Object[] {"netagy.com"}, | ||
new Object[] {"quility.com"}, | ||
new Object[] {"boink.com"}, | ||
new Object[] {"scentric.com"}, | ||
new Object[] {"filodyne.com"}, | ||
new Object[] {"quailcom.com"})); | ||
|
||
// Actual rows from the response | ||
JSONArray dataRows = result.getJSONArray("datarows"); | ||
List<Object[]> actualRows = new ArrayList<>(); | ||
for (int i = 0; i < dataRows.length(); i++) { | ||
JSONArray row = dataRows.getJSONArray(i); | ||
actualRows.add(new Object[] {row.getString(0)}); | ||
} | ||
|
||
// Sort the lists using natural ordering | ||
expectedRows.sort((a, b) -> ((String) a[0]).compareTo((String) b[0])); | ||
actualRows.sort((a, b) -> ((String) a[0]).compareTo((String) b[0])); | ||
|
||
if (expectedRows.size() != actualRows.size()) { | ||
Assert.fail("Row count is different " + expectedRows + " " + actualRows); | ||
} | ||
|
||
// Compare the sorted lists by iterating over elements and using assertArrayEquals | ||
for (int i = 0; i < expectedRows.size(); i++) { | ||
assertArrayEquals(expectedRows.get(i), actualRows.get(i)); | ||
} | ||
} | ||
|
||
@Test | ||
|
@@ -62,14 +111,38 @@ public void testParseCommandWithOtherRunTimeFields() throws IOException { | |
"source=%s | parse email '.+@(?<host>.+)' | " | ||
+ "eval eval_result=1 | fields host, eval_result", | ||
TEST_INDEX_BANK)); | ||
verifyOrder( | ||
result, | ||
rows("pyrami.com", 1), | ||
rows("netagy.com", 1), | ||
rows("quility.com", 1), | ||
rows("boink.com", 1), | ||
rows("scentric.com", 1), | ||
rows("filodyne.com", 1), | ||
rows("quailcom.com", 1)); | ||
|
||
// Create the expected rows as List<Object[]> | ||
List<Object[]> expectedRows = | ||
new ArrayList<>( | ||
List.of( | ||
new Object[] {"pyrami.com", 1}, | ||
new Object[] {"netagy.com", 1}, | ||
new Object[] {"quility.com", 1}, | ||
new Object[] {"boink.com", 1}, | ||
new Object[] {"scentric.com", 1}, | ||
new Object[] {"filodyne.com", 1}, | ||
new Object[] {"quailcom.com", 1})); | ||
|
||
// Actual rows from the response | ||
JSONArray dataRows = result.getJSONArray("datarows"); | ||
List<Object[]> actualRows = new ArrayList<>(); | ||
for (int i = 0; i < dataRows.length(); i++) { | ||
JSONArray row = dataRows.getJSONArray(i); | ||
actualRows.add(new Object[] {row.getString(0), row.getInt(1)}); | ||
} | ||
|
||
if (expectedRows.size() != actualRows.size()) { | ||
Assert.fail("Row count is different " + expectedRows + " " + actualRows); | ||
} | ||
|
||
// Sort both expected and actual rows | ||
expectedRows.sort((a, b) -> ((String) a[0]).compareTo((String) b[0])); | ||
actualRows.sort((a, b) -> ((String) a[0]).compareTo((String) b[0])); | ||
|
||
// Compare the sorted lists by iterating over elements and using assertArrayEquals | ||
for (int i = 0; i < expectedRows.size(); i++) { | ||
assertArrayEquals(expectedRows.get(i), actualRows.get(i)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.