Implementation:Datahub project Datahub Chart Entity
| Knowledge Sources | |
|---|---|
| Domains | Java_SDK, Metadata_Management |
| Last Updated | 2026-02-10 00:00 GMT |
Overview
Chart is a Java SDK V2 entity class representing a DataHub Chart entity (a visualization or report from a BI tool) with a fluent builder API and patch-based mutation support.
Description
The Chart class extends Entity and implements multiple mixin interfaces (HasTags, HasGlossaryTerms, HasOwners, HasDomains, HasSubTypes, HasStructuredProperties) to provide a comprehensive set of metadata operations. It represents visualizations from BI tools such as Looker, Tableau, or Superset.
Key characteristics:
- Entity type:
"chart" - URN format:
urn:li:chart:(tool,chartId)viaChartUrn - Patch-based mutations: All setter methods (e.g.,
setDescription,setTitle,addCustomProperty) createChartInfoPatchBuilderpatches that accumulate untilupsert()is called. - Lazy-loaded reads: Getter methods (e.g.,
getDescription,getTitle) usegetAspectLazy()to read from the aspect cache. - Mutable/read-only pattern: Entities fetched from the server are read-only. Call
.mutable()to get a mutable copy for mutation. - Lineage support: Supports input dataset edges to track which datasets a chart consumes via
addInputDataset()andsetInputDatasets(). - Builder: The inner
Builderclass requirestoolandidfields; optionally acceptstitle,description, andcustomProperties(but if any of these are set, bothtitleanddescriptionbecome required).
Default aspects fetched: Ownership, GlobalTags, GlossaryTerms, Domains, Status, InstitutionalMemory, ChartInfo, EditableChartProperties.
Usage
Use the Chart entity when you need to create, update, or read chart metadata in DataHub from a Java application. It is typically constructed via its Builder and upserted through EntityClient.upsert(chart).
Code Reference
Source Location
- Repository: Datahub_project_Datahub
- File: metadata-integration/java/datahub-client/src/main/java/datahub/client/v2/entity/Chart.java
Signature
public class Chart extends Entity
implements HasTags<Chart>, HasGlossaryTerms<Chart>, HasOwners<Chart>,
HasDomains<Chart>, HasSubTypes<Chart>, HasStructuredProperties<Chart> {
// Factory
public static Builder builder();
// Identity
public String getEntityType(); // returns "chart"
public ChartUrn getChartUrn();
public Chart mutable();
// Metadata operations
public Chart setDescription(String description);
public String getDescription();
public Chart setTitle(String title);
public String getTitle();
public Chart setExternalUrl(String externalUrl);
public String getExternalUrl();
public Chart setChartUrl(String chartUrl);
public String getChartUrl();
public Chart setChartType(String chartType);
public String getChartType();
public Chart setAccess(String access);
public String getAccess();
public Chart setLastRefreshed(long lastRefreshed);
public Long getLastRefreshed();
// Custom properties
public Chart addCustomProperty(String key, String value);
public Chart removeCustomProperty(String key);
public Chart setCustomProperties(Map<String, String> properties);
// Lineage
public Chart setInputDatasets(List<DatasetUrn> datasets);
public Chart addInputDataset(DatasetUrn dataset);
public Chart removeInputDataset(DatasetUrn dataset);
public List<DatasetUrn> getInputDatasets();
}
Import
import datahub.client.v2.entity.Chart;
I/O Contract
Builder Inputs
| Parameter | Type | Required | Description |
|---|---|---|---|
tool |
String |
Yes | BI tool name (e.g., "looker", "tableau") |
id |
String |
Yes | Chart identifier within the tool |
title |
String |
Conditional | Chart title (required if description or customProperties set) |
description |
String |
Conditional | Chart description (required if title or customProperties set) |
customProperties |
Map<String, String> |
No | Custom key-value properties |
Outputs
| Method | Return Type | Description |
|---|---|---|
build() |
Chart |
New Chart entity with ChartUrn derived from tool and id
|
getChartUrn() |
ChartUrn |
The chart URN |
getInputDatasets() |
List<DatasetUrn> |
Lineage: datasets consumed by this chart |
Usage Examples
// Create a chart
Chart chart = Chart.builder()
.tool("looker")
.id("sales_chart_1")
.title("Monthly Sales")
.description("Revenue by region")
.build();
// Add metadata via fluent patch API
chart.addTag("pii");
chart.addOwner("urn:li:corpuser:analyst", OwnershipType.TECHNICAL_OWNER);
chart.setChartType("BAR");
chart.addInputDataset(new DatasetUrn(
new DataPlatformUrn("snowflake"), "sales_db.revenue", FabricType.PROD));
// Upsert to DataHub
client.entities().upsert(chart);
// Read a chart from server
Chart fetched = client.entities().get(
"urn:li:chart:(looker,sales_chart_1)", Chart.class);
String title = fetched.getTitle();