前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Hive项目实战系列(2) | 分析前准备(创建表与插入数据)

Hive项目实战系列(2) | 分析前准备(创建表与插入数据)

作者头像
不温卜火
发布2020-10-28 16:09:16
5640
发布2020-10-28 16:09:16
举报
文章被收录于专栏:不温卜火

  此次博主为大家带来的是Hive项目实战系列的第二部分。

一 启动hive

  • .1 启动hiveserver2服务
代码语言:javascript
复制
[bigdata@hadoop002 hive]$ bin/hiveserver2
  • 2 启动beeline
代码语言:javascript
复制
[bigdata@hadoop002 hive]$ bin/beeline
Beeline version 1.2.1 by Apache Hive
beeline>
  • 3 连接hiveserver2
代码语言:javascript
复制
beeline> !connect jdbc:hive2://hadoop002:10000(回车)
Connecting to jdbc:hive2://hadoop002:10000
Enter username for jdbc:hive2://hadoop002:10000: bigdata(回车)
Enter password for jdbc:hive2://hadoop002:10000: (直接回车)
Connected to: Apache Hive (version 1.2.1)
Driver: Hive JDBC (version 1.2.1)
Transaction isolation: TRANSACTION_REPEATABLE_READ

0: jdbc:hive2://hadoop002:10000> create database guli;
0: jdbc:hive2://hadoop002:10000> use guli;
0: jdbc:hive2://hadoop002:10000> show tables;
+-----------+--+
| tab_name  |
+-----------+--+
+-----------+--+
No rows selected (0.036 seconds)

二. 创建表

2.1 拿到原始数据(日志数据| ori表 )

  • 1. 创建user_text
代码语言:javascript
复制
create external table user_text(
uploader string,
videos int, 
friends int)
row format delimited fields terminated by '\t'
collection items terminated by '&'
location '/guli/user';

// 查看前五行
0: jdbc:hive2://hadoop002:10000> select * from user_text limit 5;
1
1
  • 2. 创建video_text
代码语言:javascript
复制
// video表
create external table video_text(
    videoId string, 
    uploader string, 
    age int, 
    category array<string>, 
    length int, 
    views int, 
    rate float, 
    ratings int, 
    comments int,
    relatedId array<string>
)
row format delimited fields terminated by '\t'
collection items terminated by '&'
location '/guli/video_etc';

// 查询 
select * from video_text limit 5;
2
2

类型我们大致可以看到就行。

2.2 把数据导入到hive中进行处理(创建两张orc表)

  • 1. 创建video_orc:
代码语言:javascript
复制
create table video_orc(
    videoId string, 
    uploader string, 
    age int, 
    category array<string>, 
    length int, 
    views int, 
    rate float, 
    ratings int, 
    comments int,
    relatedId array<string>
)
row format delimited fields terminated by '\t'
collection items terminated by '&'
stored as orc;

如果创建的是表为如下的这种

3
3

就需要输入如下的命令修改,并出现下图标记处的类型就行了:

代码语言:javascript
复制
0: jdbc:hive2://hadoop002:10000> alter table video_orc set tblproperties("EXTERNAL"="FALSE")
0: jdbc:hive2://hadoop002:10000> desc formatted video_orc;
4
4
  • 2. 创建user_orc
代码语言:javascript
复制
create table user_orc(
uploader string,
videos int, 
friends int)
row format delimited fields terminated by '\t'
collection items terminated by '&'
stored as orc;

2.3 向ORC表插入数据

  • 1. 向user_orc插入数据
代码语言:javascript
复制
0: jdbc:hive2://hadoop002:10000> insert into user_orc select * from user_text;
5
5

结果在:

6
6
  • 2. 向video_orc插入数据
代码语言:javascript
复制
0: jdbc:hive2://hadoop002:10000> insert into video_orc select * from video_text;
7
7
  • 3. 测试是否成功
代码语言:javascript
复制
0: jdbc:hive2://hadoop002:10000> select * from user_orc limit 5;
0: jdbc:hive2://hadoop002:10000> select * from video_orc limit 5;
8
8

  好了,到这里,我们就把分析前的数据准备好了。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020/05/10 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一 启动hive
  • 二. 创建表
    • 2.1 拿到原始数据(日志数据| ori表 )
      • 2.2 把数据导入到hive中进行处理(创建两张orc表)
        • 2.3 向ORC表插入数据
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档