Hive数据的导入和导出

1.Load files into tables  

格式:
   
   
  1. load data [local] inpath filePath [overwrite] into table tablename [partition] (partcol1=val1,partcol2 =val2)
  • filePath原始文件存储的位置 
    • 本地local
    • hdfs 
  • 对表的数据操作
    •  覆盖 overwrite
    •  追加    
  • 分区表加载,特殊性
    • partition()
 加载数据的几种方式:
1) 加载本地文件到hive表中
    
    
  1. load data local inpath '/opt/datas/emp.txt' into table default.emp;
2)加载 hdfs 文件到hive中
    
    
  1. load data '/user/huangxgc/hive/datas/emp.txt' into table default.emp;
3) 加载数据覆盖表中已有的数据

   
   
  1. load data '/user/huangxgc/hive/datas/emp.txt overwrite into table default.emp;
4) 创建表时通过insert 加载
    
    
  1. create table  default.emp like emp 
  2. insert into select*from emp;
5) 创建表的时候通过location指定加载

2.数据的导出 insert

  • 从hive将数据覆盖导出到本地(文件未进行格式化)
    
    
  1. insert overwrite local directory '/opt/datas/hive_exp_emp'
  2. select*from default.emp;
  • 导出的文件时进行格式化
    
    
  1. insert overwrite local directory '/opt/datas/hive_exp_emp'
  2. row format delimited fields terminated by '\t' # 行内个字段采用制表符进行分割
  3. collection items terminated by '\n'             # 每行采用换行进行分割
  4. select*from default.emp;
  • 用hive脚本的-e导出文件,文件已格式化
    
    
  1. bin/hive -e "select *from default.emp;" > /opt/datas/exp_res.txt
两个专用导出导入

  • Export 导出 :将hive中的数据导出到hdfs

语法:
    
    
  1. EXPORT TABLE TABLENAME [PARTITION(part_column="value"[,....])]
  2. TO 'exportt_target_path'
export_target_path:指的是hdfs的路径

  • IMPORT 导入

语法:
    
    
  1. IMPORT [EXTERNAL] TABLE new_or_original_tablename [PARTITION(part_column="value"[....])]
  2. From'source_path'
  3. [LOCATION 'import_target_path']
import_target_path:指的是hdfs的路径




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值