Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# An OpenLineage field resolves through the stored columns, and a column it creates takes the connector's reserved-keyword name

- **Status:** Accepted
- **Revisions:** v1 2026-11-01 (initial)
- **Deciders:** ccurve1870
- **Guard:** `OpenLineageMapperTest`, `OpenLineageColumnMapperTest`, `test_openlineage.py::test_get_column_lineage_uses_stored_fqn_of_special_column_names`, `OpenLineageLineageResolutionIT#columnLineage_reachesStoredColumnsOfSpecialFieldNames`
- **Related:** #36788, #35969, #30211

## Context
OpenLineage producers report columns as the source names them, so a field can be `a>b` or `c.d`.
Since #30211 a column name cannot hold `::`, `>`, `"` or control characters, and connectors store
keywords in their place (`a__reserved__arrow__b`). A dot stays in the name and is quoted in the FQN
(`"c.d"`). A column FQN built by appending a field to the table FQN therefore misses these columns,
and `LineageRepository.validateLineageDetails` drops the entry without reporting it. Quoting every
dotted field is no answer either: `s.x` also names the child `x` of a struct `s`, and that FQN is
not quoted.

## Decision
- A column FQN in OpenLineage lineage comes from the stored column, never from the field name
alone.
- On the server (`OpenLineageMapper`), a field resolves against a table's stored columns by the
dotted path of their names: first as sent, then with reserved keywords, and only then as
`<datasetFqn>.<field>`. Trying it as sent first keeps a column stored with a raw `>` matching.
Datasets that are not tables always use `<datasetFqn>.<field>`.
- In the connector (`OpenlineageSource._match_column_fqn`), a field matches a fetched column by
case-insensitive name and takes that column's `fullyQualifiedName`. A fetched name has its
reserved characters decoded, so it cannot be used to rebuild the FQN.
- A column created from an event takes `OpenLineageColumnMapper.toStoredName`, which must produce
what `replace_separators` in `custom_basemodel_validation.py` produces: `::`, `>`, `"`, newline,
carriage return and tab become `__reserved__colon__`, `__reserved__arrow__`,
`__reserved__quote__`, `__reserved__newline__`, `__reserved__carriage_return__` and
`__reserved__tab__`.

## Consequences
- A later metadata ingestion updates a column created from an event instead of adding a second one.
- The keyword list lives in Python and Java, and no test ties the two together: changing one means
changing the other.
- A column literally named `s.x` and the child `x` of a struct `s` in the same table share one
field path, so a field reaches the one that comes later in the table.
- An event with column lineage reads the stored columns of its outputs and of each input it
references, once per event.
Original file line number Diff line number Diff line change
Expand Up @@ -560,13 +560,20 @@ def _get_by_name_cached(self, entity_class, fqn_str: str, **kwargs):
return result

@staticmethod
def _match_column_name(table, field_name: str) -> str | None:
"""Resolve an OpenLineage field name to the real stored column name, case-insensitively."""
def _match_column_fqn(table, table_fqn: str, field_name: str) -> str | None:
"""
Resolve an OpenLineage field name to the FQN of the real stored column, case-insensitively.

The stored FQN cannot be rebuilt from the column name: a fetched name has its reserved
characters decoded (`a>b` is stored as `a__reserved__arrow__b`), and a dot in it is quoted
in the FQN (`"c.d"`). The server silently drops an entry that matches no real column.
A sharded table has no column to fall back to, so an unmatched field resolves to None.
"""
lower = field_name.lower()
for column in getattr(table, "columns", None) or []:
if column.name.root.lower() == lower:
return column.name.root
return None if table and table.tableType == TableType.Sharded else lower
return model_str(column.fullyQualifiedName)
return None if table and table.tableType == TableType.Sharded else f"{table_fqn}.{lower}"

