4

I am trying to run an iterative union join on a table from within a tick function according to the kdb tick architecture as follows:

table1:([]time:`timespan$();sym:`symbol$();var1:`float$());

if[not system"t";system"t 1000";
    .z.ts:{
        table2: ...
        table1:table1 uj table2 / throws non descriptive error
        `table1 uj table2 / throws type error
    }

non descriptive error:

'table1
[0] ()

I am trying to maintain a local table that keeps the last 500 or so rows (with dynamic columns) in order to run further processing. However I can't seem to update the table from within the tick function. How should one implement this functionality? Thanks

James
  • 1,260
  • 13
  • 25
  • 1
    Isn't this the same as the other question you asked? There's a few issues in your code snippet: 1. Are you trying to do the union join twice or are you just doing that for display purposes? 2. Do you not have semi-colons at the end of your statements or are you again just not showing them for display purposes? 3. You can't reference a table by name when using union join `uj` you have to reference the table by value. In other words you can't have a backtick in front of the table name, you have to use `table1:table1 uj table2;` and note that this creates a local table not a global. – terrylynch Sep 03 '19 at 07:32

2 Answers2

6

You are getting 'table1 as an error as it is not defined locally within .z.ts. In kdb if there is local assignment to a specific variable within a function, kdb references that variable locally within the function. In the example of table1 you assign it locally within .z.ts but then attempt to reference table1 which you assigned globally outside of .z.ts. To fix your issue you must assign table1 globally within .z.ts like so table1::table1 uj table2.

table1:([]time:`timespan$();sym:`symbol$();var1:`float$());

if[not system"t";system"t 1000";
    .z.ts:{
        table2: ...
        table1::table1 uj table2

Matt Moore
  • 2,705
  • 6
  • 13
3

As a general rule,

if a signal is returned that is not one of the basic errors, then it is due to scoping.

This assumes you are not giving variables names from the given list, which is the best practice for this reason. If you are following that practice, you know that if a variable name is returned, it's due to a scoping issue.

Re: scoping, kdb does not possess lexical scoping, further details on the scoping in kdb can be found here and here. However as Matt has detailed, this is due to the kdb parser being conflicted in the local/global mixed assignments

Callum Biggs
  • 1,539
  • 5
  • 13