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. [转]C# serialPort 串口接收中this.Invoke的使用

    本文转自:https://blog.csdn.net/hjk216/article/details/72677596 转载地址:http://www.ciast.net/post/20160752.h ...

  2. 从零开始学安全(二十五)●用nmap做端口扫描

    以上是常用的端口扫描 -T 用法 每个级别发包时间  当没有使用T 时默认的使用T3级别发包 半开扫描  先探测主机是否存活 再用-sS  扫描端口   容易造成syn 包攻击 就是利用僵尸主机  进 ...

  3. Bootstrap中的datetimepicker用法

    本文实例为大家分享了bootstrap datetimepicker日期插件的简单使用,供大家参考,具体内容如下 首先在文件头部引入必要的文件: 1 2 <link rel="styl ...

  4. 构建SpringBoot第一个Demo

    使用官方地址生成项目 https://start.spring.io  Generate:可以选择Maven或者Gradle构建项目 语言:我想一般都是Java 接下来选择SpringBoot的版本, ...

  5. Java学习笔记之——封装

    1. 属性和方法放到类中 2. 信息的隐藏 (1) 属性的隐藏 (2) 方法实现的细节隐藏 3. 权限修饰符: 从小到大的顺序:private->默认的(什么都不写)->protected ...

  6. Java 原生网络编程.

    一.概念 Java 语言从其诞生开始,就和网络紧密联系在一起.在 1995 年的 Sun World 大会上,当时占浏览器市场份额绝对领先的网景公司宣布在浏览器中支持Java,从而引起一系列的公司产品 ...

  7. JavaScript黑客是这样窃取比特币的,Vue开发者不用担心!

    如果你是JavaScript或者区块链开发者,如果你有关注区块链以及比特币,那么你应该听说了比特币钱包Copay被黑客攻击的事情.但是,你知道这是怎么回事吗? 总结 比特币钱包copay依赖event ...

  8. ASPxGridView 用法

    一.ASPxGridView属性:概述设置(Settings) 1.1.Settings <Settings GridLines="Vertical" : 网格样式 Vert ...

  9. Android的ToolBar

    ToolBar比ActionBar更加可控,自由.因此,Google 逐渐使用ToolBar来代替ActionBar. 使用ToolBar 1.要引入appCompat_v7支持 2.主题设置为NoA ...

  10. Java用户自定义函数

    用户除了可以使用JavaScript的内置函数之外,还可以自己定义函数.自定义函数有3种方法. 使用关键字 function 构造 语法: function funcName([param1][,pa ...