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

Commit

Permalink
Merge branch 'nestedLimit-comparison-datecast' into enforceLimit-nest…
Browse files Browse the repository at this point in the history
…edSubProp
  • Loading branch information
cip999 authored and cip999 committed Aug 15, 2021
2 parents a17f901 + 4a70d84 commit b670e86
Show file tree
Hide file tree
Showing 7 changed files with 235 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ protected void init() throws Exception {
loadIndex(Index.PHRASE);
loadIndex(Index.GAME_OF_THRONES);
loadIndex(Index.NESTED);
loadIndex(Index.BOOKS_NESTED_WITH_SUBPROPERTIES);
}

@Override
Expand Down Expand Up @@ -518,6 +519,52 @@ public void fieldOrderOther() throws IOException {
testFieldOrder(expectedFields, expectedValues);
}

@Test
public void selectSubSubFieldOfNestedField() throws IOException {
JSONObject response = executeQuery(
String.format(Locale.ROOT, "SELECT nested(authors.info.name, authors), " +
"performance.revenue " +
"FROM %s", TestsConstants.TEST_INDEX_BOOKS));

List<String> fields = Arrays.asList("authors.info.name", "performance.revenue");
JSONArray dataRows = getDataRows(response);
assertContainsColumns(getSchema(response), fields);
assertContainsData(dataRows, fields);
assertEquals(3, dataRows.length());
}

@Test
public void selectMultipleNestedFields() throws IOException {
JSONObject response = executeQuery(
String.format(Locale.ROOT, "SELECT nested(authors.info.name, authors), " +
"nested(performance.sells.year) " +
"FROM %s", TestsConstants.TEST_INDEX_BOOKS));

List<String> fields = Arrays.asList("authors.info.name", "performance.sells.year");
JSONArray dataRows = getDataRows(response);
assertContainsColumns(getSchema(response), fields);
assertContainsData(dataRows, fields);
assertEquals(4, dataRows.length());
}

@Test
public void nestedFieldWithLimit() throws IOException {
JSONObject response = executeQuery(
String.format(Locale.ROOT, "SELECT nested(authors.info.name, authors) " +
"FROM %s LIMIT 1", TestsConstants.TEST_INDEX_BOOKS));
assertEquals(1, getDataRows(response).length());
}

@Test
public void multipleNestedFieldsWithLimit() throws IOException, InterruptedException {
JSONObject response = executeQuery(
String.format(Locale.ROOT, "SELECT nested(authors.info.name, authors), " +
"nested(performance.sells.year)" +
"FROM %s LIMIT 3", TestsConstants.TEST_INDEX_BOOKS));
assertEquals(3, getDataRows(response).length());
}


private void testFieldOrder(final String[] expectedFields, final Object[] expectedValues)
throws IOException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import static com.amazon.opendistroforelasticsearch.sql.legacy.TestUtils.getResponseBody;
import static com.amazon.opendistroforelasticsearch.sql.legacy.TestUtils.getStringIndexMapping;
import static com.amazon.opendistroforelasticsearch.sql.legacy.TestUtils.getWeblogsIndexMapping;
import static com.amazon.opendistroforelasticsearch.sql.legacy.TestUtils.getBooksIndexMapping;
import static com.amazon.opendistroforelasticsearch.sql.legacy.TestUtils.isIndexExist;
import static com.amazon.opendistroforelasticsearch.sql.legacy.TestUtils.loadDataByRestClient;
import static com.amazon.opendistroforelasticsearch.sql.legacy.plugin.RestSqlAction.CURSOR_CLOSE_ENDPOINT;
Expand Down Expand Up @@ -556,7 +557,11 @@ public enum Index {
DATA_TYPE_NONNUMERIC(TestsConstants.TEST_INDEX_DATATYPE_NONNUMERIC,
"_doc",
getDataTypeNonnumericIndexMapping(),
"src/test/resources/datatypes.json");
"src/test/resources/datatypes.json"),
BOOKS_NESTED_WITH_SUBPROPERTIES(TestsConstants.TEST_INDEX_BOOKS,
"nestedType",
getBooksIndexMapping(),
"src/test/resources/books.json");

private final String name;
private final String type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ public static String getDataTypeNonnumericIndexMapping() {
return getMappingFile(mappingFile);
}

public static String getBooksIndexMapping() {
String mappingFile = "books_index_mapping.json";
return getMappingFile(mappingFile);
}

public static void loadBulk(Client client, String jsonPath, String defaultIndex)
throws Exception {
System.out.println(String.format("Loading file %s into elasticsearch cluster", jsonPath));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class TestsConstants {
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_BOOKS = TEST_INDEX + "_nested_subproperties";

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";
Expand Down
4 changes: 4 additions & 0 deletions integ-test/src/test/resources/books.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{"index": {"_id": "1"}}
{"authors": [{"id": 8634, "info": {"name": "Andrea", "age": 22}}, {"id": 836, "info": {"name": "Carmen", "age": 19}}], "performance": {"revenue": 932.88, "sells": [{"year": 2018, "quantity": {"italy": 1000000, "abroad": 500000}}, {"year": 2020, "quantity": {"italy": 2001002, "abroad": 0}}]}}
{"index": {"_id": "2"}}
{"authors": [{"id": 8, "info": {"name": "Mark", "age": 80}}], "performance": {"revenue": 555.0, "sells": []}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"mappings": {
"properties": {
"authors": {
"type": "nested",
"properties": {
"id": {
"type": "long",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"info": {
"properties": {
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"age": {
"type": "long"
}
}
}
}
},
"performance": {
"properties": {
"revenue": {
"type": "double"
},
"sells": {
"type": "nested",
"properties": {
"year": {
"type": "long"
},
"quantity": {
"properties": {
"italy": {
"type": "long"
},
"abroad": {
"type": "long"
}
}
}
}
}
}
}
}
}
}
Loading

0 comments on commit b670e86

Please sign in to comment.