zoukankan      html  css  js  c++  java
  • hive外部表和内部表

    1.内部表指hive创建并通过load data inpath进数据库的表,这种表可以理解为数据和表结构都保存在一起的数据表。当你通过DROP TABLE table_name 删除元数据中表结构的同时,表中的数据也同样会从hdfs中被删除。

    1. CREATE TABLE new_hbase_table(rowkey string, x int, y int)   
    2. STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'  
    3. WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,cf:x,cf:y");  
    4.   
    5. SET hive.hbase.bulk=true;  
    6.   
    7. INSERT OVERWRITE TABLE new_hbase_table  
    8. SELECT rowkey_expression, x, y FROM ...any_hive_query...;  

    这里在hive中会将hbase的数据加载过来,并且保存相应的结构

    2.外部表指在表结构创建以前,数据已经保存在hdfs中了,通过创建表结构,将数据格式化到表的结构里。当DROP TABLE table_name 的时候,hive仅仅会删除元数据的表结构,而不会删除hdfs上的文件,所以,相比内部表,外部表可以更放心大胆的使用。

    1. create external table hb_range_keys(transaction_id_range_start string)  
    2. row format serde   
    3. 'org.apache.hadoop.hive.serde2.binarysortable.BinarySortableSerDe'  
    4. stored as   
    5. inputformat   
    6. 'org.apache.hadoop.mapred.TextInputFormat'  
    7. outputformat   
    8. 'org.apache.hadoop.hive.ql.io.HiveNullValueSequenceFileOutputFormat'  
    9. location '/tmp/hb_range_keys';  
    10.   
    11. insert overwrite table hb_range_keys  
    12. select transaction_id from  
    13. (select transaction_id  
    14. from transactions  
    15. tablesample(bucket 1 out of 10000 on transaction_id) s   
    16. order by transaction_id   
    17. limit 10000000) x  
    18. where (row_sequence() % 910000)=0  
    19. order by transaction_id  
    20. limit 11;  


    这里只保存数据的结构,应该就是1---910000,910001---2*910000...这样的一个分区结构

  • 相关阅读:
    java 网络编程入门
    正确、安全地停止SpringBoot应用服务
    spring boot application.properties文件外部配置
    logback
    基本排序算法的总结
    jqury属性操作,特殊效果
    click事件和jquery选项卡
    jquery加载方式,选择器,样式操作
    css之定位
    css中设置background属性
  • 原文地址:https://www.cnblogs.com/java20130722/p/3206974.html
Copyright © 2011-2022 走看看