-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support JOIN query on object field with unexpanded name (#1229)
* Resolve sub object field in search hit source Signed-off-by: Chen Dai <[email protected]> * Rename to unexpanded object Signed-off-by: Chen Dai <[email protected]> * Update IT with where condition Signed-off-by: Chen Dai <[email protected]> * Fix test index mapping Signed-off-by: Chen Dai <[email protected]> Signed-off-by: Chen Dai <[email protected]> (cherry picked from commit 151f4cc)
- Loading branch information
1 parent
31f55ca
commit e8575fd
Showing
8 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
27 changes: 27 additions & 0 deletions
27
integ-test/src/test/resources/indexDefinitions/unexpanded_object_index_mapping.json
This file contains 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,27 @@ | ||
{ | ||
"mappings": { | ||
"properties": { | ||
"id": { | ||
"properties": { | ||
"serial": { | ||
"type": "integer" | ||
} | ||
} | ||
}, | ||
"attributes": { | ||
"properties": { | ||
"hardware": { | ||
"properties": { | ||
"correlate_id": { | ||
"type": "integer" | ||
}, | ||
"platform": { | ||
"type": "keyword" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains 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,8 @@ | ||
{"index":{"_id":"1"}} | ||
{"id.serial" : 1 , "attributes.hardware.correlate_id": 3, "attributes.hardware.platform": "Linux"} | ||
{"index":{"_id":"2"}} | ||
{"id.serial" : 2 , "attributes.hardware.correlate_id": 3, "attributes.hardware.platform": "Windows"} | ||
{"index":{"_id":"3"}} | ||
{"id.serial" : 3 , "attributes.hardware.correlate_id": 3, "attributes.hardware.platform": "Linux"} | ||
{"index":{"_id":"4"}} | ||
{"id.serial" : 4 , "attributes.hardware.correlate_id": 100, "attributes.hardware.platform": "Linux"} |
This file contains 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
65 changes: 65 additions & 0 deletions
65
...t/java/org/opensearch/sql/legacy/query/planner/physical/node/scroll/SearchHitRowTest.java
This file contains 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,65 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.sql.legacy.query.planner.physical.node.scroll; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.opensearch.sql.legacy.query.planner.physical.Row.RowKey; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import org.junit.Test; | ||
import org.opensearch.common.bytes.BytesArray; | ||
import org.opensearch.search.SearchHit; | ||
|
||
public class SearchHitRowTest { | ||
|
||
@Test | ||
public void testKeyWithObjectField() { | ||
SearchHit hit = new SearchHit(1); | ||
hit.sourceRef(new BytesArray("{\"id\": {\"serial\": 3}}")); | ||
SearchHitRow row = new SearchHitRow(hit, "a"); | ||
RowKey key = row.key(new String[]{"id.serial"}); | ||
|
||
Object[] data = key.keys(); | ||
assertEquals(1, data.length); | ||
assertEquals(3, data[0]); | ||
} | ||
|
||
@Test | ||
public void testKeyWithUnexpandedObjectField() { | ||
SearchHit hit = new SearchHit(1); | ||
hit.sourceRef(new BytesArray("{\"attributes.hardware.correlate_id\": 10}")); | ||
SearchHitRow row = new SearchHitRow(hit, "a"); | ||
RowKey key = row.key(new String[]{"attributes.hardware.correlate_id"}); | ||
|
||
Object[] data = key.keys(); | ||
assertEquals(1, data.length); | ||
assertEquals(10, data[0]); | ||
} | ||
|
||
@Test | ||
public void testRetainWithObjectField() { | ||
SearchHit hit = new SearchHit(1); | ||
hit.sourceRef(new BytesArray("{\"a.id\": {\"serial\": 3}}")); | ||
SearchHitRow row = new SearchHitRow(hit, ""); | ||
row.retain(ImmutableMap.of("a.id.serial", "")); | ||
|
||
SearchHit expected = new SearchHit(1); | ||
expected.sourceRef(new BytesArray("{\"a.id\": {\"serial\": 3}}")); | ||
assertEquals(expected, row.data()); | ||
} | ||
|
||
@Test | ||
public void testRetainWithUnexpandedObjectField() { | ||
SearchHit hit = new SearchHit(1); | ||
hit.sourceRef(new BytesArray("{\"a.attributes.hardware.correlate_id\": 10}")); | ||
SearchHitRow row = new SearchHitRow(hit, ""); | ||
row.retain(ImmutableMap.of("a.attributes.hardware.correlate_id", "")); | ||
|
||
SearchHit expected = new SearchHit(1); | ||
expected.sourceRef(new BytesArray("{\"a.attributes.hardware.correlate_id\": 10}")); | ||
assertEquals(expected, row.data()); | ||
} | ||
} |