简体   繁体   中英

How can I get a list of partition keys from a DynamoDB table?

I am using java (dynamodb mapper) to make CRUD operations on a DynamoDB table with composite primary key (partition key and sort key).

I would like to make modifications to attributes partion-by-partion. How can I get a list of all the unique partition keys? The method I am doing right now involves scanning the entire table, and I know this is suboptimal and discouraged behavior. Is there a way to get all the partition keys of a dynamoDB table?

Any suggestions on what should be done?

If you don't know the partition key, a scan is your only option inside DynamoDB. Even if you do a Select PK from tablename using PartiQL for DynamoDB , it still is going to do a scan operation.

Now if you export the table's data to S3, you could write something to manipulate it there and then import it back into the table with a script you write to update items from the file. That or take it into EMR, if that is your thing.

One thing that peaked my interest in your question though is you wanting to "make modifications to attributes partion-by-partion". Just because there is a partition key, does not mean that data is in its own partition. You can have multiple different unrelated partition keys in the same partition in DynamoDB.

Without know more about your situation, I am thinking you should do a scan to get all the primary keys and then for each one, do an UpdateItem to alter the attribute in question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM