[Hive_4] Hive 插入数据
0. 说明
Hive 插入数据的方法 && Hive 插入数据的顺序 && 插入复杂数据的方法 && load 命令详解
1. Hive 插入数据的方法
Hive 插入数据不是使用 insert,而是 load
2. Hive 插入数据的顺序
2.1 先定义好表结构
create table employee(name string,
work_place array<string>,
sex_age struct<sex:string, age:int>,
score map<string, int>,
depart_title map<string, string>)
row format delimited
fields terminated by '|'
collection items terminated by ','
map keys terminated by ':'
lines terminated by '\n'
stored as textfile;
2.2 准备数据。数据格式要和表结构对应 employee.txt
Michael|Montreal,Toronto|Male,30|DB:80|Product:Developer
Will|Montreal|Male,35|Perl:85|Product:Lead,Test:Lead
Shelley|New York|Female,27|Python:80|Test:Lead,COE:Architect
Lucy|Vancouver|Female,57|Sales:89,HR:94|Sales:Lead
2.3 空表中使用 load 命令加载数据
load data local inpath '/home/centos/files/employee.txt' into table employee;

2.4 取出所有的成员
# array获取
select name ,work_place[] from employee;
# 结构体获取
select name ,sex_age.sex from employee;
# map成员获取
select name, score['Python'] from employee;
3. 插入复杂类型数据 insert
3.0 设置显示表头
临时修改命令如下,永久修改需要修改配置文件 hive-site.xml
set hive.cli.print.header=true;
3.1 插入复杂类型使用转储
insert xxx select xxx
通过 select 语句构造出 array 类型
# 通过 select 语句构造出 array 类型
select array('tom','tomas','tomson') ; # 转储 array 类型数据
insert into employee(name,work_place) select 'tom',array('beijing','shanghai','guangzhou');
通过 select 语句构造出 map 类型
# 通过 select 语句构造出 map 类型
select map('bigdata',100); # 转储 map 类型数据
insert into employee(name,score) select 'tomas', map('bigdata',100);
通过 select 语句构造出 struct 类型
# 通过 select 语句构造出 struct 类型
select struct('male',10);
select named_struct('sex','male','age',10); # 转储 struct 类型数据
insert into employee(name,sex_age) select 'tomson',named_struct('sex','male','age',10);
4. load命令详解
4.0 前提:先建表
create table duowan(id int, name string, pass string, mail string, nickname string)
row format delimited
fields terminated by '\t'
lines terminated by '\n'
stored as textfile;
4.1 使用 load
# load 本地数据,相当于上传或者复制,源文件不变
load data local inpath '/home/centos/files/employee.txt' into table employee; # load hdfs 数据,相当于移动
load data inpath '/duowan_user.txt' into table duowan; # load 本地数据 + 覆盖原始数据
load data local inpath '/home/centos/files/employee.txt' overwrite into table employee; # load hdfs 数据 + 覆盖原始数据
load data inpath '/duowan_user.txt' overwrite into table duowan;
[Hive_4] Hive 插入数据的更多相关文章
- Hive插入数据的几种常用方法
Hive的几种常见的数据导入方式这里介绍四种:(1).从本地文件系统中导入数据到Hive表:(2).从HDFS上导入数据到Hive表:(3).从别的表中查询出相应的数据并导入到Hive表中:(4).在 ...
- hive插入数据-单条
写入数据到hive的hdfs文件中即可,hive创建表的时候用小写做表名,不然查不到 相关操作如下: 查看目录与表 hive> dfs -ls /user/hive/warehouse/ 准备h ...
- Hive通过查询语句向表中插入数据注意事项
最近在学习使用Hive(版本0.13.1)的过程中,发现了一些坑,它们或许是Hive提倡的比关系数据库更加自由的体现(同时引来一些问题),或许是一些bug.总而言之,这些都需要使用Hive的开发人员额 ...
- Hive通过查询语句向表中插入数据过程中发现的坑
前言 近期在学习使用Hive(版本号0.13.1)的过程中,发现了一些坑,它们也许是Hive提倡的比关系数据库更加自由的体现(同一时候引来一些问题).也许是一些bug.总而言之,这些都须要使用Hive ...
- hive新加入字段插入数据需要注意事项
hive中新加字段需要注意如下 1)如果表中有分区字段,必须先删除分区才能插入数据否则为null; 2)insert override TABLE table1 select counm1,counm ...
- Hive/Impala批量插入数据
问题描述 现有几千条数据,需要插入到对应的Hive/Impala表中.安排给了一个同事做,但是等了好久,反馈还没有插入完成--看到他的做法是:对每条数据进行处理转换为对应的insert语句,但是,实际 ...
- Hive[4] 数据定义 HiveQL
HiveQL 是 Hive 查询语言,它不完全遵守任一种 ANSI SQL 标准的修订版,但它与 MySQL 最接近,但还有显著的差异,Hive 不支持行级插入,更新和删除的操作,也不支持事务,但 H ...
- Hive中数据的加载和导出
原文:http://blog.javachen.com/2014/06/09/hive-data-manipulation-language.html 关于 Hive DML 语法,你可以参考 apa ...
- kettle连接Hive中数据导入导出(6)
1.hive往外写数据 http://wiki.pentaho.com/display/BAD/Extracting+Data+from+Hive+to+Load+an+RDBMS 连接hive
随机推荐
- centos7安装kafka_2.11
1.下载 官网地址:http://kafka.apache.org/downloads.html 下载:wget https://www.apache.org/dyn/closer.cgi?path= ...
- 移植 Qt 至 tiny210 详细过程
实验所需资源: tiny210(cortex-a8) QT 版本:5.6.2 PC 环境:UBUNTU tslib:tslib-1.4 交叉工具链:4.5.1 开发板已装载好 Linux 编译 tsl ...
- 【转载】C#常用数据库Sqlserver中DATEPART() 函数
在Sqlserver数据库中,DATEPART() 函数用于返回日期/时间的单独部分,比如年.月.日.小时.分钟等等.DatePart()函数的语法为: DATEPART(datepart,date) ...
- 各个模式的accesstoken续期详解
一些预备知识 jwt的时间格式 转换为时间可以用js, new Date(1531841745*1000) ==>Tue Jul 17 2018 23:35:45 GMT+0800 (中国标准时 ...
- 转:VB中的API详解
在接下来的这篇文章中,我将向大家介绍.NET中的线程API,怎么样用C#创建线程,启动和停止线程,设置优先级和状态. 在.NET中编写的程序将被自动的分配一个线程.让我们来看看用C#编程语言创建线程并 ...
- 在SoapUI中模拟用户操作
SoapUI作为一款接口测试工具,具有极大的灵活性和拓展性.它可以通过安装插件,拓展其功能.Selenium作为一款Web自动化测试插件可以很好的与SoapUI进行集成.如果要在SoapUI中模拟用户 ...
- 关于Maven项目build时出现No compiler is provided in this environment的处理
版权声明:本文为博主原创文章,未经博主允许不得转载. http://blog.csdn.net/lslk9898/article/details/73836745 近日有同事遇到在编译Maven项目时 ...
- 【读书笔记】iOS-库
一,OS X和iOS自带一些标准的C程序库和操作系统相关的特殊性.在MAC和iOS的世界里,静态库采用.a扩展名(静态对象代码库存档),动态加载库采用.dylib扩展名.如果开发人员来自于Linux世 ...
- SAP MM 按采购订单查询付款信息的报表?
SAP MM 按采购订单查询付款信息的报表? 上午给P3项目采购部门用户做了一个采购相关的报表的培训.培训过程中,客户的采购部门经理提出了一个问题:有没有报表能查询到各个采购订单的付款情况,显示采购订 ...
- writing objects : 值%停住
在git bush 中使用命令:git config --global http.postBuffer 524288000 因为git上传,限定一次push命令的buffer大小.