Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get unique values of a column in AWS Dynamo?

Say, in AWS Dynamo, I have a table like this:

ID (HKey)   Date (RKey)   BoxName
0           1/1/2014      Box-1
1           2/1/2014      Box-1
2           3/1/2014      Box-2
3           4/1/2014      Box-3
4           5/1/2014      Box-3
5           5/1/2014      Box-1

I want to, in a single query, get the first row for each unique Box. There could be hundreds of boxes I need the first entry for at once, making individual requests inefficient.

I can't seem to find anything in the API that would allow me to do this. Is it possible? How would I do this?

like image 332
AlbeyAmakiir Avatar asked Sep 01 '14 23:09

AlbeyAmakiir


1 Answers

You might want to consider creating a Global secondary index (GSI) on Boxname (hash key) and date as your range key. This will enable you to use Query API on the secondary index where you can query "Find all IDs with Boxname = $box".

See the documentation for GSI.

Hope this helps, Swami

like image 52
Swami Sivasubramanian Avatar answered Sep 20 '22 15:09

Swami Sivasubramanian