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
- Architecture
- From the database to the file
- Three ways to run
- Why the Hive Metastore
- In the TDP editions
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.
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.
In the Glossary: Metastore Server
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
Architecture
Clients talk to the Metastore Server, the server talks to the metadata database, and the files stay in the warehouse.
What the figure shows:
- The clients, such as Hive, Spark, Trino, and other tools, connect to the Metastore Server through the Thrift interface to request and write metadata.
- 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.
- The metadata database is a relational database accessed through JDBC, which the server queries on behalf of the clients.
- 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.
- Database. Namespace that groups tables. A table created without a specified database goes in the default database.
- 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.
- 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.
- 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.
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
| Edition | Version | Documentation |
|---|---|---|
| TDP Datacenter | 4.0.0 | TDP Datacenter components |
| TDP Kubernetes · Hive Metastore | 4.0.0 · chart tdp-hive-metastore 3.0.3 | Configuration in TDP Kubernetes |
In TDP Datacenter
In TDP Datacenter, the Hive Metastore is a component of the Hive service, installed and managed by Ambari.
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.
Clients reach the Metastore through the Thrift address in hive.metastore.uris, in the hive-site configuration of the service.
A relational database, whose type is chosen in hive_database_type (hive-env) when customizing the service. In the documented installation, a PostgreSQL instance.
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).
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.
Thrift service published by an internal Service of type ClusterIP. The number of instances is set in metastore.replicas.
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.
metastore.type selects the mode: file, the default, or s3, which connects the Metastore to S3-compatible storage, such as Ozone.
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.
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
TDP Kubernetes
Hive Metastore Configuration
PostgreSQL, connection pool, warehouse mode and instances in the chart.
TDP Kubernetes
Hive Metastore Integrations
The service address and the configuration in the engines that query it.
Sources
Apache Hive - Metastore Administration