0%

第四章 大数据之hive搭建

说明

hive简单介绍

使用 hive 的命令行接口,感觉很像操作关系数据库,但是 hive 和关系数据库还是有很大的不同,下面我就比较下 hive 与关系数据库的区别,具体如下:

  • Hive 和关系数据库存储文件的系统不同,Hive 使用的是 hadoop 的 HDFS(hadoop 的分布式文件系统),关系数据库则是服务器本地的文件系统;
  • hive 使用的计算模型是 mapreduce,而关系数据库则是自己设计的计算模型;
  • 关系数据库都是为实时查询的业务进行设计的,而 Hive 则是为海量数据做数据挖掘设计的,实时性很差;实时性的区别导致 Hive 的应用场景和关系数据库有很大的不同;

安装hive

  • 下载版本选择为3.1.2
1
2
3
4
5
6
[root@VM-24-13-centos local]# wget --no-check-certificate  https://dlcdn.apache.org/hive/hive-3.1.2/apache-hive-3.1.2-bin.tar.gz

sudo tar -zxvf ./apache-hive-3.1.2-bin.tar.gz -C /usr/local # 解压到/usr/local中
cd /usr/local/
sudo mv apache-hive-3.1.2-bin hive # 将文件夹名改为hive
sudo chown -R hadoop:hadoop hive # 修改文件权限

配置环境

1
2
3
4
5
6
[hadoop@VM-24-13-centos local]$ vi ~/.bashrc


export HIVE_HOME=/usr/local/hive
export PATH=$PATH:$HIVE_HOME/bin
export HADOOP_HOME=/usr/local/hadoop
  • 生效环境变量

    1
    source ~/.bashrc
  • 修改/usr/local/hive/conf下的hive-site.xml

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    cd /usr/local/hive/conf
    mv hive-default.xml.template hive-default.xml

    [hadoop@VM-24-13-centos conf]$ vi hive-site.xml

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
    <configuration>
    <property>
    <name>javax.jdo.option.ConnectionURL</name>
    <value>jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true</value>
    <description>JDBC connect string for a JDBC metastore</description>
    </property>
    <property>
    <name>javax.jdo.option.ConnectionDriverName</name>
    <value>com.mysql.jdbc.Driver</value>
    <description>Driver class name for a JDBC metastore</description>
    </property>
    <property>
    <name>javax.jdo.option.ConnectionUserName</name>
    <value>hive</value>
    <description>username to use against metastore database</description>
    </property>
    <property>
    <name>javax.jdo.option.ConnectionPassword</name>
    <value>hive1234</value>
    <description>记得在创建用户时,密码要和这个对应</description>
    </property>
    </configuration>

安装和配置mysql

安装mysql

  • 我之前已经装好了,省略此步骤

配置mysql

  • 新建hive数据库
1
2
[hadoop@VM-24-13-centos conf]$ mysql -u root -p
create database hive; #这个hive数据库与hive-site.xml中localhost:3306/hive的hive对应,用来保存hive元数据
  • 配置mysql允许hive接入
1
2
3
4
5
6
7
8
9
mysql> set global validate_password.policy='LOW'; # mysql8后,有密码策略要求,改为低
mysql >create user hive@localhost identified by 'hive1234';
# hive 代表你要创建的此数据库的新用户账号
# localhost 代表访问本地权限,不可远程访问,还有其他值
# %代表通配所有host地址权限(可远程访问)
# 指定特殊Ip访问权限 如10.138.106.10
# hive1234代表你要创建的此数据库的新用密码
mysql>grant all privileges on *.* to 'hive'@'%' # 授权数据库给hive用户
mysql> flush privileges; #刷新mysql系统权限关系表

配置hive

启动hive

  • 启动hive之前,请先启动hadoop集群。

    1
    2
    3
    start-all.sh #启动hadoop
    hive #启动hive

错误处理

1
2
hive> show databases;# 输入后报错
FAILED: HiveException java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient
  • Hive现在包含一个用于 Hive Metastore 架构操控的脱机工具,名为 schematool.此工具可用于初始化当前 Hive 版本的 Metastore 架构。此外,其还可处理从较旧版本到新版本的架构升级,用下面的命令:
