hive-DML语句

Loading Data into Managed Tables -- 加载数据到表

  1. LOAD DATA LOCAL INPATH '${env:HOME}/california-employees'  
  2. OVERWRITE INTO TABLE employees  
  3. PARTITION (country = 'US', state = 'CA');  

LOAD DATA LOCAL ... copies  the  local data  to  the  final  location  in  the
distributed filesystem, while LOAD DATA ... (i.e., without LOCAL) moves
the data to the final location.


Inserting Data into Tables from Queries -- 加载数据从查询语句到表


  1. INSERT OVERWRITE TABLE employees  
  2. PARTITION (country = 'US', state = 'OR')  
  3. SELECT * FROM staged_employees se  
  4. WHERE se.cnty = 'US' AND se.st = 'OR';  

  1. FROM staged_employees se  
  2. INSERT OVERWRITE TABLE employees  
  3.   PARTITION (country = 'US', state = 'OR')  
  4.   SELECT * WHERE se.cnty = 'US' AND se.st = 'OR'  
  5. INSERT OVERWRITE TABLE employees  
  6.   PARTITION (country = 'US', state = 'CA')  
  7.   SELECT * WHERE se.cnty = 'US' AND se.st = 'CA'  
  8. INSERT OVERWRITE TABLE employees  
  9.   PARTITION (country = 'US', state = 'IL')  
  10.   SELECT * WHERE se.cnty = 'US' AND se.st = 'IL';  

Dynamic Partition Inserts  --动态分区


  1. INSERT OVERWRITE TABLE employees  
  2. PARTITION (country, state)  
  3. SELECT ..., se.cnty, se.st  
  4. FROM staged_employees se;  

  1. INSERT OVERWRITE TABLE employees  
  2. PARTITION (country = 'US', state)  
  3. SELECT ..., se.cnty, se.st  
  4. FROM staged_employees se  
  5. WHERE se.cnty = 'US';  



  1. hive> set hive.exec.dynamic.partition=true;  
  2. hive> set hive.exec.dynamic.partition.mode=nonstrict;  
  3. hive> set hive.exec.max.dynamic.partitions.pernode=1000;  
  4. hive> INSERT OVERWRITE TABLE employees  
  5.     > PARTITION (country, state)  
  6.     > SELECT ..., se.cty, se.st  
  7.     > FROM staged_employees se;  


Creating Tables and Loading Them in One Query --一个查询语句创建表


  1. CREATE TABLE ca_employees  
  2. AS SELECT name, salary, address  
  3. FROM employees  
  4. WHERE se.state = 'CA';  

Exporting Data --导出数据


  1. INSERT OVERWRITE LOCAL DIRECTORY '/tmp/ca_employees'  
  2. SELECT name, salary, address  
  3. FROM employees  
  4. WHERE se.state = 'CA';  

导出多个文件

  1. FROM staged_employees se  
  2. INSERT OVERWRITE DIRECTORY '/tmp/or_employees'  
  3.   SELECT * WHERE se.cty = 'US' and se.st = 'OR'  
  4. INSERT OVERWRITE DIRECTORY '/tmp/ca_employees'  
  5.   SELECT * WHERE se.cty = 'US' and se.st = 'CA'  
  6. INSERT OVERWRITE DIRECTORY '/tmp/il_employees'  
  7.   SELECT * WHERE se.cty = 'US' and se.st = 'IL'
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值