Implementation:Datahub project Datahub FieldPath Schematron
| Knowledge Sources | |
|---|---|
| Domains | Schema_Conversion, Field_Path_Modeling |
| Last Updated | 2026-02-10 00:00 GMT |
Overview
Description
FieldPath is a model class in the SchemaTron library that represents the hierarchical path to a field within a DataHub schema. It maintains an ordered list of FieldElement objects, each representing one level in the field hierarchy, and provides methods for path manipulation and serialization.
Key capabilities:
- V2 path formatting -- Automatically determines whether to use v2 path format (prefixed with
[version=2.0]) based on schema complexity (union/array types present) or explicit configuration. - Key schema support -- Adds a
[key=True]prefix for key schema fields. - Path manipulation -- Supports cloning with additional elements (
clonePlus), removing the last element (popLast), and expanding type information (expandType). - Parent type tracking -- Maintains an optional
DataHubTypeparent type on the last element, enabling type override for native type rendering (arrays and maps). - Recursive type detection -- Can detect recursive type references by matching schema strings against path elements.
The EMPTY_FIELD_NAME constant (a single space) is used as a sentinel for fields that need a name but do not have one.
Usage
Used throughout the SchemaTron schema conversion pipeline to build and manipulate field paths during Avro-to-DataHub schema translation. The asString() method produces the final dot-separated field path string stored in SchemaField.fieldPath.
Code Reference
Source Location
metadata-integration/java/datahub-schematron/lib/src/main/java/io/datahubproject/schematron/models/FieldPath.java
Signature
@Data
public class FieldPath {
public static final String EMPTY_FIELD_NAME = " ";
@NonNull private List<FieldElement> path;
private boolean isKeySchema;
private boolean useV2PathsAlways;
public FieldPath()
public void setPath(List<FieldElement> path)
public String getRecursive(Map<String, Object> schema)
public FieldPath popLast()
public FieldPath clonePlus(FieldElement element)
public FieldPath expandType(String type, Object typeSchema)
public boolean hasFieldName()
public boolean ensureFieldName()
public String asString()
public String dump()
}
Import
import io.datahubproject.schematron.models.FieldPath;
I/O Contract
Inputs
| Method | Parameter | Type | Description |
|---|---|---|---|
| Constructor | (none) | -- | Creates an empty path with useV2PathsAlways=true
|
setPath |
path |
List<FieldElement> |
Replaces the path elements (no nulls allowed) |
clonePlus |
element |
FieldElement |
Element to append to a cloned path |
expandType |
type |
String |
Type name to add to the last element |
expandType |
typeSchema |
Object |
Schema object whose string form is recorded |
getRecursive |
schema |
Map<String, Object> |
Schema map to match against for recursion detection |
Outputs
| Method | Return Type | Description |
|---|---|---|
asString() |
String |
The formatted field path (e.g., [version=2.0].[type=union].fieldName)
|
popLast() |
FieldPath |
New FieldPath with the last element removed |
clonePlus() |
FieldPath |
New FieldPath with an additional element appended |
expandType() |
FieldPath |
New FieldPath with expanded type info on the last element |
getRecursive() |
String (nullable) |
The matched type name if recursion is detected, null otherwise |
hasFieldName() |
boolean |
Whether any element in the path has a non-null name |
dump() |
String |
Debug string showing the full path with element details |
Usage Examples
// Build a field path
FieldPath path = new FieldPath();
FieldPath extended = path.clonePlus(new FieldElement(
new ArrayList<>(List.of("record")),
new ArrayList<>(List.of(schemaStr)),
"myField",
null));
// Convert to string
String fieldPathStr = extended.asString();
// e.g., "[version=2.0].[type=record].myField"
// Expand type for union
FieldPath withUnion = extended.expandType("union", unionSchema);
// Check for recursive types
String recursiveType = path.getRecursive(schemaMap);
Related Pages
- Datahub_project_Datahub_SchemaTronDataHubType -- Used as parent type for path elements to determine native type overrides
- Datahub_project_Datahub_SchemaTron_CLI -- CLI tool that drives the schema conversion using FieldPath