union不支持orderByClause、clusterByClause、distributeByClause、sortByClause或limitClause
union all
union
相同点 是 相当于上下拼接 上下两个拼接表必须字段保持一致
不同 union有去重效果,速度会更慢。
=============================================================================================================================
union all的子句里不支持orderByClause、clusterByClause、distributeByClause、sortByClause或limitClause
解决:改造hql,去掉union all子查询里的orderByClause、clusterByClause、distributeByClause、sortByClause和limitClause语句
示例:select t.id from (select dummy from default.dual limit 1 union all select dummy from default.dual limit 1)t;
去掉两个子查询里的limit 1;
create table lk3 (id string,nname string,grade int,goldUser int); insert into lk3 values
(1,'jack',300, 10 ),
(2,'mach', 200, 10 ),
(3,'lich', 100 ,10 ),
(4,'rock', 1, 0 ),
(5,'mick', 1 ,10 ),
(6,'kight', 0 ,10 ),
(7,'babaya', 0, 0 ),
(8,'kano', 0, 10);
select * from lk3;
+---------+------------+------------+---------------+--+
| lk3.id | lk3.nname | lk3.grade | lk3.golduser |
+---------+------------+------------+---------------+--+
| 1 | jack | 300 | 10 |
| 2 | mach | 200 | 10 |
| 3 | lich | 100 | 10 |
| 4 | rock | 1 | 0 |
| 5 | mick | 1 | 10 |
| 6 | kight | 0 | 10 |
| 7 | babaya | 0 | 0 |
| 8 | kano | 0 | 10 |
+---------+------------+------------+---------------+--+
报错代码:
0: jdbc:hive2://localhost:10000> SELECT * FROM lk3 where grade != 1 order by grade desc,goldUser
. . . . . . . . . . . . . . . .> union all
. . . . . . . . . . . . . . . .> select * from lk3 where grade != 1 order by grade desc,goldUser;
Error: Error while compiling statement: FAILED: ParseException line 3:63 Failed to recognize predicate '<EOF>'.
Failed rule: 'orderByClause clusterByClause distributeByClause sortByClause limitClause can only be applied to the whole union.' in statement (state=42000,code=40000)
正确处理
0: jdbc:hive2://localhost:10000> select * from (SELECT * FROM lk3 where grade != 1 order by grade desc,goldUser limit 1) a
. . . . . . . . . . . . . . . .> union all
. . . . . . . . . . . . . . . .> select * from lk3 where grade != 1 order by grade desc,goldUser limit 2,3;
WARNING: Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.
+--------+-----------+-----------+--------------+--+
| u1.id | u1.nname | u1.grade | u1.golduser |
+--------+-----------+-----------+--------------+--+
| 2 | mach | 200 | 10 |
| 3 | lich | 100 | 10 |
| 7 | babaya | 0 | 0 |
+--------+-----------+-----------+--------------+--+
3 rows selected (33.439 seconds)
还有上下字段必须一致的验证:
0: jdbc:hive2://localhost:10000> select id,nname from (SELECT * FROM lk3 where grade != 1 order by grade desc,goldUser limit 1) a
. . . . . . . . . . . . . . . .> union all
. . . . . . . . . . . . . . . .> select * from lk3 where grade != 1 order by grade desc,goldUser limit 2,3;
Error: Error while compiling statement: FAILED: SemanticException Schema of both sides of union should match. (state=42000,code=40000)
union不支持orderByClause、clusterByClause、distributeByClause、sortByClause或limitClause的更多相关文章
- 【HIVE】sql语句转换成mapreduce
1.hive是什么? 2.MapReduce框架实现SQL基本操作的原理是什么? 3.Hive怎样实现SQL的词法和语法解析? 连接:http://www.aboutyun.com/thread-20 ...
- Hive SQL 编译过程
转自:http://www.open-open.com/lib/view/open1400644430159.html Hive跟Impala貌似都是公司或者研究所常用的系统,前者更稳定点,实现方式是 ...
- [Hive]HiveSQL解析原理
Hive是基于Hadoop的一个数据仓库系统,在各大公司都有广泛的应用.美团数据仓库也是基于Hive搭建,每天执行近万次的Hive ETL计算流程,负责每天数百GB的数据存储和分析.Hive的稳定性和 ...
- 【转】Hive SQL的编译过程
Hive是基于Hadoop的一个数据仓库系统,在各大公司都有广泛的应用.美团数据仓库也是基于Hive搭建,每天执行近万次的Hive ETL计算流程,负责每天数百GB的数据存储和分析.Hive的稳定性和 ...
- Hive SQL的编译过程
文章转自:http://tech.meituan.com/hive-sql-to-mapreduce.html Hive是基于Hadoop的一个数据仓库系统,在各大公司都有广泛的应用.美团数据仓库也是 ...
- 转:Hive SQL的编译过程
Hive是基于Hadoop的一个数据仓库系统,在各大公司都有广泛的应用.美团数据仓库也是基于Hive搭建,每天执行近万次的Hive ETL计算流程,负责每天数百GB的数据存储和分析.Hive的稳定性和 ...
- Hive SQL的编译过程[转载自https://tech.meituan.com/hive-sql-to-mapreduce.html]
https://tech.meituan.com/hive-sql-to-mapreduce.html Hive是基于Hadoop的一个数据仓库系统,在各大公司都有广泛的应用.美团数据仓库也是基于Hi ...
- Hive SQL编译过程(转)
转自:https://www.cnblogs.com/zhzhang/p/5691997.html Hive是基于Hadoop的一个数据仓库系统,在各大公司都有广泛的应用.美团数据仓库也是基于Hive ...
- SQL Server-聚焦UNIOL ALL/UNION查询(二十三)
前言 本节我们来看看有关查询中UNION和UNION ALL的问题,简短的内容,深入的理解,Always to review the basics. 初探UNION和UNION ALL 首先我们过一遍 ...
随机推荐
- [Nowcoder212D]禁书目录_概率期望
禁书目录 题目大意:清教需要定期给Index清除记忆,在此之前需要把当中的十万三千本禁书取出来......不幸的是,禁书一旦离开了Index就非常脆弱,具体来说,每一本禁书都有一个魔力值 ai ,其记 ...
- [CF544D]Destroying Roads_最短路_bfs
D. Destroying Roads 题目大意: In some country there are exactly n cities and m bidirectional roads conne ...
- Reaching Points
A move consists of taking a point (x, y) and transforming it to either (x, x+y) or (x+y, y). Given a ...
- [转帖]postgres 创建新用户并授权-- 非常好的
postgres 创建新用户并授权 https://blog.csdn.net/XuHang666/article/details/81506297 原作者总结的挺好的 可以用来学习一下. grant ...
- PAT A1016 Phone Bills (25)
题目描述 A long-distance telephone company charges its customers by the following rules: Making a long-d ...
- PAT B1041 考试座位号(15)
解题要点: 使用结构体保存准考证号,考试座位号 试机座位号作考生数组下标 通过试机座位号获取考生号,座位号 考生号使用long long存放 //课本AC代码 #include <cstdio& ...
- 学习 Laravel - Web 开发实战入门笔记(1)
本笔记根据 LearnKu 教程边学边记而成.该教程以搭建出一个类似微博的Web 应用为最终成果,在过程中学习 Laravel 的相关知识. 准备开发环境 原教程使用官方推荐的 Homestead 开 ...
- crm--rbac权限组件使用步骤
本人的权限组件码云地址:https://gitee.com/shiguanggege/rbac 里面有文档详细介绍权限组件的使用步骤
- 【数位DP】恨7不成妻
[数位DP]恨7不成妻 时间限制: 1 Sec 内存限制: 128 MB提交: 8 解决: 4[提交] [状态] [命题人:admin] 题目描述 单身!依然单身! 吉哥依然单身!DS级码农吉哥依 ...
- Jmeter之压测探索和结果分析
1.copy过来的,很有道理的一句话~ 最大并发数:取决于你的业务类型,数据量,处理时的资源需求等,具体多少,需要做一些性能测试来衡量 确定待测试的场景,设计脚本,不断增加并发数量. 2.CPU压不上 ...