欢迎投稿

今日深度:

Hive面试题,

Hive面试题,


1、说说Hive中的内部表和外部表?

Managed Table                                         External Table。

默认                                                           创建时加上external关键字

数据由Hive管理                                         数据由HDFS管理

删除表(删除元数据和数据)                    删除表(只删除元数据)

存储位置(/user/hive/warehouse)           存储位置(自定义)
修改内部表会同步元数据                           修改外部表则需要执行MSCK REPAIR TABLE table_name刷新元数据

alter table emp set TBLPROPERTIES('EXTERNAL'='TRUE');//内部表转化成外部表
alter table emp set TBLPROPERTIES('EXTERNAL'='FALSE');//外部表转成内部表

 

select中出现的字段,如果没有出现在组函数/聚合函数中,必须出现在group by里面,否则就会产生报错

 

2、where和having的区别?
where 是对当条记录进行筛选,having是对分组后的结果进行筛选的 

 

hive> select deptno,avg(salary) from ruozedata_emp group by deptno having avg(salary) >2000;

hive> select deptno avg(salary) from ruozedata_emp where avg(salary) >2000 ;

 

3、说说Hive中的join。

hive> select * from a;

1      ruoze

2       j

3       k

hive> select * from b;

1         30

2         29

4         21

A、inner join=join

hive> select a.id,a.name,b.age from a join b on a.id=b.id;

1     ruoze     30

2     j             29

B、left join

hive> select a.id,a.name,b.age from a left join b on a.id=b.id;

1     ruoze     30

2     j             29

3     k            NULL

C、right join

hive> select a.id,a.name,b.age from a right join b on a.id=b.id;

1          ruoze     30

2          j             29

NULL   NULL     21

D、full join

hive> select a.id,a.name,b.age from a left join b on a.id=b.id;

1         ruoze         30

2         j                 29

3         k                NULL

NULL NULL         21

E、left semi join

hive> select a.id,a.name,b.age from a left join b on a.id=b.id;

1         ruoze         

2         j  

 

4、 case when then end 根据已有的字段取一个常用的标识:

hive> select ename, salary,

      > case

      > when salary > 1 and salary <= 1000 then 'LOWER'

      > when salary > 1000 and salary <= 2000 then 'MIDDLE'

      > when salary > 2000 and salary <= 4000 then 'HIGH'

      > ELSE 'HIGHEST'

      > end

      > from ruozedata_emp;

   

5、     

www.htsjk.Com true http://www.htsjk.com/hive/37520.html NewsArticle Hive面试题, 1、说说Hive中的内部表和外部表? Managed Table                                         External Table。 默认                                                      ...
相关文章
    暂无相关文章
评论暂时关闭