You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hive.apache.org by Mich Talebzadeh <mi...@gmail.com> on 2016/03/20 23:27:09 UTC

Column type conversion in Hive

As a matter of interest how does how cast columns from say String to
Integer implicitly?

For example the following shows this

create table s(col1 String);
insert into s values("1");
insert into s values("2");

Now create a target table with col1 being integer


create table o (col1 Int);
insert into o select * from s;

select * from o;
+---------+--+
| o.col1  |
+---------+--+
| 1       |
| 2       |
+---------+--+

So this implicit column conversion from String to Integer happens without
intervention in the code. As a matter of interest what is the underlying
storage for Integer. In a conventional RDBMS this needs to be done through
cast (CHAR AS INT) etc?

Thanks



Dr Mich Talebzadeh



LinkedIn * https://www.linkedin.com/profile/view?id=AAEAAAAWh2gBxianrbJd6zP6AcPCCdOABUrV8Pw
<https://www.linkedin.com/profile/view?id=AAEAAAAWh2gBxianrbJd6zP6AcPCCdOABUrV8Pw>*



http://talebzadehmich.wordpress.com

Re: Column type conversion in Hive

Posted by Edward Capriolo <ed...@gmail.com>.
Explicit conversion is done using cast (x as bigint)

You said: As a matter of interest what is the underlying storage for
Integer?

This is dictated on disk by the input format the "temporal in memory
format" is dictated by the serde, an integer could be stored as "1",
"<value>1</value>" , as dictated by the Input Format and Serde Storage
Handler in use.

On Sun, Mar 20, 2016 at 6:27 PM, Mich Talebzadeh <mi...@gmail.com>
wrote:

>
> As a matter of interest how does how cast columns from say String to
> Integer implicitly?
>
> For example the following shows this
>
> create table s(col1 String);
> insert into s values("1");
> insert into s values("2");
>
> Now create a target table with col1 being integer
>
>
> create table o (col1 Int);
> insert into o select * from s;
>
> select * from o;
> +---------+--+
> | o.col1  |
> +---------+--+
> | 1       |
> | 2       |
> +---------+--+
>
> So this implicit column conversion from String to Integer happens without
> intervention in the code. As a matter of interest what is the underlying
> storage for Integer. In a conventional RDBMS this needs to be done through
> cast (CHAR AS INT) etc?
>
> Thanks
>
>
>
> Dr Mich Talebzadeh
>
>
>
> LinkedIn * https://www.linkedin.com/profile/view?id=AAEAAAAWh2gBxianrbJd6zP6AcPCCdOABUrV8Pw
> <https://www.linkedin.com/profile/view?id=AAEAAAAWh2gBxianrbJd6zP6AcPCCdOABUrV8Pw>*
>
>
>
> http://talebzadehmich.wordpress.com
>
>
>