Implementation:Datahub project Datahub ProtobufOneOfField
| Knowledge Sources | |
|---|---|
| Domains | Protobuf_Integration, Schema_Modeling |
| Last Updated | 2026-02-10 00:00 GMT |
Overview
Description
ProtobufOneOfField is a model class that represents a Protocol Buffer oneof field within the DataHub protobuf schema integration. It extends ProtobufField and overrides key methods to provide union-type semantics. The class maps protobuf oneof declarations to DataHub's UnionType schema field type, using the fixed native type string "oneof" and field path type "[type=union]".
The comment extraction logic filters source code locations for ONEOF_DECL_FIELD_NUMBER path entries to locate the specific documentation associated with the oneof declaration.
Usage
Instantiated during protobuf schema graph construction when a oneof declaration is encountered. Participates in the visitor pattern to contribute union-type schema fields to the DataHub metadata output.
Code Reference
Source Location
metadata-integration/java/datahub-protobuf/src/main/java/datahub/protobuf/model/ProtobufOneOfField.java
Signature
@Getter
public class ProtobufOneOfField extends ProtobufField {
public static final String NATIVE_TYPE = "oneof";
public static final String FIELD_PATH_TYPE = "[type=union]";
@Builder(builderMethodName = "oneOfBuilder")
public ProtobufOneOfField(ProtobufMessage protobufMessage, FieldDescriptorProto fieldProto)
public String name()
public String fieldPathType()
public String nativeType()
public boolean isMessage()
public SchemaFieldDataType schemaFieldDataType()
public String comment()
}
Import
import datahub.protobuf.model.ProtobufOneOfField;
I/O Contract
Inputs
| Parameter | Type | Description |
|---|---|---|
protobufMessage |
ProtobufMessage |
The parent message containing this oneof declaration |
fieldProto |
FieldDescriptorProto |
The field descriptor proto for one of the fields in the oneof |
Outputs
| Method | Return Type | Description |
|---|---|---|
name() |
String |
The name of the oneof declaration (from oneOfProto().getName())
|
fieldPathType() |
String |
Always returns "[type=union]"
|
nativeType() |
String |
Always returns "oneof"
|
isMessage() |
boolean |
Always returns false
|
schemaFieldDataType() |
SchemaFieldDataType |
Returns a UnionType schema field data type
|
comment() |
String |
Extracted comments for the oneof declaration from source code info |
Usage Examples
ProtobufOneOfField oneOf = ProtobufOneOfField.oneOfBuilder()
.protobufMessage(parentMessage)
.fieldProto(fieldDescriptorProto)
.build();
String name = oneOf.name(); // e.g., "value_type"
SchemaFieldDataType type = oneOf.schemaFieldDataType(); // UnionType
String pathType = oneOf.fieldPathType(); // "[type=union]"
Related Pages
- Datahub_project_Datahub_ProtobufMessage -- Parent message model
- Datahub_project_Datahub_ProtobufDescriptorUtils -- Used for comment collapsing
- Datahub_project_Datahub_ProtobufExtensionFieldVisitor -- Visits fields including oneof fields