1. 首先下载测试数据,数据也可以创建

  1. http://files.grouplens.org/datasets/movielens/ml-latest-small.zip

2. 数据类型与字段名称

  1. movies.csv(电影元数据)
  2. movieId,title,genres
  3.  
  4. ratings.csv(用户打分数据)
  5. userId,movieId,rating,timestamp

3. 先把数据存放到HDFS上

  1. hdfs dfs -mkdir /hive_operate
  2. hdfs dfs -mkdir /hive_operate/movie_table
  3. hdfs dfs -mkdir /hive_operate/rating_table
  4.  
  5. hdfs dfs -put movies.csv /hive_operate/movie_table
  6. hdfs dfs -put ratings.csv /hive_operate/rating_table

4. 创建movie_table和rating_table

  1. ]$ cat create_movie_table.sql
  2. create external table movie_table
  3. (
  4. movieId STRING,
  5. title STRING,
  6. genres STRING
  7. )
  8. row format delimited fields terminated by ','
  9. stored as textfile
  10. location '/hive_operate/movie_table';
  11.  
  12. ]$ cat create_rating_table.sql
  13. create external table rating_table
  14. (userId STRING,
  15. movieId STRING,
  16. rating STRING,
  17. ts STRING
  18. )
  19. row format delimited fields terminated by ','
  20. stored as textfile
  21. location '/hive_operate/rating_table';
  22. 其中字段名为timestamphive的保留字段,执行的时候会报错,需用反引号或者修改字段名,我这边修改的字段名

5. 执行

  1. 可以通过复制命令到终端执行,也可以通过hive -f movie_table_e来创建表

6. 查看

  1. hive> show tables;
  2. OK
  3. movie_table
  4. rating_table
  5.  
  6. hive> select * from rating_table limit ;
  7. OK
  8. 2.5
  9. 3.0
  10. 3.0
  11. 2.0
  12. 4.0
  13. 2.0
  14. 2.0
  15. 2.0
  16. 3.5
  17. 2.0

7. 生成新表(行为表)

  1. create table behavior_table as
  2. select B.userid, A.movieid, B.rating, A.title
  3. from movie_table A
  4. join rating_table B
  5. on A.movieid == B.movieid;

8. 把Hive表数据导入到本地

  1. table->local file
  2. insert overwrite local directory '/root/hive_test/1.txt' select * from behavior_table;

9. 把Hive表数据导入到HDFS上

  1. table->hdfs file
  2. insert overwrite directory '/root/hive_test/1.txt' select * from behavior_table;

10. 把本地数据导入到Hive表中

  1. local file -> table
  2. LOAD DATA LOCAL INPATH '/root/hive_test/a.txt' OVERWRITE INTO TABLE behavior_table;

11. 把HDFS上的数导入到HIve表中

  1. hdfs file -> table
  2. LOAD DATA INPATH '/a.txt' OVERWRITE INTO TABLE behavior_table;

把HDFS上的数据导入到Hive中的更多相关文章

  1. Talend 将Oracle中数据导入到hive中,根据系统时间设置hive分区字段

    首先,概览下任务图: 流程是,先用tHDFSDelete将hdfs上的文件删除掉,然后将oracle中的机构表中的数据导入到HDFS中:建立hive连接->hive建表->tJava获取系 ...

  2. 使用sqoop将mysql数据导入到hive中

    首先准备工具环境:hadoop2.7+mysql5.7+sqoop1.4+hive3.1 准备一张数据库表: 接下来就可以操作了... 一.将MySQL数据导入到hdfs 首先我测试将zhaopin表 ...

  3. 如何将数据导入到hive中

    可以通过多种方式将数据导入hive表 1.通过外部表导入 用户在hive上建external表,建表的同时指定hdfs路径,在数据拷贝到指定hdfs路径的同时,也同时完成数据插入external表. ...

  4. Sqoop 将hdfs上的文件导入到oracle中,关于date类型的问题

    近期的项目中,需要将hadoop运行完成的结果(存在于hdfs上)导入到oracle中,但是在用sqoop导入hdfs中的日期字段'2016-03-01'时,sqoop报错,说date类型必须为'yy ...

  5. 11.把文本文件的数据导入到Hive表中

    先在hive里面创建一个表 create table mydb2.t3(id int,name string,age int) row format delimited fields terminat ...

  6. 用sqoop将mysql的数据导入到hive表中

    1:先将mysql一张表的数据用sqoop导入到hdfs中 准备一张表 需求 将 bbs_product 表中的前100条数据导 导出来  只要id  brand_id和 name 这3个字段 数据存 ...

  7. 使用Talend Open Studio将数据分步从oracle导入到hive中

    先使用Tos建立模型,将Oracle中的数据导入到本地: build job后,形成独立可以运行的程序: 将生成的zip文件,上传到hadoop集群上,有hive环境的机器上: [hive@h1 wo ...

  8. Sqoop-将MySQL数据导入到hive orc表

    sqoop创建并导入数据到hive orc表 sqoop import \ --connect jdbc:mysql://localhost:3306/spider \ --username root ...

  9. 使用 sqoop 将mysql数据导入到hive表(import)

    Sqoop将mysql数据导入到hive表中 先在mysql创建表 CREATE TABLE `sqoop_test` ( `id` ) DEFAULT NULL, `name` varchar() ...

随机推荐

  1. ios三张图片组合一张

    - (UIImage *)addImage:(UIImage *)image1 toImage:(UIImage *)image2 { UIGraphicsBeginImageContext(imag ...

  2. jenkins定时任务未生效解决

    近期在配置jenkins定时任务时,发现未生效,并没有按时触发任务 解决思路: 1.先查看下我们的定时任务有没有选择正确,如下说明: Poll SCM:定时检查源码变更,如果有更新就checkout最 ...

  3. shell脚本中对简单实现对log的处理

    用shell在写小程序时,log没用像python样用logging模块可以直接使用,下面我们就简单写下用shell函数来实现log分级 #/bin/bash sys_log="/var/l ...

  4. Unity3D笔记 英保通十 射线碰撞器检测

    射线碰撞检测可以用来检测方向和距离: 通过Physics.RayCast光线投射来实现:常用于射击利用发射的射线来判断.还有对战中刀剑交战中.. 一.要涉及到RayCast和RayCastHit 1. ...

  5. PhoneGap安装配置

    PhoneGap是一能够让你用普通NewsShow的web技术编写出能够轻松调用API接口和进入应用商店的HTML5应用开发平台.是唯一的一个支持7个平台的开源移动框架.它的优势是无以伦比的:开发成本 ...

  6. visual studio 2013设置背景图片

    今天听了公司的一个经验分享会,发现VS竟然可以设置背景图片!还是个萌妹子!!被萌了一脸鼻血!!! 设置方法很简单:安装扩展ClaudiaIDE 1.在这里下载扩展,https://visualstud ...

  7. Java Mail 发送邮件(SSL加密方式,TSL加密方式)

    一.一般配置 发送邮件需要用到  mail包 maven 依赖如下: <!-- https://mvnrepository.com/artifact/javax.mail/mail --> ...

  8. matplotlib的下载和安装方法

    官网:http://matplotlib.org/ Installation节 Visit the Matplotlib installation instructions. Installing节 ...

  9. CodeForces - 812B Sagheer, the Hausmeister 搜索 dp

    题意:给你n行长度为m的01串(n<15,m<100) .每次只能走一步,要将所有的1变为零,问最少的步数,注意从左下角开始,每次要将一层清完才能走到上一层,每次只有在第一列或者最后一列才 ...

  10. 启动了SSH服务后,一定要关闭Telnet服务

    https://baike.baidu.com/item/ssh/10407 https://baike.baidu.com/item/Telnet/810597