Implementation:Datahub project Datahub ProtobufMessage
| Knowledge Sources | |
|---|---|
| Domains | Protobuf_Integration, Schema_Modeling |
| Last Updated | 2026-02-10 00:00 GMT |
Overview
Description
ProtobufMessage is a model class that represents a Protocol Buffer message type within the DataHub protobuf schema integration. It implements the ProtobufElement interface, providing methods for name resolution, type mapping, and visitor pattern support. The class wraps a DescriptorProto along with optional parent message and file descriptor context.
Key behaviors include:
- Name resolution -- Constructs a fully qualified name from the file package, optional parent message name, and the message name.
- Type mapping -- Maps protobuf messages to DataHub
SchemaFieldDataType, distinguishing betweenMapFieldEntry(mapped toMapType) and regular messages (mapped toRecordType). - Version extraction -- Parses the major version from the file path by looking for
v<number>path segments (defaults to 1). - Comment extraction -- Delegates to
ProtobufUtils.collapseLocationCommentsfor source code comments.
Usage
Used as a node in the ProtobufGraph that represents the protobuf schema structure. Visited by various ProtobufModelVisitor implementations to produce DataHub metadata.
Code Reference
Source Location
metadata-integration/java/datahub-protobuf/src/main/java/datahub/protobuf/model/ProtobufMessage.java
Signature
@Builder
@AllArgsConstructor
public class ProtobufMessage implements ProtobufElement {
public String name()
public String fullName()
public String nativeType()
public String fieldPathType()
public FileDescriptorProto fileProto()
public DescriptorProto messageProto()
public SchemaFieldDataType schemaFieldDataType()
public int majorVersion()
public String comment()
public <T> Stream<T> accept(ProtobufModelVisitor<T> visitor, VisitContext context)
}
Import
import datahub.protobuf.model.ProtobufMessage;
I/O Contract
Inputs
| Parameter | Type | Description |
|---|---|---|
messageProto |
DescriptorProto |
The protobuf message descriptor |
parentMessageProto |
DescriptorProto (nullable) |
Parent message descriptor if this is a nested message |
fileProto |
FileDescriptorProto |
The file descriptor containing the message |
Outputs
| Method | Return Type | Description |
|---|---|---|
name() |
String |
Simple message name |
fullName() |
String |
Fully qualified name (package.parent.name or package.name) |
nativeType() |
String |
Same as fullName |
fieldPathType() |
String |
Formatted as [type=fully_qualified_name] with dots replaced by underscores
|
schemaFieldDataType() |
SchemaFieldDataType |
MapType for MapFieldEntry, RecordType otherwise
|
majorVersion() |
int |
Major version number extracted from the file path |
Usage Examples
ProtobufMessage msg = ProtobufMessage.builder()
.messageProto(descriptorProto)
.parentMessageProto(null)
.fileProto(fileDescriptorProto)
.build();
String fullName = msg.fullName(); // e.g., "com.example.MyMessage"
String pathType = msg.fieldPathType(); // e.g., "[type=com_example_MyMessage]"
SchemaFieldDataType dataType = msg.schemaFieldDataType();
int version = msg.majorVersion(); // e.g., 2 for path "com/example/v2/schema.proto"
Related Pages
- Implementation:Datahub_project_Datahub_ProtobufDescriptorUtils -- Used for comment collapsing and option extraction
- Implementation:Datahub_project_Datahub_ProtobufOneOfField -- Subclass-adjacent model for oneof fields that references ProtobufMessage
- Implementation:Datahub_project_Datahub_ProtobufDatasetVisitor -- Visitor that processes ProtobufMessage instances