How to Batch Get Object?

I’ve spent the last couple of days trying to find a good solution for batch get object. I noticed in the client there is BatchGet but no BatchGetObject.

The problem I’ve run into is not being able to store floats using Put, so I have to use PutObject, which requires me to use GetObject. However there is no BatchGetObject so I’d have to fire off a new request for potentially hundreds of different ids - which is not a great solution.

I tried to use PutObject and then Get, but then you lose the data type unpacking that you get with GetObject. I attempted to create a decoder myself using reflection, only to discover that yes, the values are all stored as ints and there’s no obvious way to turn them back into floats without the unexported unpacker.

It appears to me that the client forces you to make one of two choices: 1, use Get/Put and have batch get, but forgo the ability to store floats; or 2, use GetObject/PutObject, but completely lose the ability to batch get.

I would love it if someone could clarify this or point me in the right direction if I am missing something obvious.

Thanks

Hi,

The reason there is no BatchGet is that I was waiting to get some feedback from the community to see if the direction I was going was useful to others. BatchGet and Scan/Query would follow after a positive feedback. Since nobody came back (and I got one negative feedback that I was making the library too complicated), I didn’t follow through.

In your case, as a workaround before I add *Obj methods to other API, you can get your bins as integer, convert them to byte, and reconvert the byte to floats.

Thanks Khosrow, that is good to know.

To clarify - Should I be using a combination of PutObject and Get+byte conversion, or Put+Get+byte conversion?

My attempts to convert yield 0:

float64(byte(record.Bins["tfloat32"].(int)))

Many thanks

edit:

I mention it because the returned value for a float32 of 6.235 is 4618706004496875520, which overflows.

You can use PutObj for convenience, but a lot of it will be gone with raw Get in the end.

To encode your int into float64:

f64 := math.Float64frombits(uint64(rec.Bins["floatBin"].(int)))
3 Likes

That works perfectly, thanks so much Khosrow!