Skip to main content

Functions

The sections below describe the SQLite functions you can use to build an expression with the Expression builder. The Expression builder divides the functions into the following categories:

Strings

The following table describes the string functions used by the Expression Builder in Qlik Replicate .

String functions

Function

Description

length(x)

For a string value x, the length(x) function returns the number of characters (not bytes) in x before to the first NULL character.

If x is NULL then length(x) is NULL. If x is numeric then length(X) returns the length of a string representation of X.

like(x,y,z)

The like() function is used to implement the "Y LIKE X [ESCAPE Z]" expression. The ESCAPE (z) clause is optional. If there is a z clause, then the like() function is invoked with three arguments. Otherwise, it is invoked with two arguments.

typeof(x)

The typeof(x) function returns a string that indicates the datatype of the expression x: null, integer, real, text, or BLOB.

LOBs

The following table describes the LOB functions used by the Expression Builder in Qlik Replicate .

LOB functions

Function

Description

hex(x)

The hex() function receives an argument as a BLOB and returns an upper-case hexadecimal string version of the BLOB content.

randomblob(N)

The randomblob(N) function returns an N-byte BLOB that contains pseudo-random bytes. If N is less than 1 then a 1-byte random BLOB is returned.

zeroblob(N)

The zeroblob(N) function returns a BLOB that consists of N bytes of 0x00.

Numeric

The following table describes the numeric functions used by the Expression Builder in Qlik Replicate .

Numeric functions

Function

Description

abs(x)

The abs(x) function returns the absolute value of the numeric argument X. Abs(x) returns NULL if x is NULL. Abs(x) returns 0.0 if x is a string or BLOB that cannot be converted to a numeric value.

random()

The random() function returns a pseudo-random integer between -9223372036854775808 and +9223372036854775807.

round(x,y)

The round(x,y) function returns a floating-point value x rounded to y digits to the right of the decimal point. If there is no value for y, it is assumed to be 0.

max(x,y...)

The multi-argument max() function returns the argument with the maximum value, or returns NULL if any argument is NULL. The multi-argument max() function searches its arguments from left to right for an argument that defines a collating function and uses that collating function for all string comparisons. If none of the arguments to max() define a collating function, then the BINARY collating function is used. Note that max() is a simple function when it has two or more arguments but operates as an aggregate function if it has a single argument.

min(x,y...)

The multi-argument min() function returns the argument with the minimum value. The multi-argument min() function searches its arguments from left to right for an argument that defines a collating function and uses that collating function for all string comparisons. If none of the arguments to min() define a collating function, then the BINARY collating function is used. Note that min() is a simple function when it has two or more arguments but operates as an aggregate function if it has a single argument

NULL check

The following table describes the NULL check functions used by the Expression Builder in Qlik Replicate .

NULL check functions

Function

Description

coalesce(x,y...)

The coalesce() function returns a copy of its first non-NULL argument, it returns NULL if all arguments are NULL. Coalesce() have at least two arguments.

ifnull(x,y)

The ifnull() function returns a copy of its first non-NULL argument, it returns NULL if both arguments are NULL. Ifnull() must have exactly two arguments. The ifnull() function is the same as coalesce() with two arguments.

nullif(x,y)

The nullif(x,y) function returns a copy of its first argument if the arguments are different and returns NULL if the arguments are the same. The nullif(x,y) function searches its arguments from left to right for an argument that defines a collating function and uses that collating function for all string comparisons. If neither argument to nullif() defines a collating function then the BINARY is used.

Date and Time

The following table describes the Date and Time functions used by the Expression Builder in Qlik Replicate .

>
Date and Time functions

Function

Description

date(timestring, modifier, modifier...)

Returns the date in the format YYYY-MM-DD.

time(timestring, modifier, modifier...)

Returns the time in the format HH:MM:SS.

datetime(timestring, modifier, modifier...)

Returns the date and time in the format YYYY-MM-DD HH:MM:SS.

julianday(timestring, modifier, modifier...)

The julianday() function returns the number of days since noon in Greenwich on November 24, 4714 B.C.

