I have a table with a column double type, and I am trying to convert that from double to string.
However, when I use the cast command, it "smartly" convert that into scientific notation. like below:
select
number,
cast(number as string),
from ...
it looks like
number c1_
9999999902 9.999999902E9
9999999902 9.999999902E9
9999999902 9.999999902E9
9999999902 9.999999902E9
9999999909 9.999999909E9
Can anyone show me how to avoid converting that into scientific and keep the raw text?
By using this command below one can change the column data type: ALTER TABLE table_name CHANGE column_name column_name new_datatype; I hope this works.
Hive CAST function converts the value of an expression to any other type. The result of the function will be NULL in case if function cannot converts to particular data type. You can use this function when passing a column value or literal to a function that expects a parameter with a different data type.
Description. CONCAT_WS() stands for Concatenate With Separator and is a special form of CONCAT() . The first argument is the separator for the rest of the arguments. The separator is added between the strings to be concatenated. The separator can be a string, as can the rest of the arguments.
COALESCE(T v1, T v2, …) Returns the first v that is not NULL, or NULL if all v's are NULL. Return: T. CASE a WHEN b THEN c [WHEN d THEN e]* [ELSE f] END. This is similar to the switch statement where when a = b, returns c; when a = d, returns e; else returns f.
Hive converts double to scientific representation while cast to string because Hive treats double itself in a same way. Therefore, problem is not with cast to string.
See below example:
select 9999999902.0, cast(9999999902.0 as BIGINT), cast(cast(9999999902.0 as BIGINT) as string) from ..
Output:
OK
9.999999902E9 9999999902
Hive supports good old printf()
function so that you can control the output format explicitly - check Language Manual UDF under "String functions"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With