Page 1 of 1

Format String

Posted: Mon Oct 16, 2006 1:10 pm
by sainath
Hi
my o/p is seq file. and i have to search for , in the string.if , is found
then each word will have to be inserted in new line.

ex
int.txt = abc , def,ghi

then
int.txt = abc
int.txt= def
int.txt= ghi

can you share your thoughts.
thks

Posted: Mon Oct 16, 2006 1:40 pm
by samsuf2002
what is ur job design?

suggestion

Posted: Mon Oct 16, 2006 2:04 pm
by htrisakti3
here's my suggested approach:

1) [input seq] --> [T1] --> [output seq]
output: append
T1: Field(instr, "," , n)
n: job param = N-th occurence of word (ie: 1st=abc, 2nd=def)

2) call job (1) using another job with BASIC FOR 1..n LOOP
in your example, calling job1(n=1,2,3) .. would complete the task

3) Have another job to simply do WordNum=Count(instr, ",") & output it to some temp txt file, Call Job2 with WordNum as param.

Posted: Mon Oct 16, 2006 2:20 pm
by kcbland
Try to stick with one pass thru the file. Consider reading the entire line using a sequential stage using 1 column of metadata. Pass the entire line to a function you will write. In that function, look at the specific field that contains the data of interest. Loop thru the count of delimiters, and build a copy of the line for each pass, adding a LF as you concatenate a big string. Return the entire row back as the result. Have the job write the result to a sequential file. Because you have added LF, DataStage will only show in the monitor that it read N rows and wrote N rows, but line counting the file will show more than N rows. Now re-read the second file using fully defined column metadata and you will be fine.

Avoid running jobs inside loops.

Posted: Mon Oct 16, 2006 2:58 pm
by sainath
hi
can you guys explain little bit more clear with example.and also I have to delete original record.
pl share your thoughts
thks

Posted: Mon Oct 16, 2006 9:06 pm
by ray.wurlod
This horizontal pivot looks very like a job for a Pivot stage to me.

Posted: Mon Oct 16, 2006 9:17 pm
by chulett
Exactly... parse the columns out and then pivot. Don't think you need to 'delete' the original record, just don't pass it on.

HI

Posted: Tue Oct 17, 2006 7:20 am
by sainath
Hi
Thanks for your reply.
we have to parce data before using the pivot stage.
but how can we parce data based on delimitor ,.i dont know how many are there.

ex
key column txt
k1 k2 k3 k4 k5 abc,def,ghi.....


o/p

k1 k2 k3 k4 k5 abc
k1 k2 k3 k4 k5 def
k1 k2 k3 k4 k5 ghi

Posted: Tue Oct 17, 2006 8:30 am
by ray.wurlod
This is a different requirement from your original one, and probably deserves a separate thread. We answered the question you asked.

If you know the maximum possible number of fields, parse into this many columns, and set the remainder to NULL. Then run through a Pivot stage.