Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle empty HashSet attributes? #152

Open
danj opened this issue Jan 15, 2021 · 2 comments
Open

How to handle empty HashSet attributes? #152

danj opened this issue Jan 15, 2021 · 2 comments

Comments

@danj
Copy link

danj commented Jan 15, 2021

Hi,

I'm new to Rust and Dynomite. Have some experience with DynamoDB.
Hope my question makes sense.

I'd like to have an item with an attribute of type HashSet.

#[derive(Item, Debug, Clone)]
struct User {
    #[dynomite(partition_key)]
    id: String,
    friends: HashSet<String>
}

When I try to create such an item in DynamoDB it seems like the hashset is translated to an attribute of type SS with an empty set of values { "SS": [] }. This is not permitted by DynamoDB and returns an error.

Alternatively, when I define the attribute as an Option (initialized to None) the resulting Item has a NULL attribute { "NULL": true }

#[derive(Item, Debug, Clone)]
struct User {
    #[dynomite(partition_key)]
    id: String,
    friends: Option<HashSet<String>>
}

The challenge with the NULL attribute is that subsequent update expressions such as "ADD friends :v" no longer work, as the attribute type is not a Set.

Any advice / best-practices ?

Thanks,

@phrohdoh
Copy link
Contributor

When I try to create such an item in DynamoDB it seems like the hashset is translated to an attribute of type SS with an empty set of values { "SS": [] }.

Is the serialized set always empty (regardless of the state of your HashSet<_>)?
If so, that's be a bug (in dynomite).

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.NamingRulesDataTypes.html#HowItWorks.DataTypes.SetTypes tells us

DynamoDB does not support empty sets

Unfortunately I don't yet have sufficient relevant experience to comment further.

@danj
Copy link
Author

danj commented Jan 20, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants