未被external修饰的是内部表(managed table),被external修饰的为外部表(external table);
区别:
内部表数据由Hive自身管理,外部表数据由HDFS管理;
内部表数据存储的位置是hive.metastore.warehouse.dir(默认:/user/hive/warehouse),外部表数据的存储位置由自己制定;
删除内部表会直接删除元数据(metadata)及存储数据;删除外部表仅仅会删除元数据,HDFS上的文件并不会被删除;
对内部表的修改会将修改直接同步给元数据,而对外部表的表结构和分区进行修改,则需要修复(MSCK REPAIR TABLE table_name;)

如下,进行试验进行理解
试验理解
创建内部表t1

create table t1(
    id      int
   ,name    string
   ,hobby   array<string>
   ,add     map<String,string>
)
row format delimited
fields terminated by ','
collection items terminated by '-'
map keys terminated by ':'
;

2. 查看表的描述:desc t1;
装载数据(t1)

注:一般很少用insert (不是insert overwrite)语句,因为就算就算插入一条数据,也会调用MapReduce,这里我们选择Load Data的方式。

LOAD DATA [LOCAL] INPATH 'filepath' [OVERWRITE] INTO TABLE tablename [PARTITION (partcol1=val1, partcol2=val2 ...)]

然后上载

load data local inpath '/home/hadoop/Desktop/data' overwrite into table t1;

别忘记写文件名/data,笔者第一次忘记写,把整个Desktop上传了,一查全是null和乱码。。。。
查看表内容:

select * from t1;

创建一个外部表t2

create external table t2(
    id      int
   ,name    string
   ,hobby   array<string>
   ,add     map<String,string>
)
row format delimited
fields terminated by ','
collection items terminated by '-'
map keys terminated by ':'
location '/user/t2'
;

装载数据(t2)

load data local inpath '/home/hadoop/Desktop/data' overwrite into table t2;

查看文件位置
我们在NameNode:50070/explorer.html#/user/目录下,可以看到t2文件

t1在哪呢?在我们之前配置的默认路径里

同样我们可以通过命令行获得两者的位置信息:

desc formatted table_name;

这里写图片描述

这里写图片描述
注:图中managed table就是内部表,而external table就是外部表。
分别删除内部表和外部表

下面分别删除内部表和外部表,查看区别
观察HDFS上的文件

发现t1已经不存在了
这里写图片描述

但是t2仍然存在
这里写图片描述
因而外部表仅仅删除元数据
重新创建外部表t2

create external table t2(
    id      int
   ,name    string
   ,hobby   array<string>
   ,add     map<String,string>
)
row format delimited
fields terminated by ','
collection items terminated by '-'
map keys terminated by ':'
location '/user/t2'
;

这里写图片描述

不往里面插入数据,我们select * 看看结果
这里写图片描述
可见数据仍然在!!!
官网介绍

以下是官网中关于external表的介绍:

A table created without the EXTERNAL clause is called a managed table because Hive manages its data.
Managed and External Tables
By default Hive creates managed tables, where files, metadata and statistics are managed by internal Hive processes. A managed table is stored under the hive.metastore.warehouse.dir path property, by default in a folder path similar to /apps/hive/warehouse/databasename.db/tablename/. The default location can be overridden by the location property during table creation. If a managed table or partition is dropped, the data and metadata associated with that table or partition are deleted. If the PURGE option is not specified, the data is moved to a trash folder for a defined duration.
Use managed tables when Hive should manage the lifecycle of the table, or when generating temporary tables.
An external table describes the metadata / schema on external files. External table files can be accessed and managed by processes outside of Hive. External tables can access data stored in sources such as Azure Storage Volumes (ASV) or remote HDFS locations. If the structure or partitioning of an external table is changed, an MSCK REPAIR TABLE table_name statement can be used to refresh metadata information.
Use external tables when files are already present or in remote locations, and the files should remain even if the table is dropped.
Managed or external tables can be identified using the DESCRIBE FORMATTED table_name command, which will display either MANAGED_TABLE or EXTERNAL_TABLE depending on table type.
Statistics can be managed on internal and external tables and partitions for query optimization.

Hive官网介绍:
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-DescribeTable/View/Column

