I'm a huge fan of CouchDB and am completely in love with map functions that emit more than once per document. I am wondering if something marginally similar can be achieved in DynamoDB, by using a string or number set type as part of a hash-and-range primary key, either as the hash or range attribute, so that the same item can be queried in multiple ways.
Thanks!
DynamoDB supports the Java Set , List , and Map collection types. The following table summarizes how these Java types map to the DynamoDB types. BOOL (Boolean type), 0 or 1. S (string type).
There are two types of primary keys in DynamoDB: Partition key: This is a simple primary key. If the table has only a partition key, then no two items can have the same partition key value. Composite primary key: This is a combination of partition key and sort key.
Yet a DynamoDB table is not totally without form. When creating a DynamoDB table, you must specify a primary key. Each item that you write into your table must include the primary key, and the primary key must uniquely identify each item.
DynamoDB supports three data types (number, string, and binary), in both scalar and multi-valued sets. It supports document stores such as JSON, XML, or HTML in these data types. Tables do not have a fixed schema, so each data item can have a different number of attributes.
Interesting question - I'm afraid a code inspection and/or test will be in order, but I doubt it:
While the Amazon DynamoDB Data Types support String and Number Sets and the API for CreateTable allows submitting the set types as well for AttributeType of course (its just a string parameter after all), there is no notion of this nowhere, none of their samples does this and the CreateTable UI in the AWS Management Console explicitly limits the type to either String or Number for both hash and range key attributes as well (see the first image in Amazon DynamoDB - Internet-Scale Data Storage the NoSQL Way).
I think someone mentioned in the announcement webcast that they are starting with the listed Primary Key concepts, but might consider expanding this in the future (not 100% positive on me recalling this correctly though).
Set dataypes are not supported as primary key currently indeed, see the API docs for class KeySchemaElement
:
/**
* Sets the value of the AttributeType property for this object.
* <p>
* <b>Constraints:</b><br/>
* <b>Allowed Values: </b>S, N
*
* @param attributeType The new value for the AttributeType property for this object.
*
* @see ScalarAttributeType
*/
public void setAttributeType(String attributeType) {
this.attributeType = attributeType;
}
Modifying the Table Example yields the expected exception accordingly:
INFO: Received error response: Status Code: 400, AWS Service: AmazonDynamoDB, AWS Request ID: XXXXXXXX, AWS Error Code: ValidationException, AWS Error Message: 1 validation error detected: Value 'SS' at 'keySchema.hashKeyElement.attributeType' failed to satisfy constraint: Member must satisfy enum value set: [N, S] Failed to create table TestTable
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