hive DML操作
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操作的更多相关文章
- hive DML 操作
数据导入 向表中装载数据(Load) 1.语法 load data [local] inpath '数据的 path' [overwrite] into table student [partitio ...
- Hive DDL、DML操作
• 一.DDL操作(数据定义语言)包括:Create.Alter.Show.Drop等. • create database- 创建新数据库 • alter database - 修改数据库 • dr ...
- 入门大数据---Hive常用DML操作
Hive 常用DML操作 一.加载文件数据到表 1.1 语法 LOAD DATA [LOCAL] INPATH 'filepath' [OVERWRITE] INTO TABLE tablename ...
- 23-hadoop-hive的DDL和DML操作
跟mysql类似, hive也有 DDL, 和 DML操作 数据类型: https://cwiki.apache.org/confluence/display/Hive/LanguageManual+ ...
- Hive数据库操作
Hive数据结构 除了基本数据类型(与java类似),hive支持三种集合类型 Hive集合类型数据 array.map.structs hive (default)> create table ...
- Vertica并发DML操作性能瓶颈的产生与优化(转)
文章来源:中国联通网研院网优网管部IT技术研究团队 作者:陆昕 1. 引言 众所周知,MPP数据库以其分布式的超大存储能力以及列式的高速汇总能力,已经成为大数据分析比不可少的工具.Vertica就是这 ...
- salesforce 零基础开发入门学习(三)sObject简单介绍以及简单DML操作(SOQL)
salesforce中对于数据库操作和JAVA等语言对于数据库操作是有一定区别的.salesforce中的数据库使用的是Force.com 平台的数据库,数据表一行数据可以理解成一个sObject变量 ...
- Sql Server之旅——第十站 看看DML操作对索引的影响
我们都知道建索引是需要谨慎的,当只有利大于弊的时候才适合建,我们也知道建索引是需要维护成本的,这个维护也就在于DML操作了, 下面我们具体看看到底DML对索引都有哪些内幕.... 一:delete操作 ...
- spark使用Hive表操作
spark Hive表操作 之前很长一段时间是通过hiveServer操作Hive表的,一旦hiveServer宕掉就无法进行操作. 比如说一个修改表分区的操作 一.使用HiveServer的方式 v ...
随机推荐
- Centos7.5源码安装nginx-1.16.0
安装nginx的依赖包(pcre-devel openssl-devel) yum install -y gcc gcc-c++ make pcre pcre-devel zlib zlib-deve ...
- Ubuntu Text editor文本编辑器相关设置
刚开始不熟悉Ubuntu,设置个文本编辑界面都难找到: 打开后在顶上的导航栏,下拉框内有preferences: 里面可以设置视图.字体颜色等
- pyqt5-橡皮筋控件QRubberBand
提供一个矩形或线来指示选择或边界 一般结合鼠标事件一同协作 继承于 QWidget import sys from PyQt5.QtWidgets import QApplication, QWidg ...
- Arduino-舵机
舵机一般都外接三根线,一般棕色为接地线(GND),红色为电源正极线(VCC),橙色为信号线(PWM). 用Arduino控制舵机的方法有两种: 一种是通过Arduino的普通数字传感器接口产生占空比不 ...
- Python---进阶---函数式编程---lambda
一. 利用map()函数,把用户输入的不规范的英文,变成首字母大写,其他小写的规范的名字:比如说["ADMAm", "LISA", "JACK&quo ...
- MySQL数据库4Python操作mysql、索引、慢查询日志
目录 一.Python 操作 mysql 1.1python 操作 mysql 1.2查询数据 1.3增加(添加.更新)数据 1.4修改数据 1.5删除数据 1.6SQL注入问题 1.6.1问题的引入 ...
- A1011
找最大的,然后按规定计算后输出. 没啥可说的,除非犯了愚蠢的错误(比如把j写成i这种),按题目要求写就是了. #include<cstdio> int main(){ ]={'W','T' ...
- 面试题常考&必考之--js中的对象的浅拷贝和深拷贝(克隆,复制)(下)
这里主要是讲深拷贝: 深拷贝:个人理解就是拷贝所有的层级 1.像对象里再放数组和对象这些叫引用值.开始我们先判断大对象中是否有引用值(数组和小对象), 然后在判断引用值是数组还是对象 2.开始啦: 1 ...
- 超好用json转excel工具
给大家安利一个超实用的json数据转excel工具:http://www.yzcopen.com/doc/jsonexcel
- HDU 6620 Just an Old Puzzle
Time limit 2000 ms Memory limit 262144 kB OS Windows 解题过程 感觉搜索不可行,状态太多了,120步,判断状态是否重复时,即使用std::map也太 ...