aws-sdk-net: When using DynamoDBContext.FromScanAsync the return type AsyncSearch does not expose the pagination token
Expected Behavior
Currently unless using the Document mid-level API directly there is no way to implement pagination during a search.
I expect that the PaginationToken should be available as a property on the AsyncSearch<T> type, so that I can use it page through results returned from the Scan.
Current Behavior
The difference in behavior would be to expose PaginationToken as a public property on this class: https://github.com/aws/aws-sdk-net/blob/master/sdk/src/Services/DynamoDBv2/Custom/DataModel/AsyncSearch.cs#L40
Possible Solution
The change could be implemented in this way:
public string PaginationToken
{
get { return DocumentSearch.PaginationToken; }
}
Context
This issue is impacting me because I would prefer not to have to take a dependency in my classes on the Document API if I can just use the DynamoDBContext by itself.
Your Environment
- Service assembly and version used: AWSSDK.DynamoDBv2 nuget package v3.3.4.13
- Operating System and version: Windows 10
- Visual Studio version: VS 2017
- Targeted .NET platform: .Net Core 1.1
.NET Core Info
- .NET Core version used for development: 1.1
- .NET Core version installed in the environment where application runs: 1.1
- Output of
dotnet --info:
.NET Command Line Tools (1.0.4)
Product Information: Version: 1.0.4 Commit SHA-1 hash: af1e6684fd
Runtime Environment: OS Name: Windows OS Version: 10.0.15063 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\1.0.4
- Contents of project.json/project.csproj: not relevant
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 14
- Comments: 22 (1 by maintainers)
Why is using the IDynamoDBContext the recommended approach if it doesn’t support pagination across requests? This is not a small feature that is missing.
My team and I would also really like to see a solution to this, right now if you want pagination and the ability to easily deserialize results from a query, you need to use an
IAmazonDynamoDBclient to make the async query with a LastEvaluatedKey, and then you need to construct aDynamoDBContextusing that same client to use itsFromDocument()function. From the literature I’ve read, it seems you don’t want to be creating this context class too often as it’s apparently sort of heavy.I’d really like to see either more pagination control given to the DDB Context, or something more handy for converting results from the lower level client into the entity type we’ve stored.
Thanks for the feedback @PavelSafronov - I had already implemented your above solution to work around the issue before you even posted 😃 In my implementation I start with a null paginationToken, rather then an empty JSON array, but it still seems to work.
I do still wonder if the abstraction is a little leaky on DynamoDBContext then because the method:
Takes a ScanOperationConfig, which allows specifying a PaginationToken - which doesn’t really work in that instance because you never had a chance to grab one (unless you construct the pagination token yourself) - which is what led me to think the inability to get back the pagination token didn’t make much sense.
Also looking at the result type of FromScanAsync<T> which is AsyncSearch<T> it does not implement automatic paging via IEnumerable<T> either - this is the API it exposes (notice the comments too mentioning PaginationToken - even more confusing!)
Cheers,
Alex
@PavelSafronov So now there are no ways to implement a pagination using
DynamoDBContextwith async queries? UsingGetNextSetAsync()is not an option because I can’t get and set any tokens to share search state between my API calls.The only way I see now is to manage search state manually on the application level saving
AsyncSearchinstances somewhere but it’s not a really good option from the architecture point of view. Or am I missing something?I was not the original dev on the team that look at this issue back in 2017 that had hesitation with adding the
PaginationTokenproperty. I don’t share the same hesitation and I recognize it has been many years and we haven’t addressed the issue in any other way. I approved/merge @hamermike PR to expose thePaginationTokenonAsyncSearch. It was released today in version 3.7.301.16 of the AWSSDK.DynamoDBv2 package.I’m resolving this issue because I believe that PR address the original issue. If there are additional issues please open a new issue as this one is old and long so details will get missed.
This code actually works! Dear AWS DynamoDB API team, it is time to expose
PaginationTokenas a first class citizen. Also, when I specify the limit for scan, I can only specify how many elements will be read, not the max result size, which is kind’a dumb. If I need the next 50 elements, I should be able to set something like that up.The way I see it, after almost 5 years, there is no improvement😊
Heck I’ll just add my request as well to this. Give us our pagination token!
Cheers
Any Updates?
I am using the following patch for now to get the pagination token and it seems to get the pagination token and when using it with the QueryOperationConfig it does bring the next items. That is a nasty hack tough.
Any updates on this? There’s any way we can get Pagination Token from QueryAsync?