All map entries must be of the same type. Regardless of the type of the map's values, its keys are always strings.
The string "[]" is reserved and must not be used for key names.
When you declare a table field as a map, you use
the MAP()
statement. You must also declare
the map element's data types.
To define a simple two-field table where the primary key is a UID and the second field contains a map of integers, you use the following DDL statement:
CREATE TABLE myTable ( uid INTEGER, myMap MAP(INTEGER), PRIMARY KEY (uid) )
CHECK
constraints are supported for map
fields. See CHECK
for more information.
DEFAULT
and NOT NULL
constraints are not supported for map fields.
To write the map:
mmap = {"field1" : 1, "field2" : 2, "field3" : 3} row_d = {'uid' : 0, 'myMap' : mmap } try: store.put("myTable", row_d) logging.debug("Store write succeeded.") except IllegalArgumentException, iae: logging.error("Could not write table.") logging.error(iae.message) sys.exit(-1)
To read map field2:
try: primary_key_d = {"uid" : 0} row = store.get("myTable", primary_key_d) if not row: logging.debug("Row retrieval failed") else: logging.debug("Row retrieval succeeded.") ## prints '2' print row['myMap']['field2'] except IllegalArgumentException, iae: logging.error("Row retrieval failed.") logging.error(iae.message) return except KeyError, ke: logging.error("Row display failed. Bad key: %s" % ke.message)