conditional transformation
--------------------------
if function
-----------
It is used to perform conditional transformatins.
if(condition,true val,false val)
1st argument is condition
2nd argument true val
3rd argument false val
[cloudera@quickstart ~]$ cat file1
200,300
100,200
200,100
700,800
700,400
hive> create table data(a int,b int)
> row format delimited fields terminated by ',';
hive> load data local inpath 'file1' into table data;
hive>select *from data;
syntax
------
alter table tablename add columns(col1 type,col2 type,....);
hive>alter table data add columns(big int);
hive> insert overwrite table data
> select a,b,if(a>b,a,b) from data;
Nested if functions
-------------------
cat > file1
100,200,300
400,200,500
700,500,100
900,400,1000
hive> select a,b,c,if(a>b,if(b>c,b,c),if(a>c,a,c)) from ifdata;
--------------------------
if function
-----------
It is used to perform conditional transformatins.
if(condition,true val,false val)
1st argument is condition
2nd argument true val
3rd argument false val
[cloudera@quickstart ~]$ cat file1
200,300
100,200
200,100
700,800
700,400
hive> create table data(a int,b int)
> row format delimited fields terminated by ',';
hive> load data local inpath 'file1' into table data;
hive>select *from data;
syntax
------
alter table tablename add columns(col1 type,col2 type,....);
hive>alter table data add columns(big int);
hive> insert overwrite table data
> select a,b,if(a>b,a,b) from data;
Nested if functions
-------------------
cat > file1
100,200,300
400,200,500
700,500,100
900,400,1000
hive> select a,b,c,if(a>b,if(b>c,b,c),if(a>c,a,c)) from ifdata;
No comments:
Post a Comment