hive内部表&外部表介绍的更多相关文章

  1. 第2节 hive基本操作:9、hive当中创建外部表的语法及外部表的操作&分区表的语法和操作

    外部表: 外部表说明: 外部表因为是指定其他的hdfs路径的数据加载到表当中来,所以hive表会认为自己不完全独占这份数据,所以删除hive表的时候,数据仍然存放在hdfs当中,不会删掉 管理表和外部 ...

  2. Hive 文件格式 & Hive操作(外部表、内部表、区、桶、视图、索引、join用法、内置操作符与函数、复合类型、用户自定义函数UDF、查询优化和权限控制)

    本博文的主要内容如下: Hive文件存储格式 Hive 操作之表操作:创建外.内部表 Hive操作之表操作:表查询 Hive操作之表操作:数据加载 Hive操作之表操作:插入单表.插入多表 Hive语 ...

  3. Hive基础(5)---内部表 外部表 临时表

    1.外部表 关键字:EXTERNAL 外部表创建时需要指定LOCATION 删除外部表时,数据不被删除 CREATE EXTERNAL TABLE page_view(viewTime INT, us ...

  4. hive 四种表,分区表,内部,外部表,桶表

    Hive四大表类型内部表.外部表.分区表和桶表 一.概述 总体上Hive有四种表:外部表,内部表(管理表),分区表,桶表.分别对应不同的需求.下面主要讲解各种表的适用情形.创建和加载数据方法. 二.具 ...

  5. Hive内部表外部表转化分析(装)

    link:http://anyoneking.com/archives/127hive表分为内部表和外部表.外部表在删除的时候并不会删除到hdfs中的文件,比较安全,所以对于重要的需要进行分析的日志建 ...

  6. 分区表,桶表,外部表,以及hive一些命令行小工具

    hive中的表与hdfs中的文件通过metastore关联起来的.Hive的数据模型:内部表,分区表,外部表,桶表受控表(managed table):包括内部表,分区表,桶表 内部表: 我们删除表的 ...

  7. oracle-对象表-外部表

    http://www.blogjava.net/decode360/archive/2008/10/16/286802.html create or replace type person as ob ...

  8. hive内部表与外部表区别详细介绍

    问题导读:1.创建内部表与外部表的区别是什么?2.external关键字的作用是什么?3.外部表与内部表的区别是什么?4.删除表的时候,内部表与外部表有什么区别?5.load data local i ...

  9. hive内部表、外部表

    hive内部表.外部表区别自不用说,可实际用的时候还是要小心. Hive的数据分为表数据和元数据,表数据是Hive中表格(table)具有的数据:而元数据是用来存储表的名字,表的列和分区及其属性,表的 ...

随机推荐

  1. (转)df命令

    转:http://man.linuxde.net/df df命令用于显示磁盘分区上的可使用的磁盘空间.默认显示单位为KB.可以利用该命令来获取硬盘被占用了多少空间,目前还剩下多少空间等信息. 语法 d ...

  2. Python 进阶_生成器 & 生成器表达式

    目录 目录 相关知识点 生成器 生成器 fab 的执行过程 生成器和迭代器的区别 生成器的优势 加强的生成器特性 生成器表达式 生成器表达式样例 小结 相关知识点 Python 进阶_迭代器 & ...

  3. pip install 报SSL异常和timeout异常

    在安装pip3 install virtualenv时报了SSL异常 如图 pip is configured with locations that require TLS/SSL, however ...

  4. flask实现异步任务

    最近在开发同步mysql数据到redis的接口,因为数据同步涉及各种增删查改,如果用同步实现,可能回造成连接超时.堵塞,所以,使用python实现异步任务. 代码实现from flask import ...

  5. 安装SSH2拓展 PHP上传文件到远程服务器

    情景:客户端上传图片到服务器A,服务器A同步上传至另外一个静态资源服务器B 环境:php7 linux(ubuntu) 安装php的ssh2扩展 -dev sudo apt-get install p ...

  6. OSX 创建 randisk(或称 tmpfs)

    创建步骤: #!/bin/bash ramdisk_size_in_mb= mount_point=/private/tmp ramdisk_size_in_sectors=$((${ramdisk_ ...

  7. 使用matplotlib画出log的图像

    以下内容是学习笔记,若有侵权,立即删除! import math import matplotlib.pyplot as plt import numpy as np if __name__ == ' ...

  8. checkBox的全选与全不选

    //初始加载 $(function () {   LoadCart(); }); var RMB = 0; var Index = 0; var shu = 0; var ResultStr = &q ...

  9. Java前端控制器模式~

    前端控制器设计模式用于提供集中式请求处理机制,以便所有请求将由单个处理程序处理.此处理程序可以执行请求的身份验证/授权/记录或跟踪,然后将请求传递到相应的处理程序. 以下是这种类型的设计模式的实体. ...

  10. Dubbo 系列(07-4)集群容错 - 集群

    BDubbo 系列(07-4)集群容错 - 集群 [toc] Spring Cloud Alibaba 系列目录 - Dubbo 篇 1. 背景介绍 相关文档推荐: Dubbo 集群容错 - 实战 D ...