Implementation:Datahub project Datahub DataHubGuidGenerator
| Knowledge Sources | |
|---|---|
| Domains | Java_SDK, Metadata_Management |
| Last Updated | 2026-02-10 00:00 GMT |
Overview
Description
DataHubGuidGenerator is a utility class that generates deterministic GUID strings for DataHub entities. It takes a Map<String, String> of key-value pairs, serializes them as JSON with sorted keys for deterministic output, and computes an MD5 hash of the resulting string. The hash is returned as a lowercase hexadecimal string.
The deterministic nature of this generator ensures that the same set of input key-value pairs always produces the same GUID, which is essential for consistent entity identification across different systems and invocations.
The class uses Lombok @Slf4j for logging and @SneakyThrows to propagate checked exceptions as unchecked.
Usage
Call the static dataHubGuid() method with a map of identifying properties. The method is typically used to generate unique identifiers for entities based on their distinguishing attributes (e.g., platform, name, environment).
Code Reference
Source Location
metadata-integration/java/datahub-client/src/main/java/io/datahubproject/models/util/DataHubGuidGenerator.java
Signature
@Slf4j
public class DataHubGuidGenerator {
@SneakyThrows
public static String dataHubGuid(Map<String, String> obj)
}
Import
import io.datahubproject.models.util.DataHubGuidGenerator;
I/O Contract
Inputs
| Parameter | Type | Description |
|---|---|---|
obj |
Map<String, String> |
Key-value pairs representing the identifying attributes of an entity |
Outputs
| Return Type | Description |
|---|---|
String |
A 32-character lowercase hexadecimal MD5 hash string |
Algorithm:
- Configure Jackson
ObjectMapperto sort map entries by keys - Serialize the map to a JSON string
- Compute MD5 hash of the JSON bytes
- Convert hash bytes to lowercase hexadecimal string
Usage Examples
import io.datahubproject.models.util.DataHubGuidGenerator;
import java.util.Map;
import java.util.LinkedHashMap;
// Generate a GUID from entity properties
Map<String, String> properties = new LinkedHashMap<>();
properties.put("platform", "snowflake");
properties.put("name", "my_database.my_table");
properties.put("env", "PROD");
String guid = DataHubGuidGenerator.dataHubGuid(properties);
// Returns a deterministic 32-char hex string, e.g., "a1b2c3d4e5f6..."
// Same inputs always produce the same GUID
String guid2 = DataHubGuidGenerator.dataHubGuid(properties);
assert guid.equals(guid2);
Related Pages
- Datahub_project_Datahub_FieldPath_Util - Another utility class in the models.util package