Page 1 of 2

logic required

Posted: Fri Mar 29, 2013 8:44 am
by hargun
hi,

i have three columns in seq file as follows but i need the out put int he following way .Two extra columns required as per requirement GROUP and FAMILY

Code: Select all

Name            Phone_desc         Phone_number          GROUP    FAMILY
ABC                work            123-456-789            1         Y
XYZ                CELL            857-657-798            2         N
GHI                WORK            123-456-789            1         Y
IF NAME : ABC AND GHI having same phone number then it should come under group 1 and FAMILY is also "Y" for both of them.

Similarly if XYZ is having different cell the group should be 2 and family is "N"

In nutshell the names with same phone number comer under same group 1 and Family is "y" for those and for different phone number group is like 1,2,3 etc follows by Family as "N".

i appreciate the response.

Posted: Fri Mar 29, 2013 9:16 am
by chulett
Cleaned up your example.

:idea: People, please remember that you MUST use code tages if you want to preserve white-space in your super duper examples with (for example) columns of data. Otherwise the forum software removes all of your 'extra' spaces. It has been doing this for years, learn to love the Preview button to make sure your example still survives and makes sense when others see it. Please.

Posted: Fri Mar 29, 2013 9:20 am
by chulett
Hargun, you know the drill by now... what have you tried? What problems are you having? Your requirement seems pretty straight-forward so far.

Do you need to preserve the original file order? That's the only thing that might make this a little tricky.

Posted: Fri Mar 29, 2013 9:21 am
by hargun
chulett wrote:Cleaned up your example.
i apologise will take care

Posted: Fri Mar 29, 2013 9:26 am
by chulett
No worries, that message was for everyone - not picking on you specifically. :wink:

Posted: Fri Mar 29, 2013 12:21 pm
by hargun
i tried by adding new column Group and family in transformer and then tried by using the aggregator stage after transformer but unable to get the result.

Posted: Fri Mar 29, 2013 1:37 pm
by chulett
There's no aggregation needed here.

If you don't need to preserve the input order, what about using a Sort stage and having it add a group change key? You could then do what you need in stage variables after that.

Posted: Sun Mar 31, 2013 7:13 pm
by hargun
Can you help me what i have to define in stage variables .I appreciate.

Posted: Mon Apr 01, 2013 5:48 am
by ds@tcs
Your job esign would be:
seqfile-> sort1-> sort2-> tsfr-> target

logic would be:
Sort1- Sort on ph no with Key change col=True--Asc

Sort2- Sort on Ke change col, ph no-asc

Tsfr- Create stgv1 stggroup, Stgv2 Stgfamily, Stgv3 stgprev(Default=1)
stggroup= If keyChange =1 And Stgprev =1 Then 2 Else 1
Stgfamily= If Stggrp =1 Then 'Y' Else 'N'
stgprev= DSLink32.keyChange

map stggroup with group, stgfamily with Family.

-
Sankar

Posted: Mon Apr 01, 2013 4:50 pm
by stuartjvnorton
I hate "requirements" based on trivial examples.
What happens if you have a 4th record:

Code: Select all

Name            Phone_desc         Phone_number          GROUP    FAMILY
ABC                work            123-456-789            1         Y
XYZ                CELL            857-657-798            2         N
GHI                WORK            123-456-789            1         Y

JKL                CELL            857-657-798            ?         ?

Posted: Mon Apr 01, 2013 9:40 pm
by Rakesh311
Sort by phone number and Name , then for each of that group u can have specific GROUP and FAMILY.

Try it out , you can do it easily :)

Posted: Mon Apr 01, 2013 11:56 pm
by ds@tcs
stuartjvnorton wrote:I hate "requirements" based on trivial examples.
What happens if you have a 4th record
It will work with N no of rows. Try it out.

Posted: Tue Apr 02, 2013 12:44 am
by chandra.shekhar@tcs.com
@Sankar,
I dont think that will work, for the 4th record GROUP should have "3".
In your logic the counter thing is missing, so you have to use one more variable for incrementing the counter.

Posted: Tue Apr 02, 2013 7:45 am
by ds@tcs
You are right. I thought the requiremnt will be with two groups. If group no is increasing then we need a count variable.

Posted: Fri Apr 05, 2013 11:33 am
by hargun
ds@tcs wrote:Your job esign would be:
seqfile-> sort1-> sort2-> tsfr-> target

logic would be:
Sort1- Sort on ph no with Key change col=True--Asc

Sort2- Sort on Ke change col, ph no-asc

Tsfr- Create stgv1 stggroup, Stgv2 Stgfamily, Stgv3 stgprev(Default=1)
stggroup= If keyChange =1 And Stgprev =1 Then 2 Else 1
Stgfamily= If Stggrp =1 Then 'Y' Else 'N'
stgprev= DSLink32.keyChange

map stggroup with group, stgfamily with Family.

-
Sankar


hi,

i tried by using the above logic but its not giving the result expected ,its give group 1 and Family Y for each phone number ,group is not increment for each different number.