Array values are preserved (#1300)#3095
Conversation
Signed-off-by: Norman Jordan <norman.jordan@improving.com>
|
I am still working on the code for making this configurable. The idea is to have a query parameter named If |
penghuo
left a comment
There was a problem hiding this comment.
- 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.
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.
Removed the comment.
Signed-off-by: Norman Jordan <norman.jordan@improving.com>
Signed-off-by: Norman Jordan <norman.jordan@improving.com>
penghuo
left a comment
There was a problem hiding this comment.
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 <norman.jordan@improving.com>
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. |
| 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.
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.
maybe another option is to create OpenSearchExprValueFactory in request builder and pass it to request? In case factory needs more settings passed in future?
...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.
nit: we could keep original constructor which means fieldTypeTolerance=true, it could avoid unnecessary UT chagne.
There was a problem hiding this comment.
+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.
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
dai-chen
left a comment
There was a problem hiding this comment.
Please update documentation: https://github.com/opensearch-project/sql/blob/main/docs/user/admin/settings.rst
| 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.
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
| TOP_PATH, | ||
| Optional.of(STRUCT), | ||
| supportArrays); | ||
| fieldTypeTolerance || supportArrays); |
There was a problem hiding this comment.
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.
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 <norman.jordan@improving.com>
| 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); |
Signed-off-by: Norman Jordan <norman.jordan@improving.com>
penghuo
left a comment
There was a problem hiding this comment.
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.xThen, create a pull request where the |
…ect#3095) (opensearch-project#3120) Signed-off-by: Norman Jordan <norman.jordan@improving.com> (cherry picked from commit e109417) Co-authored-by: normanj-bitquill <78755797+normanj-bitquill@users.noreply.github.com>
…ect#3095) (opensearch-project#3120) Signed-off-by: Norman Jordan <norman.jordan@improving.com> (cherry picked from commit e109417) Co-authored-by: normanj-bitquill <78755797+normanj-bitquill@users.noreply.github.com> Signed-off-by: Louis Chu <clingzhi@amazon.com>
…ect#3095) (opensearch-project#3120) Signed-off-by: Norman Jordan <norman.jordan@improving.com> (cherry picked from commit e109417) Co-authored-by: normanj-bitquill <78755797+normanj-bitquill@users.noreply.github.com> Signed-off-by: Louis Chu <clingzhi@amazon.com>
…ect#3095) (opensearch-project#3120) Signed-off-by: Norman Jordan <norman.jordan@improving.com> (cherry picked from commit e109417) Co-authored-by: normanj-bitquill <78755797+normanj-bitquill@users.noreply.github.com> Signed-off-by: Louis Chu <clingzhi@amazon.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 <78755797+normanj-bitquill@users.noreply.github.com>
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.