Okay, I think I got it. But let’s break the problem into two parts since you want to have two tables updated at the end, the target table and the table B.
Table Target:
Like the others suggested, I would read table A and lookup the starting value in table B and use gen_row_num_per_group() function.
TableA has the values
1;1;1;5
1;2;1;5
1;2;1;5
1;2;1;5
1;1;1;3
1;2;1;3
1;2;1;3
1;1;1;3
1;2;1;3
Table B has the values
100;3
800;5
1200;6
We build a dataflow with
TableA --> Query(lookup) —>
where we use the lookup_ext() function as new-function-call in the output, condition is tableA.col4 = tableB.col2, set to pre_load_cache(!)
Result of that query will be
1;1;1;5;800;5
1;2;1;5;800;5
1;2;1;5;800;5
1;2;1;5;800;5
1;1;1;3;100;3
1;2;1;3;100;3
1;2;1;3;100;3
1;1;1;3;100;3
1;2;1;3;100;3
This query should also sort the data based on col4 for the next query.
In a subsequent query we output all columns from this query and add one additional column called counter which is mapped to gen_row_num_per_group(col4). This column will contain a strictly growing number and restart at zero whenever col4 has a new value. Hence the order by in the previous query.
Result will be
1;1;1;5;800;5;0
1;2;1;5;800;5;1
1;2;1;5;800;5;2
1;2;1;5;800;5;3
1;1;1;3;100;3;0
1;2;1;3;100;3;1
1;2;1;3;100;3;2
1;1;1;3;100;3;3
1;2;1;3;100;3;4
As you see, all that is left is adding the 800 with the counter plus 1
1;1;1;5;800;5;0;801
1;2;1;5;800;5;1;802
1;2;1;5;800;5;2;803
1;2;1;5;800;5;3;804
1;1;1;3;100;3;0;101
1;2;1;3;100;3;1;102
1;2;1;3;100;3;2;103
1;1;1;3;100;3;3;104
1;2;1;3;100;3;4;105
Voila, we got your target table (after removing the extra columns in yet another query.
Above logic needs some fine tuning, e.g. what if there is no starting number for 3 or 5, then the starting number should be zero and not null.
Your table B is simple now, you split the data from above query into a parallel query where you select col4, max(col8) and group by col4.
Result will be
5;804
3;105
which you load into table B, loader set to autocorrect load so rows get updated. Table B has to have a primary key on the column containing the values 3 and 5 and 6, col2 in your terminology.
Werner Daehn
(BOB member since 2004-12-17)