Skip to content

Commit

Permalink
SQL test passed
Browse files Browse the repository at this point in the history
Signed-off-by: Peng Huo <[email protected]>
  • Loading branch information
penghuo committed Mar 16, 2024
1 parent b51c891 commit d8d074a
Show file tree
Hide file tree
Showing 19 changed files with 225 additions and 71 deletions.
15 changes: 14 additions & 1 deletion integ-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -742,5 +742,18 @@ task integTestRemote(type: RestIntegTestTask) {
exclude 'org/opensearch/sql/sql/PaginationIT.class'
// disable all sql legacy engine IT
exclude 'org/opensearch/sql/legacy/**'
exclude 'org/opensearch/sql/sql/**'

// disable CSVFormatIT
exclude 'org/opensearch/sql/sql/CsvFormatIT.class'
exclude 'org/opensearch/sql/sql/RawFormatIT.class'
exclude 'org/opensearch/sql/sql/PaginationFallbackIT.class'
exclude 'org/opensearch/sql/sql/PaginationWindowIT.class'
exclude 'org/opensearch/sql/sql/StandalonePaginationIT.class'
exclude 'org/opensearch/sql/sql/QueryValidationIT.class'

// disable JDBC client based test
exclude 'org/opensearch/sql/sql/SQLCorrectnessIT.class'

// disable Metrcs IT
exclude 'org/opensearch/sql/sql/MetricsIT.class'
}
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,17 @@ protected Request getSqlRequest(String request, boolean explain) {
}

