Tomat Documentation
Tomat HomeCommunity
  • 👋Introduction to Tomat
  • Getting Started
    • Product Updates
    • Beginner's Guide
    • FAQ
  • Product overview
    • Home Page
    • Exploring Data
      • Data Catalog
      • Exploring Datasets
      • Statistics Panel
    • Designing Flows
      • Creating Flows
      • Flow Designer Guide
        • Working with Canvas
        • Using Groups
        • Working with Table
      • Managing Flows
      • Demo: Building a Simple Flow
    • Executing Flows
      • Running Flows
      • Jobs overview
    • Building Reports
      • Designing Reports
      • Running Reports
      • Reports Page
    • Connectors
      • Data Storages
      • Data Sources
      • Enrichments
    • Tomat Use Cases
  • Data Transformation
    • Transforms
      • Source
      • New Empty Table
      • Output
      • Chart
      • New Column
      • If...Then
      • Rolling Functions
      • Column Type
      • Columns Edit
      • Sort
      • Filter
      • Remove Duplicates
      • Split Text
      • Extract Text
      • Find and Replace Text
      • Match Text
      • Join
      • Union
      • Group By
      • Pivot
      • Unpivot
      • To JSON
      • From JSON
      • API Call
      • AI Column
      • AI Table
    • Formulas
      • What are Formulas?
      • Math Functions
        • Abs
        • Ceiling
        • Exp
        • Floor
        • IsEven
        • IsOdd
        • Ln
        • Log
        • Log10
        • Mod
        • Pi
        • Power
        • Quotient
        • Round
        • RoundDown
        • RoundUp
        • Sign
        • Sqrt
        • Truncate
      • Trigonometric Functions
        • Acos
        • Asin
        • Atan
        • Atan2
        • Cos
        • Cot
        • Degrees
        • Radians
        • Sin
        • Tan
      • String Functions
        • Compare
        • Concat
        • Contains
        • In
        • CountMatches
        • CountMatchesRegexp
        • EndsWith
        • EndsWithRegexp
        • Extract
        • FindMatchOfString
        • FindMatchOfRegexp
        • FindMatchesOfString
        • FindMatchesOfRegexp
        • Left
        • Length
        • Lower
        • Matches
        • Pad
        • ProperCase
        • RemoveSymbols
        • RemoveWhitespaces
        • Repeat
        • Replace
        • ReplaceRegexp
        • Reverse
        • Right
        • Spaces
        • Split
        • SplitRegexp
        • StartsWith
        • StartsWithRegexp
        • Stuff
        • Substring
        • SubstringDelimiter
        • SubstringRegexpDelimiter
        • Trim
        • Upper
      • Date & Time Functions
        • Date
        • DateAdd
        • DateAdd
        • DateDiff
        • DateDiff2
        • DateFromParts
        • DateTime
        • DateTimeFromParts
        • DateTrunc
        • DayName
        • DayOfMonth
        • DayOfWeek
        • DayOfYear
        • Hour
        • Minute
        • Month
        • MonthName
        • Now
        • Quarter
        • Second
        • Time
        • TimeFromParts
        • Today
        • Week
        • Year
      • Aggregate Functions
        • Array
        • ArrayIf
        • Avg
        • AvgIf
        • Count
        • CountA
        • CountIf
        • CountUnique
        • Max
        • MaxIf
        • Median
        • MedianIf
        • Min
        • MinIf
        • Mode
        • ModeIf
        • Percentile
        • Quartile
        • StdDev
        • StdDevIf
        • Sum
        • SumIf
        • SumProduct
        • Variance
        • VarianceIf
      • Conversion Functions
        • ToArray
        • ToBoolean
        • ToDate
        • ToDateTime
        • ToDecimal
        • ToInteger
        • ToObject
        • ToTime
        • ToString
      • Misc Functions
        • At
        • IsMissing
        • RowNumber
        • Random
        • If
        • Coalesce
        • True
        • False
        • Null
        • $target
      • Window Functions
      • Custom Functions
      • Data Types
      • Supported Date Parts
      • Regex: List of Tokes
  • PRICING & BILLING
    • Plans, Subscriptions, and Credits
    • Tomat for Education
  • Integrations
    • Data Storages
      • Snowflake
      • PostgreSQL
  • Tutorials
    • Merge Columns
    • Join Types
    • Union Introduction
    • Window Functions
    • What is Unpivot?
    • JSON Format Tutorial
    • Using Regex
Powered by GitBook
On this page
  • Introduction
  • Creating a Custom Function
  • Tips and Best Practices
  1. Data Transformation
  2. Formulas

Custom Functions

PreviousWindow FunctionsNextData Types

Last updated 1 year ago

Introduction

In Tomat, 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/tomat/latest/udfs

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

Replace %username% with your actual username.

4. Restart Tomat

After saving the file, restart the Tomat 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.

463B
IsEmail.json
Custom function example