generated from amazon-archives/__template_Custom
-
Notifications
You must be signed in to change notification settings - Fork 181
Support merging object-type fields when fetching the schema from the index #3653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1d06008
merge object/array
xinyual 63f8cb9
simplified code
xinyual ffd11a5
apply spotless
xinyual a81a510
fix IT by adding fields
xinyual a617b00
revert to hashmap
xinyual 81754d2
filter one indices case
xinyual 70b01c4
add ut and merge rules
xinyual 95e576d
add benchmark test
xinyual 9e65b49
revert change
xinyual 87b28b2
refactor merge rules
xinyual 2cc1b8a
merge to main
xinyual 7a35a11
fix IT
xinyual File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...ava/org/opensearch/sql/expression/operator/predicate/MergeArrayAndObjectMapBenchmark.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.expression.operator.predicate; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import org.openjdk.jmh.annotations.Benchmark; | ||
| import org.opensearch.sql.opensearch.data.type.OpenSearchDataType; | ||
| import org.opensearch.sql.opensearch.request.system.OpenSearchDescribeIndexRequest; | ||
|
|
||
| public class MergeArrayAndObjectMapBenchmark { | ||
| private static final List<Map<String, OpenSearchDataType>> candidateMaps = prepareListOfMaps(120); | ||
|
|
||
| @Benchmark | ||
| public void testMerge() { | ||
| Map<String, OpenSearchDataType> finalResult = new HashMap<>(); | ||
| for (Map<String, OpenSearchDataType> map : candidateMaps) { | ||
| OpenSearchDescribeIndexRequest.mergeObjectAndArrayInsideMap(finalResult, map); | ||
| } | ||
| } | ||
|
|
||
| private static Map<String, OpenSearchDataType> prepareMap(int recursive, String prefix) { | ||
| Map<String, OpenSearchDataType> map = new HashMap<>(); | ||
| Map<String, Object> innerMap = prepareRecursiveMap(recursive, prefix); | ||
| map.put("name", OpenSearchDataType.of(OpenSearchDataType.MappingType.Object, innerMap)); | ||
| return map; | ||
| } | ||
|
|
||
| public static Map<String, Object> prepareRecursiveMap(int recursive, String prefix) { | ||
| Map<String, Object> innerMap = new LinkedHashMap<>(); | ||
| if (recursive == 0) { | ||
| innerMap.put("type", "string"); | ||
| } else { | ||
| innerMap.put("type", "object"); | ||
| innerMap.put( | ||
| "properties", | ||
| Map.of( | ||
| prefix + "_" + String.valueOf(recursive), | ||
| Map.of("type", "text"), | ||
| "recursive", | ||
| prepareRecursiveMap(recursive - 1, prefix))); | ||
| } | ||
| return innerMap; | ||
| } | ||
|
|
||
| private static List<Map<String, OpenSearchDataType>> prepareListOfMaps(int listNumber) { | ||
| List<Map<String, OpenSearchDataType>> list = new ArrayList<>(); | ||
| for (int i = 0; i < listNumber; i++) { | ||
| list.add(prepareMap(15, "prefix" + i)); | ||
| } | ||
| return list; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,9 +5,7 @@ | |
|
|
||
| package org.opensearch.sql.calcite.standalone; | ||
|
|
||
| import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_ACCOUNT; | ||
| import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_ALIAS; | ||
| import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_BANK; | ||
| import static org.opensearch.sql.legacy.TestsConstants.*; | ||
| import static org.opensearch.sql.util.MatcherUtils.rows; | ||
| import static org.opensearch.sql.util.MatcherUtils.schema; | ||
| import static org.opensearch.sql.util.MatcherUtils.verifyDataRows; | ||
|
|
@@ -38,6 +36,8 @@ public void init() throws IOException { | |
|
|
||
| loadIndex(Index.BANK); | ||
| loadIndex(Index.DATA_TYPE_ALIAS); | ||
| loadIndex(Index.MERGE_TEST_1); | ||
| loadIndex(Index.MERGE_TEST_2); | ||
|
Comment on lines
+39
to
+40
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. consider yamlRestIT, it does not required prepare mapping and data file, https://github.com/opensearch-project/sql/tree/main/integ-test/src/yamlRestTest/resources/rest-api-spec/test/issues. |
||
| } | ||
|
|
||
| @Test | ||
|
|
@@ -566,6 +566,30 @@ public void testMetaFieldAlias() { | |
| } | ||
|
|
||
| @Test | ||
| public void testFieldsMergedObject() { | ||
| JSONObject result = | ||
| executeQuery( | ||
| String.format( | ||
| "source=%s | fields machine.os1, machine.os2, machine_array.os1, " | ||
| + " machine_array.os2, machine_deep.attr1, machine_deep.attr2," | ||
| + " machine_deep.layer.os1, machine_deep.layer.os2", | ||
| TEST_INDEX_MERGE_TEST_WILDCARD)); | ||
| verifySchema( | ||
| result, | ||
| schema("machine.os1", "string"), | ||
| schema("machine.os2", "string"), | ||
| schema("machine_array.os1", "string"), | ||
| schema("machine_array.os2", "string"), | ||
| schema("machine_deep.attr1", "long"), | ||
| schema("machine_deep.attr2", "long"), | ||
| schema("machine_deep.layer.os1", "string"), | ||
| schema("machine_deep.layer.os2", "string")); | ||
| verifyDataRows( | ||
| result, | ||
| rows("linux", null, "linux", null, 1, null, "os1", null), | ||
| rows(null, "linux", null, "linux", null, 2, null, "os2")); | ||
| } | ||
|
|
||
| public void testNumericLiteral() { | ||
| JSONObject result = | ||
| executeQuery( | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
integ-test/src/test/resources/indexDefinitions/merge_test_1_mapping.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| { | ||
| "mappings": { | ||
| "properties": { | ||
| "machine": { | ||
| "properties": { | ||
| "os1": { | ||
| "type": "text" | ||
| }, | ||
| "ram1": { | ||
| "type": "long" | ||
| } | ||
| } | ||
| }, | ||
| "machine_deep": { | ||
| "properties": { | ||
| "attr1": { | ||
| "type": "long" | ||
| }, | ||
| "layer": { | ||
| "properties": { | ||
| "os1": { | ||
| "type": "text" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "machine_array": { | ||
| "type": "nested", | ||
| "properties": { | ||
| "os1": { | ||
| "type": "text" | ||
| }, | ||
| "ram1": { | ||
| "type": "long" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
41 changes: 41 additions & 0 deletions
41
integ-test/src/test/resources/indexDefinitions/merge_test_2_mapping.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| { | ||
| "mappings": { | ||
| "properties": { | ||
| "machine": { | ||
| "properties": { | ||
| "os2": { | ||
| "type": "text" | ||
| }, | ||
| "ram2": { | ||
| "type": "long" | ||
| } | ||
| } | ||
| }, | ||
| "machine_deep": { | ||
| "properties": { | ||
| "attr2": { | ||
| "type": "long" | ||
| }, | ||
| "layer": { | ||
| "properties": { | ||
| "os2": { | ||
| "type": "text" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "machine_array": { | ||
| "type": "nested", | ||
| "properties": { | ||
| "os2": { | ||
| "type": "text" | ||
| }, | ||
| "ram2": { | ||
| "type": "long" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| {"index":{"_id":"1"}} | ||
| {"machine": {"os1": "linux", "ram1": 120}, "machine_array": [{"os1": "linux", "ram1": 120}], "machine_deep": {"attr1": 1, "layer": {"os1": "os1"}}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| {"index": {}} | ||
| {"machine": {"os2": "linux", "ram2": 120}, "machine_array": [{"os2": "linux", "ram2": 120}],"machine_deep": {"attr2": 2, "layer": {"os2": "os2"}}} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mergeObjectAndArrayInsideMap not exist