Hadoop之Hive入门教程:基础概念与操作示例

4星 · 超过85%的资源 需积分: 9 11 下载量 117 浏览量 更新于2024-09-10 收藏 372KB PDF 举报
"hive入门.pdf" 本文档主要介绍了Apache Hive的基础知识,包括Hive的简介、数据类型、内置函数以及数据定义语言(DDL)的使用。Hive是一个基于Hadoop的分布式数据仓库工具,它允许使用SQL-like语言(HQL)进行大数据分析。以下是详细内容: 1. **Hive简介** Hive设计目标是简化对大规模数据集的查询和管理,它将结构化的数据文件映射为一张数据库表,并提供简单的SQL接口来查询数据。Hive构建在Hadoop之上,利用HDFS存储数据,通过MapReduce进行计算。数据在HDFS中以文本文件形式存在,每个字段由指定的分隔符分隔。权限管理基于文件系统,用户对表的访问权限取决于他们对底层文件的权限。 2. **数据类型** - 整型:包括`int`(4字节)、`smallint`(2字节)、`tinyint`(1字节)和`bigint`(8字节)。 - 浮点数:`float`和`double`。 - 字符串:`string`。 - 布尔型:`boolean`。 - 日期时间型:Hive早期版本不直接支持,但可以通过自定义函数处理。 - 二进制串:不直接支持。 - 其他复杂数据类型:`ARRAY`、`MAP`和`STRUCT`,用于表示数组、键值对和结构化数据。 3. **内置函数** Hive提供了丰富的内置函数,涵盖数学运算、字符串处理、日期操作等多个领域,用户可以通过查阅官方文档的函数大全获取详细信息。 4. **DDL(数据定义语言)** - **创建和删除数据库**:`CREATE DATABASE IF NOT EXISTS db_test COMMENT '用于测试';` 和 `DROP DATABASE IF EXISTS db_test;` 分别用于创建和删除数据库,`IF NOT EXISTS` 选项防止在数据库已存在时抛出错误。 - **创建表**:`CREATE EXTERNAL TABLE` 用于创建外部表,如示例中的 `order_joined_extend` 表。外部表的元数据由Hive管理,而数据文件位于HDFS的指定位置。`PARTITIONED BY` 用于创建分区表,例如根据 `create_date` 和 `type` 进行分区。`ROW FORMAT DELIMITED FIELDS TERMINATED BY '\001' LINES TERMINATED BY '\n' STORED AS TEXTFILE` 定义了字段和行的分隔符及存储格式。 5. **外部表的优势** - 数据文件可直接放在HDFS的指定目录,无需通过Hive加载数据。 - 多个表可以共享同一份数据,只需指向相同的location。 - 当数据源发生变化时,只需要更新外部表的location,Hive查询就会反映出这些变化。 6. **使用场景** Hive适用于离线批处理分析,尤其适合ETL(提取、转换、加载)过程和数据仓库应用。由于其SQL-like语法,使得非编程背景的业务人员也能轻松地进行数据分析。 总结,Hive是大数据分析领域的重要工具,它通过SQL接口简化了对Hadoop集群上大量数据的处理。了解Hive的基本概念和操作,对于进行大数据分析和管理至关重要。通过熟练掌握Hive,可以有效地提升数据处理效率并增强数据分析能力。
2019-09-01 上传
Table of Contents About the Tutorial ····································································································································· i Audience ··················································································································································· i Prerequisites ············································································································································· i Disclaimer & Copyright ······························································································································ i Table of Contents ····································································································································· ii . 1. INTRODU CTION ································ ································ ································ ···················· 1 1 Hadoop ···················································································································································· 1 What is Hive? ··········································································································································· 2 Features of Hive ······································································································································· 2 Architecture of Hive ································································································································· 2 Working of Hive ······································································································································· 4 . 2. HIVE INSTALLATION ································ ································ ································ ·············· 6 6 Step 1: Verifying JAVA Installation ··········································································································· 6 Step 2: Verifying Hadoop Installation ······································································································· 8 Step 3: Downloading Hive ······················································································································ 15 Step 4: Installing Hive ····························································································································· 15 Step 5: Configuring Hive ························································································································· 16 Step 6: Downloading and Installing Apache Derby ················································································· 17 Step 7: Configuring Metastore of Hive ···································································································· 19 Step 8: Verifying Hive Installation ·········································································································· 20 . 3. HIVE DATA TYPES ································ ································ ································ ················ 22 Column Types ········································································································································· 22 Literals ··················································································································································· 24 Null Value ··············································································································································· 24 Complex Types ······································································································································· 24