Hi,
I recently implemented a new function that gets distinct primary keys in a DynamoDB table. I used the script (Scan with a modified exclusive start key) from this tutorial on AWS Blogs.
When writing tests for this function, I used moto to mock DynamoDB service. However, the response from DynamoDB and moto is inconsistent when scanning a table with a limit.
The script relies on scanning only 1 entry and skipping to the next entry with unique pk. Here is the actual response from the table scan call with limit 1:
This is what the table scan with limit 1 returns with moto. Moto scans the whole table and then returns 1 item. However in the Boto3 documentation it says "If you did not use a FilterExpression in the scan request, then Count is the same as ScannedCount." So I expect to see the Count and ScannedCount values to be 1.
Thanks for raising this @pinarkaymaz6. Looks like our logic is a bit too naive here, because we just gather all possible results first, and only limit the result-set afterwards.
Hi, I recently implemented a new function that gets distinct primary keys in a DynamoDB table. I used the script (Scan with a modified exclusive start key) from this tutorial on AWS Blogs.
When writing tests for this function, I used moto to mock DynamoDB service. However, the response from DynamoDB and moto is inconsistent when scanning a table with a limit.
The script relies on scanning only 1 entry and skipping to the next entry with unique pk. Here is the actual response from the table scan call with limit 1:
This is what the table scan with limit 1 returns with moto. Moto scans the whole table and then returns 1 item. However in the Boto3 documentation it says "If you did not use a
FilterExpression
in the scan request, thenCount
is the same asScannedCount
." So I expect to see the Count and ScannedCount values to be 1.Here is my test case:
Library versions that I'm using are:
Thank you. Pinar