David Good

Software Engineer
Software Engineer @Rivian πŸ‡ΊπŸ‡Έ.then(πŸ‡ͺπŸ‡¨).then(πŸ‡¨πŸ‡±).then(πŸ‡§πŸ‡·).then(πŸ‡©πŸ‡ͺ).then(πŸ‡¬πŸ‡§).finally(🌎) #Java #TypeScript #AWS #Serverless #DynamoDB

Querying an Item Collection of Distinct Types Java

Does anyone have suggestions for dealing with a query on an item collection?

Example: an item collection which contains a Customer, an Order, and an Employee who will fulfill the order.

What I'm finding is that the SDKs and DynamoDBMapper aren't flexible enough to read more than one object type, sort of not surprising given Java's static nature. The are a few related (sort of, these are about polymorphism) feature requests for the AWS SKDs (here for v1 which they say won't be added, and here for v2 which is still open) and one workaround here.

Aside from those options, all I can think of is going with the low-level API and constructing the instances by hand from the Map<String, AttributeValue> and vice versa.

Spring Data DynamoDB

I came across a project using spring-data-dynamodb. I was wondering if anyone had any thoughts on it.

My first thought is that it's providing ORM-like functionality and shouldn't really be necessary (DynamoDBMapper is enough), and it may even encourage bad practices like full-table scans. For example, I noticed an `@EnableScan` annotation (couldn't find any official docs for it), and it sounds like it might implicitly do scans, for example, `findByLastName` on a User where the `LastName` attribute isn't part of an index. And more generally, it provides an abstraction which makes it convenient for developers to ignore the details of DynamoDB, but those details really can't be avoided if you want to follow the best practices.

It does provide some other functionality like creating a table at start-up if it doesn't exist.