Skip to main content

Define the table once,
use it in any engine.

The Hive Metastore stores the definition of each table, with its columns, format, and file location, and serves it to any engine that needs to find it, not only Hive. Follow a table created in one engine and read in another.

The Hive Metastore is the table metadata catalog: engines ask it what each table is and where its files are, and read the data directly from storage.

Metadata, not data

The definition on one side, the files on the other

Columns, types, formats and location are kept in a metadata database. The files are kept in the warehouse, in HDFS or in S3-compatible storage.

Defined once

Reused on every query

The format and location are given when the table is created and reused every time it is referenced. Whoever queries it does not need to describe the files again.

Several engines

A shared catalog

Hive and other engines, such as Spark and Trino, query the same service through the Thrift interface and use these definitions to interpret and run queries.

On this page

See a table being found​

A table created in Spark and queried in Trino. Press Play or step through. Underlined names lead to the Glossary.

Metadata databaseWhere the definitions are kept
Relational databaseAccessed through JDBC
Hive MetastoreWho answers
Metastore ServerThrift interface
EnginesWho asks
SparkCreates and writes the table
TrinoQueries the table
WarehouseWhere the files are kept
Table directoryOne subdirectory per partition
FilesRead and written by the SerDe
Step 1 of 7

1 The table is created

In Spark, a CREATE TABLE statement defines the table sales.orders: columns and types, file format, SerDe, partitioning by the ds column and location. Spark sends this definition to the Metastore through the Thrift interface.

  1. The table is created. In Spark, a CREATE TABLE statement defines the table sales.orders: columns and types, file format, SerDe, partitioning by the ds column and location. Spark sends this definition to the Metastore through the Thrift interface.
  2. The Metastore stores the definition. The Metastore persists the definition in the metadata database, a relational database accessed through JDBC, by means of DataNucleus, an object-relational mapping layer. The database holds the description of the table, not its rows.
  3. The data goes to the warehouse. Spark writes the files to the table directory, one subdirectory per partition, converting the rows with the serializer of the SerDe registered in the definition.
  4. Another engine asks: where is the table?. In Trino, a query references sales.orders and filters by a value of ds. Before reading any file, Trino asks the Metastore for the definition of the table.
  5. The Metastore looks it up and answers. The Metastore fetches the definition from the metadata database and returns to Trino the columns and types, the format, the SerDe, the partitions and the location of each one. Because each partition has its own directory, a query that filters by ds only needs the directory for that value.
  6. Trino reads the files where they are. With the location and the format in hand, Trino reads the files directly from the warehouse. From Hive, it uses only the data and the metadata, without the Hive execution environment.
  7. Defined once, used by all. The table was described a single time, at creation, and Trino found it without anyone repeating the format or the path of the files. This is the data abstraction that the Metastore offers to all the engines that query it.
Figure 1 - The path of a table. The definitions go through the Metastore and are kept in the metadata database. The files go back and forth directly between the engines and the warehouse.

Architecture​

Clients talk to the Metastore Server, the server talks to the metadata database, and the files stay in the warehouse.

Hive Metastore architecture: clients, Metastore Server, metadata database and warehouseClients such as Hive, Spark, Trino and other tools request and write metadata to the Metastore Server through the Thrift interface. On the server, the object store implemented with DataNucleus records databases, tables, partitions, columns and types, SerDe and location, and persists these definitions in a relational database accessed through JDBC. The table files are kept in the warehouse, on HDFS or S3-compatible object storage, and are read and written directly by the clients.ClientsHiveSparkTrinoOther toolsMetastore ServerThriftInterfaceObject storeDataNucleus (ORM)Registered definitionsDatabaseTablePartitionColumns and typesSerDeLocationMetadata databaseRelational databaseaccessed via JDBCWarehouseHDFSTable and partition directoriesObject storageS3-compatibleMetadata requests and responses (Thrift)Reading and writing definitions (JDBC)Reading and writing files
Figure 2 - Hive Metastore architecture: clients, Metastore Server, metadata database and warehouse. Underlined terms lead to the Glossary.

What the figure shows:

  1. The clients, such as Hive, Spark, Trino, and other tools, connect to the Metastore Server through the Thrift interface to request and write metadata.
  2. The Metastore Server, in remote mode, is a Thrift service. Inside it, the definitions (databases, tables, partitions, columns and types, SerDe, and location) are kept in an object store implemented with DataNucleus, which persists them in the metadata database through JDBC.
  3. The metadata database is a relational database accessed through JDBC, which the server queries on behalf of the clients.
  4. The warehouse stores the table files, in HDFS or in S3-compatible object storage, and the clients read and write them directly.

The relational database was chosen so that the metadata itself can be queried.

The Metastore keeps no state, and therefore supports several instances, for high availability.

From the database to the file​

What the Metastore records, from the outermost level down to the file in storage.

Level 1 of 4

Database

