-
Notifications
You must be signed in to change notification settings - Fork 141
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 (#2902) Signed-off-by: Manasvini B S <[email protected]>
- Loading branch information
1 parent
4a735ea
commit 6972487
Showing
11 changed files
with
491 additions
and
91 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,23 @@ 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"})); | ||
|
||
List<Object[]> actualRows = convertJsonToRows(result, 2); | ||
sortRowsByFirstColumn(expectedRows); | ||
sortRowsByFirstColumn(actualRows); | ||
compareRows(expectedRows, actualRows); | ||
} | ||
|
||
@Test | ||
|
@@ -43,15 +53,23 @@ 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"})); | ||
|
||
List<Object[]> actualRows = convertJsonToRows(result, 1); | ||
sortRowsByFirstColumn(expectedRows); | ||
sortRowsByFirstColumn(actualRows); | ||
compareRows(expectedRows, actualRows); | ||
} | ||
|
||
@Test | ||
|
@@ -62,14 +80,52 @@ 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})); | ||
|
||
List<Object[]> actualRows = convertJsonToRows(result, 2); | ||
sortRowsByFirstColumn(expectedRows); | ||
sortRowsByFirstColumn(actualRows); | ||
compareRows(expectedRows, actualRows); | ||
} | ||
|
||
// Convert JSON response to List<Object[]> | ||
private List<Object[]> convertJsonToRows(JSONObject result, int columnCount) { | ||
JSONArray dataRows = result.getJSONArray("datarows"); | ||
List<Object[]> rows = new ArrayList<>(); | ||
for (int i = 0; i < dataRows.length(); i++) { | ||
JSONArray row = dataRows.getJSONArray(i); | ||
Object[] rowData = new Object[columnCount]; | ||
for (int j = 0; j < columnCount; j++) { | ||
rowData[j] = row.get(j); | ||
} | ||
rows.add(rowData); | ||
} | ||
return rows; | ||
} | ||
|
||
// Sort rows by the first column | ||
private void sortRowsByFirstColumn(List<Object[]> rows) { | ||
rows.sort((a, b) -> ((String) a[0]).compareTo((String) b[0])); | ||
} | ||
|
||
private void compareRows(List<Object[]> expectedRows, List<Object[]> actualRows) { | ||
if (expectedRows.size() != actualRows.size()) { | ||
Assert.fail( | ||
"Row count is different. expectedRows:" + expectedRows + ", actualRows: " + actualRows); | ||
} | ||
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.