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

Add Support for Nested Function in Order By Clause #1789

Merged
merged 2 commits into from
Jun 27, 2023

Conversation

forestmvey
Copy link
Collaborator

Description

Add support for nested function use in the ORDER BY clause.

Example Queries

SELECT nested(message.info) from nested_objects ORDER BY nested(message.info);

Issues Resolved

Portion of Issue: 1111
Note this does not resolve issue 1777 but only bring V2 engine to parity with V1 engine.

Check List

  • New functionality includes testing.
    • All tests pass, including unit test, integration test and doctest
  • New functionality has been documented.
    • New functionality has javadoc added
    • New functionality has user manual doc added
  • Commits are signed per the DCO using --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.

* Adding order by clause support for nested function.

Signed-off-by: forestmvey <[email protected]>

* Adding test coverage for nested in ORDER BY clause.

Signed-off-by: forestmvey <[email protected]>

* Added nested function validation to NestedAnalyzer.

Signed-off-by: forestmvey <[email protected]>

---------

Signed-off-by: forestmvey <[email protected]>
@codecov
Copy link

codecov bot commented Jun 27, 2023

Codecov Report

Merging #1789 (de77277) into main (c7dfdb3) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##               main    #1789   +/-   ##
=========================================
  Coverage     97.29%   97.29%           
- Complexity     4408     4416    +8     
=========================================
  Files           388      388           
  Lines         10944    10960   +16     
  Branches        774      777    +3     
=========================================
+ Hits          10648    10664   +16     
  Misses          289      289           
  Partials          7        7           
Flag Coverage Δ
sql-engine 97.29% <100.00%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
.../org/opensearch/sql/sql/parser/AstSortBuilder.java 100.00% <ø> (ø)
...va/org/opensearch/sql/analysis/NestedAnalyzer.java 100.00% <100.00%> (ø)
...earch/storage/scan/OpenSearchIndexScanBuilder.java 100.00% <100.00%> (ø)
...arch/storage/script/filter/lucene/LuceneQuery.java 100.00% <100.00%> (ø)
...ensearch/storage/script/sort/SortQueryBuilder.java 100.00% <100.00%> (ø)

acarbonetto
acarbonetto previously approved these changes Jun 27, 2023
Copy link
Collaborator

@acarbonetto acarbonetto left a comment

Choose a reason for hiding this comment

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

Please add another check for empty nested call if that's possible.
Otherwise, we should add a parser test/check that fails to parse

* @param nestedFunc Nested function expression.
*/
private void validateNestedArgs(FunctionExpression nestedFunc) {
if (nestedFunc.getArguments().size() > 2) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we also need to check for size() < 1?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes I'll add this check and a relevant test too.

}

@Test
void nested_with_invalid_arg_type_throws_exception() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we want to add a test case to validate that nested() returns an IllegalArgumentException?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Already have one here

Yury-Fridlyand
Yury-Fridlyand previously approved these changes Jun 27, 2023
GumpacG
GumpacG previously approved these changes Jun 27, 2023
@forestmvey forestmvey merged commit 3302ec8 into opensearch-project:main Jun 27, 2023
opensearch-trigger-bot bot pushed a commit that referenced this pull request Jun 27, 2023
* Add Support for Nested Function in Order By Clause (#280)

* Adding order by clause support for nested function.

Signed-off-by: forestmvey <[email protected]>

* Adding test coverage for nested in ORDER BY clause.

Signed-off-by: forestmvey <[email protected]>

* Added nested function validation to NestedAnalyzer.

Signed-off-by: forestmvey <[email protected]>

---------

Signed-off-by: forestmvey <[email protected]>

* Adding semantic check for missing arguments in function and unit test.

Signed-off-by: forestmvey <[email protected]>

---------

Signed-off-by: forestmvey <[email protected]>
(cherry picked from commit 3302ec8)
forestmvey added a commit that referenced this pull request Jun 27, 2023
* Add Support for Nested Function in Order By Clause (#280)

* Adding order by clause support for nested function.

Signed-off-by: forestmvey <[email protected]>

* Adding test coverage for nested in ORDER BY clause.

Signed-off-by: forestmvey <[email protected]>

* Added nested function validation to NestedAnalyzer.

Signed-off-by: forestmvey <[email protected]>

---------

Signed-off-by: forestmvey <[email protected]>

* Adding semantic check for missing arguments in function and unit test.

Signed-off-by: forestmvey <[email protected]>

---------

Signed-off-by: forestmvey <[email protected]>
(cherry picked from commit 3302ec8)
@forestmvey forestmvey deleted the integ-nested-order-by branch June 27, 2023 22:31
forestmvey added a commit that referenced this pull request Jun 28, 2023
* Add Support for Nested Function in Order By Clause (#280)

* Adding order by clause support for nested function.

Signed-off-by: forestmvey <[email protected]>

* Adding test coverage for nested in ORDER BY clause.

Signed-off-by: forestmvey <[email protected]>

* Added nested function validation to NestedAnalyzer.

Signed-off-by: forestmvey <[email protected]>

---------

Signed-off-by: forestmvey <[email protected]>

* Adding semantic check for missing arguments in function and unit test.

Signed-off-by: forestmvey <[email protected]>

---------

Signed-off-by: forestmvey <[email protected]>
(cherry picked from commit 3302ec8)

Co-authored-by: Forest Vey <[email protected]>
@acarbonetto acarbonetto added the v2.9.0 v2.9.0 label Jul 4, 2023
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.

6 participants