一、行专列
1.相关函数说明
- concat(string A/col, string B/col…):返回输入字符串连接后的结果,支持任意个输入字符串;
- concat_ws(separator, str1, str2,...):它是一个特殊形式的 concat()。第一个参数剩余参数间的分隔符。分隔符可以是与剩余参数一样的字符串。如果分隔符是 NULL,返回值也将为 NULL。这个函数会跳过分隔符参数后的任何 NULL 和空字符串。分隔符将被加到被连接的字符串之间;
- collect_set(col):函数只接受基本数据类型,它的主要作用是将某字段的值进行去重汇总,产生array类型字段。
- collect_list(col):与collect_set作用相似,区别不去重字段,产生array类型字段。
2. 数据准备
name |
constellation |
blood_type |
孙悟空 |
白羊座 |
A |
大海 |
射手座 |
A |
宋宋 |
白羊座 |
B |
猪八戒 |
白羊座 |
A |
凤姐 |
射手座 |
A |
3. 创建本地constellation.txt,导入数据
[hadoop@hadoop112 datas]$ vi constellation.txt
孙悟空 白羊座 A
大海 射手座 A
宋宋 白羊座 B
猪八戒 白羊座 A
凤姐 射手座 A
苍老师 白羊座 B
4. 创建hive表并导入数据
create table person_info(
name string,
constellation string,
blood_type string)
row format delimited fields terminated by "\t";
load data local inpath "/opt/module/datas/constellation.txt" into table person_info;