1
2
3
4
5
[hadoop@VM-24-13-centos conf]$ schematool -dbType mysql -initSchema

# 出现下面的错误,提升驱动载入失败
org.apache.hadoop.hive.metastore.HiveMetaException: Failed to load driver
Underlying cause: java.lang.ClassNotFoundException : com.mysql.jdbc.Driver

image-20211208112332826

  • 下载安装mysql驱动
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
sudo wget https://downloads.mysql.com/archives/get/p/3/file/mysql-connector-java-8.0.26-1.el7.noarch.rpm

# 可以看到其他都是文档,那么连接驱动文件是/usr/share/java/mysql-connector-java.jar
[root@study1 opt]# rpm -qpl mysql-connector-java-8.0.26-1.el7.noarch.rpm
警告:mysql-connector-java-8.0.26-1.el7.noarch.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
/usr/share/doc/mysql-connector-java-8.0.26
/usr/share/doc/mysql-connector-java-8.0.26/CHANGES
/usr/share/doc/mysql-connector-java-8.0.26/INFO_BIN
/usr/share/doc/mysql-connector-java-8.0.26/INFO_SRC
/usr/share/doc/mysql-connector-java-8.0.26/LICENSE
/usr/share/doc/mysql-connector-java-8.0.26/README
/usr/share/java/mysql-connector-java.jar

# 安装,提示缺少依赖java-headless且版本要大于1.8版本
[root@study1 opt]# rpm -ivh mysql-connector-java-8.0.26-1.el7.noarch.rpm
警告:mysql-connector-java-8.0.26-1.el7.noarch.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
错误:依赖检测失败:
java-headless >= 1:1.8.0 被 mysql-connector-java-1:8.0.26-1.el7.noarch 需要

# 安装依赖
[root@study1 opt]# yum -y install java-headless

# 再次安装
[root@study1 opt]# rpm -ivh mysql-connector-java-8.0.26-1.el7.noarch.rpm
警告:mysql-connector-java-8.0.26-1.el7.noarch.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-connector-java-1:8.0.26-1.e################################# [100%]

# 查看驱动文件
[root@study1 opt]# ll /usr/share/java
总用量 2328
-rw-r--r--. 1 root root 2381198 9月 11 05:55 mysql-connector-java.jar
# 把驱动文件拷贝到hive的lib中
[root@study1 opt]# cp /usr/share/java/mysql-connector-java.jar /usr/local/hive/lib
  • 再次schematool初始化就可以了
1
[hadoop@VM-24-13-centos local]$ schematool -dbType mysql -initSchema
  • 进入hive
1
2
3
4
5
6
7
8
9
10
[hadoop@VM-24-13-centos local]$ hive

hive> show databases;
OK
default
Time taken: 0.02 seconds, Fetched: 1 row(s)
hive> show tables;
OK
Time taken: 0.036 seconds
hive>
  • 如果要退出Hive交互式执行环境,可以输入如下命令:
1
2
hive> exit;
[hadoop@VM-24-13-centos local]$

Hive的常用HiveQL操作

Hive基本数据类型

  • Hive支持基本数据类型和复杂类型, 基本数据类型主要有数值类型(INT、FLOAT、DOUBLE ) 、布尔型和字符串, 复杂类型有三种:ARRAY、MAP 和 STRUCT。

基本数据类型

  • TINYINT: 1个字节
  • SMALLINT: 2个字节
  • INT: 4个字节
  • BIGINT: 8个字节
  • BOOLEAN: TRUE/FALSE
  • FLOAT: 4个字节,单精度浮点型
  • DOUBLE: 8个字节,双精度浮点型STRING 字符串

复杂数据类型

  • ARRAY: 有序字段
  • MAP: 无序字段
  • STRUCT: 一组命名的字段

用的HiveQL操作命令

  • Hive常用的HiveQL操作命令主要包括:数据定义、数据操作。接下来详细介绍一下这些命令即用法(想要了解更多请参照《Hive编程指南》一书)

  • 数据定义:主要用于创建修改和删除数据库、表、视图、函数和索引。

创建、修改和删除数据库

1
2
3
4
5
6
create database if not exists hive;       #创建数据库
show databases; #查看Hive中包含数据库
show databases like 'h.*'; #查看Hive中以h开头数据库
use hive; # 使用数据库
show tables; # 查看表列表
drop table usr; # 删除表

创建、修改和删除表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#创建内部表(管理表)
create table if not exists hive.usr(
name string comment 'username', # name表示字段命,string表示字段类型,comment后面内容表示说明
pwd string comment 'password',
address struct<street:string,city:string,state:string,zip:int> comment 'home address',
identify map<int,tinyint> comment 'number,sex') comment 'description of the table'
tblproperties('creator'='me','time'='2016.1.1'); #tblproperties 设置表的属性

#创建外部表
create external table if not exists usr2(
name string,
pwd string,
address struct<street:string,city:string,state:string,zip:int>,
identify map<int,tinyint>)
row format delimited fields terminated by ',' # 字段分隔符来进行分割,如:test1,223456,湖南省
location '/usr/local/hive/warehouse/hive.db/usr';
# LOCATION一般与外部表(EXTERNAL)一起使用。一般情况下hive元数据默认保存在<hive.metastore.warehouse.dir>中。
# 这个字段的适用场景是:数据已经存在HDFS上不能移动位置了,那么就通过这个字段让表可以直接读到这份数据。另外,要注意建表的时候,应该让表变成外部表。

#创建分区表
create table if not exists usr3(
name string,
pwd string,
address struct<street:string,city:string,state:string,zip:int>,
identify map<int,tinyint>)
partitioned by(city string,state string); # 双分区

#复制usr表的表模式
create table if not exists hive.usr1 like hive.usr;
show tables in hive;
show tables 'u.*'; #查看hive中以u开头的表
describe hive.usr; #查看usr表相关信息
alter table hive.usr rename to custom; #重命名表
#为表增加一个分区
alter table usr3 add if not exists partition(city="beijing",state="China") location '/usr/local/hive/warehouse/usr3/China/beijing';

#修改分区路径
alter table usr3 partition(city="beijing",state="China") set location '/usr/local/hive/warehouse/usr3/CH/beijing';
#删除分区
alter table usr3 drop if exists partition(city="beijing",state="China");
#修改列信息,注意这里,如果使用 after时,交换元素类型不一致,就无法交换成功
alter table custom change column username username string after pwd;

alter table custom add columns(hobby string); #增加列
alter table custom replace columns(uname string); #删除替换列
alter table custom set tblproperties('creator'='liming'); #修改表属性
alter table usr3 partition(city="beijing",state="China") set fileformat sequencefile; #修改存储属性
use hive; #切换到hive数据库下
drop table if exists usr1; #删除表
drop database if exists hive cascade; #删除数据库和它中的表
参考

视图和索引的创建、修改和删除

  • 主要语法如下,用户可自行实现。
1
2
create view view_name as....;                #创建视图
alter view view_name set tblproperties(…); #修改视图
  • 因为视图是只读的,所以 对于视图只允许改变元数据中的 tblproperties属性。

    1
    2
    3
    4
    5
    #删除视图
    drop view if exists view_name;
    #创建索引
    create index index_name on table table_name(partition_name/column_name)
    as 'org.apache.hadoop.hive.ql.index.compact.CompactIndexHandler' with deferred rebuild....;
  • 这里’org.apache.hadoop.hive.ql.index.compact.CompactIndexHandler’是一个索引处理器,即一个实现了索引接口的Java类,另外Hive还有其他的索引实现。

1
alter index index_name on table table_name partition(...)  rebulid;   #重建索引
  • 如果使用 deferred rebuild,那么新索引成空白状态,任何时候可以进行第一次索引创建或重建。
1
2
show formatted index on table_name;                       #显示索引
drop index if exists index_name on table table_name; #删除索引
说明

