Hive学习笔记(一)各种连接

表和数据

  • 创建数据库
create database if not exists test;
use test;
  • 创建sales表
create table sales(
		name  varchar(50),
		product_id	int
		)
row format delimited fields terminated by ',';
  • 创建things表
create table things(
		produt_id int,
		product_name varchar(100)
		)
row format delimited fields terminated by ',';
  • 装载数据
    默认在/home/usename下找
load data local inpath 'hive/data/sales.txt'
overwrite into table sales;

load data local inpath 'hive/data/things.txt'
overwrite into table things;
  • sales.txt
    wei,1
    duan,2
    tao,3
    yu,0

  • things.txt
    1,laptop
    2,cup
    3,car
    4,bar

Hive学习笔记(一)各种连接_第1张图片

笛卡尔积 join

select *
from sales s join things t;
Hive学习笔记(一)各种连接_第2张图片

inner join

select * from sales s join things t on s.product_id==t.product_id;
Hive学习笔记(一)各种连接_第3张图片

left outer join

select * from sales s left outer join things t on s.product_id==t.product_id;
Hive学习笔记(一)各种连接_第4张图片

right outer join

select * from sales s right outer join things t on s.product_id==t.product_id;
Hive学习笔记(一)各种连接_第5张图片

full outer join

select * from sales s full outer join things t on s.product_id==t.product_id;

Hive学习笔记(一)各种连接_第6张图片

left semi join

select * from sales s left semi join things t on s.product_id==t.product_id;
Hive学习笔记(一)各种连接_第7张图片

right semi join


select * from sales s right semi join things t on s.product_id==t.product_id;

map-side join

适用于大小表 小表放在map端
select /+ mapjoin(t)/ * from sales s join things t on s.product_id==t.product_id;

Hive学习笔记(一)各种连接_第8张图片

你可能感兴趣的:(大数据技术)