AQL: how to get primary key

aql

#1

Hi,

SELECT * FROM . returns list of records(one row per key), but only shows the record’s content, how to get the primary key also? For example: INSERT INTO test.someset(PK, bin) VALUES (‘primary_key_value’, ‘bin_value’) SELECT * FROM test.someset returns only ‘bin_value’, how to get ‘primary_key_value’ also in the SELECT query? ±------------+ | bin | ±------------+ | “bin_value” | ±------------+

Thanks


#2

There is no way to do this from AQL, currently. You can do it from any of the language clients, as long as the KEY_POLICY was AS_POLICY_KEY_SEND.

I opened a feature request internally, TOOLS-551 and TOOLS-539. Keep an eye out for a mention of it in the release notes.


#3

aql now has

SET KEY_SEND TRUE

option. When you create records via AQL after setting KEY_SEND true, (default is false), the primary key is stored as a BIN and then you can retrieve it via the record.

If at the time of record creation you don’t set the key policy to SEND the KEY, Aerospike by default stores only the hash of the setname+key concatenation, called the DIGEST, which is what the Aerospike Client sends to Aerospike. So, internally, Aerospike does not store your key in any form by default.

You can see the DIGEST in Base64 in AQL by setting: SET OUTPUT JSON SET RECORD_PRINT_METADATA TRUE


#4

Sample output:

aql> set output json
aql> set record_print_metadata true
aql> select * from test.links
[
  {
    "digest": "fLBhK40CvGA9J891weFg6dbysyE=",
    "ttl": 2578390,
    "gen": 1,
    "bins": {
      "id": 1,
      "time": 1590,
      "link_type": 0,
      "visibility": 1,
      "data": "abc81"
    }
  },

Now, if you were to set key_send to true and then insert your record, you will see:

aql> set key_send true
aql> set output json
aql> set record_print_metadata true
.... Insert records ...
aql> select * from test.links
[
  {
    "PK": "key9",
    "digest": "fLBhK40CvGA9J891weFg6dbysyE=",
    "ttl": 2591983,
    "gen": 1,
    "bins": {
      "id": 1,
      "time": 1590,
      "link_type": 0,
      "visibility": 1,
      "data": "abc81"
    }
  },

#5

Is this already support on Batch Get in golang client ??

When writing the object to Aerospike, I’ve set the SendKey to true.

It’s work well for querying and Get single value by PK

But when I tried to Get Batch by PK, the PK is not sent. It’s just returning nil value