Hive- basic concepts

 

 

Silicon Valley is still big data technologies Hive

The first 1 Chapter  Hive Starter

1.1 What is the Hive

Hive : the Facebook open source for statistical data to solve the massive structure of the log.

Hive is based on Hadoop is a data warehousing tools , you can map the structure of the data file to a table , and provides class SQL queries.

Essentially: the HQL converted to MapReduce program

 

. 1 ) Hive data storage processing in the HDFS

2 ) Hive achieve the underlying data is analyzed MapReduce

3 ) the implementation of a program run Yarn on

 

1.2 Hive advantages and disadvantages

1.2.1 advantage

1)  operator interface uses class SQL syntax provides the ability to rapidly develop (simple, easy to use) .

2)  avoiding to write MapReduce , developers reduce the cost of learning .

. 3) Hive execution delay is relatively high, so Hive commonly used in the data analysis, less demanding real-time applications .

4) Hive advantage of big data processing, for processing data no small advantage, because Hive execution delay is relatively high .

5) Hive support for user-defined functions, users can implement your own functions according to their needs .

1.2 Hive advantages and disadvantages

1.2.1 advantage

1)  operator interface uses class SQL syntax provides the ability to rapidly develop (simple, easy to use) .

2)  avoiding to write MapReduce , developers reduce the cost of learning .

. 3) Hive execution delay is relatively high, so Hive commonly used in the data analysis, less demanding real-time applications .

4) Hive advantage of big data processing, for processing data no small advantage, because the Hive 's execution delayed relatively high .

5) Hive support for user-defined functions, users can implement your own functions according to their needs .

1.2.2 shortcomings

1. Hive of HQL limited skills

( 1 ) iterative algorithm can not express

( 2 ) data mining are not good

2. Hive of relatively low efficiency

( . 1 ) Hive automatically generated MapReduce job, usually enough intelligence

( 2 ) Hive tuning more difficult, coarser

1.3 Hive architecture principles

Figure 6-1 Hive architecture principles

 

1. User Interface: Client

CLI ( Hive shell ), JDBC / ODBC (the Java Access hive) , the WEBUI (browser access Hive )

2. Metadata: Metastore

Metadata includes: table name, table belongs to a database (the default is the default ), owner of the table, column / partition field, type the table (if an external table), where the table of contents and other data;

The default is stored in the built-in derby database, it is recommended to use MySQL storage Metastore

 

3.Hadoop

Use HDFS storage, use MapReduce calculated.

4.驱动器:Driver

1)解析器(SQL Parser):将SQL字符串转换成抽象语法树AST,这一步一般都用第三方工具库完成,比如antlr;对AST进行语法分析,比如表是否存在、字段是否存在、SQL语义是否有误。

2)编译器(Physical Plan):将AST编译生成逻辑执行计划。

3)优化器(Query Optimizer):对逻辑执行计划进行优化。

4)执行器(Execution):把逻辑执行计划转换成可以运行的物理计划。对于Hive来说,就是MR/Spark

 

 

Hive通过给用户提供的一系列交互接口,接收到用户的指令(SQL),使用自己的Driver,结合元数据(MetaStore),将这些指令翻译成MapReduce,提交到Hadoop中执行,最后,将执行返回的结果输出到用户交互接口。

1.4 Hive和数据库比较

由于 Hive 采用了类似SQL 的查询语言 HQL(Hive Query Language),因此很容易将 Hive 理解为数据库。其实从结构上来看,Hive 和数据库除了拥有类似的查询语言,再无类似之处。本文将从多个方面来阐述 Hive 和数据库的差异。数据库可以用在 Online 的应用中,但是Hive 是为数据仓库而设计的,清楚这一点,有助于从应用角度理解 Hive 的特性。

1.4.1 查询语言

由于SQL被广泛的应用在数据仓库中,因此,专门针对Hive的特性设计了类SQL的查询语言HQL。熟悉SQL开发的开发者可以很方便的使用Hive进行开发。

1.4.2 数据存储位置

Hive 是建立在 Hadoop 之上的,所有 Hive 的数据都是存储在 HDFS 中的。而数据库则可以将数据保存在块设备或者本地文件系统中。

1.4.3 数据更新

由于Hive是针对数据仓库应用设计的,而数据仓库的内容是读多写少的因此,Hive中不建议对数据的改写,所有的数据都是在加载的时候确定好的而数据库中的数据通常是需要经常进行修改的,因此可以使用 INSERT INTO …  VALUES 添加数据,使用 UPDATE … SET修改数据。

1.4.4 索引

Hive在加载数据的过程中不会对数据进行任何处理,甚至不会对数据进行扫描,因此也没有对数据中的某些Key建立索引。Hive要访问数据中满足条件的特定值时,需要暴力扫描整个数据,因此访问延迟较高。由于 MapReduce 的引入, Hive 可以并行访问数据,因此即使没有索引,对于大数据量的访问,Hive 仍然可以体现出优势。数据库中,通常会针对一个或者几个列建立索引,因此对于少量的特定条件的数据的访问,数据库可以有很高的效率,较低的延迟。由于数据的访问延迟较高,决定了 Hive 不适合在线数据查询。

1.4.5 执行

Hive中大多数查询的执行是通过 Hadoop 提供的 MapReduce 来实现的。而数据库通常有自己的执行引擎。

1.4.6 执行延迟

Hive 在查询数据的时候,由于没有索引,需要扫描整个表,因此延迟较高。另外一个导致 Hive 执行延迟高的因素是 MapReduce框架。由于MapReduce 本身具有较高的延迟,因此在利用MapReduce 执行Hive查询时,也会有较高的延迟。相对的,数据库的执行延迟较低。当然,这个低是有条件的,即数据规模较小,当数据规模大到超过数据库的处理能力的时候,Hive的并行计算显然能体现出优势。

1.4.7 可扩展性

由于Hive是建立在Hadoop之上的,因此Hive的可扩展性是和Hadoop的可扩展性是一致的(世界上最大的Hadoop 集群在 Yahoo!2009年的规模在4000 台节点左右)。而数据库由于 ACID 语义的严格限制,扩展行非常有限。目前最先进的并行数据库 Oracle 在理论上的扩展能力也只有100台左右。

1.4.8 数据规模

由于Hive建立在集群上并可以利用MapReduce进行并行计算,因此可以支持很大规模的数据;对应的,数据库可以支持的数据规模较小。

 

Guess you like

Origin www.cnblogs.com/LXL616/p/10947383.html