hive 内部表 外部表 创建

编程入门 行业动态 更新时间:2024-10-24 22:22:40

<a href=https://www.elefans.com/category/jswz/34/1769093.html style=hive 内部表 外部表 创建"/>

hive 内部表 外部表 创建

目录

        • hive outline
        • hive 内部表 外部表的区别
        • hive 创建内部表 外部表

hive outline

链接

  1. hive中有2种类型的表:内部表(默认)和外部表
  2. 管理表又叫做内部表

hive 内部表 外部表的区别

本身有两种表,第一种的是内部表,第二种是外部表;内部表呢,又叫管理表

  1. 创建表时:创建外部表时,需要加上一个关键字external,而在创建内部表时,不需要加任何关键字,默认创建的就是内部表
  2. 删除表时:删除内部表时,数据块和元数据都会被删除,而在删除外部表时,只会删除元数据,不会删除数据块

实际应用中一般很少创建内部表,当用到临时表时,会考虑内部表

hive 创建内部表 外部表

1. 创建一个数据存储目录

mkdir input

2.创建本地文件

vim dept.txt

#添加以下内容
10	ACCOUNTING	1700
20	RESEARCH	1800
30	SALES	1900
40	OPERATIONS	1700

vim emp.txt

#添加以下内容
7369	SMITH	CLERK	7902	1980-12-17	800.00		20
7499	ALLEN	SALESMAN	7698	1981-2-20	1600.00	300.00	30
7521	WARD	SALESMAN	7698	1981-2-22	1250.00	500.00	30
7566	JONES	MANAGER	7839	1981-4-2	2975.00		20
7654	MARTIN	SALESMAN	7698	1981-9-28	1250.00	1400.00	30
7698	BLAKE	MANAGER	7839	1981-5-1	2850.00		30
7782	CLARK	MANAGER	7839	1981-6-9	2450.00		10
7788	SCOTT	ANALYST	7566	1987-4-19	3000.00		20
7839	KING	PRESIDENT		1981-11-17	5000.00		10
7844	TURNER	SALESMAN	7698	1981-9-8	1500.00	0.00	30
7876	ADAMS	CLERK	7788	1987-5-23	1100.00		20
7900	JAMES	CLERK	7698	1981-12-3	950.00		30
7902	FORD	ANALYST	7566	1981-12-3	3000.00		20
7934	MILLER	CLERK	7782	1982-1-23	1300.00		10

3.创建外部表dept
关键字 external:外部的

create external table if not exists default.dept(
deptno int,
dname string,
loc int
)
row format delimited fields terminated by '\t';

4.创建内部表emp

不加任何关键字即为创建内部表,即hive默认的表类型

create table if not exists default.emp(
empno int,
ename string,
job string,
mgr int,
hiredate string, 
sal double, 
comm double,
deptno int)
row format delimited fields terminated by '\t';
  1. 将本地文件加载到hive中
hive > load data local inpath '/opt/modules/input/dept.txt' into table dept;    
hive > load data local inpath '/opt/modules/input/emp.txt' into table emp;

更多推荐

hive 内部表 外部表 创建

本文发布于:2023-07-28 17:48:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1267010.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:hive

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!