This might two separate questions into a single one. But that's my current use case. I have a POJO which has specific attributes.
It might look like:
class MyObject {
String id;
String name;
int size;
getters and setters () ....
}
Now I have a list of these objects - List which I wish to store in a single in Dynamo. Something like
RecordID Attributes
abcd123 List<MyObject>
Can I store the data in Dynamo in the above format? My second question is related to the above use case.
Now that I have stored the records, can I retrieve a specific part of the List? Like, I want indices 0 - 5 to be returned from the DyanmoDBQuery Request and not the entire list itself.
Is that possible?
I am pretty new to DynamoDB and I am not sure how well there is support for storing custom objects in Dynamo.
In Amazon DynamoDB, you can use either the DynamoDB API, or PartiQL, a SQL-compatible query language, to query an item from a table. With Amazon DynamoDB the Query action lets you retrieve data in a similar fashion. The Query action provides quick, efficient access to the physical locations where the data is stored.
DynamoDB supports the Java Set , List , and Map collection types. The following table summarizes how these Java types map to the DynamoDB types.
The BatchGetItem operation returns the attributes of one or more items from one or more tables. You identify requested items by primary key. A single operation can retrieve up to 16 MB of data, which can contain as many as 100 items.
GetItem – Retrieves a single item from a table. This is the most efficient way to read a single item because it provides direct access to the physical location of the item.
If you are able to massage your schema and move to a Partition-Sort key schema, where the Partition key is RecordID and the Sort key is ItemNumber, where Item number is the index of each MyObject in the abcd123
list above, then you can get sublists with a range query:
Item example:
RecordID (partition key) asdfasdfadsf
ItemNumber (sort key) 0
Item an instance of MyObject
Range query parameters:
KeyCondition: RecordId = :rid AND ItemNumber BETWEEN :lower AND :upper
ExpressionAttributeValues = { ":rid": "asdfasdfasdf", ":lower": 0, ":upper": 5 }
Note that the :upper
bound is inclusive, so the query example above will return MyObjects with RecordId=asdfasdfasdf
with ItemNumbers 0, 1, 2, 3, 4, and 5.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With