2

I need to send bulks of K object to KDB via the C interface At the moment all my strings are sent as symbols which is not ideal.

I would like to replace all symbols by standard char arrays

For Symbols I did it this way

// table_def:([] name: `symbol$())

K m_data = ktn(0, 1); // 1 column
kK(m_data)[0] = ktn(KS, 100); // 100 rows in bulk

for (unsigned i = 0; i < 100; i++) {
    kS(kK(m_data)[0])[i] = ss("abc");
}

But not sure how to create the Bulk structure for char arrays, This is what I tried.

// table_def:([] name: `char$())

K m_data = ktn(0, 1); // 1 column
kK(m_data)[0] = ktn(KC, 100); // 100 rows in bulk

for (unsigned i = 0; i < 100; i++) {
    kS(kK(m_data)[0])[i] = ss("abc"); // this fail with a `type error
    kC(kK(m_data)[0])[i] = kp("abc"); // this fail because kC expect a char not a char*

Any help would be appreciated

Pierre Lacave
  • 2,608
  • 2
  • 19
  • 28

1 Answers1

3

A string column in kdb is considered as a general type (list of list of char).

q)type each flip ([]a:string`aa`bb;b:"ab")
a| 0       <-- string column
b| 10      <-- char column

So your kdb table definition should've been

// table_def:([] name: ())

Your previous definition is expecting the column values to be atom chars (which is not what you want), hence the 'type error I believe.

So when creating K object in your C code, data type in your first column should be mixed type:

kK(m_data)[0] = ktn(0, 100);

From there, create the values for each rows:

kK(kK(m_data)[0])[i] = kp("abc");

Can you try the above and see how it goes? Don't have a working example here at the moment :(

WooiKent Lee
  • 1,301
  • 6
  • 4