-
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.
Add
IPComparisonIT
tests for comparison operators, rename modules a…
…nd weblogs test index to make plural for consistency. Signed-off-by: currantw <[email protected]>
- Loading branch information
Showing
8 changed files
with
159 additions
and
14 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
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
145 changes: 145 additions & 0 deletions
145
integ-test/src/test/java/org/opensearch/sql/ppl/IPComparisonIT.java
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 |
---|---|---|
@@ -0,0 +1,145 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.sql.ppl; | ||
|
||
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_WEBLOGS; | ||
import static org.opensearch.sql.util.MatcherUtils.rows; | ||
import static org.opensearch.sql.util.MatcherUtils.verifyDataRows; | ||
|
||
import java.io.IOException; | ||
import org.json.JSONObject; | ||
import org.junit.Test; | ||
import org.opensearch.sql.legacy.SQLIntegTestCase; | ||
|
||
public class IPComparisonIT extends PPLIntegTestCase { | ||
|
||
@Override | ||
public void init() throws IOException { | ||
loadIndex(SQLIntegTestCase.Index.WEBLOG); | ||
} | ||
|
||
@Test | ||
public void test_equal() throws IOException { | ||
JSONObject result; | ||
final String operator = "="; | ||
|
||
result = executeComparisonQuery(operator, "1.2.3.4"); | ||
verifyDataRows(result, rows("1.2.3.4")); | ||
|
||
result = executeComparisonQuery(operator, "::ffff:1.2.3.4"); | ||
verifyDataRows(result, rows("1.2.3.4")); | ||
|
||
result = executeComparisonQuery(operator, "::1"); | ||
verifyDataRows(result, rows("::1")); | ||
|
||
result = executeComparisonQuery(operator, "0000:0000:0000:0000:0000:0000:0000:0001"); | ||
verifyDataRows(result, rows("::1")); | ||
} | ||
|
||
@Test | ||
public void test_not_equal() throws IOException { | ||
JSONObject result; | ||
final String operator = "!="; | ||
|
||
result = executeComparisonQuery(operator, "1.2.3.4"); | ||
verifyDataRows( | ||
result, rows("::1"), rows("0.0.0.2"), rows("::3"), rows("1.2.3.5"), rows("::ffff:1234")); | ||
|
||
result = executeComparisonQuery(operator, "::ffff:1.2.3.4"); | ||
verifyDataRows( | ||
result, rows("::1"), rows("0.0.0.2"), rows("::3"), rows("1.2.3.5"), rows("::ffff:1234")); | ||
|
||
result = executeComparisonQuery(operator, "::1"); | ||
verifyDataRows( | ||
result, | ||
rows("0.0.0.2"), | ||
rows("::3"), | ||
rows("1.2.3.4"), | ||
rows("1.2.3.5"), | ||
rows("::ffff:1234")); | ||
|
||
result = executeComparisonQuery(operator, "0000:0000:0000:0000:0000:0000:0000:0001"); | ||
verifyDataRows( | ||
result, | ||
rows("0.0.0.2"), | ||
rows("::3"), | ||
rows("1.2.3.4"), | ||
rows("1.2.3.5"), | ||
rows("::ffff:1234")); | ||
} | ||
|
||
@Test | ||
public void test_greater_than() throws IOException { | ||
JSONObject result; | ||
final String operator = ">"; | ||
|
||
result = executeComparisonQuery(operator, "1.2.3.3"); | ||
verifyDataRows(result, rows("1.2.3.4"), rows("1.2.3.5")); | ||
|
||
result = executeComparisonQuery(operator, "1.2.3.4"); | ||
verifyDataRows(result, rows("1.2.3.5")); | ||
|
||
result = executeComparisonQuery(operator, "1.2.3.5"); | ||
verifyDataRows(result); | ||
} | ||
|
||
@Test | ||
public void test_greater_than_or_equal_to() throws IOException { | ||
JSONObject result; | ||
final String operator = ">="; | ||
|
||
result = executeComparisonQuery(operator, "1.2.3.4"); | ||
verifyDataRows(result, rows("1.2.3.4"), rows("1.2.3.5")); | ||
|
||
result = executeComparisonQuery(operator, "1.2.3.5"); | ||
verifyDataRows(result, rows("1.2.3.5")); | ||
|
||
result = executeComparisonQuery(operator, "1.2.3.6"); | ||
verifyDataRows(result); | ||
} | ||
|
||
@Test | ||
public void test_less_than() throws IOException { | ||
JSONObject result; | ||
final String operator = "<"; | ||
|
||
result = executeComparisonQuery(operator, "::4"); | ||
verifyDataRows(result, rows("::1"), rows("::3")); | ||
|
||
result = executeComparisonQuery(operator, "::3"); | ||
verifyDataRows(result, rows("::1")); | ||
|
||
result = executeComparisonQuery(operator, "::1"); | ||
verifyDataRows(result); | ||
} | ||
|
||
@Test | ||
public void test_less_than_or_equal_to() throws IOException { | ||
JSONObject result; | ||
final String operator = "<="; | ||
|
||
result = executeComparisonQuery(operator, "::3"); | ||
verifyDataRows(result, rows("::1"), rows("::3")); | ||
|
||
result = executeComparisonQuery(operator, "::1"); | ||
verifyDataRows(result, rows("::1")); | ||
|
||
result = executeComparisonQuery(operator, "::0"); | ||
verifyDataRows(result); | ||
} | ||
|
||
/** | ||
* Executes a query comparison on the weblogs test index with the given comparison operator and IP | ||
* address string, and returns the resulting {@link JSONObject}; | ||
*/ | ||
private JSONObject executeComparisonQuery(String comparisonOperator, String addressString) | ||
throws IOException { | ||
String formatString = "source=%s | where host %s '%s' | fields host"; | ||
String query = | ||
String.format(formatString, TEST_INDEX_WEBLOGS, comparisonOperator, addressString); | ||
return executeQuery(query); | ||
} | ||
} |
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