-
Notifications
You must be signed in to change notification settings - Fork 139
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
Support Array and ExprValue Parsing With Inner Hits #1737
Support Array and ExprValue Parsing With Inner Hits #1737
Conversation
644ef89
to
71147ff
Compare
Codecov Report
@@ Coverage Diff @@
## main #1737 +/- ##
=========================================
Coverage 97.29% 97.30%
- Complexity 4408 4432 +24
=========================================
Files 388 388
Lines 10944 10982 +38
Branches 774 782 +8
=========================================
+ Hits 10648 10686 +38
Misses 289 289
Partials 7 7
Flags with carried forward coverage won't be shown. Click here to find out more.
|
@@ -21,6 +21,14 @@ | |||
"ignore_above": 256 | |||
} | |||
} | |||
}, | |||
"moveInDate" : { |
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.
did we want to test this with a nested
type too?
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.
This is a inner object to the nested object address
. We have IT tests to test with the nested
function in NestedIT.java#L373-L400. Is this what you were thinking of testing?
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.
Yes. I think I was wondering if we had nested within nested.
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.
Yes we already have tests for nested in nested too.
NestedIT.java#L106-L118
opensearch/src/main/java/org/opensearch/sql/opensearch/response/OpenSearchResponse.java
Outdated
Show resolved
Hide resolved
JSONObject result = executeJdbcRequest(query); | ||
|
||
assertEquals(11, result.getInt("total")); | ||
verifyDataRows(result, |
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.
what would be the data type of nested(address.moveInDate), object or array?
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.
It would be of type object. address would be of type nested, I'll add the schema verification.
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.
i see. one more question.
some rows is JSONObject, some rows are JSONArray, how does JDBC handle it?
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.
In some cases this breaks JDBC, but there is no change in the expected output with this PR. An example of this would be in ObjectFieldSelectIT
where we do a select on an OBJECT
type array, and a NESTED
type array.
ObjectFieldSelectIT.java#L69-L93
people.json
people-mapping
When selecting on an array that is not of type NESTED
, the first value in the array is returned and is functional with JDBC. As shown by the query:
SELECT accounts FROM people;
While on the other hand the query that does a basic SELECT on an NESTED
type array returns the whole array which breaks JDBC.
Query:
SELECT projects FROM people;
A user can get around this by using the nested
function to flatten the response for a correct JDBC output.
...h/src/test/java/org/opensearch/sql/opensearch/data/value/OpenSearchExprValueFactoryTest.java
Show resolved
Hide resolved
5c97d43
) | ||
) | ||
), | ||
tupleValueWithArraySupport( |
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.
ignore my comments below.
what if the data is? the expected stringV is [["zz", "au"], ["ss"], ["z"]], right?
{ "stringV": ["z", ["s"], ["zz", "au"]] }
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.
If we execute on this:
tupleValueWithArraySupport("{"stringV": ["z", ["s"], ["zz", "au"]]}").get("stringV");
The resulting value is:
["z", ["s"], ["zz", "au"]]
In your example the order is reversed which is not the case. Does this answer your question?
Signed-off-by: forestmvey <forestv@bitquilltech.com>
Signed-off-by: forestmvey <forestv@bitquilltech.com>
Signed-off-by: forestmvey <forestv@bitquilltech.com>
0394fdd
to
5d657c6
Compare
} else if (content.isDouble()) { | ||
return parse(content, prefix, Optional.of(OpenSearchDataType.of(DOUBLE)), supportArrays); | ||
} else if (content.isNumber()) { | ||
return parse(content, prefix, Optional.of(OpenSearchDataType.of(INTEGER)), supportArrays); |
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.
If you are using something with type of SHORT
or BYTE
does it get cast/treated as an INTEGER
before this point or does it need to be supported?
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.
Treated as an integer. No need to cast or treat differently.
* Add support for Array and ExprValue Parsing With Inner Hits Signed-off-by: forestmvey <forestv@bitquilltech.com> * Adding schema validation for IT test, and another UT for nested arrays. Signed-off-by: forestmvey <forestv@bitquilltech.com> * Making handleAggregationResponse a private function. Signed-off-by: forestmvey <forestv@bitquilltech.com> --------- Signed-off-by: forestmvey <forestv@bitquilltech.com> (cherry picked from commit 9fbcf11)
* Add support for Array and ExprValue Parsing With Inner Hits Signed-off-by: forestmvey <forestv@bitquilltech.com> * Adding schema validation for IT test, and another UT for nested arrays. Signed-off-by: forestmvey <forestv@bitquilltech.com> * Making handleAggregationResponse a private function. Signed-off-by: forestmvey <forestv@bitquilltech.com> --------- Signed-off-by: forestmvey <forestv@bitquilltech.com> (cherry picked from commit 9fbcf11) Signed-off-by: forestmvey <forestv@bitquilltech.com>
* Add support for Array and ExprValue Parsing With Inner Hits Signed-off-by: forestmvey <forestv@bitquilltech.com> * Adding schema validation for IT test, and another UT for nested arrays. Signed-off-by: forestmvey <forestv@bitquilltech.com> * Making handleAggregationResponse a private function. Signed-off-by: forestmvey <forestv@bitquilltech.com> --------- Signed-off-by: forestmvey <forestv@bitquilltech.com> (cherry picked from commit 9fbcf11) Signed-off-by: forestmvey <forestv@bitquilltech.com>
* Add support for Array and ExprValue Parsing With Inner Hits * Adding schema validation for IT test, and another UT for nested arrays. * Making handleAggregationResponse a private function. --------- (cherry picked from commit 9fbcf11) Signed-off-by: forestmvey <forestv@bitquilltech.com> Co-authored-by: Forest Vey <forestv@bitquilltech.com>
Description
With the addition of the nested function support in the V2 engine the
inner_hits
portion of the OS response needs to be parsed for OS types. Previously arrays were not entirely parsed due to lack of support.Parsing Functionality
Parsing of each value in arrays needs to be supported for proper
nested
functionality. The following gives examples of the current response formats when parsing arrays.Object Type - Array Of Objects
Dataset:
"obj": [{"key": "val1"}, {"key": "val2"}]
SQL Query:
V1 Engine Response:
[{'key': 'val1'},{'key': 'val2'}]
V2 Engine Response:
{'key': 'val1'}
Nested Type - Array Of Objects
Dataset:
"obj": [{"key": "val1"}, {"key": "val2"}]
SQL Query:
V1 and V2 Engine Response:
[{'key': 'val1'},{'key': 'val2'}]
Array Of Values (Nested only supports objects and not arrays of values):
Dataset:
"obj": ["val1", "val2"]
SQL Query:
V1 Engine Response:
['val1','val2']
V2 Engine Response:
{'val1'}
Issues Resolved
Issue: 1686
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.