Transformer
Moderators: chulett, rschirm, roy
Transformer
Hi,
I have a requirement as follows.
there are 3 columns User,role, and code
sample records
U1,R1,D
U1,R1,U
U2,R1,D
U2,R2,U
and i need to select only
U2,R1,D
U2,R2,U
meaning i should not select if same user/role combination has 2 codes, in the above ex U1/R1 combination has two codes D and U and so need to reject both the rows
can i do this with the help of only a transformer stage and if so pls let me know.
Note : Records will be sorted on User/role keys.
I have a requirement as follows.
there are 3 columns User,role, and code
sample records
U1,R1,D
U1,R1,U
U2,R1,D
U2,R2,U
and i need to select only
U2,R1,D
U2,R2,U
meaning i should not select if same user/role combination has 2 codes, in the above ex U1/R1 combination has two codes D and U and so need to reject both the rows
can i do this with the help of only a transformer stage and if so pls let me know.
Note : Records will be sorted on User/role keys.
Sure, stage variables doing normal 'group change detection' in a Transformer can handle this easily since the data is sorted properly. Keep track of the current and previous combination of User and Role, then only pass a record on the first time you see each particular combination.
-craig
"You can never have too many knives" -- Logan Nine Fingers
"You can never have too many knives" -- Logan Nine Fingers
Obviously, you can't do this in a Transformer - at least not without some preprocessing or as the second of two passes through the data. First pass would be to determine which records should be 'rejected' and then a second to do the dirty deed.
Unless there's some magical way in PX to do this all at once? [shrug]
Unless there's some magical way in PX to do this all at once? [shrug]
-craig
"You can never have too many knives" -- Logan Nine Fingers
"You can never have too many knives" -- Logan Nine Fingers
-
- Participant
- Posts: 467
- Joined: Tue Mar 20, 2007 6:36 am
- Location: Chennai
- Contact:
I don't see how this can be done using *just* a Transformer.
I had a similar problem and had used two sort stages with a transformer to remove these duplicates. Here is the post where Josh helped me out viewtopic.php?t=110447&highlight=
Hope that helps
I had a similar problem and had used two sort stages with a transformer to remove these duplicates. Here is the post where Josh helped me out viewtopic.php?t=110447&highlight=
Hope that helps
Minhajuddin
<a href="http://feeds.feedburner.com/~r/MyExperi ... ~6/2"><img src="http://feeds.feedburner.com/MyExperienc ... lrow.3.gif" alt="My experiences with this DLROW" border="0"></a>
<a href="http://feeds.feedburner.com/~r/MyExperi ... ~6/2"><img src="http://feeds.feedburner.com/MyExperienc ... lrow.3.gif" alt="My experiences with this DLROW" border="0"></a>
We can do this using a single transformer, however it requires one dummy record at the end. This is because we don't know until next record is processed if the previous one qualifies to be outputted..
In the test map I developed, I added the dummy record using a row generator and funnelling(sequencially) along with input before hitting the transformer stage...
Here is what I did in the transformer..
--------------------------------------------------
Stage Variables:
sCount = sPrvCount
if ( ( sUser=x.User) and (sRole=x.Role) ) then sCount+1 else 1 = sCount
sUser=sPrvUser
sRole=sPrvRole
sValue=sPrvValue
lnk.User = sUser
lnk.Role = sRole
lnk.Value = sValue
-------------------------------------------------------------
Mapping
Link Condition = ( ( sPrvUser<>Lnk.User) or (sPrvRole<>Lnk.Role) ) and sPrvCount=1
sPrvUser = User
sPrvRole = Role
sPrvValue=Value
----------------------------------------------------------
Idea is simple as with other postings tp remove duplicates. However we need one extra 'count' stage variable to hold count of previous set of records. If this count=1, means the previous set of record have only one record so it will be allowed to pass the transfomer link.
The approach uses an additional row generator and a sequencial funnel, both are lite weight. However, if a dummy record say ZZ,ZZ,Z can be added part of file, we can then achive everything within the Transfomer stage..
In the test map I developed, I added the dummy record using a row generator and funnelling(sequencially) along with input before hitting the transformer stage...
Here is what I did in the transformer..
--------------------------------------------------
Stage Variables:
sCount = sPrvCount
if ( ( sUser=x.User) and (sRole=x.Role) ) then sCount+1 else 1 = sCount
sUser=sPrvUser
sRole=sPrvRole
sValue=sPrvValue
lnk.User = sUser
lnk.Role = sRole
lnk.Value = sValue
-------------------------------------------------------------
Mapping
Link Condition = ( ( sPrvUser<>Lnk.User) or (sPrvRole<>Lnk.Role) ) and sPrvCount=1
sPrvUser = User
sPrvRole = Role
sPrvValue=Value
----------------------------------------------------------
Idea is simple as with other postings tp remove duplicates. However we need one extra 'count' stage variable to hold count of previous set of records. If this count=1, means the previous set of record have only one record so it will be allowed to pass the transfomer link.
The approach uses an additional row generator and a sequencial funnel, both are lite weight. However, if a dummy record say ZZ,ZZ,Z can be added part of file, we can then achive everything within the Transfomer stage..
--------------------------------------------------
Srini
When the Going Gets Tough, the Tough Get Going!
Srini
When the Going Gets Tough, the Tough Get Going!