Map datatype

Registered by Ilya Sviridov on 2014-08-21

Map datatype should be implemented in similar way as well as Set data type, but store key value pairs. Key and value can be only simple data type (not a collection): String, Number or Blob. So actually we have 9 new datatypes: SSM, SNM, SBM, NSM, NNM, SBM, BSM, BNM, BBM. firs letter specifies key type, second - value type and the third one - M shows us that it is actually Map data type.

So bellow is the CreateTable request example with map data type attribute defined:
{
    "table_name": "demo_table",
    "attribute_definitions": [
        {
            "attribute_name": "hash_key",
            "attribute_type": "N"
        },
        {
            "attribute_name": "range_key",
            "attribute_type": "S"
        },
                {
            "attribute_name": "ss_map_value",
            "attribute_type": "SSM"
        }
    ],
    "key_schema": [
        {
            "attribute_name": "hash_key",
            "key_type": "HASH"
        },
        {
            "attribute_name": "range_key",
            "key_type": "RANGE"
        }
    ]
}

As well as Set data type you can't use attributes of Map data type for keys and indices. You can only store data of Map data type

Now I will show you how to put item with Map data type:

{
    "item": {
        "hash_key": {
            "N": "1"
        },
        "range_key": {
            "S": "d"
        },
        "ss_map_value": {
                "SSM": {
              "key1": "value1",
              "key2": "value2"
            }
        },
        "ns_map_value": {
                "NSM": {
              "1.1": "value1",
              "2.2": "value2"
            }
        }
    }
}

It is Put request example. Hopefully Json format is aimed to specify keys and it values so Map attribute value format is simple json.
Here you can see that we set ss_map_value predefined attribute of SSM type (attribute specified in CreateTable request example) and ns_map_value dynamically defined attribute (was absent in table schema). Dynamically created attributes are aslo implemented And you can document it too

Aslo UpdateItem request supports Map data types, (PUT, ADD and DELETE operations). PUT rewrites all map (like PutItem request), ADD - adds new items to existed map or rewrites specified keys and leave not specified non touched, DELETE - removes specified keys from map

Here is example of UpdateItem with ADD action:

{
    "attribute_updates": {
        "ss_map_value": {
            "action": "ADD",
            "value": {
                "SSM": {
                   "key1": "new_value1",
                   "key11": "value11"
                }
            }
        },
        "ns_map_value": {
            "action": "ADD",
            "value": {
                "NSM": {
                   "2.2": "new_value1",
                   "11.11": "value11"
                }
            }
        }
    },
    "key": {
        "hash_key": {
            "N": "1"
        },
        "range_key": {
            "S": "d"
        }
    }
}

And with DELETE action:

{
    "attribute_updates": {
        "ss_map_value": {
            "action": "DELETE",
            "value": {
                "SS": [
                   "key1",
                   "key11"
                ]
            }
        }
    },
    "key": {
        "hash_key": {
            "N": "1"
        },
        "range_key": {
            "S": "d"
        }
    }
}

Blueprint information

Status:
Complete
Approver:
None
Priority:
Medium
Drafter:
Ilya Sviridov
Direction:
Approved
Assignee:
Dmitriy Ukhlov
Definition:
New
Series goal:
Accepted for juno
Implementation:
Implemented
Milestone target:
milestone icon juno-3
Started by
Ilya Sviridov on 2014-08-21
Completed by
Ilya Sviridov on 2014-08-27

Related branches

Sprints

Whiteboard

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.

Subscribers

No subscribers.