Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Support mvn build and integration-test for Elasticsearch 7.0.1 #51

Merged
merged 2 commits into from
May 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ afterEvaluate {
url 'https://opendistro.github.io/elasticsearch/downloads'
summary '''
SQL plugin for OpenDistro for Elasticsearch.
Reference documentation can be found at https://opendistro.github.io/elasticsearch/docs.
Reference documentation can be found at https://opendistro.github.io/for-elasticsearch-docs/.
'''.stripIndent().replace('\n', ' ').trim()
}

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.amazon.opendistroforelasticsearch</groupId>
<artifactId>opendistro-sql</artifactId>
<version>6.7.1.0</version>
<version>7.0.1.0</version>
<packaging>jar</packaging>
<description>Open Distro for Elasticsearch SQL</description>
<name>opendistro-sql</name>
Expand All @@ -27,7 +27,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<runSuite>**/MainTestSuite.class</runSuite>
<elasticsearch.plugin.name>opendistro-sql</elasticsearch.plugin.name>
<elasticsearch.version>6.7.1</elasticsearch.version>
<elasticsearch.version>7.0.1</elasticsearch.version>
<elasticsearch.plugin.classname>com.amazon.opendistroforelasticsearch.sql.plugin.SqlPlug</elasticsearch.plugin.classname>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ public static XContentBuilder hitsAsStringResultZeroCopy(List<SearchHit> results
/** Code copy from SearchHits */
private static void toXContent(XContentBuilder builder, Params params, List<SearchHit> hits, ElasticJoinExecutor executor) throws IOException {
builder.startObject(SearchHits.Fields.HITS);
builder.field(SearchHits.Fields.TOTAL, hits.size());
builder.field(SearchHits.Fields.TOTAL, ImmutableMap.of(
"value", hits.size(),
"relation", Relation.EQUAL_TO
));
builder.field(SearchHits.Fields.MAX_SCORE, 1.0f);
builder.field(SearchHits.Fields.HITS);
builder.startArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ private static Tuple<String, String> date_format(SQLExpr field, String pattern,

private static Tuple<String, String> dateFunctionTemplate(String methodName, SQLExpr field) {
String name = randomize(methodName);
return new Tuple<>(name, def(name, doc(field) + ".date." + methodName));
return new Tuple<>(name, def(name, doc(field) + ".value." + methodName));
arsen-es marked this conversation as resolved.
Show resolved Hide resolved
}

public static Tuple<String, String> add(SQLExpr a, SQLExpr b) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ public void testSubAggregations() throws Exception {
}
}

Assert.assertEquals(response.getHits().getTotalHits(), 1000);
Assert.assertEquals(response.getHits().getTotalHits().value, 1000);
Assert.assertEquals(response.getHits().getHits().length, 10);
}

Expand All @@ -581,7 +581,7 @@ public void testSimpleSubAggregations() throws Exception {
}
}

