create table company_info( personId string, company string, money float
)row format delimited fields terminated by "\t"
p1 公司 1 100
p2 公司 2 200
p1 公司 3 150
p3 公司 4 300
load data local inpath "/opt/module/datas/company_info.txt" into table company_info;
select * from company_info order by money desc;
select * from company_info distribute by personId sort by personId, money desc;
select * from company_info distribute by personId sort by personId;
select * from company_info cluster by personId;
p1 公司 3 150.0
p1 公司 1 100.0
p2 公司 2 200.0
p3 公司 4 300.0
select * from company_info distribute by personId
p3 公司 4 300.0
p1 公司 3 150.0
p2 公司 2 200.0
p1 公司 1 100.0
==========================
create table person(
name string,
constellation string,
blood_type string)
row format delimited fields terminated by "\t";
load data local inpath '/opt/module/datas/person.tsv' into table person;
孙悟空 白羊座 A
大海 射手座 A
康师傅 白羊座 B
猪八戒 白羊座 A
凤姐 射手座 A
select
t1.base,
concat_ws('|', collect_set(t1.name)) name
from
(select
name,
concat(constellation, ",", blood_type) base
from
person) t1
group by
t1.base;
t1.base name
射手座,A 凤姐
射手座,A 大海
白羊座,A 孙悟空
白羊座,A 猪八戒
白羊座,B 康师傅
射手座,A 大海|凤姐
白羊座,A 孙悟空|猪八戒
白羊座,B 康师傅
=========================
create table movie( movie string, category array<string>)
row format delimited fields terminated by "\t" collection items terminated by ",";
《疑犯追踪》 悬疑,动作,科幻,剧情
《疑犯追踪》 悬疑,动作,科幻,剧情
《Lie to me》 悬疑,警匪,动作,心理,剧情
《战狼 2》 战争,动作,灾难
load data local inpath "/opt/module/datas/movie.tsv" into table movie;
select explode(category) as category_name
from
movie
悬疑
动作
科幻
剧情
悬疑
警匪
动作
心理
剧情
战争
动作
灾难
select
movie,
category_name
from
movie lateral view explode(category) table_tmp as category_name;
《疑犯追踪》 悬疑
《疑犯追踪》 动作
《疑犯追踪》 科幻
《疑犯追踪》 剧情
《Lie to me》 悬疑
《Lie to me》 警匪
《Lie to me》 动作
《Lie to me》 心理
《Lie to me》 剧情
《战狼 2》 战争
《战狼 2》 动作
《战狼 2》 灾难
select
t1.category_name,
concat_ws('|', collect_set(t1.movie)) name
from
( select
movie,
category_name
from
movie lateral view explode(category) table_tmp as category_name) t1
group by
t1.category_name;
剧情 《疑犯追踪》|《Lie to me》
动作 《疑犯追踪》|《Lie to me》|《战狼 2》
心理 《Lie to me》
悬疑 《疑犯追踪》|《Lie to me》
战争 《战狼 2》
灾难 《战狼 2》
科幻 《疑犯追踪》
警匪 《Lie to me》
create table category_list(
category_name string,
name array<string>)
row format delimited
fields terminated by "\t"
collection items terminated by "|";
load data inpath "/youtube/output2" into table category_list;
insert overwrite directory "/youtube/output3" row format delimited fields terminated by "\t"
collection items terminated by "&" select * from category_list;
剧情 《疑犯追踪》&《Lie to me》
动作 《疑犯追踪》&《Lie to me》&《战狼 2》
心理 《Lie to me》
悬疑 《疑犯追踪》&《Lie to me》
战争 《战狼 2》
灾难 《战狼 2》
科幻 《疑犯追踪》
警匪 《Lie to me》
select
t1.category_name,
count(distinct movie) ct
from
( select
movie,
category_name
from
movie lateral view explode(category) table_tmp as category_name) t1
group by
t1.category_name;
剧情 2
动作 3
心理 1
悬疑 2
战争 1
灾难 1
科幻 1
警匪 1
select *
from emp, dept, (select * from emp)
where
group by
having
order by
limit
)row format delimited fields terminated by "\t"
p1 公司 1 100
p2 公司 2 200
p1 公司 3 150
p3 公司 4 300
load data local inpath "/opt/module/datas/company_info.txt" into table company_info;
select * from company_info order by money desc;
select * from company_info distribute by personId sort by personId, money desc;
select * from company_info distribute by personId sort by personId;
select * from company_info cluster by personId;
p1 公司 3 150.0
p1 公司 1 100.0
p2 公司 2 200.0
p3 公司 4 300.0
select * from company_info distribute by personId
p3 公司 4 300.0
p1 公司 3 150.0
p2 公司 2 200.0
p1 公司 1 100.0
==========================
create table person(
name string,
constellation string,
blood_type string)
row format delimited fields terminated by "\t";
load data local inpath '/opt/module/datas/person.tsv' into table person;
孙悟空 白羊座 A
大海 射手座 A
康师傅 白羊座 B
猪八戒 白羊座 A
凤姐 射手座 A
select
t1.base,
concat_ws('|', collect_set(t1.name)) name
from
(select
name,
concat(constellation, ",", blood_type) base
from
person) t1
group by
t1.base;
t1.base name
射手座,A 凤姐
射手座,A 大海
白羊座,A 孙悟空
白羊座,A 猪八戒
白羊座,B 康师傅
射手座,A 大海|凤姐
白羊座,A 孙悟空|猪八戒
白羊座,B 康师傅
=========================
create table movie( movie string, category array<string>)
row format delimited fields terminated by "\t" collection items terminated by ",";
《疑犯追踪》 悬疑,动作,科幻,剧情
《疑犯追踪》 悬疑,动作,科幻,剧情
《Lie to me》 悬疑,警匪,动作,心理,剧情
《战狼 2》 战争,动作,灾难
load data local inpath "/opt/module/datas/movie.tsv" into table movie;
select explode(category) as category_name
from
movie
悬疑
动作
科幻
剧情
悬疑
警匪
动作
心理
剧情
战争
动作
灾难
select
movie,
category_name
from
movie lateral view explode(category) table_tmp as category_name;
《疑犯追踪》 悬疑
《疑犯追踪》 动作
《疑犯追踪》 科幻
《疑犯追踪》 剧情
《Lie to me》 悬疑
《Lie to me》 警匪
《Lie to me》 动作
《Lie to me》 心理
《Lie to me》 剧情
《战狼 2》 战争
《战狼 2》 动作
《战狼 2》 灾难
select
t1.category_name,
concat_ws('|', collect_set(t1.movie)) name
from
( select
movie,
category_name
from
movie lateral view explode(category) table_tmp as category_name) t1
group by
t1.category_name;
剧情 《疑犯追踪》|《Lie to me》
动作 《疑犯追踪》|《Lie to me》|《战狼 2》
心理 《Lie to me》
悬疑 《疑犯追踪》|《Lie to me》
战争 《战狼 2》
灾难 《战狼 2》
科幻 《疑犯追踪》
警匪 《Lie to me》
create table category_list(
category_name string,
name array<string>)
row format delimited
fields terminated by "\t"
collection items terminated by "|";
load data inpath "/youtube/output2" into table category_list;
insert overwrite directory "/youtube/output3" row format delimited fields terminated by "\t"
collection items terminated by "&" select * from category_list;
剧情 《疑犯追踪》&《Lie to me》
动作 《疑犯追踪》&《Lie to me》&《战狼 2》
心理 《Lie to me》
悬疑 《疑犯追踪》&《Lie to me》
战争 《战狼 2》
灾难 《战狼 2》
科幻 《疑犯追踪》
警匪 《Lie to me》
select
t1.category_name,
count(distinct movie) ct
from
( select
movie,
category_name
from
movie lateral view explode(category) table_tmp as category_name) t1
group by
t1.category_name;
剧情 2
动作 3
心理 1
悬疑 2
战争 1
灾难 1
科幻 1
警匪 1
select *
from emp, dept, (select * from emp)
where
group by
having
order by
limit