Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does DynamoDB support using one of the set datatypes in a table's primary key?

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!

like image 253
Hristo Avatar asked Jan 19 '12 12:01

Hristo


People also ask

Which data types are supported when configuring a DynamoDB primary key?

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).

How many types of primary keys does DynamoDB support?

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.

Does DynamoDB need a primary 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.

What are three types of data types offered by DynamoDB?

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.


1 Answers

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).


Update: inspection/test result

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

like image 58
Steffen Opel Avatar answered Jan 01 '23 13:01

Steffen Opel