Hive数据的上传(Load、Insert)和下载

一、Load加载数据

  • 从本地加载数据

    LOAD DATA LOCAL INPATH '/root/hivedata/students.txt' INTO TABLE student_local;
    
  • 从HDFS加载数据

    LOAD DATA INPATH '/students.txt' INTO TABLE student_HDFS;
    
  • 从HDFS加载数据到分区表并制定分区

    LOAD DATA INPATH '/students.txt' INTO TABLE student_HDFS_p partition(country ="CHina");
    

二、Insert插入数据

  • 将查询结果插入到表中

    insert into table student_from_insert select num,name from student;
    
  • 多重插入,将数据插入到多个表中

    from student
    insert overwrite table student_insert1
    select num
    insert overwrite table student_insert2
    select name;
    
  • 动态分区插入

    # 开启动态分区功能
    set hive.exec.dynamic.partition = true;
    # 设置动态分区模式为非严格模式
    set hive.exec.dynamic.partition.mode = nonstrict;
    # 执行插入操作
    insert into table student_partition partition(Sdept)
    select Sno,Sname,Sex,Sage,Sdept from student;
    

三、数据的导出

  • 导出查询结果到HDFS指定目录下

    insert overwrite directory '/tmp/hive_export/e1' select * from student;
    
  • 导出时指定分隔符和文件存储方式

    insert overwrite directory '/tmp/hive_export/e2' 
    row format delimited fields terminated by ','
    stored as orc
    select * from student;
    
  • 导出数据到本地

    insert overwrite local directory '/root/hive_export/e1' select * from student;
    
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值