michaelwittig / node-q

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

Typed - functional select #36

Open richardbutler opened 7 years ago

richardbutler commented 7 years ago

Hi Michael

Have you considered how this library might support functional selects (parse trees) via its serialisation capability? For example, the Q expression:

.xyz.func[`test;(`filterClause`foo)!(enlist[(=;`account;`C12345)];1b)]

could be expressed as something like this:

connection.k('.xyz.func', [
  '`test', {
    filterClause: [
      [typed.operator('='), '`account', '`C12345'] // could be one of '=', '>=', '>', 'in', etc
    ],
    foo: true
  }
], callback);
michaelwittig commented 7 years ago

Hi @richardbutler

Just by looking at the example, it seems to me that the "only" thing that is missing is the typed.operator() thing?

the rest should work.

Let's see how q serialises operators:

q)-8!(=;`a;1b)
0x01000000150000 00000003000000 66 08 f5 6100 ff 01

q)-8!(>;`a;1b)
0x0100000015000000000003000000 66 0a f5 6100 ff 01

q)-8!(in;`a;1b)
0x0100000015000000000003000000 66 17 f5 6100 ff 01

so the type of the operator seems to be 102 (66 hex) which is binary primitive according to code.kx.com

I can't really find a documentation about this data type. Do we have to map all the primitives? :)

= => 08
> => 0a
in => 17
richardbutler commented 7 years ago

On further investigation with some colleagues who know KDB far better than I do, it seems these codes will likely change from version to version. It seems that this may well break from one release to the next or, at the very least, KX don't guarantee they won't change.

michaelwittig commented 7 years ago

I think we need some insights from KX here. Unfortunately, I have no access to the internal mailing list any more. Do you have access? Otherwise I can post to to the open source list.