Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Datahub project Datahub Entity Metadata Mutations

From Leeroopedia


Field Value
Implementation Name Entity Metadata Mutations
Type API Doc
Status Active
Last Updated 2026-02-10
Repository Datahub_project_Datahub
Source Files HasTags.java (Lines 46-335), HasOwners.java (Lines 36-169), HasGlossaryTerms.java (Lines 36-185), HasDomains.java (Lines 23-164), Dataset.java (Lines 368-430)

Overview

The entity metadata mutation interfaces and methods provide the API for adding, removing, and replacing metadata facets on DataHub entities. Operations are accumulated in patch builders and flushed during upsert().

Import Statements

The trait interfaces are part of the entity classes; no separate imports are needed when working with entity types:

import datahub.client.v2.entity.Dataset;
import com.linkedin.common.OwnershipType;

HasTags Interface

File: metadata-integration/java/datahub-client/src/main/java/datahub/client/v2/entity/HasTags.java (Lines 46-335)

public interface HasTags<T extends Entity & HasTags<T>> {

    default T addTag(@Nonnull String tagUrn) { ... }
    default T addTag(@Nonnull TagUrn tagUrn) { ... }
    default T removeTag(@Nonnull String tagUrn) { ... }
    default T removeTag(@Nonnull TagUrn tagUrn) { ... }
    default T setTags(@Nonnull List<String> tagUrns) { ... }
    default List<TagAssociation> getTags() { ... }
}
Method Parameters Returns Description
addTag(String) Tag name or URN T (fluent) Adds a tag; auto-prefixes urn:li:tag: if needed. Accumulates in GlobalTagsPatchBuilder
addTag(TagUrn) TagUrn object T (fluent) Adds a tag using typed URN object
removeTag(String) Tag name or URN T (fluent) Removes a tag via patch operation
removeTag(TagUrn) TagUrn object T (fluent) Removes a tag using typed URN object
setTags(List<String>) List of tag URNs T (fluent) Replaces all tags with full aspect UPSERT (not a patch)
getTags() -- List<TagAssociation> or null Returns current tags (lazy-loaded from server if bound)

HasOwners Interface

File: metadata-integration/java/datahub-client/src/main/java/datahub/client/v2/entity/HasOwners.java (Lines 36-169)

public interface HasOwners<T extends Entity & HasOwners<T>> {

    default T addOwner(@Nonnull String ownerUrn, @Nonnull OwnershipType type) { ... }
    default T addOwner(@Nonnull Urn ownerUrn, @Nonnull OwnershipType type) { ... }
    default T removeOwner(@Nonnull String ownerUrn) { ... }
    default T removeOwner(@Nonnull Urn ownerUrn) { ... }
    default T setOwners(@Nonnull List<Owner> owners) { ... }
    default List<Owner> getOwners() { ... }
}
Method Parameters Returns Description
addOwner(String, OwnershipType) Owner URN string, ownership type T (fluent) Adds an owner with typed role. Accumulates in OwnershipPatchBuilder
addOwner(Urn, OwnershipType) Owner URN object, ownership type T (fluent) Adds an owner using typed URN object
removeOwner(String) Owner URN string T (fluent) Removes an owner; also evicts cached Ownership aspect
removeOwner(Urn) Owner URN object T (fluent) Removes an owner using typed URN object
setOwners(List<Owner>) List of Owner objects T (fluent) Replaces all owners with full aspect UPSERT
getOwners() -- List<Owner> or null Returns current owners (lazy-loaded if bound)

HasGlossaryTerms Interface

File: metadata-integration/java/datahub-client/src/main/java/datahub/client/v2/entity/HasGlossaryTerms.java (Lines 36-185)

public interface HasGlossaryTerms<T extends Entity & HasGlossaryTerms<T>> {

