zoukankan      html  css  js  c++  java
  • Hive内表和外表的区别

    本文以例子的形式介绍一下Hive内表和外表的区别。例子共有4个:不带分区的内表、带分区的内表、不带分区的外表、带分区的外表。

    1 不带分区的内表

    #创建表

    create table innerTable(id int,name string) row format delimited fields terminated by ‘|’;(show tables发现没有innerTable,只有innertable。不多说,记住了)

    #从HDFS上加载数据

    load data inpath ‘hdfs://master:9000/user/root/test/innerTable’ into table innertable; (查看HDFS上/user/root/test/innerTable,发现文件价innerTable还在,但是里面的文件已经不在了。去哪了,去innertable表中了)

    #删除刚刚创建的表

    drop table innertable;(到HDFS上看一下innertable文件夹及其中的文件都没有了。去哪了,删除表的时候删除了)

    2 带分区的内表

    #创建表

    create table inner_table_with_p(id int,name string) partitioned by (part_num int);(HDFS 出现文件夹inner_table_with_p,文件夹中为空)

    #从HDFS加载数据

    load data inpath ‘hdfs://master:9000/user/root/test/innerTable/part1′ into table inner_table_with_p partition(part_num=1)(文件夹inner_table_with_p出现子文件夹part_num=1,innerTable中part1消失);

    load data inpath ‘hdfs://master:9000/user/root/test/innerTable/part2′ into table inner_table_with_p partition(part_num=2)(文件夹inner_table_with_p出现子文件夹part_num=2,innerTable中part2消失);

    load data inpath ‘hdfs://master:9000/user/root/test/innerTable/part3′ into table inner_table_with_p partition(part_num=3)(文件夹inner_table_with_p出现子文件夹part_num=3,innerTable中part3消失);

    #删除分区

    alter table inner_table_with_p drop partition(part_num=1);(part_num=1对应分区文件夹本删除)

    #删除表

    drop table inner_table_with_p;(HDFS上inner_table_with_p文件夹被删除)

    3 不带分区的外表

    创建表

    create external table outer_table(id int,name string) row format delimited fields terminated by ‘|’;      (hive仓储目录中出现outer_table)

    加载数据

    load data inpath ‘/user/root/test/outerTable/outer’ into table outer_table;(outer_table中出现子文件outer,outerTable中outer消失)

    删除表

    drop table outer_table;    (outer_table及子文件outer依然存在,因为这是外表)

    4 带分区的外表

    创建表

    create external table outer_table_with_p(id int,name string) partitioned by (part_num int) row format delimited fields terminated by ‘|’; (hive仓储目录中出现outer_table_with_p)

    加载数据

    load data inpath ‘/user/root/test/outerTable/part1′ into table outer_table_with_p partiton(part_num=1);  (outer_table_with_p中出现子文件夹part_num=1)

    load data inpath ‘/user/root/test/outerTable/part2′ into table outer_table_with_p partition(part_num=2);(outer_table_with_p中出现子文件夹part_num=2)

    load data inpath ‘/user/root/test/outerTable/part3′ into table outer_table_with_p partition(part_num=3);(outer_table_with_p中出现子文件夹part_num=3)

    删除分区

    alter table outer_table_with_p drop partition(part_num=1);(HDFS上分区文件依旧存在)

    删除表

    drop table outer_table_with_p;(HDFS上对应数据依旧存在)

    总结:

    1 删除内表时,内表数据会一并删除;

    2 删除外表时,外表数据依旧存在。

    推荐阅读:

    Hive本地独立模式安装 http://www.linuxidc.com/Linux/2013-06/86104.htm

    [Hive] 完全分布式安装过程(MetaStore: MySQL) http://www.linuxidc.com/Linux/2013-05/84085.htm

    Meet so Meet. C plusplus I-PLUS....
  • 相关阅读:
    剑指offer 二叉树中和为某一个值的路径
    剑指offer 二叉搜索树的后序遍历序列
    二叉树
    剑指offer 二叉树的层序遍历
    剑指offer 二叉树的镜像
    二叉树的子结构
    牛客网 斐波那契数列
    NMT 机器翻译
    剑指offer 从尾到头打印链表
    剑指offer 链表中倒数第k个节点
  • 原文地址:https://www.cnblogs.com/iplus/p/4489930.html
Copyright © 2011-2022 走看看