问题
How do I include the PK when doing a AQL select?
Example:
SELECT * from test.users
Returns:
FirstName, LastName etc
What I really want to know is the PK or key so I can delete a row. How can I include the PK in a SELECT AQL statement.
回答1:
By default, Aerospike does not store the actual primary key in the database. It stores the 20-byte digest (hash of the key) by default. This will be a huge saving for the large keys. However, in the latest version, this can be changed by the put() operation to store the key also. But the AQL client is not enhanced yet to exploit this fact. I will file an internal ticket for this enhancement.
In the mean time...
- option-1 : you can take a backup of your data which will also dump the digests (hash of key) in base64 encoding format. You can use those digests to delete the records.
- option-2 : if you write scan code using C/Java or any API, you will get the list of digests too. You can use them to delete the records.
回答2:
To DELETE the data from the sets - To delete a record from the set, you could use scanAll API which iterates through all the records and delete. During scanCallback call it gets the digest key for each record and deletes. Here is the reference link
http://www.aerospike.com/community/labs/deleting_sets_and_data.html
Once we have extended functionality of retrieving primary index through AQL then you can retrieve primary index key which you have created but make sure you have stored key by calling sendKey attribute of WritePolicy class. SendKey sends user defined key in addition to hash digest on a record put. By default it's not sent.
回答3:
Alternative solution
create extra bin to save primary key and index it. Then you can retrieve this primary key using AQL statement.
来源:https://stackoverflow.com/questions/24611748/aql-how-to-show-pk-in-a-select