Advertisement
Guest User

Untitled

a guest
Apr 12th, 2017
562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.76 KB | None | 0 0
  1. ```
  2. docker run -d --name aerospike aerospike/aerospike-server
  3.  
  4. docker run -it aerospike/aerospike-tools aql -h $(docker inspect -f '{{.NetworkSettings.IPAddress }}' aerospike)
  5. aql> insert into test.foo (PK, foo) values ('123', 'my string')
  6. OK, 1 record affected.
  7.  
  8. aql> select * from test.foo
  9. +-------------+
  10. | foo |
  11. +-------------+
  12. | "my string" |
  13. +-------------+
  14. 1 row in set (0.052 secs)
  15. ```
  16.  
  17. When a durable delete is issued a tombstone is written.
  18.  
  19. As Durable Delete depends on accurate clocks, it is important to have clocks in sync across the cluster.
  20.  
  21.  
  22.  
  23. 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.
  24.  
  25. ```
  26. aql> insert into test.demo (PK, bin) values ('key2', 'JSON[2,1,3]')
  27. OK, 1 record affected.
  28.  
  29. aql> select * from test.demo where PK='key'
  30. +--------------------+
  31. | bin |
  32. +--------------------+
  33. | LIST('[1, 2, 3]') |
  34. +--------------------+
  35. 1 row in set (0.001 secs)
  36. ```
  37.  
  38. This example shows how maps and lists allow arbitrary nesting.
  39.  
  40.  
  41. ```
  42. aql> insert into test.demo (PK, bin) values('key3', 'JSON["string", 10, ["list", "of", "strings"], {"map": 1, "of": 2, "items": 3}]')
  43. OK, 1 record affected.
  44.  
  45. aql> select * from test.demo where PK='key3'
  46. +----------------------------------------------------------------------------------+
  47. | bin |
  48. +----------------------------------------------------------------------------------+
  49. | LIST('["string", 10, ["list", "of", "strings"], {"items":3, "of":2, "map":1}]') |
  50. +----------------------------------------------------------------------------------+
  51. 1 row in set (0.000 secs)
  52. ```
  53.  
  54.  
  55. 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.
  56.  
  57.  
  58.  
  59. ```
  60. 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"}')
  61. OK, 1 record affected.
  62.  
  63. aql> select * from test.demo where PK='1'
  64. +-------+----------------------------------------------------------------+-------------------------------------------------+
  65. | name | emails | shopping_cart |
  66. +-------+----------------------------------------------------------------+-------------------------------------------------+
  67. | "Bob" | LIST('["bob@email.com", "bob@email2.com", "bob@email3.com"]') | MAP('{"Phone":"CA", "Rope":"FL", "Car":"AZ"}') |
  68. +-------+----------------------------------------------------------------+-------------------------------------------------+
  69. 1 row in set (0.000 secs)
  70.  
  71. aql> create mapkeys index item_idx on test.demo (shopping_cart) string
  72. OK, 1 index added.
  73.  
  74. aql> create mapvalue index item_idx on test.demo (shopping_cart) string
  75. Unsupported command format with token - 'mapvalue'
  76. Type " aql --help " from console or simply "help" from within the aql-prompt.
  77.  
  78. aql> create mapvalues index item_state_idx on test.demo (shopping_cart) string
  79. OK, 1 index added.
  80.  
  81. aql> select * from test.demo in mapkeys where shopping_cart = "Rope"
  82. +-------+----------------------------------------------------------------+-------------------------------------------------+
  83. | name | emails | shopping_cart |
  84. +-------+----------------------------------------------------------------+-------------------------------------------------+
  85. | "Bob" | LIST('["bob@email.com", "bob@email2.com", "bob@email3.com"]') | MAP('{"Phone":"CA", "Rope":"FL", "Car":"AZ"}') |
  86. +-------+----------------------------------------------------------------+-------------------------------------------------+
  87. 1 row in set (0.001 secs)
  88.  
  89. aql> select * from test.demo in mapvalues where shopping_cart = "FL"
  90. +--------+----------------------------------------------------------------+-----------------------------------------------------+
  91. | name | emails | shopping_cart |
  92. +--------+----------------------------------------------------------------+-----------------------------------------------------+
  93. | "Bob" | LIST('["bob@email.com", "bob@email2.com", "bob@email3.com"]') | MAP('{"Phone":"CA", "Rope":"FL", "Car":"AZ"}') |
  94. | "Bill" | LIST('["bill@email1.com", "bill@email2.com"]') | MAP('{"ladder":"PA", "Phone":"NV", "Torch":"FL"}') |
  95. +--------+----------------------------------------------------------------+-----------------------------------------------------+
  96. 2 rows in set (0.001 secs)
  97. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement