Apache Hive is a data warehouse software project. It is built on top of Apache Hadoop for providing data query and analysis. 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. While initially developed by Facebook, Apache Hive is used and developed by other companies such as Netflix and the Financial Industry Regulatory Authority (FINRA). Amazon maintains a software fork of Apache Hive included in Amazon Elastic MapReduce on Amazon Web Services.
Features 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 with schema on read and transparently converts queries to MapReduce, Apache Tez 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 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. The first four file formats supported in Hive were plain text, sequence file, optimized row columnar (ORC) format and RCFile. Apache Parquet can be read via plugin in versions later than 0.10 and natively starting at 0.13.
Architecture 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. 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. 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). The DAG divides operators to MapReduce stages and tasks based on the input query and data. 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. 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. An optimizer called YSmart 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. 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.
HiveQL 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. Support for insert, update, and delete with full ACID functionality was made available with release 0.14. Internally, a compiler translates HiveQL statements into a directed acyclic graph of MapReduce, Tez, or Spark jobs, which are submitted to Hadoop for execution.
Example The word count program counts the number of times each word occurs in the input. The word count can be written in HiveQL as:
A brief explanation of each of the statements is as follows:
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.
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.
… excerpt ends here. Continue reading the full article.

