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

Typed - functional select

Open richardbutler opened this issue 8 years ago • 3 comments

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);

richardbutler avatar Sep 12 '17 15:09 richardbutler

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

michaelwittig avatar Sep 19 '17 15:09 michaelwittig

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.

richardbutler avatar Sep 20 '17 07:09 richardbutler

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.

michaelwittig avatar Sep 20 '17 16:09 michaelwittig