hive行列转换面试题

一、行转列的使用
1、问题
hive如何将

a b 1
a b 2
a b 3
c d 4
c d 5
c d 6

变为:

a b 1,2,3
c d 4,5,6

2、数据
test.txt

a b 1
a b 2
a b 3
c d 4
c d 5
c d 6

3、答案
1.建表

drop table tmp_jiangzl_test;
create table tmp_jiangzl_test
(
col1 string,
col2 string,
col3 string
)
row format delimited fields terminated by ‘\t’
stored as textfile;

load data local inpath ‘/home/jiangzl/shell/test.txt’ into table tmp_jiangzl_test;

2.处理

select col1,col2,concat_ws(‘,’,collect_set(col3))
from tmp_jiangzl_test
group by col1,col2;

二、列转行

1、问题
hive如何将

a b 1,2,3
c d 4,5,6

变为:

a b 1
a b 2
a b 3
c d 4
c d 5
c d 6

2、答案
1.建表

drop table tmp_jiangzl_test;
create table tmp_jiangzl_test
(
col1 string,
col2 string,
col3 string
)
row format delimited fields terminated by ‘\t’
stored as textfile;

处理:

select col1, col2, col3

from tmp_jiangzl_test a

lateral view explode(split(col3,’,’))
b AS col3

left join
right join
inner join

union -去重
union all -不去重

//去重
SELECT id,name,age1 as age FROM table1
UNION
SELECT id,name,age2 as age FROM table2;

//不去重
SELECT id,name,age1 as age FROM table1
UNION all
SELECT id,name,age2 as age FROM table2;

在hive中,创建表之后,你的表结构可以修改吗?分区表创建的时候没有指定分区,是否可以修改增加分区?或者有分区的话,可以删除分区?
ALTER TABLE

//COUNT()与sum()区别?

count():返回的是受影响的行数
sum():指定了某一列字段累加的总和

//select * from table;
select count(id) from table;与select count(distinct id) from table;

id为主键
id不为主键

//分区和分捅

//外部表和内部表的区别
外部表:数据不在warehouse中,所以在创建外部表的时候,需要指定文件的位置(location)
内部表:-表在指定的warehouse中,数据也在warehouse中

//搭建hive环境的时候注意的问题
1、hive安装包
2、安装mysql,并且要启动
3、链接mysql-需要驱动包
4、配置文件修改,增加
5、启动 beeline客户端连接,首先要启动server

集群安装过程
1、安装Linux(hostname,ip,macAddr,免密登陆-需要给自己也要配置免密登陆)
2、关闭防火墙(chkconfig iptables off -> reboot)[halt]
3、修改hosts
4、上传jar,修改配置文件,启动,配置环境变量

问题1、时间同步问题 (date->”date -s “2018-01-08 20:45:00”“)

面试过程中,会问,你对Linux熟悉吗?命令熟悉吗?

Linux里面经常修改哪些文件,并说明他是干什么的?
1、/etc/sysconfig/network-script/ifcfg-eth0 (IP,gateway,mask)
2、/etc/profile (环境变量)->source /etc/profile
3、/etc/hosts(域名映射使用)
4、/etc/udev/rule.d/70-persist-*(eth0)

5、/etc/sysconfig/network (修改主机名)

ln命令-创建软连接

kafka_2.11_0.8.2.0

ln kafka kafka_2.11_0.8.2.0
kafka->kafka_2.11_0.8.2.0

cd kafka

linux 命令或者shell

python


工具
http://www.ofmonkey.com/front/color 程序员在线工具

http://www.runoob.com/scala/scala-tutorial.html 菜鸟教程

https://github.com/

http://www.yiibai.com/hbase/ 易佰教程 HBase

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值