用户自定义函数

  • 没有实践自定义函数,后续有需求在学

  • 在新建用户自定义函数(UDF)方法前,先了解一下Hive自带的那些函数。show functions; 命令会显示Hive中所有的函数名称:

1
2
3
4
5
6
7
8
9
10
11
12
hive> show functions;
OK
!
!=
$sum0
....
cardinality_violation
case
cbrt
ceil
ceiling
...
  • 若想要查看具体函数使用方法可使用describe function 函数名:
1
2
3
hive> describe function abs;
OK
abs(x) - returns the absolute value of x
  • 首先编写自己的UDF前需要继承UDF类并实现evaluate()函数,或是继承GenericUDF类实现initialize()函数、evaluate()函数和getDisplayString()函数,还有其他的实现方法,感兴趣的用户可以自行学习。

  • 另外,如果用户想在Hive中使用该UDF需要将我们编写的Java代码进行编译,然后将编译后的UDF二进制类文件(.class文件)打包成一个JAR文件,然后在Hive会话中将这个JAR文件加入到类路径下,在通过create function语句定义好使用这个Java类的函数。

1
2
3
add jar <jar文件的绝对路径>;                        #创建函数
create temporary function function_name;
drop temporary function if exists function_name; #删除函数

数据操作

  • 主要实现的是将数据装载到表中(或是从表中导出),并进行相应查询操作,对熟悉SQL语言的用户应该不会陌生。

向表中装载数据

这里我们以只有两个属性的简单表为例来介绍。首先创建表stu和course,stu有两个属性id与name,course有两个属性cid与sid。

1
2
3
4
create table if not exists hive.stu(id int,name string) 
row format delimited fields terminated by '\t';
create table if not exists hive.course(cid int,sid int)
row format delimited fields terminated by '\t';
  • 向表中装载数据有两种方法:从文件中导入和通过查询语句插入
从文件中导入
  • 假如这个表中的记录存储于文件stu.txt中,该文件的存储路径为/usr/local/hadoop/examples/stu.txt,内容如下。
1
2
3
4
# id后面的name分割符号要用键盘上的tab隔开,直接复制过去,导入进去会全部都是null
1 xiapi
2 xiaoxue
3 qingqing
  • 下面我们把这个文件中的数据装载到表stu中,操作如下:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    hive> use hive;
    hive> load data local inpath '/usr/local/hadoop/examples/stu.txt' overwrite into table stu;
    Loading data to table hive.stu
    OK
    # 查询到数据
    hive> select * from hive.stu;
    OK
    1 xiapi
    2 xiaoxue
    3 qingqing
    Time taken: 1.324 s
    • 如果stu.txt文件存储在HDFS 上,则不需要 local 关键字。
通过查询语句插入

使用如下命令,创建stu1表,它和stu表属性相同,我们要把从stu表中查询得到的数据插入到stu1中:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
hive> create table stu1 as select id,name from stu;
...
Moving data to directory hdfs://localhost:9000/user/hive/warehouse/hive.db/.hive-staging_hive_2021-12-10_10-42-32_320_1543053100774530944-1/-ext-10002
Moving data to directory hdfs://localhost:9000/user/hive/warehouse/hive.db/stu1
MapReduce Jobs Launched:
Stage-Stage-1: HDFS Read: 31 HDFS Write: 114 SUCCESS
Total MapReduce CPU Time Spent: 0 msec
OK
# 查询到stu1表结构如下
hive> describe stu1;
OK
id int
name string
Time taken: 0.268 seconds, Fetched: 2 row(s)

上面是创建表,并直接向新表插入数据;若表已经存在,向表中插入数据需执行以下命令:

1
2
3
4
5
6
7
# 这里关键字overwrite的作用是替换掉表(或分区)中原有数据,换成into关键字,直接追加到原有内容后。
hive> insert overwrite table stu1 select id,name from stu where(id='1');

# 查询发现只有id为1的数据,其他数据全部清空
hive> select * from hive.stu1;
OK
1 xiapi

从表中导出数据

导出到本地文件
1
2
3
4
5
6
7
8
9
10
11
hive> insert overwrite local directory '/usr/local/hadoop/examples/export_stu' select * from hive.stu;
...
Moving data to local directory /usr/local/hadoop/examples/export_stu
MapReduce Jobs Launched:
Stage-Stage-1: HDFS Read: 30 HDFS Write: 0 SUCCESS

# 查看导出的文件
[hadoop@VM-24-13-centos local]$ cat /usr/local/hadoop/examples/export_stu/000000_0
1xiapi
2xiaoxue
3qingqing
导出到hdfs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
hive> insert overwrite directory '/usr/local/hadoop/examples/export_hdfs_stu' select * from hive.stu;
...

Moving data to directory /usr/local/hadoop/examples/export_hdfs_stu
MapReduce Jobs Launched:
Stage-Stage-1: HDFS Read: 30 HDFS Write: 30 SUCCESS
Total MapReduce CPU Time Spent: 0 msec
OK

# 查看导出成功的数据
hive> dfs -cat /usr/local/hadoop/examples/export_hdfs_stu/*;
1xiapi
2xiaoxue
3qingqing

查询操作

  • 和SQL的查询完全一样,这里不再赘述。主要使用select…from…where…等语句,再结合关键字group by、having、like、rlike等操作。这里我们简单介绍一下SQL中没有的case…when…then…句式、join操作和子查询操作。

  • case…when…then…句式和if条件语句类似,用于处理单个列的查询结果,语句如下:

1
2
3
4
5
6
7
8
9
10
11
hive> select id,name,
> case
> when id=1 then 'first'
> when id=2 then 'second'
> else 'third'
> end from stu;
OK
1 xiapi first
2 xiaoxue second
3 qingqing third
Time taken: 0.385 seconds, Fetched: 3 row(s)
  • 连接(join)是将两个表中在共同数据项上相互匹配的那些行合并起来, HiveQL 的连接分为内连接、左向外连接、右向外连接、全外连接和半连接 5 种。
内连接
  • 内连接使用比较运算符根据每个表共有的列的值匹配两个表中的行。
  • 首先,我们先把以下内容插入到course表中
1
2
3
hive> insert into course values(1,3);
hive> insert into course values(2,1);
hive> insert into course values(3,1);
  • 下面, 查询stu和course表中学号相同的所有行,命令如下:

    1
    2
    3
    4
    5
    6
    7
    8
    hive> select stu.*, course.* from stu join course on(stu.id=course.sid);


    OK
    1 xiapi 2 1
    1 xiapi 3 1
    2 xiaoxue 1 2
    Time taken: 11.049 seconds, Fetched: 3 row(s)
右连接

右连接是左向外连接的反向连接,将返回右表的所有行。如果右表的某行在左表中没有匹配行,则将为左表返回空值。命令

1
2
3
4
5
6
7
8

hive> select stu.*, course.* from stu right outer join course on(stu.id=course.sid);
Total MapReduce CPU Time Spent: 0 msec
OK
2 xiaoxue 1 2
1 xiapi 2 1
1 xiapi 3 1
Time taken: 10.887 seconds, Fetched: 3 row(s)
全连接

全连接返回左表和右表中的所有行。当某行在另一表中没有匹配行时,则另一个表的选择列表包含空值。如果表之间有匹配行,则整个结果集包含基表的数据值。命令如下:

1
2
3
4
5
6
7
8
hive> select stu.*, course.* from stu full outer join course on(stu .id=course .sid);


OK
1 xiapi 3 1
1 xiapi 2 1
2 xiaoxue 1 2
3 qingqing NULL NULL
半连接

半连接是 Hive 所特有的, Hive 不支持 in 操作,但是拥有替代的方案; left semi join, 称为半连接, 需要注意的是连接的表不能在查询的列中,只能出现在 on 子句中。命令如下:

1
2
3
4
5
6
7
8
hive> select stu.* from stu left semi join course on(stu .id=course .sid);


Total MapReduce CPU Time Spent: 0 msec
OK
1 xiapi
2 xiaoxue
Time taken: 9.267 seconds, Fetched: 2 row(s)
子查询

标准 SQL 的子查询支持嵌套的 select 子句,HiveQL 对子查询的支持很有限,只能在from 引导的子句中出现子查询。

Hive简单编程实践

  • 下面我们以词频统计算法为例,来介绍怎么在具体应用中使用Hive。词频统计算法又是最能体现MapReduce思想的算法之一,这里我们可以对比它在MapReduce中的实现,来说明使用Hive后的优势。

  • MapReduce实现词频统计的代码可以通过下载Hadoop源码后,在 $HADOOP_HOME/share/hadoop/mapreduce/hadoop-mapreduce-examples-3.0.3.jar 包中找到(wordcount类),wordcount类由63行Java代码编写而成。下面首先简单介绍一下怎么使用MapReduce中wordcount类来统计单词出现的次数,具体步骤如下:

    • 创建input目录,output目录会自动生成。其中input为输入目录,output目录为输出目录。命令如下:
    1
    2
    3
    cd /usr/local/hadoop
    rm -r input
    mkdir input
    • 然后,在input文件夹中创建两个测试文件file1.txt和file2.txt,命令如下:
    1
    2
    3
    cd  /usr/local/hadoop/input
    [hadoop@VM-24-13-centos input]$ echo "hello world" > file1.txt
    [hadoop@VM-24-13-centos input]$ echo "hello world" > file1.txt
    • 执行如下hadoop命令:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    [hadoop@VM-24-13-centos hadoop]$ cd  ..
    # 先删除hdfs中output目录,不然会报错
    [hadoop@VM-24-13-centos hadoop]$ hadoop dfs -rm -r output
    # 删除input
    [hadoop@VM-24-13-centos hadoop]$ hdfs dfs -rm -r input
    # 在HDFS创建一个目录
    [hadoop@VM-24-13-centos hadoop]$ hdfs dfs -mkdir input

    # 复制input到hdfs中的input目录
    [hadoop@VM-24-13-centos hadoop]$ hdfs dfs -put input/* input

    [hadoop@VM-24-13-centos hadoop]$ hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-3.0.3.jar wordcount input output

    ...
    2021-12-10 15:22:03,703 INFO mapreduce.Job: map 100% reduce 100%
    2021-12-10 15:22:03,704 INFO mapreduce.Job: Job job_local1659054277_0001 completed successfully

    • 我们可以到output文件夹中查看结果,结果如下:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    [hadoop@VM-24-13-centos hadoop]$ hdfs dfs -ls output/*
    -rw-r--r-- 1 hadoop supergroup 0 2021-12-10 17:12 output/_SUCCESS
    -rw-r--r-- 1 hadoop supergroup 25 2021-12-10 17:12 output/part-r-00000

    [hadoop@VM-24-13-centos hadoop]$ hdfs dfs -cat output/part-r-00000
    hadoop 1
    hello 2
    world 1

    • 下面我们通过HiveQL实现词频统计功能,此时只要编写下面7行代码,而且不需要进行编译生成jar来执行。HiveQL实现命令如下:

      1
      2
      3
      4
      5
      6
      7
      8
      [hadoop@VM-24-13-centos hadoop]$ hive

      hive> create table docs(line string);
      hive> load data inpath 'input' overwrite into table docs;
      # create table word_count 表示创建数据库
      # as select word, count(1) as count 表示查询列表,一个word,一个统计值
      # from (select explode(split(line,' '))as word from docs) 这里就是从docs复制数据
      hive> create table word_count as select word, count(1) as count from (select explode(split(line,' '))as word from docs) w group by word order by word;
    • 执行后,用select语句查看,结果如下:

      1
      2
      3
      4
      5
      6
      hive> select * from word_count;
      OK
      hadoop 1
      hello 2
      world 1
      Time taken: 0.148 seconds, Fetched: 3 row(s)
  • 由上可知,采用Hive实现最大的优势是,对于非程序员,不用学习编写Java MapReduce代码了,只需要用户学习使用HiveQL就可以了,而这对于有SQL基础的用户而言是非常容易的。