Is #DynamoDBAutoGeneratedKey attribute always incremental? - amazon-dynamodb

Dynamodb Table with an attribute say id(unique value) which is a Range key and it should always be an incremental value. Using DynamoDBAutoGeneratedKey will solve my requirement?

No. auto-generated-keys get a UUID value which is a unique random string (e.g., 0674e9df-0059-4f71-a172-6e2dcb32a92d)
Specifically, the Java Doc says the following:
Only String typed keys can be auto generated, and are given a random UUID.

Related

enforce case-insensitive value for unique key constraint in cosmosDB?

we have a sql container. We’d like to enforce case-insensitive unique constraint on a particular property (say, ‘Name’. if a document's Name is ‘ALICE’, no other document in that logical partition shall have ‘alice’ as Name).
One solution might be introducing another property LowerCaseName and enforce the natively supported unique key config on path /LowerCaseName. Every time Name is updated, we make sure LowerCaseName is always updated as the lower-case version of Name in the same request.
I’m not sure if this is the best practice for this problem? Thanks.
public MyDocumentModel
{
string Name {get; set;}
string LowerCaseName {get; set;}
}
From the documentation here:
In Azure Cosmos DB's SQL (Core) API, items are stored as JSON values.
These JSON values are case sensitive. When you choose a property as a
unique key, you can insert case sensitive values for that property.
For example, If you have a unique key defined on the name property,
"Gaby" is different from "gaby" and you can insert both into the
container.
Based on this, I believe your approach for having a 2nd property to enforce unique key is correct.

DynamodbDB query without a range key

I have table defined with two column, column 1 is the hash key and column 2 is the range key.
I want to get all items defined with the same hash key (so the range key doesn't matter).
I tried to use the new KeyPair().withHashKey(k). But it will throw exception saying that no RANGE key value present.
Is the only option I have is to do a scan for the table to achieve this?
I think the problem is that you are trying to use the GetItem call, which requires the complete key, and only returns one item. You need to use the Query call, and pass in a KeyExpression that only includes the partition key.

How to set DynamoDB range key, String or Map

I have a DynamoDB table with a primary hash key, and a range key. Range key will have two attributes. Say those attribute names are: name1, name2, with values value1, value2
Plan A: combine two attributes as string, use comma as delimiter
Primary hash key: id
Range key: value1,value2
Cons
1. comma may not work if some wired values contain this delimiter
Plan B: convert map as String for range key
Primary hash key: id
Range key: “{\“name1\”: \“value1\”, \“name2\”: \“value2\”}”
Cons
1. different SDK may result into different JSON String based on the same value? (Not sure), need to support multiple SDK read/write. Like Java and Ruby
So, which solution works better? Or there are any better suggestions?
Thanks!
Ray
You're on the right track. The AWS docs regarding key design promote your first suggestion, but it also has some warnings about the situation that you refered as cons.
I don't think that you could have problemas with different sdk parsers, but I also think that a little bit of precautions here would be a good ideia. So instead of directly parse a json to string using the sdk, I would manually concatenate the values using a custom function to generate a deterministic value like "name1-value1-name2-value2" or "name1:value1-name2:value2".

Creating DynamoDB Table with List type as a primary key

I have a use case where I want to create a Dynamodb Table which contains only 2 attributes - List of String (for example, Countries) and a Boolean value.
I am extracting this value for each country and implementing different logic in case of true or false.
My question is that, what is a best way (best practice) to create a dynamodb table.
I thought of few of following ways -
Boolean value as a key
Use boolean value as key and List as another attribute.
Add a row for each country.
Create a separate record with Country value as key and flag as an attribute.
Use List of countries as key and boolean value as another attribute. (I don't think this can be a good choice)
What could be the best practice while designing tables like this?
Thank You,
Prasad
From AWS DynamoDB Docs, NamingRulesDataTypes:
When you create a table or a secondary index, you must specify the names and data types of each primary key attribute (partition key and sort key). Furthermore, each primary key attribute must be defined as type string, number, or binary.
There are many options to model your table, but keep in mind you have to respect the rules cited above.
Your second case is a good one:
Add a row for each country. Create a separate record with Country value as key and flag as an attribute.
Partition key: country - string
Some column you do not have to define at creation: flag - boolean

What is a hash table that doesn't know the keys?

For example, if I create a dictionary in python I can use d.keys() to retrieve the keys.
What is a hash table/dictionary without this kind of access? Storage might be an issue and the keys may be of least importance.
Edit (clarification): I want a data structure that can access values through the key but doesn't know the key, only the hash. For example:
Hash Value
-----------------------------------------------------------------------
2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae|hey!
c9fc5d06292274fd98bcb57882657bf71de1eda4df902c519d915fc585b10190|hello!
If I try and access the data structure with the key "this is a key", it will hash that and get "hello!". If I try to access it with the key "foo", I will get "hey!".
We cannot retrieve the keys from this hash table, but we can access the data. This would be useful in cases where storage is important.
Normally, this would be the table:
Hash Value Key
-------------------------------------------------------------------------------------
2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae|hey! |foo
c9fc5d06292274fd98bcb57882657bf71de1eda4df902c519d915fc585b10190|hello!|this is a key
This is called a Set - in this case the value is the key, and implementations generally use the hashcode and equality operations on the items before adding them to the set.
Some implementations of Set can be sorted, generally those are referred to as SortedSet. Think of Set<T> as an equivalent to Dictionary<T,T> (and SortedSet<T> being approximate of SortedDictionary<T,T> in C# parlance.
Sorted variants are generally implemented using binary trees, whereas unsorted implementations use hashing tables. As the key is the value, most implementations only store the value itself.
Which platform / language are you using? Java?

Resources