Assert.assertEquals(response.getHits().getTotalHits(), 1000);
Assert.assertEquals(response.getHits().getTotalHits().value, 1000);
Assert.assertEquals(response.getHits().getHits().length, 10);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,31 +50,31 @@ public class DateFormatTest {
@Test
public void equalTo() {
assertThat(
query(SELECT_FROM + "WHERE date_format(insert_time, 'YYYY-MM-dd', 'UTC') = '2014-08-17'"),
query(SELECT_FROM + "WHERE date_format(insert_time, 'yyyy-MM-dd', 'UTC') = '2014-08-17'"),
containsInAnyOrder("2014-08-17")
);
}

@Test
public void lessThan() {
assertThat(
query(SELECT_FROM + "WHERE date_format(insert_time, 'YYYY-MM-dd', 'UTC') < '2014-08-18'"),
query(SELECT_FROM + "WHERE date_format(insert_time, 'yyyy-MM-dd', 'UTC') < '2014-08-18'"),
containsInAnyOrder("2014-08-17")
);
}

@Test
public void lessThanOrEqualTo() {
assertThat(
query(SELECT_FROM + "WHERE date_format(insert_time, 'YYYY-MM-dd', 'UTC') <= '2014-08-18'"),
query(SELECT_FROM + "WHERE date_format(insert_time, 'yyyy-MM-dd', 'UTC') <= '2014-08-18' LIMIT 1000"),
containsInAnyOrder("2014-08-17", "2014-08-18")
);
}

@Test
public void greaterThan() {
assertThat(
query(SELECT_FROM + "WHERE date_format(insert_time, 'YYYY-MM-dd', 'UTC') > '2014-08-23'"),
query(SELECT_FROM + "WHERE date_format(insert_time, 'yyyy-MM-dd', 'UTC') > '2014-08-23'"),
containsInAnyOrder("2014-08-24")
);
}
Expand All @@ -86,7 +86,7 @@ public void greaterThan() {
@Test
public void greaterThanOrEqualTo() {
assertThat(
query(SELECT_FROM + "WHERE date_format(insert_time, 'YYYY-MM-dd', 'UTC') >= '2014-08-23' LIMIT 1000"),
query(SELECT_FROM + "WHERE date_format(insert_time, 'yyyy-MM-dd', 'UTC') >= '2014-08-23' LIMIT 2000"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you increase the limits ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return hits in ES 7.0 is different with ES 6.7. ES 7.0 return value doesn't include "2014-08-24" is limited 1000.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But is it the expected behavior? I am ok with updating the test queries as long as we know the test is checking the right thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is the expected behavior. In the test data set, there are 1424 records has insert_time 2014-08-23. With the limit 1000, in ES 6.7, the return hits include record with insert_time as 2014-08-23 and 2014-08-24. But in ES 7.0, with the limit 1000, the result only include insert_time 2014-08-23. I didn't find the doc which mention it, but it seems the ES 7.0 sort the output in order.

containsInAnyOrder("2014-08-23", "2014-08-24")
);
}
Expand All @@ -95,8 +95,8 @@ public void greaterThanOrEqualTo() {
public void and() {
assertThat(
query(SELECT_FROM +
"WHERE date_format(insert_time, 'YYYY-MM-dd', 'UTC') >= '2014-08-21' " +
"AND date_format(insert_time, 'YYYY-MM-dd', 'UTC') <= '2014-08-23' LIMIT 1000"),
"WHERE date_format(insert_time, 'yyyy-MM-dd', 'UTC') >= '2014-08-21' " +
"AND date_format(insert_time, 'yyyy-MM-dd', 'UTC') <= '2014-08-23' LIMIT 3000"),
containsInAnyOrder("2014-08-21", "2014-08-22", "2014-08-23")
);
}
Expand All @@ -105,8 +105,9 @@ public void and() {
public void or() {
assertThat(
query(SELECT_FROM +
"WHERE date_format(insert_time, 'YYYY-MM-dd', 'UTC') < '2014-08-18' " +
"OR date_format(insert_time, 'YYYY-MM-dd', 'UTC') > '2014-08-23'"),
"WHERE date_format(insert_time, 'yyyy-MM-dd', 'UTC') < '2014-08-18' " +
"OR date_format(insert_time, 'yyyy-MM-dd', 'UTC') > '2014-08-23'" +
"LIMIT 3000"),
containsInAnyOrder("2014-08-17", "2014-08-24")
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void deleteAllTest() throws SqlParseException, SQLFeatureNotSupportedExce
SearchRequestBuilder request = MainTestSuite.getClient().prepareSearch(TEST_INDEX_ACCOUNT_TEMP);
request.setTypes("temp_account");
SearchResponse response = request.setQuery(QueryBuilders.matchAllQuery()).get();
assertThat(response.getHits().getTotalHits(), equalTo(0L));
assertThat(response.getHits().getTotalHits().value, equalTo(0L));
}


Expand All @@ -64,7 +64,7 @@ public void deleteWithConditionTest() throws SqlParseException, SQLFeatureNotSup
SearchRequestBuilder request = MainTestSuite.getClient().prepareSearch(TEST_INDEX_PHRASE);
request.setTypes("phrase");
SearchResponse response = request.setQuery(QueryBuilders.matchAllQuery()).get();
assertThat(response.getHits().getTotalHits(), equalTo(5L));
assertThat(response.getHits().getTotalHits().value, equalTo(5L));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ public static void prepareOdbcIndex(){
"\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\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" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.amazon.opendistroforelasticsearch.sql.request.SqlRequest;
import com.amazon.opendistroforelasticsearch.sql.request.SqlRequestFactory;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.http.HttpChannel;
import org.elasticsearch.http.HttpRequest;
Expand All @@ -34,6 +35,7 @@

import java.sql.SQLFeatureNotSupportedException;

import static org.elasticsearch.rest.RestRequest.Method.POST;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.greaterThan;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -78,7 +80,9 @@ public void search() {
private SearchHits query(String request) {
try {
final HttpRequest httpRequest = mock(HttpRequest.class);
when (httpRequest.uri()).thenReturn("");
when(httpRequest.uri()).thenReturn("uri");
when(httpRequest.method()).thenReturn(POST);
when(httpRequest.content()).thenReturn(new BytesArray(request));

SqlRequest sqlRequest = SqlRequestFactory.getSqlRequest(RestRequest.request(NamedXContentRegistry.EMPTY, httpRequest, mock(HttpChannel.class)));

Expand Down
Loading