1、数据导入

1)向表中装载数据(load)

语法
hive> load data [local] inpath '/opt/module/datas/student.txt' [overwrite] into table student [partition (partcol1=val1,…)];

(1)load data:表示加载数据

(2)local:表示从本地加载数据到hive表;否则从HDFS加载数据到hive表

(3)inpath:表示加载数据的路径

(4)overwrite:表示覆盖表中已有数据,否则表示追加

(5)into table:表示加载到哪张表

(6)student:表示具体的表

(7)partition:表示上传到指定分区

实例操作

创建一张表

create table student(id string,name string)
row format delimited fields terminated by '\t';

(1)加载本地文件到hive

load data local inpath '/opt/student.txt' into table student;

(2)加载hdfs文件到hive

load data inpath '/user/hive/warehouse/stu.txt' into table student;

(3)加载数据覆盖表中已有的数据

load data inpath '/user/hive/warehouse/stu.txt' overwrite into table student;

2)通过查询语句向表中插入数据(insert)

创建一张分区表

create table student(id int, name string) partitioned by (month string) row format delimited fields terminated by '\t';

(1)基本插入

insert into table student partition(month='2019') values(1,"wang"),(2,"zhang");
insert  overwrite table stu partition(month='2019') select id,name from  student where month='2019';

insert into :以追加数据的方式插入到表或分区,原有数据不会删除

insert overwrite:会覆盖表或分区中已经存在的数据

insert 不支持插入部分字段

(2)多表(多分区)插入

from student
insert overwrite table student partition(month='201706')
select id,name where month='201706'
insert overwrite table student partition(month='201707')
select id,name where month='201707';

3)查询语句中创建表并加载数据(as select)

create table if not exists stu
as
select id,name from student;

4)创建表时通过location指定加载数据路径

create external table if not exists student(
id int ,name string
)
row format delimited fields terminated by '\t'
location '/student';

5)Import数据到指定hive表中

先用export导出后,再将数据导入

import table stu partition(month='201901')
from
'/user/hive/warehouse/export/student';

2、数据导出

1)insert导出

(1)将查询的结果导出到本地(各列数据紧挨着,没有分隔符)

insert overwrite local directory '/opt/export/student' select * from student;

(2)将查询的结果格式化导出到本地

insert overwrite local directory '/opt/export/student' row format delimited fileds terminated by '\t' select * from student;

(3)将查询结果导出到hdfs上(没有local)

insert overwrite local directory '/user/hive/warehouse/export/student' row format delimited fileds terminated by '\t' select * from student;

2)hadoop命令导出到本地

dfs -get /user/hive/warehouse/student/month=201709/000000_0 /opt/module/datas/export/student.txt;

3)hive shell命令导出

hive -f/-e 执行语句或者脚本 > file

hive -e 'select * from student' > /opt/datas/student.txt;

4)export导出到hdfs上

export table student to  '/user/hive/warehouse/export/student';

export 和import主要用于两个hadoop平台集群之间hive表迁移

