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 ExtensionRegistry Override

From Leeroopedia


Knowledge Sources
Domains Protobuf_Integration
Last Updated 2026-02-10 00:00 GMT

Overview

A custom override of Google's com.google.protobuf.ExtensionRegistry that modifies the hash/equals behavior of the DescriptorIntPair inner class to use full name-based comparison instead of descriptor identity-based comparison.

Description

This class extends ExtensionRegistryLite and provides a table of known protobuf extensions searchable by name or field number. When parsing protocol buffer messages that may contain extensions, this registry must be provided so that extensions can be properly deserialized rather than being treated as unknown fields.

The key DataHub modification is in the DescriptorIntPair inner class. The upstream Google Protobuf library uses the descriptor object reference for equality checks, but DataHub's use of the registry can produce objects that are practically identical except for the jsonName field -- a difference generated by internal components that is not under DataHub's control. This override changes equals() and hashCode() to compare based on fullName (a String) instead, ensuring consistent lookups.

The registry maintains four internal maps for both mutable and immutable extension lookups:

  • immutableExtensionsByName / mutableExtensionsByName -- keyed by fully-qualified extension name
  • immutableExtensionsByNumber / mutableExtensionsByNumber -- keyed by (Descriptor, fieldNumber) pairs

Usage

Use this override when building a ProtobufGraph from a FileDescriptorSet. The ProtobufUtils.buildRegistry() method returns an instance of this class, and it is then used to re-parse the file descriptor set with extensions properly resolved. This is essential for the protobuf-to-DataHub metadata pipeline to correctly handle custom protobuf annotations (e.g., ownership, tags, domain markers).

Code Reference

Source Location

Signature

public class ExtensionRegistry extends ExtensionRegistryLite {

    public static ExtensionRegistry newInstance();
    public static ExtensionRegistry getEmptyRegistry();
    public ExtensionRegistry getUnmodifiable();

    // Lookup methods
    public ExtensionInfo findImmutableExtensionByName(String fullName);
    public ExtensionInfo findMutableExtensionByName(String fullName);
    public ExtensionInfo findImmutableExtensionByNumber(Descriptor containingType, int fieldNumber);
    public ExtensionInfo findMutableExtensionByNumber(Descriptor containingType, int fieldNumber);
    public Set<ExtensionInfo> getAllMutableExtensionsByExtendedType(String fullName);
    public Set<ExtensionInfo> getAllImmutableExtensionsByExtendedType(String fullName);

    // Registration methods
    public void add(Extension<?, ?> extension);
    public void add(FieldDescriptor type);
    public void add(FieldDescriptor type, Message defaultInstance);

    // DataHub-modified inner class
    private static final class DescriptorIntPair {
        // Uses fullName-based equals/hashCode instead of descriptor identity
    }
}

Import

import com.google.protobuf.ExtensionRegistry;

I/O Contract

Input Type Description
extension Extension<?, ?> A protobuf extension to register
type FieldDescriptor A field descriptor for a non-message extension
fullName String Fully-qualified extension name for lookups
containingType / fieldNumber Descriptor / int Containing type and field number for number-based lookups
Output Type Description
ExtensionInfo ExtensionInfo Contains the extension's FieldDescriptor and optional default Message instance
Set<ExtensionInfo> Set All extensions matching a given extended type name

Usage Examples

// Create a new registry and register extensions
ExtensionRegistry registry = ExtensionRegistry.newInstance();
registry.add(MyCustomAnnotations.ownership);
registry.add(MyCustomAnnotations.tagAnnotation);

// Re-parse a FileDescriptorSet with extensions resolved
FileDescriptorSet fileSetExtended =
    FileDescriptorSet.parseFrom(fileSet.toByteArray(), registry);

// Look up an extension by name
ExtensionRegistry.ExtensionInfo info =
    registry.findImmutableExtensionByName("my.package.ownership");

Related Pages

Page Connections

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