strftime(format, timestring, modifier, modifier...)

The strftime() routine returns the date formatted according to the format string specified as the first argument. It supports the following variables:

%d: day of month

%H: hour 00-24

%f: ** fractional seconds SS.SSS

%j: day of year 001-366

%J: ** Julian day number

%m: month 01-12

%M: minute 00-59

%s: seconds since 1970-01-01

%S: seconds 00-59

%w: day of week 0-6 sunday==0

%W: week of year 00-53

%Y: year 0000-9999

%%: %

Data Enrichment

Data Enrichment functions allow the selected source tables to be augmented with data from other records located in either the source or target endpoints. Practical applications of data enrichment functions include code lookup or master record lookup (e.g. social security number lookup to find a person’s name).

You can enrich the target tables with supplemental data retrieved from the source or target endpoint by defining a transformation on the table. For more information about defining transformations on a single table, see Defining transformations for a single table/view.

Limitations

Amazon Redshift is not supported.

Data Enrichment functions

The table below describes the source and target lookup functions, which can be used both for table transformations and for global transformations. For a description of the parameters available for these functions, see Input Parameters below.

Data Enrichment functions

Function

Description

source_lookup(TTL,'SCHM','TBL','EXP','COND',

COND_PARAMS)

Use to retrieve additional data from the source endpoint.

target_lookup(TTL,'SCHM','TBL','EXP','COND',

COND_PARAMS)

Use to retrieve additional data from the target endpoint.

Input parameters

The possible input parameters for the lookup functions are described in the table below. For a usage example, see Data Enrichment example.

Data Enrichment input parameters

Function

Description

TTL

TTL (Time to Live) is the amount of time the 'COND' return value will be cached. Caching the 'COND' return value improves performance by reducing the frequency that Qlik Replicate needs to access the source/target endpoint. As there is no default, you must specify a TTL value, which can be one of the following:

<SECONDS> - The time to cache the 'COND' return value in seconds. Specify a short caching time (e.g. 3) for data that is frequently updated or a long caching time for data that rarely changes.

'NO_CACHING'- Specify 'NO_CACHING' if you do not want to cache the 'COND' return value. This is recommended for data that is constantly updated (e.g. share prices).

'NO_EXPIRATION'- For data that is never updated (e.g. a street name), specify 'NO_EXPIRATION' to store the Functions return value permanently in the cache.

'SCHM'

The schema name.

'TBL'

The table on which to perform the lookup.

'EXP'

The expression to retrieve data from the lookup table.

Note: The expression syntax must be native to the endpoint it accesses.

The result should be a single column. Possible expressions include: col1, col1+5, max(col1).

Note: Full LOB columns are not supported. For information on including Limited-size LOB columns in the replication, see the description of the Metadata tab.

Columns (transformations and filters only), Headers, and Metadata (Global transformations only) can also be used in the expression and are evaluated before the lookup statement is performed against the endpoint.

'COND'

The condition for the lookup statement.

Note: The condition syntax must be native to the endpoint it accesses.

The COND is a single field referencing all required fields.

Example if the lookup table is located in Oracle:

'Fieldname1=:1 and Fieldname2=:2 and Fieldname3 =:3'

Example if the lookup table is located in Microsoft SQL Server:

'Fieldname1=? and Fieldname2=? and Fieldname3=?'

Columns (transformations and filters only), Headers, and Metadata (Global transformations only) can also be used in the expression and are evaluated before the lookup statement is performed against the endpoint.

COND_PARAMS

Any parameters required by the COND parameter.

The COND_PARAMS (condition parameters) is not a single field, but a list of fields.

Syntax:

$FIELDNAME1 , $FIELDNAME2 , $FIELDNAME3

Full example:

source_lookup(

10000 ,

'HR' ,

'DEPARTMENTS' ,

'DEPARTMENT_NAME’ ,

'COMPANY_ID=? and DIVISION_ID=? and DEPT_ID=?' ,

$COMP_ID , $DIV_ID , $DEPT_ID )

To improve efficiency, the source/target lookup tables should be indexed for the specified lookup fields.