hive DML操作的更多相关文章

  1. hive DML 操作

    数据导入 向表中装载数据(Load) 1.语法 load data [local] inpath '数据的 path' [overwrite] into table student [partitio ...

  2. Hive DDL、DML操作

    • 一.DDL操作(数据定义语言)包括:Create.Alter.Show.Drop等. • create database- 创建新数据库 • alter database - 修改数据库 • dr ...

  3. 入门大数据---Hive常用DML操作

    Hive 常用DML操作 一.加载文件数据到表 1.1 语法 LOAD DATA [LOCAL] INPATH 'filepath' [OVERWRITE] INTO TABLE tablename ...

  4. 23-hadoop-hive的DDL和DML操作

    跟mysql类似, hive也有 DDL, 和 DML操作 数据类型: https://cwiki.apache.org/confluence/display/Hive/LanguageManual+ ...

  5. Hive数据库操作

    Hive数据结构 除了基本数据类型(与java类似),hive支持三种集合类型 Hive集合类型数据 array.map.structs hive (default)> create table ...

  6. Vertica并发DML操作性能瓶颈的产生与优化(转)

    文章来源:中国联通网研院网优网管部IT技术研究团队 作者:陆昕 1. 引言 众所周知,MPP数据库以其分布式的超大存储能力以及列式的高速汇总能力,已经成为大数据分析比不可少的工具.Vertica就是这 ...

  7. salesforce 零基础开发入门学习(三)sObject简单介绍以及简单DML操作(SOQL)

    salesforce中对于数据库操作和JAVA等语言对于数据库操作是有一定区别的.salesforce中的数据库使用的是Force.com 平台的数据库,数据表一行数据可以理解成一个sObject变量 ...

  8. Sql Server之旅——第十站 看看DML操作对索引的影响

    我们都知道建索引是需要谨慎的,当只有利大于弊的时候才适合建,我们也知道建索引是需要维护成本的,这个维护也就在于DML操作了, 下面我们具体看看到底DML对索引都有哪些内幕.... 一:delete操作 ...

  9. spark使用Hive表操作

    spark Hive表操作 之前很长一段时间是通过hiveServer操作Hive表的,一旦hiveServer宕掉就无法进行操作. 比如说一个修改表分区的操作 一.使用HiveServer的方式 v ...

随机推荐

  1. test dword ptr [eax],eax ; probe page.局部数组变量定义所分配的最大空间为1M

    问题的出现 使用VS2017编写程序时,程序编译可以通过,但运行时就会弹出错误 经过查证发现: 这跟局部数组变量定义所分配的最大空间设置大小有关. 局部变量的申请空间是存放于栈中,windows里默认 ...

  2. 配置本地yum仓库

        前言 我们知道yum工具是基于rpm的,其一个重要的特性就是可以自动解决依赖问题,但是yum的本质依旧是把后缀名.rpm的包下载到本地,然后按次序安装之.但是每次执行yum install x ...

  3. AGC009题解

    为了1天4题的flag不倒所以开新坑... B. 考虑把这棵树直接建出来,f[i]表示i最少的比赛次数,然后按照定义转移就行了. //Love and Freedom. #include<cst ...

  4. 【bzoj4552】【Tjoi2016&Heoi2016】【NOIP2016模拟7.12】排序

    题目 在2016年,佳媛姐姐喜欢上了数字序列.因而他经常研究关于序列的一些奇奇怪怪的问题,现在他在研究一个难题,需要你来帮助他.这个难题是这样子的:给出一个1到n的全排列,现在对这个全排列序列进行m次 ...

  5. DI,依赖注入,给对象赋值 ,get,set

    DI,依赖注入,给对象赋值 ,get,set给对象赋值 2种方式:1.get.set默认无参构造方法给对象赋值 2.xml中有参构造器方法给对象赋值

  6. Manacher模板( 线性求最长回文子串 )

    模板 #include<stdio.h> #include<string.h> #include<algorithm> #include<map> us ...

  7. 在XenCenter6.2中构建CentOS7虚拟机的启动错误

    在XenCenter6.2中创建CentOS7虚拟机时,发现系统并没有提供CentOS7 64bit的模板,只有CentOS6 64bit模板.如果采用CentOS6作为其模板来创建CentOS7虚拟 ...

  8. spring学习笔记之---JDBC Template

    JDBC  Template(简化持久化操作) (一)创建项目 (1)Maven配置 <dependencies> <dependency> <groupId>ju ...

  9. RedisTemplate访问Redis数据结构(一)——String

    当对String数据结构进行操作时,推荐直接使用spring-data-redis提供的StringRedisTemplate,其配置如下 <bean id="stringRedisT ...

  10. A - Biorhythms (第三周)

    A - Biorhythms 链接:https://vjudge.net/contest/154063#problem Description 人生来就有三个生理周期,分别为体力.感情和智力周期,它们 ...