Flink CDC Built-in Functions
Use these built-in functions in transform module expressions for Flink CDC data ingestion jobs.
Built-in functions
Flink CDC provides built-in functions for use directly in projection and filter expressions within the transform module.
Arithmetic functions
|
Function |
Description |
|
numeric1 + numeric2 |
Returns the sum of numeric1 and numeric2. |
|
numeric1 - numeric2 |
Returns numeric1 minus numeric2. |
|
numeric1 * numeric2 |
Returns numeric1 multiplied by numeric2. |
|
numeric1 / numeric2 |
Returns numeric1 divided by numeric2. |
|
numeric1 % numeric2 |
Returns numeric1 modulo numeric2. |
|
ABS(numeric) |
Returns the absolute value of numeric. |
|
CEIL(numeric) |
Returns the smallest integer greater than or equal to numeric. |
|
FLOOR(numeric) |
Returns the largest integer less than or equal to numeric. |
|
ROUND(numeric, int) |
Returns a numeric value rounded to n decimal places. |
|
UUID() |
Generates a globally unique identifier (UUID) string, such as 3d3c68f7-f608-473f-b60c-b0c44ad4cc4e. Uses RFC 4122 type 4 to generate pseudo-random UUIDs. |
Time functions
|
Function |
Description |
|
LOCALTIME |
Returns the local time in the current time zone. Return type: |
|
LOCALTIMESTAMP |
Returns the local timestamp in the current time zone. Return type: |
|
CURRENT_TIME |
Returns the local time in the current time zone. Equivalent to LOCALTIME. |
|
CURRENT_DATE |
Returns the local date in the current time zone. |
|
CURRENT_TIMESTAMP |
Returns the local timestamp in the current time zone. Return type: |
|
NOW() |
Returns the local timestamp in the current time zone. Equivalent to CURRENT_TIMESTAMP. |
|
DATE_FORMAT(timestamp, string) |
Formats the input timestamp using the specified format string. Note
The format string is compatible with Java SimpleDateFormat. |
|
DATE_FORMAT_TZ(timestamp, string) |
Formats the input timestamp as a string in the specified time zone. Note
|
|
DATE_FORMAT_TZ(timestamp, string1[, string2]) |
Converts the input timestamp to a string formatted as string1 in the time zone string2. Note
The format string is compatible with Java SimpleDateFormat. |
|
TIMESTAMPADD(timeintervalunit, interval, timepoint) |
Returns the timepoint after adding interval (in timeintervalunit units) to timepoint. Valid values for timeintervalunit: SECOND, MINUTE, HOUR, DAY, MONTH, YEAR. |
|
DATE_ADD(timestamp, integer, string) |
If timestamp has no time zone, converts it to local time in the time zone specified by string, then adds the number of days specified by integer, and returns the result as a string in yyyy-MM-dd format. |
|
TIMESTAMPDIFF(timepointunit, timepoint1, timepoint2) |
Returns the difference between timepoint1 and timepoint2 in timepointunit units. Valid values for timepointunit: SECOND, MINUTE, HOUR, DAY, MONTH, YEAR. |
|
TO_DATE(string1[, string2]) |
Parses the date string string1 into a DATE type using format string string2. Note
If format string string2 is not specified, the default format is |
|
TO_TIMESTAMP(string1[, string2]) |
Parses the timestamp string string1 into a timezone-free TIMESTAMP type using format string string2. Note
If format string string2 is not specified, the default format is |
|
TO_TIMESTAMP_LTZ(string1[, string2][, string3]) |
Parses the timestamp string string1 into a TIMESTAMP_LTZ type in time zone string3 using format string string2. Note
|
|
TO_TIMESTAMP_LTZ(bigint[, integer]) |
Converts a timestamp (bigint) to TIMESTAMP_LTZ with the precision specified by integer. Note
The integer must be 0 or 3. |
|
FROM_UNIXTIME(numeric[, string]) |
Converts numeric (seconds since 1970-01-01 00:00:00 UTC) to a timestamp string in the format specified by string. Note
If format string string is not specified, the default format is |
|
UNIX_TIMESTAMP() |
Returns the current UNIX timestamp in seconds. |
|
UNIX_TIMESTAMP(string1[, string2]) |
Converts the given datetime string string1 to another datetime format string2. |
When evaluating projection and filter expressions, each subexpression returns the same time point. For example, NOW() AS t1, NOW() AS t2, NOW() AS t3 always returns the same timestamp for t1, t2, and t3, regardless of evaluation order or timing.
String functions
|
Function |
Description |
|
string1 || string2 |
Returns the concatenation of string1 and string2. Note
Note: this is the string concatenation operator, not the logical OR operator. |
|
CHAR_LENGTH(string) |
Returns the number of characters in string. |
|
UPPER(string) |
Returns string in uppercase. |
|
LOWER(string) |
Returns string in lowercase. |
|
TRIM(string1) |
Removes leading and trailing whitespace from string1. |
|
REGEXP_REPLACE(string1, string2, string3) |
Replaces all substrings in string1 that match the regular expression string2 with string3. For example, |
|
SUBSTRING(string FROM integer1 [ FOR integer2 ]) |
Returns the substring of string starting at position integer1 and ending at position integer2. Note
If |
|
CONCAT(string1, string2,…) |
Returns a new string formed by concatenating string1, string2, and so on. For example, |
Type conversion functions
You can use the CAST(<expression> AS <type>) syntax for explicit type conversion. The following conversion paths are supported:
|
Source type |
Target type |
Description |
|
Any |
VARCHAR Important
Do not use |
Fields of any type can be converted to strings. |
|
NUMERIC STRING |
BOOLEAN |
Any string literal that is not '0' or 'FALSE' is converted to 'TRUE'. |
|
NUMERIC STRING |
TINYINT |
The result is truncated to the range -128 to 127. |
|
NUMERIC STRING |
SMALLINT |
The result is truncated to the range -32768 to 32767. |
|
NUMERIC STRING |
INTEGER |
The result is truncated to the range -2147483648 to 2147483647. |
|
NUMERIC STRING |
BIGINT |
The result is truncated to the range -9223372036854775808 to 9223372036854775807. |
|
NUMERIC STRING |
FLOAT |
|
|
NUMERIC |
DOUBLE |
|
|
NUMERIC |
DECIMAL |
|
|
STRING TIMESTAMP_TZ TIMESTAMP_LTZ |
TIMESTAMP |
The string must be in a valid ISO_LOCAL_DATE_TIME format. |
Comparison functions
These functions return NULL when any input parameter is NULL, unless otherwise noted.
|
Function |
Description |
|
value1 = value2 |
Returns TRUE if value1 equals value2. Otherwise, returns FALSE. |
|
value1 <> value2 |
Returns TRUE if value1 does not equal value2. Otherwise, returns FALSE. |
|
value1 > value2 |
Returns TRUE if value1 is greater than value2. Otherwise, returns FALSE. |
|
value1 >= value2 |
Returns TRUE if value1 is greater than or equal to value2. Otherwise, returns FALSE. |
|
value1 < value2 |
Returns TRUE if value1 is less than value2. Otherwise, returns FALSE. |
|
value1 <= value2 |
Returns TRUE if value1 is less than or equal to value2. Otherwise, returns FALSE. |
|
value IS NULL |
Returns TRUE if value is NULL. Otherwise, returns FALSE. |
|
value IS NOT NULL |
Returns TRUE if value is not NULL. Otherwise, returns FALSE. |
|
value1 BETWEEN value2 AND value3 |
Returns TRUE if value1 is between value2 and value3. Otherwise, returns FALSE. |
|
value1 NOT BETWEEN value2 AND value3 |
Returns TRUE if value1 is not between value2 and value3. Otherwise, returns FALSE. |
|
string1 LIKE string2 |
Returns TRUE if the regular expression defined by string2 can be found in string1 (substring matching). Otherwise, returns FALSE. |
|
string1 NOT LIKE string2 |
Returns TRUE if the regular expression defined by string2 cannot be found in string1. Otherwise, returns FALSE. |
|
value1 IN (value2 [, value3]* ) |
Returns TRUE if value1 exists in the list [value2, value3, ...]. Otherwise, returns FALSE. |
|
value1 NOT IN (value2 [, value3]* ) |
Returns TRUE if value1 does not exist in the list [value2, value3, ...]. Otherwise, returns FALSE. |
LIKE and NOT LIKE have matching semantics that differ from the SQL standard in two important ways:
• The pattern is a Java regular expression, not the SQL % and _ wildcards. % and _ are treated as regex literals and do not act as wildcards.
• Substring matching (Java regex find() semantics): the pattern only needs to appear at some position in the string to return TRUE; full-string matching is not required. For example, col LIKE 'V.*' matches V123, ABC_V, ABC_V123, and any string containing V, which is equivalent to SQL col LIKE '%V%'.
To achieve semantics strictly equivalent to SQL LIKE, use the anchors ^ and $ to constrain matching positions, as shown below:
|
SQL syntax |
Equivalent CDC regex |
Meaning |
|
|
|
Starts with HSRS (HSRS can be followed by nothing) |
|
|
|
Ends with HSRS |
|
|
|
Contains HSRS |
|
|
|
Exactly equals HSRS |
|
|
|
H followed by any single character, then SRS |
|
(No direct SQL equivalent) |
|
Starts with V followed by at least one character |
Logical functions
|
Function |
Description |
|
boolean1 OR boolean2 |
Returns TRUE if boolean1 or boolean2 is TRUE. |
|
boolean1 AND boolean2 |
Returns TRUE if boolean1 and boolean2 are both TRUE. |
|
NOT boolean |
Returns FALSE if boolean is TRUE. Returns TRUE if boolean is FALSE. |
|
boolean IS FALSE |
Returns FALSE if boolean is TRUE. Returns TRUE if boolean is FALSE. |
|
boolean IS NOT FALSE |
Returns TRUE if boolean is TRUE. Returns FALSE if boolean is FALSE. |
|
boolean IS TRUE |
Returns TRUE if boolean is TRUE. Returns FALSE if boolean is FALSE. |
|
boolean IS NOT TRUE |
Returns FALSE if boolean is TRUE. Returns TRUE if boolean is FALSE. |
Conditional functions
|
Function |
Description |
|
CASE value WHEN value1_1 [, value1_2]* THEN RESULT1 (WHEN value2_1 [, value2_2 ]* THEN result_2)* (ELSE result_z) END |
Checks whether value equals each value in the WHEN clauses in order. Returns the result of the first matching clause. If no clause matches, returns the ELSE value. If there is no ELSE clause, returns NULL. |
|
CASE WHEN condition1 THEN result1 (WHEN condition2 THEN result2)* (ELSE result_z) END |
Checks each condition in the WHEN clauses in order. Returns the result of the first true condition. If no clause matches, returns the ELSE value. If there is no ELSE clause, returns NULL. |
|
COALESCE(value1 [, value2]*) |
Returns the first non-NULL value in the list [value1, value2, ...]. Returns NULL if all values are NULL. |
|
IF(condition, true_value, false_value) |
Returns true_value if condition is true. Otherwise, returns false_value. |
JSON functions
VARIANT types and related functions are available in data ingestion jobs starting with Ververica Runtime (VVR) 11.6.
|
Function |
Description |
|
PARSE_JSON(json_string[, allow_duplicate_keys]) |
Parses a JSON string into a VARIANT. Throws an error if the JSON string is invalid. To return NULL instead of throwing an error, use the When the input contains duplicate keys, the parser keeps the last field with the same key if allowDuplicateKeys is true, or throws an error if false. Default: allowDuplicateKeys = false. |
|
TRY_PARSE_JSON(json_string[, allow_duplicate_keys]) |
Parses a JSON string into a VARIANT. Returns NULL if the JSON string is invalid. To throw an error instead of returning NULL, use the When the input contains duplicate keys, the parser keeps the last field with the same key if allowDuplicateKeys is true, or throws an error if false. Default: allowDuplicateKeys = false. |
|
JSON_EXISTS(json_string, json_path) |
Checks whether the specified path exists in the JSON string. Example:
The path supports the following symbols:
Note
Supported only in Ververica Runtime (VVR) 11.7 and later. |
|
JSON_VALUE(json_string, json_path) |
Extracts the object at the specified path from the JSON string. Supports both scalar values and object values. Note
Supported only in Ververica Runtime (VVR) 11.7 and later. |
Hash functions
Hash functions are available in data ingestion jobs starting with Ververica Runtime (VVR) 11.6.
|
Function |
Description |
|
MD5(string) |
Returns the MD5 hash of string as a 32-character hexadecimal string. If string is |
|
SHA1(string) |
Returns the SHA-1 hash of string as a 40-character hexadecimal string. If string is |
|
SHA224(string) |
Returns the SHA-224 hash of string as a 56-character hexadecimal string. If string is |
|
SHA256(string) |
Returns the SHA-256 hash of string as a 64-character hexadecimal string. If string is |
|
SHA384(string) |
Returns the SHA-384 hash of string as a 96-character hexadecimal string. If string is |
|
SHA512(string) |
Returns the SHA-512 hash of string as a 128-character hexadecimal string. If string is |
|
SHA2(string, hashLength) |
Returns a hash using a SHA-2 family function (SHA-224, SHA-256, SHA-384, or SHA-512). The first parameter string is the string to hash. The second parameter hashLength specifies the bit length of the result: 224, 256, 384, or 512. If string or hashLength is |
AI functions
Starting with Ververica Runtime (VVR) 11.8.0 preview2, the Transform module of CDC YAML supports AI functions in projection expressions. Before you use these functions, activate Flink AI service (built-in models).
|
Function |
Signature |
Return fields |
Purpose |
|
AI_COMPLETE |
|
|
General-purpose text generation. |
|
|
|
Text classification. |
|
|
|
|
Text translation. |
|
|
|
|
Text summarization. |
|
|
|
|
Sentiment analysis. |
|
|
|
|
Structured information extraction. |
|
|
|
|
Sensitive information masking. |
|
|
AI_EMBED |
|
|
Converts text into vectors. This function is suitable for multimodal dataset labeling, RAG filtering and retrieval, feature Backfill, and similar scenarios. Note
Available in Ververica Runtime (VVR) 11.9 and later. |
|
AI_IMAGE_COMPLETE |
|
|
Generates text based on an image and a prompt. This function is suitable for image content recognition, information extraction, classification, and similar scenarios. Note
Available in Ververica Runtime (VVR) 11.9 and later. |
|
AI_IMAGE_EMBED |
|
|
Converts images into vectors. This function is suitable for multimodal dataset labeling, RAG filtering and retrieval, feature Backfill, and similar scenarios. Note
Available in Ververica Runtime (VVR) 11.9 and later. |
In a projection expression, use ['fieldName'] to access a return field. Example: AI_COMPLETE('mymodel', content, '')['result'].
For detailed instructions and examples of AI functions, see AI intelligent text annotation and Configure and call AI Function.
Multimodal functions
|
Function signature |
Return type |
Description |
|
FETCH_CONTENT(uri) |
BYTES |
Retrieves binary content from the specified URI. By default, a failed HTTP request is retried 3 times. Note
Supported only in Ververica Runtime (VVR) 11.8 and later. |
|
FETCH_CONTENT(uri, httpRetryCount) |
BYTES |
Retrieves binary content from the specified URI and specifies the number of retries for HTTP requests. Note
Supported only in Ververica Runtime (VVR) 11.8 and later. |
|
FFMPEG_VIDEO_FILTER(content, filters) |
BYTES |
Applies FFmpeg video filters to an image or video. Images are output in PNG format by default, and videos are output in MP4 format by default. Note
Supported only in Ververica Runtime (VVR) 11.9 and later. |
|
FFMPEG_VIDEO_FILTER(content, filters, outputExtension) |
BYTES |
Applies FFmpeg video filters to an image or video and specifies the output format. Note
Supported only in Ververica Runtime (VVR) 11.9 and later. |
|
FFMPEG_AUDIO_FILTER(content, filters) |
BYTES |
Applies FFmpeg audio filters to an audio stream. The output is in WAV format by default. Note
Supported only in Ververica Runtime (VVR) 11.9 and later. |
|
FFMPEG_AUDIO_FILTER(content, filters, outputExtension) |
BYTES |
Applies FFmpeg audio filters to an audio stream and specifies the output format. Note
Supported only in Ververica Runtime (VVR) 11.9 and later. |
Collection functions
Starting with Ververica Runtime (VVR) 11.10, you can use the following collection functions in projection and filter expressions.
|
Function |
Description |
|
|
Constructs an ARRAY from the given values. All elements must be implicitly convertible to a common type. For example, |
|
|
Constructs a MAP from alternating keys and values. The arguments must contain at least one key-value pair, and the total number of arguments must be even. Otherwise, an error is returned. Keys and values are implicitly converted to their respective common types. If duplicate keys exist, later values overwrite earlier ones. |
|
|
Constructs a ROW from the given values. Anonymous fields are named |
|
|
Returns the number of elements in an ARRAY or the number of entries in a MAP. Returns NULL if the input is NULL. |
|
|
Checks whether an ARRAY contains the specified value. Numeric values are compared by numeric value (for example, elements |
|
|
Returns the position of the first matching element in an ARRAY (starting from 1). Returns |
|
|
Returns the single element of an ARRAY that contains exactly one element. Returns NULL for an empty array or NULL input. Throws an exception if the array contains more than one element. |
Access nested data types
Starting with Ververica Runtime (VVR) 11.6, for nested data fields of type ARRAY, MAP, VARIANT and similar types, you can use the [] operator to access specific elements.
Access methods
The following examples use a nested field named nest_col. The access syntax depends on its internal data format:
-
Array format (ARRAY/VARIANT)
Description: Usenest_col[integer]to retrieve the element at the specified index (indexing starts at 1).Example: If
nest_colis[{"id": 1, "name": "Project A"}, {"id": 2, "name": "Project B"}].Operation:
nest_col[1]returns{"id": 1, "name": "Project A"}. -
Hash table format (MAP/VARIANT)
Description: Use
nest_col[string]to retrieve the value for the specified key.Example: If
nest_colis{"id": 1, "name": "Project A"}.Operation:
nest_col['id']returns1.
For complex nested data, you can chain the [] operator to access deeply nested elements.
Example: If nest_col is [{"id": 1, "name": "Project A"}, {"id": 2, "name": "Project B"}].
Operation: nest_col[1]['id'] returns 1.
Return types
The return type of the [] operator for retrieving a specific element depends on the internal type of the original nested field:
-
The original field is of type
ARRAY[T]with element typeT
The return type ofnest_col[integer]for the element at the specified index isT. -
The original field is of type
MAP<K, V>, where the key type isKand the value type isTThe return type of
nest_col[string]for the element at the specified key isV. -
The original field is of type
VARIANTThe return type of
nest_col[integer]ornest_col[string]for accessing an element is alwaysVARIANT.