World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
title: "Manage Tags" slug: "/manage-tags-in-gravitino" keyword: "tag management, tag, tags, Gravitino" license: "This software is licensed under the Apache License version 2."
import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';
Introduction
This page covers the Gravitino API for tags. For what a tag is, which object types can carry one, how inheritance resolves, and how to work with tags in the UI, see Tags.
Policies can be associated with tags to govern objects carrying those tags. See Policy-to-Tag Associations.
Domains derive membership from explicit backing tags and existing assignments. See Manage domains for binding, ownership and conflict rules.
Tag Operations
Create a Tag
A tag needs a name, and can carry a comment and properties.
curl -X POST -H "Accept: application/vnd.gravitino.v1+json" \
-H "Content-Type: application/json" -d '{
"name": "pii",
"comment": "Personally identifiable information",
"properties": {"owner": "data-governance"}
}' http://localhost:8090/api/metalakes/test/tags
GravitinoClient client = ...
Tag tag = client.createTag(
"pii",
"Personally identifiable information",
ImmutableMap.of("owner", "data-governance"));
tag = client.create_tag(
tag_name="pii",
comment="Personally identifiable information",
properties={"owner": "data-governance"})
Create a Tag With a Value Constraint
A tag can accept any value, no value, or only a fixed set of values. The constraint is set at
creation time and cannot be altered later. Omitting allowedValues over REST or Python creates an
unrestricted tag; an empty list creates a tag that can only be assigned without a value.
curl -X POST -H "Accept: application/vnd.gravitino.v1+json" \
-H "Content-Type: application/json" -d '{
"name": "data_domain",
"comment": "Business data domain",
"allowedValues": ["finance", "risk", "ml"]
}' http://localhost:8090/api/metalakes/test/tags
Tag tag = client.createTag(
"data_domain",
"Business data domain",
ImmutableMap.of(),
TagValueConstraint.ofAllowedValues("finance", "risk", "ml"));
Use TagValueConstraint.anyValue() for an unrestricted tag and
TagValueConstraint.noValue() for a tag that cannot carry assignment values.
tag = client.create_tag(
tag_name="data_domain",
comment="Business data domain",
properties={},
allowed_values=["finance", "risk", "ml"])
List Tags
Listing returns names, or full tag objects when details=true is set.
curl -X GET -H "Accept: application/vnd.gravitino.v1+json" \
http://localhost:8090/api/metalakes/test/tags
curl -X GET -H "Accept: application/vnd.gravitino.v1+json" \
"http://localhost:8090/api/metalakes/test/tags?details=true"
String[] tagNames = client.listTags();
Tag[] tags = client.listTagsInfo();
tag_names = client.list_tags()
tags = client.list_tags_info()
Get a Tag
curl -X GET -H "Accept: application/vnd.gravitino.v1+json" \
http://localhost:8090/api/metalakes/test/tags/pii
Tag tag = client.getTag("pii");
tag = client.get_tag("pii")
Alter a Tag
Changes are applied as a list in one request.
| Change | JSON | Java | Python |
|---|---|---|---|
| Rename | {"@type":"rename","newName":"tag_renamed"} |
TagChange.rename("tag_renamed") |
TagChange.rename("tag_renamed") |
| Update the comment | {"@type":"updateComment","newComment":"new_comment"} |
TagChange.updateComment("new_comment") |
TagChange.update_comment("new_comment") |
| Set a property | {"@type":"setProperty","property":"key1","value":"value1"} |
TagChange.setProperty("key1", "value1") |
TagChange.set_property("key1", "value1") |
| Remove a property | {"@type":"removeProperty","property":"key1"} |
TagChange.removeProperty("key1") |
TagChange.remove_property("key1") |
curl -X PUT -H "Accept: application/vnd.gravitino.v1+json" \
-H "Content-Type: application/json" -d '{
"updates": [
{"@type": "updateComment", "newComment": "Reviewed quarterly"},
{"@type": "setProperty", "property": "owner", "value": "privacy-office"}
]
}' http://localhost:8090/api/metalakes/test/tags/pii
Tag tag = client.alterTag(
"pii",
TagChange.updateComment("Reviewed quarterly"),
TagChange.setProperty("owner", "privacy-office"));
tag = client.alter_tag(
"pii",
TagChange.update_comment("Reviewed quarterly"),
TagChange.set_property("owner", "privacy-office"))
Delete a Tag
Deleting a tag also removes it from every object it was attached to.
curl -X DELETE -H "Accept: application/vnd.gravitino.v1+json" \
http://localhost:8090/api/metalakes/test/tags/pii
client.deleteTag("pii");
client.delete_tag("pii")
Object Operations
Attach and Detach Tags
Both happen in one request, and either list can be omitted. The object type and full name go in the path, so the same call covers catalogs, schemas, tables, views, columns, filesets, topics, models, functions, and Semantic Models.
Tag names that do not exist in the metalake are ignored instead of failing the request, in either list. The call returns the tags attached to the object after the change, so compare it with the names you sent to catch a typo or a tag that was dropped in the meantime.
curl -X POST -H "Accept: application/vnd.gravitino.v1+json" \
-H "Content-Type: application/json" -d '{
"tagsToAdd": ["pii"],
"tagsToRemove": ["unreviewed"]
}' http://localhost:8090/api/metalakes/test/objects/table/catalog1.schema1.customers/tags
curl -X POST -H "Accept: application/vnd.gravitino.v1+json" \
-H "Content-Type: application/json" -d '{
"tagsToAdd": ["pii"]
}' http://localhost:8090/api/metalakes/test/objects/fileset/catalog1.schema1.raw_events/tags
Table customers = ...
customers.supportsTags().associateTags(
new String[] {"pii"},
new String[] {"unreviewed"});
Fileset rawEvents = ...
rawEvents.supportsTags().associateTags(new String[] {"pii"}, null);
customers = ...
customers.supports_tags().associate_tags(["pii"], ["unreviewed"])
raw_events = ...
raw_events.supports_tags().associate_tags(["pii"], None)
:::note Column tags follow the column's internal id. For tables whose metadata is kept by an external catalog, such as Hive, Iceberg or JDBC catalogs, a column rename that runs concurrently with a load or another alter of the same table, on any Gravitino server, can be stored as a dropped column plus a new one. The renamed column then loses its tags. Avoid loading or altering a table while one of its columns is being renamed, and check the column's tags after the rename. :::
Assign and Remove Tag Values
Tag values are updated as pairs of tag name and value. Adding a pair preserves the tag's other
values; removing a pair removes only that value. Omit value to represent an assignment without a
value. The REST operation uses the v2 media type for the request body.
curl -X POST -H "Accept: application/vnd.gravitino.v2+json" \
-H "Content-Type: application/vnd.gravitino.v2+json" -d '{
"tagsToAdd": [
{"name": "data_domain", "value": "finance"},
{"name": "data_domain", "value": "risk"},
{"name": "pii"}
],
"tagsToRemove": [
{"name": "data_domain", "value": "old"}
]
}' http://localhost:8090/api/metalakes/test/objects/table/catalog1.schema1.customers/tags
Table customers = ...
customers.supportsTags().associateTags(
new TagValue[] {
TagValue.of("data_domain", "finance"),
TagValue.of("data_domain", "risk"),
TagValue.noValue("pii")
},
new TagValue[] {TagValue.of("data_domain", "old")});
customers = ...
customers.supports_tags().assign_tags(
tags_to_add=[
{"name": "data_domain", "value": "finance"},
{"name": "data_domain", "value": "risk"},
{"name": "pii"},
],
tags_to_remove=[{"name": "data_domain", "value": "old"}])
The same pair can be added or removed repeatedly without changing the result. A request cannot add the same tag both with and without values, or include the same pair in both lists. To convert a valued assignment to a valueless one, remove every active value and add the valueless pair in the same request. Removing the last value without adding a valueless pair detaches the tag.
List Tags on an Object
The response includes tags inherited from ancestors. With details=true each tag carries an
inherited field and its assignmentValues, which a plain name listing does not. An empty
assignmentValues array means the tag is assigned without a value. allowedValues is null for an
unrestricted tag, empty for a valueless-only tag, and otherwise contains the tag's allowed values.
Both response modes include hasInaccessibleTags. Gravitino resolves direct and inherited tag
assignments before authorization filtering, so the flag also covers inaccessible inherited tags.
The flag reveals only that at least one tag was omitted; it does not reveal the tag's name, count,
details, or inheritance source.
curl -X GET -H "Accept: application/vnd.gravitino.v1+json" \
"http://localhost:8090/api/metalakes/test/objects/table/catalog1.schema1.customers/tags?details=true"
The response includes each tag's definition and assignment details:
{
"code": 0,
"tags": [
{
"name": "data_domain",
"comment": "Business data domain",
"properties": {},
"allowedValues": ["finance", "risk", "ml"],
"assignmentValues": ["finance", "risk"],
"inherited": false
}
],
"hasInaccessibleTags": false
}
If every effective tag is inaccessible, the response contains an empty list and sets the flag:
{
"code": 0,
"tags": [],
"hasInaccessibleTags": true
}
Table customers = ...
TagList<String> nameList = customers.supportsTags().listTagsWithVisibility();
String[] tagNames = nameList.tags();
boolean omittedTags = nameList.hasInaccessibleTags();
TagList<Tag> detailList = customers.supportsTags().listTagsInfoWithVisibility();
Tag[] tags = detailList.tags();
boolean omittedTagDetails = detailList.hasInaccessibleTags();
String[] values =
tags[0].assignment().map(assignment -> assignment.values()).orElse(new String[0]);
The existing listTags() and listTagsInfo() methods continue to return only the visible arrays.
customers = ...
name_list = customers.supports_tags().list_tags_with_visibility()
tag_names = name_list.tags()
omitted_tags = name_list.has_inaccessible_tags()
detail_list = customers.supports_tags().list_tags_info_with_visibility()
tags = detail_list.tags()
omitted_tag_details = detail_list.has_inaccessible_tags()
values = tags[0].assignment_values()
The existing list_tags() and list_tags_info() methods continue to return only the visible lists.
Interpret the visible list and hasInaccessibleTags together:
| Visible list | hasInaccessibleTags |
Meaning |
|---|---|---|
| Empty | false |
The object has no effective tag assignments. |
| Empty | true |
All effective tag assignments are inaccessible. |
| Non-empty | true |
The response includes visible tags and omits at least one inaccessible tag. |
| Non-empty | false |
All effective tag assignments are visible. |
Get One Tag on an Object
curl -X GET -H "Accept: application/vnd.gravitino.v1+json" \
http://localhost:8090/api/metalakes/test/objects/table/catalog1.schema1.customers/tags/pii
Tag tag = customers.supportsTags().getTag("pii");
tag = customers.supports_tags().get_tag("pii")
List Objects Carrying a Tag
The response lists direct attachments only, so a tag attached to a catalog returns that catalog
rather than the objects beneath it. Pass value to return only direct assignments containing that
exact, case-sensitive value. Valueless assignments do not match a value filter.
curl -X GET -H "Accept: application/vnd.gravitino.v1+json" \
http://localhost:8090/api/metalakes/test/tags/pii/objects
curl -X GET -H "Accept: application/vnd.gravitino.v1+json" \
"http://localhost:8090/api/metalakes/test/tags/data_domain/objects?value=finance"
Tag tag = client.getTag("pii");
MetadataObject[] objects = tag.associatedObjects().objects();
int count = tag.associatedObjects().count();
Tag domain = client.getTag("data_domain");
MetadataObject[] financeObjects = domain.associatedObjects().objects("finance");
tag = client.get_tag("data_domain")
objects = tag.associated_objects().objects()
finance_objects = tag.associated_objects().objects(value="finance")