Skip to content

How to Add a UDA to a Package

Introduction

Adding a User Defined Analytics (UDA) to a package involves organizing the necessary files, defining metadata, and configuring settings to ensure smooth deployment within kdb Insights.

Steps to add a UDA to a package

This section describes how to package a UDA that counts the number of records for specified columns and tables within a selected time range. This example is based on the Creating UDAs example and outlines how to deploy the package to kdb Insights.

Prerequisites

Before deploying a package containing a UDA, ensure the following prerequisites are met:

If you are unfamiliar with packaging in kdb Insights Enterprise, it is recommended to review this process before proceeding.

Refer to the Package Lifecycle documentation and the packaging Quickstart for more details.

Step 1 - Create or choose an existing package

Use the kxi package init command to create a bare package structure.

kxi package init mypackage

Refer to the kdb Insights SDK specific documentation for guidance on deploying a UDA.

  • Add the UDA to an existing package that contains the database your UDA reads data from:

    • Refer to the Packaging guide to create the database package.

    • If the database is already configured, you can pull the database package locally, add the UDA to it, and then push the updated version to the deployment.

  • Alternatively, if want the UDA to be in a code-only package and loaded into the your database when it is deployed, you can use the kxi package init command to create a bare package structure.

    kxi package init mypackage
    

Step 2 - Create, define, and register the UDA

  1. Add code to the package

    Copy the code defined in the Creating a UDA section into a myUDA.q file in the mypackage/src folder within the package. This step adds the UDA to the package and registers it with the DAPs and Aggregator.

  2. Add entrypoints for the UDA

    In the package, specify entrypoints labeled data-access and aggregator to ensure that the UDA is loaded by the Data Access and Aggregator processes. To add these entrypoints, use the following kxi package add commands:

    kxi package add --to mypackage entrypoint --name aggregator --path src/myUDA.q
    kxi package add --to mypackage entrypoint --name data-access --path src/myUDA.q
    

    Running the above kxi package add commands ensures that src/myUDA.q is included in the entrypoints section of the manifest, as shown:

    entrypoints:
        default: init.q
        data-access: src/myUDA.q
        aggregator: src/myUDA.q
    

Step 3 - Load the UDA

To complete the deployment of the UDA, you must load it into the processes that utilize it. Follow the instructions below:

Refer to the Installing UDAs on kdb Insights SDK guide for details on setting environment variables to locate and load the package.

Refer to the Installing UDAs on kdb Insights Enterprise guide to configure environment variables in the database package to locate and load the UDA.