node-q icon indicating copy to clipboard operation
node-q copied to clipboard

Infinty for different data types

Open jerry40 opened this issue 5 years ago • 4 comments

Hi!

I'm struggling with this task: sometimes I need to send timestamp as infinity (0Wp). Is it possible? Perhaps typed could take Infinity or some parameter that means "I want to deserialize it as null/inf etc... on kdb side"?

Thanks!

jerry40 avatar Sep 30 '20 10:09 jerry40

From looking at the code I don't think that it is possible at the moment.

The only workaround would be to send the whole command as a string:

con.k("something[1;0Wp]", function(err, res) { ... });

michaelwittig avatar Sep 30 '20 13:09 michaelwittig

Unfortunately I need this for .u.upd command, I create a javascript array with timestamps. I can send nulls but can't send infinity. But in theory can we have 2 additional states/flags (+Inf/-Inf) for typed data? I think it can be checked at deserialization moment and every type can turn the inf value into correct 0W value before sending it to kdb.

jerry40 avatar Sep 30 '20 13:09 jerry40

For writing, we use the JavaScript Date type which does not support the idea of infinity. So you are in a bad position.

You can switch from Date to Number (then with nano second precission) with the nanos2date flag but only when reading.

To solve this issue, you would need to make a change to support writing of a JavaScript Number (in nano seconds) as a timestamp: https://github.com/michaelwittig/node-q/blob/master/lib/c.js#L703 and you would need to allow to pass a Number into the typed api https://github.com/michaelwittig/node-q/blob/master/lib/typed.js#L158

michaelwittig avatar Sep 30 '20 13:09 michaelwittig

Interesting, I'll try this idea, thanks!

jerry40 avatar Sep 30 '20 14:09 jerry40