docs/api/tutorials/custom-properties.md
import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';
Custom properties to datasets can help to provide additional information about the data that is not readily available in the standard metadata fields. Custom properties can be used to describe specific attributes of the data, such as the units of measurement used, the date range covered, or the geographical region the data pertains to. This can be particularly helpful when working with large and complex datasets, where additional context can help to ensure that the data is being used correctly and effectively.
DataHub models custom properties of a Dataset as a map of key-value pairs of strings.
Custom properties can also be used to enable advanced search and discovery capabilities, by allowing users to filter and sort datasets based on specific attributes. This can help users to quickly find and access the data they need, without having to manually review large numbers of datasets.
This guide will show you how to add, remove or replace custom properties on a dataset fct_users_deleted. Here's what each operation means:
DatasetProperties aspect contains customProperties as well as other fields like name and description.For this tutorial, you need to deploy DataHub Quickstart and ingest sample data. For detailed information, please refer to DataHub Quickstart Guide.
:::note Before adding custom properties, you need to ensure the target dataset is already present in your DataHub instance. If you attempt to manipulate entities that do not exist, your operation will fail. In this guide, we will be using data from sample ingestion. :::
In this example, we will add some custom properties cluster_name and retention_time to the dataset fct_users_deleted.
After you have ingested sample data, the dataset fct_users_deleted should have a custom properties section with encoding set to utf-8.
datahub get --urn "urn:li:dataset:(urn:li:dataPlatform:hive,fct_users_deleted,PROD)" --aspect datasetProperties
{
"datasetProperties": {
"customProperties": {
"encoding": "utf-8"
},
"description": "table containing all the users deleted on a single day",
"tags": []
}
}
The following code adds custom properties cluster_name and retention_time to a dataset named fct_users_deleted without affecting existing properties.
</TabItem> <TabItem value="java" label="Java">🚫 Adding Custom Properties on Dataset via GraphQL is currently not supported. Please check out API feature comparison table for more information,
{{ inline /metadata-integration/java/examples/src/main/java/io/datahubproject/examples/DatasetCustomPropertiesAdd.java show_path_as_comment }}
{{ inline /metadata-ingestion/examples/library/dataset_add_custom_properties_patch.py show_path_as_comment }}
You can now see the two new properties are added to fct_users_deleted and the previous property encoding is unchanged.
We can also verify this operation by programmatically checking the datasetProperties aspect after running this code using the datahub cli.
datahub get --urn "urn:li:dataset:(urn:li:dataPlatform:hive,fct_users_deleted,PROD)" --aspect datasetProperties
{
"datasetProperties": {
"customProperties": {
"encoding": "utf-8",
"cluster_name": "datahubproject.acryl.io",
"retention_time": "2 years"
},
"description": "table containing all the users deleted on a single day",
"tags": []
}
}
The following code shows you how can add and remove custom properties in the same call. In the following code, we add custom property cluster_name and remove property retention_time from a dataset named fct_users_deleted without affecting existing properties.
</TabItem> <TabItem value="java" label="Java">🚫 Adding and Removing Custom Properties on Dataset via GraphQL is currently not supported. Please check out API feature comparison table for more information,
{{ inline /metadata-integration/java/examples/src/main/java/io/datahubproject/examples/DatasetCustomPropertiesAddRemove.java show_path_as_comment }}
{{ inline /metadata-ingestion/examples/library/dataset_add_remove_custom_properties_patch.py show_path_as_comment }}
You can now see the cluster_name property is added to fct_users_deleted and the retention_time property is removed.
We can also verify this operation programmatically by checking the datasetProperties aspect using the datahub cli.
datahub get --urn "urn:li:dataset:(urn:li:dataPlatform:hive,fct_users_deleted,PROD)" --aspect datasetProperties
{
"datasetProperties": {
"customProperties": {
"encoding": "utf-8",
"cluster_name": "datahubproject.acryl.io"
},
"description": "table containing all the users deleted on a single day",
"tags": []
}
}
The following code replaces the current custom properties with a new properties map that includes only the properties cluster_name and retention_time. After running this code, the previous encoding property will be removed.
</TabItem> <TabItem value="java" label="Java">🚫 Replacing Custom Properties on Dataset via GraphQL is currently not supported. Please check out API feature comparison table for more information,
{{ inline /metadata-integration/java/examples/src/main/java/io/datahubproject/examples/DatasetCustomPropertiesReplace.java show_path_as_comment }}
{{ inline /metadata-ingestion/examples/library/dataset_replace_properties.py show_path_as_comment }}
You can now see the cluster_name and retention_time properties are added to fct_users_deleted but the previous encoding property is no longer present.
We can also verify this operation programmatically by checking the datasetProperties aspect using the datahub cli.
datahub get --urn "urn:li:dataset:(urn:li:dataPlatform:hive,fct_users_deleted,PROD)" --aspect datasetProperties
{
"datasetProperties": {
"customProperties": {
"cluster_name": "datahubproject.acryl.io",
"retention_time": "2 years"
},
"description": "table containing all the users deleted on a single day",
"tags": []
}
}