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. spring学习(四) ———— 整合web项目(SSH)

    清楚了spring的IOC 和 AOP,最后一篇就来整合SSH框架把,记录下来,以后应该会用的到. --WH 一.web项目中如何使用spring? 当tomcat启动时,就应该加载spring的配置 ...

  2. 五分钟彻底学会iptables防火墙--技术流ken

    iptables简介 IPTABLES 是与最新的 3.5 版本 Linux内核集成的 IP 信息包过滤系统.如果 Linux 系统连接到因特网或 LAN.服务器或连接 LAN 和因特网的代理服务器, ...

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

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

  4. mybatis_09关联查询_一对一

    复杂查询时,单表对应的po类已不能满足输出结果集的映射. 所以有些时候就需要关联查询_一对一:通过条件查询结果每个字段都唯一 一对一:模型里面有模型 一对多:模型里面有集合 多对多:集合里面有集合 方 ...

  5. linux下ftp服务器搭建

    1.yum install vsftpd  使用yum安装ftp 2.创建并授权ftp文件目录   mkdir -P /ftp/ftpadmin       chmod -R 777 /ftp/ftp ...

  6. nginx部署与安装

    1.在学习ngnix的时候,免不了需要进行安装,安装其实很简单,一个shell脚本就可以搞定可以参考如下 使用root用户执行nginx-install.sh脚本即可,脚本如下: #!/bin/bas ...

  7. Could not open input file: artisan 【Laravel初体验】

    1,情景描述:在命令行窗口写入php artisan make:model Models\MenuModel用于创建模型时,出现此错误(Could not open input file: artis ...

  8. 实现响应式——CSS变量

    CSS 变量是 CSS 引入的一个新特性,目前绝大多数浏览器已经支持了,它可以帮助我们用更少的代码写出同样多的样式,大大提高了工作效率,本篇文章将教你如何使用 CSS 变量(css variable) ...

  9. Django的下载安装以及实现一个简单示例

    一.Django下载安装 Django下载链接 1. 下载Django: pip3 install django==1.11.9    (大的版本1.11不要错) 2.创建一个django proje ...

  10. HDU 3032 Nim or not Nim?(Multi-Nim)

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...