Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ```
- docker run -d --name aerospike aerospike/aerospike-server
- docker run -it aerospike/aerospike-tools aql -h $(docker inspect -f '{{.NetworkSettings.IPAddress }}' aerospike)
- aql> insert into test.foo (PK, foo) values ('123', 'my string')
- OK, 1 record affected.
- aql> select * from test.foo
- +-------------+
- | foo |
- +-------------+
- | "my string" |
- +-------------+
- 1 row in set (0.052 secs)
- ```
- When a durable delete is issued a tombstone is written.
- As Durable Delete depends on accurate clocks, it is important to have clocks in sync across the cluster.
- List data types are an ordered collection of values. Lists can contain values of any supported data type. List data order is maintained on writes and reads.
- ```
- aql> insert into test.demo (PK, bin) values ('key2', 'JSON[2,1,3]')
- OK, 1 record affected.
- aql> select * from test.demo where PK='key'
- +--------------------+
- | bin |
- +--------------------+
- | LIST('[1, 2, 3]') |
- +--------------------+
- 1 row in set (0.001 secs)
- ```
- This example shows how maps and lists allow arbitrary nesting.
- ```
- aql> insert into test.demo (PK, bin) values('key3', 'JSON["string", 10, ["list", "of", "strings"], {"map": 1, "of": 2, "items": 3}]')
- OK, 1 record affected.
- aql> select * from test.demo where PK='key3'
- +----------------------------------------------------------------------------------+
- | bin |
- +----------------------------------------------------------------------------------+
- | LIST('["string", 10, ["list", "of", "strings"], {"items":3, "of":2, "map":1}]') |
- +----------------------------------------------------------------------------------+
- 1 row in set (0.000 secs)
- ```
- This example illustrates use of map indexes using aql scripts. The example creates index over bin shopping_carts which is map of products and state from which it was ordered and queries the record based product name or state.
- ```
- aql> insert into test.demo (PK, name, emails, shopping_cart) values ("1", "Bob", 'JSON["bob@email.com", "bob@email2.com", "bob@email3.com"]', 'JSON{"Phone" : "CA", "Car": "AZ", "Rope":"FL"}')
- OK, 1 record affected.
- aql> select * from test.demo where PK='1'
- +-------+----------------------------------------------------------------+-------------------------------------------------+
- | name | emails | shopping_cart |
- +-------+----------------------------------------------------------------+-------------------------------------------------+
- | "Bob" | LIST('["bob@email.com", "bob@email2.com", "bob@email3.com"]') | MAP('{"Phone":"CA", "Rope":"FL", "Car":"AZ"}') |
- +-------+----------------------------------------------------------------+-------------------------------------------------+
- 1 row in set (0.000 secs)
- aql> create mapkeys index item_idx on test.demo (shopping_cart) string
- OK, 1 index added.
- aql> create mapvalue index item_idx on test.demo (shopping_cart) string
- Unsupported command format with token - 'mapvalue'
- Type " aql --help " from console or simply "help" from within the aql-prompt.
- aql> create mapvalues index item_state_idx on test.demo (shopping_cart) string
- OK, 1 index added.
- aql> select * from test.demo in mapkeys where shopping_cart = "Rope"
- +-------+----------------------------------------------------------------+-------------------------------------------------+
- | name | emails | shopping_cart |
- +-------+----------------------------------------------------------------+-------------------------------------------------+
- | "Bob" | LIST('["bob@email.com", "bob@email2.com", "bob@email3.com"]') | MAP('{"Phone":"CA", "Rope":"FL", "Car":"AZ"}') |
- +-------+----------------------------------------------------------------+-------------------------------------------------+
- 1 row in set (0.001 secs)
- aql> select * from test.demo in mapvalues where shopping_cart = "FL"
- +--------+----------------------------------------------------------------+-----------------------------------------------------+
- | name | emails | shopping_cart |
- +--------+----------------------------------------------------------------+-----------------------------------------------------+
- | "Bob" | LIST('["bob@email.com", "bob@email2.com", "bob@email3.com"]') | MAP('{"Phone":"CA", "Rope":"FL", "Car":"AZ"}') |
- | "Bill" | LIST('["bill@email1.com", "bill@email2.com"]') | MAP('{"ladder":"PA", "Phone":"NV", "Torch":"FL"}') |
- +--------+----------------------------------------------------------------+-----------------------------------------------------+
- 2 rows in set (0.001 secs)
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement