Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scan count returns significantly less number for a dynamodb table

I'm running a sample java program to query a dynamodb table, the table has about 90000 items but when i get the scan count from java it shows only 1994 items

 ScanRequest scanRequest = new ScanRequest().withTableName(tableName);
 ScanResult result = client.scan(scanRequest);
 System.out.println("#items:" + result.getScannedCount());

the program outputs #items:1994 but the detail from amazon aws console shows:

Item Count*: 89249

any idea? thanks

like image 947
nightograph Avatar asked Dec 19 '22 16:12

nightograph


2 Answers

scanning or querying dynamodb only returns maximum of 1MB of data. the count is the number of return items fit in 1MB. in order to get the whole table, you should aggressively scan the database until the value LastEvaluatedKey is null

like image 196
nightograph Avatar answered Dec 22 '22 05:12

nightograph


Set your book object with correct hash key value, and use DynamoDBMapper to get the count.

DynamoDBQueryExpression<Book> queryExpression = new DynamoDBQueryExpression<Book>()
                .withHashKeyValues(book);
dynamoDbMapper.count(Book.class, queryExpression);
like image 31
sunvenka Avatar answered Dec 22 '22 05:12

sunvenka