Transform Data in Data Pipelines
Data pipeline functionality supports data transformation during loading to efficiently convert and clean source data for your chosen table schema. You can use two broad classes of data transformation: source field references or SQL transformation functions.
Source Field References
When you load data using a data pipeline, you reference extracted data using a special syntax named a source field reference. These expressions are either a named reference such as $my_field or a numeric field reference such as $1.
In structured data formats like JSON, more complex source field references allow you to transform the structured data into the required form. For example, you can extract an array of values from an array of nested objects with an expression such as $data.items[].price.
To learn more about transforming data with source field references, see:
Supported Transformation Functions in Data Pipelines
Data pipeline loading supports numerous SQL functions for use in transforming data during loading. You can use these transformation functions in the INTO ... SELECT portion of a pipeline. Transformation functions generally match the syntax and behavior of the function you use when you query in Ocient®. The behavior might differ from querying behavior in two ways:
- Some additional functions exist that provide behavior that does not exist in queries.
- Some existing functions have extended behavior during loading that provides important capabilities that are not in queries.
The types of transformation functions supported in loading include:
- Scalar data conversion and casting of data types
- Special loading transformation functions
- Date and time transformations
- Character data transformations
- Binary data transformations
- Array data transformations
- Logical operations transformations
- Network type functions
- Other data transformations
- Custom user-defined Pipeline Functions using Apache® Groovy™
Scalar Transformation Functions and Casting
Scalar transformation functions include constructors, scalar data conversions, and data-casting functions.
Special Data Pipeline Transformation Functions
Special data pipeline transformation functions include functions that only exist in loading, such as the METADATA function to load special data during pipeline execution.
Date and Time Transformation Functions
Date and time transformation functions provide utilities to parse, convert, or transform DATE, TIME, and TIMESTAMP values in pipelines.
For the TO_TIMESTAMP function, the Ocient formatter currently does not support variable-length sections of timestamps (i.e., the data might have a different number of fractions of seconds across records).
For example, assume this source data.
2024-01-01 12:00:00.123456
2024-01-01 12:00:00.1234
Then, you must specify the format_type as java and enter the DateTimeFormatter format string to parse the timestamps.
Character Data Transformation Functions
Character data transformation functions operate on VARCHAR data to transform a string of data.
- BINARY |
substring($order.postcode, 1, 5) as col_postcode
| |TRIM(arg1[, arg2])BTRIM(arg1[, arg2])| Trims the leading and trailing space characters (or optionally, characters specified in thearg2argument) from thearg1argument. |arg1: CHARarg2( optional) must be a CHAR of length 1. | CHAR |TRIM('__testTrimFunction__', '_') -> 'testTrimFunction'BTRIM(' testBtrimFunction ') -> 'testBtrimFunction'| |REPLACE(arg1, arg2, arg3)| Thearg1argument is the input string for the replace operation.
Thearg2argument is the pattern to replace or the target string.
Thearg3argument is the pattern for the replacement or the replacement string.
This function replaces occurrences ofarg2inarg1witharg3. |arg1: CHARarg2: CHARarg3: CHAR | CHAR |REPLACE('testReplaceFunctionXYZ', 'X', 'Z') -> 'testReplaceFunctionZYZ'| |LENGTH(arg1)CHAR_LENGTH(arg1)CHARACTER_LENGTH(arg1)| These functions perform the same operation of returning the character length of the input string.arg1is the input string.
⚠️ When you use these functions with theSUBSTRING,RIGHT, orLEFTfunction, you might experience unintended results for multi-byte characters, such as Arabic in UTF-8 if you do not cast the field reference toCHAR. | CHAR | INT |LENGTH('hello world') -> 11| |UPPER(arg1)UCASE(arg1)| Converts the characters in the input string to all uppercase characters. | CHAR | CHAR |UPPER('Hello there') -> 'HELLO THERE'| |LOWER(arg1)LCASE(arg1)| Converts the characters in the input string to all lowercase characters | CHAR | CHAR |LOWER('Obi Wan Kenobi') -> 'obi wan kenobi'| |LOCATE(arg1, arg2[, arg3])POSITION(arg1, arg2[, arg3])| Returns the index position of the first occurrence of the character valuearg1in character valuearg2.
Optionally, you can also includearg3to offset the search by the specified number of spaces. |arg1: CHARarg2: CHARarg3: LONG | INT |LOCATE('F', 'testLocateFunction') -> 11POSITION('on', 'testPositionFunction', 12) -> 19| |LEFT(arg1, arg2)| Returns the number of characters in thearg1string equal to thearg2integer value. If the integer is negative, the function returns all characters except the last number of characters as specified by thearg2value.
This function treats source field references (e.g.,$your_field) as single-byte ASCII characters by default, similar to theSUBSTRINGfunction. |arg1: CHARarg2: LONG | CHAR |LEFT('testLeftFunction', 4) -> 'test'LEFT('testLeftFunction', -4) -> 'testLeftFunc'| |RIGHT(arg1, arg2)| Returns the number of trailing characters in thearg1string equal to thearg2integer value. If the integer is negative, the function returns all characters except the first number of characters as specified by thearg2value.
This function treats source field references (e.g.,$your_field) as single-byte ASCII characters by default, similar to theSUBSTRINGfunction. |arg1: CHARarg2: LONG | CHAR |RIGHT('green tea', 3) -> 'tea'RIGHT('coffee beans', -7) -> 'beans| |TO_CHAR(value, format)| Converts the binary value specified byvalueinto a character value by performing an encode or decoding using the format value specified byformat.
|value— BINARY(N) or VARBINARYformat— CHAR with these supported values:'hex'— Encodes into a hexadecimal string with no0xprefix and lowercase letters.'base64'— Encodes into abase64string with padding. This encoding is not URL-safe and does not include line breaks.'char'— Decodes into a string with the specifiedCHARencoding, which can be values such as:'utf-8','utf-16le','utf-16be', oriso-8859-1. | CHAR |TO_CHAR(BINARY('0x6f6369656e74'), 'hex') -> '6f6369656e74'
TO_CHAR(BINARY('0x6f6369656e74'), 'utf-8') -> 'ocient'| |HEX(value)| Alias forTO_CHAR(value, 'hex')|value— BINARY(N) or VARBINARY | CHAR |HEX(BINARY('0x6f6369656e74')) -> '6f6369656e74'| |TO_HASH(value, length, format)| Converts the string value specified byvalueinto a fixed length binary value with lengh specified bylengthby encoding or decoding using the format value specified byformat. |value— CHARlength— INTformat— CHAR with these supported values:'hex'— Decodes from a hexadecimal string with optional0xprefix and case-insensitivity.'base64'— Decodes from abase64string with optional padding. This decoding is not URL-safe and does not expect line breaks.char— Encodes into a string with the specifiedCHARencoding, which can be values such as:'utf-8','utf-16le','utf-16be', oriso-8859-1. | HASH(arg2) |TO_HASH('6f6369656e74', 6, 'hex') -> 0x6f6369656e74TO_HASH('ocient', 6, 'utf-8') -> 0x6f6369656e74
| |TO_VARBINARY(value, format)| Converts the string value specified byvalueinto a variable length binary value by encoding or decoding using the format value specified byformat. | SeeTO_HASHdescription. | VARBINARY |TO_VARBINARY('6f6369656e74', 'hex') -> 0x6f6369656e74TO_VARBINARY('ocient', 'utf-8') -> 0x6f6369656e74
| |UNHEX(value)| Alias forTO_VARBINARY(value, 'hex')|value: CHAR | VARBINARY |UNHEX('6f6369656e74') -> 0x6f6369656e74|
When you use the SUBSTRING, RIGHT, and LEFT functions with Delimited or JSON formatted data sources, the Ocient System does not treat a source field reference (e.g., $your_field) as multi-byte character data. Each byte is treated as a single-byte ASCII character. To handle multi-byte character data like UTF-8 in a source field, you must cast the source field using CHAR($your_field) or use another function that returns CHAR data.
When you use the LENGTH, CHAR_LENGTH, and CHARACTER_LENGTH functions with the SUBSTRING, RIGHT, and LEFT functions, you might experience unintended results for multi-byte characters, such as Arabic in UTF-8 if you do not cast the source field reference to CHAR.
Binary Data Transformation Functions
Binary data transformation functions operate on bytes provided when you use the BINARY format type in a pipeline. These functions are typically used in processing mainframe data outputs.
Array Data Transformation Functions
Logical Operations Transformation Functions
These transformation functions execute logical operations on the data in the data pipeline.
Network Type Functions
Network type functions are also supported in loading. For example, SUBNET(IP($9),13) AS ipv6_subnet_form1 in the CREATE PIPELINE SELECT SQL statement converts the input data in the column to an IPv6-mapped IPv4 address and then computes the prefix of size 13 for that address. For the supported network type functions, see Network Type Functions.
Other Data Transformation Functions
Other data transformation functions include the extraction of values from the JSON format and miscellaneous functions such as COALESCE, which are commonly used when working with data pipelines.
DEFAULT Keyword
You can use the DEFAULT keyword to include the configured default value of a column in transformation functions.
Example
Lambda Functions
Lambda functions are a transformative tool in data pipelines, enabling declarative and highly flexible data transformations. By supporting per-element operations on arrays and nested data structures, lambda functions streamline data ingestion and reduce the need for post-processing. Their adoption enables you to handle complex, real-time data engineering scenarios natively.
Lambda functions enable you to apply custom logic to each element of an array during ingestion. They support advanced operations like filtering and aggregation. You can embed transformation logic directly in the pipeline definition. This embedding reduces the need for additional processing steps after the load.
User-Defined Data Pipeline Functions
You can create a user-defined data pipeline function using the CREATE PIPELINE FUNCTION SQL statement and Groovy. After you create data pipeline functions, you can execute them in data pipelines like any other function to transform records.
For more details, see CREATE PIPELINE FUNCTION and Data Types for User-Defined Data Pipeline Functions.
Related Links
Data Formats for Data Pipelines
Load Metadata and File-Based Partitioned Data in Data Pipelines
Data Pipeline Load of JSON Data from Kafka

