Manage relational metadata using Apache Gravitino
This page introduces how to manage relational metadata by Apache Gravitino, relational metadata refers to relational catalog, schema, table and partitions. Through Gravitino, you can create, edit, and delete relational metadata via unified REST APIs or Java client.
In this document, Gravitino uses Apache Hive catalog as an example to show how to manage relational metadata by Gravitino. Other relational catalogs are similar to Hive catalog, but they may have some differences, especially in catalog property, table property, and column type. For more details, please refer to the related doc.
Assuming:
- Gravitino has just started, and the host and port is http://localhost:8090.
- Metalake has been created.
Catalog operations
Create a catalog
The code below is an example of creating a Hive catalog. For other relational catalogs, the code is similar, but the catalog type, provider, and properties may be different. For more details, please refer to the related doc.
For relational catalog, you must specify the catalog type
as RELATIONAL
when creating a catalog.
You can create a catalog by sending a POST
request to the /api/metalakes/{metalake_name}/catalogs
endpoint or just use the Gravitino Java client. The following is an example of creating a catalog:
- Shell
- Java
curl -X POST -H "Accept: application/vnd.gravitino.v1+json" \
-H "Content-Type: application/json" -d '{
"name": "catalog",
"type": "RELATIONAL",
"comment": "comment",
"provider": "hive",
"properties": {
"metastore.uris": "thrift://localhost:9083"
}
}' http://localhost:8090/api/metalakes/metalake/catalogs
// Assuming you have just created a metalake named `metalake`
GravitinoClient gravitinoClient = GravitinoClient
.builder("http://127.0.0.1:8090")
.withMetalake("metalake")
.build();
Map<String, String> hiveProperties = ImmutableMap.<String, String>builder()
// You should replace the following with your own hive metastore uris that Gravitino can access
.put("metastore.uris", "thrift://localhost:9083")
.build();
Catalog catalog = gravitinoClient.createCatalog("catalog",
Type.RELATIONAL,
"hive", // provider, We support hive, jdbc-mysql, jdbc-postgresql, lakehouse-iceberg, lakehouse-paimon etc.
"This is a hive catalog",
hiveProperties); // Please change the properties according to the value of the provider.
// ...
Currently, Gravitino supports the following catalog providers:
Catalog provider | Catalog property |
---|---|
hive | Hive catalog property |
lakehouse-iceberg | Iceberg catalog property |
lakehouse-paimon | Paimon catalog property |
jdbc-mysql | MySQL catalog property |
jdbc-postgresql | PostgreSQL catalog property |
jdbc-doris | Doris catalog property |
Load a catalog
You can load a catalog by sending a GET
request to the /api/metalakes/{metalake_name}/catalogs/{catalog_name}
endpoint or just use the Gravitino Java client. The following is an example of loading a catalog:
- Shell
- Java
curl -X GET -H "Accept: application/vnd.gravitino.v1+json" \
-H "Content-Type: application/json" http://localhost:8090/api/metalakes/metalake/catalogs/catalog
// ...
// Assuming you have created a metalake named `metalake` and a catalog named `catalog`
Catalog catalog = gravitinoClient.loadCatalog("catalog");
// ...
Alter a catalog
You can modify a catalog by sending a PUT
request to the /api/metalakes/{metalake_name}/catalogs/{catalog_name}
endpoint or just use the Gravitino Java client. The following is an example of altering a catalog:
- Shell
- Java
curl -X PUT -H "Accept: application/vnd.gravitino.v1+json" \
-H "Content-Type: application/json" -d '{
"updates": [
{
"@type": "rename",
"newName": "alter_catalog"
},
{
"@type": "setProperty",
"property": "key3",
"value": "value3"
}
]
}' http://localhost:8090/api/metalakes/metalake/catalogs/catalog
// ...
// Assuming you have created a metalake named `metalake` and a catalog named `catalog`
Catalog catalog = gravitinoClient.alterCatalog("catalog",
CatalogChange.rename("alter_catalog"), CatalogChange.updateComment("new comment"));
// ...
Currently, Gravitino supports the following changes to a catalog:
Supported modification | JSON | Java |
---|---|---|
Rename metalake | {"@type":"rename","newName":"metalake_renamed"} | CatalogChange.rename("catalog_renamed") |
Update comment | {"@type":"updateComment","newComment":"new_comment"} | CatalogChange.updateComment("new_comment") |
Set a property | {"@type":"setProperty","property":"key1","value":"value1"} | CatalogChange.setProperty("key1", "value1") |
Remove a property | {"@type":"removeProperty","property":"key1"} | CatalogChange.removeProperty("key1") |
Most catalog-altering operations are generally safe. However, if you want to change the catalog's URI, you should proceed with caution. Changing the URI may point to a different cluster, rendering the metadata stored in Gravitino unusable. For instance, if the old URI and the new URI point to different clusters that both have a database named db1, changing the URI might cause the old metadata, such as audit information, to be used when accessing db1, which is undesirable.
Therefore, do not change the catalog's URI unless you fully understand the consequences of such a modification.
Drop a catalog
You can remove a catalog by sending a DELETE
request to the /api/metalakes/{metalake_name}/catalogs/{catalog_name}
endpoint or just use the Gravitino Java client. The following is an example of dropping a catalog:
- Shell
- Java
curl -X DELETE -H "Accept: application/vnd.gravitino.v1+json" \
-H "Content-Type: application/json" \
http://localhost:8090/api/metalakes/metalake/catalogs/catalog
// ...
// Assuming you have created a metalake named `metalake` and a catalog named `catalog`
gravitinoClient.dropCatalog("catalog");
// ...
Dropping a catalog only removes metadata about the catalog, schemas, and tables under the catalog in Gravitino, It doesn't remove the real data (table and schema) in Apache Hive.
List all catalogs in a metalake
You can list all catalogs under a metalake by sending a GET
request to the /api/metalakes/{metalake_name}/catalogs
endpoint or just use the Gravitino Java client. The following is an example of listing all the catalogs in
a metalake:
- Shell
- Java
curl -X GET -H "Accept: application/vnd.gravitino.v1+json" \
-H "Content-Type: application/json" \
http://localhost:8090/api/metalakes/metalake/catalogs
// ...
// Assuming you have just created a metalake named `metalake`
String[] catalogNames = gravitinoClient.listCatalogs();
// ...
List all catalogs' information in a metalake
You can list all catalogs' information under a metalake by sending a GET
request to the /api/metalakes/{metalake_name}/catalogs?details=true
endpoint or just use the Gravitino Java client. The following is an example of listing all the catalogs' information in a metalake:
- Shell
- Java
curl -X GET -H "Accept: application/vnd.gravitino.v1+json" \
-H "Content-Type: application/json" \
http://localhost:8090/api/metalakes/metalake/catalogs?details=true
// ...
// Assuming you have just created a metalake named `metalake`
Catalog[] catalogsInfos = gravitinoMetaLake.listCatalogsInfo();
// ...
Schema operations
Users should create a metalake and a catalog before creating a schema.