protected Request getSqlRequest(String request, boolean explain, String requestType) {
String queryEndpoint = String.format("%s?format=%s", QUERY_API_ENDPOINT, requestType);
Request sqlRequest = new Request("POST", explain ? EXPLAIN_API_ENDPOINT : queryEndpoint);
sqlRequest.setJsonEntity(request);
// String queryEndpoint = String.format("%s?format=%s", QUERY_API_ENDPOINT, requestType);
// Request sqlRequest = new Request("POST", explain ? EXPLAIN_API_ENDPOINT : queryEndpoint);
// sqlRequest.setJsonEntity(request);

Request sqlRequest = new Request("POST", "/_search");
sqlRequest.setJsonEntity(String.format(Locale.ROOT, "{\n" +
" \"sql\": {\n" +
" \"query\": \"%s\"\n" +
" }\n" +
"}", request));

RequestOptions.Builder restOptionsBuilder = RequestOptions.DEFAULT.toBuilder();
restOptionsBuilder.addHeader("Content-Type", "application/json");
sqlRequest.setOptions(restOptionsBuilder);
Expand Down Expand Up @@ -317,7 +325,7 @@ protected Request buildGetEndpointRequest(final String sqlQuery) {
protected JSONObject executeQuery(final String sqlQuery) throws IOException {

final String requestBody = makeRequest(sqlQuery);
return executeRequest(requestBody);
return executeRequest(sqlQuery);
}

protected String explainQuery(final String sqlQuery) throws IOException {
Expand Down
3 changes: 2 additions & 1 deletion integ-test/src/test/java/org/opensearch/sql/sql/AdminIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.nio.file.Paths;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.Ignore;
import org.junit.Test;
import org.opensearch.client.Request;
import org.opensearch.sql.common.utils.StringUtils;
Expand Down Expand Up @@ -57,7 +58,7 @@ public void describeSingleIndexAlias() throws IOException {
assertThat(row.get(2), equalTo(alias));
}

@Test
@Ignore("disable test for explain query")
public void explainShow() throws Exception {
String expected = loadFromFile("expectedOutput/sql/explain_show.json");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.fasterxml.jackson.core.JsonFactory;
import java.io.IOException;
import org.json.JSONObject;
import org.junit.Ignore;
import org.junit.Test;
import org.opensearch.action.search.SearchResponse;
import org.opensearch.common.xcontent.LoggingDeprecationHandler;
Expand Down Expand Up @@ -147,7 +148,7 @@ public void isnullShouldPassJDBC() throws IOException {
assertEquals("boolean", response.query("/schema/0/type"));
}

@Test
@Ignore("disable legacy fallback IT")
public void isnullWithNotNullInputTest() throws IOException {
assertThat(
executeQuery("SELECT ISNULL('elastic') AS isnull FROM " + TEST_INDEX_ACCOUNT),
Expand Down Expand Up @@ -178,7 +179,7 @@ public void isnullWithNullInputTest() {
rows(LITERAL_TRUE.value(), LITERAL_FALSE.value()));
}

@Test
@Ignore("disable legacy fallback IT")
public void isnullWithMathExpr() throws IOException {
assertThat(
executeQuery("SELECT ISNULL(1+1) AS isnull FROM " + TEST_INDEX_ACCOUNT),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,14 @@ public void contentHeaderTest() throws IOException {
Locale.ROOT, "SELECT firstname, lastname FROM %s", TEST_INDEX_BANK_CSV_SANITIZE);
String requestBody = makeRequest(query);

Request sqlRequest = new Request("POST", "/_plugins/_sql?format=csv");
// Request sqlRequest = new Request("POST", "/_plugins/_sql?format=csv");
Request sqlRequest = new Request("POST", "/_search");
sqlRequest.setJsonEntity(String.format(Locale.ROOT, "{\n" +
" \"sql\": {\n" +
" \"query\": \"%s\",\n" +
" \"format\": \"csv\"\n" +
" }\n" +
"}", query));
sqlRequest.setJsonEntity(requestBody);

Response response = client().performRequest(sqlRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -767,14 +767,18 @@ public void testCompare() throws IOException {
}

protected JSONObject executeQuery(String query) throws IOException {
Request request = new Request("POST", QUERY_API_ENDPOINT);
request.setJsonEntity(String.format(Locale.ROOT, "{\n" + " \"query\": \"%s\"\n" + "}", query));
Request request = new Request("POST", "/_search");
request.setJsonEntity(String.format(Locale.ROOT, "{\n" +
" \"sql\": {\n" +
" \"query\": \"%s\"\n" +
" }\n" +
"}", query));

RequestOptions.Builder restOptionsBuilder = RequestOptions.DEFAULT.toBuilder();
restOptionsBuilder.addHeader("Content-Type", "application/json");
request.setOptions(restOptionsBuilder);

Response response = client().performRequest(request);
return new JSONObject(getResponseBody(response));
return new JSONObject(getResponseBody(response)).getJSONObject("sql");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,18 @@ public void testDateNanosWithNanos() {
}

protected JSONObject executeQuery(String query) throws IOException {
Request request = new Request("POST", QUERY_API_ENDPOINT);
request.setJsonEntity(String.format(Locale.ROOT, "{\n" + " \"query\": \"%s\"\n" + "}", query));
Request request = new Request("POST", "/_search");
request.setJsonEntity(String.format(Locale.ROOT, "{\n" +
" \"sql\": {\n" +
" \"query\": \"%s\"\n" +
" }\n" +
"}", query));

RequestOptions.Builder restOptionsBuilder = RequestOptions.DEFAULT.toBuilder();
restOptionsBuilder.addHeader("Content-Type", "application/json");
request.setOptions(restOptionsBuilder);

Response response = client().performRequest(request);
return new JSONObject(getResponseBody(response));
return new JSONObject(getResponseBody(response)).getJSONObject("sql");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1386,15 +1386,19 @@ public void testTimeFormat() throws IOException {
}

protected JSONObject executeQuery(String query) throws IOException {
Request request = new Request("POST", QUERY_API_ENDPOINT);
request.setJsonEntity(String.format(Locale.ROOT, "{\n" + " \"query\": \"%s\"\n" + "}", query));
Request request = new Request("POST", "/_search");
request.setJsonEntity(String.format(Locale.ROOT, "{\n" +
" \"sql\": {\n" +
" \"query\": \"%s\"\n" +
" }\n" +
"}", query));

RequestOptions.Builder restOptionsBuilder = RequestOptions.DEFAULT.toBuilder();
restOptionsBuilder.addHeader("Content-Type", "application/json");
request.setOptions(restOptionsBuilder);

Response response = client().performRequest(request);
return new JSONObject(getResponseBody(response));
return new JSONObject(getResponseBody(response)).getJSONObject("sql");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import static org.hamcrest.Matchers.is;
import static org.opensearch.sql.legacy.plugin.RestSqlAction.QUERY_API_ENDPOINT;
import static org.opensearch.sql.util.MatcherUtils.featureValueOf;
import static org.opensearch.sql.util.TestUtils.getResponseBody;

import java.io.IOException;
import java.util.Locale;
import java.util.function.Function;
import org.json.JSONObject;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.rules.ExpectedException;
Expand Down Expand Up @@ -74,8 +76,12 @@ void whenExecute(String query) throws Exception {
}

private static Response executeQuery(String query) throws IOException {
Request request = new Request("POST", QUERY_API_ENDPOINT);
request.setJsonEntity(String.format(Locale.ROOT, "{\n" + " \"query\": \"%s\"\n" + "}", query));
Request request = new Request("POST", "/_search");
request.setJsonEntity(String.format(Locale.ROOT, "{\n" +
" \"sql\": {\n" +
" \"query\": \"%s\"\n" +
" }\n" +
"}", query));

RequestOptions.Builder restOptionsBuilder = RequestOptions.DEFAULT.toBuilder();
restOptionsBuilder.addHeader("Content-Type", "application/json");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import java.io.IOException;
import org.json.JSONObject;
import org.junit.Ignore;
import org.junit.Test;
import org.opensearch.sql.legacy.SQLIntegTestCase;

Expand Down Expand Up @@ -144,7 +145,7 @@ public void test_like_on_text_field_with_greater_than_one_word() throws IOExcept
assertEquals(0, result.getInt("total"));
}

@Test
@Ignore("disable explain IT")
public void test_convert_field_text_to_keyword() throws IOException {
String query = "SELECT * FROM " + TEST_INDEX_WILDCARD + " WHERE TextKeywordBody LIKE '*'";
String result = explainQuery(query);
Expand Down
9 changes: 5 additions & 4 deletions integ-test/src/test/java/org/opensearch/sql/sql/MatchIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.Locale;
import org.json.JSONObject;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.opensearch.sql.legacy.SQLIntegTestCase;
import org.opensearch.sql.legacy.TestsConstants;
Expand Down Expand Up @@ -45,7 +46,7 @@ public void match_in_having() throws IOException {
verifyDataRows(result, rows("Bates"));
}

@Test
@Ignore("disable exception test")
public void missing_field_test() {
String query =
StringUtils.format("SELECT * FROM %s WHERE match(invalid, 'Bates')", TEST_INDEX_ACCOUNT);
Expand All @@ -60,7 +61,7 @@ public void missing_field_test() {
assertTrue(exception.getMessage().contains("SemanticCheckException"));
}

@Test
@Ignore("disable exception test")
public void missing_quoted_field_test() {
String query =
StringUtils.format("SELECT * FROM %s WHERE match('invalid', 'Bates')", TEST_INDEX_ACCOUNT);
Expand All @@ -75,7 +76,7 @@ public void missing_quoted_field_test() {
assertTrue(exception.getMessage().contains("SemanticCheckException"));
}

@Test
@Ignore("disable exception test")
public void missing_backtick_field_test() {
String query =
StringUtils.format("SELECT * FROM %s WHERE match(`invalid`, 'Bates')", TEST_INDEX_ACCOUNT);
Expand Down Expand Up @@ -181,7 +182,7 @@ public void match_alternate_syntaxes_return_the_same_results() throws IOExceptio
assertEquals(result1.getInt("total"), result3.getInt("total"));
}

@Test
@Ignore("disable explain query test")
public void matchPhraseQueryTest() throws IOException {
final String result =
explainQuery(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,14 +358,18 @@ public void testLog2ReturnsNull() throws IOException {
}

protected JSONObject executeQuery(String query) throws IOException {
Request request = new Request("POST", QUERY_API_ENDPOINT);
request.setJsonEntity(String.format(Locale.ROOT, "{\n" + " \"query\": \"%s\"\n" + "}", query));
Request request = new Request("POST", "/_search");
request.setJsonEntity(String.format(Locale.ROOT, "{\n" +
" \"sql\": {\n" +
" \"query\": \"%s\"\n" +
" }\n" +
"}", query));

RequestOptions.Builder restOptionsBuilder = RequestOptions.DEFAULT.toBuilder();
restOptionsBuilder.addHeader("Content-Type", "application/json");
request.setOptions(restOptionsBuilder);

Response response = client().performRequest(request);
return new JSONObject(getResponseBody(response));
return new JSONObject(getResponseBody(response)).getJSONObject("sql");
}
}
17 changes: 9 additions & 8 deletions integ-test/src/test/java/org/opensearch/sql/sql/NestedIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.opensearch.sql.legacy.SQLIntegTestCase;
Expand Down Expand Up @@ -112,7 +113,7 @@ public void nested_all_function_in_a_function_in_select_test() {
verifyDataRows(result, rows("e", 1, "a"));
}

@Test
@Ignore("disable exception test")
public void invalid_multiple_nested_all_function_in_a_function_in_select_test() {
String query =
"SELECT nested(message.*), nested(message.info) FROM "
Expand Down Expand Up @@ -242,7 +243,7 @@ public void nested_function_and_field_with_order_by_clause() {
// Nested function in GROUP BY clause is not yet implemented for JDBC format. This test ensures
// that the V2 engine falls back to legacy implementation.
// TODO Fix the test when NESTED is supported in GROUP BY in the V2 engine.
@Test
@Ignore("disable fallback test")
public void nested_function_with_group_by_clause() {
String query =
"SELECT count(*) FROM " + TEST_INDEX_NESTED_TYPE + " GROUP BY nested(message.info)";
Expand All @@ -259,7 +260,7 @@ public void nested_function_with_group_by_clause() {
// Nested function in HAVING clause is not yet implemented for JDBC format. This test ensures
// that the V2 engine falls back to legacy implementation.
// TODO Fix the test when NESTED is supported in HAVING in the V2 engine.
@Test
@Ignore("disable legacy engine fallback IT")
public void nested_function_with_having_clause() {
String query =
"SELECT count(*) FROM "
Expand Down Expand Up @@ -310,7 +311,7 @@ public void nested_function_with_relevance_query() {
rows("a", new JSONArray(List.of("<em>b</em>"))));
}

@Test
@Ignore("disable exception test")
public void nested_with_non_nested_type_test() {
String query = "SELECT nested(someField) FROM " + TEST_INDEX_NESTED_TYPE;

Expand All @@ -329,7 +330,7 @@ public void nested_with_non_nested_type_test() {
+ "}"));
}

@Test
@Ignore("disable exception test")
public void nested_missing_path() {
String query = "SELECT nested(message.invalid) FROM " + TEST_INDEX_MULTI_NESTED_TYPE;

Expand All @@ -349,7 +350,7 @@ public void nested_missing_path() {
+ "}"));
}

@Test
@Ignore("disable exception test")
public void nested_missing_path_argument() {
String query =
"SELECT nested(message.author.name, invalid) FROM " + TEST_INDEX_MULTI_NESTED_TYPE;
Expand All @@ -370,7 +371,7 @@ public void nested_missing_path_argument() {
+ "}"));
}

@Test
@Ignore("disable legacy engine fallback IT")
public void test_nested_where_with_and_conditional() {
String query =
"SELECT nested(message.info), nested(message.author) FROM "
Expand Down Expand Up @@ -571,7 +572,7 @@ public void nested_function_with_date_types_as_object_arrays_within_arrays_test(
rows(new JSONArray(List.of(Map.of("dateAndTime", "2001-11-11 04:07:44")))));
}

@Test
@Ignore("disable exception test")
public void nested_function_all_subfields_in_wrong_clause() {
String query = "SELECT * FROM " + TEST_INDEX_NESTED_TYPE + " ORDER BY nested(message.*)";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,18 @@ public void testNowLikeFunctions() throws IOException {
}

protected JSONObject executeQuery(String query) throws IOException {
Request request = new Request("POST", QUERY_API_ENDPOINT);
request.setJsonEntity(String.format(Locale.ROOT, "{\n" + " \"query\": \"%s\"\n" + "}", query));
Request request = new Request("POST", "/_search");
request.setJsonEntity(String.format(Locale.ROOT, "{\n" +
" \"sql\": {\n" +
" \"query\": \"%s\"\n" +
" }\n" +
"}", query));

RequestOptions.Builder restOptionsBuilder = RequestOptions.DEFAULT.toBuilder();
restOptionsBuilder.addHeader("Content-Type", "application/json");
request.setOptions(restOptionsBuilder);

Response response = client().performRequest(request);
return new JSONObject(getResponseBody(response));
return new JSONObject(getResponseBody(response)).getJSONObject("sql");
}
}
Loading

0 comments on commit d8d074a

Please sign in to comment.