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: 
Anonymous
Not applicable

loop on a condition

Hi team,


I want to distribute the attribute "number" by 1 on the attributes "Supp" which have the biggest "rest" and which are grouped by code,
I use:
tOracleInput-> tSortRow-> Tjavaflex-> tLogRow

I use tSortRow to sort the "rest" attributes,

tJavaFlex:
for (int i = 0; i <= row7.code; i ++)
{for (j = 0; j <= row7.number; j--)
     
{row10.Supp = row7.Supp + 1;}

 

input
code|number|rest|supp
1 |2 |150 |4
1 |2 |125 |1
1 |2 |110 |1
2 |3 |145 |0
2 |3 |130 |3
2 |3 |50 |1
2 |3 |10 |4
Iwant an output like this:
code|number|rest|supp
1 |2 |150 |5
1 |2 |125 |2
1 |2 |110 |1
2 |3 |145 |1
2 |3 |130 |4
2 |3 |50 |2
2 |3 |10 |4


Could anyone please give me a hint of how to do this?

Your help is very much appreciated.


thanks,

nadakh

Labels (1)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Find attached the job

 

Here is the tJavaRow

String code = input_row.code;
int num = input_row.number;

output_row.code = input_row.code;
output_row.number = input_row.number;
output_row.rest = input_row.rest;
output_row.supp = input_row.supp;

if( code.contains(context.current_code) ){
	context.to_distribute -= 1 ;
	output_row.supp += ( 0 > context.to_distribute ? 0 : 1 );
} else {
	context.current_code = input_row.code;
	context.to_distribute = input_row.number - 1;
	output_row.supp += ( 0 > context.to_distribute ? 0 : 1 );
}

hope this will help

 


DEMO_INTEGRATION.zip

View solution in original post

16 Replies
Anonymous
Not applicable
Author

Your example does not make this very clear. Why does .....

1 |2 |150 |4
1 |2 |125 |1
1 |2 |110 |1
2 |3 |145 |0
2 |3 |130 |3
2 |3 |50 |1
2 |3 |10 |4

......turn into this....

1 |2 |150 |5
1 |2 |125 |2
1 |2 |110 |1
2 |3 |145 |1
2 |3 |130 |4
2 |3 |50 |2
2 |3 |10 |4

 

The first 3 columns are exactly the same, but there doesn't appear to be a a reason for the column 4 change??

Anonymous
Not applicable
Author

Hi rhall_2_0,

then, I will explain this example, for the code "1": I have 3 lists, each list gets a "rest" and a "Supp" and I have a "Number" to distribute on the lists that have the most highest "rest" (for code "1": I have "number" = 2).
for "rest" = 150 we assign a "Number"=1 -> Supp = Supp + 1
for "rest" = 125 we assign a "Number"=1 -> Supp = Supp + 1
for "rest" = 110 there is no "number" to assign it -> Supp = Supp + 0
  and I repeat the same procedure for each code. (for code "2" I have "number" = 3 to distribute it)

 

I hope that I explain my problem well, I do not find how to make this loop with talend 

Anonymous
Not applicable
Author

I'm still not sure about the logic, but what you describe should be possible using a tJavaFlex (as you've suggested). What is the issue you are getting?

Anonymous
Not applicable
Author

So, the code is like a group

Then "Number" is the total to distribute to the group
When you have distributed all (by doing +1 on each item), you stop distributing

Is it how it works?

Anonymous
Not applicable
Author

Hi dgm01,

 

Yes it works like that.

 

 

 

Anonymous
Not applicable
Author

Then it's simple,
You have to use global variables.

Then what do you do, if After distributing +1 to each item of the group, you have something remaining?

For example, let's say, for group (code = 1), you have "Number"=10
After distributing the 3 items, you have a remaining of 7
Anonymous
Not applicable
Author

Always, "Number" < number of items , it will be distrubuted all
Anonymous
Not applicable
Author

Now busy, will send the solution to you when I find time during the day
Anonymous
Not applicable
Author

Ok thank you 😊