what does this c++ code do??

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
Pavan_Yelugula
Premium Member
Premium Member
Posts: 133
Joined: Tue Nov 23, 2004 11:24 pm
Location: India

what does this c++ code do??

Post by Pavan_Yelugula »

Hi All
I have a build op with the following code

Code: Select all

DEFINITION SECTION
-------------------------
#include <map>
#include <string>
#include <iostream>
   using namespace std;

map<string, int> mymap;
map<string, int>::iterator mymapit;
string holdkey;
string holdmsg;
string holdacnr;
bool firstrec = true;

PER RECORD SECTION
------------------------
if (KEY_IN != holdkey.c_str())
{
    if (firstrec == false)
    {
       KEY_OUT = holdkey.c_str();
       FBL_AC_NR_OUT = holdacnr.c_str();
       for (mymapit = mymap.begin(); mymapit != mymap.end(); ++mymapit)
         {
            MSG_CD_OUT = mymapit->first.c_str();
         }
       transferAndWriteRecord(0);
       mymap.clear();
    }
    else
      firstrec = false;
    
    holdkey = KEY_IN.data();
    holdacnr = FBL_AC_NR_IN.data();
}

for (int x=0; x < 20; x+=2)
{
   holdmsg = MSG_CD_IN.substring(x,2);
   if (holdmsg != "  ")
      mymap[holdmsg] ++;
}


POST LOOP SECTION
-------------------
KEY_OUT = holdkey.c_str();
FBL_AC_NR_OUT = holdacnr.c_str();
for (mymapit = mymap.begin(); mymapit != mymap.end(); ++mymapit)
 {
    MSG_CD_OUT = mymapit->first.c_str();
 }
transferAndWriteRecord(0);

Can some please give me a clue what it does???


Thanks
Pavan[/code]
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Before we do that, do you understand C/C++ syntax at all? And have you read the chapter on programming within parallel jobs?
Please post the pre-loop code (where, for example, the variable called holdkey is initialized).
Please ask more specific questions.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
UPS
Premium Member
Premium Member
Posts: 56
Joined: Tue Oct 10, 2006 12:18 pm
Location: New Jersey

Post by UPS »

ray.wurlod wrote:Before we do that, do you understand C/C++ syntax at all? And have you read the chapter on programming within parallel jobs?
Please post the pre-loop code (where, for example, the variable called holdkey is initialized).
Please ask more specific questions.
Basically this is what we wanted to achieve with this build-op:
Get the unique 2-byte values from the string field with the same key.
Example
Input:
rec# key string (20 byte value)
1 KEY1 aa
2 KEY1 abaa
.
.
10000 KEY1 xxaaab
10001 KEY2 yy

Expected Output:
KEY1 aaabxx
KEY2 yy

Output that we are getting from the above buildop:
KEY1 xx
KEY2 yy

Can someone pls. tell us how to get the expected output?
Instead of getting the concatenation, the latest 2 byte value is overlaying the previous ones in the first two bytes...
I'll post the pre-loop code tomorrow..
Thanks for any help
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Can you be more specific with the logic of this concatenation please. Post ten records and show us what the expected output should be.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
Pavan_Yelugula
Premium Member
Premium Member
Posts: 133
Joined: Tue Nov 23, 2004 11:24 pm
Location: India

Post by Pavan_Yelugula »

Ray,
There is no code in the Pre-Loop.

DSGuru a much more diverse example
InPut
rec# key string (20 byte value)
1 KEY1 aa
2 KEY1 abaa
3 KEY1 acabbbaa
4 KEY1 aa
5 KEY1 ss
6 KEY1 ab
7 KEY1 aa
8 KEY1 aa
9 KEY1 bb
10KEY1 cc

In the above example. The String is a 20 digit value and every 2 digits has some business value to them.so this string can contain 10 value pairs.

From the above example i want to get all unique 2 digit values from my string field. i will take aa from the first record and when i go to the next record i have 2 value pairs ab and aa. As i have already considered aa i will pick ab. similarly when i go to the third i have 4 value pairs ac,ab,bb,aa. in these i will pick ac and bb as i have already considered ab and aa.......

The expected out put in the above example is
KEY1 aaabacbbsscc.

The build op which i have now gives me the following output
KEY1 cc..

There might be other ways of doing this but a build op was coded as there can be millions of entries in the input and there can be 1000's of enteries with the same matching key...

Unfortunetly This buildop is not coded my me and i don't have expertise on c++.

Any help in tweaking it to get what i am expecting will be really great...

Thanks
Pavan
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Pavan_Yelugula wrote:Unfortunetly This buildop is not coded my me and i don't have expertise on c++.
Then - in my humble opinion - you shouldn't be the one posting the issue. Either the original coder or someone who's taken over for them with the C++ experience needed to work with it. Would that be 'UPS'? :?
-craig

"You can never have too many knives" -- Logan Nine Fingers
Pavan_Yelugula
Premium Member
Premium Member
Posts: 133
Joined: Tue Nov 23, 2004 11:24 pm
Location: India

Post by Pavan_Yelugula »

Chulett
It was coded by some IBM Professional and passed on. we came up with a new requirement and wanted to leverage what he has done.

If i can find someone who knows c++ around me They would have been the first person i would have shown this right...

But i am really wondering if this is a really bad idea of posting this on this forum. I was jus looking for someone to point me in the right direction where i can do some research to solve my issue.

I was just taking this as a chance to learn more about c++ and Buildops with this issue.

No Hardfeelings I am neither the original coder nor someone with c++ exp but i don't think i should just give up without trying....
but either you help me in getting me near my goal or u don't respond...what do we achieve with stray comments...

Sorry if u found my reply rude...

Thanks
Pavan
[/quote]
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

And these same 'IBM Professionals' not only didn't comment the code but also did not leave you any documentation for it? That's... unfortunate.

No worries, it's a public forum and everyone is entitled to an opinion - however, there's really no place for "put up or shut up" comments. We're not really here to teach someone C++ nor is it something you pick up from a forum post or two - but I would think some of those who do this on a regular basis - DSGuru2B or tinsmith off the top of my head as two recent C++ posters - could be popping in here and helping out should they so desire. Me, that's not something I profess any expertise in so can't help other than to provide 'stray comments'.

I was serious about the 'UPS' question. They posted in this thread, stated that "Basically this is what we wanted to achieve with this build-op" so I was legitimately wondering if they were the resource you / we should be working with since they seemed to have been involved in writing it.

Anyway, good luck. I'll leave you to your own devices.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply