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 首先我们过一遍 ...
随机推荐
- 二项式反演/minmax容斥初探
世界是物质的,物质是运动的,运动是有规律的,规律是可以被认识的 二项式反演 \[ g_n=\sum_{i=0}^n \binom{n}if_i\Rightarrow f_n=\sum_{i=0}^n( ...
- 切割nginx access日志
#!/bin/bash nginx_root=/www/server/nginx log_path=/www/wwwlogs yesterday=`date -d "-1 day" ...
- [js]EasyUI导出数据表格(Export DataGrid)
包括 'datagrid-export.js' 文件 <script type="text/javascript" src="datagrid-export.js& ...
- golang(9):网络编程 & redis
网络编程 TCP/IP 协议: . TCP(传输控制协议) -- 应用程序之间通信 . UDP(用户数据包协议)-- 应用程序之间的简单通信 . IP(网际协议) -- 计算机之间的通信 . DHCP ...
- 基于光线追踪的渲染中景深(Depth of field)效果的实现
图形学离线渲染中常用的透视摄像机模型时根据小孔成像的原理建立的,其实现通常是从向成像平面上发射ray,并把trace这条ray的结果作为成像平面上对应交点的采样结果.即: 图片来自<Fundam ...
- [CSS] w3c 盒模型 和 IE 盒模型
- 不错的abap技术网站
http://www.saptechnical.com/index.htm https://sapcodes.com/
- C++虚函数和纯虚函数的用法和区别
C++虚函数与纯虚函数用法与区别(转) 1. 虚函数和纯虚函数可以定义在同一个类(class)中,含有纯虚函数的类被称为抽象类(abstract class),而只含有虚函数的类(class)不能 ...
- 【异常】lockfile.AlreadyLocked: ~/airflow/airflow-scheduler.pid is already locked
1 完整异常信息 File "/usr/bin/airflow", line 32, in <module> args.func(args) File "/u ...
- python如何编译py文件生成pyc、pyo、pyd以及如何和C语言结合使用
python执行py文件的流程 当我们执行一个py文件的时候,直接python xx.py即可,那么这个流程是怎么样的呢.先说明一下,python执行代码实际上是先打开文件然后执行里面的代码,所以文件 ...