Data Enrichment example

In the following example, Mike needs to add the DEPARTMENT_NAME column to the HR.JOB_HISTORY table. The DEPARTMENT_NAME column is located in the HR.DEPARTMENTS table in the source endpoint.

This is how the HR.JOB_HISTORY table appears before the column is added:

Example table data before Full Load

This is how the HR.JOB_HISTORY table appears after the Full LoadClosedCreates all defined files or tables at the target endpoint, automatically defines the metadata that is required at the target, and populates the tables with data from the source. completes:

Example table data after Full Load, with DEPARTMENT_NAME field added in the rightmost column

  1. Create a new task and select the HR.JOB_HISTORY table for replication.
  2. Apply a “New Column” transformation to the HR.JOB_HISTORY table. For more information on defining transformations, see Defining transformations for a single table/view.
  3. Open the Expression Builder and choose Data Enrichment from the Functions tab. For more information on the Expression Builder, see Using the Expression Builder (for filters, transformations, and global transformations).
  4. Select the source_lookup function and configure it as follows (using the native syntax of the source endpoint):

    If the lookup table is located in Oracle:

    source_lookup(10000,'HR','DEPARTMENTS','DEPARTMENT_NAME',

    'DEPARTMENT_ID=:1',$DEPARTMENT_ID)

    If the lookup table is located in Microsoft SQL Server:

    source_lookup

    (10000,'HR','DEPARTMENTS','[DEPARTMENT_NAME]',

    '[DEPARTMENT]=?',$DEPARTMENT_ID)

    Where:

    • 10000 is the TTL parameter.
    • HR is the schema name.
    • DEPARTMENTS is the table name.
    • DEPARTMENT_NAME is the expression.
    • DEPARTMENT_ID=:1 (or ? on Microsoft SQL Server) is the condition.
    • $DEPARTMENT_ID is the condition parameter.
  5. Run the task.

Operation

The following table describes the Operation functions used by the Expression Builder in Qlik Replicate .

Operation functions

Function

Description

operation_indicator(value_on_delete, value_on_update, value_on_insert)

When the operation_indicator function is invoked on its own or as part of an expression, records deleted from the source endpoint will not be deleted from the target endpoint. Instead, the corresponding target record will be flagged (with a user-provided value) to indicate that it was deleted from the source. The operation_indicator function also requires you to provide values to indicate records that were inserted or updated in the source endpoint.

Note: The operation_indicator function is not supported on tables that do not have a Primary Key.

Note: It is recommended to add a dedicated column for the flag values, for example, OPERATION. For an explanation of how to add a column, see Using the Transform tab.

To specify the function values:

Replace value_on_delete, value_on_insert and value_on_update with the values that you want to appear in the target endpoint.

Values should be formatted according to the corresponding column type.

Example when the column type is INT4:

operation_indicator(’1’, ’0’, ’0’)

Example when the column type is STRING:

operation_indicator(’Deleted’, ’Updated’, ’Inserted’)

Other Functions

The following table describes additional functions used by the Expression Builder in Qlik Replicate .

Other functions

Function

Description

length(x)

For a string value x, the length(x) function returns the number of characters (not bytes) in x before to the first NULL character.

If x is NULL then length(x) is NULL. If x is numeric then length(X) returns the length of a string representation of X.

like(x,y,z)

The like() function is used to implement the "Y LIKE X [ESCAPE Z]" expression. The ESCAPE (z) clause is optional. If there is a z clause, then the like() function is invoked with three arguments. Otherwise, it is invoked with two arguments.

typeof(x)

The typeof(x) function returns a string that indicates the datatype of the expression x: null, integer, real, text, or BLOB.

Hash

The Hash function generates a hash value for an inputted column (using the SHA-256 algorithm) and then returns the hex value of the generated hash value.

To use the function in an expression, add the hash_sha256(x) function to the Build Expression pane and then replace the "x" with the desired source column name (from the Input Columns tab).

The function is especially useful for masking sensitive information. In the expression below, for example, the Hash function has been used to obfuscate employees' email addresses.

Expression builder with Hash function example