Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Datahub project Datahub Container Key Guid Generator

From Leeroopedia
Revision as of 14:42, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Datahub_project_Datahub_Container_Key_Guid_Generator.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Knowledge Sources
Domains Python_CLI, Metadata_Emission
Last Updated 2026-02-10 00:00 GMT

Overview

A Python CLI tool that generates DataHub container URNs for database and schema entities using Click and the DataHub MCP builder library.

Description

The Container Key GUID Generator is a command-line utility built with the Click framework that produces deterministic URN identifiers for DataHub container entities. It follows the Strategy pattern through an abstract URNGenerator base class with two concrete implementations:

  • DatabaseURNGenerator -- Generates URNs for database containers using DatabaseKey from the DataHub MCP builder. Requires platform and database parameters, with an optional instance parameter.
  • SchemaURNGenerator -- Generates URNs for schema containers using SchemaKey from the DataHub MCP builder. Requires platform, database, and schema parameters, with optional instance and env parameters.

Both generators perform strict input validation, rejecting unknown or missing fields with descriptive error messages. The tool supports two output formats: plain text (default) and JSON, which includes the URN, container type, and input parameters.

Usage

Use this script when you need to deterministically generate container URNs outside of the normal ingestion pipeline, for example during testing, debugging, or manual metadata operations. It is especially useful for verifying the URN format that the Java SDK or Python ingestion framework would produce for a given set of container key parameters.

Code Reference

Source Location

metadata-integration/java/datahub-client/scripts/container_key_guid_generator.py

Signature

class URNGenerator(ABC):
    @abstractmethod
    def generate(self, args: Dict[str, Any]) -> str: ...

class DatabaseURNGenerator(URNGenerator):
    def generate(self, args: Dict[str, Any]) -> str: ...

class SchemaURNGenerator(URNGenerator):
    def generate(self, args: Dict[str, Any]) -> str: ...

def validate_key_value(ctx, param, value) -> dict: ...

@click.command()
def generate_urn(container_type: str, param: Dict[str, str], output_format: str): ...

Import

from datahub.emitter.mcp_builder import DatabaseKey, SchemaKey
import click

I/O Contract

Inputs

Parameter Type Required Description
--container-type Choice: database, schema Yes The type of container URN to generate
--param / -p Multiple key=value pairs Yes Container key fields (e.g., -p platform=mysql -p database=mydb)
--output-format Choice: text, json No (default: text) Controls whether output is a plain URN string or a JSON object

Database container required params: platform, database; optional: instance

Schema container required params: platform, database, schema; optional: instance, env

Outputs

  • Text format: A single URN string printed to stdout (e.g., urn:li:container:...)
  • JSON format: A JSON object containing urn, container_type, and parameters fields

Usage Examples

# Generate a database container URN
python container_key_guid_generator.py --container-type database \
  -p platform=test-platform -p instance=DEV -p database=test-database

# Generate a schema container URN with JSON output
python container_key_guid_generator.py --container-type schema \
  -p platform=mysql -p database=mydb -p schema=public --output-format json

JSON output example:

{
  "urn": "urn:li:container:...",
  "container_type": "schema",
  "parameters": {
    "platform": "mysql",
    "database": "mydb",
    "schema": "public"
  }
}

Related Pages

Page Connections

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