hive行列轉換面試題

2021-12-30 12:46:11 字數 2795 閱讀 7951

一、行轉列的使用

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)

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

linux 命令或者shell

python

SQL面試題之行列轉換

建表語句 set foreign key checks 0 table structure for tb drop table ifexists tb create table tb 姓名 varchar 10 default null,課程 varchar 10 default null,分數 i...

Hive 行列轉換

在京東眾多業務中,業務充滿了複雜性和挑戰性,因為業務的靈活性,很多資料都儲存成xml和json格式資料,這就要求下游資料分析師們需要對其做解析後方可使用 在眾多操作中 有一種是需要對資料做行列轉換操作。資料結構 create external table jd row to column jd id...

Hive面試題三

2014010114 2014010216 2014010317 2014010410 2014010506 2012010609 2012010732 2012010812 2012010919 2012011023 2001010116 2001010212 2001010310 2001010...