Can anybody please tell me how to convert N1QL results to BinaryDocuments.
My output is like below
"results": [
{ "b": "<binary (139 b)>",
“id”: “cn_billingphonenumber123_hashed|1004901933|10.12.121.140”
},
{ "b": "<binary (139 b)>",
“id”: “cn_billingphonenumber123_hashed|1004901933|10.12.121.141”
}
]
While storing I am using BinaryDocument.
Now I am using N1QL to fetch the documents, but I am getting them in Objects.
Is there any way to get BinaryDocuments as is from N1QL.
The result in N1QL is coming as String instead of Object
i.e
{ "b": "<binary (139 b)>",
“id”: “cn_billingphonenumber123_hashed|1004901933|10.12.121.141”
} "<binary (139 b)>" -> is a plain String instead of BinaryDocument.
Ah, I see. There isn’t a N1QL reply type that the client will automatically map back to the Java BinaryDocument class. I think the best way to handle that might be for the query to be on meta().id only, and then do a .get() of the key. That’ll be the most efficient way.
The only other approach would be the N1QL raw query and then processing the string back into the Java Object yourself. This is likely to be much less efficient and harder to code.
In effect it’ll be two steps. First step is to get the keys of interest with your wildcard range query, second step is to fetch the item as a BinaryDocument based on the .get() in the SDK. This can be parallelized if needed. I’d probably recommend just doing it in two steps first and if that meets your needs, that’ll be the simplest to manage.
I’d probably recommend:
Run your query and get the meta().ids of interest
Do a series of CouchbaseBucket.async().get() operations to fetch the items. Then the SDK will automatically retrieve them as BinaryDocuments.
I agree with what @ingenthr has said, this approach will give you the best performance. That said, if you still want to do this directly you need to extract the value as a string, base64decode it (I think it comes base64 encoded) and then store it in a ByteBuf to create a BinaryDocument. It’s possible, but more wasteful on GC and the approach outlined above will give you better performance with less code to write ultimately.