michaelwittig / node-q

Q interfacing with Node.js
MIT License
52 stars 14 forks source link

Infinty for different data types #55

Open jerry40 opened 3 years ago

jerry40 commented 3 years ago

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!

michaelwittig commented 3 years ago

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) { ... });
jerry40 commented 3 years ago

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.

michaelwittig commented 3 years ago

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

jerry40 commented 3 years ago

Interesting, I'll try this idea, thanks!