Page 1 of 1

String

Posted: Mon Mar 24, 2008 11:52 am
by albasir
Hi all,

My input:

AAAAA = 10000 OR AAAAA = 10000 AND BBBBB = 20000 AND CCCCC = 20000 OR CCCCC=20000 AND DDDDD=30000

Output should be:

(AAAAA = 10000 OR AAAAA = 10000) AND (BBBBB = 20000) AND (CCCCC = 20000 OR CCCCC=20000) AND (DDDDD=30000)

basically all the ORs should be grouped and put into braces from the input.
PLease suggest me to arrive at the desired result.

Thanks,
-M

Posted: Mon Mar 24, 2008 12:00 pm
by ArndW
Can you perhaps explain exactly which stage and what columns you have? Are AAAAA, BBBBB, CCCCC column names?

Posted: Mon Mar 24, 2008 12:06 pm
by albasir
ArndW wrote:Can you perhaps explain exactly which stage and what columns you have? Are AAAAA, BBBBB, CCCCC column names? ...

These are not column names... AAAAA, BBBBB are the values as part my test input data stream...i am trying to build a dynamic WHERE clause in transformer stage...this WHERE clause will be used later to query a Oracle stage...

Let me now if you need furthe info

Thanks
-M

Posted: Mon Mar 24, 2008 12:23 pm
by ArndW
This is more along the lines of a buildop in PX. If you can use server jobs then you could do some string manipulation in a loop, I'd use INDEX(In.Col,' OR ') to find the "or" statement, then go back 3 words and prepend a '(' and then go forward 3 words and put in a ')'. That approach is straightforward, but won't work if you have 2 or more ORs in a row.

Posted: Mon Mar 24, 2008 1:22 pm
by trammohan
Can be implemented in a C routine and call it from the transformer..

Posted: Mon Mar 24, 2008 1:23 pm
by trammohan
Can be implemented in a C routine and call it from the transformer..

Posted: Mon Mar 24, 2008 1:55 pm
by albasir
ArndW wrote:This is more along the lines of a buildop in PX. If you can use server jobs then you could do some string manipulation in a loop, I'd use INDEX(In.Col,' OR ') to find the "or" statement, then go back ...
Yes...Index function is returning the position of my "AND" Keywords...
Please give me some hint how to put these into a loop to find position of all the AND keywords in a particulare record...

My idea is to replace all the' AND ' with ') AND (' with some more additional adjustments. In this way i can brackets for all my OR keywords.
But i could not figure out CHANGE function or EREPLACE function in the transformer.

Is there a more elegant way to acheive this!!!

Posted: Mon Mar 24, 2008 2:45 pm
by trammohan
Albasir,

There is one External Filter stage in PX... use that stage to replace string with the following sed command

sed 's/AND/\) AND \(/g'

hope this helps...

Posted: Tue Mar 25, 2008 2:20 am
by ArndW
The "EREPLACE" function doesn't exist in the PX transform stage, so the external sed function, perhaps in a wrapper, will work but might be just as slow as using a BASIC transform stage. In that case, it would be better to evaluate writing this job in Server.

Posted: Tue Mar 25, 2008 10:56 am
by albasir
ArndW wrote:The "EREPLACE" function doesn't exist in the PX transform stage, so the external sed function, perhaps in a wrapper, will work but might be just as slow as using a BASIC transform stage. In that case, ...
Hi Arndw,

your suggesstions are not appearing till the end...Some premium content icon comes in between so i could not get your suggesstions entirely. IS that a way to get rid of this??

Posted: Tue Mar 25, 2008 11:22 am
by gateleys
albasir wrote:...Some premium content icon comes in between so i could not get your suggesstions entirely. IS that a way to get rid of this??
Yeah! Get a premium membership.

Posted: Tue Mar 25, 2008 11:55 am
by ArndW
That particular post only had a couple more words to it, but it is certainly worthwhile getting a premium membership.

Posted: Tue Mar 25, 2008 12:11 pm
by albasir
ArndW wrote:That particular post only had a couple more words to it, but it is certainly worthwhile getting a premium membership.
Sure...Thanks for your help :D