def _build_db_service_type_map(self):
"""Build a map of {service_name: DatabaseServiceType} filtered to configured dbServiceNames."""
Expand Down Expand Up @@ -892,16 +899,18 @@ def _get_column_lineage(self, inputs: list, outputs: list) -> dict[str, dict[str
if not input_table_fqn:
continue
input_table_entity = self._get_by_name_cached(Table, input_table_fqn, fields=["columns"])
output_column = self._match_column_name(output_table_entity, field_name)
input_column = self._match_column_name(input_table_entity, input_field.get("field", ""))
output_column = self._match_column_fqn(output_table_entity, output_table_fqn, field_name)
input_column = self._match_column_fqn(
input_table_entity, input_table_fqn, input_field.get("field", "")
)
if not output_column or not input_column:
continue
_result.append( # output table, input table, output column, input column
(
output_table_fqn,
input_table_fqn,
f"{output_table_fqn}.{output_column}",
f"{input_table_fqn}.{input_column}",
output_column,
input_column,
)
)

Expand Down
125 changes: 118 additions & 7 deletions ingestion/tests/unit/topology/pipeline/test_openlineage.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from metadata.generated.schema.api.lineage.addLineage import AddLineageRequest
from metadata.generated.schema.entity.data.pipeline import Pipeline, Task
from metadata.generated.schema.entity.data.table import Table
from metadata.generated.schema.entity.data.table import Table, TableType
from metadata.generated.schema.entity.services.connections.metadata.openMetadataConnection import (
OpenMetadataConnection,
)
Expand Down Expand Up @@ -520,13 +520,16 @@ def test_get_column_lineage_valid_inputs_outputs(self, mock_build_map, mock_get_
self.assertEqual(result, expected)

@staticmethod
def _mock_table_with_columns(*column_names):
"""Build a lightweight stand-in for a Table entity with the given real column names."""
def _mock_table_with_columns(table_fqn, fqn_segment_by_name):
"""Build a lightweight stand-in for a Table entity with the given real columns.

Keyed by the name a fetched column carries, with the spelling its FQN stores."""
table = Mock()
columns = []
for column_name in column_names:
for column_name, fqn_segment in fqn_segment_by_name.items():
column = Mock()
column.name.root = column_name
column.fullyQualifiedName = FullyQualifiedEntityName(f"{table_fqn}.{fqn_segment}")
columns.append(column)
table.columns = columns
return table
Expand All @@ -548,8 +551,12 @@ def test_get_column_lineage_matches_stored_column_case(
mock_build_map.return_value = {
"sqlserver://host:1433/hk_schema.CASE_TEST_SOURCE": "database.schema.case_test_source",
}
source_table = self._mock_table_with_columns("first_name", "last_name")
target_table = self._mock_table_with_columns("FIRST_NAME", "LAST_NAME")
source_table = self._mock_table_with_columns(
"database.schema.case_test_source", {"first_name": "first_name", "last_name": "last_name"}
)
target_table = self._mock_table_with_columns(
"database.schema.case_test_target", {"FIRST_NAME": "FIRST_NAME", "LAST_NAME": "LAST_NAME"}
)
mock_get_by_name_cached.side_effect = lambda entity_class, fqn_str, **kwargs: (
target_table if fqn_str == "database.schema.case_test_target" else source_table
)
Expand Down Expand Up @@ -608,6 +615,110 @@ def test_get_column_lineage_matches_stored_column_case(
}
self.assertEqual(result, expected)

@patch("metadata.ingestion.source.pipeline.openlineage.metadata.OpenlineageSource._get_by_name_cached")
@patch("metadata.ingestion.source.pipeline.openlineage.metadata.OpenlineageSource._get_table_fqn")
@patch("metadata.ingestion.source.pipeline.openlineage.metadata.OpenlineageSource._build_ol_name_to_fqn_map")
def test_get_column_lineage_uses_stored_fqn_of_special_column_names(
self, mock_build_map, mock_get_table_fqn, mock_get_by_name_cached
):
"""A column name with a reserved character or a dot is not its FQN segment, so
column lineage has to carry the stored FQN. An entry built as "<table>.<name>"
matches no real column and the server silently drops it."""
fqn_segment_by_name = {
"a>b": "a__reserved__arrow__b",
"c.d": '"c.d"',
"e.>f": '"e.__reserved__arrow__f"',
".>": '".__reserved__arrow__"',
}
mock_get_table_fqn.side_effect = lambda table_details, namespace=None: f"database.schema.{table_details.name}"
mock_build_map.return_value = {"postgres://host:5432/db.schema.source": "database.schema.source"}
mock_get_by_name_cached.side_effect = lambda entity_class, fqn_str, **kwargs: self._mock_table_with_columns(
fqn_str, fqn_segment_by_name
)

outputs = [
{
"name": "db.schema.target",
"namespace": "postgres://host:5432",
"facets": {
"columnLineage": {
"fields": {
column_name: {
"inputFields": [
{
"field": column_name,
"namespace": "postgres://host:5432",
"name": "db.schema.source",
}
]
}
for column_name in fqn_segment_by_name
}
}
},
}
]
result = self.open_lineage_source._get_column_lineage([], outputs)

expected = {
"database.schema.target": {
"database.schema.source": [
ColumnLineage(
toColumn=f"database.schema.target.{fqn_segment}",
fromColumns=[f"database.schema.source.{fqn_segment}"],
)
for fqn_segment in fqn_segment_by_name.values()
],
}
}
self.assertEqual(result, expected)

@patch("metadata.ingestion.source.pipeline.openlineage.metadata.OpenlineageSource._get_by_name_cached")
@patch("metadata.ingestion.source.pipeline.openlineage.metadata.OpenlineageSource._get_table_fqn")
@patch("metadata.ingestion.source.pipeline.openlineage.metadata.OpenlineageSource._build_ol_name_to_fqn_map")
def test_get_column_lineage_drops_unmatched_field_of_sharded_table(
self, mock_build_map, mock_get_table_fqn, mock_get_by_name_cached
):
"""A sharded table has no column to fall back to, so a field it does not store is
dropped instead of becoming an invented "<table>.<field>" FQN."""
sharded_source = self._mock_table_with_columns("database.schema.source", {"id": "id"})
sharded_source.tableType = TableType.Sharded
target = self._mock_table_with_columns("database.schema.target", {"id": "id", "extra": "extra"})
mock_get_table_fqn.side_effect = lambda table_details, namespace=None: f"database.schema.{table_details.name}"
mock_build_map.return_value = {"bigquery://host/db.schema.source": "database.schema.source"}
mock_get_by_name_cached.side_effect = lambda entity_class, fqn_str, **kwargs: (
target if fqn_str == "database.schema.target" else sharded_source
)

outputs = [
{
"name": "db.schema.target",
"namespace": "bigquery://host",
"facets": {
"columnLineage": {
"fields": {
column_name: {
"inputFields": [
{"field": column_name, "namespace": "bigquery://host", "name": "db.schema.source"}
]
}
for column_name in ("id", "extra")
}
}
},
}
]
result = self.open_lineage_source._get_column_lineage([], outputs)

expected = {
"database.schema.target": {
"database.schema.source": [
ColumnLineage(toColumn="database.schema.target.id", fromColumns=["database.schema.source.id"]),
],
}
}
self.assertEqual(result, expected)

@patch("metadata.ingestion.source.pipeline.openlineage.metadata.OpenlineageSource._get_by_name_cached")
@patch("metadata.ingestion.source.pipeline.openlineage.metadata.OpenlineageSource._get_table_fqn")
@patch("metadata.ingestion.source.pipeline.openlineage.metadata.OpenlineageSource._build_ol_name_to_fqn_map")
Expand Down Expand Up @@ -669,7 +780,7 @@ def test_get_column_lineage_falls_back_to_lowercase_when_table_entity_unavailabl
def test_get_column_lineage_requests_columns_field(
self, mock_build_map, mock_get_table_fqn, mock_get_by_name_cached
):
"""_match_column_name only works if the fetched Table entity actually
"""_match_column_fqn only works if the fetched Table entity actually
has its columns populated. Table lookups must explicitly request the
'columns' field rather than relying on whatever the default response
happens to include."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.stream.Collectors;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.MethodOrderer;
Expand Down Expand Up @@ -105,6 +108,17 @@ public class OpenLineageLineageResolutionIT {
new Column().withName("id").withDataType(ColumnDataType.BIGINT),
new Column().withName("name").withDataType(ColumnDataType.VARCHAR).withDataLength(255));

private static final List<Column> COLUMNS_WITH_SPECIAL_NAMES =
List.of(
new Column().withName("a__reserved__arrow__b").withDataType(ColumnDataType.INT),
new Column().withName("c.d").withDataType(ColumnDataType.INT),
new Column().withName("e.__reserved__arrow__f").withDataType(ColumnDataType.INT),
new Column()
.withName("s")
.withDataType(ColumnDataType.STRUCT)
.withDataTypeDisplay("struct<x:int>")
.withChildren(List.of(new Column().withName("x").withDataType(ColumnDataType.INT))));

private static final String EVENT_TIME = "2024-01-15T10:00:00Z";
private static final long EVENT_TIME_MS = 1705312800000L;
private static final List<Map<String, Object>> FIELDS =
Expand Down Expand Up @@ -1129,6 +1143,55 @@ void kafkaDataset_resolvesToTheTopicOfTheServiceListingItsBroker(TestNamespace n
Entity.TOPIC, topic.getFullyQualifiedName(), schemaFqn + "." + outputName));
}

@Test
@Order(30)
@ResourceLock(
value = SharedResourceLocks.OPEN_LINEAGE_SETTINGS,
mode = ResourceAccessMode.READ_WRITE)
void columnLineage_reachesStoredColumnsOfSpecialFieldNames() throws Exception {
String namespace = uniqueDatasetNamespace();
String inputName = "ol_special_in_" + uniqueSuffix();
String outputName = "ol_special_out_" + uniqueSuffix();
String inputDataset = "ecommerce_db.shopify." + inputName;
Table input =
Tables.create()
.name(inputName)
.inSchema(schemaFqn)
.withColumns(COLUMNS_WITH_SPECIAL_NAMES)
.execute();

JsonNode response =
withOpenLineageSettings(
autoCreateUnder(namespace),
() ->
send(
completeEvent("ol_special_ns", "ol_special_job_" + uniqueSuffix())
.addInput(inputDataset, namespace)
.addOutput(
outputWithFieldLineage(
namespace,
"ecommerce_db.shopify." + outputName,
inputDataset,
Map.of("a>b", "a>b", "c.d", "c.d", "e.>f", "e.>f", "x", "s.x")))));

assertEquals("success", response.get("status").asText(), response.toString());
Table output =
SdkClients.adminClient().tables().getByName(schemaFqn + "." + outputName, "columns");
assertEquals(
Set.of("a__reserved__arrow__b", "c.d", "e.__reserved__arrow__f", "x"),
output.getColumns().stream().map(Column::getName).collect(Collectors.toSet()));
String inputFqn = input.getFullyQualifiedName();
String outputFqn = output.getFullyQualifiedName();
assertEquals(
Map.of(
outputFqn + ".a__reserved__arrow__b", List.of(inputFqn + ".a__reserved__arrow__b"),
outputFqn + ".\"c.d\"", List.of(inputFqn + ".\"c.d\""),
outputFqn + ".\"e.__reserved__arrow__f\"",
List.of(inputFqn + ".\"e.__reserved__arrow__f\""),
outputFqn + ".x", List.of(inputFqn + ".s.x")),
fromColumnsByToColumn(fetchOpenLineageEdgeDetails(inputName, outputName)));
}

// ====================================================================================
// Helpers
// ====================================================================================
Expand Down Expand Up @@ -1214,6 +1277,43 @@ private static Map<String, Object> datasetWithColumns(String namespace, String n
"namespace", namespace, "name", name, "facets", Map.of("schema", Map.of("fields", FIELDS)));
}

private static Map<String, Object> outputWithFieldLineage(
String namespace,
String name,
String inputDataset,
Map<String, String> inputFieldByOutputField) {
List<Map<String, Object>> schemaFields = new ArrayList<>();
Map<String, Object> lineageFields = new HashMap<>();
inputFieldByOutputField.forEach(
(outputField, inputField) -> {
schemaFields.add(Map.of("name", outputField, "type", "int"));
lineageFields.put(
outputField,
Map.of(
"inputFields",
List.of(
Map.of("namespace", namespace, "name", inputDataset, "field", inputField))));
});
return Map.of(
"namespace",
namespace,
"name",
name,
"facets",
Map.of("schema", Map.of("fields", schemaFields)),
"outputFacets",
Map.of("columnLineage", Map.of("fields", lineageFields)));
}

private static Map<Object, Object> fromColumnsByToColumn(Map<?, ?> edgeDetails) {
return ((List<?>) edgeDetails.get("columnsLineage"))
.stream()
.map(Map.class::cast)
.collect(
Collectors.toMap(
entry -> entry.get("toColumn"), entry -> entry.get("fromColumns")));
}

private static String uniqueDatasetNamespace() {
return "postgres://ol-it-" + uniqueSuffix() + ":5432";
}
Expand Down
Loading
Loading