Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Alpha549
Creator II
Creator II

tMap : complexe inner join and complexe left join

Hello everyone,

 

In the majority of cases, I believe that when we use a tMap to join rows, join is made with equality.

However, for some joins, the condition can me more complexe, for instance : row1.id >= row2.id && row1.id <= row2.id

 

HERE ARE 2 CASES : A COMPLEXE INNER JOIN, AND A COMPLEXE LEFT JOIN

 

COMPLEXE INNER JOIN

 

0695b00000kYPTFAA4.png0695b00000kYPTPAA4.png0695b00000kYPTZAA4.png 

The tMap is configured on Join Model : Inner Join.

 

The output, as expected :

 

0695b00000kYPTeAAO.png 

I TRIED TO GET THE SAME RESULT, BUT AS LEFT JOINT : I SHOULD GET A THIRD ROW 8, NULL, NULL, NULL

 

I changed the tMap join model from Inner Join to Left Outer Join.

The result is the same. I understand that because as I use a filter here, other rows are removed.

 

Here is how I proceeded :

 

0695b00000kYPTyAAO.png0695b00000kYPU3AAO.png 

 

FIRST TMAP :

 

0695b00000kYPU8AAO.png 

FILTERED : COPYOF...1

0695b00000kYPUDAA4.png 

The other file is COPYOF...2 AFTER A TUNIQUEROW

I USE CSV FILES TO STORE TEMPORARY DATA

 

0695b00000kYPUNAA4.png 

 

THEN, I DETECT THE ROWS OF COPYOF...2 (PREVIOUSLY INSERTED IN A CSV FILE) WHICH ARE NOT IN COPYOF...1 (PREVIOUSLY INSERTED IN A CSV FILE) : INNER JOIN AND I GET THE REJECTED

AND SEND THEM IN A THIRD CSV FILE, HERE TO STORE TEMPORARY DATA

 

 0695b00000kYPUrAAO.png 

As I can't include more that 10 image, I continue in the first comment.

Labels (4)
1 Solution

Accepted Solutions
Alpha549
Creator II
Creator II
Author

Hello @Anselmo Peixoto​ 

 

Thank you a lot. I didn't know this feature.

 

 

Beyond the tips you gave me, I found a solution to make a left join with a complexe join condition. I share with the community.

 

Here we go :

 

The final job :

 

0695b00000lvR21AAE.png0695b00000lvR39AAE.png 

I selected commons just to remove the alert. Then, in advanced settings :

import java.util.HashMap;

 

0695b00000lvR4RAAU.png0695b00000lvR5AAAU.pngTMAP :

0695b00000lvR5yAAE.pngNothing in the expression field, as we use the lookup table filter for our complexe join (not a simple equality test).

All rows, INNER JOIN (even if we want to do a left join, it's always inner in the case of complexe join condition)

 

We create the first output.

Then, the tips you gave me @Anselmo Peixoto​ : we create a second output using the + icone on the upper right part, and we select join.

 

Create a join table :

0695b00000lvRB3AAM.png 

As seen before, for the join table, we only set the value of AID. Nothing more.

 

We create a new column called JOINED.

 

(CONTINUE IN THE NEXT COMMENT)

View solution in original post

7 Replies
Alpha549
Creator II
Creator II
Author

0695b00000kYPVGAA4.png 

THIRD SUB-JOB, I CONCATENATE THE TWO FILES, AND I GET WHAT I WISHED :

 

0695b00000kYPVQAA4.png 

Can you give me some advice on how to proceed, and if there is an easier way to achieve a "complex left join"?

anselmopeixoto
Partner - Creator III
Partner - Creator III

Hi @Alpha549 Alpha549​ 

 

What if you try the following:

 

  1. Keep the lookup as inner join just like in your example;
  2. On the output section, click on the "add output table" icon with a plus sign;
  3. Select "Create join table from" and select "out2" as its source. This will create another mapping based on out2 schema;
  4. On this new output mapping, click on the "tMap settings" icon with a wrench tool;
  5. Set the "Catch lookup inner join reject" option to true;
  6. Map the output columns just like you did on the first schema;

 

These steps allows you to create "virtual" schemas that are joined to a single output row, so you'll need to connect only "out2" to an output component (in fact, you'll notice there will be only "out2" row when you try to connect tMap to another component).

 

I hope this helps you achieve the complex left join you need.

 

 

 

 

Alpha549
Creator II
Creator II
Author

Hello @Anselmo Peixoto​ ,

 

Thank you a lot for your answer.

 

Could you show some screenshots from step 3 ?

 

Please.

Alpha549
Creator II
Creator II
Author

@Anselmo Peixoto​  ?

anselmopeixoto
Partner - Creator III
Partner - Creator III

Hi @Alpha549 Alpha549​ , here it goes:

 

Add output table:

 

0695b00000lv9BKAAY.png 

Create join table:

 

0695b00000lv9BAAAY.png 

Click on tMap settings for the new output you just created:

 

0695b00000lv9B0AAI.png 

Enable Catch lookup inner join reject:

 

0695b00000lv9AHAAY.png 

Connect tMap original output schema to the output component:

 

0695b00000lv9BUAAY.png 

Alpha549
Creator II
Creator II
Author

Hello @Anselmo Peixoto​ 

 

Thank you a lot. I didn't know this feature.

 

 

Beyond the tips you gave me, I found a solution to make a left join with a complexe join condition. I share with the community.

 

Here we go :

 

The final job :

 

0695b00000lvR21AAE.png0695b00000lvR39AAE.png 

I selected commons just to remove the alert. Then, in advanced settings :

import java.util.HashMap;

 

0695b00000lvR4RAAU.png0695b00000lvR5AAAU.pngTMAP :

0695b00000lvR5yAAE.pngNothing in the expression field, as we use the lookup table filter for our complexe join (not a simple equality test).

All rows, INNER JOIN (even if we want to do a left join, it's always inner in the case of complexe join condition)

 

We create the first output.

Then, the tips you gave me @Anselmo Peixoto​ : we create a second output using the + icone on the upper right part, and we select join.

 

Create a join table :

0695b00000lvRB3AAM.png 

As seen before, for the join table, we only set the value of AID. Nothing more.

 

We create a new column called JOINED.

 

(CONTINUE IN THE NEXT COMMENT)

Alpha549
Creator II
Creator II
Author

For the out1 schema, we set JOINED to true.

For the join table, JOINED to false.

For the join table, we set catch lookup inner reject to true.

 

Then, we sort the rows on JOINED value : to get joined rows BEFORE null ones.

0695b00000lvRElAAM.pngTJAVAFLEX with its schema and code :

 

0695b00000lvRHQAA2.png 

In the output we add a column called VALIDE (for instance).

 

Start code, we create a HashMap which records if a AID is already encountered.

 

Main code : we consider that the line is not valide.

if the row is joined, we remember that this AID is encountered, and the line becomes valid.

 

If the row is not joined, we check if this AID has already been encountered. If not, the row is valid => we keep it.

 

Then we filter the row :

 

0695b00000lvRMBAA2.png 

Then we keep unique rows only :

 

0695b00000lvRMuAAM.png 

When we run the job, we get what I wanted : a left join output based on our complexe join condition, which is not a simple equality test.

 

0695b00000lvRNEAA2.png 

I hope this will help !

Thank you again @Anselmo Peixoto​ !