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

Support for BatchGetItem #122

Closed
yyamanoi1222 opened this issue Sep 20, 2022 · 5 comments
Closed

Support for BatchGetItem #122

yyamanoi1222 opened this issue Sep 20, 2022 · 5 comments
Labels
feature-request A feature should be added or improved.

Comments

@yyamanoi1222
Copy link

Are there any plans to implement BatchGetItem in this gem?

I saw this issue #12
We have a requirement and BatchGetItem may be better than TransactGetItems. (e.g., retrieve large number of items , no need to consider transaction conflict errors, etc.)

If you don't plan to implement it and are be open the idea, may I add the feature myself?
The API interface will be something like transact_find

result = Aws::Record::Batch.find(
  batch_items: [
    TableOne.bfind_opts(key: { uuid: "uuid1234" }),
    TableTwo.tfind_opts(key: { hk: "hk1", rk: "rk1"}), 
    TableTwo.tfind_opts(key: { hk: "hk2", rk: "rk2"})  
  ]
)

result.responses # { TableOne.table_name => [TableOne], TableTwo.table_name => [TableTwo, TableTwo] }

Thanks!

@alextwoods alextwoods added the feature-request A feature should be added or improved. label Sep 20, 2022
@alextwoods
Copy link
Contributor

alextwoods commented Sep 20, 2022

Thanks for reaching out on this - we do have plans to add support for BatchGetItems! As part of a new investment in this library we are planning to add support following the approach taken in PR #119 where we added support for batch writing items using a new BatchWrite class to avoid any backwards compatibility / breaking changes.

We are planning to add support for batch_get_item with a BatchRead class (capable of reading multiple items from multiple tables) which can be used by individual Record classes, giving an interface like:

class Foo
  include Aws::Record
  string_attr :name, hash_key: true
end

class Bar
  include Aws::Record
  string_attr :id, hash_key: true
  string_attr :rk, range_key: true
end

# produces a heterogeneous ItemCollection
items = Aws::Record::Batch.read do |db|
  db.find(Foo, name: 'n1')
  db.find(Foo, name: 'n2')
  db.find(Bar, id: 'id1', rk: 'rk1')
  db.find(Bar, id: 'id1', rk: 'rk2')
end

# returns a homogenous ItemCollection
foo_items = Foo.find_all(
  [
    {name: 'n1'},
    {name: 'n2'}
  ])

# an alternative syntax
foo_items = Foo.find_all do |db|
  db.find(name: 'n1') # the Foo class is implied here
  db.find(name: 'n2')
end

Would that work for your use case?

@yyamanoi1222
Copy link
Author

yyamanoi1222 commented Sep 21, 2022

Thank you for your reply
It looks like good!

One point of concern is that the existing ItemCollection class would have to be significantly modified.
This is because BatchGetItem has no pagination and the batch_get_item response contains multiple table name keys.
It seems simpler to return a simple array like transact_find than to abstract it with ItemCollection.

@yyamanoi1222
Copy link
Author

@alextwoods
What do you think about the above?

And when will this function be implemented?
I wonder if I should extend this gem to use it or wait for implementation.
I can always help with implementation about this function.
Sorry to bother you.

@alextwoods
Copy link
Contributor

Sorry for the delay in response. Yes, the existing ItemCollection class wouldn't quite work for this case - and we would return an enumerable with a similar interface (supporting an each method) rather than modifying the ItemCollection class itself.

I believe we are currently targeting about mid Q4 of this year for the feature.

@jterapin jterapin mentioned this issue Nov 23, 2022
jterapin added a commit that referenced this issue Jan 13, 2023
* Implemented the `BatchGetItem` operation (#122).

Co-authored-by: Juli Tera <terajul@amazon.com>
@jterapin
Copy link
Contributor

Implemented the feature and published a new gem (v2.10.0).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved.
Projects
None yet
Development

No branches or pull requests

3 participants