Page 1 of 1

How to generate the following using data in datastage

Posted: Mon Jan 23, 2012 7:50 am
by jpradeep.net
I have to generate a file with two columns (ID and COMB). ID must contain a sequence number so Integer data type.(I took care of that). COMB column must have the data like this. ( it can be numeric or string)
111111111111111
111111111111110
111111111111100

and so on. The size is 15 and it must have binary only (either 1 or 0).
so, we can get (2 power 15)=32768 combinations.
that means

1. 111111111111111
2. 111111111111110
3. 111111111111100
|
|
|
32768. 000000000000000

Posted: Mon Jan 23, 2012 1:56 pm
by qt_ky
Is this a training exercise?

You know all ones = 32768 and all zeros = 0. Following your logic, you should start with ID = 0, right? Do you care about the order?

Posted: Mon Jan 23, 2012 3:24 pm
by ray.wurlod
Much, much, much easier done in a server job. Is this an interview question?

In a server job, generate the integers using a Transformer stage and, in that stage, generate the binary equivalents using Oconv(integer, "MB0C") then left-pad with zeroes as required.

Posted: Mon Jan 23, 2012 8:28 pm
by qt_ky
Correction: all ones = 32767

Posted: Mon Jan 23, 2012 8:55 pm
by qt_ky
In a parallel job, you can do this with a Row Generator to create the ID as a number 1 through 32768, then a Transformer stage derivation for the COMB column:

Code: Select all

BitExpand(32768 - lnk.ID)[15]
The BitExpand function returns a string of the binary representation a given integer. The [15] takes the right-most 15 characters. The minus part gives you the "reversed order" you mentioned, where ID 1 gives COMB of all ones (15 ones represents integer 32767) and ID 32768 gives COMB of all zeros, representing integer value zero.

Output to a Sequential File and apply whatever sorting you want, i.e. based on the ID, in the stage properties.

Hi Eric Dodson, Thank you for the reply

Posted: Tue Jan 24, 2012 12:23 am
by jpradeep.net
Thanks a lot for the reply, but i just want to have the combination of the 1 and zero for the length of 15 and every combination must be unique.for example 100000000000000
000000000000001
000000000000011
000000000001111
and so on. We have to use 1 and 0 only and the length is 15 so 2 power 15=32768 combinations.there is no particular order also. I have to get each combination in a separate row.this is not a training exercise.

Posted: Tue Jan 24, 2012 2:28 am
by ray.wurlod
That's what Eric's solution will give you.