zoukankan      html  css  js  c++  java
  • [HIve

    Union Syntax

    select_statement UNION ALL select_statement UNION ALL select_statement ...

    UNION is used to combine the result from multiple SELECT statements into a single result set. Hive currently only supports UNION ALL (bag union), in which duplicates are not eliminated. The number and names of columns returned by each select_statement have to be the same. Otherwise, a schema error is thrown.

    If some additional processing has to be done on the result of the UNION, the entire statement expression can be embedded in a FROM clause like below:

    SELECT *
    FROM (
      select_statement
      UNION ALL
      select_statement
    ) unionResult

    For example, if we suppose there are two different tables that track which user has published a video and which user has published a comment, the following query joins the results of a UNION ALL with the user table to create a single annotated stream for all the video publishing and comment publishing events:

    SELECT u.id, actions.date
    FROM (
        SELECT av.uid AS uid
        FROM action_video av
        WHERE av.date = '2008-06-03'
        UNION ALL
        SELECT ac.uid AS uid
        FROM action_comment ac
        WHERE ac.date = '2008-06-03'
     ) actions JOIN users u ON (u.id = actions.uid)

    Unions can be used in views, inserts, and CTAS (create table as select) statements. A query can contain multiple UNION ALL clauses, as shown in the syntax above.

    Version information

    Icon

    In Hive 0.12.0 and earlier releases, unions can only be used within a subquery such as "SELECT * FROM (select_statement UNION ALLselect_statement UNION ALL ...) unionResult".

    As of Hive 0.13.0, unions can also be used in a top-level query: "select_statement UNION ALL select_statement UNION ALL ...". (See HIVE-6189.)

    谨言慎行,专注思考 , 工作与生活同乐
  • 相关阅读:
    【Codeforces 429D】 Tricky Function
    【HDU 1007】 Quoit Design
    S3C2440开发环境搭建(Ubuntu)
    ubuntu 14.04使用root登陆出现错误“Error found when loading /root/.profile”解决
    Ubuntu 14.04下NFS安装配置
    gcc及其选项详解
    class_create(),class_device_create()创建/dev/xxx 名字
    class_create(),device_create自动创建设备文件结点
    ZedGraph 总论
    ZedGraph类库之基本教程篇
  • 原文地址:https://www.cnblogs.com/tmeily/p/4249843.html
Copyright © 2011-2022 走看看