Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamodb max value

I'm using Dynamodb. I have a simple Employee table with fields like id, name, salary, doj, etc. What is the equivalent query of select max(salary) from employee in dynamodb?

like image 231
arunapavan Avatar asked Jun 22 '16 05:06

arunapavan


People also ask

What is the DynamoDB Max item size?

Item size. The maximum item size in DynamoDB is 400 KB, which includes both attribute name binary length (UTF-8 length) and attribute value lengths (again binary length). The attribute name counts towards the size limit.

Can DynamoDB handle big data?

DynamoDB is a key-value and document database that can support tables of virtually any size with horizontal scaling. This enables DynamoDB to scale to more than ten trillion requests per day with peaks greater than 20 million requests per second, over petabytes of storage.

What is limit in DynamoDB query?

A single Query operation can retrieve a maximum of 1 MB of data. This limit applies before any FilterExpression or ProjectionExpression is applied to the results. If LastEvaluatedKey is present in the response and is non-null, you must paginate the result set (see Paginating table query results).

What is the capacity of DynamoDB?

If your application reads or writes larger items (up to the DynamoDB maximum item size of 400 KB), it will consume more capacity units.


2 Answers

Not sure about boto3 but inboto can be run this way

from boto.dynamodb2.table import Table

table = Table("employee")
values = list(table.query_2(reverse=True, limit=1))
MAXVALUE = values[0][salary]
like image 73
sameera sy Avatar answered Sep 16 '22 17:09

sameera sy


You can model your schema something like:

  • employee_id, as partition-key
  • salary, as sort-key of the table or local secondary index.

Then, Query your table for given employee_id, with ScanIndexForward as false, and pick the first returned entry. Since all rows one employee_id are stored in sorted fashion, the first entry in desc order will be the one with highest salary.

You can also keep Limit as 1, in which case DynamoDB will return only one record.

Relevant documentation here.

like image 33
ketan vijayvargiya Avatar answered Sep 17 '22 17:09

ketan vijayvargiya