1

A query result come in the form of list of Map<String, AttributeValue>,

To convert a single Map<String, AttributeValue> to a JSON the only way I have found is to iterate over each key in the map, and build the JSON string.

final ObjectNode node = JsonNodeFactory.instance.objectNode();

for (final Entry<String, AttributeValue> entry : item.entrySet()) {
    node.put(entry.getKey(), getJsonNode(entry.getValue(), depth + 1));
}

Is there a more efficient way to achieve this? Is there a way to get a result from dynamoDB as JSON.

soundslikeodd
  • 1,078
  • 3
  • 19
  • 32
user3312154
  • 235
  • 3
  • 14

1 Answers1

0

I figured out what was going on. AWS dynamoDB documentation needs to be updated . (e.g) http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/QueryAndScan.html#QueryAndScan.Query

AWS DynamoDB java api offers 3 options for doing queries, QueryResult, QuerySpec , and Scan.
There documentation does not clearly distinguish between QueryResult / QuerySpec. They return different objects, and internally behave very differently. QueryResult returns a map, which cannot be effeciently converted to json. QuerySpec returns aws ITEMS, which can be converted quickly to json strings They state in there docs that Queries (in general) have a max data return size of 1MB per query, so if you need to fetch more, then you must make subsequent calls. What I found is that this only applies to QueryResult query method, which contains a LastEvaluatedKey, which can used to figure out the next "page" to fetch if more data is available. However, QuerySpec method does not contain the LastEvaluatedKey, which confused me , then I figured out that QuerySpec appears to internally paginate the data for you. I was able to return 4Mb with a single call,

user3312154
  • 235
  • 3
  • 14