zoukankan      html  css  js  c++  java
  • hive

    1)引自http://www.crazyant.net/1470.html

    测试数据为:

    hive left join测试数据

    hive left join测试数据

    测试1:left join

    语句:

    select * from table1 left outer join table2 on(table1.student_no=table2.student_no);

    结果:

    FAILED: Parse Error: line 1:22 cannot recognize input near ‘left’ ‘join’ ‘table2’ in join type specifier

    我用的HIVE版本是0.8,不支持直接的left join写法;

    测试2:left outer join

    语句:

    select * from table1 left outer join table2 on(table1.student_no=table2.student_no);

    结果:

    1 name1 1 11
    1 name1 1 12
    1 name1 1 13
    2 name2 2 11
    2 name2 2 14
    3 name3 3 15
    3 name3 3 12
    4 name4 4 13
    4 name4 4 12
    5 name5 5 14
    5 name5 5 16
    6 name6 NULL NULL

    可以看到left outer join左边表的数据都列出来了,如果右边表没有对应的列,则写成了NULL值。

    同时注意到,如果左边的主键在右边找到了N条,那么结果也是会叉乘得到N条的,比如这里主键为1的显示了右边的3条。

    测试3:left semi join

    语句:

    select * from table1 left semi join table2 on(table1.student_no=table2.student_no);

    结果:

    1 name1
    2 name2
    3 name3
    4 name4
    5 name5

    可以看到,只打印出了左边的表中的列,规律是如果主键在右边表中存在,则打印,否则过滤掉了。

    结论:

      • hive不支持’left join’的写法;
      • hive的left outer join:如果右边有多行和左边表对应,就每一行都映射输出;如果右边没有行与左边行对应,就输出左边行,右边表字段为NULL;
      • hive的left semi join:相当于SQL的in语句,比如上面测试3的语句相当于“select * from table1 where table1.student_no in (table2.student_no)”,注意,结果中是没有B表的字段的。

    2) hive 简介,安装,本地文件上传到hive操作

  • 相关阅读:
    细看运维85条军规,是否触动了你内心深处那根弦?
    SQL语句的CRUD
    sqlserver数据库类型对应Java中的数据类型
    Struts2文件上传--多文件上传(插件uploadify)
    web.xml文件详解
    关于Java的散列桶, 以及附上一个案例-重写map集合
    hibernate多表查询封装实体
    spring的7个模块
    Struts标签库详解【3】
    Struts标签库详解【2】
  • 原文地址:https://www.cnblogs.com/hugh2006/p/5642459.html
Copyright © 2011-2022 走看看