In my previous blog we came to know what is hive and how to install it. In this blog I’ll take you through the architecture and its working.
The diagram represents CLI (Command Line Interface), JDBC/ODBC and Web GUI (Web Graphical User Interface).
When user comes with CLI (Hive Terminal) it is directly connected to Hive Drivers, When User comes with JDBC/ODBC (JDBC Program) at that time by using API (Thrift Server) it is connected to Hive driver and when the user comes with Web GUI (Ambari server) it is directly connected to Hive Driver.
The Hive driver receives the tasks (Queries) from user and send to Hadoop architecture. The Hadoop architecture uses namenode, datanode, job tracker and task tracker for receiving and dividing the work what Hive sends to Hadoop (MapReduce Architecture).
Components & Working of Hive:
Components of Hive and their functionalities:
- UI (User Interface): The user interface is for users to submit queries and other operations to the system.
- Driver:The component which receives the queries. This component implements the notion of session handles and provides execute and fetch APIs modelled on JDBC/ODBC interfaces.
- Compiler:The component that parses the query does semantic analysis on the different query blocks and query expressions and eventually generates an execution plan with the help of the table and partition metadata looked up from the Metastore.
- Metastore :The component that stores all the structure information of the various tables and partitions in the warehouse including column and column type information, the serializers and deserializers necessary to read and write data and the corresponding HDFS files where the data is stored.
- Execution Engine:The component which executes the execution plan created by the compiler. The plan is a DAG of stages. The execution engine manages the dependencies between these different stages of the plan and executes these stages on the appropriate system components.
We are aware of all the components of hive and their functionalities. So now let’s see the working of hive
Step 1: The UI calls the execute interface to the Driver.
Step 2: The Driver creates a session handle for the query and sends the query to the compiler to generate an execution plan.
Step 3 & 4: The compiler gets the necessary metadata from the Metastore.
Step 5: This metadata is used to type check the expressions in the query tree as well as to prune partitions based on query predicates. The plan generated by the compiler is a DAG of stages with each stage being either a map/reduce job, a metadata operation or an operation on HDFS. For map/reduce stages, the plan contains map operator trees (operator trees that are executed on the mappers) and a reduce operator tree (for operations that need reducers).
Step 6: The execution engine submits these stages to appropriate components (steps 6, 6.1, 6.2 and 6.3). In each task (mapper/reducer) the deserializers associated with the table or intermediate outputs is used to read the rows from HDFS files and these are passed through the associated operator tree. Once the output is generated, it is written to a temporary HDFS file though the serializers (this happens in the mapper in case the operation does not need a reduce). The temporary files are used to provide data to subsequent map/reduce stages of the plan. For DML operations the final temporary file is moved to the table’s location.
Step 7 & 8 & 9: For queries, the contents of the temporary file are read by the execution engine directly from HDFS as part of the fetch call from the Driver.