Skip to content
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

Merged

Conversation

normanj-bitquill
Copy link
Contributor

Description

Preserve array values so that they are represented correctly in the result set with all nested values.

Related Issues

Resolves #1300

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • New functionality has javadoc added.
  • New functionality has a user manual doc added.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

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.

Signed-off-by: Norman Jordan <[email protected]>
@normanj-bitquill
Copy link
Contributor Author

I am still working on the code for making this configurable. The idea is to have a query parameter named arrays that is optional. If it is included, the only valid value is preserve.

If arrays=preserve, then arrays returned from the OpenSearch engine can flow to the result set and include all of the nested values.

Copy link
Collaborator

@penghuo penghuo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 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.
  2. 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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove comments

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the comment.

Copy link
Collaborator

@penghuo penghuo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@normanj-bitquill normanj-bitquill force-pushed the issue-1300-array-passthrough branch from ab02d1d to bd462c7 Compare October 24, 2024 05:44
Copy link

codecov bot commented Oct 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.49%. Comparing base (e838e46) to head (bd462c7).
Report is 7 commits behind head on main.

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           
Flag Coverage Δ
sql-engine 94.49% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -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);
Copy link
Collaborator

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());

Copy link
Collaborator

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Comment on lines 54 to 57
OpenSearchClient client,
boolean fieldTypeTolerance,
int maxResponseSize,
OpenSearchRequest request) {
Copy link
Collaborator

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.

Copy link
Collaborator

@Swiddis Swiddis Oct 24, 2024

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?

Copy link
Contributor Author

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.

Copy link
Collaborator

@dai-chen dai-chen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -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);
Copy link
Collaborator

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?

@@ -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);
Copy link
Collaborator

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?

Copy link
Contributor Author

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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused field, remove it.

Copy link
Contributor Author

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]>
Copy link
Collaborator

@penghuo penghuo left a 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

@penghuo penghuo merged commit e109417 into opensearch-project:main Oct 24, 2024
14 of 15 checks passed
@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 128

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 base branch is 2.x and the compare/head branch is backport/backport-3095-to-2.x.

@penghuo penghuo changed the title WIP: Array values are preserved (#1300) Array values are preserved (#1300) Oct 24, 2024
penghuo pushed a commit to penghuo/os-sql that referenced this pull request Oct 25, 2024
penghuo pushed a commit to penghuo/os-sql that referenced this pull request Oct 25, 2024
penghuo added a commit that referenced this pull request Oct 25, 2024
Signed-off-by: Norman Jordan <[email protected]>
(cherry picked from commit e109417)

Co-authored-by: normanj-bitquill <[email protected]>
noCharger pushed a commit to noCharger/sql that referenced this pull request Oct 25, 2024
…ect#3095) (opensearch-project#3120)

Signed-off-by: Norman Jordan <[email protected]>
(cherry picked from commit e109417)

Co-authored-by: normanj-bitquill <[email protected]>
noCharger pushed a commit to noCharger/sql that referenced this pull request Oct 25, 2024
…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]>
noCharger pushed a commit to noCharger/sql that referenced this pull request Oct 26, 2024
…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]>
noCharger pushed a commit to noCharger/sql that referenced this pull request Oct 26, 2024
…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]>
opensearch-trigger-bot bot pushed a commit that referenced this pull request Oct 30, 2024
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>
penghuo pushed a commit that referenced this pull request Oct 30, 2024
(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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[DISCUSSION] Properly support array values in new engine
4 participants