Does KDB IPC support Arrays of Arrays?

I’m a bit puzzled by some behaviour I am observing in a client library which talks to KDB over IPC.

This library is able to send arrays of strings. Strings themselves are arrays of characters.

It this an exceptional case, or does KDB support serialization and deserialization of arrays of arrays in general?

To explain in more detail, KDB supports a range of datatypes. See the documentation below.

Data types | Basics | kdb+ and q documentation - kdb+ and q documentation

Broadly speaking, the datatypes can be split into 3 categories.

  • Atoms
  • Arrays of atoms
  • Dict, Table, Function, etc (special things which are not one of the above two categories)

Let us ignore the last of these 3.

When it comes to strings and symbols, a char is an atom, and a symbol is an atom. There are array versions of both of these. There is an array of char, which is the same as a string, and there is an array of symbol.

What then is an array of strings? Well, since strings are not atoms, they are arrays of char. So it seems as if KDB supports arrays of arrays of char.

This makes sense. Consider what types might be contained in a KDB table. A table has columns, which are arrays of values. The column might be of type string. But a string is an array of char, so KDB must support arrays of arrays of char.

Going back to IPC, is the ability to send arrays of arrays of char (arrays of string) an exceptional case or are arrays of arrays supported in general?

It seems that for a tabular data structure, the only case where one might need an array of array is for the case of columns of strings.

There is no such datatype for “array of array of char”.

Type 0h is used for generic lists. They can contain any combination of datatypes.

q)type ("this";`that)
0h

q)type ("this";1 2 3)
0h

q)type ("this";"that")
0h

You can get the IPC serialized representation of any object using -8!:

q)-8!("this";`that)
0x010000001e0000000000020000000a000400000074686973f57468617400

q)-8!("this";1 2 3)
0x01000000360000000000020000000a000400000074686973070003000000010000000000000002000000000000000300000000000000

q)-8!("this";"that")
0x01000000220000000000020000000a0004000000746869730a000400000074686174

Matching atoms with automatically become a strongly typed vector. Here 2 longs become a 7h vector:

q)type (1;2)
7h