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

Improve semantics for listing methods #569

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Improve semantics for listing methods #569

wants to merge 9 commits into from

Conversation

nfx
Copy link
Contributor

@nfx nfx commented Aug 3, 2023

This PR moves listing requests to an ListXXXInternal entity, which keeps all the low-level pagination request fields, like offset, limit, token, page. Original entity keeps all of the fields, except pagination-related. This allows to mitigate a common confusion, where users supply limit for the iterator and it acting only a result page limit, not the max number of results.

Follow-up Python SDK PR: databricks/databricks-sdk-py#279

@nfx nfx requested a review from mgyucht August 3, 2023 16:03
@nfx nfx added codegen Related to code generation do-not-merge labels Aug 3, 2023
@mgyucht
Copy link
Contributor

mgyucht commented Aug 4, 2023

Is the idea that the limit field in the request is only used for the page size and not the total number of responses? I thought you would just be able to remove https://github.com/databricks/databricks-sdk-go/blob/main/.codegen/api.go.tmpl#L219-L221, then no global limit is enforced and this API behaves the same as in the other SDKs.

Rather than supporting a global limit, we should instead switch to the lazy iterator approach and allow users to pull as many resources as they need.

@nfx
Copy link
Contributor Author

nfx commented Aug 4, 2023

@mgyucht https://github.com/databricks/databricks-sdk-go/blob/main/.codegen/api.go.tmpl#L219-L221 i think we need to change this to max_results "virtual field", that would do a "global limit". Or we can keep the limit name, but redefine the semantics for when they're used in iterators. It's necessary for things like CLI. e.g. get the latest XX jobs or show the latest XX queries.

@mgyucht
Copy link
Contributor

mgyucht commented Aug 4, 2023

Once I get around to #543, users can define their own iterators and filter however they like. IMO I don't think it needs to be built into the Go SDK, and it isn't in any other SDK we publish today.

@nfx
Copy link
Contributor Author

nfx commented Aug 7, 2023

@mgyucht it's orthogonal to #543 (we should hold on that because of the upcoming language changes - golang/go#61405).

this change is about cross-SDK semantics on removing low-level fields to paginated methods, so it should be merged ;)

@nfx nfx linked an issue Aug 8, 2023 that may be closed by this pull request
This PR moves listing requests to an `ListXXXInternal` entity, which keeps all the low-level pagination request fields, like `offset`, `limit`, `token`, `page`. Original entity keeps all of the fields, except pagination-related. This allows to mitigate a common confusion, where users supply `limit` for the iterator and it acting only a _result page limit_, not the _max number of results_.
@codecov-commenter
Copy link

codecov-commenter commented Aug 10, 2023

Codecov Report

Patch coverage: 1.55% and project coverage change: +0.07% 🎉

Comparison is base (a3c5a3c) 17.97% compared to head (b55e389) 18.04%.
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #569      +/-   ##
==========================================
+ Coverage   17.97%   18.04%   +0.07%     
==========================================
  Files          85       85              
  Lines        9805     9990     +185     
==========================================
+ Hits         1762     1803      +41     
- Misses       7889     8030     +141     
- Partials      154      157       +3     
Files Changed Coverage Δ
openapi/code/method.go 35.36% <ø> (+17.62%) ⬆️
service/catalog/api.go 0.00% <0.00%> (ø)
service/catalog/impl.go 0.00% <ø> (ø)
service/catalog/model.go 0.00% <ø> (ø)
service/compute/api.go 12.46% <0.00%> (-0.20%) ⬇️
service/compute/impl.go 10.74% <ø> (ø)
service/compute/model.go 0.00% <ø> (ø)
service/iam/model.go 0.00% <ø> (ø)
service/jobs/api.go 0.00% <0.00%> (ø)
service/jobs/impl.go 0.00% <ø> (ø)
... and 14 more

... and 1 file with indirect coverage changes

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

Copy link
Contributor

@mgyucht mgyucht left a comment

Choose a reason for hiding this comment

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

This is a good change, but I think there are a couple issues that need to be resolved.

.codegen/api.go.tmpl Show resolved Hide resolved
openapi/code/service.go Outdated Show resolved Hide resolved
openapi/code/service.go Outdated Show resolved Hide resolved
if svc.Name == "Jobs" {
// add generation for client-side maximum number of results during iteration.
// platform already implements this field for part of the APIs and it's
// consistently named as max_results everywhere. Perhaps we should
Copy link
Contributor

Choose a reason for hiding this comment

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

max_results is also confusing and incorrect as listing will return all results, regardless of the value passed here. Can we rename this field to page_size instead? This aligns with our internal standards on pagination.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it we use any other name than limit, it'll break the CLI. @pietern are we fine with that? :)

max_results is also confusing and incorrect as listing will return all results, regardless of the value passed here.

we can make deterministic logic here. max_results is really the closest thing semantically. page_size is not applicable here, as this listing request is for the entire dataset, not the page. the concept of page is totally hidden from a user.

Copy link
Contributor

Choose a reason for hiding this comment

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

If the concept of page is hidden from users, then we should not expose this parameter at all, as its only use is to determine the page size.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we're keeping this limit for CLI, then. other renames are out of scope for now.

openapi/code/service.go Outdated Show resolved Hide resolved
.codegen/api.go.tmpl Outdated Show resolved Hide resolved
openapi/code/service.go Outdated Show resolved Hide resolved
@nfx nfx requested a review from mgyucht August 10, 2023 14:13
@mgyucht
Copy link
Contributor

mgyucht commented Aug 10, 2023

Can we prepare the changes in the other SDKs at the same time, since we're making changes to the template logic? This change seems good to me, but to minimize clashes with others developing on the SDKs, I want to decrease the wall-clock time that the OpenAPI generator won't work with the other SDKs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
codegen Related to code generation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pipelines list-pipeline-events with filter error
3 participants