Field from a word

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
arunkumarmm
Participant
Posts: 246
Joined: Mon Jun 30, 2008 3:22 am
Location: New York
Contact:

Field from a word

Post by arunkumarmm »

My requirement is to split the incoming string based on the no. of words.

If the source data has four words, my output should be C1 - first 2 words and C2 - next 2 words.

If there are 7 words, C1 - 3 words and C2 - next 4 words.

I can count the no. of spaces and div by 2 and find the word from which the string should be split.

As Field fn will not accept more than one char as delimiter, If it is server, I can use the Ereplace and replace that word with @FM and use @FM as delimiter in Field fn to extract first part.

Is there a similar kind of fn in parallel that I can use to achieve this?
I believe convert can only replace single char.
Arun
anbu
Premium Member
Premium Member
Posts: 596
Joined: Sat Feb 18, 2006 2:25 am
Location: india

Post by anbu »

Use Field function to extract the words based on the delimiter
You are the creator of your destiny - Swami Vivekananda
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

There is an EReplace function available in this forum. Please search and use it.
arunkumarmm
Participant
Posts: 246
Joined: Mon Jun 30, 2008 3:22 am
Location: New York
Contact:

Post by arunkumarmm »

anbu wrote:Use Field function to extract the words based on the delimiter
Anbu, creating the delimiter is my problem. I cannot replace the entire word with @FM using convert nor I can use that word as delimiter in the field function.

In server I can write the derivation like,

Field(Ereplace('Arun Kumar','Kumar',@FM),@FM,1),
Is there a similar function/way in parallel?
Arun
anbu
Premium Member
Premium Member
Posts: 596
Joined: Sat Feb 18, 2006 2:25 am
Location: india

Post by anbu »

If i understand your requirement

Code: Select all

wrds="A B C D"
C1=Field(wrds," ",1) : Field(wrds," ",2)
C2=Field(wrds," ",3) : Field(wrds," ",4)
You can have two links from transformer one constraint as space count equal to 4 and other for 7. In second link write derivation like above to get 3 and 4 words from your input
You are the creator of your destiny - Swami Vivekananda
arunkumarmm
Participant
Posts: 246
Joined: Mon Jun 30, 2008 3:22 am
Location: New York
Contact:

Post by arunkumarmm »

No Anbu. My requirement is to split the input string into two, if the words are not equal maximum words should be on the second column. No. of words are dynamic in the input.

Eg., Str = "One Two Three Four"
O/P: C1 = 'One Two" C2 = "Three Four"

If Str = "One Two Three Four Five"
O/P: C1 = 'One Two" C2 = "Three Four Five"

If Str = "One Two Three Four Five Six Seven"
O/P: C1 = 'One Two Three" C2 = "Four Five Six Seven"

And no restriction for No. of words in the input. Hope this is clear.
Arun
arunkumarmm
Participant
Posts: 246
Joined: Mon Jun 30, 2008 3:22 am
Location: New York
Contact:

Post by arunkumarmm »

arunkumarmm wrote:
anbu wrote:Use Field function to extract the words based on the delimiter
Anbu, creating the delimiter is my problem. I cannot replace the entire word with @FM using convert nor I can use that word as delimiter in the field function.

In server I can write the derivation like,

Field(Ereplace('Arun Kumar','Kumar',@FM),@FM,1),
Is there a similar function/way in parallel?
Thanks Sainath. I found that.
Arun
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You don't need Ereplace() to split. Field() function alone will suffice.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
arunkumarmm
Participant
Posts: 246
Joined: Mon Jun 30, 2008 3:22 am
Location: New York
Contact:

Post by arunkumarmm »

Field will work only if the delimiter is one character. If the delimiter is more than one, it will take the first character as delimiter
Arun
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

The requirement does not specify multiple-character delimiters.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

Wait a sec, I have a different idea.

When you say your delimiter is of more than one character, does it imply 2 identical characters or different values.

For example, do you see
'ThisbbIsbbAbbTestbbString'
Or
'ThisXYIsXYAXYTestXYStringXY'
If it is the first case, you can take fields of odd numbers together or trim your fields before concat. In second case, you can use your first delimiter ('X' in this case') in your field function and remove leading 'Y's from your non-first columns.

These remove the need for EReplace. But includes one extra step.
arunkumarmm
Participant
Posts: 246
Joined: Mon Jun 30, 2008 3:22 am
Location: New York
Contact:

Post by arunkumarmm »

ray.wurlod wrote:The requirement does not specify multiple-character delimiters. ...
Ray, I quoted that field fn will not accpet more than one char as delimiter.

I'm sorry if that was not clear.
As Field fn will not accept more than one char as delimiter, If it is server, I can use the Ereplace and replace that word with @FM and use @FM as delimiter in Field fn to extract first part.

Is there a similar kind of fn in parallel that I can use to achieve this?
I believe convert can only replace single char.
Arun
arunkumarmm
Participant
Posts: 246
Joined: Mon Jun 30, 2008 3:22 am
Location: New York
Contact:

Post by arunkumarmm »

Sainath.Srinivasan wrote:Wait a sec, I have a different idea.

When you say your delimiter is of more than one character, does it imply 2 identical characters or different values.

For example, do you see
'ThisbbIs ...
Sai, Thanks for your reply!

I dont have any specific delimiter. I want to split the incoming string based on the no. of words. So I want to use one of those words as a delimiter to split it.
Eg.,
If Str = "One Two Three Four Five Six Seven"
O/P should be: C1 = 'One Two Three" C2 = "Four Five Six Seven"

What I'm trying to do is, Count(Str,' ') = 6, 6/2 = 3, so my column 1 should have 3 words. So, so replace the 4th word with @FM, use it as delimiter and extract the first three words.
Arun
Post Reply