Implementation:Datahub project Datahub FieldPath Util
| Knowledge Sources | |
|---|---|
| Domains | Java_SDK, Metadata_Management |
| Last Updated | 2026-02-10 00:00 GMT |
Overview
Description
FieldPath is a utility class that parses and analyzes DataHub schema field paths. DataHub schema fields use a rich path notation that includes metadata annotations such as version numbers ([version=2.0]) and type information ([type=Foo]). This class provides methods to extract meaningful information from these annotated paths.
Key capabilities:
- Version extraction: Parses
[version=X]annotations, defaulting to"1"if absent - Simple path computation: Strips all metadata annotations to produce a clean dot-separated path
- Depth calculation: Computes logical depth ignoring metadata segments
- Leaf field extraction: Returns the last segment of the raw path
- Top-level detection: Checks if the field is at depth 1
Usage
Create a FieldPath instance with a raw field path string. The class eagerly computes the version and simplified path during construction for efficient repeated access.
Code Reference
Source Location
metadata-integration/java/datahub-client/src/main/java/io/datahubproject/models/util/FieldPath.java
Signature
public class FieldPath {
public FieldPath(@NonNull String rawFieldPath)
public boolean isTopLevel()
public int depth()
public String leafFieldName()
public String version()
public String simplePath()
}
Import
import io.datahubproject.models.util.FieldPath;
I/O Contract
Inputs
| Parameter | Type | Description |
|---|---|---|
rawFieldPath |
String (non-null) |
The raw field path string, potentially containing metadata annotations like [version=2.0] and [type=Foo]
|
Outputs
| Method | Return Type | Description |
|---|---|---|
| isTopLevel | boolean |
true if the field is at depth 1 (a root-level field)
|
| depth | int |
Logical depth of the field, ignoring type and version metadata |
| leafFieldName | String |
The last segment of the raw path (including any metadata) |
| version | String |
Extracted version number (defaults to "1" if no [version=X] annotation)
|
| simplePath | String |
Clean dot-separated path with all [...] metadata removed
|
Path simplification examples:
| Raw Path | Simple Path | Version | Depth |
|---|---|---|---|
[version=2.0][type=Foo].address.[type=union].[type=string].street |
address.street |
2.0 |
2 |
a.b.c |
a.b.c |
1 |
3 |
[version=20].a.b.c |
a.b.c |
20 |
3 |
Usage Examples
import io.datahubproject.models.util.FieldPath;
// Simple path
FieldPath simple = new FieldPath("name");
simple.isTopLevel(); // true
simple.depth(); // 1
simple.simplePath(); // "name"
simple.version(); // "1"
// Nested path with annotations
FieldPath annotated = new FieldPath(
"[version=2.0][type=Foo].address.[type=union].[type=string].street");
annotated.simplePath(); // "address.street"
annotated.depth(); // 2
annotated.version(); // "2.0"
annotated.isTopLevel(); // false
annotated.leafFieldName(); // "street"
// Versioned path
FieldPath versioned = new FieldPath("[version=20].a.b.c");
versioned.version(); // "20"
versioned.simplePath(); // "a.b.c"
versioned.depth(); // 3
Related Pages
- Datahub_project_Datahub_DataHubGuidGenerator - Another utility class in the models.util package