{} Real-time UDFs in q

Real-time UDF functions in q

  • take either no arguments, or a 2-list: (tableName;tableData)
  • have access to the get* APIs, that operate on a local set of data
  • should return a table; if the result is not a table it will be wrapped as a 1×1 table with column name result

Examples

With arguments:

{[tabName;data] select avg price from data}

With no arguments, using getTicks API:

{[] select avg price from getTicks`symList`assetClass`dataType!`VOD.L`equity`trade}

Trigger functions

Trigger functions

  • operate on a table to determine whether a UDF should be run
  • take a single argument, the table listed in the trigTab field
  • return a boolean atom: whether to run the UDF or not

Example:

{[data] `mySym in data`sym}

In this example, we would execute our UDF if the trigTab contained the symbol `mySym.

Initialization functions

Initialization functions are run on boot of the UDF worker nodes to prepare the process for UDF execution. They are useful for one-time loads of configuration, libraries, or reference data. Initialization functions take no arguments.

Example:

{[]
    system"l ",getenv[`UDF_LIBS_DIR],"/myDependency.q";
    .myUDF.referenceTable:([]sym:`a`b;num:1 2); }

In this example, we load a q script and set a table that we can later reference in a namespace. Dependencies (such as the q script in the example above) can be placed in the UDF_LIBS_DIR which is located in the udfdir. Dependencies will then be included when the UDF package is exported via the command line interface.

  • ml.q (KX Machine Learning library)
  • Pandas (Python library)

Recommended dependencies enable smoother conversion between q tables and Python, as in the pre-execution function example above. New UDFs can be added to the system and managed with

Querying results

Outputs of real-time UDFs can be accessed through the getUDF API call.