0

I have a bin with map as datatype and created a secondary on MAPKEYS. Now i want to run a udf with filter on MAPKEYS index. It gives the error AEROSPIKE_ERR_INDEX_NOT_FOUND.

This is my aql query:
aql> aggregate test.check_password('hii') on test.user in MAPKEYS where pids = 'test2' Error: (201) AEROSPIKE_ERR_INDEX_NOT_FOUND

whereas the normal query works
aql> select * from test.user in MAPKEYS where pids = 'test2'
returns some data

Sample data inserted for testing, in the ideal case it will be a Map of String to Object

enter image description here

Swetha
  • 87
  • 9

1 Answers1

2
aql> INSERT INTO test.user (PK, pids, test2, test1) VALUES ('k1',  MAP('{"test1": "t1", "test2": "t2", "test3":"t3", "test4":"t4", "test5":"t5"}'), "t2bin", "t1bin")
aql> INSERT INTO test.user (PK, pids, test2, test1) VALUES ('k2',  MAP('{"test1": "t1", "test3":"t3", "test4":"t4", "test5":"t5"}'), "t2b", "t1b")
aql> INSERT INTO test.user (PK, pids, test2, test1) VALUES ('k3',  MAP('{"test1": "t1", "test2":"t22", "test4":"t4", "test5":"t5"}'), "t2b", "t1b")

aql> CREATE MAPKEYS INDEX pidIndex ON test.user (pids) STRING
OK, 1 index added.

aql> select * from test.user in MAPKEYS where pids="test2"
+--------------------------------------------------------------------------------+---------+---------+
| pids                                                                           | test2   | test1   |
+--------------------------------------------------------------------------------+---------+---------+
| MAP('{"test2":"t22", "test4":"t4", "test5":"t5", "test1":"t1"}')               | "t2b"   | "t1b"   |
| MAP('{"test2":"t2", "test3":"t3", "test4":"t4", "test5":"t5", "test1":"t1"}')  | "t2bin" | "t1bin" |
+--------------------------------------------------------------------------------+---------+---------+

I inserted three records in your format, one did not have the test2 key in its map (k2). I then created the secondary index on the MAPKEY and ran the query, gave me the desired result.

AGGREGATE is used to run a stream User Defined Function on this result set of records. What is the UDF code that you want to run?

(AGGREGATE test.check_password("hii") ....implies you have a test.lua file which has a check_password() function that takes a string argument. )

You must create the secondary index on the MAP Keys first. Its reporting index not found. To check if you have the index, you can do:

aql> show indexes
+--------+--------+-----------+--------+-------+------------+--------+------------+----------+
| ns     | bin    | indextype | set    | state | indexname  | path   | sync_state | type     |
+--------+--------+-----------+--------+-------+------------+--------+------------+----------+
| "test" | "pids" | "MAPKEYS" | "user" | "RW"  | "pidIndex" | "pids" | "synced"   | "STRING" |
+--------+--------+-----------+--------+-------+------------+--------+------------+----------+
1 row in set (0.000 secs)
OK
pgupta
  • 5,130
  • 11
  • 8