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. Linux正则表达式结合三剑客企业级实战

    1.取系统ip 解答: 1)ifconfig ens33 |sed -n '2p'|sed "s#inet##g"|sed 's#n.*$##g'  2)ifconfig ens3 ...

  2. PHP中的闭包

    1.语句结构 在PHP中,由于存在函数内部不能访问全局作用的,所以就需要一种可以引入上一级作用域的语法结构,这种就是 function () use () {} 将需要引入到这个函数作用于内的变量写入 ...

  3. spring boot 使用elasticsearch

    在文章开始之前我们先来介绍一下elasticsearch 是一个分布式的 RESTful 风格的搜索和数据分析引擎. 查询 : Elasticsearch 允许执行和合并多种类型的搜索 — 结构化.非 ...

  4. 怎么将本地项目放到码云(gitee)上面?图文详解

    git的好处什么的,在此就不多赘述.现在很多公司都在用git了. 那么怎么将本地已经有的项目放到码云(gitee)上呢? 前置条件说明: 1:原来项目所在位置:D:\workspace01\class ...

  5. ARST第四周打卡

    Algorithm : 做一个 leetcode 的算法题 ////////////////////////////////////////////////////////////////////// ...

  6. Django之模型层:表操作

    目录 Django之模型层:表操作 一.ORM简介 django测试环境搭建 Django终端打印SQL语句 二 单表操作 2.1 按步骤创建表 2.2记录 三.多表操作 1 创建模型 2 添加.删除 ...

  7. T100——按xls格式批量导入数据

    弹出File Browser窗口 PRIVATE FUNCTION cxrt020_open_file() DEFINE l_dir LIKE type_t.chr500 DEFINE r_succe ...

  8. Codeforces 1237C2. Balanced Removals (Harder)

    传送门 先来考虑一下二维时的情况,那么对于 $x$ 相同的点,我们按 $y$ 排序,然后相邻的一对对消除 最后 $x$ 坐标相同的点最多剩下一个,那么此时所有点的 $x$ 坐标都不一样 再按 $x$ ...

  9. c++ 性能优化策略

    c++ 性能优化策略 作者:D_Guco 来源:CSDN 原文:https://blog.csdn.net/D_Guco/article/details/75729259 1 关于继承:不可否认良好的 ...

  10. O047、 Cinder 组件详解

    参考https://www.cnblogs.com/CloudMan6/p/5585637.html   cinder-api   cinder-api 是整个Cinder 组件的门户,所有cinde ...