-
Notifications
You must be signed in to change notification settings - Fork 141
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
Array values are preserved (#1300) #3095
Array values are preserved (#1300) #3095
Conversation
Signed-off-by: Norman Jordan <[email protected]>
I am still working on the code for making this configurable. The idea is to have a query parameter named If |
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.
- could u add setting
plugins.query.field_type_tolerance
. If the plugins.query.field_type_tolerance setting is set to true, the backend will return scalar data types with array datasets, allowing basic queries like SELECT * FROM tbl WHERE condition; however, using multi-value fields in aggregations, ORDER BY clauses, or expressions will result in exceptions. If the setting is false or does not exist, only the first element of an array is returned, maintaining the current behavior. - could u add exception if operator/expression does not support array value, for instance groupby.
@@ -81,7 +81,7 @@ public void testSelectObjectFieldOfArrayValuesItself() { | |||
JSONObject response = new JSONObject(query("SELECT accounts FROM %s")); | |||
|
|||
// Only the first element of the list of is returned. |
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.
remove comments
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.
Since the default behaviour is to only use the first element of an array, this comment is still valid.
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.
Removed the comment.
Signed-off-by: Norman Jordan <[email protected]>
Signed-off-by: Norman Jordan <[email protected]>
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.
Please update doc also https://github.com/opensearch-project/sql/blob/main/docs/user/admin/settings.rst
opensearch/src/main/java/org/opensearch/sql/opensearch/setting/OpenSearchSettings.java
Outdated
Show resolved
Hide resolved
opensearch/src/main/java/org/opensearch/sql/opensearch/response/OpenSearchResponse.java
Outdated
Show resolved
Hide resolved
opensearch/src/main/java/org/opensearch/sql/opensearch/request/OpenSearchQueryRequest.java
Outdated
Show resolved
Hide resolved
integ-test/src/test/resources/expectedOutput/ppl/explain_filter_agg_push.json
Outdated
Show resolved
Hide resolved
…ctory Signed-off-by: Norman Jordan <[email protected]>
ab02d1d
to
bd462c7
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3095 +/- ##
=========================================
Coverage 94.48% 94.49%
- Complexity 5416 5420 +4
=========================================
Files 528 528
Lines 15430 15449 +19
Branches 1023 1025 +2
=========================================
+ Hits 14579 14598 +19
Misses 804 804
Partials 47 47
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
@@ -151,7 +153,8 @@ public OpenSearchQueryRequest(StreamInput in, OpenSearchStorageEngine engine) th | |||
} | |||
|
|||
OpenSearchIndex index = (OpenSearchIndex) engine.getTable(null, indexName.toString()); | |||
exprValueFactory = new OpenSearchExprValueFactory(index.getFieldOpenSearchTypes()); | |||
exprValueFactory = | |||
new OpenSearchExprValueFactory(index.getFieldOpenSearchTypes(), fieldTypeTolerance); |
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.
Logic should similar to OpenSearchScrollRequest right? If yes, fieldTypeTolerance should not associate with OpenSearchQueryRequest.
OpenSearchIndex index = (OpenSearchIndex) engine.getTable(null, indexName.toString());
exprValueFactory =
new OpenSearchExprValueFactory(
index.getFieldOpenSearchTypes(), index.isFieldTypeTolerance());
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.
maybe another option is to create OpenSearchExprValueFactory
in request builder and pass it to request? In case factory needs more settings passed in future?
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.
Updated.
...earch/src/main/java/org/opensearch/sql/opensearch/data/value/OpenSearchExprValueFactory.java
Show resolved
Hide resolved
...h/src/test/java/org/opensearch/sql/opensearch/data/value/OpenSearchExprValueFactoryTest.java
Show resolved
Hide resolved
OpenSearchClient client, | ||
boolean fieldTypeTolerance, | ||
int maxResponseSize, | ||
OpenSearchRequest request) { |
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.
nit: we could keep original constructor which means fieldTypeTolerance=true, it could avoid unnecessary UT chagne.
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.
+1. I'm also curious if it even needs to be a parameter since nearly every refactor hardcodes it to true
and the false
case isn't even tested. What's the use case where we don't want this?
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.
Changed back, since this change is not actually needed.
opensearch/src/test/java/org/opensearch/sql/opensearch/response/OpenSearchResponseTest.java
Show resolved
Hide resolved
integ-test/src/test/java/org/opensearch/sql/legacy/ObjectFieldSelectIT.java
Show resolved
Hide resolved
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.
Please update documentation: https://github.com/opensearch-project/sql/blob/main/docs/user/admin/settings.rst
@@ -151,7 +153,8 @@ public OpenSearchQueryRequest(StreamInput in, OpenSearchStorageEngine engine) th | |||
} | |||
|
|||
OpenSearchIndex index = (OpenSearchIndex) engine.getTable(null, indexName.toString()); | |||
exprValueFactory = new OpenSearchExprValueFactory(index.getFieldOpenSearchTypes()); | |||
exprValueFactory = | |||
new OpenSearchExprValueFactory(index.getFieldOpenSearchTypes(), fieldTypeTolerance); |
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.
maybe another option is to create OpenSearchExprValueFactory
in request builder and pass it to request? In case factory needs more settings passed in future?
integ-test/src/test/java/org/opensearch/sql/ppl/StandaloneIT.java
Outdated
Show resolved
Hide resolved
@@ -164,7 +168,7 @@ public ExprValue construct(String jsonString, boolean supportArrays) { | |||
new OpenSearchJsonContent(OBJECT_MAPPER.readTree(jsonString)), | |||
TOP_PATH, | |||
Optional.of(STRUCT), | |||
supportArrays); | |||
fieldTypeTolerance || 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.
I'm thinking should we use fieldTypeTolerance
directly in parseArray
(not sure parseGeopoint
)? Because I think supportArrays
has its own meaning? Unless we change it and rename the argument?
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 also applies to geopoints and anything else that could be in an array. If fieldTypeTolerance
is not also applied to parseGeopoint
, then an array of geopoints would get reduced to only the first element.
* Cleaned up how the fieldTypeTolerance setting is accessed * Added an integration test for when fieldTypeTolerance is disabled Signed-off-by: Norman Jordan <[email protected]>
@@ -110,6 +110,7 @@ private OpenSearchRequest buildRequestWithPit( | |||
int size = requestedTotalSize; | |||
FetchSourceContext fetchSource = this.sourceBuilder.fetchSource(); | |||
List<String> includes = fetchSource != null ? Arrays.asList(fetchSource.includes()) : List.of(); | |||
boolean fieldTypeTolerance = settings.getSettingValue(Settings.Key.FIELD_TYPE_TOLERANCE); |
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.
unused field, remove 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.
Removed.
Signed-off-by: Norman Jordan <[email protected]>
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.
Thanks for the change!
Please update doc in following PR. https://github.com/opensearch-project/sql/blob/main/docs/user/admin/settings.rst
The backport to
To backport manually, run these commands in your terminal: # Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/sql/backport-2.x 2.x
# Navigate to the new working tree
pushd ../.worktrees/sql/backport-2.x
# Create a new branch
git switch --create backport/backport-3095-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 e109417bb3ce770fb54cfd7b231b8219a22ed46f
# Push it to GitHub
git push --set-upstream origin backport/backport-3095-to-2.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/sql/backport-2.x Then, create a pull request where the |
…ect#3095) Signed-off-by: Norman Jordan <[email protected]> (cherry picked from commit e109417)
…ect#3095) Signed-off-by: Norman Jordan <[email protected]> (cherry picked from commit e109417)
Signed-off-by: Norman Jordan <[email protected]> (cherry picked from commit e109417) Co-authored-by: normanj-bitquill <[email protected]>
…ect#3095) (opensearch-project#3120) Signed-off-by: Norman Jordan <[email protected]> (cherry picked from commit e109417) Co-authored-by: normanj-bitquill <[email protected]>
…ect#3095) (opensearch-project#3120) Signed-off-by: Norman Jordan <[email protected]> (cherry picked from commit e109417) Co-authored-by: normanj-bitquill <[email protected]> Signed-off-by: Louis Chu <[email protected]>
…ect#3095) (opensearch-project#3120) Signed-off-by: Norman Jordan <[email protected]> (cherry picked from commit e109417) Co-authored-by: normanj-bitquill <[email protected]> Signed-off-by: Louis Chu <[email protected]>
…ect#3095) (opensearch-project#3120) Signed-off-by: Norman Jordan <[email protected]> (cherry picked from commit e109417) Co-authored-by: normanj-bitquill <[email protected]> Signed-off-by: Louis Chu <[email protected]>
Signed-off-by: Norman Jordan <[email protected]> (cherry picked from commit e109417) Co-authored-by: normanj-bitquill <[email protected]> (cherry picked from commit 81577df) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
(cherry picked from commit e109417) (cherry picked from commit 81577df) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: normanj-bitquill <[email protected]>
Description
Preserve array values so that they are represented correctly in the result set with all nested values.
Related Issues
Resolves #1300
Check List
--signoff
.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.