Table types in Apache Hive

Contents

Overview

  • Apache Hive es una herramienta imprescindible para cualquier persona interesada en la ciencia y la ingeniería de datos.
  • Learn about the different types of Apache Hive tables

Introduction

I have spent more than half a decade working with the Big Data technology stack and consulting with clients in various domains. One thing I have noticed is how often Hive is used as a storage solution across all business domains.

You just can't ignore Apache Hive when you are learning Apache Hadoop.

apache hive

Hive es parte del gran ecosistema de Hadoop que le posibilita proporcionar un esquema para grandes datos que residen en HDFS. Most of you will know RDBMS and its tables. We use them so often that it has now become part of our lives. And here is the question: tables in Hive are no different.

Ever wonder what the different types of tables could be in Hive? That is what we will discuss in this post!!

Table of Contents

  1. What is Apache Hive?
  2. Table types in Apache Hive # 1: managed tables
  3. Table types in Apache Hive # 2: External tables
  4. Managed vs external table: what is the difference?
  5. Identify the Apache Hive table type

What is Apache Hive?

Apache Hive is a data storage system for Apache Hadoop. Provides SQL equivalent access to data in HDFS so that Hadoop can be used as a warehouse structure. Hive enables you to provide structure over largely unstructured data. After establishing the structure, you can use Hive to query the data without knowledge of Java or Map Reduce.

Hive Query Language (HQL) cuenta con una semántica y funciones similares a las de SQL estándar en la database relacional para que los analistas de bases de datos experimentados puedan ingresar fácilmente a los datos.

apache beehive boards

What are the features offered by Hive?

Apache Hive provides the following features:

  1. Apache Hive provides a simpler query model with less coding than Map Reduce
  2. HQL and SQL have an equivalent syntax
  3. Provides many features that make analytics easy to use.
  4. Response time is usually much faster than other types of queries on the same huge data sets
  5. Apache Hive supports running on different computing frameworks
  6. Supports ad hoc data queries on HDFS
  7. Apache Hive supports user-defined functions, scripts and an E format / S customized to extend its functionality.
  8. It is scalable and extensible to various types of data and larger data sets.
  9. Mature JDBC and ODBC drivers enable many applications to pull data from Hive for smooth reporting
  10. Hive enables users to read data in arbitrary formats, using SerDes and input formats / Exit
  11. Hive has a well-established architecture for managing metadata, authentication and query optimization.
  12. There is a large community of professionals and developers who work and use Hive.

Table types in Apache Hive

These are the types of tables in Apache Hive:

Managed tables

In a managed table, Hive manages both the data and the table schema. The data will be located in a folder with the name of the table within the Hive data store, which is simply a file location in HDFS.

Location is user configurable when Hive is installed. By managed or controlled we mean that if you delete (remove) a managed table, Hive will remove both the schema (the table description) as the data files associated with the table. The default location is / Username / hive / stock).

Syntax for creating a managed table

CREATE TABLE IF NOT EXISTS stocks (exchange STRING,
symbol STRING,
price_open FLOAT,
price_high FLOAT,
price_low FLOAT,
price_adj_close FLOAT)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' ;

how to managed tables, you can also copy the schematic (but not the data) from an existing table:

CREATE EXTERNAL TABLE IF NOT EXISTS mydb.employees3
LIKE mydb.employees
LOCATION '/path/to/data';

External Tables
An external table is one in which Hive only controls the table schema. In most cases, user will set folder location within HDFS and copy data files there. This location is included as part of the table definition declaration. When an external table is dropped, Hive will only delete the schema associated with the table. Data files are not affected.

Syntax for creating an external table

CREATE EXTERNAL TABLE IF NOT EXISTS stocks (exchange STRING,
symbol STRING,
price_open FLOAT,
price_high FLOAT,
price_low FLOAT,
price_adj_close FLOAT)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ','
LOCATION '/data/stocks';

Managed table vs. external table: what is the difference?

Managed table External Table
Hive assumes that has data from managed tables. For external tables, Hive assumes yes no manage data.
If a table or managed partition is deleted, the data and metadata associated with that table or partition is deleted. Leaving the table does not delete the data, even though the table metadata will be removed.
To Managed tables, Hive stores data in your warehouse directory To External Tables, Hive stores the data in the LOCATION specified during the creation of the mesa(generally not in the warehouse directory)
Managed table provides ACID support / transnational action. The external table does not provide support for ACID actions / transactional.
Declarations: ARCHIVE, UNARCHIVE, TRUNCATE, MERGE, CONCATENATE compatible Not supported.
Query result caching is supported (saves the results of a executed Hive query for reuse) Not supported

Identify the Apache Hive table type

You can tell if a table is managed or external using the output of DESCRIBE EXTENDED table name.

Near the end of the detailed information output of the table, you will see the following for administered tables:

... tableType: MANAGED_TABLE)

To external boards, you will see the following:

... tableType: EXTERNAL_TABLE)

Note: If you omit the EXTERNAL keyword and the original table is external, the new table will also be external. If you omit EXTERNAL and the original table is managed, also the new table will be managed. Despite this, if it includes the keyword EXTERNAL and the original table is managed, the new table will be external. Even in this scenario, the LOCATION clause will remain optional.

Final notes

In this post, we learned about Apache Hive and its table types. Hopefully, you may have gotten a good overview of table types in Hive. The differences indicated are not exhaustive. Feel free to add more in the comment section below.

The following are some additional data engineering resources that I recommend you explore:

I hope you liked the post. If you have any questions related to this post, let me know in the comment section below.

Recommended reading-

https://cwiki.apache.org/confluence/display/Hive/Home

Subscribe to our Newsletter

We will not send you SPAM mail. We hate it as much as you.

Datapeaker