把HDFS上的数据导入到Hive中
1. 首先下载测试数据,数据也可以创建
http://files.grouplens.org/datasets/movielens/ml-latest-small.zip
2. 数据类型与字段名称
movies.csv(电影元数据)
movieId,title,genres ratings.csv(用户打分数据)
userId,movieId,rating,timestamp
3. 先把数据存放到HDFS上
hdfs dfs -mkdir /hive_operate
hdfs dfs -mkdir /hive_operate/movie_table
hdfs dfs -mkdir /hive_operate/rating_table hdfs dfs -put movies.csv /hive_operate/movie_table
hdfs dfs -put ratings.csv /hive_operate/rating_table
4. 创建movie_table和rating_table
]$ cat create_movie_table.sql
create external table movie_table
(
movieId STRING,
title STRING,
genres STRING
)
row format delimited fields terminated by ','
stored as textfile
location '/hive_operate/movie_table'; ]$ cat create_rating_table.sql
create external table rating_table
(userId STRING,
movieId STRING,
rating STRING,
ts STRING
)
row format delimited fields terminated by ','
stored as textfile
location '/hive_operate/rating_table';
其中字段名为timestamp为hive的保留字段,执行的时候会报错,需用反引号或者修改字段名,我这边修改的字段名
5. 执行
可以通过复制命令到终端执行,也可以通过hive -f movie_table_e来创建表
6. 查看
hive> show tables;
OK
movie_table
rating_table hive> select * from rating_table limit ;
OK
2.5
3.0
3.0
2.0
4.0
2.0
2.0
2.0
3.5
2.0
7. 生成新表(行为表)
create table behavior_table as
select B.userid, A.movieid, B.rating, A.title
from movie_table A
join rating_table B
on A.movieid == B.movieid;
8. 把Hive表数据导入到本地
table->local file
insert overwrite local directory '/root/hive_test/1.txt' select * from behavior_table;
9. 把Hive表数据导入到HDFS上
table->hdfs file
insert overwrite directory '/root/hive_test/1.txt' select * from behavior_table;
10. 把本地数据导入到Hive表中
local file -> table
LOAD DATA LOCAL INPATH '/root/hive_test/a.txt' OVERWRITE INTO TABLE behavior_table;
11. 把HDFS上的数导入到HIve表中
hdfs file -> table
LOAD DATA INPATH '/a.txt' OVERWRITE INTO TABLE behavior_table;
把HDFS上的数据导入到Hive中的更多相关文章
- Talend 将Oracle中数据导入到hive中,根据系统时间设置hive分区字段
首先,概览下任务图: 流程是,先用tHDFSDelete将hdfs上的文件删除掉,然后将oracle中的机构表中的数据导入到HDFS中:建立hive连接->hive建表->tJava获取系 ...
- 使用sqoop将mysql数据导入到hive中
首先准备工具环境:hadoop2.7+mysql5.7+sqoop1.4+hive3.1 准备一张数据库表: 接下来就可以操作了... 一.将MySQL数据导入到hdfs 首先我测试将zhaopin表 ...
- 如何将数据导入到hive中
可以通过多种方式将数据导入hive表 1.通过外部表导入 用户在hive上建external表,建表的同时指定hdfs路径,在数据拷贝到指定hdfs路径的同时,也同时完成数据插入external表. ...
- Sqoop 将hdfs上的文件导入到oracle中,关于date类型的问题
近期的项目中,需要将hadoop运行完成的结果(存在于hdfs上)导入到oracle中,但是在用sqoop导入hdfs中的日期字段'2016-03-01'时,sqoop报错,说date类型必须为'yy ...
- 11.把文本文件的数据导入到Hive表中
先在hive里面创建一个表 create table mydb2.t3(id int,name string,age int) row format delimited fields terminat ...
- 用sqoop将mysql的数据导入到hive表中
1:先将mysql一张表的数据用sqoop导入到hdfs中 准备一张表 需求 将 bbs_product 表中的前100条数据导 导出来 只要id brand_id和 name 这3个字段 数据存 ...
- 使用Talend Open Studio将数据分步从oracle导入到hive中
先使用Tos建立模型,将Oracle中的数据导入到本地: build job后,形成独立可以运行的程序: 将生成的zip文件,上传到hadoop集群上,有hive环境的机器上: [hive@h1 wo ...
- Sqoop-将MySQL数据导入到hive orc表
sqoop创建并导入数据到hive orc表 sqoop import \ --connect jdbc:mysql://localhost:3306/spider \ --username root ...
- 使用 sqoop 将mysql数据导入到hive表(import)
Sqoop将mysql数据导入到hive表中 先在mysql创建表 CREATE TABLE `sqoop_test` ( `id` ) DEFAULT NULL, `name` varchar() ...
随机推荐
- NGINX域名跳转案列
1.不同域名不同路径跳转 nginx实现a.com/teacher域名跳转到b.com/student 若想实现上面题目的跳转,目前鄙人知道两种方式: 1.return 2.proxy_pass 具体 ...
- JAVA中域、方法、类的可见性
多态在域的问题上是特殊的.我理解不了中文版的书直接叫域,看了英文原版,原版写的是fields,直接翻译虽然没错,但是出问题的变量不是域.特地查了what is the meaning of field ...
- Solr学习笔记之6、Solr学习资源
一.官方资源 1.官网:http://lucene.apache.org/solr/ 2.wiki:http://wiki.apache.org/solr/FrontPage 3.solr中文网:ht ...
- CCCC L2-007. 家庭房产 建图 XJB模拟
https://www.patest.cn/contests/gplt/L2-007 题解:一开始是想直接并查集,一个家就是一个集合,对每个集合维护一个人数num1一个房产数num2 一个房产面积ar ...
- sql中exist()的用法
转自:https://www.cnblogs.com/netserver/archive/2008/12/25/1362615.html 比如在Northwind数据库中有一个查询为 SELECT c ...
- 5839Special Tetrahedron---hdu5839(计算几何,求特殊四面体个数)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5839 给你n个三维的点,然后求这n各点可以构成多少个特殊四面体,特殊四面体满足一下两点: 1.至少有四 ...
- php 中date显示时间不对与Linux文件乱码问题
php 中date显示时间不对解决办法如下1.修改/etc/php.ini文件 在里头中找到data.timezone =去掉它前面的分号';' 然后设置data.timezone = “Asia/S ...
- 全局ID的重要性
全局ID的重要性 体现在sharding的时候 gtid MySQL:global transaction id uuid:universally unique identifier guid:glo ...
- PHPExcel 基本用法详解
.header header("Content-Type:application/vnd.ms-excel"); header("Content-Disposition: ...
- [py]python自省工具
参考 在日常生活中,自省(introspection)是一种自我检查行为.自省是指对某人自身思想.情绪.动机和行为的检查.伟大的哲学家苏格拉底将生命中的大部分时间用于自我检查,并鼓励他的雅典朋友们也这 ...