Custom Functions

Introduction

In Tabula.io, users can create and utilize custom functions to enhance their data manipulation capabilities. While the platform lacks a direct user interface for this feature, custom functions can be easily implemented through a JSON configuration.

Creating a Custom Function

1. Define the Function in JSON Format.

Custom functions are defined in a specific JSON structure. Use the following template for a custom function and save it as YourFunctionName.json file:

jsonCopy code{
  "signature": {
    "name": "FunctionName",
    "typeParameters": [],
    "valueParameters": [
      {
        "name": "Parameter1",
        "typeSet": [{"type":"PrimitiveType","name":"String"}],
        "argumentDescription": "Parameter1 description"
      },
      {
        "name": "Parameter2",
        "typeSet": [{"type":"PrimitiveType","name":"String"}],
        "argumentDescription": "Parameter1 description"
      }
    ],
    "returnType": {"type":"PrimitiveType","name":"String"}
  },
  "body": "FindMatchOfRegexp(Parameter1, \"(?<=\\?\" | Parameter2 | \"=|&\" | Parameter2 | \"=)[^&#]*\", false)",
  "description": "Function description"
}

2. Fill template parameters

Function Name:

name: Enter the name of your custom function.

Function Parameters (Arguments):

valueParameters: List the parameters your function will use.

  • name: Specify the name of each parameter.

  • typeSet: Define the type of each parameter. Possible types include String, Integer, Double, Date, DateTime, Time, Object, Array, and AnyType.

  • argumentDescription: Describe each parameter to explain its purpose and usage.

Return Type:

returnType: Indicate the type of value your function returns. Options include String, Integer, Double, Date, DateTime, Time, Object, Array, AnyType.

Function Description:

description: Write a brief description of what your function does and its intended use.

Function Body (Expression):

body: Input the expression that defines your function's logic. It's recommended first to test the expression using the New Column node for validation, then copy it to the file. Remember to add additional escape characters (\) before quotes (") and backslashes (\) in the expression.

For instance, an email validation expression in the New Column node might be:

 Matches(EmailColumnName, "^[a-z0-9.!#$%&*+/=?^_`{|}~-]+@[a-z0-9-]+(?:\.[a-z0-9-]+)*\.[a-z]{2,}$", false)

In the JSON file, it should be formatted as:

"body": "Matches(EmailColumnName, \"^[a-z0-9.!#$%&‘*+/=?^_`{|}~-]+@[a-z0-9-]+(?:\\.[a-z0-9-]+)*\\.[a-z]{2,}$\", false)"

3. Saving and Using the Custom Function

Save the File: Store the JSON file in the appropriate directory:

  • For Mac OS: /Users/%username%/Library/Application Support/tabula/latest/udfs

  • For Windows: C:\Users\%username%\AppData\Roaming\tabula\latest\udfs

Replace %username% with your actual username.

4. Restart Tabula

After saving the file, restart the Tabula application for the custom function to be recognized and available.

Tips and Best Practices

  • Thorough Testing: Before implementing your custom function in critical data flows, test it extensively to ensure it behaves as expected.

  • Clear Naming Conventions: Use clear and descriptive names for your functions and parameters for easy understanding and maintenance.

  • Comprehensive Descriptions: Provide detailed descriptions for your functions, outlining their purpose and how they work, to assist other users.

Last updated