Version:

UDF Python Examples

The following are complete examples of the implementation & execution of User-Defined Functions (UDFs) in the UDF Python API.

Example UDF (Non-CUDA) - Sum of Squares
Example of the computation of the sum of squares, summing the squares of input table columns and storing the result in an output table. This UDF does not use CUDA libraries and can be run on an Intel build of Kinetica.
Example UDF (CUDA) - CUBLAS
Example of various computations, making use of the scikit-CUDA interface for making CUDA calls from Python. This UDF uses CUDA libraries and must be run on a CUDA build of Kinetica. It also involves a Python package that must be installed before the UDF is run.

Sample Code Block

A simple distributed example of a UDF which copies data from one set of tables to another would look like the following:

from kinetica_proc import ProcData

proc_data = ProcData()

# Loop through input and output tables (assume the same number)
for in_table, out_table in zip(proc_data.input_data, proc_data.output_data):
    out_table.size = in_table.size

    # Loop through columns in the input and output tables (assume the same number and types)
    for in_column, out_column in zip(in_table, out_table):
        out_column.extend(in_column)

# Copy any parameters from the input parameter map into the output results map (not necessary for table copying, just for illustrative purposes)
proc_data.results.update(proc_data.params)
proc_data.bin_results.update(proc_data.bin_params)

# Inform Kinetica that the proc has finished successfully
proc_data.complete()