Apache Hive
This article needs more citations. (May 2023) |
| Apache Hive | |
|---|---|
| Original author | Facebook, Inc. |
| Developer | The Apache Software Foundation[note 1] |
| Release | October 1, 2010[1] |
| Stable release | 4.1.0
/ July 31, 2025[2] |
| Written in | Java |
| Operating system | Cross-platform |
| Available in | SQL |
| Type | Data warehouse |
| License | Apache License 2.0 |
| Website | hive |
| Repository | github |
Apache Hive is a data warehouse software project. It is built on top of Apache Hadoop for providing data query and analysis.[3][4] Hive gives an SQL-like interface to query data stored in various databases and file systems that integrate with Hadoop. Traditional SQL queries must be implemented in the MapReduce Java API to execute SQL applications and queries over distributed data.
Hive provides the necessary SQL abstraction to integrate SQL-like queries (HiveQL) into the underlying Java without the need to implement queries in the low-level Java API. Hive facilitates the integration of SQL-based querying languages with Hadoop, which is commonly used in data warehousing applications.[5] While initially developed by Facebook, Apache Hive is used and developed by other companies such as Netflix and the Financial Industry Regulatory Authority (FINRA).[6][7] Amazon maintains a software fork of Apache Hive included in Amazon Elastic MapReduce on Amazon Web Services.[8]
Features
[edit]Apache Hive supports the analysis of large datasets stored in Hadoop's HDFS and compatible file systems such as Amazon S3 filesystem and Alluxio. It provides a SQL-like query language called HiveQL[9] with schema on read and transparently converts queries to MapReduce, Apache Tez[10] and Spark jobs. All three execution engines can run in Hadoop's resource negotiator, YARN (Yet Another Resource Negotiator). To accelerate queries, it provided indexes, but this feature was removed in version 3.0[11] Other features of Hive include:
- Different storage types such as plain text, RCFile, HBase, ORC, and others.
- Metadata storage in a relational database management system, significantly reduces the time to perform semantic checks during query execution.
- Operating on compressed data stored in the Hadoop ecosystem using algorithms including DEFLATE, BWT, Snappy, etc.
- Built-in user-defined functions (UDFs) to manipulate dates, strings, and other data-mining tools. Hive supports extending the UDF set to handle use cases not supported by built-in functions.
- SQL-like queries (HiveQL), which are implicitly converted into MapReduce or Tez, or Spark jobs.
By default, Hive stores metadata in an embedded Apache Derby database, and other client/server databases like MySQL can optionally be used.[12]
The first four file formats supported in Hive were plain text,[13] sequence file, optimized row columnar (ORC) format[14][15] and RCFile.[16][17] Apache Parquet can be read via plugin in versions later than 0.10 and natively starting at 0.13.[18][19]
Architecture
[edit]Major components of the Hive architecture include the metastore, driver, compiler, optimizer, executor, and user interfaces.
The metastore stores metadata for each of the tables, such as their schema and location. It also includes partition metadata which helps the driver to track the progress of various data sets distributed over the cluster.[20] The data is stored in a traditional RDBMS format. This metadata enables the driver to keep track of the data. A backup server regularly replicates the data to provide recovery in case of data loss.
The driver acts like a controller which receives the HiveQL statements. It starts the execution of the statement by creating sessions and monitors the life cycle and progress of the execution. It stores the necessary metadata generated during the execution of a HiveQL statement. The driver also acts as a collection point of data or query results obtained after the Reduce operation.[16]
The compiler performs compilation of the HiveQL query, converting the query to an execution plan. This plan contains the tasks and steps needed to be performed by the Hadoop MapReduce to get the output as translated by the query. The compiler converts the query to an abstract syntax tree (AST). After checking for compatibility and compile time errors, it converts the AST to a directed acyclic graph (DAG).[21] The DAG divides operators to MapReduce stages and tasks based on the input query and data.[20]
The optimizer performs various transformations on the execution plan to produce an optimized DAG. Transformations can be aggregated together, such as converting a pipeline of joins to a single join, for better performance.[22] It can also split tasks, such as applying a transformation on data before a reduce operation, to provide better performance and scalability. The logic of transformation used for optimization can be modified or pipelined using another optimizer.[16] An optimizer called YSmart[23] is a part of Apache Hive. This correlated optimizer merges correlated MapReduce jobs into a single MapReduce job, significantly reducing the execution time.
The executor executes the tasks after compilation and optimization. It interacts with the job tracker of Hadoop to schedule tasks to be run. It takes care of pipelining the tasks by making sure that a task with a dependency gets executed only if all other prerequisites have been completed.[22]
A command-line interface (CLI) provides a user interface for an external user to interact with Hive by submitting queries and instructions and monitoring the process status. The Thrift Server allows external clients to interact with Hive over a network, similar to the JDBC or ODBC protocols.[24]
HiveQL
[edit]While based on SQL, HiveQL does not strictly follow the full SQL-92 standard. HiveQL offers extensions not in SQL, including multi-table inserts, and creates tables as select. HiveQL lacked support for transactions and materialized views, and offered only limited subquery support.[25][26] Support for insert, update, and delete with full ACID functionality was made available with release 0.14.[27]
Internally, a compiler translates HiveQL statements into a directed acyclic graph of MapReduce, Tez, or Spark jobs, which are submitted to Hadoop for execution.[28]
Example
[edit]The word count program counts the number of times each word occurs in the input. The word count can be written in HiveQL as:[5]
DROP TABLE IF EXISTS docs;
CREATE TABLE docs (line STRING);
LOAD DATA INPATH 'input_file' OVERWRITE INTO TABLE docs;
CREATE TABLE word_counts AS
SELECT word, count(1) AS count FROM
(SELECT explode(split(line, '\s')) AS word FROM docs) temp
GROUP BY word
ORDER BY word;
A brief explanation of each of the statements is as follows:
DROP TABLE IF EXISTS docs;
CREATE TABLE docs (line STRING);
Checks if table docs exists and drops it if it does. Creates a new table called docs with a single column of type STRING called line.
LOAD DATA INPATH 'input_file' OVERWRITE INTO TABLE docs;
Loads the specified file or directory (In this case “input_file”) into the table. OVERWRITE specifies that the target table to which the data is being loaded into is to be re-written; Otherwise, the data would be appended.
CREATE TABLE word_counts AS
SELECT word, count(1) AS count FROM
(SELECT explode(split(line, '\s')) AS word FROM docs) temp
GROUP BY word
ORDER BY word;
The query CREATE TABLE word_counts AS SELECT word, count(1) AS count creates a table called word_counts with two columns: word and count. This query draws its input from the inner query (SELECT explode(split(line, '\s')) AS word FROM docs) temp, which splits the input words into different rows of a temporary table aliased as temp. The GROUP BY WORD clause groups the results based on their keys, so that the count column holds the number of occurrences for each word of the word column. The ORDER BY WORDS clause sorts the words alphabetically.
Comparison with traditional databases
[edit]The storage and querying operations of Hive resemble those of traditional relational databases. Although Hive utilizes an SQL-like dialect, differences exist in its structure and operation because it is built on top of the Hadoop ecosystem and operates within the design characteristics of Hadoop and MapReduce.
A schema is applied to a table in traditional databases. In such traditional databases, the table typically enforces the schema when the data is loaded into the table. This enables the database to make sure that the data entered follows the representation of the table as specified by the table definition. This design is called schema on write. In comparison, Hive does not verify the data against the table schema on write. Instead, it subsequently does run time checks when the data is read. This model is called schema on read.[25] The two approaches have their own advantages and drawbacks.
Checking data against a table schema during load time adds operational overhead, meaning traditional databases require more time to load data. Verification checks are performed during loading to detect corrupt data prior to query execution. Because data validation occurs during or immediately after the load stage, subsequent query performance is optimized. In contrast, Hive loads data without initial schema verification, resulting in faster data loading but slower query execution times. Hive can be utilized when the schema is unavailable during data ingestion and is instead defined dynamically at run time.[25]
Transactions are key operations in traditional databases. As any typical RDBMS, Hive supports all four properties of transactions (ACID): Atomicity, Consistency, Isolation, and Durability. Transactions in Hive were introduced in Hive 0.13 but were only limited to the partition level.[29] The recent version of Hive 0.14 had these functions fully added to support complete ACID properties. Hive 0.14 and later provides different row level transactions such as INSERT, DELETE and UPDATE.[30] Enabling INSERT, UPDATE, and DELETE transactions require setting appropriate values for configuration properties such as hive.support.concurrency, hive.enforce.bucketing, and hive.exec.dynamic.partition.mode.[31]
Security
[edit]Hive v0.7.0 added integration with Hadoop security. Hadoop began using Kerberos authorization support to provide security. Kerberos allows for mutual authentication between client and server, where the client's request for a ticket is passed along with the request. In earlier versions of Hadoop, users could modify usernames via the hadoop.job.ugi property, and MapReduce operations ran under a shared default user identity (such as Hadoop or mapred). Following Hive v0.7.0's integration with Hadoop security, TaskTracker jobs are executed by the user who initiated them, and the username can no longer be spoofed by setting the hadoop.job.ugi property. Permissions for newly created files in Hive are dictated by the HDFS. The Hadoop distributed file system authorization model uses three entities: user, group and others with three permissions: read, write and execute. The default permissions for newly created files can be set by changing the unmask value for the Hive configuration variable hive.files.umask.value.[5]. Permissions for newly created files in Hive are dictated by the HDFS. The Hadoop distributed file system authorization model uses three entities: user, group and others with three permissions: read, write and execute. The default permissions for newly created files can be set by changing the unmask value for the Hive configuration variable hive.files.umask.value.[5]
See also
[edit]Notes
[edit]References
[edit]- ↑ "Release release-1.0.0 · apache/Hive". GitHub.
- ↑ "Apache Hive - Downloads". Retrieved 2025-03-14.
- ↑ Venner, Jason (2009). Pro Hadoop. Apress. ISBN 978-1-4302-1942-2.
- ↑ Yin Huai, Ashutosh Chauhan, Alan Gates, Gunther Hagleitner, Eric N.Hanson, Owen O'Malley, Jitendra Pandey, Yuan Yuan, Rubao Lee, and Xiaodong Zhang (2014). "Major Technical Advancements in Apache Hive". SIGMOD' 14. pp. 1235–1246. doi:10.1145/2588555.2595630.
{{cite conference}}: CS1 maint: multiple names: authors list (link) - 1 2 3 4 Programming Hive [Book].
- ↑ Use Case Study of Hive/Hadoop
- ↑ OSCON Data 2011, Adrian Cockcroft, "Data Flow at Netflix" on YouTube
- ↑ Amazon Elastic MapReduce Developer Guide
- ↑ HiveQL Language Manual
- ↑ Apache Tez
- ↑ Hive Language Manual
- ↑ Lam, Chuck (2010). Hadoop in Action. Manning Publications. ISBN 978-1-935182-19-1.
- ↑ "Optimising Hadoop and Big Data with Text and HiveOptimising Hadoop and Big Data with Text and Hive". Archived from the original on 2014-11-15. Retrieved 2014-11-16.
- ↑ "ORC Language Manual". Hive project wiki. Retrieved April 24, 2017.
- ↑ Yin Huai, Siyuan Ma, Rubao Lee, Owen O'Malley, and Xiaodong Zhang (2013). "Understanding Insights into the Basic Structure and Essential Issues of Table Placement Methods in Clusters ". VLDB' 39. pp. 1750–1761. CiteSeerX 10.1.1.406.4342. doi:10.14778/2556549.2556559.
{{cite conference}}: CS1 maint: multiple names: authors list (link) - 1 2 3 "Facebook's Petabyte Scale Data Warehouse using Hive and Hadoop" (PDF). Archived from the original (PDF) on 2011-07-28. Retrieved 2011-09-09.
- ↑ Yongqiang He, Rubao Lee, Yin Huai, Zheng Shao, Namit Jain, Xiaodong Zhang, and Zhiwei Xu (2011). "RCFile: A Fast and Space-efficient Data Placement Structure in MapReduce-based Warehouse Systems". IEEE 27th International Conference on Data Engineering.
{{cite conference}}: CS1 maint: multiple names: authors list (link) - ↑ "Parquet". 18 Dec 2014. Archived from the original on 2 February 2015. Retrieved 2 February 2015.
- ↑ Massie, Matt (21 August 2013). "A Powerful Big Data Trio: Spark, Parquet and Avro". zenfractal.com. Archived from the original on 2 February 2015. Retrieved 2 February 2015.
- 1 2 "Design - Apache Hive - Apache Software Foundation". cwiki.apache.org. Retrieved 2016-09-12.
- ↑ "Abstract Syntax Tree". c2.com. Retrieved 2016-09-12.
- 1 2 Dokeroglu, Tansel; Ozal, Serkan; Bayir, Murat Ali; Cinar, Muhammet Serkan; Cosar, Ahmet (2014-07-29). "Improving the performance of Hadoop Hive by sharing scan and computation tasks". Journal of Cloud Computing. 3 (1) 12: 1–11. doi:10.1186/s13677-014-0012-6.
- ↑ Rubao Lee, Tian Luo, Yin Huai, Fusheng Wang, Yongqiang He, and Xiaodong Zhang (2011). "YSmart: Yet Another SQL-to-MapReduce Translator". 31st International Conference on Distributed Computing Systems. pp. 25–36.
{{cite conference}}: CS1 maint: multiple names: authors list (link) - ↑ "HiveServer - Apache Hive - Apache Software Foundation". cwiki.apache.org. Retrieved 2016-09-12.
- 1 2 3 White, Tom (2010). Hadoop: The Definitive Guide. O'Reilly Media. ISBN 978-1-4493-8973-4.
- ↑ Hive Language Manual
- ↑ ACID and Transactions in Hive
- ↑ "Hive A Warehousing Solution Over a MapReduce Framework" (PDF). Archived from the original (PDF) on 2013-10-08. Retrieved 2011-09-03.
- ↑ "Introduction to Hive transactions". datametica.com. Archived from the original on 2016-09-03. Retrieved 2016-09-12.
- ↑ "Hive Transactions - Apache Hive - Apache Software Foundation". cwiki.apache.org. Retrieved 2016-09-12.
- ↑ "Configuration Properties - Apache Hive - Apache Software Foundation". cwiki.apache.org. Retrieved 2016-09-12.