Page 1 of 1

String to Double DataType Conversion

Posted: Tue Jan 10, 2017 6:37 am
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?

Posted: Tue Jan 10, 2017 1:47 pm
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.

Posted: Wed Jan 11, 2017 11:08 pm
by ray.wurlod
You could use decimal_from_string() function, possibly encapsulated in a dfloat_from_decimal() function.

Posted: Wed Feb 01, 2017 1:47 am
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>

Posted: Wed Feb 01, 2017 7:58 am
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.

Posted: Thu Jun 22, 2017 4:52 am
by ray.wurlod
Moderator: please clean up this thread and block the poster of the previous three messages, yangping55.

Posted: Thu Jun 22, 2017 6:04 am
by chulett
As a moderator I can only do the former. The latter requires someone like Rick or Andy.

Texted Rick...