    default T addTerm(@Nonnull String termUrn) { ... }
    default T addTerm(@Nonnull GlossaryTermUrn termUrn) { ... }
    default T removeTerm(@Nonnull String termUrn) { ... }
    default T removeTerm(@Nonnull GlossaryTermUrn termUrn) { ... }
    default T setTerms(@Nonnull List<String> termUrns) { ... }
    default List<GlossaryTermAssociation> getTerms() { ... }
}
Method Parameters Returns Description
addTerm(String) Term URN string T (fluent) Adds a glossary term. Accumulates in GlossaryTermsPatchBuilder
addTerm(GlossaryTermUrn) GlossaryTermUrn object T (fluent) Adds a glossary term using typed URN
removeTerm(String) Term URN string T (fluent) Removes a glossary term; evicts cached aspect
removeTerm(GlossaryTermUrn) GlossaryTermUrn object T (fluent) Removes a glossary term using typed URN
setTerms(List<String>) List of term URN strings T (fluent) Replaces all terms with full aspect UPSERT
getTerms() -- List<GlossaryTermAssociation> or null Returns current terms (lazy-loaded if bound)

HasDomains Interface

File: metadata-integration/java/datahub-client/src/main/java/datahub/client/v2/entity/HasDomains.java (Lines 23-164)

public interface HasDomains<T extends Entity & HasDomains<T>> {

    default T setDomain(@Nonnull String domainUrn) { ... }
    default T setDomain(@Nonnull Urn domain) { ... }
    default T removeDomain(@Nonnull String domainUrn) { ... }
    default T removeDomain(@Nonnull Urn domain) { ... }
    default T clearDomains() { ... }
    default Urn getDomain() { ... }
    default List<Urn> getDomains() { ... }
}
Method Parameters Returns Description
setDomain(String) Domain URN string T (fluent) Sets a single domain (replaces existing). Uses direct aspect caching, not patches
setDomain(Urn) Domain URN object T (fluent) Sets a single domain using typed URN
removeDomain(String) Domain URN string T (fluent) Removes a specific domain. Requires mutable entity
removeDomain(Urn) Domain URN object T (fluent) Removes a specific domain using typed URN
clearDomains() -- T (fluent) Removes all domains. Requires mutable entity
getDomain() -- Urn or null Returns the first domain (convenience method)
getDomains() -- List<Urn> or null Returns all domains (lazy-loaded if bound)

Dataset Custom Properties

File: metadata-integration/java/datahub-client/src/main/java/datahub/client/v2/entity/Dataset.java (Lines 368-430)

public Dataset addCustomProperty(@Nonnull String key, @Nonnull String value) { ... }
public Dataset removeCustomProperty(@Nonnull String key) { ... }
public Dataset setCustomProperties(@Nonnull Map<String, String> properties) { ... }
Method Parameters Returns Description
addCustomProperty(String, String) Key, value Dataset (fluent) Adds a single custom property. Accumulates in DatasetPropertiesPatchBuilder
removeCustomProperty(String) Key Dataset (fluent) Removes a custom property by key. Accumulates in builder
setCustomProperties(Map) Map of properties Dataset (fluent) Replaces all custom properties via patch MCP

I/O Contract

Input: An entity instance (mutable or newly built) and metadata values to attach.

Output: The same entity instance (fluent return) with mutations accumulated internally:

  • Patch operations stored in patchBuilders map (keyed by aspect name)
  • Full aspect replacements stored in pendingMCPs list
  • Entity marked as dirty (pending mutations flag set)

Exceptions:

  • InvalidUrnException -- if a provided URN string is malformed
  • ReadOnlyEntityException -- if attempting to mutate a read-only entity (from get() without .mutable())

Usage Examples

Dataset dataset = Dataset.builder()
    .platform("snowflake")
    .name("my_database.my_schema.my_table")
    .build();

// Add tags (accumulates patches)
dataset.addTag("pii");
dataset.addTag("urn:li:tag:sensitive");

// Add owners (accumulates patches)
dataset.addOwner("urn:li:corpuser:johndoe", OwnershipType.DATA_OWNER);
dataset.addOwner("urn:li:corpuser:janedoe", OwnershipType.TECHNICAL_OWNER);

// Add glossary terms (accumulates patches)
dataset.addTerm("urn:li:glossaryTerm:CustomerData");

// Set domain (direct aspect caching)
dataset.setDomain("urn:li:domain:Marketing");

// Add custom properties (accumulates patches)
dataset.addCustomProperty("team", "data-engineering");
dataset.addCustomProperty("pii_level", "high");

// All mutations are flushed during upsert
client.entities().upsert(dataset);

Related

Knowledge Sources

Domains

Data_Integration, Metadata_Management, Java_SDK

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment