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

Pagination: Add Close Cursor API in v2. #1660

Merged

Conversation

Yury-Fridlyand
Copy link
Collaborator

@Yury-Fridlyand Yury-Fridlyand commented May 26, 2023

Description

Add close cursor API to V2 similar to V1. Refer to pagination doc.

This code branched of #1600. Once #1600 merged I'll update this branch and change base branch of this PR. Currently, it is a temporary branch to show the changes and approach.

Design

https://github.com/opensearch-project/sql/blob/9100c6285f033784b5a2e58f53d575ece360737f/docs/dev/Pagination-v2.md#close-cursor

Issues Resolved

New endpoint on _plugins/_sql/close. Under the hood it works as a subsequent query request, reserialized the cursor, but instead of executing it, just closes to encoded scroll.

TODOs

  • Update docs
  • Add UT with coverage
  • Complete todos in code
  • Return an error on repetitive close or on failure
  • Don't fallback to V1 on close failure
  • Record a demo

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.

@codecov
Copy link

codecov bot commented May 26, 2023

Codecov Report

Merging #1660 (92e9fb7) into feature/pagination/integ (9ebdda5) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@                     Coverage Diff                     @@
##             feature/pagination/integ    #1660   +/-   ##
===========================================================
  Coverage                       97.22%   97.23%           
- Complexity                       4217     4238   +21     
===========================================================
  Files                             381      385    +4     
  Lines                           10596    10626   +30     
  Branches                          727      726    -1     
===========================================================
+ Hits                            10302    10332   +30     
  Misses                            287      287           
  Partials                            7        7           
Flag Coverage Δ
sql-engine 97.23% <100.00%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
...g/opensearch/sql/executor/execution/QueryPlan.java 100.00% <ø> (ø)
...search/sql/planner/logical/LogicalFetchCursor.java 100.00% <ø> (ø)
...opensearch/executor/OpenSearchExecutionEngine.java 100.00% <ø> (ø)
...ain/java/org/opensearch/sql/analysis/Analyzer.java 100.00% <100.00%> (ø)
...opensearch/sql/executor/execution/CommandPlan.java 100.00% <100.00%> (ø)
...earch/sql/executor/execution/QueryPlanFactory.java 100.00% <100.00%> (ø)
...org/opensearch/sql/planner/DefaultImplementor.java 100.00% <100.00%> (ø)
...search/sql/planner/logical/LogicalCloseCursor.java 100.00% <100.00%> (ø)
...ch/sql/planner/logical/LogicalPlanNodeVisitor.java 100.00% <100.00%> (ø)
...arch/sql/planner/physical/CursorCloseOperator.java 100.00% <100.00%> (ø)
... and 6 more

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.

Thanks for this Yury

GumpacG
GumpacG previously approved these changes May 26, 2023
forestmvey
forestmvey previously approved these changes May 26, 2023
Copy link
Collaborator

@MaxKsyunz MaxKsyunz left a comment

Choose a reason for hiding this comment

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

Thank you @Yury-Fridlyand!

What happens when closing the cursor fails?

sql/src/main/java/org/opensearch/sql/sql/SQLService.java Outdated Show resolved Hide resolved
public class CloseCursor extends UnresolvedPlan {

/** An instance of {@link Cursor} */
private UnresolvedPlan child;
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is this child used for?

As far as I can see, this can be cursor id without loss of generality and would make the code more straight-forward.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

True.
I tried to follow this graph:
image

If I store here the cursor itself instead of a child plan, the planner logic should be a bit more complicated to create 2 nodes.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see how it works but it's hard to follow. I hope we can make it more explicit at some point later.

MitchellGale
MitchellGale previously approved these changes May 29, 2023
@Yury-Fridlyand Yury-Fridlyand force-pushed the feature/pagination/close-cursor-api branch from 9100c62 to 96cf27b Compare May 29, 2023 18:49
@Yury-Fridlyand Yury-Fridlyand changed the base branch from tmp-pagination-integ to tmp-pagination-integ2 May 29, 2023 18:58
@Yury-Fridlyand
Copy link
Collaborator Author

Yury-Fridlyand commented May 29, 2023

What happens when closing the cursor fails?

Nothing. A exception is suppressed and not even logged.

@GumpacG
Copy link
Collaborator

GumpacG commented May 29, 2023

Seems that jacoco is failing

@Yury-Fridlyand
Copy link
Collaborator Author

Thanks, fixed.

MaxKsyunz
MaxKsyunz previously approved these changes May 29, 2023
@Yury-Fridlyand Yury-Fridlyand added the pagination Pagination feature, ref #656 label May 29, 2023
acarbonetto
acarbonetto previously approved these changes May 29, 2023
return new ExecutionEngine.Schema(List.of());
}

// TODO remove
Copy link
Collaborator

Choose a reason for hiding this comment

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

TODO?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Yury-Fridlyand Yury-Fridlyand dismissed stale reviews from acarbonetto and MaxKsyunz via d7f44aa May 29, 2023 23:57
@Yury-Fridlyand Yury-Fridlyand changed the base branch from tmp-pagination-integ2 to feature/pagination/integ May 30, 2023 00:06
Signed-off-by: Yury-Fridlyand <yury.fridlyand@improving.com>
@Yury-Fridlyand Yury-Fridlyand force-pushed the feature/pagination/close-cursor-api branch from c8c4f17 to 92e9fb7 Compare May 30, 2023 01:47
@Yury-Fridlyand Yury-Fridlyand merged commit bc5bede into feature/pagination/integ May 30, 2023
@Yury-Fridlyand Yury-Fridlyand deleted the feature/pagination/close-cursor-api branch May 30, 2023 03:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pagination Pagination feature, ref #656
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants