0
点赞
收藏
分享

微信扫一扫

大数据课程-学习二十周总结

看山远兮 2023-05-23 阅读 83

4.2.10.hive表中的数据导出

将hive表中的数据导出到其他任意目录,例如linux本地磁盘,例如hdfs,例如mysql等等
4.2.10.1.insert导出
1)将查询的结果导出到本地
insert overwrite local directory ‘/export/data/exporthive’ select * from score;

2)将查询的结果格式化导出到本地
insert overwrite local directory ‘/export/data/exporthive’ row format delimited fields terminated by ‘\t’ select * from student;

3)将查询的结果导出到HDFS上(没有local)

insert overwrite directory ‘/exporthive’ row format delimited fields terminated by ‘\t’ select * from score;

4.2.10.2.hive shell 命令导出

基本语法:(hive -f/-e 执行语句或者脚本 > file)
hive -e “select * from myhive.score;” > /export/data/exporthive/score.txt

4.2.10.3.export导出到HDFS上
export table score to ‘/export/exporthive/score’;

4.2.10.4.sqoop导出
后续单独讲。

5.hive查询语法

5.1.SELECT语句
5.1.1.语句结构
基本语法:
SELECT [ALL | DISTINCT]select_expr, select_expr, …
FROM table_reference
[WHERE where_condition]
[GROUP BY col_list]
[HAVING where_condition]
[ORDER BY col_list]
[CLUSTER BY col_list
| [DISTRIBUTE BY col_list] [SORT BY col_list]
]
[LIMIT number]
解释:
1、ORDER BY用于全局排序,就是对指定的所有排序键进行全局排序,使用ORDER BY的查询语句,最后会用一个Reduce Task来完成全局排序。
2、sort by用于分区内排序,即每个Reduce任务内排序。,则sort by只保证每个reducer的输出有序,不保证全局有序。
3、distribute by(字段)根据指定的字段将数据分到不同的reducer,且分发算法是hash散列。
4、cluster by(字段) 除了具有Distribute by的功能外,还兼具sort by的排序功能。。
因此,如果distribute by和sort by字段是同一个时,此时,cluster by = distribute by + sort by

5.1.2.全表查询
select * from score ;

5.1.3.选择特定列查询
select sid ,cid from score;

5.1.4.列别名
select sid as myid ,cid from score;

5.1.5.常用函数
1)求总行数(count)
select count(1) from score;
2)求分数的最大值(max)
select max(sscore) from score;
3)求分数的最小值(min)
select min(sscore) from score;
4)求分数的总和(sum)
select sum(sscore) from score;
5)求分数的平均值(avg)
select avg(sscore) from score;

5.1.6.LIMIT语句
典型的查询会返回多行数据。LIMIT子句用于限制返回的行数。
select * from score limit 3;
select * from score limit 3,5; #从索引为3的行开始,显示5行

5.1.7.WHERE语句
1)使用WHERE 子句,将不满足条件的行过滤掉。
2)WHERE 子句紧随 FROM 子句。
3)案例实操
查询出分数大于60的数据
select * from score where sscore > 60;

举报

相关推荐

0 条评论