JavaScript Transform
Use the power of Javascript to modify incoming event object, replace it with a completely new event or produce multiple events based on incoming data. Also, you can use Transform to assign Data Warehouse specific SQL types for object fields, set the destination table name for each event or to skip the event altogether.
Overview
You can use modern javascript language features and built-in functions to transform an incoming event. Jitsu puts incoming events as a global variable: $
Provided javascript must return:
single object - modified incoming event or completely new object
array of objects - a single incoming event will result in multiple events in destinations
null - to skip events from processing
To override the destination table, you need to add a special property named Luden_TABLE_NAME
to the resulting events.
To override the destination SQL column type for a specific object field, you need to add an extra property with the special prefix __sql_type_
added to the name of a field to resulting events. E.g.: __sql_type_utc_time: "date"
sets SQL type date for column utc_time
NOTE Luden uses Node.js under the hood for JavaScript execution. This requires that node
and npm
executables are present in $PATH
. Furthermore, Jitsu needs node-fetch@2.6.7
and vm2@3.9.9
NPM modules in order to run JavaScript transformations and plugins. These modules are installed in a temporary directory automatically on Jitsu Server startup, but you may set NODE_PATH
environment variable with the location of node_modules
directory with node-fetch
and vm2
installed in order to use pre-installed modules. You can also use our Docker image which is already set up to run JavaScript transformations and plugins.
Server YAML Configuration
Transform is controlled via data_layout.transform_enabled
and data_layout.transform
properties of the destination object.
Example:
Modify Incoming Event
Javascript spread operator allows making a copy of an incoming event while applying some changes in just a few lines of code:
Add property to user object:
Build New Event
Collect some user properties to the new object:
Put an original event as a string payload:
Override Destination Table
Using Javascript spread operator:
Conventional way:
Override SQL Column Type
Set simple SQL types:
SQL types with extra parameters:
Some Data Warehouses support extra parameters for column types during table creation. For such cases, Transform uses the following syntax to provide data type and column type separately:
Last updated