Parallel routine for patteren matching with a lookup file

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
devnhi
Premium Member
Premium Member
Posts: 68
Joined: Wed Jun 17, 2009 10:47 am

Parallel routine for patteren matching with a lookup file

Post by devnhi »

Hi

we want to do some patteren matching with a look up file(with 800 rows) and reject the data which does not match the criteria . It will not be a straight match up and so I have created a parallel routine .So basically I am taking the input and comparing the values against a look up file .But this is working only when the look up file has one record only. I am not sure why it is not working when theere are multiple values (rows) in the lookup file .

Any help would be greatly appreciated .

Code: Select all

int retflg(char *lastnm,char *firstnm)
{
char fromfile[200];
FILE *file = fopen ( "tmp.txt", "r" );
int flag=0;
strcpy(fromfile,lastnm);
if ( file != NULL ) {
 char line [ 128 ];
while ( fgets ( line, sizeof line, file ) != NULL )
{
if (strncmp (fromfile,line,1)==0)
     {
       flag=1;
       return flag;
     }
    else
     {
       flag=0;return flag;
     }
}
fclose ( file );
 }
else { perror ( "/home/nhiprod/tmp.txt" ); /* why didn't the file open? */ } return 0;

}
jwiles
Premium Member
Premium Member
Posts: 1274
Joined: Sun Nov 14, 2004 8:50 pm
Contact:

Post by jwiles »

Your routine returns after comparing to the first lookup record, whether or not you get a match. You can simply change the while condition to include "&& flag == 0", remove the returns from the loop and place a return after the fclose statement.

How many rows of data will you be processing? Why not do this in a buildop instead, where you could read the lookup table into an array rather than opening and reading it each and every time you call the routine?

Regards,
- james wiles


All generalizations are false, including this one - Mark Twain.
devnhi
Premium Member
Premium Member
Posts: 68
Joined: Wed Jun 17, 2009 10:47 am

Post by devnhi »

Thank you so much.I have changed it and it is working now . I am processing 80 records in the lookup table . I have never used a array before and thought this way would be better .

Not sure if I can ask , but Do you have any sample program which loops through an array.

Thanks again.
devnhi
Premium Member
Premium Member
Posts: 68
Joined: Wed Jun 17, 2009 10:47 am

Post by devnhi »

I am sorry , just now learning the parallel routine and worked for a simple one .May be some silly questions , but want to take the expertise.

can i invoke multiple parallel routines in a single transformer ?cause for some reason only one routine is working for me in that case .Did i miss anything ?

Can i invoke multiple routines in a single Parallel routine , as it don't have a mian , not sure how to invoke like that ?

Thanks for all your help.
jwiles
Premium Member
Premium Member
Posts: 1274
Joined: Sun Nov 14, 2004 8:50 pm
Contact:

Post by jwiles »

There are plenty of examples for looping in C and C++ available on the web. In fact, you are already using one method in your routine--the while loop. There are others: until is a variation on while, and for is used quite often as well.

You can call as many routines as you feel necessary inside a transformer, and they can either be contained in one or more objects/libraries (the .o/.so/.a files) so long as each is given a unique name. You must create a separate definition in Designer for each routine, however. You will provide the name of the routine itself (the function name), as well as the name of the object/library it is contained in.

Regards,
- james wiles


All generalizations are false, including this one - Mark Twain.
Post Reply