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 插入数据的更多相关文章

  1. Hive插入数据的几种常用方法

    Hive的几种常见的数据导入方式这里介绍四种:(1).从本地文件系统中导入数据到Hive表:(2).从HDFS上导入数据到Hive表:(3).从别的表中查询出相应的数据并导入到Hive表中:(4).在 ...

  2. hive插入数据-单条

    写入数据到hive的hdfs文件中即可,hive创建表的时候用小写做表名,不然查不到 相关操作如下: 查看目录与表 hive> dfs -ls /user/hive/warehouse/ 准备h ...

  3. Hive通过查询语句向表中插入数据注意事项

    最近在学习使用Hive(版本0.13.1)的过程中,发现了一些坑,它们或许是Hive提倡的比关系数据库更加自由的体现(同时引来一些问题),或许是一些bug.总而言之,这些都需要使用Hive的开发人员额 ...

  4. Hive通过查询语句向表中插入数据过程中发现的坑

    前言 近期在学习使用Hive(版本号0.13.1)的过程中,发现了一些坑,它们也许是Hive提倡的比关系数据库更加自由的体现(同一时候引来一些问题).也许是一些bug.总而言之,这些都须要使用Hive ...

  5. hive新加入字段插入数据需要注意事项

    hive中新加字段需要注意如下 1)如果表中有分区字段,必须先删除分区才能插入数据否则为null; 2)insert override TABLE table1 select counm1,counm ...

  6. Hive/Impala批量插入数据

    问题描述 现有几千条数据,需要插入到对应的Hive/Impala表中.安排给了一个同事做,但是等了好久,反馈还没有插入完成--看到他的做法是:对每条数据进行处理转换为对应的insert语句,但是,实际 ...

  7. Hive[4] 数据定义 HiveQL

    HiveQL 是 Hive 查询语言,它不完全遵守任一种 ANSI SQL 标准的修订版,但它与 MySQL 最接近,但还有显著的差异,Hive 不支持行级插入,更新和删除的操作,也不支持事务,但 H ...

  8. Hive中数据的加载和导出

    原文:http://blog.javachen.com/2014/06/09/hive-data-manipulation-language.html 关于 Hive DML 语法,你可以参考 apa ...

  9. kettle连接Hive中数据导入导出(6)

    1.hive往外写数据 http://wiki.pentaho.com/display/BAD/Extracting+Data+from+Hive+to+Load+an+RDBMS 连接hive

随机推荐

  1. Python中的序列操作

    官方手册:https://docs.python.org/3.7/library/stdtypes.html#sequence-types-list-tuple-range 序列简介 序列是指按照位置 ...

  2. python语法风格

    这里只给出其它文章里不适合出现部分语法风格. python有几种类型的复合语句:if.for.while.def.class.try/except.with/as等.这些复合类型的语句在编写时,要遵循 ...

  3. 翻译:window function(已提交到MariaDB官方手册)

    本文为mariadb官方手册:window functions的译文. 原文:https://mariadb.com/kb/en/window-functions-overview/ 我提交到Mari ...

  4. javascript小实例,移动端页面中的拖拽

    上文说到,想将移动端的拖拽说一说,那现在趁有时间,就将这个福利文带来了,哈哈! 在我还不知道怎么做移动端的手势操作的时候,我觉得这TM实在是太难了,这是多么高深的学问啊,手势操作耶,上滑下滑左滑右滑的 ...

  5. js如何获取url参数

    匹配URL参数的正则是: var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", ...

  6. [转]Rabbitmq的使用及Web监控工具使用

    本文转自:https://blog.csdn.net/xingxing513234072/article/details/51014850 一.文档资料        1.官方网站:http://ww ...

  7. Python GUI

    1.flexx Flexx 是一个纯Python工具包,用来创建图形化界面应用程序.其使用 Web 技术进行界面的渲染.你可以用Flexx来创建桌面应用,同时也可以导出一个应用到独立的 HTML 文档 ...

  8. MVC Post 提交表单 允许他提交参数包含html标记的解决方法

    MVC Post 提交表单的时候,如果参数中包含html标记,则需要在控制器上方加上 [ValidateInput(false)]标记后就可以正常提交表单了例如: [HttpPost] [Valida ...

  9. ECharts中color : function的用法(转)

    ECharts图表实战经验1:如何设置图表同序列不同数据点的独立颜色值   最近有不少朋友在追问这样一个问题:我单序列的柱状图,我想让每一个根柱子的颜色都不一样,应该如何做? 针对这个问题,其实我只想 ...

  10. mysql length和char_length

    length和char_length都是为了统计字符串的长度,length是按照字节来统计,char_lenght是按照字符来统计. 位(bit):计算机储存的最小单位. 字节(byte):计算机处理 ...