Page 1 of 2

Use of index function

Posted: Mon May 28, 2007 4:10 am
by sjordery
Hi all,

I am not getting the proper output while using index function.
My source data contains data like this

-------------------------
file_name,file_type

abcd.txt,txt
efgh.csv,csv
--------------------------

I want the output like this

------------------------------
file_name,file_type,occurence

abcd.txt,txt,5
efgh.csv,csv,5

------------------------------------

the value of occurence is calculated by calaculating the the position of " . " in the file_name column

for this I have used a stage variable whose derivation is set to
index(input.file_name,'.',1)and mapped to the occurence column.
But every time I am getting the value as 0.

Can anybody suggest?

Posted: Mon May 28, 2007 5:48 am
by rafik2k
Is your job parallel or server?


0 means it is not finding "." in the input string.

For server job, try writing small subroutine and check like

findDot

Code: Select all

Position = Index(Arg1, ".", 1) 
Ans = Position
call the subroutine in column derivation of occurance as findDot(file_name), though ur code and this routine are same, just for checking.

Posted: Mon May 28, 2007 6:23 am
by sjordery
Thanks rafique
As I have mentioned on the top job type is parallel.
If the function is avaliable in the transformer do I need to go for the subroutine?

Posted: Mon May 28, 2007 6:34 am
by balajisr
What is your source?

Can you replace your source with row generator stage and generate these values and post the result?

Posted: Mon May 28, 2007 6:49 am
by JoshGeorge
index(input.file_name,'.',1) or index(input.file_name,".",1) is right. Stage variable type also does not matter even if you are using the default type. Now you need to debug yourself with different sample records.

Posted: Mon May 28, 2007 6:56 am
by sjordery
my job design is like this

seqfile------->transformer----->sequential_file

If I will use rowgenerator please suggest how I will generate data for the column having .(dot)extension?

Posted: Mon May 28, 2007 7:02 am
by sjordery
josh,

I have put the same syntax on the top what you have specified,but I am getting 0 as output.
I have used the stage varibale like this

input.filename stagevar1
index(stagevar1,'.',1) stagevar2

The data type I have specified as varchar for both the stage variables,I tried with specifying integer also but nt able to get the output as required.

Posted: Mon May 28, 2007 7:04 am
by balajisr
Have column datatype as varchar in row generator. Have a test job with only one column and generate value for that column alone.

Also, Try writing the sequential file to peek to check what you receive is what you expect.

Do you get any warnings when you run the job?

Were you able to view data in the sequential file?

Posted: Mon May 28, 2007 7:13 am
by sjordery
The job is running sucessfully.
In the output I mean in the occurance column I am supposed to get values 5,5(Please check the 1st post) but,I am getting 0,0.
If I will use rowgenerator stage as source it will produce random values which maynt contain . part.

Posted: Mon May 28, 2007 7:17 am
by balajisr
If I will use rowgenerator stage as source it will produce random values which maynt contain . part.
Not true.

Posted: Mon May 28, 2007 7:44 am
by DSguru2B
Then there is something fishy in the data.
Try the following and see what the following shows in your output

Code: Select all

Field(in.Data, ".", 1)

Posted: Mon May 28, 2007 10:42 pm
by sjordery
Code:

Field(in.Data, ".", 1)

I tried this one,but getting 0,0 values.

Posted: Mon May 28, 2007 11:05 pm
by ray.wurlod
Index should be fine. What are the data types of stage variables? You will need Integer of some kind for the result of Index().

Posted: Mon May 28, 2007 11:10 pm
by sjordery
The data type of both the stage variables are Varchar.

Posted: Mon May 28, 2007 11:15 pm
by ray.wurlod
You will need Integer of some kind for the result of Index().