• hive的union问题


    内容来源:http://blog.csdn.net/azhao_dn/article/details/6921429

    在hive上执行查询:

    select count(*) from user_active_vv_20110801_31 where active_type_3>

    UNION ALL 

    select count(*) from user_active_vv_20110801_31 where active_type_7>

    union all 

    select count(*) from user_active_vv_20110801_31 where active_type_9>

    union all 

    select count(*) from user_active_vv_20110801_31 where active_type_11>

    union all 

    select count(*) from user_active_vv_20110801_31 where active_type_12>

    union all 

    select count(*) from user_active_vv_20110801_31 where active_type_17>

    union all 

    select count(*) from user_active_vv_20110801_31 where active_type_22>0; 

    报错:

    FAILED: Error in semantic analysis: Top level UNION is not supported currently; use a subquery for the UNION 

    原来hive不支持顶层union,只能将union封装在子查询中;且必须为union的查询输出定义别名,正确的hql如下:

     

    select * from (select count(*) as type3 from user_active_vv_20110801_31 where user_active_vv_20110801_31.active_type_3>

    UNION ALL 

    select count(*) as type3 from user_active_vv_20110801_31  where user_active_vv_20110801_31.active_type_7>

    union all 

    select count(*) as type3 from user_active_vv_20110801_31 where user_active_vv_20110801_31.active_type_9>

    union all 

    select count(*) as type3 from user_active_vv_20110801_31 where user_active_vv_20110801_31.active_type_11>

    union all 

    select count(*) as type3 from user_active_vv_20110801_31 where user_active_vv_20110801_31.active_type_12>

    union all 

    select count(*) as type3 from user_active_vv_20110801_31 where user_active_vv_20110801_31.active_type_17>

    union all 

    select count(*) as type3 from user_active_vv_20110801_31 where user_active_vv_20110801_31.active_type_22>0) tmp; 

    执行结果如下:

    • 54211920 
    • 57691832 
    • 41080830 
    • 44067696 
    • 32052350 
    • 34341676 
    • 13968539 
  • 相关阅读:
    代理模式 值代理
    装饰者模式 检查装饰器循环
    装饰者模式 静态装饰组合
    装饰者模式 在依赖注入中体现
    代理模式 属性代理
    装饰器模式 动态组合装饰
    代理模式 请勿饮酒
    享元模式 文本编辑
    Mysql 字符串字段判断是否包含某个字符串的3种方法
    vuex存储保存数据、使用数据
  • 原文地址:https://www.cnblogs.com/judylucky/p/3714001.html
Copyright © 2020-2023  润新知