Repository navigation
Conversation
When code reconciliation is on, map notebook column renames onto the Spark job, including select lists built before they are applied. Native executor runs also install a missing source extra so the plugin can load. Co-authored-by: Cursor <cursoragent@cursor.com>
❌ 7 Tests Failed:
View the top 3 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
The installer is unrelated to notebook column lineage and can fail native runs that previously succeeded. Co-authored-by: Cursor <cursoragent@cursor.com>
Spark union stacks columns by position and keeps the left-hand names. unionByName still matches columns by name. Co-authored-by: Cursor <cursoragent@cursor.com>
Connector Tests ResultsAll connector tests passed for commit To skip connector tests, add the Autogenerated by the connector-tests CI pipeline. |
Spark resolves column names case-insensitively by default and keeps the dataframe's spelling. case_sensitive_columns turns that off for sessions where Name and NAME are different columns. Co-authored-by: Cursor <cursoragent@cursor.com>
A function parameter shadowed a global only when its argument resolved. load(get_name()) could otherwise follow an outer table_name. Co-authored-by: Cursor <cursoragent@cursor.com>
…fails A crash while walking the notebook source now stays on that notebook. Table edges from the Spark plan are kept, column lineage is skipped, and the report counts the failure. Co-authored-by: Cursor <cursoragent@cursor.com>
…tion' into feat/fabric-notebook-column-lineage
Code analysis skipped an if branch when its condition was a known boolean. A parameter cell holds only defaults that a pipeline can override, so a write in the skipped branch went missing and reconciliation then dropped the Spark plan's lineage for that table. Walk both branches again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
7 issues found across 9 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="metadata-ingestion/docs/sources/fabric-onelake/fabric-onelake_post.md">
<violation number="1" location="metadata-ingestion/docs/sources/fabric-onelake/fabric-onelake_post.md:380">
P3: The spelling-preservation statement is not true for `convert_urns_to_lowercase: true`: the emitter lowercases both field paths before publishing fine-grained lineage. Qualify this statement with the configured URN normalization so users do not expect `NAME` in the emitted lineage when lowercasing is enabled.</violation>
</file>
<file name="metadata-ingestion/tests/unit/fabric_onelake/test_notebook_code_lineage.py">
<violation number="1" location="metadata-ingestion/tests/unit/fabric_onelake/test_notebook_code_lineage.py:279">
P2: This assertion does not prove that `reconcile_code=False` suppresses column lineage because `_emit_dim_user` uses `_NOTEBOOK`, which has no column renames to emit. Run the disabled case with a notebook containing a known rename, such as `_COLUMN_NOTEBOOK`, and assert table lineage remains while field lineage is absent.</violation>
<violation number="2" location="metadata-ingestion/tests/unit/fabric_onelake/test_notebook_code_lineage.py:583">
P2: The integration test never exercises `convert_urns_to_lowercase` behavior: its identity normalizer and matching-case setup allow incorrect field casing to pass. Use a lowercasing normalizer with mixed-case source/output names and assert the emitted field URNs use the normalized schema-field names.</violation>
</file>
<file name="metadata-ingestion/src/datahub/ingestion/source/fabric/onelake/notebook_code_lineage.py">
<violation number="1" location="metadata-ingestion/src/datahub/ingestion/source/fabric/onelake/notebook_code_lineage.py:374">
P2: Custom agent: **Enforce Strict Maintainability Standards**
This change grows `notebook_code_lineage.py` from 465 to 1,311 lines by adding the column-lineage interpreter here. Extract the projection and column-analysis logic into a focused module to keep this file below the 1,000-line threshold.</violation>
<violation number="2" location="metadata-ingestion/src/datahub/ingestion/source/fabric/onelake/notebook_code_lineage.py:726">
P2: `select("*")` drops the raw dataframe’s passthrough columns from the analyzer, so a subsequent advertised rename such as `df.select("*").select(col("x").alias("y"))` produces no upstream field edge. Preserve wildcard passthrough state when building the projected expression.</violation>
<violation number="3" location="metadata-ingestion/src/datahub/ingestion/source/fabric/onelake/notebook_code_lineage.py:797">
P2: `_union` discards column origins when either input is not already projected. Consequently, `read_a.union(read_b).select(col("id").alias("new_id"))` emits no column lineage; preserve origins for both union branches.</violation>
</file>
<file name="metadata-ingestion/src/datahub/ingestion/source/fabric/onelake/notebook_jobs.py">
<violation number="1" location="metadata-ingestion/src/datahub/ingestion/source/fabric/onelake/notebook_jobs.py:358">
P2: Custom agent: **Enforce i18n for User-Facing Strings**
This warning title and message are shown in the ingestion report UI, but they are raw English literals. Wrap both in the translation mechanism required for user-facing text.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
| report=FabricOneLakeSourceReport(), | ||
| client=client, | ||
| known_table_urns=known, | ||
| normalize_name=lambda name: name, |
There was a problem hiding this comment.
P2: The integration test never exercises convert_urns_to_lowercase behavior: its identity normalizer and matching-case setup allow incorrect field casing to pass. Use a lowercasing normalizer with mixed-case source/output names and assert the emitted field URNs use the normalized schema-field names.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At metadata-ingestion/tests/unit/fabric_onelake/test_notebook_code_lineage.py, line 583:
<comment>The integration test never exercises `convert_urns_to_lowercase` behavior: its identity normalizer and matching-case setup allow incorrect field casing to pass. Use a lowercasing normalizer with mixed-case source/output names and assert the emitted field URNs use the normalized schema-field names.</comment>
<file context>
@@ -237,9 +264,359 @@ def test_emitter_uses_code_to_drop_unused_plan_sources() -> None:
+ report=FabricOneLakeSourceReport(),
+ client=client,
+ known_table_urns=known,
+ normalize_name=lambda name: name,
+ owners_fn=lambda _upn: None,
+ reconcile_code=True,
</file context>
| io = _emit_dim_user(reconcile_code=True, report=report) | ||
| assert report.notebook_code_lineage_extraction_failures == 1 | ||
| assert products.to_urn("PROD", None) in (io.inputDatasets or []) | ||
| assert not io.fineGrainedLineages |
There was a problem hiding this comment.
P2: This assertion does not prove that reconcile_code=False suppresses column lineage because _emit_dim_user uses _NOTEBOOK, which has no column renames to emit. Run the disabled case with a notebook containing a known rename, such as _COLUMN_NOTEBOOK, and assert table lineage remains while field lineage is absent.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At metadata-ingestion/tests/unit/fabric_onelake/test_notebook_code_lineage.py, line 279:
<comment>This assertion does not prove that `reconcile_code=False` suppresses column lineage because `_emit_dim_user` uses `_NOTEBOOK`, which has no column renames to emit. Run the disabled case with a notebook containing a known rename, such as `_COLUMN_NOTEBOOK`, and assert table lineage remains while field lineage is absent.</comment>
<file context>
@@ -237,9 +264,359 @@ def test_emitter_uses_code_to_drop_unused_plan_sources() -> None:
+ io = _emit_dim_user(reconcile_code=True, report=report)
+ assert report.notebook_code_lineage_extraction_failures == 1
+ assert products.to_urn("PROD", None) in (io.inputDatasets or [])
+ assert not io.fineGrainedLineages
+
+
</file context>
| reads = set(base.reads) | ||
| for refs in explicit.values(): | ||
| reads.update(ref.table for ref in refs) | ||
| return _Projection(reads=reads, explicit=explicit, projected=True) |
There was a problem hiding this comment.
P2: select("*") drops the raw dataframe’s passthrough columns from the analyzer, so a subsequent advertised rename such as df.select("*").select(col("x").alias("y")) produces no upstream field edge. Preserve wildcard passthrough state when building the projected expression.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At metadata-ingestion/src/datahub/ingestion/source/fabric/onelake/notebook_code_lineage.py, line 726:
<comment>`select("*")` drops the raw dataframe’s passthrough columns from the analyzer, so a subsequent advertised rename such as `df.select("*").select(col("x").alias("y"))` produces no upstream field edge. Preserve wildcard passthrough state when building the projected expression.</comment>
<file context>
@@ -406,13 +649,533 @@ def _writer_args(
+ reads = set(base.reads)
+ for refs in explicit.values():
+ reads.update(ref.table for ref in refs)
+ return _Projection(reads=reads, explicit=explicit, projected=True)
+
+ def _with_column(self, base: _Projection, call: ast.Call) -> _Projection:
</file context>
| return base | ||
| right = self._projection_of(call.args[0]) | ||
| if right is None or not base.projected or not right.projected: | ||
| return _Projection(reads=base.reads | (right.reads if right else set())) |
There was a problem hiding this comment.
P2: _union discards column origins when either input is not already projected. Consequently, read_a.union(read_b).select(col("id").alias("new_id")) emits no column lineage; preserve origins for both union branches.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At metadata-ingestion/src/datahub/ingestion/source/fabric/onelake/notebook_code_lineage.py, line 797:
<comment>`_union` discards column origins when either input is not already projected. Consequently, `read_a.union(read_b).select(col("id").alias("new_id"))` emits no column lineage; preserve origins for both union branches.</comment>
<file context>
@@ -406,13 +649,533 @@ def _writer_args(
+ return base
+ right = self._projection_of(call.args[0])
+ if right is None or not base.projected or not right.projected:
+ return _Projection(reads=base.reads | (right.reads if right else set()))
+ case_sensitive = self._case_sensitive_columns
+ left_columns = _visible_columns(base, case_sensitive=case_sensitive)
</file context>
| @@ -7,15 +7,20 @@ | |||
| The source text names those tables even when the path is built at run time | |||
There was a problem hiding this comment.
P2: Custom agent: Enforce Strict Maintainability Standards
This change grows notebook_code_lineage.py from 465 to 1,311 lines by adding the column-lineage interpreter here. Extract the projection and column-analysis logic into a focused module to keep this file below the 1,000-line threshold.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At metadata-ingestion/src/datahub/ingestion/source/fabric/onelake/notebook_code_lineage.py, line 374:
<comment>This change grows `notebook_code_lineage.py` from 465 to 1,311 lines by adding the column-lineage interpreter here. Extract the projection and column-analysis logic into a focused module to keep this file below the 1,000-line threshold.</comment>
<file context>
@@ -273,12 +364,119 @@ def _tail_has_tables(expr: ast.expr, env: Dict[str, str]) -> bool:
+
+
+@dataclass
+class _Projection:
+ """Columns of one dataframe expression.
+
</file context>
| except NotebookCodeExtractionError as exc: | ||
| self._report.report_notebook_code_lineage_failed() | ||
| self._report.warning( | ||
| title="Failed to Extract Notebook Code Lineage", |
There was a problem hiding this comment.
P2: Custom agent: Enforce i18n for User-Facing Strings
This warning title and message are shown in the ingestion report UI, but they are raw English literals. Wrap both in the translation mechanism required for user-facing text.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At metadata-ingestion/src/datahub/ingestion/source/fabric/onelake/notebook_jobs.py, line 358:
<comment>This warning title and message are shown in the ingestion report UI, but they are raw English literals. Wrap both in the translation mechanism required for user-facing text.</comment>
<file context>
@@ -298,12 +340,33 @@ def _spark_lineage(self, nb: PendingNotebook) -> Dict[SparkTableRef, List[str]]:
+ except NotebookCodeExtractionError as exc:
+ self._report.report_notebook_code_lineage_failed()
+ self._report.warning(
+ title="Failed to Extract Notebook Code Lineage",
+ message=(
+ "Could not read the notebook source for lineage. "
</file context>
| `notebook_execution.enabled` (off by default, requires `include_notebooks: true`) also models each notebook as a **pipeline**: one DataFlow per notebook (subtype "Fabric Spark Pipeline"), and under it one Spark-job DataJob (subtype "Fabric Spark Job") **per table the notebook writes**. Each job carries that output table's own upstreams, so lineage renders as `input → [job] → output` — precise table-to-table edges with the notebook transformation attributed, not one job with a cross-product of every table the notebook ever read and wrote. When one output table is itself an input to another output table's job in the same notebook, the two jobs are chained **job → job**. The lineage lives on the jobs, not the notebook dataset, so the notebook's code and its lineage (process) stay cleanly separated. It emits two things from the notebook's run history over `notebook_execution.history_days` (default 7): table-level **lineage** on the per-output jobs, and a **run history** of `DataProcessInstance`s on those jobs. | ||
|
|
||
| **Lineage.** Fabric exposes no API that lists the tables a notebook reads or writes, and the source text hides them when paths are built at run time (e.g. `spark.read.format("delta").load(f"{source}{table}")` or `DeltaTable.forPath(spark, target)`). So the connector reads the **resolved Spark physical plans** of each run instead: for every run in the window it fetches the run's SQL executions from the Spark monitoring API (`livySessions` + the Spark History Server SQL API) and extracts the `abfss://` OneLake table paths actually read and written. Attribution is **order-aware within a run**: a notebook usually reads a table in one Spark execution and writes a derived table in a later execution whose plan references a cached relation rather than the source path, so each written table is credited with the tables read earlier in the same run (the read set resets after each write). This keeps independent, sequential pipelines precise instead of collapsing a run into a cross-product, and recovers read-then-write edges that span executions. Those paths map directly to the GUID-based dataset URNs the connector emits. Set `notebook_execution.reconcile_code: true` (off by default; requires `notebook_execution.enabled`) to narrow that plan lineage with the notebook source when it is Python: each write is kept only with the tables its dataframe actually uses, and a write that exists only in a commented-out cell is dropped. The plans still supply the resolved OneLake path, so a table loaded from a run-time path stays attached to the name in the code. With the flag off, plan lineage is emitted unchanged. Because a notebook may apply only specific cells on a given run, lineage is **accumulated across all of the notebook's runs** in the window, giving a complete picture over time. Only edges to tables ingested in the same run are kept; GUID-built URNs that do not match an ingested table, and internal Spark scratch paths (shuffle, lakehouse-warmup), are dropped. | ||
| **Lineage.** Fabric exposes no API that lists the tables a notebook reads or writes, and the source text hides them when paths are built at run time (e.g. `spark.read.format("delta").load(f"{source}{table}")` or `DeltaTable.forPath(spark, target)`). So the connector reads the **resolved Spark physical plans** of each run instead: for every run in the window it fetches the run's SQL executions from the Spark monitoring API (`livySessions` + the Spark History Server SQL API) and extracts the `abfss://` OneLake table paths actually read and written. Attribution is **order-aware within a run**: a notebook usually reads a table in one Spark execution and writes a derived table in a later execution whose plan references a cached relation rather than the source path, so each written table is credited with the tables read earlier in the same run (the read set resets after each write). This keeps independent, sequential pipelines precise instead of collapsing a run into a cross-product, and recovers read-then-write edges that span executions. Those paths map directly to the GUID-based dataset URNs the connector emits. Set `notebook_execution.reconcile_code: true` (off by default; requires `notebook_execution.enabled`) to narrow that plan lineage with the notebook source when it is Python: each write is kept only with the tables its dataframe actually uses, and a write that exists only in a commented-out cell is dropped. The same pass reads column renames — `col(src).alias(dst)`, a `{source: target}` mapping dict, `alias.*` after a join, and `df["column"]` — and emits them as column-level lineage on that write's job. Column names are matched without regard to case, which is Spark's default, and the dataframe's own spelling is kept (`select("name")` still emits `NAME`). Set `notebook_execution.case_sensitive_columns: true` when the Spark session has `spark.sql.caseSensitive` enabled. The plans still supply the resolved OneLake path, so a table loaded from a run-time path stays attached to the name in the code. With the flag off, plan lineage is emitted unchanged. Because a notebook may apply only specific cells on a given run, lineage is **accumulated across all of the notebook's runs** in the window, giving a complete picture over time. Only edges to tables ingested in the same run are kept; GUID-built URNs that do not match an ingested table, and internal Spark scratch paths (shuffle, lakehouse-warmup), are dropped. |
There was a problem hiding this comment.
P3: The spelling-preservation statement is not true for convert_urns_to_lowercase: true: the emitter lowercases both field paths before publishing fine-grained lineage. Qualify this statement with the configured URN normalization so users do not expect NAME in the emitted lineage when lowercasing is enabled.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At metadata-ingestion/docs/sources/fabric-onelake/fabric-onelake_post.md, line 380:
<comment>The spelling-preservation statement is not true for `convert_urns_to_lowercase: true`: the emitter lowercases both field paths before publishing fine-grained lineage. Qualify this statement with the configured URN normalization so users do not expect `NAME` in the emitted lineage when lowercasing is enabled.</comment>
<file context>
@@ -377,7 +377,7 @@ The caller needs `Workspace.Read.All` or `Workspace.ReadWrite.All`.
`notebook_execution.enabled` (off by default, requires `include_notebooks: true`) also models each notebook as a **pipeline**: one DataFlow per notebook (subtype "Fabric Spark Pipeline"), and under it one Spark-job DataJob (subtype "Fabric Spark Job") **per table the notebook writes**. Each job carries that output table's own upstreams, so lineage renders as `input → [job] → output` — precise table-to-table edges with the notebook transformation attributed, not one job with a cross-product of every table the notebook ever read and wrote. When one output table is itself an input to another output table's job in the same notebook, the two jobs are chained **job → job**. The lineage lives on the jobs, not the notebook dataset, so the notebook's code and its lineage (process) stay cleanly separated. It emits two things from the notebook's run history over `notebook_execution.history_days` (default 7): table-level **lineage** on the per-output jobs, and a **run history** of `DataProcessInstance`s on those jobs.
-**Lineage.** Fabric exposes no API that lists the tables a notebook reads or writes, and the source text hides them when paths are built at run time (e.g. `spark.read.format("delta").load(f"{source}{table}")` or `DeltaTable.forPath(spark, target)`). So the connector reads the **resolved Spark physical plans** of each run instead: for every run in the window it fetches the run's SQL executions from the Spark monitoring API (`livySessions` + the Spark History Server SQL API) and extracts the `abfss://` OneLake table paths actually read and written. Attribution is **order-aware within a run**: a notebook usually reads a table in one Spark execution and writes a derived table in a later execution whose plan references a cached relation rather than the source path, so each written table is credited with the tables read earlier in the same run (the read set resets after each write). This keeps independent, sequential pipelines precise instead of collapsing a run into a cross-product, and recovers read-then-write edges that span executions. Those paths map directly to the GUID-based dataset URNs the connector emits. Set `notebook_execution.reconcile_code: true` (off by default; requires `notebook_execution.enabled`) to narrow that plan lineage with the notebook source when it is Python: each write is kept only with the tables its dataframe actually uses, and a write that exists only in a commented-out cell is dropped. The plans still supply the resolved OneLake path, so a table loaded from a run-time path stays attached to the name in the code. With the flag off, plan lineage is emitted unchanged. Because a notebook may apply only specific cells on a given run, lineage is **accumulated across all of the notebook's runs** in the window, giving a complete picture over time. Only edges to tables ingested in the same run are kept; GUID-built URNs that do not match an ingested table, and internal Spark scratch paths (shuffle, lakehouse-warmup), are dropped.
+**Lineage.** Fabric exposes no API that lists the tables a notebook reads or writes, and the source text hides them when paths are built at run time (e.g. `spark.read.format("delta").load(f"{source}{table}")` or `DeltaTable.forPath(spark, target)`). So the connector reads the **resolved Spark physical plans** of each run instead: for every run in the window it fetches the run's SQL executions from the Spark monitoring API (`livySessions` + the Spark History Server SQL API) and extracts the `abfss://` OneLake table paths actually read and written. Attribution is **order-aware within a run**: a notebook usually reads a table in one Spark execution and writes a derived table in a later execution whose plan references a cached relation rather than the source path, so each written table is credited with the tables read earlier in the same run (the read set resets after each write). This keeps independent, sequential pipelines precise instead of collapsing a run into a cross-product, and recovers read-then-write edges that span executions. Those paths map directly to the GUID-based dataset URNs the connector emits. Set `notebook_execution.reconcile_code: true` (off by default; requires `notebook_execution.enabled`) to narrow that plan lineage with the notebook source when it is Python: each write is kept only with the tables its dataframe actually uses, and a write that exists only in a commented-out cell is dropped. The same pass reads column renames — `col(src).alias(dst)`, a `{source: target}` mapping dict, `alias.*` after a join, and `df["column"]` — and emits them as column-level lineage on that write's job. Column names are matched without regard to case, which is Spark's default, and the dataframe's own spelling is kept (`select("name")` still emits `NAME`). Set `notebook_execution.case_sensitive_columns: true` when the Spark session has `spark.sql.caseSensitive` enabled. The plans still supply the resolved OneLake path, so a table loaded from a run-time path stays attached to the name in the code. With the flag off, plan lineage is emitted unchanged. Because a notebook may apply only specific cells on a given run, lineage is **accumulated across all of the notebook's runs** in the window, giving a complete picture over time. Only edges to tables ingested in the same run are kept; GUID-built URNs that do not match an ingested table, and internal Spark scratch paths (shuffle, lakehouse-warmup), are dropped.
**Run history.** A Fabric run executes the whole notebook (the Job Scheduler reports one status per run, not per table), so for each run in the window the connector emits a `DataProcessInstance` on each of the notebook's per-output jobs — the whole-notebook run is recorded against every job it contains, falling back to the DataFlow only when a run resolved no per-table lineage — read from the Job Scheduler `GET /workspaces/{id}/items/{itemId}/jobs/instances` API. Each instance records start/end time and the run result (success / failure / skipped).
</file context>
| **Lineage.** Fabric exposes no API that lists the tables a notebook reads or writes, and the source text hides them when paths are built at run time (e.g. `spark.read.format("delta").load(f"{source}{table}")` or `DeltaTable.forPath(spark, target)`). So the connector reads the **resolved Spark physical plans** of each run instead: for every run in the window it fetches the run's SQL executions from the Spark monitoring API (`livySessions` + the Spark History Server SQL API) and extracts the `abfss://` OneLake table paths actually read and written. Attribution is **order-aware within a run**: a notebook usually reads a table in one Spark execution and writes a derived table in a later execution whose plan references a cached relation rather than the source path, so each written table is credited with the tables read earlier in the same run (the read set resets after each write). This keeps independent, sequential pipelines precise instead of collapsing a run into a cross-product, and recovers read-then-write edges that span executions. Those paths map directly to the GUID-based dataset URNs the connector emits. Set `notebook_execution.reconcile_code: true` (off by default; requires `notebook_execution.enabled`) to narrow that plan lineage with the notebook source when it is Python: each write is kept only with the tables its dataframe actually uses, and a write that exists only in a commented-out cell is dropped. The same pass reads column renames — `col(src).alias(dst)`, a `{source: target}` mapping dict, `alias.*` after a join, and `df["column"]` — and emits them as column-level lineage on that write's job. Column names are matched without regard to case, which is Spark's default, and the dataframe's own spelling is kept (`select("name")` still emits `NAME`). Set `notebook_execution.case_sensitive_columns: true` when the Spark session has `spark.sql.caseSensitive` enabled. The plans still supply the resolved OneLake path, so a table loaded from a run-time path stays attached to the name in the code. With the flag off, plan lineage is emitted unchanged. Because a notebook may apply only specific cells on a given run, lineage is **accumulated across all of the notebook's runs** in the window, giving a complete picture over time. Only edges to tables ingested in the same run are kept; GUID-built URNs that do not match an ingested table, and internal Spark scratch paths (shuffle, lakehouse-warmup), are dropped. | |
| **Lineage.** Fabric exposes no API that lists the tables a notebook reads or writes, and the source text hides them when paths are built at run time (e.g. `spark.read.format("delta").load(f"{source}{table}")` or `DeltaTable.forPath(spark, target)`). So the connector reads the **resolved Spark physical plans** of each run instead: for every run in the window it fetches the run's SQL executions from the Spark monitoring API (`livySessions` + the Spark History Server SQL API) and extracts the `abfss://` OneLake table paths actually read and written. Attribution is **order-aware within a run**: a notebook usually reads a table in one Spark execution and writes a derived table in a later execution whose plan references a cached relation rather than the source path, so each written table is credited with the tables read earlier in the same run (the read set resets after each write). This keeps independent, sequential pipelines precise instead of collapsing a run into a cross-product, and recovers read-then-write edges that span executions. Those paths map directly to the GUID-based dataset URNs the connector emits. Set `notebook_execution.reconcile_code: true` (off by default; requires `notebook_execution.enabled`) to narrow that plan lineage with the notebook source when it is Python: each write is kept only with the tables its dataframe actually uses, and a write that exists only in a commented-out cell is dropped. The same pass reads column renames — `col(src).alias(dst)`, a `{source: target}` mapping dict, `alias.*` after a join, and `df["column"]` — and emits them as column-level lineage on that write's job. Column matching ignores case by default, and the dataframe's spelling is preserved before the connector applies its configured URN normalization (`select("name")` resolves to `NAME`; with `convert_urns_to_lowercase: true`, the emitted field path is lowercased). Set `notebook_execution.case_sensitive_columns: true` when the Spark session has `spark.sql.caseSensitive` enabled. The plans still supply the resolved OneLake path, so a table loaded from a run-time path stays attached to the name in the code. With the flag off, plan lineage is emitted unchanged. Because a notebook may apply only specific cells on a given run, lineage is **accumulated across all of the notebook's runs** in the window, giving a complete picture over time. Only edges to tables ingested in the same run are kept; GUID-built URNs that do not match an ingested table, and internal Spark scratch paths (shuffle, lakehouse-warmup), are dropped. |
Notebook code lineage only resolved writes made directly in the cell, so a loop that calls a helper per config entry left the previous write's table as an input of the next one. Unroll loops over lists of table configs, resolve config fields in paths, and follow helpers that save without returning a dataframe. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
2 issues found across 2 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="metadata-ingestion/src/datahub/ingestion/source/fabric/onelake/notebook_code_lineage.py">
<violation number="1" location="metadata-ingestion/src/datahub/ingestion/source/fabric/onelake/notebook_code_lineage.py:520">
P2: `_record_lists` leaks through function-parameter shadowing, so an unresolved helper argument can reuse an outer loop’s configs and emit false lineage. Clear `_record_lists[name]` in `_hide_binding`.</violation>
<violation number="2" location="metadata-ingestion/src/datahub/ingestion/source/fabric/onelake/notebook_code_lineage.py:1008">
P2: Passing the loop config object itself to a helper loses the new record binding at the function boundary. `config["table_name"]` then remains unresolved, so the helper write is omitted and Spark’s carried-forward inputs are not reconciled; preserve record bindings in `_capture`/`_install` (or expand the fields at the call site).</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
| flag = self._eval_bool(expr) | ||
| if flag is not None: | ||
| return ("bool", flag) | ||
| text = _eval_tail(expr, self._strings, self._records) |
There was a problem hiding this comment.
P2: Passing the loop config object itself to a helper loses the new record binding at the function boundary. config["table_name"] then remains unresolved, so the helper write is omitted and Spark’s carried-forward inputs are not reconciled; preserve record bindings in _capture/_install (or expand the fields at the call site).
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At metadata-ingestion/src/datahub/ingestion/source/fabric/onelake/notebook_code_lineage.py, line 1008:
<comment>Passing the loop config object itself to a helper loses the new record binding at the function boundary. `config["table_name"]` then remains unresolved, so the helper write is omitted and Spark’s carried-forward inputs are not reconciled; preserve record bindings in `_capture`/`_install` (or expand the fields at the call site).</comment>
<file context>
@@ -904,7 +1005,7 @@ def _capture(self, expr: ast.expr) -> Tuple[str, object]:
if flag is not None:
return ("bool", flag)
- text = _eval_tail(expr, self._strings)
+ text = _eval_tail(expr, self._strings, self._records)
if text is not None:
return ("str", text)
</file context>
| self._return_projection: Optional[_Projection] = None | ||
| # Loop variable -> the config dict for the iteration being applied. | ||
| self._records: Dict[str, Dict[str, str]] = {} | ||
| self._record_lists: Dict[str, List[Dict[str, str]]] = {} |
There was a problem hiding this comment.
P2: _record_lists leaks through function-parameter shadowing, so an unresolved helper argument can reuse an outer loop’s configs and emit false lineage. Clear _record_lists[name] in _hide_binding.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At metadata-ingestion/src/datahub/ingestion/source/fabric/onelake/notebook_code_lineage.py, line 520:
<comment>`_record_lists` leaks through function-parameter shadowing, so an unresolved helper argument can reuse an outer loop’s configs and emit false lineage. Clear `_record_lists[name]` in `_hide_binding`.</comment>
<file context>
@@ -477,6 +515,9 @@ def __init__(self, *, case_sensitive_columns: bool = False) -> None:
self._return_projection: Optional[_Projection] = None
+ # Loop variable -> the config dict for the iteration being applied.
+ self._records: Dict[str, Dict[str, str]] = {}
+ self._record_lists: Dict[str, List[Dict[str, str]]] = {}
# function name -> (dataframe param, path param, dataframe index, path index)
self._writers: Dict[str, Tuple[str, str, int, int]] = {}
</file context>
When include_notebook_source is enabled and notebook_execution is on, each notebook job carries the masked notebook source as dataTransformLogic so it shows in the job's Logic section. The language is always SQL because the GraphQL QueryLanguage enum has no UNKNOWN value and emitting it fails lineage queries. Co-authored-by: Cursor <cursoragent@cursor.com>
…cells - Drop Spark executions whose cell code is not in the notebook, so shared sessions no longer leak one notebook's reads into another's writes - Resolve table paths built by helper functions in notebook code - Emit same-name column lineage for notebooks that copy a table unchanged - Add notebook_spark_executions_skipped report counter Co-authored-by: Cursor <cursoragent@cursor.com>
…rmat uv 0.13.10 writes environment markers in a simplified form, so the checkLockFile comparison failed on hf-xet, ibm-db, ibm-db-sa and win-precise-time. Versions are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
notebook_execution.reconcile_codeis on, Python notebook column renames are emitted as column-level lineage on the Spark job that writes each table.col(src).alias(dst),{source: target}mapping dicts,alias.*,df["column"], and select lists built before they are applied (select(*select_exprs)). Literal columns are omitted. An edge is kept only when both tables were resolved by the Spark plan and ingested in the same run.person_PersonPartymatchesperson_personpartywhenconvert_urns_to_lowercaseis on.Column lineage is stored on the job's
dataJobInputOutput.fineGrainedLineages, not on the datasetupstreamLineageaspect.Test plan
pytest metadata-ingestion/tests/unit/fabric_onelake/test_notebook_code_lineage.py metadata-ingestion/tests/unit/fabric_onelake/test_notebook_jobs.pyinclude_notebooks: true,notebook_execution.enabled: true, andreconcile_code: trueinputOutput.fineGrainedLineageslinks each output field to its upstream fieldreconcile_code: falsestill emits table lineage and no column edgesconvert_urns_to_lowercase: true, confirm field paths match the lowercased schema fields