Namespace that groups tables. A table created without a specified database goes in the default database.

  1. Database. Namespace that groups tables. A table created without a specified database goes in the default database.
  2. Table. Columns and types, owner, input and output formats of the files, bucketing information and the location of the data, in a warehouse directory. Everything is given when the table is created.
    • SerDe. Class that serializes and deserializes the rows: it is what the table files are written and read with.
    • External table. Created over files that already exist, by their location. Dropping it removes only the definition. The directory remains in storage.
  3. Partition. Divides the table by the values of a key column, such as a date: each value has its own directory, and a query that filters by this column reads only the relevant directories. Each partition can have its own columns, SerDe and location.
    • Location. Path of the directory in the warehouse, in HDFS or in S3-compatible object storage.
  4. Bucket. Subdivides the data of a partition by the hash of a column. Each bucket is a file in the partition directory, which makes queries over a sample of the data efficient.
Figure 3 - What the Metastore records: each level contains the next. SerDe, external table and location accompany the table and the partition.

Three ways to run​

The same Metastore can run inside each client or as a service shared by all of them.

Embedded

A Derby database in the process itself

The metadata database is an embedded Derby. Only one process connects to it at a time, so this mode is mainly suited to tests.

Local

A library inside the client

The Metastore works as a library inside each client, and each client opens its own connection to the metadata database.

Remote

One service for all clients

Clients connect to a remote Metastore through the Thrift interface, and the service queries the metadata database. This is the mode used in both TDP editions.

Why the Hive Metastore​

Abstraction

The format is stated once

The format, extraction and loading information is kept in the table definition, instead of accompanying every query.

Discovery

The data can be found

The metadata makes it possible to discover and explore the relevant data in the warehouse, and other tools can be built on top of it.

Integration

Beyond Hive

The Metastore is also distributed separately and can run without the rest of Hive, so that other systems can integrate with it easily.

Open interface

Thrift in many languages

Third-party tools use the Thrift interface to bring Hive metadata into other business metadata repositories.

Queryable metadata

Definitions in a relational database

PostgreSQL, MySQL, MariaDB, Oracle and SQL Server are among the databases tested and recommended for storing the definitions.

Availability

Several instances

With no state of its own, the service supports several instances. Clients receive the list of addresses and, if a connection fails, try another one.

In the TDP editions​

Available in the TDP editions
EditionVersionDocumentation
TDP Datacenter4.0.0TDP Datacenter components
TDP Kubernetes · Hive Metastore4.0.0 · chart tdp-hive-metastore 3.0.3Configuration in TDP Kubernetes

In TDP Datacenter​

In TDP Datacenter, the Hive Metastore is a component of the Hive service, installed and managed by Ambari.

Service components

HIVE_CLIENT (client, one or more), HIVE_METASTORE (master, one or more), HIVE_SERVER (master, one or more), HIVE_SERVER_INTERACTIVE (master, optional) and MYSQL_SERVER (master, optional, one instance). The HIVE_SERVER requires ZOOKEEPER_SERVER (ZooKeeper), TEZ_CLIENT (Tez), YARN_CLIENT (YARN), MAPREDUCE2_CLIENT (MapReduce) and ZOOKEEPER_CLIENT (ZooKeeper). The HIVE_SERVER_INTERACTIVE requires ZOOKEEPER_SERVER (ZooKeeper), YARN_CLIENT (YARN), HDFS_CLIENT (HDFS), MAPREDUCE2_CLIENT (MapReduce) and TEZ_CLIENT (Tez). Component category.

Client address

Clients reach the Metastore through the Thrift address in hive.metastore.uris, in the hive-site configuration of the service.

Metadata database

A relational database, whose type is chosen in hive_database_type (hive-env) when customizing the service. In the documented installation, a PostgreSQL instance.

Integrated engines

Spark access to the catalog is configurable in spark3-hive-site-override. In Trino, the Hive connector can be enabled in Ambari, in connectors-properties (use.hive).

Dependencies

Ambari requires in the cluster ZooKeeper, HDFS, YARN and Tez.

Required by

These services require this one in the cluster: Spark.

In TDP Kubernetes​

In TDP Kubernetes, the Hive Metastore is installed by the tdp-hive-metastore chart, as a service of its own.

Metastore Server

Thrift service published by an internal Service of type ClusterIP. The number of instances is set in metastore.replicas.

Metadata database

Embedded PostgreSQL, enabled by default in postgres.enabled. An external PostgreSQL, such as tdp-postgresql, is the recommended option, and the TDP-Settings.externalDatabase hooks validate the connection and provision the Hive database. The Secret with the external PostgreSQL administrator password is, by default, tdp-postgresql-auth, which the tdp-postgresql chart creates. The Hive Metastore needs the external PostgreSQL to accept a high number of connections, above the tdp-postgresql default. See Hive Metastore configuration.

Warehouse

metastore.type selects the mode: file, the default, or s3, which connects the Metastore to S3-compatible storage, such as Ozone.

Credentials

The database and S3 credentials reach the process through environment variables read from Secrets, without appearing in the ConfigMap, in the Deployment specification, on the command line or in the logs.

Who queries it

The Trino hive and iceberg catalogs, pointed at the Metastore in hive.metastore.uri, and the maintenance jobs of tdp-iceberg, which use the Metastore as the catalog by default; the Spark Iceberg catalog, which can be enabled in tdp-spark.iceberg.enabled; and the JupyterLab servers, whose NetworkPolicy allows egress to the Metastore.

Next steps​

Sources​

Apache Hive - Design

Apache Hive - Metastore Administration

Apache Hive - Metastore 3.0 Administration

Trino - Hive connector

Apache Spark - Hive Tables