Composite primary key as key object in python client

Hi Team,

We have a requirement wherein a composite key has to be fed as the primary key via python client. Eg : PrimaryKey={"a1": "val1", "b1": val2}

key = ('namespace', 'setname', primaryKey)

client.put(key,bins)

Error : (-2L, ‘key is invalid’, ‘src/main/conversions.c’, 952, False)

I understand that key should be either String/int/byteArr.

What is the effective way to convert the above primaryKey to ByteArray? Please note the records must be editable on GUI , which uses java client to fetch records?

Why not just concatenate it into 1 string like a1val1b1val2 as the PK string? You know the PK isn’t stored, right (at least by default…)? Seems odd to use a dict as a key so just throwing that out there…

Can’t you just convert that dict to bytes? Google yields a couple of ways on the top result to do that like https://stackoverflow.com/questions/55277431/python-convert-dictionary-to-bytes

the records must be editable on GUI , which uses java client to fetch records? im not sure what to do with this information.

Maybe you mean to store that as bins?

bin a1=val1
bin b1=val2

?

Hi Albot,

Thanks for your reply.

Seems odd to use a dict as a key so just throwing that out there

We had to design in this way to meet our requirements and cannot redesign this approach now as there are a lot of dependencies involved.

Can’t you just convert that dict to bytes?

Tried it, The records that are persisted via python client couldn’t be queried from java client, The way python generates byte array is different from what we have implemented in java code. The problem here is, During the implementation in java, we are serializing the map and converting both key value pair using ByteArrayOutputStream and getting byteArray. Which is then passed as primary key in key tuple.

Maybe you mean to store that as bins?

No, Not as separate bins.

I understand that having dict as the primary key is not advised. Is there any way to solve my problem?

Is that just a language specific issue? What about using protobuf on each side so you get the same byte array?

1 Like
© 2015 Copyright Aerospike, Inc. | All rights reserved. Creators of the Aerospike Database.