String to Double DataType Conversion

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
atulgoel
Participant
Posts: 84
Joined: Tue Feb 03, 2009 1:09 am
Location: Bangalore, India

String to Double DataType Conversion

Post by atulgoel »

Hi,

My Source and target is Hive Database. I need to convert a column datatype from String to Double. I am using Run Time Column Propagation.

Using Modify stage is it possible to convert a Column from String to Double?
Atul
UCDI
Premium Member
Premium Member
Posts: 383
Joined: Mon Mar 21, 2016 2:00 pm

Post by UCDI »

No.

You need to call a transformer and convert the column from one type to another (the incoming metadata is char or varchar or whatever, the outgoing metadata is numeric type of your choice) and use the data conversion function to do this.

Modify is more generally used to add or drop columns, though it can do a few other things this is not one of them. You can use the modify to restructure the metadata from "string" to "numeric" but it wouldn't do the conversion -- you would just get the string bytes misinterpreted into numeric bytes and effectively create a random number generator.

the column you are operating on should not be RCP but exposed in the metadata. You can use modify or other tricks to expose or rename or otherwise force some column into the path that does the conversion but generally it would be best to pass it in as an exposed column -- its easier to write it that way, and its easier to understand it that way, etc.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You could use decimal_from_string() function, possibly encapsulated in a dfloat_from_decimal() function.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
atulgoel
Participant
Posts: 84
Joined: Tue Feb 03, 2009 1:09 am
Location: Bangalore, India

Post by atulgoel »

Below function is working fine. Using this I can load the String data from source to target having Double datatype in Hive.

<ColName>:DFLOAT=<ColName>
Atul
UCDI
Premium Member
Premium Member
Posts: 383
Joined: Mon Mar 21, 2016 2:00 pm

Post by UCDI »

Interesting!

I saw the 'm' (for manual) on the float types and understood it to mean "use a transformer function" in the help page : https://www.ibm.com/support/knowledgece ... stage.html

so apparently I misread it. My apologies. I guess d and m mean you can do it either way, not that "manual is required". Its worded a little strangely.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Moderator: please clean up this thread and block the poster of the previous three messages, yangping55.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

As a moderator I can only do the former. The latter requires someone like Rick or Andy.

Texted Rick...
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply