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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
sheftalenduser
Contributor
Contributor

How to map data in multiple rows to a single record in a table

Hello everyone

I have a query that returns between 1 and 8 rows; Within each row is a column value that I want to map to a table. The columns I want to map to are:
PREREQUISITE_UNIT_CODE1
PREREQUISITE_UNIT_CODE2
PREREQUISITE_UNIT_CODE3
PREREQUISITE_UNIT_CODE4
PREREQUISITE_UNIT_CODE5
PREREQUISITE_UNIT_CODE6
PREREQUISITE_UNIT_CODE7
PREREQUISITE_UNIT_CODE8

 

and the source data is: 

0683p000009M0AO.png

In this example there are 5 rows so row 1 with mmb_seq = 1 should be mapped to PREREQUISITE_UNIT_CODE1; the row with mmb_seq = 2 should be mapped to PREREQUISITE_UNIT_CODE2 and so on. 

The job is as below. The table should be updated with values in the prereq_unit_code column.

0683p000009M01r.png

The tMap is as below:

0683p000009M0AT.png

 

The expression that maps the row to the column takes the form:

(PrerequisiteUnit.mmb_seq.equals("001") ?
PrerequisiteUnit.prereq_unit_code : "") 

The mmb_seq check increments for each expression up to "008".

The job runs but only the last column in the target table is updated (PREREQUISITE_UNIT_CODE5); No other columns are populated. If I split the lookup table into 5 lookups, filitering on the mmb_seq value then the job works but this isn't practical as I have a number of categories of data like this so would lead to a proliferation of lookups.

 

Hope this makes sense - Andrew

Labels (2)
3 Replies
Anonymous
Not applicable

hey there, 

 

I also wanted to know that hpw to map data in multiple rows without being confused and easy to accessible.

Thanks for sharing these information and images. I just want to ask, Will somebody guide me personally???

Anonymous
Not applicable

hey there, I also wanted to know that hpw to map data in multiple rows without being confused and easy to accessible. Thanks for sharing these information and images. I just want to ask, Will somebody guide me personally ???

sheftalenduser
Contributor
Contributor
Author

Hi again,

Having failed to tempt anyone to offer a solution I've finally come up with one though it's not very elegant.

I've created a subjob that runs first to acquire the source data and associated lookup data as below.

 0683p000009M0UE.png

The code for the tJavaFlex is as follows:

0683p000009M0UO.png

The code for the Java method is below

public static String getMapValue(Object obj, String seq) {
		@SuppressWarnings("unchecked")
		HashMap<String, String> map = (HashMap<String, String>)obj;
		String ret = "";
		ret = map.get(seq);
		return ret;
	}

The method lookup is done in the tMap as below:

Module.getMapValue(globalMap.get("locationsMap"), "001") 

Any comments/alternative approaches are welcome.

 

Andrew

 

 

 


Talend-map-rows-to-columns-tjavaflex-job.PNG