Skip to main content
Skip table of contents

Example: Using an Identity Expression

You are looking at an older version of the documentation. The latest version is found here.

1. Initial Situation:

source.table before Materialization

id
orderDate
description
12010/01/01descr_1
22011/01/01descr_2
32012/01/01descr_3

2. Running Optimization Job (full copy):

source.table is at first fully copied to the dwh.table:

id
orderDate
description
12010/01/01descr_1
22011/01/01descr_2
32012/01/01descr_3

3. Source table grows up and some rows are updated (highlighted with a blue color)

idorderDatedescription
12010/01/01descr_1
22013/02/01descr_2_changed
32012/01/01descr_3_changed
3.12012/01/01descr_3.1
42012/06/01descr_4
52013/02/01descr_5

The value of the orderDate for the row with id = 2 is updated and the new value matches now the checkExpressionValue.

4. Running Incremental Optimization Job (newRowCheckExpression = "orderDate", identityExpression = "'id'", deleteOldDate= "true")

4.1 Finding data that is already in the Materialized Table

To estimate the last row that is already in the dwh.table the incremental job will first issue

SQL
SELECT MAX(orderDate) as checkExprValue FROM dwh.table

and retrieve

SQL
checkExprValue = '2012/01/01'

4.2 Create and fill the DELTA table

The DELTA is calculated as follows:

SQL
SELECT * INTO dwh.delta FROM source.table WHERE orderDate >= '2012/01/01'

dwh.delta

idorderDatedescription
22013/02/01descr_2_changed
32012/01/01descr_3_changed
3.12012/01/01descr_3.1
42012/06/01descr_4
52013/02/01descr_5

4.3.b Delete rows to update from the original Materialized Table (using the identityExpression value)

SQL
DELETE FROM dwh.table WHERE id IN (SELECT id FROM dwh.delta)

After that, the Materialized Table will contain the following rows:

dwh.table

idorderDatedescription
12010/01/01descr_1

Please, note that the identity expression is provided as a SQL code and it will be injected in the DELETE statement as follows:

SQL
DELETE FROM dwh.table WHERE <identityExpression> IN (SELECT <identityExpression> FROM dwh.delta)

If the identity expression should contain more than one column, it can be done by concatenating them to a string

SQL
CONCAT ( CAST ( id as string ), STRINGCOL1 )

Please pay attention to substituting null values and data types which cannot be implicitly cast to string have to be cast explicitly: xml, clob. Data types which cannot be cast to a string cannot be used in identity expression: blob, object.

4.4 Add DELTA to the original Materialized Table 

will be calculated like

SQL
INSERT INTO dwh.table SELECT * FROM dwh.delta

and result in

dwh.table

idorderDatedescription
12010/01/01descr_1
22013/02/01descr_2_changed
32012/01/01descr_3_changed
3.12012/01/01descr_3.1
42012/06/01descr_4
52013/02/01descr_5

It is important to note that using the identityExpression prevented the generation of duplicates. If the identityExpression were NULL, two rows with id = 2 would have been copied into the materialized table.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.