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

feat(orm): specify generic gRPC query service #11791

Merged
merged 7 commits into from
Jun 13, 2022
Merged

Conversation

aaronc
Copy link
Member

@aaronc aaronc commented Apr 26, 2022

Description

Ref #11774

This proposes a generic gRPC query service that uses direct index access and can basically be implemented as a thin layer directly on top of ormtable.Table. There is relatively little code required to implement this but it can potentially provide a lot of value as a way to expose queries to basically everything that's using the ORM without needing to implement any custom gRPC queries.

A version of this which is type safe is also proposed in #11774 but that would require additional codegen of .proto files. #11774 also proposes a logical query layer instead of direct index access but that's substantially more code to do even naively and an optimized version would take more effort.


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

@codecov
Copy link

codecov bot commented Apr 26, 2022

Codecov Report

Merging #11791 (d84946a) into main (82412af) will increase coverage by 0.03%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #11791      +/-   ##
==========================================
+ Coverage   66.14%   66.18%   +0.03%     
==========================================
  Files         673      708      +35     
  Lines       71160    74055    +2895     
==========================================
+ Hits        47072    49016    +1944     
- Misses      21444    22127     +683     
- Partials     2644     2912     +268     
Impacted Files Coverage Δ
x/group/keeper/keeper.go 54.43% <0.00%> (-0.43%) ⬇️
orm/model/ormtable/unique.go 44.09% <0.00%> (ø)
orm/internal/fieldnames/fieldnames.go 100.00% <0.00%> (ø)
orm/encoding/ormfield/int64.go 100.00% <0.00%> (ø)
orm/encoding/ormkv/index_key.go 62.82% <0.00%> (ø)
orm/model/ormdb/file.go 56.52% <0.00%> (ø)
orm/encoding/ormfield/enum.go 80.00% <0.00%> (ø)
orm/model/ormtable/primary_key.go 49.66% <0.00%> (ø)
orm/model/ormtable/util.go 57.89% <0.00%> (ø)
orm/encoding/ormkv/primary_key.go 57.77% <0.00%> (ø)
... and 26 more

Copy link
Contributor

@technicallyty technicallyty left a comment

Choose a reason for hiding this comment

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

lgtm! exciting 💯

Copy link
Contributor

@ValarDragon ValarDragon left a comment

Choose a reason for hiding this comment

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

This seems great to me!

Then JS libraries can build better direct interfaces on top of these ORM queries

Copy link
Collaborator

@robert-zaremba robert-zaremba left a comment

Choose a reason for hiding this comment

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

left 2 suggestions

message GetResponse {

// result is the result of the get query. If no value is found, the gRPC
// status code NOT_FOUND will be returned.
Copy link
Collaborator

Choose a reason for hiding this comment

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

what if a wrong index is used? I think we should return InvalidRequst in that case.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes


// pagination is the pagination request.
cosmos.base.query.v1beta1.PageRequest pagination = 5;

Copy link
Collaborator

Choose a reason for hiding this comment

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

how about adding reverse flag?

Copy link
Member Author

Choose a reason for hiding this comment

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

PageRequest already includes reverse

@aaronc
Copy link
Member Author

aaronc commented Apr 26, 2022

I'd like to move this to cosmos.orm.query.v1 to version it separately. Any objections to that?

Copy link
Member Author

@aaronc aaronc left a comment

Choose a reason for hiding this comment

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

I'm actually thinking of simplying the API and removing IndexValue and maybe the query oneof, and using string (proto JSON encoding) instead.

I'm trying to think of gRPC gateway usage. Consider (the current format):

{"message_name":"cosmos.bank.v1.Balance","index":"address,denom","query":{"prefix":{"values":[{"str":"cosmos34sdgihi"}]}}}

vs

{"message_name":"cosmos.bank.v1.Balance","index":"address,denom","prefix":["cosmos34sdgihi"]}

Any objections?

// values are the values of the fields corresponding to the requested index.
// There must be as many values provided as there are fields in the index and
// these values must correspond to the index field types.
repeated IndexValue values = 3;
Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
repeated IndexValue values = 3;
repeated string values = 3;

Comment on lines 56 to 63
oneof query {

// prefix defines a prefix query.
Prefix prefix = 3;

// range defines a range query.
Range range = 4;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
oneof query {
// prefix defines a prefix query.
Prefix prefix = 3;
// range defines a range query.
Range range = 4;
}
repeated string prefix = 3;
repeated string start = 4;
repeated string end = 5;

@aaronc
Copy link
Member Author

aaronc commented Apr 28, 2022

I'm now thinking of maybe not taking this approach and instead going with logical queries, see #11774 (comment) and #11822

@github-actions
Copy link
Contributor

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Jun 13, 2022
@tac0turtle
Copy link
Member

@aaronc is it okay to merge this then come back?

@tac0turtle tac0turtle requested a review from a team as a code owner June 13, 2022 18:23
@aaronc
Copy link
Member Author

aaronc commented Jun 13, 2022

@aaronc is it okay to merge this then come back?

I'd want to mark it as alpha first

@aaronc
Copy link
Member Author

aaronc commented Jun 13, 2022

Marked as v1alpha1 for now and going to merge. I think this may still be relevant as a very basic layer to sit under other tools as I mentioned here: #11822 (comment)

@aaronc aaronc added A:automerge Automatically merge PR once all prerequisites pass. C:orm and removed stale labels Jun 13, 2022
@mergify mergify bot merged commit d084887 into main Jun 13, 2022
@mergify mergify bot deleted the aaronc/orm-grpc-proto branch June 13, 2022 20:45
Copy link

@Mita23456 Mita23456 left a comment

Choose a reason for hiding this comment

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

Fa
M

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:automerge Automatically merge PR once all prerequisites pass. C:orm
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants