diff --git a/integ-test/src/test/java/org/opensearch/sql/correctness/TestConfig.java b/integ-test/src/test/java/org/opensearch/sql/correctness/TestConfig.java
index d344c29e20..a498f15d63 100644
--- a/integ-test/src/test/java/org/opensearch/sql/correctness/TestConfig.java
+++ b/integ-test/src/test/java/org/opensearch/sql/correctness/TestConfig.java
@@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/
-
package org.opensearch.sql.correctness;
import static java.util.stream.Collectors.joining;
@@ -19,11 +18,13 @@
import org.opensearch.sql.legacy.utils.StringUtils;
/**
+ *
* Test configuration parse the following information from command line arguments:
* 1) Test schema and data
* 2) Test queries
* 3) OpenSearch connection URL
* 4) Other database connection URLs
+ *
*/
public class TestConfig {
@@ -37,9 +38,7 @@ public class TestConfig {
private final String openSearchHostUrl;
- /**
- * Test against some database rather than OpenSearch via our JDBC driver
- */
+ /** Test against some database rather than OpenSearch via our JDBC driver */
private final String dbConnectionUrl;
private final Map otherDbConnectionNameAndUrls = new HashMap<>();
@@ -75,12 +74,14 @@ public Map getOtherDbConnectionNameAndUrls() {
private TestDataSet[] buildDefaultTestDataSet() {
return new TestDataSet[] {
- new TestDataSet("opensearch_dashboards_sample_data_flights",
- readFile("opensearch_dashboards_sample_data_flights.json"),
- readFile("opensearch_dashboards_sample_data_flights.csv")),
- new TestDataSet("opensearch_dashboards_sample_data_ecommerce",
- readFile("opensearch_dashboards_sample_data_ecommerce.json"),
- readFile("opensearch_dashboards_sample_data_ecommerce.csv")),
+ new TestDataSet(
+ "opensearch_dashboards_sample_data_flights",
+ readFile("opensearch_dashboards_sample_data_flights.json"),
+ readFile("opensearch_dashboards_sample_data_flights.csv")),
+ new TestDataSet(
+ "opensearch_dashboards_sample_data_ecommerce",
+ readFile("opensearch_dashboards_sample_data_ecommerce.json"),
+ readFile("opensearch_dashboards_sample_data_ecommerce.csv")),
};
}
@@ -118,31 +119,33 @@ private static String readFile(String relativePath) {
@Override
public String toString() {
return "\n=================================\n"
- + "Tested Database : " + openSearchHostUrlToString() + '\n'
- + "Other Databases :\n" + otherDbConnectionInfoToString() + '\n'
- + "Test data set(s) :\n" + testDataSetsToString() + '\n'
- + "Test query set : " + testQuerySet + '\n'
- + "=================================\n";
+ + "Tested Database : "
+ + openSearchHostUrlToString()
+ + "\nOther Databases :\n"
+ + otherDbConnectionInfoToString()
+ + "\nTest data set(s) :\n"
+ + testDataSetsToString()
+ + "\nTest query set : "
+ + testQuerySet
+ + "\n=================================\n";
}
private String testDataSetsToString() {
- return Arrays.stream(testDataSets).
- map(TestDataSet::toString).
- collect(joining("\n"));
+ return Arrays.stream(testDataSets).map(TestDataSet::toString).collect(joining("\n"));
}
private String openSearchHostUrlToString() {
if (!dbConnectionUrl.isEmpty()) {
return dbConnectionUrl;
}
- return openSearchHostUrl.isEmpty() ? "(Use internal OpenSearch in workspace)" :
- openSearchHostUrl;
+ return openSearchHostUrl.isEmpty()
+ ? "(Use internal OpenSearch in workspace)"
+ : openSearchHostUrl;
}
private String otherDbConnectionInfoToString() {
- return otherDbConnectionNameAndUrls.entrySet().stream().
- map(e -> StringUtils.format(" %s = %s", e.getKey(), e.getValue())).
- collect(joining("\n"));
+ return otherDbConnectionNameAndUrls.entrySet().stream()
+ .map(e -> StringUtils.format(" %s = %s", e.getKey(), e.getValue()))
+ .collect(joining("\n"));
}
-
}
diff --git a/integ-test/src/test/java/org/opensearch/sql/correctness/report/SuccessTestCase.java b/integ-test/src/test/java/org/opensearch/sql/correctness/report/SuccessTestCase.java
index 62cd9b3fbe..8ec996e660 100644
--- a/integ-test/src/test/java/org/opensearch/sql/correctness/report/SuccessTestCase.java
+++ b/integ-test/src/test/java/org/opensearch/sql/correctness/report/SuccessTestCase.java
@@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/
-
package org.opensearch.sql.correctness.report;
import static org.opensearch.sql.correctness.report.TestCaseReport.TestResult.SUCCESS;
@@ -12,9 +11,7 @@
import lombok.Getter;
import lombok.ToString;
-/**
- * Report for successful test case result.
- */
+/** Report for successful test case result. */
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Getter
diff --git a/integ-test/src/test/java/org/opensearch/sql/correctness/report/TestCaseReport.java b/integ-test/src/test/java/org/opensearch/sql/correctness/report/TestCaseReport.java
index 1a6285c52e..7567e9cd6a 100644
--- a/integ-test/src/test/java/org/opensearch/sql/correctness/report/TestCaseReport.java
+++ b/integ-test/src/test/java/org/opensearch/sql/correctness/report/TestCaseReport.java
@@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/
-
package org.opensearch.sql.correctness.report;
import static org.opensearch.sql.correctness.report.TestCaseReport.TestResult.SUCCESS;
@@ -12,22 +11,19 @@
import lombok.Getter;
import lombok.ToString;
-/**
- * Base class for different test result.
- */
+/** Base class for different test result. */
@EqualsAndHashCode
@ToString
public abstract class TestCaseReport {
public enum TestResult {
- SUCCESS, FAILURE;
+ SUCCESS,
+ FAILURE;
}
- @Getter
- private final int id;
+ @Getter private final int id;
- @Getter
- private final String sql;
+ @Getter private final String sql;
private final TestResult result;
@@ -40,5 +36,4 @@ public TestCaseReport(int id, String sql, TestResult result) {
public String getResult() {
return result == SUCCESS ? "Success" : "Failed";
}
-
}
diff --git a/integ-test/src/test/java/org/opensearch/sql/correctness/report/TestReport.java b/integ-test/src/test/java/org/opensearch/sql/correctness/report/TestReport.java
index 88b23ccd5b..9b9b3b7a23 100644
--- a/integ-test/src/test/java/org/opensearch/sql/correctness/report/TestReport.java
+++ b/integ-test/src/test/java/org/opensearch/sql/correctness/report/TestReport.java
@@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/
-
package org.opensearch.sql.correctness.report;
import java.util.ArrayList;
@@ -12,9 +11,7 @@
import lombok.Getter;
import lombok.ToString;
-/**
- * Test report class to generate JSON report.
- */
+/** Test report class to generate JSON report. */
@EqualsAndHashCode
@ToString
@Getter
@@ -37,5 +34,4 @@ public void addTestCase(TestCaseReport testCase) {
summary.addFailure();
}
}
-
}
diff --git a/integ-test/src/test/java/org/opensearch/sql/correctness/report/TestSummary.java b/integ-test/src/test/java/org/opensearch/sql/correctness/report/TestSummary.java
index 90767582b5..bbd4385460 100644
--- a/integ-test/src/test/java/org/opensearch/sql/correctness/report/TestSummary.java
+++ b/integ-test/src/test/java/org/opensearch/sql/correctness/report/TestSummary.java
@@ -3,16 +3,13 @@
* SPDX-License-Identifier: Apache-2.0
*/
-
package org.opensearch.sql.correctness.report;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
-/**
- * Test summary section.
- */
+/** Test summary section. */
@EqualsAndHashCode
@ToString
@Getter
@@ -33,5 +30,4 @@ public void addFailure() {
failure++;
total++;
}
-
}
diff --git a/integ-test/src/test/java/org/opensearch/sql/correctness/runner/resultset/Type.java b/integ-test/src/test/java/org/opensearch/sql/correctness/runner/resultset/Type.java
index 23cc0e3347..d626f75ccb 100644
--- a/integ-test/src/test/java/org/opensearch/sql/correctness/runner/resultset/Type.java
+++ b/integ-test/src/test/java/org/opensearch/sql/correctness/runner/resultset/Type.java
@@ -3,25 +3,17 @@
* SPDX-License-Identifier: Apache-2.0
*/
-
package org.opensearch.sql.correctness.runner.resultset;
import lombok.Data;
-/**
- * Column type in schema
- */
+/** Column type in schema */
@Data
public class Type {
- /**
- * Column name
- */
+ /** Column name */
private final String name;
- /**
- * Column type
- */
+ /** Column type */
private final String type;
-
}
diff --git a/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestConfigTest.java b/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestConfigTest.java
index 1abe6ea109..daf084d371 100644
--- a/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestConfigTest.java
+++ b/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestConfigTest.java
@@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/
-
package org.opensearch.sql.correctness.tests;
import static java.util.Collections.emptyMap;
@@ -18,9 +17,7 @@
import org.junit.Test;
import org.opensearch.sql.correctness.TestConfig;
-/**
- * Tests for {@link TestConfig}
- */
+/** Tests for {@link TestConfig} */
public class TestConfigTest {
@Test
@@ -31,9 +28,7 @@ public void testDefaultConfig() {
config.getOtherDbConnectionNameAndUrls(),
allOf(
hasEntry("H2", "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1"),
- hasEntry("SQLite", "jdbc:sqlite::memory:")
- )
- );
+ hasEntry("SQLite", "jdbc:sqlite::memory:")));
}
@Test
@@ -45,18 +40,16 @@ public void testCustomESUrls() {
@Test
public void testCustomDbUrls() {
- Map args = ImmutableMap.of("otherDbUrls",
- "H2=jdbc:h2:mem:test;DB_CLOSE_DELAY=-1,"
- + "Derby=jdbc:derby:memory:myDb;create=true");
+ Map args =
+ ImmutableMap.of(
+ "otherDbUrls",
+ "H2=jdbc:h2:mem:test;DB_CLOSE_DELAY=-1,Derby=jdbc:derby:memory:myDb;create=true");
TestConfig config = new TestConfig(args);
assertThat(
config.getOtherDbConnectionNameAndUrls(),
allOf(
hasEntry("H2", "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1"),
- hasEntry("Derby", "jdbc:derby:memory:myDb;create=true")
- )
- );
+ hasEntry("Derby", "jdbc:derby:memory:myDb;create=true")));
}
-
}
diff --git a/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestDataSetTest.java b/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestDataSetTest.java
index 3967d96658..7411df6a54 100644
--- a/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestDataSetTest.java
+++ b/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestDataSetTest.java
@@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/
-
package org.opensearch.sql.correctness.tests;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -13,9 +12,7 @@
import org.junit.Test;
import org.opensearch.sql.correctness.testset.TestDataSet;
-/**
- * Tests for {@link TestDataSet}
- */
+/** Tests for {@link TestDataSet} */
public class TestDataSetTest {
@Test
@@ -40,9 +37,7 @@ public void testDataSetWithSingleColumnData() {
new Object[] {"field"},
new Object[] {"hello"},
new Object[] {"world"},
- new Object[] {"123"}
- )
- );
+ new Object[] {"123"}));
}
@Test
@@ -61,16 +56,13 @@ public void testDataSetWithMultiColumnsData() {
+ " }\n"
+ "}";
- TestDataSet dataSet = new TestDataSet("test", mappings,
- "field1,field2\nhello,123\nworld,456");
+ TestDataSet dataSet = new TestDataSet("test", mappings, "field1,field2\nhello,123\nworld,456");
assertThat(
dataSet.getDataRows(),
contains(
new Object[] {"field1", "field2"},
new Object[] {"hello", 123},
- new Object[] {"world", 456}
- )
- );
+ new Object[] {"world", 456}));
}
@Test
@@ -86,17 +78,15 @@ public void testDataSetWithEscapedComma() {
+ " }\n"
+ "}";
- TestDataSet dataSet = new TestDataSet("test", mappings,
- "field\n\"hello,world,123\"\n123\n\"[abc,def,ghi]\"");
+ TestDataSet dataSet =
+ new TestDataSet("test", mappings, "field\n\"hello,world,123\"\n123\n\"[abc,def,ghi]\"");
assertThat(
dataSet.getDataRows(),
contains(
new Object[] {"field"},
new Object[] {"hello,world,123"},
new Object[] {"123"},
- new Object[] {"[abc,def,ghi]"}
- )
- );
+ new Object[] {"[abc,def,ghi]"}));
}
@Test
@@ -115,17 +105,13 @@ public void testDataSetWithNullData() {
+ " }\n"
+ "}";
- TestDataSet dataSet = new TestDataSet("test", mappings,
- "field1,field2\n,123\nworld,\n,");
+ TestDataSet dataSet = new TestDataSet("test", mappings, "field1,field2\n,123\nworld,\n,");
assertThat(
dataSet.getDataRows(),
contains(
new Object[] {"field1", "field2"},
new Object[] {null, 123},
new Object[] {"world", null},
- new Object[] {null, null}
- )
- );
+ new Object[] {null, null}));
}
-
}
diff --git a/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestQuerySetTest.java b/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestQuerySetTest.java
index 1c97f743f4..08d360dfc7 100644
--- a/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestQuerySetTest.java
+++ b/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestQuerySetTest.java
@@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/
-
package org.opensearch.sql.correctness.tests;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -12,22 +11,13 @@
import org.junit.Test;
import org.opensearch.sql.correctness.testset.TestQuerySet;
-/**
- * Tests for {@link TestQuerySet}
- */
+/** Tests for {@link TestQuerySet} */
public class TestQuerySetTest {
@Test
public void testQuerySet() {
TestQuerySet querySet =
new TestQuerySet("SELECT * FROM accounts\nSELECT * FROM accounts LIMIT 5");
- assertThat(
- querySet,
- contains(
- "SELECT * FROM accounts",
- "SELECT * FROM accounts LIMIT 5"
- )
- );
+ assertThat(querySet, contains("SELECT * FROM accounts", "SELECT * FROM accounts LIMIT 5"));
}
-
}
diff --git a/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestReportTest.java b/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestReportTest.java
index 35b64fd5d6..9ac5151b21 100644
--- a/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestReportTest.java
+++ b/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestReportTest.java
@@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/
-
package org.opensearch.sql.correctness.tests;
import static java.util.Arrays.asList;
@@ -20,9 +19,7 @@
import org.opensearch.sql.correctness.runner.resultset.Row;
import org.opensearch.sql.correctness.runner.resultset.Type;
-/**
- * Test for {@link TestReport}
- */
+/** Test for {@link TestReport} */
public class TestReportTest {
private TestReport report = new TestReport();
@@ -31,22 +28,22 @@ public class TestReportTest {
public void testSuccessReport() {
report.addTestCase(new SuccessTestCase(1, "SELECT * FROM accounts"));
JSONObject actual = new JSONObject(report);
- JSONObject expected = new JSONObject(
- "{" +
- " \"summary\": {" +
- " \"total\": 1," +
- " \"success\": 1," +
- " \"failure\": 0" +
- " }," +
- " \"tests\": [" +
- " {" +
- " \"id\": 1," +
- " \"result\": 'Success'," +
- " \"sql\": \"SELECT * FROM accounts\"," +
- " }" +
- " ]" +
- "}"
- );
+ JSONObject expected =
+ new JSONObject(
+ "{"
+ + " \"summary\": {"
+ + " \"total\": 1,"
+ + " \"success\": 1,"
+ + " \"failure\": 0"
+ + " },"
+ + " \"tests\": ["
+ + " {"
+ + " \"id\": 1,"
+ + " \"result\": 'Success',"
+ + " \"sql\": \"SELECT * FROM accounts\","
+ + " }"
+ + " ]"
+ + "}");
if (!actual.similar(expected)) {
fail("Actual JSON is different from expected: " + actual.toString(2));
@@ -55,54 +52,63 @@ public void testSuccessReport() {
@Test
public void testFailedReport() {
- report.addTestCase(new FailedTestCase(1, "SELECT * FROM accounts", asList(
- new DBResult("OpenSearch", singleton(new Type("firstName", "text")),
- singleton(new Row(asList("hello")))),
- new DBResult("H2", singleton(new Type("firstName", "text")),
- singleton(new Row(asList("world"))))),
- "[SQLITE_ERROR] SQL error or missing database;"
- ));
+ report.addTestCase(
+ new FailedTestCase(
+ 1,
+ "SELECT * FROM accounts",
+ asList(
+ new DBResult(
+ "OpenSearch",
+ singleton(new Type("firstName", "text")),
+ singleton(new Row(asList("hello")))),
+ new DBResult(
+ "H2",
+ singleton(new Type("firstName", "text")),
+ singleton(new Row(asList("world"))))),
+ "[SQLITE_ERROR] SQL error or missing database;"));
JSONObject actual = new JSONObject(report);
- JSONObject expected = new JSONObject(
- "{" +
- " \"summary\": {" +
- " \"total\": 1," +
- " \"success\": 0," +
- " \"failure\": 1" +
- " }," +
- " \"tests\": [" +
- " {" +
- " \"id\": 1," +
- " \"result\": 'Failed'," +
- " \"sql\": \"SELECT * FROM accounts\"," +
- " \"explain\": \"Data row at [0] is different: this=[Row(values=[world])], other=[Row(values=[hello])]\"," +
- " \"errors\": \"[SQLITE_ERROR] SQL error or missing database;\"," +
- " \"resultSets\": [" +
- " {" +
- " \"database\": \"H2\"," +
- " \"schema\": [" +
- " {" +
- " \"name\": \"firstName\"," +
- " \"type\": \"text\"" +
- " }" +
- " ]," +
- " \"dataRows\": [[\"world\"]]" +
- " }," +
- " {" +
- " \"database\": \"OpenSearch\"," +
- " \"schema\": [" +
- " {" +
- " \"name\": \"firstName\"," +
- " \"type\": \"text\"" +
- " }" +
- " ]," +
- " \"dataRows\": [[\"hello\"]]" +
- " }" +
- " ]" +
- " }" +
- " ]" +
- "}"
- );
+ JSONObject expected =
+ new JSONObject(
+ "{"
+ + " \"summary\": {"
+ + " \"total\": 1,"
+ + " \"success\": 0,"
+ + " \"failure\": 1"
+ + " },"
+ + " \"tests\": ["
+ + " {"
+ + " \"id\": 1,"
+ + " \"result\": 'Failed',"
+ + " \"sql\": \"SELECT * FROM accounts\","
+ + " \"explain\": \"Data row at [0] is different: "
+ + "this=[Row(values=[world])], "
+ + "other=[Row(values=[hello])]\","
+ + " \"errors\": \"[SQLITE_ERROR] SQL error or missing database;\","
+ + " \"resultSets\": ["
+ + " {"
+ + " \"database\": \"H2\","
+ + " \"schema\": ["
+ + " {"
+ + " \"name\": \"firstName\","
+ + " \"type\": \"text\""
+ + " }"
+ + " ],"
+ + " \"dataRows\": [[\"world\"]]"
+ + " },"
+ + " {"
+ + " \"database\": \"OpenSearch\","
+ + " \"schema\": ["
+ + " {"
+ + " \"name\": \"firstName\","
+ + " \"type\": \"text\""
+ + " }"
+ + " ],"
+ + " \"dataRows\": [[\"hello\"]]"
+ + " }"
+ + " ]"
+ + " }"
+ + " ]"
+ + "}");
if (!actual.similar(expected)) {
fail("Actual JSON is different from expected: " + actual.toString(2));
@@ -113,27 +119,26 @@ public void testFailedReport() {
public void testErrorReport() {
report.addTestCase(new ErrorTestCase(1, "SELECT * FROM", "Missing table name in query"));
JSONObject actual = new JSONObject(report);
- JSONObject expected = new JSONObject(
- "{" +
- " \"summary\": {" +
- " \"total\": 1," +
- " \"success\": 0," +
- " \"failure\": 1" +
- " }," +
- " \"tests\": [" +
- " {" +
- " \"id\": 1," +
- " \"result\": 'Failed'," +
- " \"sql\": \"SELECT * FROM\"," +
- " \"reason\": \"Missing table name in query\"," +
- " }" +
- " ]" +
- "}"
- );
+ JSONObject expected =
+ new JSONObject(
+ "{"
+ + " \"summary\": {"
+ + " \"total\": 1,"
+ + " \"success\": 0,"
+ + " \"failure\": 1"
+ + " },"
+ + " \"tests\": ["
+ + " {"
+ + " \"id\": 1,"
+ + " \"result\": 'Failed',"
+ + " \"sql\": \"SELECT * FROM\","
+ + " \"reason\": \"Missing table name in query\","
+ + " }"
+ + " ]"
+ + "}");
if (!actual.similar(expected)) {
fail("Actual JSON is different from expected: " + actual.toString(2));
}
}
-
}
diff --git a/integ-test/src/test/java/org/opensearch/sql/correctness/tests/UnitTests.java b/integ-test/src/test/java/org/opensearch/sql/correctness/tests/UnitTests.java
index 0bc5456069..367e2e10bf 100644
--- a/integ-test/src/test/java/org/opensearch/sql/correctness/tests/UnitTests.java
+++ b/integ-test/src/test/java/org/opensearch/sql/correctness/tests/UnitTests.java
@@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/
-
package org.opensearch.sql.correctness.tests;
import org.junit.runner.RunWith;
@@ -11,15 +10,14 @@
@RunWith(Suite.class)
@Suite.SuiteClasses({
- ComparisonTestTest.class,
- TestConfigTest.class,
- TestDataSetTest.class,
- TestQuerySetTest.class,
- TestReportTest.class,
- OpenSearchConnectionTest.class,
- JDBCConnectionTest.class,
- DBResultTest.class,
- RowTest.class,
+ ComparisonTestTest.class,
+ TestConfigTest.class,
+ TestDataSetTest.class,
+ TestQuerySetTest.class,
+ TestReportTest.class,
+ OpenSearchConnectionTest.class,
+ JDBCConnectionTest.class,
+ DBResultTest.class,
+ RowTest.class,
})
-public class UnitTests {
-}
+public class UnitTests {}
diff --git a/integ-test/src/test/java/org/opensearch/sql/correctness/testset/TestDataSet.java b/integ-test/src/test/java/org/opensearch/sql/correctness/testset/TestDataSet.java
index 66fc7c88af..25a3f907cf 100644
--- a/integ-test/src/test/java/org/opensearch/sql/correctness/testset/TestDataSet.java
+++ b/integ-test/src/test/java/org/opensearch/sql/correctness/testset/TestDataSet.java
@@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/
-
package org.opensearch.sql.correctness.testset;
import static java.util.stream.Collectors.joining;
@@ -15,9 +14,7 @@
import org.json.JSONObject;
import org.opensearch.sql.legacy.utils.StringUtils;
-/**
- * Test data set
- */
+/** Test data set */
public class TestDataSet {
private final String tableName;
@@ -42,9 +39,7 @@ public List getDataRows() {
return dataRows;
}
- /**
- * Split columns in each line by separator and ignore escaped separator(s) in quoted string.
- */
+ /** Split columns in each line by separator and ignore escaped separator(s) in quoted string. */
private List splitColumns(String content, char separator) {
List result = new ArrayList<>();
for (String line : content.split("\\r?\\n")) {
@@ -76,8 +71,8 @@ private List splitColumns(String content, char separator) {
}
/**
- * Convert column string values (read from CSV file) to objects of its real type
- * based on the type information in index mapping file.
+ * Convert column string values (read from CSV file) to objects of its real type based on the type
+ * information in index mapping file.
*/
private List convertStringDataToActualType(List rows) {
JSONObject types = new JSONObject(schema);
@@ -93,7 +88,8 @@ private List convertStringDataToActualType(List rows) {
return result;
}
- private Object[] convertStringArrayToObjectArray(JSONObject types, String[] columnNames, String[] row) {
+ private Object[] convertStringArrayToObjectArray(
+ JSONObject types, String[] columnNames, String[] row) {
Object[] result = new Object[row.length];
for (int i = 0; i < row.length; i++) {
String colName = columnNames[i];
@@ -126,22 +122,15 @@ private Object convertStringToObject(String type, String str) {
case "boolean":
return Boolean.valueOf(str);
default:
- throw new IllegalStateException(StringUtils.format(
- "Data type %s is not supported yet for value: %s", type, str));
+ throw new IllegalStateException(
+ StringUtils.format("Data type %s is not supported yet for value: %s", type, str));
}
}
@Override
public String toString() {
int total = dataRows.size();
- return "Test data set :\n"
- + " Table name: " + tableName + '\n'
- + " Schema: " + schema + '\n'
- + " Data rows (first 5 in " + total + "):"
- + dataRows.stream().
- limit(5).
- map(Arrays::toString).
- collect(joining("\n ", "\n ", "\n"));
+ return String.format("Test data set:\n Table name: %s\n Schema: %s\n Data rows (first 5 in %d):", tableName, schema, total)
+ + dataRows.stream().limit(5).map(Arrays::toString).collect(joining("\n ", "\n ", "\n"));
}
-
}
diff --git a/integ-test/src/test/java/org/opensearch/sql/correctness/testset/TestQuerySet.java b/integ-test/src/test/java/org/opensearch/sql/correctness/testset/TestQuerySet.java
index 7eee2cde9f..161d314c1d 100644
--- a/integ-test/src/test/java/org/opensearch/sql/correctness/testset/TestQuerySet.java
+++ b/integ-test/src/test/java/org/opensearch/sql/correctness/testset/TestQuerySet.java
@@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/
-
package org.opensearch.sql.correctness.testset;
import static java.util.stream.Collectors.joining;
@@ -12,9 +11,7 @@
import java.util.Iterator;
import java.util.List;
-/**
- * Test query set including SQL queries for comparison testing.
- */
+/** Test query set including SQL queries for comparison testing. */
public class TestQuerySet implements Iterable {
private List queries;
@@ -49,10 +46,9 @@ private List lines(String content) {
@Override
public String toString() {
int total = queries.size();
- return "SQL queries (first 5 in " + total + "):"
- + queries.stream().
- limit(5).
- collect(joining("\n ", "\n ", "\n"));
+ return "SQL queries (first 5 in "
+ + total
+ + "):"
+ + queries.stream().limit(5).collect(joining("\n ", "\n ", "\n"));
}
-
}
diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/SubqueryIT.java b/integ-test/src/test/java/org/opensearch/sql/legacy/SubqueryIT.java
index 0fd0fea7f7..c1d656628f 100644
--- a/integ-test/src/test/java/org/opensearch/sql/legacy/SubqueryIT.java
+++ b/integ-test/src/test/java/org/opensearch/sql/legacy/SubqueryIT.java
@@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/
-
package org.opensearch.sql.legacy;
import static org.hamcrest.Matchers.both;
@@ -38,9 +37,7 @@
public class SubqueryIT extends SQLIntegTestCase {
- @Rule
- public ExpectedException exceptionRule = ExpectedException.none();
-
+ @Rule public ExpectedException exceptionRule = ExpectedException.none();
@Override
protected void init() throws Exception {
@@ -51,50 +48,55 @@ protected void init() throws Exception {
@Test
public void testIN() throws IOException {
- String query = String.format(Locale.ROOT,
- "SELECT dog_name " +
- "FROM %s A " +
- "WHERE holdersName IN (SELECT firstname FROM %s B) " +
- "AND dog_name <> 'babala'",
- TEST_INDEX_DOGSUBQUERY, TEST_INDEX_ACCOUNT);
+ String query =
+ String.format(
+ Locale.ROOT,
+ "SELECT dog_name "
+ + "FROM %s A "
+ + "WHERE holdersName IN (SELECT firstname FROM %s B) "
+ + "AND dog_name <> 'babala'",
+ TEST_INDEX_DOGSUBQUERY,
+ TEST_INDEX_ACCOUNT);
JSONObject response = executeQuery(query);
assertThat(
response,
hitAll(
kvString("/_source/A.dog_name", is("snoopy")),
- kvString("/_source/A.dog_name", is("gogo"))
- )
- );
+ kvString("/_source/A.dog_name", is("gogo"))));
}
@Test
public void testINWithAlias() throws IOException {
- String query = String.format(Locale.ROOT,
- "SELECT A.dog_name " +
- "FROM %s A " +
- "WHERE A.holdersName IN (SELECT B.firstname FROM %s B) " +
- "AND A.dog_name <> 'babala'",
- TEST_INDEX_DOGSUBQUERY, TEST_INDEX_ACCOUNT);
+ String query =
+ String.format(
+ Locale.ROOT,
+ "SELECT A.dog_name "
+ + "FROM %s A "
+ + "WHERE A.holdersName IN (SELECT B.firstname FROM %s B) "
+ + "AND A.dog_name <> 'babala'",
+ TEST_INDEX_DOGSUBQUERY,
+ TEST_INDEX_ACCOUNT);
JSONObject response = executeQuery(query);
assertThat(
response,
hitAll(
kvString("/_source/A.dog_name", is("snoopy")),
- kvString("/_source/A.dog_name", is("gogo"))
- )
- );
+ kvString("/_source/A.dog_name", is("gogo"))));
}
@Test
public void testINSelectAll() throws IOException {
- String query = String.format(Locale.ROOT,
- "SELECT * " +
- "FROM %s A " +
- "WHERE holdersName IN (SELECT firstname FROM %s B) " +
- "AND dog_name <> 'babala'",
- TEST_INDEX_DOGSUBQUERY, TEST_INDEX_ACCOUNT);
+ String query =
+ String.format(
+ Locale.ROOT,
+ "SELECT * "
+ + "FROM %s A "
+ + "WHERE holdersName IN (SELECT firstname FROM %s B) "
+ + "AND dog_name <> 'babala'",
+ TEST_INDEX_DOGSUBQUERY,
+ TEST_INDEX_ACCOUNT);
JSONObject response = executeQuery(query);
assertThat(
@@ -105,39 +107,38 @@ public void testINSelectAll() throws IOException {
.and(kvInt("/_source/A.age", is(4))),
both(kvString("/_source/A.dog_name", is("gogo")))
.and(kvString("/_source/A.holdersName", is("Gabrielle")))
- .and(kvInt("/_source/A.age", is(6)))
- )
- );
+ .and(kvInt("/_source/A.age", is(6)))));
}
@Test
public void testINWithInnerWhere() throws IOException {
- String query = String.format(Locale.ROOT,
- "SELECT dog_name " +
- "FROM %s A " +
- "WHERE holdersName IN (SELECT firstname FROM %s B WHERE age <> 36) " +
- "AND dog_name <> 'babala'",
- TEST_INDEX_DOGSUBQUERY, TEST_INDEX_ACCOUNT);
+ String query =
+ String.format(
+ Locale.ROOT,
+ "SELECT dog_name "
+ + "FROM %s A "
+ + "WHERE holdersName IN (SELECT firstname FROM %s B WHERE age <> 36) "
+ + "AND dog_name <> 'babala'",
+ TEST_INDEX_DOGSUBQUERY,
+ TEST_INDEX_ACCOUNT);
JSONObject response = executeQuery(query);
- assertThat(
- response,
- hitAll(
- kvString("/_source/A.dog_name", is("gogo"))
- )
- );
+ assertThat(response, hitAll(kvString("/_source/A.dog_name", is("gogo"))));
}
@Test
public void testNotSupportedQuery() throws IOException {
exceptionRule.expect(ResponseException.class);
exceptionRule.expectMessage("Unsupported subquery");
- String query = String.format(Locale.ROOT,
- "SELECT dog_name " +
- "FROM %s A " +
- "WHERE holdersName NOT IN (SELECT firstname FROM %s B WHERE age <> 36) " +
- "AND dog_name <> 'babala'",
- TEST_INDEX_DOGSUBQUERY, TEST_INDEX_ACCOUNT);
+ String query =
+ String.format(
+ Locale.ROOT,
+ "SELECT dog_name "
+ + "FROM %s A "
+ + "WHERE holdersName NOT IN (SELECT firstname FROM %s B WHERE age <> 36) "
+ + "AND dog_name <> 'babala'",
+ TEST_INDEX_DOGSUBQUERY,
+ TEST_INDEX_ACCOUNT);
executeQuery(query);
}
@@ -145,100 +146,91 @@ public void testNotSupportedQuery() throws IOException {
@Ignore
@Test
public void testINWithDuplicate() throws IOException {
- String query = String.format(Locale.ROOT,
- "SELECT dog_name " +
- "FROM %s A " +
- "WHERE holdersName IN (SELECT firstname FROM %s B)",
- TEST_INDEX_DOGSUBQUERY, TEST_INDEX_ACCOUNT);
+ String query =
+ String.format(
+ Locale.ROOT,
+ "SELECT dog_name FROM %s A WHERE holdersName IN (SELECT firstname FROM %s B)",
+ TEST_INDEX_DOGSUBQUERY,
+ TEST_INDEX_ACCOUNT);
JSONObject response = executeQuery(query);
assertThat(
response,
hitAll(
kvString("/_source/A.dog_name", is("snoopy")),
- kvString("/_source/A.dog_name", is("babala"))
- )
- );
+ kvString("/_source/A.dog_name", is("babala"))));
}
@Test
public void nonCorrelatedExists() throws IOException {
- String query = String.format(Locale.ROOT,
- "SELECT e.name " +
- "FROM %s as e " +
- "WHERE EXISTS (SELECT * FROM e.projects as p)",
- TEST_INDEX_EMPLOYEE_NESTED);
+ String query =
+ String.format(
+ Locale.ROOT,
+ "SELECT e.name FROM %s as e WHERE EXISTS (SELECT * FROM e.projects as p)",
+ TEST_INDEX_EMPLOYEE_NESTED);
JSONObject response = executeQuery(query);
assertThat(
response,
hitAll(
kvString("/_source/name", is("Bob Smith")),
- kvString("/_source/name", is("Jane Smith"))
- )
- );
+ kvString("/_source/name", is("Jane Smith"))));
}
@Test
public void nonCorrelatedExistsWhere() throws IOException {
- String query = String.format(Locale.ROOT,
- "SELECT e.name " +
- "FROM %s as e " +
- "WHERE EXISTS (SELECT * FROM e.projects as p WHERE p.name LIKE 'aurora')",
- TEST_INDEX_EMPLOYEE_NESTED);
+ String query =
+ String.format(
+ Locale.ROOT,
+ "SELECT e.name "
+ + "FROM %s as e "
+ + "WHERE EXISTS (SELECT * FROM e.projects as p WHERE p.name LIKE 'aurora')",
+ TEST_INDEX_EMPLOYEE_NESTED);
JSONObject response = executeQuery(query);
- assertThat(
- response,
- hitAll(
- kvString("/_source/name", is("Bob Smith"))
- )
- );
+ assertThat(response, hitAll(kvString("/_source/name", is("Bob Smith"))));
}
@Test
public void nonCorrelatedExistsParentWhere() throws IOException {
- String query = String.format(Locale.ROOT,
- "SELECT e.name " +
- "FROM %s as e " +
- "WHERE EXISTS (SELECT * FROM e.projects as p WHERE p.name LIKE 'security') " +
- "AND e.name LIKE 'jane'",
- TEST_INDEX_EMPLOYEE_NESTED);
+ String query =
+ String.format(
+ Locale.ROOT,
+ "SELECT e.name "
+ + "FROM %s as e "
+ + "WHERE EXISTS (SELECT * FROM e.projects as p WHERE p.name LIKE 'security') "
+ + "AND e.name LIKE 'jane'",
+ TEST_INDEX_EMPLOYEE_NESTED);
JSONObject response = executeQuery(query);
- assertThat(
- response,
- hitAll(
- kvString("/_source/name", is("Jane Smith"))
- )
- );
+ assertThat(response, hitAll(kvString("/_source/name", is("Jane Smith"))));
}
@Test
public void nonCorrelatedNotExists() throws IOException {
- String query = String.format(Locale.ROOT,
- "SELECT e.name " +
- "FROM %s as e " +
- "WHERE NOT EXISTS (SELECT * FROM e.projects as p)",
- TEST_INDEX_EMPLOYEE_NESTED);
+ String query =
+ String.format(
+ Locale.ROOT,
+ "SELECT e.name FROM %s as e WHERE NOT EXISTS (SELECT * FROM e.projects as p)",
+ TEST_INDEX_EMPLOYEE_NESTED);
JSONObject response = executeQuery(query);
assertThat(
response,
hitAll(
kvString("/_source/name", is("Susan Smith")),
- kvString("/_source/name", is("John Doe"))
- )
- );
+ kvString("/_source/name", is("John Doe"))));
}
@Test
public void nonCorrelatedNotExistsWhere() throws IOException {
- String query = String.format(Locale.ROOT,
- "SELECT e.name " +
- "FROM %s as e " +
- "WHERE NOT EXISTS (SELECT * FROM e.projects as p WHERE p.name LIKE 'aurora')",
- TEST_INDEX_EMPLOYEE_NESTED);
+ String query =
+ String.format(
+ Locale.ROOT,
+ "SELECT e.name "
+ + "FROM %s as e "
+ + "WHERE NOT EXISTS (SELECT * FROM e.projects as p WHERE p.name LIKE 'aurora')",
+ TEST_INDEX_EMPLOYEE_NESTED);
JSONObject response = executeQuery(query);
assertThat(
@@ -246,52 +238,55 @@ public void nonCorrelatedNotExistsWhere() throws IOException {
hitAll(
kvString("/_source/name", is("Susan Smith")),
kvString("/_source/name", is("Jane Smith")),
- kvString("/_source/name", is("John Doe"))
- )
- );
+ kvString("/_source/name", is("John Doe"))));
}
@Test
public void nonCorrelatedNotExistsParentWhere() throws IOException {
- String query = String.format(Locale.ROOT,
- "SELECT e.name " +
- "FROM %s as e " +
- "WHERE NOT EXISTS (SELECT * FROM e.projects as p WHERE p.name LIKE 'security') " +
- "AND e.name LIKE 'smith'",
- TEST_INDEX_EMPLOYEE_NESTED);
+ String query =
+ String.format(
+ Locale.ROOT,
+ "SELECT e.name "
+ + "FROM %s as e "
+ + "WHERE NOT EXISTS (SELECT * FROM e.projects as p WHERE p.name LIKE 'security') "
+ + "AND e.name LIKE 'smith'",
+ TEST_INDEX_EMPLOYEE_NESTED);
JSONObject response = executeQuery(query);
- assertThat(
- response,
- hitAll(
- kvString("/_source/name", is("Susan Smith"))
- )
- );
+ assertThat(response, hitAll(kvString("/_source/name", is("Susan Smith"))));
}
@Test
public void selectFromSubqueryWithCountShouldPass() throws IOException {
- JSONObject result = executeQuery(
- StringUtils.format("SELECT t.TEMP as count " +
- "FROM (SELECT COUNT(*) as TEMP FROM %s) t", TEST_INDEX_ACCOUNT));
+ JSONObject result =
+ executeQuery(
+ StringUtils.format(
+ "SELECT t.TEMP as count FROM (SELECT COUNT(*) as TEMP FROM %s) t",
+ TEST_INDEX_ACCOUNT));
assertThat(result.query("/aggregations/count/value"), equalTo(1000));
}
@Test
public void selectFromSubqueryWithWhereAndCountShouldPass() throws IOException {
- JSONObject result = executeQuery(
- StringUtils.format("SELECT t.TEMP as count " +
- "FROM (SELECT COUNT(*) as TEMP FROM %s WHERE age > 30) t", TEST_INDEX_ACCOUNT));
+ JSONObject result =
+ executeQuery(
+ StringUtils.format(
+ "SELECT t.TEMP as count "
+ + "FROM (SELECT COUNT(*) as TEMP FROM %s WHERE age > 30) t",
+ TEST_INDEX_ACCOUNT));
assertThat(result.query("/aggregations/count/value"), equalTo(502));
}
@Test
public void selectFromSubqueryWithCountAndGroupByShouldPass() throws Exception {
- JSONObject result = executeQuery(
- StringUtils.format("SELECT t.TEMP as count " +
- "FROM (SELECT COUNT(*) as TEMP FROM %s GROUP BY gender) t", TEST_INDEX_ACCOUNT));
+ JSONObject result =
+ executeQuery(
+ StringUtils.format(
+ "SELECT t.TEMP as count "
+ + "FROM (SELECT COUNT(*) as TEMP FROM %s GROUP BY gender) t",
+ TEST_INDEX_ACCOUNT));
assertThat(getTotalHits(result), equalTo(1000));
JSONObject gender = (JSONObject) result.query("/aggregations/gender");
@@ -312,11 +307,12 @@ public void selectFromSubqueryWithCountAndGroupByShouldPass() throws Exception {
@Test
public void selectFromSubqueryWithCountAndGroupByAndOrderByShouldPass() throws IOException {
- JSONObject result = executeQuery(
- StringUtils.format(
- "SELECT t.TEMP as count " +
- "FROM (SELECT COUNT(*) as TEMP FROM %s GROUP BY age ORDER BY TEMP) t",
- TEST_INDEX_ACCOUNT));
+ JSONObject result =
+ executeQuery(
+ StringUtils.format(
+ "SELECT t.TEMP as count "
+ + "FROM (SELECT COUNT(*) as TEMP FROM %s GROUP BY age ORDER BY TEMP) t",
+ TEST_INDEX_ACCOUNT));
JSONArray buckets = (JSONArray) result.query("/aggregations/age/buckets");
List countList = new ArrayList<>();
for (int i = 0; i < buckets.length(); ++i) {
@@ -328,44 +324,50 @@ public void selectFromSubqueryWithCountAndGroupByAndOrderByShouldPass() throws I
@Test
public void selectFromSubqueryWithCountAndGroupByAndHavingShouldPass() throws Exception {
- JSONObject result = executeQuery(
- StringUtils.format("SELECT t.T1 as g, t.T2 as c " +
- "FROM (SELECT gender as T1, COUNT(*) as T2 " +
- " FROM %s " +
- " GROUP BY gender " +
- " HAVING T2 > 500) t", TEST_INDEX_ACCOUNT));
+ JSONObject result =
+ executeQuery(
+ StringUtils.format(
+ "SELECT t.T1 as g, t.T2 as c "
+ + "FROM (SELECT gender as T1, COUNT(*) as T2 "
+ + " FROM %s "
+ + " GROUP BY gender "
+ + " HAVING T2 > 500) t",
+ TEST_INDEX_ACCOUNT));
assertThat(result.query("/aggregations/g/buckets/0/c/value"), equalTo(507));
}
@Test
public void selectFromSubqueryCountAndSum() throws IOException {
- JSONObject result = executeQuery(
- StringUtils.format(
- "SELECT t.TEMP1 as count, t.TEMP2 as balance " +
- "FROM (SELECT COUNT(*) as TEMP1, SUM(balance) as TEMP2 " +
- " FROM %s) t",
- TEST_INDEX_ACCOUNT));
+ JSONObject result =
+ executeQuery(
+ StringUtils.format(
+ "SELECT t.TEMP1 as count, t.TEMP2 as balance "
+ + "FROM (SELECT COUNT(*) as TEMP1, SUM(balance) as TEMP2 "
+ + " FROM %s) t",
+ TEST_INDEX_ACCOUNT));
assertThat(result.query("/aggregations/count/value"), equalTo(1000));
- assertThat(((BigDecimal) result.query("/aggregations/balance/value")).doubleValue(),
+ assertThat(
+ ((BigDecimal) result.query("/aggregations/balance/value")).doubleValue(),
closeTo(25714837.0, 0.01));
}
@Test
public void selectFromSubqueryWithoutAliasShouldPass() throws IOException {
- JSONObject response = executeJdbcRequest(
- StringUtils.format(
- "SELECT a.firstname AS my_first, a.lastname AS my_last, a.age AS my_age " +
- "FROM (SELECT firstname, lastname, age " +
- "FROM %s " +
- "WHERE age = 40 and account_number = 291) AS a",
- TEST_INDEX_ACCOUNT));
-
- verifySchema(response,
+ JSONObject response =
+ executeJdbcRequest(
+ StringUtils.format(
+ "SELECT a.firstname AS my_first, a.lastname AS my_last, a.age AS my_age "
+ + "FROM (SELECT firstname, lastname, age "
+ + "FROM %s "
+ + "WHERE age = 40 and account_number = 291) AS a",
+ TEST_INDEX_ACCOUNT));
+
+ verifySchema(
+ response,
schema("firstname", "my_first", "text"),
schema("lastname", "my_last", "text"),
schema("age", "my_age", "long"));
- verifyDataRows(response,
- rows("Lynn", "Pollard", 40));
+ verifyDataRows(response, rows("Lynn", "Pollard", 40));
}
}
diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/TermQueryExplainIT.java b/integ-test/src/test/java/org/opensearch/sql/legacy/TermQueryExplainIT.java
index fcc9b048c9..6c33b2b242 100644
--- a/integ-test/src/test/java/org/opensearch/sql/legacy/TermQueryExplainIT.java
+++ b/integ-test/src/test/java/org/opensearch/sql/legacy/TermQueryExplainIT.java
@@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/
-
package org.opensearch.sql.legacy;
import static org.hamcrest.Matchers.containsString;
@@ -17,7 +16,6 @@
import org.opensearch.client.ResponseException;
import org.opensearch.core.rest.RestStatus;
-
public class TermQueryExplainIT extends SQLIntegTestCase {
@Override
@@ -35,13 +33,15 @@ protected void init() throws Exception {
@Test
public void testNonExistingIndex() throws IOException {
try {
- explainQuery("SELECT firstname, lastname " +
- "FROM opensearch_sql_test_fake_index " +
- "WHERE firstname = 'Leo'");
+ explainQuery(
+ "SELECT firstname, lastname "
+ + "FROM opensearch_sql_test_fake_index "
+ + "WHERE firstname = 'Leo'");
Assert.fail("Expected ResponseException, but none was thrown");
} catch (ResponseException e) {
- assertThat(e.getResponse().getStatusLine().getStatusCode(),
+ assertThat(
+ e.getResponse().getStatusLine().getStatusCode(),
equalTo(RestStatus.BAD_REQUEST.getStatus()));
final String entity = TestUtils.getResponseBody(e.getResponse());
assertThat(entity, containsString("no such index"));
@@ -52,13 +52,13 @@ public void testNonExistingIndex() throws IOException {
@Test
public void testNonResolvingIndexPattern() throws IOException {
try {
- explainQuery("SELECT * " +
- "FROM opensearch_sql_test_blah_blah* " +
- "WHERE firstname = 'Leo'");
+ explainQuery(
+ "SELECT * FROM opensearch_sql_test_blah_blah* WHERE firstname = 'Leo'");
Assert.fail("Expected ResponseException, but none was thrown");
} catch (ResponseException e) {
- assertThat(e.getResponse().getStatusLine().getStatusCode(),
+ assertThat(
+ e.getResponse().getStatusLine().getStatusCode(),
equalTo(RestStatus.BAD_REQUEST.getStatus()));
final String entity = TestUtils.getResponseBody(e.getResponse());
assertThat(entity, containsString("Field [firstname] cannot be found or used here."));
@@ -68,10 +68,11 @@ public void testNonResolvingIndexPattern() throws IOException {
@Test
public void testNonResolvingIndexPatternWithExistingIndex() throws IOException {
- String result = explainQuery(
- "SELECT * " +
- "FROM opensearch_sql_test_blah_blah*, opensearch-sql_test_index_bank " +
- "WHERE state = 'DC'");
+ String result =
+ explainQuery(
+ "SELECT * "
+ + "FROM opensearch_sql_test_blah_blah*, opensearch-sql_test_index_bank "
+ + "WHERE state = 'DC'");
assertThat(result, containsString("\"term\":{\"state.keyword\""));
}
@@ -79,12 +80,13 @@ public void testNonResolvingIndexPatternWithExistingIndex() throws IOException {
public void testNonResolvingIndexPatternWithNonExistingIndex() throws IOException {
try {
explainQuery(
- "SELECT firstname, lastname " +
- "FROM opensearch_sql_test_blah_blah*, another_fake_index " +
- "WHERE firstname = 'Leo'");
+ "SELECT firstname, lastname "
+ + "FROM opensearch_sql_test_blah_blah*, another_fake_index "
+ + "WHERE firstname = 'Leo'");
Assert.fail("Expected ResponseException, but none was thrown");
} catch (ResponseException e) {
- assertThat(e.getResponse().getStatusLine().getStatusCode(),
+ assertThat(
+ e.getResponse().getStatusLine().getStatusCode(),
equalTo(RestStatus.BAD_REQUEST.getStatus()));
final String entity = TestUtils.getResponseBody(e.getResponse());
assertThat(entity, containsString("no such index"));
@@ -95,11 +97,11 @@ public void testNonResolvingIndexPatternWithNonExistingIndex() throws IOExceptio
@Test
public void testNonCompatibleMappings() throws IOException {
try {
- explainQuery(
- "SELECT * FROM opensearch-sql_test_index_dog, opensearch-sql_test_index_dog2");
+ explainQuery("SELECT * FROM opensearch-sql_test_index_dog, opensearch-sql_test_index_dog2");
Assert.fail("Expected ResponseException, but none was thrown");
} catch (ResponseException e) {
- assertThat(e.getResponse().getStatusLine().getStatusCode(),
+ assertThat(
+ e.getResponse().getStatusLine().getStatusCode(),
equalTo(RestStatus.BAD_REQUEST.getStatus()));
final String entity = TestUtils.getResponseBody(e.getResponse());
assertThat(entity, containsString("Field [holdersName] have conflict type"));
@@ -108,14 +110,15 @@ public void testNonCompatibleMappings() throws IOException {
}
/**
- * The dog_name field has same type in dog and dog2 index.
- * But, the holdersName field has different type.
+ * The dog_name field has same type in dog and dog2 index. But, the holdersName field has
+ * different type.
*/
@Test
public void testNonCompatibleMappingsButTheFieldIsNotUsed() throws IOException {
- String result = explainQuery(
- "SELECT dog_name " +
- "FROM opensearch-sql_test_index_dog, opensearch-sql_test_index_dog2 WHERE dog_name = 'dog'");
+ String result =
+ explainQuery(
+ "SELECT dog_name FROM opensearch-sql_test_index_dog, opensearch-sql_test_index_dog2"
+ + " WHERE dog_name = 'dog'");
System.out.println(result);
assertThat(result, containsString("dog_name"));
assertThat(result, containsString("_source"));
@@ -123,20 +126,21 @@ public void testNonCompatibleMappingsButTheFieldIsNotUsed() throws IOException {
@Test
public void testEqualFieldMappings() throws IOException {
- String result = explainQuery(
- "SELECT color " +
- "FROM opensearch-sql_test_index_dog2, opensearch-sql_test_index_dog3");
+ String result =
+ explainQuery(
+ "SELECT color "
+ + "FROM opensearch-sql_test_index_dog2, opensearch-sql_test_index_dog3");
assertThat(result, containsString("color"));
assertThat(result, containsString("_source"));
}
@Test
public void testIdenticalMappings() throws IOException {
- String result = explainQuery(
- "SELECT firstname, birthdate, state " +
- "FROM opensearch-sql_test_index_bank, opensearch-sql_test_index_bank_two " +
- "WHERE state = 'WA' OR male = true"
- );
+ String result =
+ explainQuery(
+ "SELECT firstname, birthdate, state "
+ + "FROM opensearch-sql_test_index_bank, opensearch-sql_test_index_bank_two "
+ + "WHERE state = 'WA' OR male = true");
assertThat(result, containsString("term"));
assertThat(result, containsString("state.keyword"));
assertThat(result, containsString("_source"));
@@ -144,24 +148,23 @@ public void testIdenticalMappings() throws IOException {
@Test
public void testIdenticalMappingsWithTypes() throws IOException {
- String result = explainQuery(
- "SELECT firstname, birthdate, state " +
- "FROM opensearch-sql_test_index_bank/account, opensearch-sql_test_index_bank_two/account_two " +
- "WHERE state = 'WA' OR male = true"
- );
+ String result =
+ explainQuery(
+ "SELECT firstname, birthdate, state FROM opensearch-sql_test_index_bank/account,"
+ + " opensearch-sql_test_index_bank_two/account_two WHERE state = 'WA' OR male ="
+ + " true");
assertThat(result, containsString("term"));
assertThat(result, containsString("state.keyword"));
assertThat(result, containsString("_source"));
}
-
@Test
public void testIdenticalMappingsWithPartialType() throws IOException {
- String result = explainQuery(
- "SELECT firstname, birthdate, state " +
- "FROM opensearch-sql_test_index_bank/account, opensearch-sql_test_index_bank_two " +
- "WHERE state = 'WA' OR male = true"
- );
+ String result =
+ explainQuery(
+ "SELECT firstname, birthdate, state "
+ + "FROM opensearch-sql_test_index_bank/account, opensearch-sql_test_index_bank_two "
+ + "WHERE state = 'WA' OR male = true");
assertThat(result, containsString("term"));
assertThat(result, containsString("state.keyword"));
assertThat(result, containsString("_source"));
@@ -170,22 +173,22 @@ public void testIdenticalMappingsWithPartialType() throws IOException {
@Test
public void testTextFieldOnly() throws IOException {
- String result = explainQuery(
- "SELECT firstname, birthdate, state " +
- "FROM opensearch-sql_test_index_bank " +
- "WHERE firstname = 'Abbas'"
- );
+ String result =
+ explainQuery(
+ "SELECT firstname, birthdate, state "
+ + "FROM opensearch-sql_test_index_bank "
+ + "WHERE firstname = 'Abbas'");
assertThat(result, containsString("term"));
assertThat(result, not(containsString("firstname.")));
}
@Test
public void testTextAndKeywordAppendsKeywordAlias() throws IOException {
- String result = explainQuery(
- "SELECT firstname, birthdate, state " +
- "FROM opensearch-sql_test_index_bank " +
- "WHERE state = 'WA' OR lastname = 'Chen'"
- );
+ String result =
+ explainQuery(
+ "SELECT firstname, birthdate, state "
+ + "FROM opensearch-sql_test_index_bank "
+ + "WHERE state = 'WA' OR lastname = 'Chen'");
assertThat(result, containsString("term"));
assertThat(result, containsString("state.keyword"));
assertThat(result, not(containsString("lastname.")));
@@ -194,8 +197,7 @@ public void testTextAndKeywordAppendsKeywordAlias() throws IOException {
@Test
public void testBooleanFieldNoKeywordAlias() throws IOException {
- String result =
- explainQuery("SELECT * FROM opensearch-sql_test_index_bank WHERE male = false");
+ String result = explainQuery("SELECT * FROM opensearch-sql_test_index_bank WHERE male = false");
assertThat(result, containsString("term"));
assertThat(result, not(containsString("male.")));
}
@@ -203,8 +205,8 @@ public void testBooleanFieldNoKeywordAlias() throws IOException {
@Test
public void testDateFieldNoKeywordAlias() throws IOException {
- String result = explainQuery(
- "SELECT * FROM opensearch-sql_test_index_bank WHERE birthdate = '2018-08-19'");
+ String result =
+ explainQuery("SELECT * FROM opensearch-sql_test_index_bank WHERE birthdate = '2018-08-19'");
assertThat(result, containsString("term"));
assertThat(result, not(containsString("birthdate.")));
}
@@ -218,11 +220,11 @@ public void testNumberNoKeywordAlias() throws IOException {
@Test
public void inTestInWhere() throws IOException {
- String result = explainQuery(
- "SELECT * " +
- "FROM opensearch-sql_test_index_bank " +
- "WHERE state IN ('WA' , 'PA' , 'TN')"
- );
+ String result =
+ explainQuery(
+ "SELECT * "
+ + "FROM opensearch-sql_test_index_bank "
+ + "WHERE state IN ('WA' , 'PA' , 'TN')");
assertThat(result, containsString("term"));
assertThat(result, containsString("state.keyword"));
}
@@ -230,53 +232,52 @@ public void inTestInWhere() throws IOException {
@Test
@Ignore // TODO: enable when subqueries are fixed
public void inTestInWhereSubquery() throws IOException {
- String result = explainQuery(
- "SELECT * " +
- "FROM opensearch-sql_test_index_bank/account WHERE " +
- "state IN (SELECT state FROM opensearch-sql_test_index_bank WHERE city = 'Nicholson')"
- );
+ String result =
+ explainQuery(
+ "SELECT * FROM opensearch-sql_test_index_bank/account WHERE state IN (SELECT state FROM"
+ + " opensearch-sql_test_index_bank WHERE city = 'Nicholson')");
assertThat(result, containsString("term"));
assertThat(result, containsString("state.keyword"));
}
@Test
public void testKeywordAliasGroupBy() throws IOException {
- String result = explainQuery(
- "SELECT firstname, state " +
- "FROM opensearch-sql_test_index_bank/account " +
- "GROUP BY firstname, state");
+ String result =
+ explainQuery(
+ "SELECT firstname, state "
+ + "FROM opensearch-sql_test_index_bank/account "
+ + "GROUP BY firstname, state");
assertThat(result, containsString("term"));
assertThat(result, containsString("state.keyword"));
}
@Test
public void testKeywordAliasGroupByUsingTableAlias() throws IOException {
- String result = explainQuery(
- "SELECT a.firstname, a.state " +
- "FROM opensearch-sql_test_index_bank/account a " +
- "GROUP BY a.firstname, a.state");
+ String result =
+ explainQuery(
+ "SELECT a.firstname, a.state "
+ + "FROM opensearch-sql_test_index_bank/account a "
+ + "GROUP BY a.firstname, a.state");
assertThat(result, containsString("term"));
assertThat(result, containsString("state.keyword"));
}
@Test
public void testKeywordAliasOrderBy() throws IOException {
- String result = explainQuery(
- "SELECT * " +
- "FROM opensearch-sql_test_index_bank " +
- "ORDER BY state, lastname "
- );
+ String result =
+ explainQuery(
+ "SELECT * FROM opensearch-sql_test_index_bank ORDER BY state, lastname ");
assertThat(result, containsString("\"state.keyword\":{\"order\":\"asc\""));
assertThat(result, containsString("\"lastname\":{\"order\":\"asc\"}"));
}
@Test
public void testKeywordAliasOrderByUsingTableAlias() throws IOException {
- String result = explainQuery(
- "SELECT * " +
- "FROM opensearch-sql_test_index_bank b " +
- "ORDER BY b.state, b.lastname "
- );
+ String result =
+ explainQuery(
+ "SELECT * "
+ + "FROM opensearch-sql_test_index_bank b "
+ + "ORDER BY b.state, b.lastname ");
assertThat(result, containsString("\"state.keyword\":{\"order\":\"asc\""));
assertThat(result, containsString("\"lastname\":{\"order\":\"asc\"}"));
}
@@ -286,13 +287,13 @@ public void testKeywordAliasOrderByUsingTableAlias() throws IOException {
public void testJoinWhere() throws IOException {
String expectedOutput =
TestUtils.fileToString("src/test/resources/expectedOutput/term_join_where", true);
- String result = explainQuery(
- "SELECT a.firstname, a.lastname , b.city " +
- "FROM opensearch-sql_test_index_account a " +
- "JOIN opensearch-sql_test_index_account b " +
- "ON a.city = b.city " +
- "WHERE a.city IN ('Nicholson', 'Yardville')"
- );
+ String result =
+ explainQuery(
+ "SELECT a.firstname, a.lastname , b.city "
+ + "FROM opensearch-sql_test_index_account a "
+ + "JOIN opensearch-sql_test_index_account b "
+ + "ON a.city = b.city "
+ + "WHERE a.city IN ('Nicholson', 'Yardville')");
assertThat(result.replaceAll("\\s+", ""), equalTo(expectedOutput.replaceAll("\\s+", "")));
}
@@ -301,57 +302,56 @@ public void testJoinWhere() throws IOException {
public void testJoinAliasMissing() throws IOException {
try {
explainQuery(
- "SELECT a.firstname, a.lastname , b.city " +
- "FROM opensearch-sql_test_index_account a " +
- "JOIN opensearch-sql_test_index_account b " +
- "ON a.city = b.city " +
- "WHERE city IN ('Nicholson', 'Yardville')"
- );
+ "SELECT a.firstname, a.lastname , b.city "
+ + "FROM opensearch-sql_test_index_account a "
+ + "JOIN opensearch-sql_test_index_account b "
+ + "ON a.city = b.city "
+ + "WHERE city IN ('Nicholson', 'Yardville')");
Assert.fail("Expected ResponseException, but none was thrown");
} catch (ResponseException e) {
- assertThat(e.getResponse().getStatusLine().getStatusCode(),
+ assertThat(
+ e.getResponse().getStatusLine().getStatusCode(),
equalTo(RestStatus.BAD_REQUEST.getStatus()));
final String entity = TestUtils.getResponseBody(e.getResponse());
assertThat(entity, containsString("Field name [city] is ambiguous"));
assertThat(entity, containsString("\"type\": \"VerificationException\""));
}
-
}
@Test
public void testNestedSingleConditionAllFields() throws IOException {
- String result = explainQuery(
- "SELECT * " +
- "FROM opensearch-sql_test_index_employee_nested e, e.projects p " +
- "WHERE p.name = 'something' "
- );
- assertThat(result,
- containsString("\"term\":{\"projects.name.keyword\":{\"value\":\"something\""));
+ String result =
+ explainQuery(
+ "SELECT * "
+ + "FROM opensearch-sql_test_index_employee_nested e, e.projects p "
+ + "WHERE p.name = 'something' ");
+ assertThat(
+ result, containsString("\"term\":{\"projects.name.keyword\":{\"value\":\"something\""));
assertThat(result, containsString("\"path\":\"projects\""));
}
@Test
public void testNestedMultipleCondition() throws IOException {
- String result = explainQuery(
- "SELECT e.id, p.name " +
- "FROM opensearch-sql_test_index_employee_nested e, e.projects p " +
- "WHERE p.name = 'something' and p.started_year = 1990 "
- );
- assertThat(result,
- containsString("\"term\":{\"projects.name.keyword\":{\"value\":\"something\""));
+ String result =
+ explainQuery(
+ "SELECT e.id, p.name "
+ + "FROM opensearch-sql_test_index_employee_nested e, e.projects p "
+ + "WHERE p.name = 'something' and p.started_year = 1990 ");
+ assertThat(
+ result, containsString("\"term\":{\"projects.name.keyword\":{\"value\":\"something\""));
assertThat(result, containsString("\"term\":{\"projects.started_year\":{\"value\":1990"));
assertThat(result, containsString("\"path\":\"projects\""));
}
@Test
public void testConditionsOnDifferentNestedDocs() throws IOException {
- String result = explainQuery(
- "SELECT p.name, c.likes " +
- "FROM opensearch-sql_test_index_employee_nested e, e.projects p, e.comments c " +
- "WHERE p.name = 'something' or c.likes = 56 "
- );
- assertThat(result,
- containsString("\"term\":{\"projects.name.keyword\":{\"value\":\"something\""));
+ String result =
+ explainQuery(
+ "SELECT p.name, c.likes "
+ + "FROM opensearch-sql_test_index_employee_nested e, e.projects p, e.comments c "
+ + "WHERE p.name = 'something' or c.likes = 56 ");
+ assertThat(
+ result, containsString("\"term\":{\"projects.name.keyword\":{\"value\":\"something\""));
assertThat(result, containsString("\"term\":{\"comments.likes\":{\"value\":56"));
assertThat(result, containsString("\"path\":\"projects\""));
assertThat(result, containsString("\"path\":\"comments\""));
@@ -359,11 +359,11 @@ public void testConditionsOnDifferentNestedDocs() throws IOException {
@Test
public void testNestedSingleConditionSpecificFields() throws IOException {
- String result = explainQuery(
- "SELECT e.id, p.name " +
- "FROM opensearch-sql_test_index_employee_nested e, e.projects p " +
- "WHERE p.name = 'hello' or p.name = 'world' "
- );
+ String result =
+ explainQuery(
+ "SELECT e.id, p.name "
+ + "FROM opensearch-sql_test_index_employee_nested e, e.projects p "
+ + "WHERE p.name = 'hello' or p.name = 'world' ");
assertThat(result, containsString("\"term\":{\"projects.name.keyword\":{\"value\":\"hello\""));
assertThat(result, containsString("\"term\":{\"projects.name.keyword\":{\"value\":\"world\""));
assertThat(result, containsString("\"path\":\"projects\""));
@@ -371,32 +371,33 @@ public void testNestedSingleConditionSpecificFields() throws IOException {
@Test
public void testNestedSingleGroupBy() throws IOException {
- String result = explainQuery(
- "SELECT e.id, p.name " +
- "FROM opensearch-sql_test_index_employee_nested e, e.projects p " +
- "GROUP BY p.name ");
+ String result =
+ explainQuery(
+ "SELECT e.id, p.name "
+ + "FROM opensearch-sql_test_index_employee_nested e, e.projects p "
+ + "GROUP BY p.name ");
assertThat(result, containsString("\"terms\":{\"field\":\"projects.name.keyword\""));
assertThat(result, containsString("\"nested\":{\"path\":\"projects\""));
}
@Test
public void testNestedSingleOrderBy() throws IOException {
- String result = explainQuery(
- "SELECT e.id, p.name " +
- "FROM opensearch-sql_test_index_employee_nested e, e.projects p " +
- "ORDER BY p.name "
- );
+ String result =
+ explainQuery(
+ "SELECT e.id, p.name "
+ + "FROM opensearch-sql_test_index_employee_nested e, e.projects p "
+ + "ORDER BY p.name ");
assertThat(result, containsString("\"sort\":[{\"projects.name.keyword\""));
assertThat(result, containsString("\"nested\":{\"path\":\"projects\""));
}
@Test
public void testNestedIsNotNullExplain() throws IOException {
- String explain = explainQuery(
- "SELECT e.name " +
- "FROM opensearch-sql_test_index_employee_nested as e, e.projects as p " +
- "WHERE p IS NOT NULL"
- );
+ String explain =
+ explainQuery(
+ "SELECT e.name "
+ + "FROM opensearch-sql_test_index_employee_nested as e, e.projects as p "
+ + "WHERE p IS NOT NULL");
assertThat(explain, containsString("\"exists\":{\"field\":\"projects\""));
assertThat(explain, containsString("\"path\":\"projects\""));
@@ -407,14 +408,15 @@ public void testNestedIsNotNullExplain() throws IOException {
public void testMultiQuery() throws IOException {
String expectedOutput =
TestUtils.fileToString("src/test/resources/expectedOutput/term_union_where", true);
- String result = explainQuery(
- "SELECT firstname " +
- "FROM opensearch-sql_test_index_account/account " +
- "WHERE firstname = 'Amber' " +
- "UNION ALL " +
- "SELECT dog_name as firstname " +
- "FROM opensearch-sql_test_index_dog/dog " +
- "WHERE holdersName = 'Hattie' OR dog_name = 'rex'");
+ String result =
+ explainQuery(
+ "SELECT firstname "
+ + "FROM opensearch-sql_test_index_account/account "
+ + "WHERE firstname = 'Amber' "
+ + "UNION ALL "
+ + "SELECT dog_name as firstname "
+ + "FROM opensearch-sql_test_index_dog/dog "
+ + "WHERE holdersName = 'Hattie' OR dog_name = 'rex'");
assertThat(result.replaceAll("\\s+", ""), equalTo(expectedOutput.replaceAll("\\s+", "")));
}
}
diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/TestUtils.java b/integ-test/src/test/java/org/opensearch/sql/legacy/TestUtils.java
index 30cee86e15..1abc1d6183 100644
--- a/integ-test/src/test/java/org/opensearch/sql/legacy/TestUtils.java
+++ b/integ-test/src/test/java/org/opensearch/sql/legacy/TestUtils.java
@@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/
-
package org.opensearch.sql.legacy;
import static com.google.common.base.Strings.isNullOrEmpty;
@@ -36,14 +35,14 @@
public class TestUtils {
- private final static String MAPPING_FILE_PATH = "src/test/resources/indexDefinitions/";
+ private static final String MAPPING_FILE_PATH = "src/test/resources/indexDefinitions/";
/**
* Create test index by REST client.
*
- * @param client client connection
+ * @param client client connection
* @param indexName test index name
- * @param mapping test index mapping or null if no predefined mapping
+ * @param mapping test index mapping or null if no predefined mapping
*/
public static void createIndexByRestClient(RestClient client, String indexName, String mapping) {
Request request = new Request("PUT", "/" + indexName);
@@ -54,16 +53,16 @@ public static void createIndexByRestClient(RestClient client, String indexName,
}
/**
- * https://github.com/elastic/elasticsearch/pull/49959
- * Deprecate creation of dot-prefixed index names except for hidden and system indices.
- * Create hidden index by REST client.
+ * https://github.com/elastic/elasticsearch/pull/49959
+ * Deprecate creation of dot-prefixed index
+ * names except for hidden and system indices. Create hidden index by REST client.
*
- * @param client client connection
+ * @param client client connection
* @param indexName test index name
- * @param mapping test index mapping or null if no predefined mapping
+ * @param mapping test index mapping or null if no predefined mapping
*/
- public static void createHiddenIndexByRestClient(RestClient client, String indexName,
- String mapping) {
+ public static void createHiddenIndexByRestClient(
+ RestClient client, String indexName, String mapping) {
Request request = new Request("PUT", "/" + indexName);
JSONObject jsonObject = isNullOrEmpty(mapping) ? new JSONObject() : new JSONObject(mapping);
jsonObject.put("settings", new JSONObject("{\"index\":{\"hidden\":true}}"));
@@ -73,11 +72,10 @@ public static void createHiddenIndexByRestClient(RestClient client, String index
}
/**
- * Check if index already exists by OpenSearch index exists API which returns:
- * 200 - specified indices or aliases exist
- * 404 - one or more indices specified or aliases do not exist
+ * Check if index already exists by OpenSearch index exists API which returns: 200 - specified
+ * indices or aliases exist 404 - one or more indices specified or aliases do not exist
*
- * @param client client connection
+ * @param client client connection
* @param indexName index name
* @return true for index exist
*/
@@ -93,13 +91,13 @@ public static boolean isIndexExist(RestClient client, String indexName) {
/**
* Load test data set by REST client.
*
- * @param client client connection
- * @param indexName index name
+ * @param client client connection
+ * @param indexName index name
* @param dataSetFilePath file path of test data set
* @throws IOException
*/
- public static void loadDataByRestClient(RestClient client, String indexName,
- String dataSetFilePath) throws IOException {
+ public static void loadDataByRestClient(
+ RestClient client, String indexName, String dataSetFilePath) throws IOException {
Path path = Paths.get(getResourceFilePath(dataSetFilePath));
Request request = new Request("POST", "/" + indexName + "/_bulk?refresh=true");
request.setJsonEntity(new String(Files.readAllBytes(path)));
@@ -109,7 +107,7 @@ public static void loadDataByRestClient(RestClient client, String indexName,
/**
* Perform a request by REST client.
*
- * @param client client connection
+ * @param client client connection
* @param request request object
*/
public static Response performRequest(RestClient client, Request request) {
@@ -177,7 +175,6 @@ public static String getEmployeeNestedTypeIndexMapping() {
return getMappingFile(mappingFile);
}
-
public static String getNestedTypeIndexMapping() {
String mappingFile = "nested_type_index_mapping.json";
return getMappingFile(mappingFile);
@@ -255,8 +252,8 @@ public static void loadBulk(Client client, String jsonPath, String defaultIndex)
BulkRequest bulkRequest = new BulkRequest();
try (final InputStream stream = new FileInputStream(absJsonPath);
- final Reader streamReader = new InputStreamReader(stream, StandardCharsets.UTF_8);
- final BufferedReader br = new BufferedReader(streamReader)) {
+ final Reader streamReader = new InputStreamReader(stream, StandardCharsets.UTF_8);
+ final BufferedReader br = new BufferedReader(streamReader)) {
while (true) {
@@ -285,8 +282,11 @@ public static void loadBulk(Client client, String jsonPath, String defaultIndex)
BulkResponse bulkResponse = client.bulk(bulkRequest).actionGet();
if (bulkResponse.hasFailures()) {
- throw new Exception("Failed to load test data into index " + defaultIndex + ", " +
- bulkResponse.buildFailureMessage());
+ throw new Exception(
+ "Failed to load test data into index "
+ + defaultIndex
+ + ", "
+ + bulkResponse.buildFailureMessage());
}
System.out.println(bulkResponse.getItems().length + " documents loaded.");
// ensure the documents are searchable
@@ -312,8 +312,8 @@ public static String getResponseBody(Response response, boolean retainNewLines)
final StringBuilder sb = new StringBuilder();
try (final InputStream is = response.getEntity().getContent();
- final BufferedReader br = new BufferedReader(
- new InputStreamReader(is, StandardCharsets.UTF_8))) {
+ final BufferedReader br =
+ new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
String line;
while ((line = br.readLine()) != null) {
@@ -326,15 +326,14 @@ public static String getResponseBody(Response response, boolean retainNewLines)
return sb.toString();
}
- public static String fileToString(final String filePathFromProjectRoot,
- final boolean removeNewLines)
- throws IOException {
+ public static String fileToString(
+ final String filePathFromProjectRoot, final boolean removeNewLines) throws IOException {
final String absolutePath = getResourceFilePath(filePathFromProjectRoot);
try (final InputStream stream = new FileInputStream(absolutePath);
- final Reader streamReader = new InputStreamReader(stream, StandardCharsets.UTF_8);
- final BufferedReader br = new BufferedReader(streamReader)) {
+ final Reader streamReader = new InputStreamReader(stream, StandardCharsets.UTF_8);
+ final BufferedReader br = new BufferedReader(streamReader)) {
final StringBuilder stringBuilder = new StringBuilder();
String line = br.readLine();
@@ -388,12 +387,16 @@ public static List> getPermutations(final List items) {
}
final String currentItem = items.get(i);
- result.addAll(getPermutations(smallerSet).stream().map(smallerSetPermutation -> {
- final List permutation = new ArrayList<>();
- permutation.add(currentItem);
- permutation.addAll(smallerSetPermutation);
- return permutation;
- }).collect(Collectors.toCollection(LinkedList::new)));
+ result.addAll(
+ getPermutations(smallerSet).stream()
+ .map(
+ smallerSetPermutation -> {
+ final List permutation = new ArrayList<>();
+ permutation.add(currentItem);
+ permutation.addAll(smallerSetPermutation);
+ return permutation;
+ })
+ .collect(Collectors.toCollection(LinkedList::new)));
}
return result;
diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/TestsConstants.java b/integ-test/src/test/java/org/opensearch/sql/legacy/TestsConstants.java
index 338be25a0c..29bc9813fa 100644
--- a/integ-test/src/test/java/org/opensearch/sql/legacy/TestsConstants.java
+++ b/integ-test/src/test/java/org/opensearch/sql/legacy/TestsConstants.java
@@ -3,66 +3,63 @@
* SPDX-License-Identifier: Apache-2.0
*/
-
package org.opensearch.sql.legacy;
-/**
- * Created by omershelef on 18/12/14.
- */
+/** Created by omershelef on 18/12/14. */
public class TestsConstants {
- public final static String PERSISTENT = "persistent";
- public final static String TRANSIENT = "transient";
+ public static final String PERSISTENT = "persistent";
+ public static final String TRANSIENT = "transient";
- public final static String TEST_INDEX = "opensearch-sql_test_index";
+ public static final String TEST_INDEX = "opensearch-sql_test_index";
- public final static String TEST_INDEX_ONLINE = TEST_INDEX + "_online";
- public final static String TEST_INDEX_ACCOUNT = TEST_INDEX + "_account";
- public final static String TEST_INDEX_PHRASE = TEST_INDEX + "_phrase";
- public final static String TEST_INDEX_DOG = TEST_INDEX + "_dog";
- public final static String TEST_INDEX_DOG2 = TEST_INDEX + "_dog2";
- public final static String TEST_INDEX_DOG3 = TEST_INDEX + "_dog3";
- public final static String TEST_INDEX_DOGSUBQUERY = TEST_INDEX + "_subquery";
- public final static String TEST_INDEX_PEOPLE = TEST_INDEX + "_people";
- public final static String TEST_INDEX_PEOPLE2 = TEST_INDEX + "_people2";
- public final static String TEST_INDEX_GAME_OF_THRONES = TEST_INDEX + "_game_of_thrones";
- public final static String TEST_INDEX_SYSTEM = TEST_INDEX + "_system";
- public final static String TEST_INDEX_ODBC = TEST_INDEX + "_odbc";
- public final static String TEST_INDEX_LOCATION = TEST_INDEX + "_location";
- public final static String TEST_INDEX_LOCATION2 = TEST_INDEX + "_location2";
- public final static String TEST_INDEX_NESTED_TYPE = TEST_INDEX + "_nested_type";
- public final static String TEST_INDEX_NESTED_TYPE_WITHOUT_ARRAYS =
+ public static final String TEST_INDEX_ONLINE = TEST_INDEX + "_online";
+ public static final String TEST_INDEX_ACCOUNT = TEST_INDEX + "_account";
+ public static final String TEST_INDEX_PHRASE = TEST_INDEX + "_phrase";
+ public static final String TEST_INDEX_DOG = TEST_INDEX + "_dog";
+ public static final String TEST_INDEX_DOG2 = TEST_INDEX + "_dog2";
+ public static final String TEST_INDEX_DOG3 = TEST_INDEX + "_dog3";
+ public static final String TEST_INDEX_DOGSUBQUERY = TEST_INDEX + "_subquery";
+ public static final String TEST_INDEX_PEOPLE = TEST_INDEX + "_people";
+ public static final String TEST_INDEX_PEOPLE2 = TEST_INDEX + "_people2";
+ public static final String TEST_INDEX_GAME_OF_THRONES = TEST_INDEX + "_game_of_thrones";
+ public static final String TEST_INDEX_SYSTEM = TEST_INDEX + "_system";
+ public static final String TEST_INDEX_ODBC = TEST_INDEX + "_odbc";
+ public static final String TEST_INDEX_LOCATION = TEST_INDEX + "_location";
+ public static final String TEST_INDEX_LOCATION2 = TEST_INDEX + "_location2";
+ public static final String TEST_INDEX_NESTED_TYPE = TEST_INDEX + "_nested_type";
+ public static final String TEST_INDEX_NESTED_TYPE_WITHOUT_ARRAYS =
TEST_INDEX + "_nested_type_without_arrays";
- public final static String TEST_INDEX_NESTED_SIMPLE = TEST_INDEX + "_nested_simple";
- public final static String TEST_INDEX_NESTED_WITH_QUOTES =
+ public static final String TEST_INDEX_NESTED_SIMPLE = TEST_INDEX + "_nested_simple";
+ public static final String TEST_INDEX_NESTED_WITH_QUOTES =
TEST_INDEX + "_nested_type_with_quotes";
- public final static String TEST_INDEX_EMPLOYEE_NESTED = TEST_INDEX + "_employee_nested";
- public final static String TEST_INDEX_JOIN_TYPE = TEST_INDEX + "_join_type";
- public final static String TEST_INDEX_UNEXPANDED_OBJECT = TEST_INDEX + "_unexpanded_object";
- public final static String TEST_INDEX_BANK = TEST_INDEX + "_bank";
- public final static String TEST_INDEX_BANK_TWO = TEST_INDEX_BANK + "_two";
- public final static String TEST_INDEX_BANK_WITH_NULL_VALUES =
+ public static final String TEST_INDEX_EMPLOYEE_NESTED = TEST_INDEX + "_employee_nested";
+ public static final String TEST_INDEX_JOIN_TYPE = TEST_INDEX + "_join_type";
+ public static final String TEST_INDEX_UNEXPANDED_OBJECT = TEST_INDEX + "_unexpanded_object";
+ public static final String TEST_INDEX_BANK = TEST_INDEX + "_bank";
+ public static final String TEST_INDEX_BANK_TWO = TEST_INDEX_BANK + "_two";
+ public static final String TEST_INDEX_BANK_WITH_NULL_VALUES =
TEST_INDEX_BANK + "_with_null_values";
- public final static String TEST_INDEX_BANK_CSV_SANITIZE = TEST_INDEX_BANK + "_csv_sanitize";
- public final static String TEST_INDEX_BANK_RAW_SANITIZE = TEST_INDEX_BANK + "_raw_sanitize";
- public final static String TEST_INDEX_ORDER = TEST_INDEX + "_order";
- public final static String TEST_INDEX_WEBLOG = TEST_INDEX + "_weblog";
- public final static String TEST_INDEX_DATE = TEST_INDEX + "_date";
- public final static String TEST_INDEX_DATE_TIME = TEST_INDEX + "_datetime";
- public final static String TEST_INDEX_DEEP_NESTED = TEST_INDEX + "_deep_nested";
- public final static String TEST_INDEX_STRINGS = TEST_INDEX + "_strings";
- public final static String TEST_INDEX_DATATYPE_NUMERIC = TEST_INDEX + "_datatypes_numeric";
- public final static String TEST_INDEX_DATATYPE_NONNUMERIC = TEST_INDEX + "_datatypes_nonnumeric";
- public final static String TEST_INDEX_BEER = TEST_INDEX + "_beer";
- public final static String TEST_INDEX_NULL_MISSING = TEST_INDEX + "_null_missing";
- public final static String TEST_INDEX_CALCS = TEST_INDEX + "_calcs";
- public final static String TEST_INDEX_DATE_FORMATS = TEST_INDEX + "_date_formats";
- public final static String TEST_INDEX_WILDCARD = TEST_INDEX + "_wildcard";
- public final static String TEST_INDEX_MULTI_NESTED_TYPE = TEST_INDEX + "_multi_nested";
- public final static String TEST_INDEX_NESTED_WITH_NULLS = TEST_INDEX + "_nested_with_nulls";
- public final static String DATASOURCES = ".ql-datasources";
+ public static final String TEST_INDEX_BANK_CSV_SANITIZE = TEST_INDEX_BANK + "_csv_sanitize";
+ public static final String TEST_INDEX_BANK_RAW_SANITIZE = TEST_INDEX_BANK + "_raw_sanitize";
+ public static final String TEST_INDEX_ORDER = TEST_INDEX + "_order";
+ public static final String TEST_INDEX_WEBLOG = TEST_INDEX + "_weblog";
+ public static final String TEST_INDEX_DATE = TEST_INDEX + "_date";
+ public static final String TEST_INDEX_DATE_TIME = TEST_INDEX + "_datetime";
+ public static final String TEST_INDEX_DEEP_NESTED = TEST_INDEX + "_deep_nested";
+ public static final String TEST_INDEX_STRINGS = TEST_INDEX + "_strings";
+ public static final String TEST_INDEX_DATATYPE_NUMERIC = TEST_INDEX + "_datatypes_numeric";
+ public static final String TEST_INDEX_DATATYPE_NONNUMERIC = TEST_INDEX + "_datatypes_nonnumeric";
+ public static final String TEST_INDEX_BEER = TEST_INDEX + "_beer";
+ public static final String TEST_INDEX_NULL_MISSING = TEST_INDEX + "_null_missing";
+ public static final String TEST_INDEX_CALCS = TEST_INDEX + "_calcs";
+ public static final String TEST_INDEX_DATE_FORMATS = TEST_INDEX + "_date_formats";
+ public static final String TEST_INDEX_WILDCARD = TEST_INDEX + "_wildcard";
+ public static final String TEST_INDEX_MULTI_NESTED_TYPE = TEST_INDEX + "_multi_nested";
+ public static final String TEST_INDEX_NESTED_WITH_NULLS = TEST_INDEX + "_nested_with_nulls";
+ public static final String DATASOURCES = ".ql-datasources";
- public final static String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
- public final static String TS_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS";
- public final static String SIMPLE_DATE_FORMAT = "yyyy-MM-dd";
+ public static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
+ public static final String TS_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS";
+ public static final String SIMPLE_DATE_FORMAT = "yyyy-MM-dd";
}
diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/TypeInformationIT.java b/integ-test/src/test/java/org/opensearch/sql/legacy/TypeInformationIT.java
index 646a38b011..421aae9622 100644
--- a/integ-test/src/test/java/org/opensearch/sql/legacy/TypeInformationIT.java
+++ b/integ-test/src/test/java/org/opensearch/sql/legacy/TypeInformationIT.java
@@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/
-
package org.opensearch.sql.legacy;
import static org.opensearch.sql.util.MatcherUtils.schema;
@@ -26,8 +25,8 @@ protected void init() throws Exception {
@Test
public void testAbsWithIntFieldReturnsInt() {
JSONObject response =
- executeJdbcRequest("SELECT ABS(age) FROM " + TestsConstants.TEST_INDEX_ACCOUNT +
- " ORDER BY age LIMIT 5");
+ executeJdbcRequest(
+ "SELECT ABS(age) FROM " + TestsConstants.TEST_INDEX_ACCOUNT + " ORDER BY age LIMIT 5");
verifySchema(response, schema("ABS(age)", null, "long"));
}
@@ -35,8 +34,10 @@ public void testAbsWithIntFieldReturnsInt() {
@Test
public void testCeilWithLongFieldReturnsLong() {
JSONObject response =
- executeJdbcRequest("SELECT CEIL(balance) FROM " + TestsConstants.TEST_INDEX_ACCOUNT +
- " ORDER BY balance LIMIT 5");
+ executeJdbcRequest(
+ "SELECT CEIL(balance) FROM "
+ + TestsConstants.TEST_INDEX_ACCOUNT
+ + " ORDER BY balance LIMIT 5");
verifySchema(response, schema("CEIL(balance)", null, "long"));
}
@@ -46,8 +47,8 @@ public void testCeilWithLongFieldReturnsLong() {
*/
@Test
public void testPiReturnsDouble() {
- JSONObject response = executeJdbcRequest("SELECT PI() FROM " + TestsConstants.TEST_INDEX_ACCOUNT
- + " LIMIT 1");
+ JSONObject response =
+ executeJdbcRequest("SELECT PI() FROM " + TestsConstants.TEST_INDEX_ACCOUNT + " LIMIT 1");
verifySchema(response, schema("PI()", null, "double"));
}
@@ -57,16 +58,22 @@ public void testPiReturnsDouble() {
*/
@Test
public void testUpperWithStringFieldReturnsString() {
- JSONObject response = executeJdbcRequest("SELECT UPPER(firstname) AS firstname_alias FROM " +
- TestsConstants.TEST_INDEX_ACCOUNT + " ORDER BY firstname_alias LIMIT 2");
+ JSONObject response =
+ executeJdbcRequest(
+ "SELECT UPPER(firstname) AS firstname_alias FROM "
+ + TestsConstants.TEST_INDEX_ACCOUNT
+ + " ORDER BY firstname_alias LIMIT 2");
verifySchema(response, schema("UPPER(firstname)", "firstname_alias", "keyword"));
}
@Test
public void testLowerWithTextFieldReturnsText() {
- JSONObject response = executeJdbcRequest("SELECT LOWER(firstname) FROM " +
- TestsConstants.TEST_INDEX_ACCOUNT + " ORDER BY firstname LIMIT 2");
+ JSONObject response =
+ executeJdbcRequest(
+ "SELECT LOWER(firstname) FROM "
+ + TestsConstants.TEST_INDEX_ACCOUNT
+ + " ORDER BY firstname LIMIT 2");
verifySchema(response, schema("LOWER(firstname)", null, "keyword"));
}
@@ -76,8 +83,11 @@ public void testLowerWithTextFieldReturnsText() {
*/
@Test
public void testLengthWithTextFieldReturnsInt() {
- JSONObject response = executeJdbcRequest("SELECT length(firstname) FROM " +
- TestsConstants.TEST_INDEX_ACCOUNT + " ORDER BY firstname LIMIT 2");
+ JSONObject response =
+ executeJdbcRequest(
+ "SELECT length(firstname) FROM "
+ + TestsConstants.TEST_INDEX_ACCOUNT
+ + " ORDER BY firstname LIMIT 2");
verifySchema(response, schema("length(firstname)", null, "integer"));
}
@@ -85,8 +95,10 @@ public void testLengthWithTextFieldReturnsInt() {
@Test
public void testLengthWithGroupByExpr() {
JSONObject response =
- executeJdbcRequest("SELECT Length(firstname) FROM " + TestsConstants.TEST_INDEX_ACCOUNT +
- " GROUP BY LENGTH(firstname) LIMIT 5");
+ executeJdbcRequest(
+ "SELECT Length(firstname) FROM "
+ + TestsConstants.TEST_INDEX_ACCOUNT
+ + " GROUP BY LENGTH(firstname) LIMIT 5");
verifySchema(response, schema("Length(firstname)", null, "integer"));
}
@@ -96,16 +108,22 @@ public void testLengthWithGroupByExpr() {
*/
@Test
public void testSinWithLongFieldReturnsDouble() {
- JSONObject response = executeJdbcRequest("SELECT sin(balance) FROM " +
- TestsConstants.TEST_INDEX_ACCOUNT + " ORDER BY firstname LIMIT 2");
+ JSONObject response =
+ executeJdbcRequest(
+ "SELECT sin(balance) FROM "
+ + TestsConstants.TEST_INDEX_ACCOUNT
+ + " ORDER BY firstname LIMIT 2");
verifySchema(response, schema("sin(balance)", null, "double"));
}
@Test
public void testRadiansWithLongFieldReturnsDouble() {
- JSONObject response = executeJdbcRequest("SELECT radians(balance) FROM " +
- TestsConstants.TEST_INDEX_ACCOUNT + " ORDER BY firstname LIMIT 2");
+ JSONObject response =
+ executeJdbcRequest(
+ "SELECT radians(balance) FROM "
+ + TestsConstants.TEST_INDEX_ACCOUNT
+ + " ORDER BY firstname LIMIT 2");
verifySchema(response, schema("radians(balance)", null, "double"));
}
@@ -115,16 +133,22 @@ public void testRadiansWithLongFieldReturnsDouble() {
*/
@Test
public void testAddWithIntReturnsInt() {
- JSONObject response = executeJdbcRequest("SELECT (balance + 5) AS balance_add_five FROM " +
- TestsConstants.TEST_INDEX_ACCOUNT + " ORDER BY firstname LIMIT 2");
+ JSONObject response =
+ executeJdbcRequest(
+ "SELECT (balance + 5) AS balance_add_five FROM "
+ + TestsConstants.TEST_INDEX_ACCOUNT
+ + " ORDER BY firstname LIMIT 2");
verifySchema(response, schema("(balance + 5)", "balance_add_five", "long"));
}
@Test
public void testSubtractLongWithLongReturnsLong() {
- JSONObject response = executeJdbcRequest("SELECT (balance - balance) FROM " +
- TestsConstants.TEST_INDEX_ACCOUNT + " ORDER BY firstname LIMIT 2");
+ JSONObject response =
+ executeJdbcRequest(
+ "SELECT (balance - balance) FROM "
+ + TestsConstants.TEST_INDEX_ACCOUNT
+ + " ORDER BY firstname LIMIT 2");
verifySchema(response, schema("(balance - balance)", null, "long"));
}
@@ -134,17 +158,18 @@ public void testSubtractLongWithLongReturnsLong() {
*/
@Test
public void testDayOfWeekWithKeywordReturnsText() {
- JSONObject response = executeJdbcRequest("SELECT DAYOFWEEK(insert_time) FROM "
- + TestsConstants.TEST_INDEX_ONLINE + " LIMIT 2");
+ JSONObject response =
+ executeJdbcRequest(
+ "SELECT DAYOFWEEK(insert_time) FROM " + TestsConstants.TEST_INDEX_ONLINE + " LIMIT 2");
- verifySchema(response,
- schema("DAYOFWEEK(insert_time)", null, "integer"));
+ verifySchema(response, schema("DAYOFWEEK(insert_time)", null, "integer"));
}
@Test
public void testYearWithKeywordReturnsText() {
- JSONObject response = executeJdbcRequest("SELECT YEAR(insert_time) FROM "
- + TestsConstants.TEST_INDEX_ONLINE + " LIMIT 2");
+ JSONObject response =
+ executeJdbcRequest(
+ "SELECT YEAR(insert_time) FROM " + TestsConstants.TEST_INDEX_ONLINE + " LIMIT 2");
verifySchema(response, schema("YEAR(insert_time)", null, "integer"));
}
diff --git a/integ-test/src/test/java/org/opensearch/sql/ppl/StandaloneIT.java b/integ-test/src/test/java/org/opensearch/sql/ppl/StandaloneIT.java
index 8ef8787597..f81e1b6615 100644
--- a/integ-test/src/test/java/org/opensearch/sql/ppl/StandaloneIT.java
+++ b/integ-test/src/test/java/org/opensearch/sql/ppl/StandaloneIT.java
@@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/
-
package org.opensearch.sql.ppl;
import static org.opensearch.sql.datasource.model.DataSourceMetadata.defaultOpenSearchDataSourceMetadata;
@@ -78,17 +77,21 @@ public class StandaloneIT extends PPLIntegTestCase {
public void init() {
RestHighLevelClient restClient = new InternalRestHighLevelClient(client());
OpenSearchClient client = new OpenSearchRestClient(restClient);
- DataSourceService dataSourceService = new DataSourceServiceImpl(
- new ImmutableSet.Builder()
- .add(new OpenSearchDataSourceFactory(client, defaultSettings()))
- .build(), getDataSourceMetadataStorage(), getDataSourceUserRoleHelper());
+ DataSourceService dataSourceService =
+ new DataSourceServiceImpl(
+ new ImmutableSet.Builder()
+ .add(new OpenSearchDataSourceFactory(client, defaultSettings()))
+ .build(),
+ getDataSourceMetadataStorage(),
+ getDataSourceUserRoleHelper());
dataSourceService.createDataSource(defaultOpenSearchDataSourceMetadata());
ModulesBuilder modules = new ModulesBuilder();
- modules.add(new StandaloneModule(new InternalRestHighLevelClient(client()), defaultSettings(), dataSourceService));
+ modules.add(
+ new StandaloneModule(
+ new InternalRestHighLevelClient(client()), defaultSettings(), dataSourceService));
Injector injector = modules.createInjector();
- pplService =
- SecurityAccess.doPrivileged(() -> injector.getInstance(PPLService.class));
+ pplService = SecurityAccess.doPrivileged(() -> injector.getInstance(PPLService.class));
}
@Test
@@ -146,9 +149,8 @@ public void onFailure(Exception e) {
private Settings defaultSettings() {
return new Settings() {
- private final Map defaultSettings = new ImmutableMap.Builder()
- .put(Key.QUERY_SIZE_LIMIT, 200)
- .build();
+ private final Map defaultSettings =
+ new ImmutableMap.Builder().put(Key.QUERY_SIZE_LIMIT, 200).build();
@Override
public T getSettingValue(Key key) {
@@ -162,9 +164,7 @@ public List> getSettings() {
};
}
- /**
- * Internal RestHighLevelClient only for testing purpose.
- */
+ /** Internal RestHighLevelClient only for testing purpose. */
static class InternalRestHighLevelClient extends RestHighLevelClient {
public InternalRestHighLevelClient(RestClient restClient) {
super(restClient, RestClient::close, Collections.emptyList());
@@ -197,8 +197,8 @@ public StorageEngine storageEngine(OpenSearchClient client) {
}
@Provides
- public ExecutionEngine executionEngine(OpenSearchClient client, ExecutionProtector protector,
- PlanSerializer planSerializer) {
+ public ExecutionEngine executionEngine(
+ OpenSearchClient client, ExecutionProtector protector, PlanSerializer planSerializer) {
return new OpenSearchExecutionEngine(client, protector, planSerializer);
}
@@ -257,28 +257,20 @@ public Optional getDataSourceMetadata(String datasourceName)
}
@Override
- public void createDataSourceMetadata(DataSourceMetadata dataSourceMetadata) {
-
- }
+ public void createDataSourceMetadata(DataSourceMetadata dataSourceMetadata) {}
@Override
- public void updateDataSourceMetadata(DataSourceMetadata dataSourceMetadata) {
-
- }
+ public void updateDataSourceMetadata(DataSourceMetadata dataSourceMetadata) {}
@Override
- public void deleteDataSourceMetadata(String datasourceName) {
-
- }
+ public void deleteDataSourceMetadata(String datasourceName) {}
};
}
public static DataSourceUserAuthorizationHelper getDataSourceUserRoleHelper() {
return new DataSourceUserAuthorizationHelper() {
@Override
- public void authorizeDataSource(DataSourceMetadata dataSourceMetadata) {
-
- }
+ public void authorizeDataSource(DataSourceMetadata dataSourceMetadata) {}
};
}
}
diff --git a/integ-test/src/test/java/org/opensearch/sql/ppl/StatsCommandIT.java b/integ-test/src/test/java/org/opensearch/sql/ppl/StatsCommandIT.java
index 5389f245a4..92b9e309b8 100644
--- a/integ-test/src/test/java/org/opensearch/sql/ppl/StatsCommandIT.java
+++ b/integ-test/src/test/java/org/opensearch/sql/ppl/StatsCommandIT.java
@@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/
-
package org.opensearch.sql.ppl;
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_ACCOUNT;
@@ -66,26 +65,23 @@ public void testStatsDistinctCount() throws IOException {
verifySchema(response, schema("distinct_count(gender)", null, "integer"));
verifyDataRows(response, rows(2));
- response =
- executeQuery(String.format("source=%s | stats dc(age)", TEST_INDEX_ACCOUNT));
+ response = executeQuery(String.format("source=%s | stats dc(age)", TEST_INDEX_ACCOUNT));
verifySchema(response, schema("dc(age)", null, "integer"));
verifyDataRows(response, rows(21));
}
@Test
public void testStatsMin() throws IOException {
- JSONObject response = executeQuery(String.format(
- "source=%s | stats min(age)",
- TEST_INDEX_ACCOUNT));
+ JSONObject response =
+ executeQuery(String.format("source=%s | stats min(age)", TEST_INDEX_ACCOUNT));
verifySchema(response, schema("min(age)", null, "long"));
verifyDataRows(response, rows(20));
}
@Test
public void testStatsMax() throws IOException {
- JSONObject response = executeQuery(String.format(
- "source=%s | stats max(age)",
- TEST_INDEX_ACCOUNT));
+ JSONObject response =
+ executeQuery(String.format("source=%s | stats max(age)", TEST_INDEX_ACCOUNT));
verifySchema(response, schema("max(age)", null, "long"));
verifyDataRows(response, rows(40));
}
@@ -93,8 +89,8 @@ public void testStatsMax() throws IOException {
@Test
public void testStatsNested() throws IOException {
JSONObject response =
- executeQuery(String.format("source=%s | stats avg(abs(age) * 2) as AGE",
- TEST_INDEX_ACCOUNT));
+ executeQuery(
+ String.format("source=%s | stats avg(abs(age) * 2) as AGE", TEST_INDEX_ACCOUNT));
verifySchema(response, schema("AGE", null, "double"));
verifyDataRows(response, rows(60.342));
}
@@ -102,8 +98,7 @@ public void testStatsNested() throws IOException {
@Test
public void testStatsNestedDoubleValue() throws IOException {
JSONObject response =
- executeQuery(String.format("source=%s | stats avg(abs(age) * 2.0)",
- TEST_INDEX_ACCOUNT));
+ executeQuery(String.format("source=%s | stats avg(abs(age) * 2.0)", TEST_INDEX_ACCOUNT));
verifySchema(response, schema("avg(abs(age) * 2.0)", null, "double"));
verifyDataRows(response, rows(60.342));
}
@@ -111,88 +106,87 @@ public void testStatsNestedDoubleValue() throws IOException {
@Test
public void testStatsWhere() throws IOException {
JSONObject response =
- executeQuery(String.format(
- "source=%s | stats sum(balance) as a by state | where a > 780000",
- TEST_INDEX_ACCOUNT));
- verifySchema(response, schema("a", null, "long"),
- schema("state", null, "string"));
+ executeQuery(
+ String.format(
+ "source=%s | stats sum(balance) as a by state | where a > 780000",
+ TEST_INDEX_ACCOUNT));
+ verifySchema(response, schema("a", null, "long"), schema("state", null, "string"));
verifyDataRows(response, rows(782199, "TX"));
}
@Test
public void testGroupByNullValue() throws IOException {
JSONObject response =
- executeQuery(String.format(
- "source=%s | stats avg(balance) as a by age",
- TEST_INDEX_BANK_WITH_NULL_VALUES));
- verifySchema(response, schema("a", null, "double"),
- schema("age", null, "integer"));
- verifyDataRows(response,
+ executeQuery(
+ String.format(
+ "source=%s | stats avg(balance) as a by age", TEST_INDEX_BANK_WITH_NULL_VALUES));
+ verifySchema(response, schema("a", null, "double"), schema("age", null, "integer"));
+ verifyDataRows(
+ response,
rows(null, null),
rows(32838D, 28),
rows(39225D, 32),
rows(4180D, 33),
rows(48086D, 34),
- rows(null, 36)
- );
+ rows(null, 36));
}
- //Todo. The column of agg function is in random order. This is because we create the project
+ // Todo. The column of agg function is in random order. This is because we create the project
// all operator from the symbol table which can't maintain the original column order.
@Test
public void testMultipleAggregationFunction() throws IOException {
- JSONObject response = executeQuery(String.format(
- "source=%s | stats min(age), max(age)",
- TEST_INDEX_ACCOUNT));
- verifySchema(response, schema("min(age)", null, "long"),
- schema("max(age)", null, "long"));
+ JSONObject response =
+ executeQuery(String.format("source=%s | stats min(age), max(age)", TEST_INDEX_ACCOUNT));
+ verifySchema(response, schema("min(age)", null, "long"), schema("max(age)", null, "long"));
verifyDataRows(response, rows(20, 40));
}
@Test
public void testStatsWithNull() throws IOException {
JSONObject response =
- executeQuery(String.format(
- "source=%s | stats avg(age)",
- TEST_INDEX_BANK_WITH_NULL_VALUES));
+ executeQuery(String.format("source=%s | stats avg(age)", TEST_INDEX_BANK_WITH_NULL_VALUES));
verifySchema(response, schema("avg(age)", null, "double"));
verifyDataRows(response, rows(33.166666666666664));
}
@Test
public void testStatsWithMissing() throws IOException {
- JSONObject response = executeQuery(String.format(
- "source=%s | stats avg(balance)",
- TEST_INDEX_BANK_WITH_NULL_VALUES));
+ JSONObject response =
+ executeQuery(
+ String.format("source=%s | stats avg(balance)", TEST_INDEX_BANK_WITH_NULL_VALUES));
verifySchema(response, schema("avg(balance)", null, "double"));
verifyDataRows(response, rows(31082.25));
}
@Test
public void testStatsBySpan() throws IOException {
- JSONObject response = executeQuery(String.format(
- "source=%s | stats count() by span(age,10)",
- TEST_INDEX_BANK));
- verifySchema(response, schema("count()", null, "integer"), schema("span(age,10)", null, "integer"));
+ JSONObject response =
+ executeQuery(String.format("source=%s | stats count() by span(age,10)", TEST_INDEX_BANK));
+ verifySchema(
+ response, schema("count()", null, "integer"), schema("span(age,10)", null, "integer"));
verifyDataRows(response, rows(1, 20), rows(6, 30));
}
@Test
public void testStatsTimeSpan() throws IOException {
- JSONObject response = executeQuery(String.format(
- "source=%s | stats count() by span(birthdate,1y)",
- TEST_INDEX_BANK));
- verifySchema(response, schema("count()", null, "integer"), schema(
- "span(birthdate,1y)", null, "timestamp"));
+ JSONObject response =
+ executeQuery(
+ String.format("source=%s | stats count() by span(birthdate,1y)", TEST_INDEX_BANK));
+ verifySchema(
+ response,
+ schema("count()", null, "integer"),
+ schema("span(birthdate,1y)", null, "timestamp"));
verifyDataRows(response, rows(2, "2017-01-01 00:00:00"), rows(5, "2018-01-01 00:00:00"));
}
@Test
public void testStatsAliasedSpan() throws IOException {
- JSONObject response = executeQuery(String.format(
- "source=%s | stats count() by span(age,10) as age_bucket",
- TEST_INDEX_BANK));
- verifySchema(response, schema("count()", null, "integer"), schema("age_bucket", null, "integer"));
+ JSONObject response =
+ executeQuery(
+ String.format(
+ "source=%s | stats count() by span(age,10) as age_bucket", TEST_INDEX_BANK));
+ verifySchema(
+ response, schema("count()", null, "integer"), schema("age_bucket", null, "integer"));
verifyDataRows(response, rows(1, 20), rows(6, 30));
}
}
diff --git a/integ-test/src/test/java/org/opensearch/sql/ppl/SystemFunctionIT.java b/integ-test/src/test/java/org/opensearch/sql/ppl/SystemFunctionIT.java
index de13aa5488..d2cd140e99 100644
--- a/integ-test/src/test/java/org/opensearch/sql/ppl/SystemFunctionIT.java
+++ b/integ-test/src/test/java/org/opensearch/sql/ppl/SystemFunctionIT.java
@@ -26,49 +26,63 @@ public void init() throws IOException {
@Test
public void typeof_sql_types() throws IOException {
- JSONObject response = executeQuery(String.format("source=%s | eval "
- + "`str` = typeof('pewpew'), `double` = typeof(1.0),"
- + "`int` = typeof(12345), `long` = typeof(1234567891011), `interval` = typeof(INTERVAL 2 DAY)"
- + " | fields `str`, `double`, `int`, `long`, `interval`",
- TEST_INDEX_DATATYPE_NUMERIC));
+ JSONObject response =
+ executeQuery(
+ String.format(
+ "source=%s | eval `str` = typeof('pewpew'),"
+ + " `double` = typeof(1.0),"
+ + "`int` = typeof(12345),"
+ + " `long` = typeof(1234567891011),"
+ + " `interval` = typeof(INTERVAL 2 DAY)"
+ + " | fields `str`, `double`, `int`, `long`, `interval`",
+ TEST_INDEX_DATATYPE_NUMERIC));
// TODO: test null in PPL
- verifyDataRows(response,
- rows("KEYWORD", "DOUBLE", "INTEGER", "LONG", "INTERVAL"));
+ verifyDataRows(response, rows("KEYWORD", "DOUBLE", "INTEGER", "LONG", "INTERVAL"));
- response = executeQuery(String.format("source=%s | eval "
- + "`timestamp` = typeof(CAST('1961-04-12 09:07:00' AS TIMESTAMP)),"
- + "`time` = typeof(CAST('09:07:00' AS TIME)),"
- + "`date` = typeof(CAST('1961-04-12' AS DATE)),"
- + "`datetime` = typeof(DATETIME('1961-04-12 09:07:00'))"
- + " | fields `timestamp`, `time`, `date`, `datetime`",
- TEST_INDEX_DATATYPE_NUMERIC));
- verifyDataRows(response,
- rows("TIMESTAMP", "TIME", "DATE", "DATETIME"));
+ response =
+ executeQuery(
+ String.format(
+ "source=%s | eval "
+ + "`timestamp` = typeof(CAST('1961-04-12 09:07:00' AS TIMESTAMP)),"
+ + "`time` = typeof(CAST('09:07:00' AS TIME)),"
+ + "`date` = typeof(CAST('1961-04-12' AS DATE)),"
+ + "`datetime` = typeof(DATETIME('1961-04-12 09:07:00'))"
+ + " | fields `timestamp`, `time`, `date`, `datetime`",
+ TEST_INDEX_DATATYPE_NUMERIC));
+ verifyDataRows(response, rows("TIMESTAMP", "TIME", "DATE", "DATETIME"));
}
@Test
public void typeof_opensearch_types() throws IOException {
- JSONObject response = executeQuery(String.format("source=%s | eval "
- + "`double` = typeof(double_number), `long` = typeof(long_number),"
- + "`integer` = typeof(integer_number), `byte` = typeof(byte_number),"
- + "`short` = typeof(short_number), `float` = typeof(float_number),"
- + "`half_float` = typeof(half_float_number), `scaled_float` = typeof(scaled_float_number)"
- + " | fields `double`, `long`, `integer`, `byte`, `short`, `float`, `half_float`, `scaled_float`",
- TEST_INDEX_DATATYPE_NUMERIC));
- verifyDataRows(response,
- rows("DOUBLE", "LONG", "INTEGER", "BYTE", "SHORT", "FLOAT", "FLOAT", "DOUBLE"));
+ JSONObject response =
+ executeQuery(
+ String.format(
+ "source=%s | eval `double` = typeof(double_number), `long` ="
+ + " typeof(long_number),`integer` = typeof(integer_number), `byte` ="
+ + " typeof(byte_number),`short` = typeof(short_number), `float` ="
+ + " typeof(float_number),`half_float` = typeof(half_float_number),"
+ + " `scaled_float` = typeof(scaled_float_number) | fields `double`, `long`,"
+ + " `integer`, `byte`, `short`, `float`, `half_float`, `scaled_float`",
+ TEST_INDEX_DATATYPE_NUMERIC));
+ verifyDataRows(
+ response, rows("DOUBLE", "LONG", "INTEGER", "BYTE", "SHORT", "FLOAT", "FLOAT", "DOUBLE"));
- response = executeQuery(String.format("source=%s | eval "
- + "`text` = typeof(text_value), `date` = typeof(date_value),"
- + "`boolean` = typeof(boolean_value), `object` = typeof(object_value),"
- + "`keyword` = typeof(keyword_value), `ip` = typeof(ip_value),"
- + "`binary` = typeof(binary_value), `geo_point` = typeof(geo_point_value)"
- // TODO activate this test once `ARRAY` type supported, see ExpressionAnalyzer::isTypeNotSupported
- //+ ", `nested` = typeof(nested_value)"
- + " | fields `text`, `date`, `boolean`, `object`, `keyword`, `ip`, `binary`, `geo_point`",
- TEST_INDEX_DATATYPE_NONNUMERIC));
- verifyDataRows(response,
- rows("TEXT", "TIMESTAMP", "BOOLEAN", "OBJECT", "KEYWORD",
- "IP", "BINARY", "GEO_POINT"));
+ response =
+ executeQuery(
+ String.format(
+ "source=%s | eval "
+ + "`text` = typeof(text_value), `date` = typeof(date_value),"
+ + "`boolean` = typeof(boolean_value), `object` = typeof(object_value),"
+ + "`keyword` = typeof(keyword_value), `ip` = typeof(ip_value),"
+ + "`binary` = typeof(binary_value), `geo_point` = typeof(geo_point_value)"
+ // TODO activate this test once `ARRAY` type supported, see
+ // ExpressionAnalyzer::isTypeNotSupported
+ // + ", `nested` = typeof(nested_value)"
+ + " | fields `text`, `date`, `boolean`, `object`, `keyword`, `ip`, `binary`,"
+ + " `geo_point`",
+ TEST_INDEX_DATATYPE_NONNUMERIC));
+ verifyDataRows(
+ response,
+ rows("TEXT", "TIMESTAMP", "BOOLEAN", "OBJECT", "KEYWORD", "IP", "BINARY", "GEO_POINT"));
}
}
diff --git a/integ-test/src/test/java/org/opensearch/sql/ppl/TextFunctionIT.java b/integ-test/src/test/java/org/opensearch/sql/ppl/TextFunctionIT.java
index 024f190bee..dc9f1d98d2 100644
--- a/integ-test/src/test/java/org/opensearch/sql/ppl/TextFunctionIT.java
+++ b/integ-test/src/test/java/org/opensearch/sql/ppl/TextFunctionIT.java
@@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/
-
package org.opensearch.sql.ppl;
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_STRINGS;
@@ -23,27 +22,45 @@ public void init() throws IOException {
loadIndex(Index.BANK_WITH_STRING_VALUES);
}
- void verifyQuery(String command, String initialArgs, String additionalArgs,
- String outputRow1, String outputRow2, String outputRow3) throws IOException {
- String query = String.format(
- "source=%s | eval f=%s(%sname%s) | fields f", TEST_INDEX_STRINGS, command, initialArgs, additionalArgs);
+ void verifyQuery(
+ String command,
+ String initialArgs,
+ String additionalArgs,
+ String outputRow1,
+ String outputRow2,
+ String outputRow3)
+ throws IOException {
+ String query =
+ String.format(
+ "source=%s | eval f=%s(%sname%s) | fields f",
+ TEST_INDEX_STRINGS, command, initialArgs, additionalArgs);
JSONObject result = executeQuery(query);
verifySchema(result, schema("f", null, "string"));
verifyDataRows(result, rows(outputRow1), rows(outputRow2), rows(outputRow3));
}
- void verifyQuery(String command, String initialArgs, String additionalArgs,
- Integer outputRow1, Integer outputRow2, Integer outputRow3) throws IOException {
- String query = String.format(
- "source=%s | eval f=%s(%sname%s) | fields f", TEST_INDEX_STRINGS, command, initialArgs, additionalArgs);
+ void verifyQuery(
+ String command,
+ String initialArgs,
+ String additionalArgs,
+ Integer outputRow1,
+ Integer outputRow2,
+ Integer outputRow3)
+ throws IOException {
+ String query =
+ String.format(
+ "source=%s | eval f=%s(%sname%s) | fields f",
+ TEST_INDEX_STRINGS, command, initialArgs, additionalArgs);
JSONObject result = executeQuery(query);
verifySchema(result, schema("f", null, "integer"));
verifyDataRows(result, rows(outputRow1), rows(outputRow2), rows(outputRow3));
}
- void verifyRegexQuery(String pattern, Integer outputRow1, Integer outputRow2, Integer outputRow3) throws IOException {
- String query = String.format(
- "source=%s | eval f=name regexp '%s' | fields f", TEST_INDEX_STRINGS, pattern);
+ void verifyRegexQuery(String pattern, Integer outputRow1, Integer outputRow2, Integer outputRow3)
+ throws IOException {
+ String query =
+ String.format(
+ "source=%s | eval f=name regexp '%s' | fields f", TEST_INDEX_STRINGS, pattern);
JSONObject result = executeQuery(query);
verifySchema(result, schema("f", null, "integer"));
verifyDataRows(result, rows(outputRow1), rows(outputRow2), rows(outputRow3));
@@ -55,7 +72,7 @@ public void testRegexp() throws IOException {
verifyRegexQuery(".*", 1, 1, 1);
}
- @Test
+ @Test
public void testSubstr() throws IOException {
verifyQuery("substr", "", ", 2", "ello", "orld", "elloworld");
verifyQuery("substr", "", ", 2, 2", "el", "or", "el");
@@ -99,14 +116,19 @@ public void testLtrim() throws IOException {
@Test
public void testConcat() throws IOException {
- verifyQuery("concat", "", ", 'there', 'all', '!'",
- "hellothereall!", "worldthereall!", "helloworldthereall!");
+ verifyQuery(
+ "concat",
+ "",
+ ", 'there', 'all', '!'",
+ "hellothereall!",
+ "worldthereall!",
+ "helloworldthereall!");
}
@Test
public void testConcat_ws() throws IOException {
- verifyQuery("concat_ws", "',', ", ", 'there'",
- "hello,there", "world,there", "helloworld,there");
+ verifyQuery(
+ "concat_ws", "',', ", ", 'there'", "hello,there", "world,there", "helloworld,there");
}
@Test
@@ -137,7 +159,8 @@ public void testLocate() throws IOException {
@Test
public void testReplace() throws IOException {
- verifyQuery("replace", "", ", 'world', ' opensearch'", "hello", " opensearch", "hello opensearch");
+ verifyQuery(
+ "replace", "", ", 'world', ' opensearch'", "hello", " opensearch", "hello opensearch");
}
@Test
diff --git a/integ-test/src/test/java/org/opensearch/sql/ppl/TopCommandIT.java b/integ-test/src/test/java/org/opensearch/sql/ppl/TopCommandIT.java
index 054ff303a1..f9587e4b63 100644
--- a/integ-test/src/test/java/org/opensearch/sql/ppl/TopCommandIT.java
+++ b/integ-test/src/test/java/org/opensearch/sql/ppl/TopCommandIT.java
@@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/
-
package org.opensearch.sql.ppl;
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_ACCOUNT;
@@ -14,7 +13,7 @@
import org.json.JSONObject;
import org.junit.jupiter.api.Test;
-public class TopCommandIT extends PPLIntegTestCase{
+public class TopCommandIT extends PPLIntegTestCase {
@Override
public void init() throws IOException {
@@ -24,30 +23,20 @@ public void init() throws IOException {
@Test
public void testTopWithoutGroup() throws IOException {
- JSONObject result =
- executeQuery(String.format("source=%s | top gender", TEST_INDEX_ACCOUNT));
- verifyDataRows(
- result,
- rows("M"),
- rows("F"));
+ JSONObject result = executeQuery(String.format("source=%s | top gender", TEST_INDEX_ACCOUNT));
+ verifyDataRows(result, rows("M"), rows("F"));
}
@Test
- public void testTopNWithoutGroup() throws IOException{
- JSONObject result =
- executeQuery(String.format("source=%s | top 1 gender", TEST_INDEX_ACCOUNT));
- verifyDataRows(
- result,
- rows("M"));
+ public void testTopNWithoutGroup() throws IOException {
+ JSONObject result = executeQuery(String.format("source=%s | top 1 gender", TEST_INDEX_ACCOUNT));
+ verifyDataRows(result, rows("M"));
}
@Test
public void testTopNWithGroup() throws IOException {
JSONObject result =
executeQuery(String.format("source=%s | top 1 state by gender", TEST_INDEX_ACCOUNT));
- verifyDataRows(
- result,
- rows("F", "TX"),
- rows("M", "MD"));
+ verifyDataRows(result, rows("F", "TX"), rows("M", "MD"));
}
}
diff --git a/integ-test/src/test/java/org/opensearch/sql/ppl/VisualizationFormatIT.java b/integ-test/src/test/java/org/opensearch/sql/ppl/VisualizationFormatIT.java
index d530b4140d..263ed502ed 100644
--- a/integ-test/src/test/java/org/opensearch/sql/ppl/VisualizationFormatIT.java
+++ b/integ-test/src/test/java/org/opensearch/sql/ppl/VisualizationFormatIT.java
@@ -24,8 +24,9 @@ public void init() throws IOException {
@Test
void format() throws IOException {
- String result = executeVizQuery(
- String.format(Locale.ROOT, "source=%s | fields firstname, age", TEST_INDEX_BANK), true);
+ String result =
+ executeVizQuery(
+ String.format(Locale.ROOT, "source=%s | fields firstname, age", TEST_INDEX_BANK), true);
assertEquals(
"{\n"
+ " \"data\": {\n"
@@ -67,8 +68,10 @@ void format() throws IOException {
}
private String executeVizQuery(String query, boolean pretty) throws IOException {
- Request request = buildRequest(query,
- QUERY_API_ENDPOINT + String.format(Locale.ROOT, "?format=csv&pretty=%b", pretty));
+ Request request =
+ buildRequest(
+ query,
+ QUERY_API_ENDPOINT + String.format(Locale.ROOT, "?format=csv&pretty=%b", pretty));
Response response = client().performRequest(request);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
return getResponseBody(response, true);
diff --git a/integ-test/src/test/java/org/opensearch/sql/ppl/WhereCommandIT.java b/integ-test/src/test/java/org/opensearch/sql/ppl/WhereCommandIT.java
index ba870732fd..d56f9ffe32 100644
--- a/integ-test/src/test/java/org/opensearch/sql/ppl/WhereCommandIT.java
+++ b/integ-test/src/test/java/org/opensearch/sql/ppl/WhereCommandIT.java
@@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/
-
package org.opensearch.sql.ppl;
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_ACCOUNT;
diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/StandalonePaginationIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/StandalonePaginationIT.java
index 4738d233bf..e884734c96 100644
--- a/integ-test/src/test/java/org/opensearch/sql/sql/StandalonePaginationIT.java
+++ b/integ-test/src/test/java/org/opensearch/sql/sql/StandalonePaginationIT.java
@@ -66,17 +66,19 @@ public class StandalonePaginationIT extends SQLIntegTestCase {
public void init() {
RestHighLevelClient restClient = new InternalRestHighLevelClient(client());
client = new OpenSearchRestClient(restClient);
- DataSourceService dataSourceService = new DataSourceServiceImpl(
- new ImmutableSet.Builder()
- .add(new OpenSearchDataSourceFactory(client, defaultSettings()))
- .build(),
- getDataSourceMetadataStorage(),
- getDataSourceUserRoleHelper()
- );
+ DataSourceService dataSourceService =
+ new DataSourceServiceImpl(
+ new ImmutableSet.Builder()
+ .add(new OpenSearchDataSourceFactory(client, defaultSettings()))
+ .build(),
+ getDataSourceMetadataStorage(),
+ getDataSourceUserRoleHelper());
dataSourceService.createDataSource(defaultOpenSearchDataSourceMetadata());
ModulesBuilder modules = new ModulesBuilder();
- modules.add(new StandaloneModule(new InternalRestHighLevelClient(client()), defaultSettings(), dataSourceService));
+ modules.add(
+ new StandaloneModule(
+ new InternalRestHighLevelClient(client()), defaultSettings(), dataSourceService));
Injector injector = modules.createInjector();
queryService = injector.getInstance(QueryService.class);
@@ -85,10 +87,9 @@ public void init() {
@Test
public void test_pagination_whitebox() throws IOException {
- class TestResponder
- implements ResponseListener {
- @Getter
- Cursor cursor = Cursor.None;
+ class TestResponder implements ResponseListener {
+ @Getter Cursor cursor = Cursor.None;
+
@Override
public void onResponse(ExecutionEngine.QueryResponse response) {
cursor = response.getCursor();
@@ -113,13 +114,16 @@ public void onFailure(Exception e) {
// act 1, asserts in firstResponder
var t = new OpenSearchIndex(client, defaultSettings(), "test");
- LogicalPlan p = new LogicalPaginate(1, List.of(
- new LogicalProject(
- new LogicalRelation("test", t), List.of(
- DSL.named("name", DSL.ref("name", ExprCoreType.STRING)),
- DSL.named("age", DSL.ref("age", ExprCoreType.LONG))),
- List.of()
- )));
+ LogicalPlan p =
+ new LogicalPaginate(
+ 1,
+ List.of(
+ new LogicalProject(
+ new LogicalRelation("test", t),
+ List.of(
+ DSL.named("name", DSL.ref("name", ExprCoreType.STRING)),
+ DSL.named("age", DSL.ref("age", ExprCoreType.LONG))),
+ List.of())));
var firstResponder = new TestResponder();
queryService.executePlan(p, PlanContext.emptyPlanContext(), firstResponder);
@@ -139,24 +143,30 @@ public void test_explain_not_supported() {
// Request should be rejected before index names are resolved
request.setJsonEntity("{ \"query\": \"select * from something\", \"fetch_size\": 10 }");
var exception = assertThrows(ResponseException.class, () -> client().performRequest(request));
- var response = new JSONObject(new String(exception.getResponse().getEntity().getContent().readAllBytes()));
- assertEquals("`explain` feature for paginated requests is not implemented yet.",
+ var response =
+ new JSONObject(new String(exception.getResponse().getEntity().getContent().readAllBytes()));
+ assertEquals(
+ "`explain` feature for paginated requests is not implemented yet.",
response.getJSONObject("error").getString("details"));
// Request should be rejected before cursor parsed
request.setJsonEntity("{ \"cursor\" : \"n:0000\" }");
exception = assertThrows(ResponseException.class, () -> client().performRequest(request));
- response = new JSONObject(new String(exception.getResponse().getEntity().getContent().readAllBytes()));
- assertEquals("Explain of a paged query continuation is not supported. Use `explain` for the initial query request.",
+ response =
+ new JSONObject(new String(exception.getResponse().getEntity().getContent().readAllBytes()));
+ assertEquals(
+ "Explain of a paged query continuation is not supported. Use `explain` for the initial"
+ + " query request.",
response.getJSONObject("error").getString("details"));
}
private Settings defaultSettings() {
return new Settings() {
- private final Map defaultSettings = new ImmutableMap.Builder()
- .put(Key.QUERY_SIZE_LIMIT, 200)
- .put(Key.SQL_CURSOR_KEEP_ALIVE, TimeValue.timeValueMinutes(1))
- .build();
+ private final Map defaultSettings =
+ new ImmutableMap.Builder()
+ .put(Key.QUERY_SIZE_LIMIT, 200)
+ .put(Key.SQL_CURSOR_KEEP_ALIVE, TimeValue.timeValueMinutes(1))
+ .build();
@Override
public T getSettingValue(Key key) {
diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/StringLiteralIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/StringLiteralIT.java
index e54000f80d..d98016d62b 100644
--- a/integ-test/src/test/java/org/opensearch/sql/sql/StringLiteralIT.java
+++ b/integ-test/src/test/java/org/opensearch/sql/sql/StringLiteralIT.java
@@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/
-
package org.opensearch.sql.sql;
import static org.opensearch.sql.util.MatcherUtils.rows;
@@ -16,8 +15,6 @@
import org.junit.Test;
import org.opensearch.sql.legacy.SQLIntegTestCase;
-
-
public class StringLiteralIT extends SQLIntegTestCase {
@Test
public void testStringHelloSingleQuote() throws IOException {
diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/SystemFunctionIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/SystemFunctionIT.java
index 584cdd05dd..4b39e2925c 100644
--- a/integ-test/src/test/java/org/opensearch/sql/sql/SystemFunctionIT.java
+++ b/integ-test/src/test/java/org/opensearch/sql/sql/SystemFunctionIT.java
@@ -24,37 +24,47 @@ protected void init() throws Exception {
@Test
public void typeof_sql_types() {
- JSONObject response = executeJdbcRequest("SELECT typeof('pewpew'), typeof(NULL), typeof(1.0),"
- + "typeof(12345), typeof(1234567891011), typeof(INTERVAL 2 DAY);");
- verifyDataRows(response,
- rows("KEYWORD", "UNDEFINED", "DOUBLE", "INTEGER", "LONG", "INTERVAL"));
-
- response = executeJdbcRequest("SELECT"
- + " typeof(CAST('1961-04-12 09:07:00' AS TIMESTAMP)),"
- + " typeof(CAST('09:07:00' AS TIME)),"
- + " typeof(CAST('1961-04-12' AS DATE)),"
- + " typeof(DATETIME('1961-04-12 09:07:00'))");
- verifyDataRows(response,
- rows("TIMESTAMP", "TIME", "DATE", "DATETIME"));
+ JSONObject response =
+ executeJdbcRequest(
+ "SELECT typeof('pewpew'), typeof(NULL), typeof(1.0),"
+ + "typeof(12345), typeof(1234567891011), typeof(INTERVAL 2 DAY);");
+ verifyDataRows(response, rows("KEYWORD", "UNDEFINED", "DOUBLE", "INTEGER", "LONG", "INTERVAL"));
+
+ response =
+ executeJdbcRequest(
+ "SELECT"
+ + " typeof(CAST('1961-04-12 09:07:00' AS TIMESTAMP)),"
+ + " typeof(CAST('09:07:00' AS TIME)),"
+ + " typeof(CAST('1961-04-12' AS DATE)),"
+ + " typeof(DATETIME('1961-04-12 09:07:00'))");
+ verifyDataRows(response, rows("TIMESTAMP", "TIME", "DATE", "DATETIME"));
}
@Test
public void typeof_opensearch_types() {
- JSONObject response = executeJdbcRequest(String.format("SELECT typeof(double_number),"
- + "typeof(long_number), typeof(integer_number), typeof(byte_number), typeof(short_number),"
- + "typeof(float_number), typeof(half_float_number), typeof(scaled_float_number)"
- + " from %s;", TEST_INDEX_DATATYPE_NUMERIC));
- verifyDataRows(response,
- rows("DOUBLE", "LONG", "INTEGER", "BYTE", "SHORT", "FLOAT", "FLOAT", "DOUBLE"));
-
- response = executeJdbcRequest(String.format("SELECT typeof(text_value),"
- + "typeof(date_value), typeof(boolean_value), typeof(object_value), typeof(keyword_value),"
- + "typeof(ip_value), typeof(binary_value), typeof(geo_point_value)"
- // TODO activate this test once `ARRAY` type supported, see ExpressionAnalyzer::isTypeNotSupported
- //+ ", typeof(nested_value)"
- + " from %s;", TEST_INDEX_DATATYPE_NONNUMERIC));
- verifyDataRows(response,
- rows("TEXT", "TIMESTAMP", "BOOLEAN", "OBJECT", "KEYWORD",
- "IP", "BINARY", "GEO_POINT"));
+ JSONObject response =
+ executeJdbcRequest(
+ String.format(
+ "SELECT typeof(double_number),typeof(long_number), typeof(integer_number),"
+ + " typeof(byte_number), typeof(short_number),typeof(float_number),"
+ + " typeof(half_float_number), typeof(scaled_float_number) from %s;",
+ TEST_INDEX_DATATYPE_NUMERIC));
+ verifyDataRows(
+ response, rows("DOUBLE", "LONG", "INTEGER", "BYTE", "SHORT", "FLOAT", "FLOAT", "DOUBLE"));
+
+ response =
+ executeJdbcRequest(
+ String.format(
+ "SELECT typeof(text_value),typeof(date_value), typeof(boolean_value),"
+ + " typeof(object_value), typeof(keyword_value),typeof(ip_value),"
+ + " typeof(binary_value), typeof(geo_point_value)"
+ // TODO activate this test once `ARRAY` type supported, see
+ // ExpressionAnalyzer::isTypeNotSupported
+ // + ", typeof(nested_value)"
+ + " from %s;",
+ TEST_INDEX_DATATYPE_NONNUMERIC));
+ verifyDataRows(
+ response,
+ rows("TEXT", "TIMESTAMP", "BOOLEAN", "OBJECT", "KEYWORD", "IP", "BINARY", "GEO_POINT"));
}
}
diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/TextFunctionIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/TextFunctionIT.java
index 94677354e4..314132fed0 100644
--- a/integ-test/src/test/java/org/opensearch/sql/sql/TextFunctionIT.java
+++ b/integ-test/src/test/java/org/opensearch/sql/sql/TextFunctionIT.java
@@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/
-
package org.opensearch.sql.sql;
import static org.opensearch.sql.legacy.plugin.RestSqlAction.QUERY_API_ENDPOINT;
@@ -43,8 +42,7 @@ void verifyQuery(String query, String type, Integer output) throws IOException {
void verifyQueryWithNullOutput(String query, String type) throws IOException {
JSONObject result = executeQuery("select 'test null'," + query);
- verifySchema(result, schema(query, null, type),
- schema("'test null'", null, type));
+ verifySchema(result, schema(query, null, type), schema("'test null'", null, type));
verifyDataRows(result, rows("test null", null));
}
diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/WildcardQueryIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/WildcardQueryIT.java
index 030c07c5fa..8123f887f2 100644
--- a/integ-test/src/test/java/org/opensearch/sql/sql/WildcardQueryIT.java
+++ b/integ-test/src/test/java/org/opensearch/sql/sql/WildcardQueryIT.java
@@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/
-
package org.opensearch.sql.sql;
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_WILDCARD;
@@ -25,11 +24,17 @@ protected void init() throws Exception {
public void test_wildcard_query_asterisk_function() throws IOException {
String expected = "test wildcard";
- String query1 = "SELECT KeywordBody FROM " + TEST_INDEX_WILDCARD + " WHERE wildcard_query(KeywordBody, 't*') LIMIT 1";
+ String query1 =
+ "SELECT KeywordBody FROM "
+ + TEST_INDEX_WILDCARD
+ + " WHERE wildcard_query(KeywordBody, 't*') LIMIT 1";
JSONObject result1 = executeJdbcRequest(query1);
verifyDataRows(result1, rows(expected));
- String query2 = "SELECT KeywordBody FROM " + TEST_INDEX_WILDCARD + " WHERE wildcardquery(KeywordBody, 't*') LIMIT 1";
+ String query2 =
+ "SELECT KeywordBody FROM "
+ + TEST_INDEX_WILDCARD
+ + " WHERE wildcardquery(KeywordBody, 't*') LIMIT 1";
JSONObject result2 = executeJdbcRequest(query2);
verifyDataRows(result2, rows(expected));
}
@@ -38,11 +43,17 @@ public void test_wildcard_query_asterisk_function() throws IOException {
public void test_wildcard_query_question_mark_function() throws IOException {
String expected = "test wildcard";
- String query1 = "SELECT KeywordBody FROM " + TEST_INDEX_WILDCARD + " WHERE wildcard_query(KeywordBody, 'test wild??rd')";
+ String query1 =
+ "SELECT KeywordBody FROM "
+ + TEST_INDEX_WILDCARD
+ + " WHERE wildcard_query(KeywordBody, 'test wild??rd')";
JSONObject result1 = executeJdbcRequest(query1);
verifyDataRows(result1, rows(expected));
- String query2 = "SELECT KeywordBody FROM " + TEST_INDEX_WILDCARD + " WHERE wildcardquery(KeywordBody, 'test wild??rd')";
+ String query2 =
+ "SELECT KeywordBody FROM "
+ + TEST_INDEX_WILDCARD
+ + " WHERE wildcardquery(KeywordBody, 'test wild??rd')";
JSONObject result2 = executeJdbcRequest(query2);
verifyDataRows(result2, rows(expected));
}
@@ -50,11 +61,17 @@ public void test_wildcard_query_question_mark_function() throws IOException {
// SQL uses ? as a wildcard which is converted to * in WildcardQuery.java
@Test
public void test_wildcard_query_sql_wildcard_percent_conversion() throws IOException {
- String query1 = "SELECT KeywordBody FROM " + TEST_INDEX_WILDCARD + " WHERE wildcard_query(KeywordBody, 'test%')";
+ String query1 =
+ "SELECT KeywordBody FROM "
+ + TEST_INDEX_WILDCARD
+ + " WHERE wildcard_query(KeywordBody, 'test%')";
JSONObject result1 = executeJdbcRequest(query1);
assertEquals(8, result1.getInt("total"));
- String query2 = "SELECT KeywordBody FROM " + TEST_INDEX_WILDCARD + " WHERE wildcard_query(KeywordBody, 'test*')";
+ String query2 =
+ "SELECT KeywordBody FROM "
+ + TEST_INDEX_WILDCARD
+ + " WHERE wildcard_query(KeywordBody, 'test*')";
JSONObject result2 = executeJdbcRequest(query2);
assertEquals(result1.getInt("total"), result2.getInt("total"));
}
@@ -62,27 +79,41 @@ public void test_wildcard_query_sql_wildcard_percent_conversion() throws IOExcep
// SQL uses _ as a wildcard which is converted to ? in WildcardQuery.java
@Test
public void test_wildcard_query_sql_wildcard_underscore_conversion() throws IOException {
- String query1 = "SELECT KeywordBody FROM " + TEST_INDEX_WILDCARD + " WHERE wildcard_query(KeywordBody, 'test wild_ard*')";
+ String query1 =
+ "SELECT KeywordBody FROM "
+ + TEST_INDEX_WILDCARD
+ + " WHERE wildcard_query(KeywordBody, 'test wild_ard*')";
JSONObject result1 = executeJdbcRequest(query1);
assertEquals(7, result1.getInt("total"));
- String query2 = "SELECT KeywordBody FROM " + TEST_INDEX_WILDCARD + " WHERE wildcard_query(KeywordBody, 'test wild?ard*')";
+ String query2 =
+ "SELECT KeywordBody FROM "
+ + TEST_INDEX_WILDCARD
+ + " WHERE wildcard_query(KeywordBody, 'test wild?ard*')";
JSONObject result2 = executeJdbcRequest(query2);
assertEquals(result1.getInt("total"), result2.getInt("total"));
}
@Test
public void test_escaping_wildcard_percent_in_the_beginning_of_text() throws IOException {
- String query = "SELECT KeywordBody FROM " + TEST_INDEX_WILDCARD + " WHERE wildcard_query(KeywordBody, '\\\\%*')";
+ String query =
+ "SELECT KeywordBody FROM "
+ + TEST_INDEX_WILDCARD
+ + " WHERE wildcard_query(KeywordBody, '\\\\%*')";
JSONObject result = executeJdbcRequest(query);
verifyDataRows(result, rows("%test wildcard in the beginning of the text"));
}
@Test
public void test_escaping_wildcard_percent_in_text() throws IOException {
- String query = "SELECT KeywordBody FROM " + TEST_INDEX_WILDCARD + " WHERE wildcard_query(KeywordBody, '*\\\\%%')";
+ String query =
+ "SELECT KeywordBody FROM "
+ + TEST_INDEX_WILDCARD
+ + " WHERE wildcard_query(KeywordBody, '*\\\\%%')";
JSONObject result = executeJdbcRequest(query);
- verifyDataRows(result, rows("test wildcard in % the middle of the text"),
+ verifyDataRows(
+ result,
+ rows("test wildcard in % the middle of the text"),
rows("test wildcard %% beside each other"),
rows("test wildcard in the end of the text%"),
rows("%test wildcard in the beginning of the text"));
@@ -90,30 +121,44 @@ public void test_escaping_wildcard_percent_in_text() throws IOException {
@Test
public void test_escaping_wildcard_percent_in_the_end_of_text() throws IOException {
- String query = "SELECT KeywordBody FROM " + TEST_INDEX_WILDCARD + " WHERE wildcard_query(KeywordBody, '*\\\\%')";
+ String query =
+ "SELECT KeywordBody FROM "
+ + TEST_INDEX_WILDCARD
+ + " WHERE wildcard_query(KeywordBody, '*\\\\%')";
JSONObject result = executeJdbcRequest(query);
verifyDataRows(result, rows("test wildcard in the end of the text%"));
}
@Test
public void test_double_escaped_wildcard_percent() throws IOException {
- String query = "SELECT KeywordBody FROM " + TEST_INDEX_WILDCARD + " WHERE wildcard_query(KeywordBody, '*\\\\%\\\\%*')";
+ String query =
+ "SELECT KeywordBody FROM "
+ + TEST_INDEX_WILDCARD
+ + " WHERE wildcard_query(KeywordBody, '*\\\\%\\\\%*')";
JSONObject result = executeJdbcRequest(query);
verifyDataRows(result, rows("test wildcard %% beside each other"));
}
@Test
public void test_escaping_wildcard_underscore_in_the_beginning_of_text() throws IOException {
- String query = "SELECT KeywordBody FROM " + TEST_INDEX_WILDCARD + " WHERE wildcard_query(KeywordBody, '\\\\_*')";
+ String query =
+ "SELECT KeywordBody FROM "
+ + TEST_INDEX_WILDCARD
+ + " WHERE wildcard_query(KeywordBody, '\\\\_*')";
JSONObject result = executeJdbcRequest(query);
verifyDataRows(result, rows("_test wildcard in the beginning of the text"));
}
@Test
public void test_escaping_wildcard_underscore_in_text() throws IOException {
- String query = "SELECT KeywordBody FROM " + TEST_INDEX_WILDCARD + " WHERE wildcard_query(KeywordBody, '*\\\\_*')";
+ String query =
+ "SELECT KeywordBody FROM "
+ + TEST_INDEX_WILDCARD
+ + " WHERE wildcard_query(KeywordBody, '*\\\\_*')";
JSONObject result = executeJdbcRequest(query);
- verifyDataRows(result, rows("test wildcard in _ the middle of the text"),
+ verifyDataRows(
+ result,
+ rows("test wildcard in _ the middle of the text"),
rows("test wildcard __ beside each other"),
rows("test wildcard in the end of the text_"),
rows("_test wildcard in the beginning of the text"),
@@ -122,60 +167,77 @@ public void test_escaping_wildcard_underscore_in_text() throws IOException {
@Test
public void test_escaping_wildcard_underscore_in_the_end_of_text() throws IOException {
- String query = "SELECT KeywordBody FROM " + TEST_INDEX_WILDCARD + " WHERE wildcard_query(KeywordBody, '*\\\\_')";
+ String query =
+ "SELECT KeywordBody FROM "
+ + TEST_INDEX_WILDCARD
+ + " WHERE wildcard_query(KeywordBody, '*\\\\_')";
JSONObject result = executeJdbcRequest(query);
- verifyDataRows(result,
- rows("test wildcard in the end of the text_"),
- rows("test backslash wildcard \\_"));
+ verifyDataRows(
+ result, rows("test wildcard in the end of the text_"), rows("test backslash wildcard \\_"));
}
@Test
public void test_double_escaped_wildcard_underscore() throws IOException {
- String query = "SELECT KeywordBody FROM " + TEST_INDEX_WILDCARD + " WHERE wildcard_query(KeywordBody, '*\\\\_\\\\_*')";
+ String query =
+ "SELECT KeywordBody FROM "
+ + TEST_INDEX_WILDCARD
+ + " WHERE wildcard_query(KeywordBody, '*\\\\_\\\\_*')";
JSONObject result = executeJdbcRequest(query);
verifyDataRows(result, rows("test wildcard __ beside each other"));
}
@Test
public void test_backslash_wildcard() throws IOException {
- String query = "SELECT KeywordBody FROM " + TEST_INDEX_WILDCARD + " WHERE wildcard_query(KeywordBody, '*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\_')";
+ String query =
+ "SELECT KeywordBody FROM "
+ + TEST_INDEX_WILDCARD
+ + " WHERE wildcard_query(KeywordBody, '*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\_')";
JSONObject result = executeJdbcRequest(query);
verifyDataRows(result, rows("test backslash wildcard \\_"));
}
@Test
public void all_params_test() throws IOException {
- String query = "SELECT KeywordBody FROM " + TEST_INDEX_WILDCARD
- + " WHERE wildcard_query(KeywordBody, 'test*', boost = 0.9,"
- + " case_insensitive=true, rewrite='constant_score')";
+ String query =
+ "SELECT KeywordBody FROM "
+ + TEST_INDEX_WILDCARD
+ + " WHERE wildcard_query(KeywordBody, 'test*', boost = 0.9,"
+ + " case_insensitive=true, rewrite='constant_score')";
JSONObject result = executeJdbcRequest(query);
assertEquals(8, result.getInt("total"));
}
@Test
public void test_wildcard_query_on_text_field_with_one_word() throws IOException {
- String query = "SELECT * FROM " + TEST_INDEX_WILDCARD + " WHERE wildcard_query(TextBody, 'test*')";
+ String query =
+ "SELECT * FROM " + TEST_INDEX_WILDCARD + " WHERE wildcard_query(TextBody, 'test*')";
JSONObject result = executeJdbcRequest(query);
assertEquals(9, result.getInt("total"));
}
@Test
public void test_wildcard_query_on_text_keyword_field_with_one_word() throws IOException {
- String query = "SELECT * FROM " + TEST_INDEX_WILDCARD + " WHERE wildcard_query(TextKeywordBody, 'test*')";
+ String query =
+ "SELECT * FROM " + TEST_INDEX_WILDCARD + " WHERE wildcard_query(TextKeywordBody, 'test*')";
JSONObject result = executeJdbcRequest(query);
assertEquals(9, result.getInt("total"));
}
@Test
public void test_wildcard_query_on_text_field_with_greater_than_one_word() throws IOException {
- String query = "SELECT * FROM " + TEST_INDEX_WILDCARD + " WHERE wildcard_query(TextBody, 'test wild*')";
+ String query =
+ "SELECT * FROM " + TEST_INDEX_WILDCARD + " WHERE wildcard_query(TextBody, 'test wild*')";
JSONObject result = executeJdbcRequest(query);
assertEquals(0, result.getInt("total"));
}
@Test
- public void test_wildcard_query_on_text_keyword_field_with_greater_than_one_word() throws IOException {
- String query = "SELECT * FROM " + TEST_INDEX_WILDCARD + " WHERE wildcard_query(TextKeywordBody, 'test wild*')";
+ public void test_wildcard_query_on_text_keyword_field_with_greater_than_one_word()
+ throws IOException {
+ String query =
+ "SELECT * FROM "
+ + TEST_INDEX_WILDCARD
+ + " WHERE wildcard_query(TextKeywordBody, 'test wild*')";
JSONObject result = executeJdbcRequest(query);
assertEquals(0, result.getInt("total"));
}
diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/WindowFunctionIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/WindowFunctionIT.java
index b586125af3..86257e6a22 100644
--- a/integ-test/src/test/java/org/opensearch/sql/sql/WindowFunctionIT.java
+++ b/integ-test/src/test/java/org/opensearch/sql/sql/WindowFunctionIT.java
@@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/
-
package org.opensearch.sql.sql;
import static org.opensearch.sql.util.MatcherUtils.rows;
@@ -25,11 +24,16 @@ protected void init() throws Exception {
@Test
public void testOrderByNullFirst() {
- JSONObject response = new JSONObject(
- executeQuery("SELECT age, ROW_NUMBER() OVER(ORDER BY age DESC NULLS FIRST) "
- + "FROM " + TestsConstants.TEST_INDEX_BANK_WITH_NULL_VALUES, "jdbc"));
+ JSONObject response =
+ new JSONObject(
+ executeQuery(
+ "SELECT age, ROW_NUMBER() OVER(ORDER BY age DESC NULLS FIRST) "
+ + "FROM "
+ + TestsConstants.TEST_INDEX_BANK_WITH_NULL_VALUES,
+ "jdbc"));
- verifyDataRows(response,
+ verifyDataRows(
+ response,
rows(null, 1),
rows(36, 2),
rows(36, 3),
@@ -41,11 +45,16 @@ public void testOrderByNullFirst() {
@Test
public void testOrderByNullLast() {
- JSONObject response = new JSONObject(
- executeQuery("SELECT age, ROW_NUMBER() OVER(ORDER BY age NULLS LAST) "
- + "FROM " + TestsConstants.TEST_INDEX_BANK_WITH_NULL_VALUES, "jdbc"));
+ JSONObject response =
+ new JSONObject(
+ executeQuery(
+ "SELECT age, ROW_NUMBER() OVER(ORDER BY age NULLS LAST) "
+ + "FROM "
+ + TestsConstants.TEST_INDEX_BANK_WITH_NULL_VALUES,
+ "jdbc"));
- verifyDataRows(response,
+ verifyDataRows(
+ response,
rows(28, 1),
rows(32, 2),
rows(33, 3),
@@ -57,10 +66,15 @@ public void testOrderByNullLast() {
@Test
public void testDistinctCountOverNull() {
- JSONObject response = new JSONObject(executeQuery(
- "SELECT lastname, COUNT(DISTINCT gender) OVER() "
- + "FROM " + TestsConstants.TEST_INDEX_BANK, "jdbc"));
- verifyDataRows(response,
+ JSONObject response =
+ new JSONObject(
+ executeQuery(
+ "SELECT lastname, COUNT(DISTINCT gender) OVER() "
+ + "FROM "
+ + TestsConstants.TEST_INDEX_BANK,
+ "jdbc"));
+ verifyDataRows(
+ response,
rows("Duke Willmington", 2),
rows("Bond", 2),
rows("Bates", 2),
@@ -72,10 +86,15 @@ public void testDistinctCountOverNull() {
@Test
public void testDistinctCountOver() {
- JSONObject response = new JSONObject(executeQuery(
- "SELECT lastname, COUNT(DISTINCT gender) OVER(ORDER BY lastname) "
- + "FROM " + TestsConstants.TEST_INDEX_BANK, "jdbc"));
- verifyDataRowsInOrder(response,
+ JSONObject response =
+ new JSONObject(
+ executeQuery(
+ "SELECT lastname, COUNT(DISTINCT gender) OVER(ORDER BY lastname) "
+ + "FROM "
+ + TestsConstants.TEST_INDEX_BANK,
+ "jdbc"));
+ verifyDataRowsInOrder(
+ response,
rows("Adams", 1),
rows("Ayala", 2),
rows("Bates", 2),
@@ -87,10 +106,15 @@ public void testDistinctCountOver() {
@Test
public void testDistinctCountPartition() {
- JSONObject response = new JSONObject(executeQuery(
- "SELECT lastname, COUNT(DISTINCT gender) OVER(PARTITION BY gender ORDER BY lastname) "
- + "FROM " + TestsConstants.TEST_INDEX_BANK, "jdbc"));
- verifyDataRowsInOrder(response,
+ JSONObject response =
+ new JSONObject(
+ executeQuery(
+ "SELECT lastname, COUNT(DISTINCT gender) OVER(PARTITION BY gender ORDER BY"
+ + " lastname) FROM "
+ + TestsConstants.TEST_INDEX_BANK,
+ "jdbc"));
+ verifyDataRowsInOrder(
+ response,
rows("Ayala", 1),
rows("Bates", 1),
rows("Mcpherson", 1),
@@ -99,5 +123,4 @@ public void testDistinctCountPartition() {
rows("Duke Willmington", 1),
rows("Ratliff", 1));
}
-
}
diff --git a/integ-test/src/test/java/org/opensearch/sql/util/StandaloneModule.java b/integ-test/src/test/java/org/opensearch/sql/util/StandaloneModule.java
index ad8afc47ca..5d6f0b5a55 100644
--- a/integ-test/src/test/java/org/opensearch/sql/util/StandaloneModule.java
+++ b/integ-test/src/test/java/org/opensearch/sql/util/StandaloneModule.java
@@ -37,8 +37,8 @@
import org.opensearch.sql.storage.StorageEngine;
/**
- * A utility class which registers SQL engine singletons as `OpenSearchPluginModule` does.
- * It is needed to get access to those instances in test and validate their behavior.
+ * A utility class which registers SQL engine singletons as `OpenSearchPluginModule` does. It is
+ * needed to get access to those instances in test and validate their behavior.
*/
@RequiredArgsConstructor
public class StandaloneModule extends AbstractModule {
@@ -53,8 +53,7 @@ public class StandaloneModule extends AbstractModule {
BuiltinFunctionRepository.getInstance();
@Override
- protected void configure() {
- }
+ protected void configure() {}
@Provides
public OpenSearchClient openSearchClient() {
@@ -67,8 +66,8 @@ public StorageEngine storageEngine(OpenSearchClient client) {
}
@Provides
- public ExecutionEngine executionEngine(OpenSearchClient client, ExecutionProtector protector,
- PlanSerializer planSerializer) {
+ public ExecutionEngine executionEngine(
+ OpenSearchClient client, ExecutionProtector protector, PlanSerializer planSerializer) {
return new OpenSearchExecutionEngine(client, protector, planSerializer);
}
diff --git a/integ-test/src/test/java/org/opensearch/sql/util/TestUtils.java b/integ-test/src/test/java/org/opensearch/sql/util/TestUtils.java
index 3281c172cb..ac5cee118c 100644
--- a/integ-test/src/test/java/org/opensearch/sql/util/TestUtils.java
+++ b/integ-test/src/test/java/org/opensearch/sql/util/TestUtils.java
@@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/
-
package org.opensearch.sql.util;
import static com.google.common.base.Strings.isNullOrEmpty;
@@ -44,9 +43,9 @@ public class TestUtils {
/**
* Create test index by REST client.
*
- * @param client client connection
+ * @param client client connection
* @param indexName test index name
- * @param mapping test index mapping or null if no predefined mapping
+ * @param mapping test index mapping or null if no predefined mapping
*/
public static void createIndexByRestClient(RestClient client, String indexName, String mapping) {
Request request = new Request("PUT", "/" + indexName);
@@ -57,16 +56,16 @@ public static void createIndexByRestClient(RestClient client, String indexName,
}
/**
- * https://github.com/elastic/elasticsearch/pull/49959
- * Deprecate creation of dot-prefixed index names except for hidden and system indices.
- * Create hidden index by REST client.
+ * https://github.com/elastic/elasticsearch/pull/49959
+ * Deprecate creation of dot-prefixed index
+ * names except for hidden and system indices. Create hidden index by REST client.
*
- * @param client client connection
+ * @param client client connection
* @param indexName test index name
- * @param mapping test index mapping or null if no predefined mapping
+ * @param mapping test index mapping or null if no predefined mapping
*/
- public static void createHiddenIndexByRestClient(RestClient client, String indexName,
- String mapping) {
+ public static void createHiddenIndexByRestClient(
+ RestClient client, String indexName, String mapping) {
Request request = new Request("PUT", "/" + indexName);
JSONObject jsonObject = isNullOrEmpty(mapping) ? new JSONObject() : new JSONObject(mapping);
jsonObject.put("settings", new JSONObject("{\"index\":{\"hidden\":true}}"));
@@ -76,11 +75,11 @@ public static void createHiddenIndexByRestClient(RestClient client, String index
}
/**
- * Check if index already exists by OpenSearch index exists API which returns:
- * 200 - specified indices or aliases exist
+ * Check if index already exists by OpenSearch index exists API which returns:
+ * 200 - specified indices or aliases exist
* 404 - one or more indices specified or aliases do not exist
*
- * @param client client connection
+ * @param client client connection
* @param indexName index name
* @return true for index exist
*/
@@ -96,13 +95,13 @@ public static boolean isIndexExist(RestClient client, String indexName) {
/**
* Load test data set by REST client.
*
- * @param client client connection
- * @param indexName index name
+ * @param client client connection
+ * @param indexName index name
* @param dataSetFilePath file path of test data set
* @throws IOException
*/
- public static void loadDataByRestClient(RestClient client, String indexName,
- String dataSetFilePath) throws IOException {
+ public static void loadDataByRestClient(
+ RestClient client, String indexName, String dataSetFilePath) throws IOException {
Path path = Paths.get(getResourceFilePath(dataSetFilePath));
Request request = new Request("POST", "/" + indexName + "/_bulk?refresh=true");
request.setJsonEntity(new String(Files.readAllBytes(path)));
@@ -112,7 +111,7 @@ public static void loadDataByRestClient(RestClient client, String indexName,
/**
* Perform a request by REST client.
*
- * @param client client connection
+ * @param client client connection
* @param request request object
*/
public static Response performRequest(RestClient client, Request request) {
@@ -129,566 +128,567 @@ public static Response performRequest(RestClient client, Request request) {
}
public static String getAccountIndexMapping() {
- return "{ \"mappings\": {" +
- " \"properties\": {\n" +
- " \"gender\": {\n" +
- " \"type\": \"text\",\n" +
- " \"fielddata\": true\n" +
- " }," +
- " \"address\": {\n" +
- " \"type\": \"text\",\n" +
- " \"fielddata\": true\n" +
- " }," +
- " \"firstname\": {\n" +
- " \"type\": \"text\",\n" +
- " \"fielddata\": true,\n" +
- " \"fields\": {\n" +
- " \"keyword\": {\n" +
- " \"type\": \"keyword\",\n" +
- " \"ignore_above\": 256\n" +
- " }" +
- " }" +
- " }," +
- " \"lastname\": {\n" +
- " \"type\": \"text\",\n" +
- " \"fielddata\": true,\n" +
- " \"fields\": {\n" +
- " \"keyword\": {\n" +
- " \"type\": \"keyword\",\n" +
- " \"ignore_above\": 256\n" +
- " }" +
- " }" +
- " }," +
- " \"state\": {\n" +
- " \"type\": \"text\",\n" +
- " \"fielddata\": true,\n" +
- " \"fields\": {\n" +
- " \"keyword\": {\n" +
- " \"type\": \"keyword\",\n" +
- " \"ignore_above\": 256\n" +
- " }" +
- " }" +
- " }" +
- " }" +
- " }" +
- "}";
+ return "{ \"mappings\": {"
+ + " \"properties\": {\n"
+ + " \"gender\": {\n"
+ + " \"type\": \"text\",\n"
+ + " \"fielddata\": true\n"
+ + " },"
+ + " \"address\": {\n"
+ + " \"type\": \"text\",\n"
+ + " \"fielddata\": true\n"
+ + " },"
+ + " \"firstname\": {\n"
+ + " \"type\": \"text\",\n"
+ + " \"fielddata\": true,\n"
+ + " \"fields\": {\n"
+ + " \"keyword\": {\n"
+ + " \"type\": \"keyword\",\n"
+ + " \"ignore_above\": 256\n"
+ + " }"
+ + " }"
+ + " },"
+ + " \"lastname\": {\n"
+ + " \"type\": \"text\",\n"
+ + " \"fielddata\": true,\n"
+ + " \"fields\": {\n"
+ + " \"keyword\": {\n"
+ + " \"type\": \"keyword\",\n"
+ + " \"ignore_above\": 256\n"
+ + " }"
+ + " }"
+ + " },"
+ + " \"state\": {\n"
+ + " \"type\": \"text\",\n"
+ + " \"fielddata\": true,\n"
+ + " \"fields\": {\n"
+ + " \"keyword\": {\n"
+ + " \"type\": \"keyword\",\n"
+ + " \"ignore_above\": 256\n"
+ + " }"
+ + " }"
+ + " }"
+ + " }"
+ + " }"
+ + "}";
}
public static String getPhraseIndexMapping() {
- return "{ \"mappings\": {" +
- " \"properties\": {\n" +
- " \"phrase\": {\n" +
- " \"type\": \"text\",\n" +
- " \"store\": true\n" +
- " }" +
- " }" +
- " }" +
- "}";
+ return "{ \"mappings\": {"
+ + " \"properties\": {\n"
+ + " \"phrase\": {\n"
+ + " \"type\": \"text\",\n"
+ + " \"store\": true\n"
+ + " }"
+ + " }"
+ + " }"
+ + "}";
}
public static String getDogIndexMapping() {
- return "{ \"mappings\": {" +
- " \"properties\": {\n" +
- " \"dog_name\": {\n" +
- " \"type\": \"text\",\n" +
- " \"fielddata\": true\n" +
- " }" +
- " }" +
- " }" +
- "}";
+ return "{ \"mappings\": {"
+ + " \"properties\": {\n"
+ + " \"dog_name\": {\n"
+ + " \"type\": \"text\",\n"
+ + " \"fielddata\": true\n"
+ + " }"
+ + " }"
+ + " }"
+ + "}";
}
public static String getDogs2IndexMapping() {
- return "{ \"mappings\": {" +
- " \"properties\": {\n" +
- " \"dog_name\": {\n" +
- " \"type\": \"text\",\n" +
- " \"fielddata\": true\n" +
- " },\n" +
- " \"holdersName\": {\n" +
- " \"type\": \"keyword\"\n" +
- " }" +
- " }" +
- " }" +
- "}";
+ return "{ \"mappings\": {"
+ + " \"properties\": {\n"
+ + " \"dog_name\": {\n"
+ + " \"type\": \"text\",\n"
+ + " \"fielddata\": true\n"
+ + " },\n"
+ + " \"holdersName\": {\n"
+ + " \"type\": \"keyword\"\n"
+ + " }"
+ + " }"
+ + " }"
+ + "}";
}
public static String getDogs3IndexMapping() {
- return "{ \"mappings\": {" +
- " \"properties\": {\n" +
- " \"holdersName\": {\n" +
- " \"type\": \"keyword\"\n" +
- " },\n" +
- " \"color\": {\n" +
- " \"type\": \"text\"\n" +
- " }" +
- " }" +
- " }" +
- "}";
+ return "{ \"mappings\": {"
+ + " \"properties\": {\n"
+ + " \"holdersName\": {\n"
+ + " \"type\": \"keyword\"\n"
+ + " },\n"
+ + " \"color\": {\n"
+ + " \"type\": \"text\"\n"
+ + " }"
+ + " }"
+ + " }"
+ + "}";
}
public static String getPeople2IndexMapping() {
- return "{ \"mappings\": {" +
- " \"properties\": {\n" +
- " \"firstname\": {\n" +
- " \"type\": \"keyword\"\n" +
- " }" +
- " }" +
- " }" +
- "}";
+ return "{ \"mappings\": {"
+ + " \"properties\": {\n"
+ + " \"firstname\": {\n"
+ + " \"type\": \"keyword\"\n"
+ + " }"
+ + " }"
+ + " }"
+ + "}";
}
public static String getGameOfThronesIndexMapping() {
- return "{ \"mappings\": { " +
- " \"properties\": {\n" +
- " \"nickname\": {\n" +
- " \"type\":\"text\", " +
- " \"fielddata\":true" +
- " },\n" +
- " \"name\": {\n" +
- " \"properties\": {\n" +
- " \"firstname\": {\n" +
- " \"type\": \"text\",\n" +
- " \"fielddata\": true\n" +
- " },\n" +
- " \"lastname\": {\n" +
- " \"type\": \"text\",\n" +
- " \"fielddata\": true\n" +
- " },\n" +
- " \"ofHerName\": {\n" +
- " \"type\": \"integer\"\n" +
- " },\n" +
- " \"ofHisName\": {\n" +
- " \"type\": \"integer\"\n" +
- " }\n" +
- " }\n" +
- " },\n" +
- " \"house\": {\n" +
- " \"type\": \"text\",\n" +
- " \"fields\": {\n" +
- " \"keyword\": {\n" +
- " \"type\": \"keyword\"\n" +
- " }\n" +
- " }\n" +
- " },\n" +
- " \"gender\": {\n" +
- " \"type\": \"text\",\n" +
- " \"fields\": {\n" +
- " \"keyword\": {\n" +
- " \"type\": \"keyword\"\n" +
- " }\n" +
- " }\n" +
- " }" +
- "} } }";
+ return "{ \"mappings\": { "
+ + " \"properties\": {\n"
+ + " \"nickname\": {\n"
+ + " \"type\":\"text\", "
+ + " \"fielddata\":true"
+ + " },\n"
+ + " \"name\": {\n"
+ + " \"properties\": {\n"
+ + " \"firstname\": {\n"
+ + " \"type\": \"text\",\n"
+ + " \"fielddata\": true\n"
+ + " },\n"
+ + " \"lastname\": {\n"
+ + " \"type\": \"text\",\n"
+ + " \"fielddata\": true\n"
+ + " },\n"
+ + " \"ofHerName\": {\n"
+ + " \"type\": \"integer\"\n"
+ + " },\n"
+ + " \"ofHisName\": {\n"
+ + " \"type\": \"integer\"\n"
+ + " }\n"
+ + " }\n"
+ + " },\n"
+ + " \"house\": {\n"
+ + " \"type\": \"text\",\n"
+ + " \"fields\": {\n"
+ + " \"keyword\": {\n"
+ + " \"type\": \"keyword\"\n"
+ + " }\n"
+ + " }\n"
+ + " },\n"
+ + " \"gender\": {\n"
+ + " \"type\": \"text\",\n"
+ + " \"fields\": {\n"
+ + " \"keyword\": {\n"
+ + " \"type\": \"keyword\"\n"
+ + " }\n"
+ + " }\n"
+ + " }"
+ + "} } }";
}
// System
public static String getOdbcIndexMapping() {
- return "{\n" +
- "\t\"mappings\" :{\n" +
- "\t\t\"properties\":{\n" +
- "\t\t\t\"odbc_time\":{\n" +
- "\t\t\t\t\"type\":\"date\",\n" +
- "\t\t\t\t\"format\": \"'{ts' ''yyyy-MM-dd HH:mm:ss.SSS'''}'\"\n" +
- "\t\t\t},\n" +
- "\t\t\t\"docCount\":{\n" +
- "\t\t\t\t\"type\":\"text\"\n" +
- "\t\t\t}\n" +
- "\t\t}\n" +
- "\t}\n" +
- "}";
+ return "{\n"
+ + "\t\"mappings\" :{\n"
+ + "\t\t\"properties\":{\n"
+ + "\t\t\t\"odbc_time\":{\n"
+ + "\t\t\t\t\"type\":\"date\",\n"
+ + "\t\t\t\t\"format\": \"'{ts' ''yyyy-MM-dd HH:mm:ss.SSS'''}'\"\n"
+ + "\t\t\t},\n"
+ + "\t\t\t\"docCount\":{\n"
+ + "\t\t\t\t\"type\":\"text\"\n"
+ + "\t\t\t}\n"
+ + "\t\t}\n"
+ + "\t}\n"
+ + "}";
}
public static String getLocationIndexMapping() {
- return "{\n" +
- "\t\"mappings\" :{\n" +
- "\t\t\"properties\":{\n" +
- "\t\t\t\"place\":{\n" +
- "\t\t\t\t\"type\":\"geo_shape\"\n" +
- //"\t\t\t\t\"tree\": \"quadtree\",\n" + // Field tree and precision are deprecated in OpenSearch
- //"\t\t\t\t\"precision\": \"10km\"\n" +
- "\t\t\t},\n" +
- "\t\t\t\"center\":{\n" +
- "\t\t\t\t\"type\":\"geo_point\"\n" +
- "\t\t\t},\n" +
- "\t\t\t\"description\":{\n" +
- "\t\t\t\t\"type\":\"text\"\n" +
- "\t\t\t}\n" +
- "\t\t}\n" +
- "\t}\n" +
- "}";
+ return "{\n"
+ + "\t\"mappings\" :{\n"
+ + "\t\t\"properties\":{\n"
+ + "\t\t\t\"place\":{\n"
+ + "\t\t\t\t\"type\":\"geo_shape\"\n"
+ +
+ // "\t\t\t\t\"tree\": \"quadtree\",\n" + // Field tree and precision are deprecated in
+ // OpenSearch
+ // "\t\t\t\t\"precision\": \"10km\"\n" +
+ "\t\t\t},\n"
+ + "\t\t\t\"center\":{\n"
+ + "\t\t\t\t\"type\":\"geo_point\"\n"
+ + "\t\t\t},\n"
+ + "\t\t\t\"description\":{\n"
+ + "\t\t\t\t\"type\":\"text\"\n"
+ + "\t\t\t}\n"
+ + "\t\t}\n"
+ + "\t}\n"
+ + "}";
}
public static String getEmployeeNestedTypeIndexMapping() {
- return "{\n" +
- " \"mappings\": {\n" +
- " \"properties\": {\n" +
- " \"comments\": {\n" +
- " \"type\": \"nested\",\n" +
- " \"properties\": {\n" +
- " \"date\": {\n" +
- " \"type\": \"date\"\n" +
- " },\n" +
- " \"likes\": {\n" +
- " \"type\": \"long\"\n" +
- " },\n" +
- " \"message\": {\n" +
- " \"type\": \"text\",\n" +
- " \"fields\": {\n" +
- " \"keyword\": {\n" +
- " \"type\": \"keyword\",\n" +
- " \"ignore_above\": 256\n" +
- " }\n" +
- " }\n" +
- " }\n" +
- " }\n" +
- " },\n" +
- " \"id\": {\n" +
- " \"type\": \"long\"\n" +
- " },\n" +
- " \"name\": {\n" +
- " \"type\": \"text\",\n" +
- " \"fields\": {\n" +
- " \"keyword\": {\n" +
- " \"type\": \"keyword\",\n" +
- " \"ignore_above\": 256\n" +
- " }\n" +
- " }\n" +
- " },\n" +
- " \"projects\": {\n" +
- " \"type\": \"nested\",\n" +
- " \"properties\": {\n" +
- " \"address\": {\n" +
- " \"type\": \"nested\",\n" +
- " \"properties\": {\n" +
- " \"city\": {\n" +
- " \"type\": \"text\",\n" +
- " \"fields\": {\n" +
- " \"keyword\": {\n" +
- " \"type\": \"keyword\",\n" +
- " \"ignore_above\": 256\n" +
- " }\n" +
- " }\n" +
- " },\n" +
- " \"state\": {\n" +
- " \"type\": \"text\",\n" +
- " \"fields\": {\n" +
- " \"keyword\": {\n" +
- " \"type\": \"keyword\",\n" +
- " \"ignore_above\": 256\n" +
- " }\n" +
- " }\n" +
- " }\n" +
- " }\n" +
- " },\n" +
- " \"name\": {\n" +
- " \"type\": \"text\",\n" +
- " \"fields\": {\n" +
- " \"keyword\": {\n" +
- " \"type\": \"keyword\"\n" +
- " }\n" +
- " },\n" +
- " \"fielddata\": true\n" +
- " },\n" +
- " \"started_year\": {\n" +
- " \"type\": \"long\"\n" +
- " }\n" +
- " }\n" +
- " },\n" +
- " \"title\": {\n" +
- " \"type\": \"text\",\n" +
- " \"fields\": {\n" +
- " \"keyword\": {\n" +
- " \"type\": \"keyword\",\n" +
- " \"ignore_above\": 256\n" +
- " }\n" +
- " }\n" +
- " }\n" +
- " }\n" +
- " }\n" +
- "}\n";
+ return "{\n"
+ + " \"mappings\": {\n"
+ + " \"properties\": {\n"
+ + " \"comments\": {\n"
+ + " \"type\": \"nested\",\n"
+ + " \"properties\": {\n"
+ + " \"date\": {\n"
+ + " \"type\": \"date\"\n"
+ + " },\n"
+ + " \"likes\": {\n"
+ + " \"type\": \"long\"\n"
+ + " },\n"
+ + " \"message\": {\n"
+ + " \"type\": \"text\",\n"
+ + " \"fields\": {\n"
+ + " \"keyword\": {\n"
+ + " \"type\": \"keyword\",\n"
+ + " \"ignore_above\": 256\n"
+ + " }\n"
+ + " }\n"
+ + " }\n"
+ + " }\n"
+ + " },\n"
+ + " \"id\": {\n"
+ + " \"type\": \"long\"\n"
+ + " },\n"
+ + " \"name\": {\n"
+ + " \"type\": \"text\",\n"
+ + " \"fields\": {\n"
+ + " \"keyword\": {\n"
+ + " \"type\": \"keyword\",\n"
+ + " \"ignore_above\": 256\n"
+ + " }\n"
+ + " }\n"
+ + " },\n"
+ + " \"projects\": {\n"
+ + " \"type\": \"nested\",\n"
+ + " \"properties\": {\n"
+ + " \"address\": {\n"
+ + " \"type\": \"nested\",\n"
+ + " \"properties\": {\n"
+ + " \"city\": {\n"
+ + " \"type\": \"text\",\n"
+ + " \"fields\": {\n"
+ + " \"keyword\": {\n"
+ + " \"type\": \"keyword\",\n"
+ + " \"ignore_above\": 256\n"
+ + " }\n"
+ + " }\n"
+ + " },\n"
+ + " \"state\": {\n"
+ + " \"type\": \"text\",\n"
+ + " \"fields\": {\n"
+ + " \"keyword\": {\n"
+ + " \"type\": \"keyword\",\n"
+ + " \"ignore_above\": 256\n"
+ + " }\n"
+ + " }\n"
+ + " }\n"
+ + " }\n"
+ + " },\n"
+ + " \"name\": {\n"
+ + " \"type\": \"text\",\n"
+ + " \"fields\": {\n"
+ + " \"keyword\": {\n"
+ + " \"type\": \"keyword\"\n"
+ + " }\n"
+ + " },\n"
+ + " \"fielddata\": true\n"
+ + " },\n"
+ + " \"started_year\": {\n"
+ + " \"type\": \"long\"\n"
+ + " }\n"
+ + " }\n"
+ + " },\n"
+ + " \"title\": {\n"
+ + " \"type\": \"text\",\n"
+ + " \"fields\": {\n"
+ + " \"keyword\": {\n"
+ + " \"type\": \"keyword\",\n"
+ + " \"ignore_above\": 256\n"
+ + " }\n"
+ + " }\n"
+ + " }\n"
+ + " }\n"
+ + " }\n"
+ + "}\n";
}
-
public static String getNestedTypeIndexMapping() {
- return "{ \"mappings\": {\n" +
- " \"properties\": {\n" +
- " \"message\": {\n" +
- " \"type\": \"nested\",\n" +
- " \"properties\": {\n" +
- " \"info\": {\n" +
- " \"type\": \"keyword\",\n" +
- " \"index\": \"true\"\n" +
- " },\n" +
- " \"author\": {\n" +
- " \"type\": \"keyword\",\n" +
- " \"fields\": {\n" +
- " \"keyword\": {\n" +
- " \"type\": \"keyword\",\n" +
- " \"ignore_above\" : 256\n" +
- " }\n" +
- " },\n" +
- " \"index\": \"true\"\n" +
- " },\n" +
- " \"dayOfWeek\": {\n" +
- " \"type\": \"long\"\n" +
- " }\n" +
- " }\n" +
- " },\n" +
- " \"comment\": {\n" +
- " \"type\": \"nested\",\n" +
- " \"properties\": {\n" +
- " \"data\": {\n" +
- " \"type\": \"keyword\",\n" +
- " \"index\": \"true\"\n" +
- " },\n" +
- " \"likes\": {\n" +
- " \"type\": \"long\"\n" +
- " }\n" +
- " }\n" +
- " },\n" +
- " \"myNum\": {\n" +
- " \"type\": \"long\"\n" +
- " },\n" +
- " \"someField\": {\n" +
- " \"type\": \"keyword\",\n" +
- " \"index\": \"true\"\n" +
- " }\n" +
- " }\n" +
- " }\n" +
- " }}";
+ return "{ \"mappings\": {\n"
+ + " \"properties\": {\n"
+ + " \"message\": {\n"
+ + " \"type\": \"nested\",\n"
+ + " \"properties\": {\n"
+ + " \"info\": {\n"
+ + " \"type\": \"keyword\",\n"
+ + " \"index\": \"true\"\n"
+ + " },\n"
+ + " \"author\": {\n"
+ + " \"type\": \"keyword\",\n"
+ + " \"fields\": {\n"
+ + " \"keyword\": {\n"
+ + " \"type\": \"keyword\",\n"
+ + " \"ignore_above\" : 256\n"
+ + " }\n"
+ + " },\n"
+ + " \"index\": \"true\"\n"
+ + " },\n"
+ + " \"dayOfWeek\": {\n"
+ + " \"type\": \"long\"\n"
+ + " }\n"
+ + " }\n"
+ + " },\n"
+ + " \"comment\": {\n"
+ + " \"type\": \"nested\",\n"
+ + " \"properties\": {\n"
+ + " \"data\": {\n"
+ + " \"type\": \"keyword\",\n"
+ + " \"index\": \"true\"\n"
+ + " },\n"
+ + " \"likes\": {\n"
+ + " \"type\": \"long\"\n"
+ + " }\n"
+ + " }\n"
+ + " },\n"
+ + " \"myNum\": {\n"
+ + " \"type\": \"long\"\n"
+ + " },\n"
+ + " \"someField\": {\n"
+ + " \"type\": \"keyword\",\n"
+ + " \"index\": \"true\"\n"
+ + " }\n"
+ + " }\n"
+ + " }\n"
+ + " }}";
}
public static String getJoinTypeIndexMapping() {
- return "{\n" +
- " \"mappings\": {\n" +
- " \"properties\": {\n" +
- " \"join_field\": {\n" +
- " \"type\": \"join\",\n" +
- " \"relations\": {\n" +
- " \"parentType\": \"childrenType\"\n" +
- " }\n" +
- " },\n" +
- " \"parentTile\": {\n" +
- " \"index\": \"true\",\n" +
- " \"type\": \"keyword\"\n" +
- " },\n" +
- " \"dayOfWeek\": {\n" +
- " \"type\": \"long\"\n" +
- " },\n" +
- " \"author\": {\n" +
- " \"index\": \"true\",\n" +
- " \"type\": \"keyword\"\n" +
- " },\n" +
- " \"info\": {\n" +
- " \"index\": \"true\",\n" +
- " \"type\": \"keyword\"\n" +
- " }\n" +
- " }\n" +
- " }\n" +
- "}";
+ return "{\n"
+ + " \"mappings\": {\n"
+ + " \"properties\": {\n"
+ + " \"join_field\": {\n"
+ + " \"type\": \"join\",\n"
+ + " \"relations\": {\n"
+ + " \"parentType\": \"childrenType\"\n"
+ + " }\n"
+ + " },\n"
+ + " \"parentTile\": {\n"
+ + " \"index\": \"true\",\n"
+ + " \"type\": \"keyword\"\n"
+ + " },\n"
+ + " \"dayOfWeek\": {\n"
+ + " \"type\": \"long\"\n"
+ + " },\n"
+ + " \"author\": {\n"
+ + " \"index\": \"true\",\n"
+ + " \"type\": \"keyword\"\n"
+ + " },\n"
+ + " \"info\": {\n"
+ + " \"index\": \"true\",\n"
+ + " \"type\": \"keyword\"\n"
+ + " }\n"
+ + " }\n"
+ + " }\n"
+ + "}";
}
public static String getBankIndexMapping() {
- return "{\n" +
- " \"mappings\": {\n" +
- " \"properties\": {\n" +
- " \"account_number\": {\n" +
- " \"type\": \"long\"\n" +
- " },\n" +
- " \"address\": {\n" +
- " \"type\": \"text\"\n" +
- " },\n" +
- " \"age\": {\n" +
- " \"type\": \"integer\"\n" +
- " },\n" +
- " \"balance\": {\n" +
- " \"type\": \"long\"\n" +
- " },\n" +
- " \"birthdate\": {\n" +
- " \"type\": \"date\"\n" +
- " },\n" +
- " \"city\": {\n" +
- " \"type\": \"keyword\"\n" +
- " },\n" +
- " \"email\": {\n" +
- " \"type\": \"text\"\n" +
- " },\n" +
- " \"employer\": {\n" +
- " \"type\": \"text\"\n" +
- " },\n" +
- " \"firstname\": {\n" +
- " \"type\": \"text\"\n" +
- " },\n" +
- " \"gender\": {\n" +
- " \"type\": \"text\",\n" +
- " \"fielddata\": true\n" +
- " }," +
- " \"lastname\": {\n" +
- " \"type\": \"keyword\"\n" +
- " },\n" +
- " \"male\": {\n" +
- " \"type\": \"boolean\"\n" +
- " },\n" +
- " \"state\": {\n" +
- " \"type\": \"text\",\n" +
- " \"fields\": {\n" +
- " \"keyword\": {\n" +
- " \"type\": \"keyword\",\n" +
- " \"ignore_above\": 256\n" +
- " }\n" +
- " }\n" +
- " }\n" +
- " }\n" +
- " }\n" +
- "}";
+ return "{\n"
+ + " \"mappings\": {\n"
+ + " \"properties\": {\n"
+ + " \"account_number\": {\n"
+ + " \"type\": \"long\"\n"
+ + " },\n"
+ + " \"address\": {\n"
+ + " \"type\": \"text\"\n"
+ + " },\n"
+ + " \"age\": {\n"
+ + " \"type\": \"integer\"\n"
+ + " },\n"
+ + " \"balance\": {\n"
+ + " \"type\": \"long\"\n"
+ + " },\n"
+ + " \"birthdate\": {\n"
+ + " \"type\": \"date\"\n"
+ + " },\n"
+ + " \"city\": {\n"
+ + " \"type\": \"keyword\"\n"
+ + " },\n"
+ + " \"email\": {\n"
+ + " \"type\": \"text\"\n"
+ + " },\n"
+ + " \"employer\": {\n"
+ + " \"type\": \"text\"\n"
+ + " },\n"
+ + " \"firstname\": {\n"
+ + " \"type\": \"text\"\n"
+ + " },\n"
+ + " \"gender\": {\n"
+ + " \"type\": \"text\",\n"
+ + " \"fielddata\": true\n"
+ + " },"
+ + " \"lastname\": {\n"
+ + " \"type\": \"keyword\"\n"
+ + " },\n"
+ + " \"male\": {\n"
+ + " \"type\": \"boolean\"\n"
+ + " },\n"
+ + " \"state\": {\n"
+ + " \"type\": \"text\",\n"
+ + " \"fields\": {\n"
+ + " \"keyword\": {\n"
+ + " \"type\": \"keyword\",\n"
+ + " \"ignore_above\": 256\n"
+ + " }\n"
+ + " }\n"
+ + " }\n"
+ + " }\n"
+ + " }\n"
+ + "}";
}
public static String getBankWithNullValuesIndexMapping() {
- return "{\n" +
- " \"mappings\": {\n" +
- " \"properties\": {\n" +
- " \"account_number\": {\n" +
- " \"type\": \"long\"\n" +
- " },\n" +
- " \"address\": {\n" +
- " \"type\": \"text\"\n" +
- " },\n" +
- " \"age\": {\n" +
- " \"type\": \"integer\"\n" +
- " },\n" +
- " \"balance\": {\n" +
- " \"type\": \"long\"\n" +
- " },\n" +
- " \"gender\": {\n" +
- " \"type\": \"text\"\n" +
- " },\n" +
- " \"firstname\": {\n" +
- " \"type\": \"text\"\n" +
- " },\n" +
- " \"lastname\": {\n" +
- " \"type\": \"keyword\"\n" +
- " }\n" +
- " }\n" +
- " }\n" +
- "}";
+ return "{\n"
+ + " \"mappings\": {\n"
+ + " \"properties\": {\n"
+ + " \"account_number\": {\n"
+ + " \"type\": \"long\"\n"
+ + " },\n"
+ + " \"address\": {\n"
+ + " \"type\": \"text\"\n"
+ + " },\n"
+ + " \"age\": {\n"
+ + " \"type\": \"integer\"\n"
+ + " },\n"
+ + " \"balance\": {\n"
+ + " \"type\": \"long\"\n"
+ + " },\n"
+ + " \"gender\": {\n"
+ + " \"type\": \"text\"\n"
+ + " },\n"
+ + " \"firstname\": {\n"
+ + " \"type\": \"text\"\n"
+ + " },\n"
+ + " \"lastname\": {\n"
+ + " \"type\": \"keyword\"\n"
+ + " }\n"
+ + " }\n"
+ + " }\n"
+ + "}";
}
public static String getOrderIndexMapping() {
- return "{\n" +
- " \"mappings\": {\n" +
- " \"properties\": {\n" +
- " \"id\": {\n" +
- " \"type\": \"long\"\n" +
- " },\n" +
- " \"name\": {\n" +
- " \"type\": \"text\",\n" +
- " \"fields\": {\n" +
- " \"keyword\": {\n" +
- " \"type\": \"keyword\",\n" +
- " \"ignore_above\": 256\n" +
- " }\n" +
- " }\n" +
- " }\n" +
- " }\n" +
- " }\n" +
- "}";
+ return "{\n"
+ + " \"mappings\": {\n"
+ + " \"properties\": {\n"
+ + " \"id\": {\n"
+ + " \"type\": \"long\"\n"
+ + " },\n"
+ + " \"name\": {\n"
+ + " \"type\": \"text\",\n"
+ + " \"fields\": {\n"
+ + " \"keyword\": {\n"
+ + " \"type\": \"keyword\",\n"
+ + " \"ignore_above\": 256\n"
+ + " }\n"
+ + " }\n"
+ + " }\n"
+ + " }\n"
+ + " }\n"
+ + "}";
}
public static String getWeblogsIndexMapping() {
- return "{\n" +
- " \"mappings\": {\n" +
- " \"properties\": {\n" +
- " \"host\": {\n" +
- " \"type\": \"ip\"\n" +
- " },\n" +
- " \"method\": {\n" +
- " \"type\": \"text\"\n" +
- " },\n" +
- " \"url\": {\n" +
- " \"type\": \"text\"\n" +
- " },\n" +
- " \"response\": {\n" +
- " \"type\": \"text\"\n" +
- " },\n" +
- " \"bytes\": {\n" +
- " \"type\": \"text\"\n" +
- " }\n" +
- " }\n" +
- " }\n" +
- "}";
+ return "{\n"
+ + " \"mappings\": {\n"
+ + " \"properties\": {\n"
+ + " \"host\": {\n"
+ + " \"type\": \"ip\"\n"
+ + " },\n"
+ + " \"method\": {\n"
+ + " \"type\": \"text\"\n"
+ + " },\n"
+ + " \"url\": {\n"
+ + " \"type\": \"text\"\n"
+ + " },\n"
+ + " \"response\": {\n"
+ + " \"type\": \"text\"\n"
+ + " },\n"
+ + " \"bytes\": {\n"
+ + " \"type\": \"text\"\n"
+ + " }\n"
+ + " }\n"
+ + " }\n"
+ + "}";
}
public static String getDateIndexMapping() {
- return "{ \"mappings\": {" +
- " \"properties\": {\n" +
- " \"date_keyword\": {\n" +
- " \"type\": \"keyword\",\n" +
- " \"ignore_above\": 256\n" +
- " }" +
- " }" +
- " }" +
- "}";
+ return "{ \"mappings\": {"
+ + " \"properties\": {\n"
+ + " \"date_keyword\": {\n"
+ + " \"type\": \"keyword\",\n"
+ + " \"ignore_above\": 256\n"
+ + " }"
+ + " }"
+ + " }"
+ + "}";
}
public static String getDateTimeIndexMapping() {
- return "{" +
- " \"mappings\": {" +
- " \"properties\": {" +
- " \"birthday\": {" +
- " \"type\": \"date\"" +
- " }" +
- " }" +
- " }" +
- "}";
+ return "{"
+ + " \"mappings\": {"
+ + " \"properties\": {"
+ + " \"birthday\": {"
+ + " \"type\": \"date\""
+ + " }"
+ + " }"
+ + " }"
+ + "}";
}
public static String getNestedSimpleIndexMapping() {
- return "{" +
- " \"mappings\": {" +
- " \"properties\": {" +
- " \"address\": {" +
- " \"type\": \"nested\"," +
- " \"properties\": {" +
- " \"city\": {" +
- " \"type\": \"text\"," +
- " \"fields\": {" +
- " \"keyword\": {" +
- " \"type\": \"keyword\"," +
- " \"ignore_above\": 256" +
- " }" +
- " }" +
- " }," +
- " \"state\": {" +
- " \"type\": \"text\"," +
- " \"fields\": {" +
- " \"keyword\": {" +
- " \"type\": \"keyword\"," +
- " \"ignore_above\": 256" +
- " }" +
- " }" +
- " }" +
- " }" +
- " }," +
- " \"age\": {" +
- " \"type\": \"long\"" +
- " }," +
- " \"id\": {" +
- " \"type\": \"long\"" +
- " }," +
- " \"name\": {" +
- " \"type\": \"text\"," +
- " \"fields\": {" +
- " \"keyword\": {" +
- " \"type\": \"keyword\"," +
- " \"ignore_above\": 256" +
- " }" +
- " }" +
- " }" +
- " }" +
- " }" +
- "}";
+ return "{"
+ + " \"mappings\": {"
+ + " \"properties\": {"
+ + " \"address\": {"
+ + " \"type\": \"nested\","
+ + " \"properties\": {"
+ + " \"city\": {"
+ + " \"type\": \"text\","
+ + " \"fields\": {"
+ + " \"keyword\": {"
+ + " \"type\": \"keyword\","
+ + " \"ignore_above\": 256"
+ + " }"
+ + " }"
+ + " },"
+ + " \"state\": {"
+ + " \"type\": \"text\","
+ + " \"fields\": {"
+ + " \"keyword\": {"
+ + " \"type\": \"keyword\","
+ + " \"ignore_above\": 256"
+ + " }"
+ + " }"
+ + " }"
+ + " }"
+ + " },"
+ + " \"age\": {"
+ + " \"type\": \"long\""
+ + " },"
+ + " \"id\": {"
+ + " \"type\": \"long\""
+ + " },"
+ + " \"name\": {"
+ + " \"type\": \"text\","
+ + " \"fields\": {"
+ + " \"keyword\": {"
+ + " \"type\": \"keyword\","
+ + " \"ignore_above\": 256"
+ + " }"
+ + " }"
+ + " }"
+ + " }"
+ + " }"
+ + "}";
}
public static void loadBulk(Client client, String jsonPath, String defaultIndex)
@@ -698,8 +698,8 @@ public static void loadBulk(Client client, String jsonPath, String defaultIndex)
BulkRequest bulkRequest = new BulkRequest();
try (final InputStream stream = new FileInputStream(absJsonPath);
- final Reader streamReader = new InputStreamReader(stream, StandardCharsets.UTF_8);
- final BufferedReader br = new BufferedReader(streamReader)) {
+ final Reader streamReader = new InputStreamReader(stream, StandardCharsets.UTF_8);
+ final BufferedReader br = new BufferedReader(streamReader)) {
while (true) {
@@ -728,8 +728,11 @@ public static void loadBulk(Client client, String jsonPath, String defaultIndex)
BulkResponse bulkResponse = client.bulk(bulkRequest).actionGet();
if (bulkResponse.hasFailures()) {
- throw new Exception("Failed to load test data into index " + defaultIndex + ", " +
- bulkResponse.buildFailureMessage());
+ throw new Exception(
+ "Failed to load test data into index "
+ + defaultIndex
+ + ", "
+ + bulkResponse.buildFailureMessage());
}
System.out.println(bulkResponse.getItems().length + " documents loaded.");
// ensure the documents are searchable
@@ -755,8 +758,8 @@ public static String getResponseBody(Response response, boolean retainNewLines)
final StringBuilder sb = new StringBuilder();
try (final InputStream is = response.getEntity().getContent();
- final BufferedReader br = new BufferedReader(
- new InputStreamReader(is, StandardCharsets.UTF_8))) {
+ final BufferedReader br =
+ new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
String line;
while ((line = br.readLine()) != null) {
@@ -769,15 +772,14 @@ public static String getResponseBody(Response response, boolean retainNewLines)
return sb.toString();
}
- public static String fileToString(final String filePathFromProjectRoot,
- final boolean removeNewLines)
- throws IOException {
+ public static String fileToString(
+ final String filePathFromProjectRoot, final boolean removeNewLines) throws IOException {
final String absolutePath = getResourceFilePath(filePathFromProjectRoot);
try (final InputStream stream = new FileInputStream(absolutePath);
- final Reader streamReader = new InputStreamReader(stream, StandardCharsets.UTF_8);
- final BufferedReader br = new BufferedReader(streamReader)) {
+ final Reader streamReader = new InputStreamReader(stream, StandardCharsets.UTF_8);
+ final BufferedReader br = new BufferedReader(streamReader)) {
final StringBuilder stringBuilder = new StringBuilder();
String line = br.readLine();
@@ -831,36 +833,41 @@ public static List> getPermutations(final List items) {
}
final String currentItem = items.get(i);
- result.addAll(getPermutations(smallerSet).stream().map(smallerSetPermutation -> {
- final List permutation = new ArrayList<>();
- permutation.add(currentItem);
- permutation.addAll(smallerSetPermutation);
- return permutation;
- }).collect(Collectors.toCollection(LinkedList::new)));
+ result.addAll(
+ getPermutations(smallerSet).stream()
+ .map(
+ smallerSetPermutation -> {
+ final List permutation = new ArrayList<>();
+ permutation.add(currentItem);
+ permutation.addAll(smallerSetPermutation);
+ return permutation;
+ })
+ .collect(Collectors.toCollection(LinkedList::new)));
}
return result;
}
public static void verifyIsV1Cursor(JSONObject response) {
- var legacyCursorPrefixes = Arrays.stream(CursorType.values())
- .map(c -> c.getId() + ":").collect(Collectors.toList());
+ var legacyCursorPrefixes =
+ Arrays.stream(CursorType.values()).map(c -> c.getId() + ":").collect(Collectors.toList());
verifyCursor(response, legacyCursorPrefixes, "v1");
}
-
public static void verifyIsV2Cursor(JSONObject response) {
verifyCursor(response, List.of(CURSOR_PREFIX), "v2");
}
- private static void verifyCursor(JSONObject response, List validCursorPrefix, String engineName) {
- assertTrue("'cursor' property does not exist", response.has("cursor"));
+ private static void verifyCursor(
+ JSONObject response, List validCursorPrefix, String engineName) {
+ assertTrue("'cursor' property does not exist", response.has("cursor"));
- var cursor = response.getString("cursor");
- assertFalse("'cursor' property is empty", cursor.isEmpty());
- assertTrue("The cursor '" + cursor.substring(0, 50) + "...' is not from " + engineName + " engine.",
- validCursorPrefix.stream().anyMatch(cursor::startsWith));
- }
+ var cursor = response.getString("cursor");
+ assertFalse("'cursor' property is empty", cursor.isEmpty());
+ assertTrue(
+ "The cursor '" + cursor.substring(0, 50) + "...' is not from " + engineName + " engine.",
+ validCursorPrefix.stream().anyMatch(cursor::startsWith));
+ }
public static void verifyNoCursor(JSONObject response) {
assertTrue(!response.has("cursor"));