Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Aami
Contributor III
Contributor III

Soft delete when there are duplicates in source

Hi,

I am reading data from a csv file which does not have a primary key and there are duplicate entries as well. This data is loaded into database. The requirement is to implement the soft delete when something gets deleted from source.

For example if there are 4 occurrences of a particular record in source and once of them is deleted, one of the record to be marked as N in target during the next load and rest three would be Y. In case two of them gets deleted, two records should be marked as N and rest two will remain as Y. 

I am thinking about sequencing the group of duplicates in incremental order and using that column to differentiate between the duplicates. However I'm not sure how to practically implement this.

Can someone please help with ideas.

Thanks in advance,

 

 

 

 

Labels (6)
1 Solution

Accepted Solutions
Aami
Contributor III
Contributor III
Author

  1. Select all active records from Target and source and store them in buffer (tHashoutput) component.
  2. While fetching records from Source create a Hash value (Hash1) of all the applicable columns using DataMasking.createMD5 or any similar hashing technique in tMap1. In tMap2 create a numeric sequence for Hash value using Numeric.sequence(Hash1,1,1). Use this Sequence as ID for the Target Table and create another Hash key (Hash2) using all the applicable columns +Hash1 + Numeric sequence (ID)
  3. Insert New Record: Use src data as input1 and target data as input 2 into tMap and join them on Hash2 and ID created in previous step and all the applicable columns. Insert if ID == null . Add below columns with default values as mentioned

ROW_EFFECTIVE_DATE -> TalendDate.getCurrentDate()

ROW_EXPIRY_DATE -> TalendDate.parseDate("yyyy-MM-dd","9999-12-31") 

ROW_CREATED_DATE-> TalendDate.getCurrentDate()

ROW_UPDATED_DATE -> TalendDate.getCurrentDate()

ACTIVE_IND-> "Y"

 

4. Logical delete of records deleted in source: Use target as input 1 and source as input 2 into tmap and join them on Hash2 and ID created in step 2 and all the applicable columns. If ID == null update the active indicator to N.

ROW_EFFECTIVE_DATE -> Keep as it is in target

ROW_EXPIRY_DATE -> TalendDate.addDate(TalendDate.getCurrentDate(),-1,"dd")

ROW_CREATED_DATE-> Keep as it is in target

ROW_UPDATED_DATE -> TalendDate.getCurrentDate()

ACTIVE_IND-> "N"

 

 

View solution in original post

3 Replies
Anonymous
Not applicable

To do a ranking you need a tSortRow and a tMap.

You may omit the tSortRow component if the duplicates rows are exactly the same, if there is someting different you can order by these fields. Then in the tMap create a variable with integer type. In the expression write: Numeric.sequence(fields you want to group by,1,1). These fields must appear as only one string field so you can do something like: Numeric.sequence(field1.toString() + field2.toString(),1,1)

Aami
Contributor III
Contributor III
Author

Any idea how to achieve this?

Since the source doesn't have a primary key and has duplicated rows, Marking any of the deleted record as inactive in target is looking like a challenge.

Aami
Contributor III
Contributor III
Author

  1. Select all active records from Target and source and store them in buffer (tHashoutput) component.
  2. While fetching records from Source create a Hash value (Hash1) of all the applicable columns using DataMasking.createMD5 or any similar hashing technique in tMap1. In tMap2 create a numeric sequence for Hash value using Numeric.sequence(Hash1,1,1). Use this Sequence as ID for the Target Table and create another Hash key (Hash2) using all the applicable columns +Hash1 + Numeric sequence (ID)
  3. Insert New Record: Use src data as input1 and target data as input 2 into tMap and join them on Hash2 and ID created in previous step and all the applicable columns. Insert if ID == null . Add below columns with default values as mentioned

ROW_EFFECTIVE_DATE -> TalendDate.getCurrentDate()

ROW_EXPIRY_DATE -> TalendDate.parseDate("yyyy-MM-dd","9999-12-31") 

ROW_CREATED_DATE-> TalendDate.getCurrentDate()

ROW_UPDATED_DATE -> TalendDate.getCurrentDate()

ACTIVE_IND-> "Y"

 

4. Logical delete of records deleted in source: Use target as input 1 and source as input 2 into tmap and join them on Hash2 and ID created in step 2 and all the applicable columns. If ID == null update the active indicator to N.

ROW_EFFECTIVE_DATE -> Keep as it is in target

ROW_EXPIRY_DATE -> TalendDate.addDate(TalendDate.getCurrentDate(),-1,"dd")

ROW_CREATED_DATE-> Keep as it is in target

ROW_UPDATED_DATE -> TalendDate.getCurrentDate()

ACTIVE_IND-> "N"