Apache Hive--DML--select 查询| 学习笔记

简介: 快速学习 Apache Hive--DML--select 查询

开发者学堂课程【大数据 Hive 教程精讲Apache Hive--DML--select 查询】学习笔记,与课程紧密联系,让用户快速学习知识。

课程地址https://developer.aliyun.com/learning/course/90/detail/1378


Apache Hive--DML--select查询

 

Select:

基本的 Select 操作

语法结构

SELECT[ALL | DISTINCT] select_expr, select_expr,...FROM table_reference

JOIN table_other ON expr[WHERE where_condition]

[GROUP BY col_list [HAVING condition]][CLUSTER BY col_list

[DISTRIBUTE BY col_list] [SORT BY| ORDER BY col_list]

]

[LIMIT number]

说明:

1order by 会对输入做全局排序,因此只有一个 reducer,会导致当输入规模较大时,需要较长的计算时间。

2sort by不是全局排序,其在数据进入 reduce r前完成排序。因此,如果用 sort by进行排序,并且设置 mapred.reduce.tasks>1,则 sort by 只保证每个 reducer 的输出有序,不保证全局有序。

3distribute by(字段)根据指定字段将数据分到不同的 reducer,分发算法是hash散列。4Cluster by(字段)除了具有 Distribute by的功能外,还会对该字段进行排序。

如果distribute sort的字段是同一个时,此时,cluster by = distribute by + sort by

分桶、排序等查询:

cluster by . sort bydistribute by

select * from student cluster by (sno);

insert overwrite table student_buck

select * from student cluster by(Sno) sort by(Sage);报错,cluster sort

不能共存

对某列进行分桶的同时,根据另一列进行排序

insert overwrite table stu_buck

select * from student distribute by (Sno) sort by (Sage asc) ;

总结:

cluster(分且排序,必须一样) ==distribute()+ sort(排序)(可以不一样)

1.png

LOAD DAPA local INPATH '/root/hivedata/aaa.txt ' INTO TABLEsource_table;insert overwrite table stu_buck

select * from student cluster by (sno) ;

create table student(Sno int ,Sname string,Sex string ,sage int,sdept string)row format delimited

fields terminated by ', ';

LOAD DATA local INPATH '/root/hivedata/students.txt ' INTO TABLE student;

create external table student_ext (8no int ,Sname string ,sex string,Sage int,sdept string) row format delimited field:

insert overwrite local directory '/root/aaa666'

select *from source_table;

insert overwrite local directory '/root/aaa777'select *from student cluster by (Sno);

2.png

3.png

相关文章
|
1月前
|
SQL 存储 JSON
阿里云数据库 SelectDB 内核 Apache Doris 2.1.0 版本发布:开箱盲测性能大幅优化,复杂查询性能提升 100%
亲爱的社区小伙伴们,Apache Doris 2.1.0 版本已于 2024 年 3 月 8 日正式发布,新版本开箱盲测性能大幅优化,在复杂查询性能方面提升100%,新增Arrow Flight接口加速数据读取千倍,支持半结构化数据类型与分析函数。异步多表物化视图优化查询并助力仓库分层建模。引入自增列、自动分区等存储优化,提升实时写入效率。Workload Group 资源隔离强化及运行时监控功能升级,保障多负载场景下的稳定性。新版本已经上线,欢迎大家下载使用!
阿里云数据库 SelectDB 内核 Apache Doris 2.1.0 版本发布:开箱盲测性能大幅优化,复杂查询性能提升 100%
|
1月前
|
存储 缓存 分布式计算
Apache Hudi数据跳过技术加速查询高达50倍
Apache Hudi数据跳过技术加速查询高达50倍
38 2
|
4月前
|
存储 监控 安全
带你读《Apache Doris 案例集》——07查询平均提速700% ,奇安信基于 Apache Doris 升级日志安全分析系统(1)
带你读《Apache Doris 案例集》——07查询平均提速700% ,奇安信基于 Apache Doris 升级日志安全分析系统(1)
|
4月前
|
SQL 存储 安全
带你读《Apache Doris 案例集》——07查询平均提速700% ,奇安信基于 Apache Doris 升级日志安全分析系统(2)
带你读《Apache Doris 案例集》——07查询平均提速700% ,奇安信基于 Apache Doris 升级日志安全分析系统(2)
107 0
|
1月前
|
SQL 数据可视化 Apache
阿里云数据库内核 Apache Doris 兼容 Presto、Trino、ClickHouse、Hive 等近十种 SQL 方言,助力业务平滑迁移
阿里云数据库 SelectDB 内核 Doris 的 SQL 方言转换工具, Doris SQL Convertor 致力于提供高效、稳定的 SQL 迁移解决方案,满足用户多样化的业务需求。兼容 Presto、Trino、ClickHouse、Hive 等近十种 SQL 方言,助力业务平滑迁移。
阿里云数据库内核 Apache Doris 兼容 Presto、Trino、ClickHouse、Hive 等近十种 SQL 方言,助力业务平滑迁移
|
1月前
|
SQL JSON 算法
hive学习笔记
hive学习笔记
|
1月前
|
分布式计算 大数据 测试技术
查询时间降低60%!Apache Hudi数据布局黑科技了解下
查询时间降低60%!Apache Hudi数据布局黑科技了解下
22 0
|
1月前
|
SQL 分布式计算 Java
Apache Hudi与Hive集成手册
Apache Hudi与Hive集成手册
72 0
|
1月前
|
SQL 分布式计算 API
Apache Hudi从零到一:深入研究读取流程和查询类型(二)
Apache Hudi从零到一:深入研究读取流程和查询类型(二)
49 1
|
3月前
|
SQL 关系型数据库 Apache
Apache Doris 整合 FLINK CDC 、Paimon 构建实时湖仓一体的联邦查询入门
Apache Doris 整合 FLINK CDC 、Paimon 构建实时湖仓一体的联邦查询入门
664 1

推荐镜像

更多