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的更多相关文章

  1. 【HIVE】sql语句转换成mapreduce

    1.hive是什么? 2.MapReduce框架实现SQL基本操作的原理是什么? 3.Hive怎样实现SQL的词法和语法解析? 连接:http://www.aboutyun.com/thread-20 ...

  2. Hive SQL 编译过程

    转自:http://www.open-open.com/lib/view/open1400644430159.html Hive跟Impala貌似都是公司或者研究所常用的系统,前者更稳定点,实现方式是 ...

  3. [Hive]HiveSQL解析原理

    Hive是基于Hadoop的一个数据仓库系统,在各大公司都有广泛的应用.美团数据仓库也是基于Hive搭建,每天执行近万次的Hive ETL计算流程,负责每天数百GB的数据存储和分析.Hive的稳定性和 ...

  4. 【转】Hive SQL的编译过程

    Hive是基于Hadoop的一个数据仓库系统,在各大公司都有广泛的应用.美团数据仓库也是基于Hive搭建,每天执行近万次的Hive ETL计算流程,负责每天数百GB的数据存储和分析.Hive的稳定性和 ...

  5. Hive SQL的编译过程

    文章转自:http://tech.meituan.com/hive-sql-to-mapreduce.html Hive是基于Hadoop的一个数据仓库系统,在各大公司都有广泛的应用.美团数据仓库也是 ...

  6. 转:Hive SQL的编译过程

    Hive是基于Hadoop的一个数据仓库系统,在各大公司都有广泛的应用.美团数据仓库也是基于Hive搭建,每天执行近万次的Hive ETL计算流程,负责每天数百GB的数据存储和分析.Hive的稳定性和 ...

  7. Hive SQL的编译过程[转载自https://tech.meituan.com/hive-sql-to-mapreduce.html]

    https://tech.meituan.com/hive-sql-to-mapreduce.html Hive是基于Hadoop的一个数据仓库系统,在各大公司都有广泛的应用.美团数据仓库也是基于Hi ...

  8. Hive SQL编译过程(转)

    转自:https://www.cnblogs.com/zhzhang/p/5691997.html Hive是基于Hadoop的一个数据仓库系统,在各大公司都有广泛的应用.美团数据仓库也是基于Hive ...

  9. SQL Server-聚焦UNIOL ALL/UNION查询(二十三)

    前言 本节我们来看看有关查询中UNION和UNION ALL的问题,简短的内容,深入的理解,Always to review the basics. 初探UNION和UNION ALL 首先我们过一遍 ...

随机推荐

  1. windows下安装Sonar

    1.sonar安装: sonar有三部分组成: 1.服务端:显示分析结果和sonar相关配置 2.客户端:对项目运行源代码进行运算和分析 3.数据库:存储sonar配置和代码分析结果的数据库 2.so ...

  2. 【ActiveReports 大数据分析报告】2019国庆旅游出行趋势预测

    今年国庆假期全国接待国内游客人数有望达到8亿人次! 随着2019国庆小长假的临近,不少游客已经开始着手规划假期出游路线.据权威机构发布的<2019国庆旅游趋势预测报告>显示,今年“十一黄金 ...

  3. Python +requests 关于post请求返回报错

    python+request 发送post请求:msg返回"Content type 'application/octet-stream' not supported" 一.问题源 ...

  4. IDEA自动生成的注释模板

    使用效果如下: * * @功能描述 : $params$ * @return $returns$ * @author xuetao */ 其中 $params$的表达式如下: groovyScript ...

  5. ArrayList与LinkedList的区别,如何减少嵌套循环的使用

    如果要减少嵌套循环的使用: 我们可以将需要在二重循环里面判断的条件放在一个Map的key里面: 在判断的时候只需要进行key是否存在,然后操作接下来的步骤: 这样子就会减少二重循环了,不会发生循环n* ...

  6. C/C++文件输入输出操作——FILE*、fstream、windowsAPI(转载)

    基于C的文件操作 在ANSI C中,对文件的操作分为两种方式,即流式文件操作和I/O文件操作,下面就分别介绍之. 一.流式文件操作 这种方式的文件操作有一个重要的结构FILE,FILE在头文件stdi ...

  7. phpQuery简介

    接上一篇,使用 Snoopy 抓取回来网页之后,需要解析网页中的元素,但是对于 https://www.cnblogs.com/hellowzd/p/5163276.html

  8. php网络请求

    get请求 /** * get请求 * @param $url,请求地址 * @return bool|string */ function getRequest($url){ $headerArra ...

  9. CentOS7 Python3上安装paramiko

    1. CentOS 7下安装Python3.5 CentOS7默认安装了python2.7.5,要用 Python3需要自己手动安装.注意不要删除python2. 1.1 下载python3源码包 w ...

  10. 并不对劲的复健训练-p3674

    题目大意 给出序列$ a_1,...,a_n $ ( $ n\leq10^5,a\leq 10^5 $ ),有\(m\) ( \(m\leq 10^5\))个以下三类询问: (1)给出\(l,r,k\ ...