classifyre-cli 0.9.6__py3-none-any.whl → 0.9.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {classifyre_cli-0.9.6.dist-info → classifyre_cli-0.9.7.dist-info}/METADATA +1 -1
- {classifyre_cli-0.9.6.dist-info → classifyre_cli-0.9.7.dist-info}/RECORD +14 -14
- src/sources/dremio/source.py +3 -2
- src/sources/mssql/source.py +61 -28
- src/sources/mysql/source.py +44 -11
- src/sources/odbc/source.py +22 -11
- src/sources/oracle/source.py +54 -28
- src/sources/postgresql/source.py +53 -9
- src/sources/snowflake/source.py +34 -39
- src/sources/tabular_base.py +108 -10
- src/sources/tabular_utils.py +11 -0
- src/utils/file_metadata.py +21 -3
- {classifyre_cli-0.9.6.dist-info → classifyre_cli-0.9.7.dist-info}/WHEEL +0 -0
- {classifyre_cli-0.9.6.dist-info → classifyre_cli-0.9.7.dist-info}/entry_points.txt +0 -0
|
@@ -125,8 +125,8 @@ src/sources/inline_paging.py,sha256=bv-SIDLrRFdROa6yEf6bq2545kopbsUXUFuhJGd_wJc,
|
|
|
125
125
|
src/sources/recipe_normalizer.py,sha256=tgZj_jYnT-67rlDiEF9AsQUS7EcxCvDUUsk2LO8RrRE,6207
|
|
126
126
|
src/sources/s3_client.py,sha256=_v-JlCihlltbbI6dA-OeW4rAvglCKVmj4r8Ib1ViU_A,2368
|
|
127
127
|
src/sources/search_engine_base.py,sha256=meQbpV2Si2T8tBe2DS7VvvpZZ7KVCn6cNqCYCwdwLUE,18308
|
|
128
|
-
src/sources/tabular_base.py,sha256=
|
|
129
|
-
src/sources/tabular_utils.py,sha256=
|
|
128
|
+
src/sources/tabular_base.py,sha256=TlzQ-kXPg9aOqYEefgnREHkZ3pGaniu3Oz-yeFoZPE8,62238
|
|
129
|
+
src/sources/tabular_utils.py,sha256=zHgdQlw10CmIRAUc98VR3TahIf2N51XUWCf_uezRMeE,8539
|
|
130
130
|
src/sources/athena/__init__.py,sha256=zOxrzPsc1cz7m2JZPh1kCpkipIFgSGSGrFbrtrADgdM,61
|
|
131
131
|
src/sources/athena/source.py,sha256=f1BqZVxFvqXDZ_hBRfo9SAh7edjfvmg_C4IBBlT8_CI,10986
|
|
132
132
|
src/sources/azure_blob_storage/__init__.py,sha256=EAsp7N2Vpzc_S-ownm3-ieXVWZSIVXPPNiSlDGCyenI,81
|
|
@@ -143,7 +143,7 @@ src/sources/databricks/__init__.py,sha256=yZZxIF-qhpt_W_zksFQoJGBqaIA40vQCyYLFSk
|
|
|
143
143
|
src/sources/databricks/source.py,sha256=9yXuXlkxrk8W4VZLGG6jdWcLdnkiHd5-FpF4wLKvRyg,53030
|
|
144
144
|
src/sources/dremio/__init__.py,sha256=qIDDLY7WK1lMIU2hGbLxRE_uPLN8-Ksb0FHuwmBZTlw,61
|
|
145
145
|
src/sources/dremio/client.py,sha256=iExOStiAUnxBGDCVi3AMxpDPe7-e0jRRZa7gkKmp-Lo,19146
|
|
146
|
-
src/sources/dremio/source.py,sha256=
|
|
146
|
+
src/sources/dremio/source.py,sha256=WCSpDBx1RWVd4nlmATC_0T7Rq4LdHJR2qqX0ljlTApE,32376
|
|
147
147
|
src/sources/dropbox/__init__.py,sha256=jJRijaY0t62AFNBwi9M3Eub7D-KEsWd0ltJpyQe8cPY,63
|
|
148
148
|
src/sources/dropbox/auth.py,sha256=qVx-8NRbAVH3BxviQ9H26q08WmvRWuq2mgkPDhtmZ_M,8085
|
|
149
149
|
src/sources/dropbox/source.py,sha256=Tgz2h1C6ElrccCoCNoG8OU4_RAM1IbNowttr5syOHuE,33052
|
|
@@ -179,9 +179,9 @@ src/sources/microsoft_365/source.py,sha256=cQfuldXqe9icEN0m06WDUtXzYD9EssFZUUiyh
|
|
|
179
179
|
src/sources/mongodb/__init__.py,sha256=IcSTuVMB3JOXAjYpwFcFvRuc2a7m6xgZ1VG5AfM4eJU,63
|
|
180
180
|
src/sources/mongodb/source.py,sha256=BBHPKqNb29SHvjiFPpaFPaFojx_oc5H5vsCZD6R2cQk,26068
|
|
181
181
|
src/sources/mssql/__init__.py,sha256=Y2WuywS2C8lIsiwbikGKQQ9S3Pbp4X5cHyXiDNz8JPI,59
|
|
182
|
-
src/sources/mssql/source.py,sha256=
|
|
182
|
+
src/sources/mssql/source.py,sha256=r_IJFPItDm_IhBM1Y_o_DJYM3TvWwV9A9u_KvDFlak8,28323
|
|
183
183
|
src/sources/mysql/__init__.py,sha256=V0hGtrFJLjGpc3iXzt2k8fH0WzAnyuuDG_2FogcwJBE,59
|
|
184
|
-
src/sources/mysql/source.py,sha256=
|
|
184
|
+
src/sources/mysql/source.py,sha256=ZEqKABrw6cYjBUrf_e7KrqxQKaK9kJZImzgPo9b8rH4,17912
|
|
185
185
|
src/sources/neo4j/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
186
186
|
src/sources/neo4j/source.py,sha256=NcGbW_aj2A3rjAW_InOD6QwqFctP1StWYw9qKi7ChGA,26968
|
|
187
187
|
src/sources/notion/__init__.py,sha256=FIOPK4itaRGa449jBpvRQd_qlJPPRsjIhSoUBUnMem0,61
|
|
@@ -189,13 +189,13 @@ src/sources/notion/client.py,sha256=Wu-JSXI9KnDgfRUzzP8Vm-_TbhY2FDHdEID_Z-EcMd8,
|
|
|
189
189
|
src/sources/notion/source.py,sha256=vaqWGVDtdlBAbuhI2vBf3zRQIG56-9C7_yBuflM1DS8,38218
|
|
190
190
|
src/sources/object_storage/base.py,sha256=Y_WA8ZsUqwXO7hhcF0Po2zsyWSuk0kJ5KC9w6LzqRH8,71612
|
|
191
191
|
src/sources/odbc/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
192
|
-
src/sources/odbc/source.py,sha256=
|
|
192
|
+
src/sources/odbc/source.py,sha256=7S1yADOS__u7JzinD78NurZH66UdMtdTkmApX7nutrk,30207
|
|
193
193
|
src/sources/opensearch/__init__.py,sha256=Z6wjAWy_pQlCCkWzJyh3DdR091Evqkmks2wTqVo1eCc,69
|
|
194
194
|
src/sources/opensearch/source.py,sha256=i9NQE7XP5zYXeWdW6od3gKTQGD76H_z3VApN0qNjbjc,1158
|
|
195
195
|
src/sources/oracle/__init__.py,sha256=saYMyNR-UGniyVgLYS8u1PwPO5WQ_mEuq8WqYrl30rU,61
|
|
196
|
-
src/sources/oracle/source.py,sha256
|
|
196
|
+
src/sources/oracle/source.py,sha256=-C_PteXxiq8CHuWcJua6zHDgiQUnoPoDcUUROm_JQD8,29126
|
|
197
197
|
src/sources/postgresql/__init__.py,sha256=lHNYhsvG9fdnrr4b2Ya1mSdDdDRImmWOUEpQSXSu9dE,69
|
|
198
|
-
src/sources/postgresql/source.py,sha256=
|
|
198
|
+
src/sources/postgresql/source.py,sha256=ukti25TWXsPRxeIAZeDSjk4zyLxPtu62v7fWeU5rSwo,16278
|
|
199
199
|
src/sources/powerbi/__init__.py,sha256=oDQQoV94r8xHqNjlCeFOULA-8Wyzr6tNCGznFEHEHF0,63
|
|
200
200
|
src/sources/powerbi/source.py,sha256=2KdGzOXe2Htatflza7wNoBYR0BucH0WB0J_uycgdMWY,35169
|
|
201
201
|
src/sources/reddit/__init__.py,sha256=ilcyMJOgzMkX7GYWDioTyBqvPkMr5iBguYTb6bzUquY,61
|
|
@@ -212,7 +212,7 @@ src/sources/servicedesk/source.py,sha256=Pt_WA_YvEBl_b0jXUhaiiDuimbazA5cdQxm1kKr
|
|
|
212
212
|
src/sources/slack/__init__.py,sha256=k-3Or9wLb48KXjDXqQzrUc7VenJtb5SucyoFhGKdiow,59
|
|
213
213
|
src/sources/slack/source.py,sha256=TTN3C23djjQTYYi3z3Le_4Ye23TAuXgi38J8UmNK1dU,40588
|
|
214
214
|
src/sources/snowflake/__init__.py,sha256=NGXckaCGaD6eHCIlHs4aErhOxCc3BbNDPvdbV_xx24g,67
|
|
215
|
-
src/sources/snowflake/source.py,sha256=
|
|
215
|
+
src/sources/snowflake/source.py,sha256=a4A_lfi2ADz4YBWqvSCfmQUWL0UsFtj3nTxJDycp_TY,32991
|
|
216
216
|
src/sources/tableau/__init__.py,sha256=Di1Bh9s9SYrUYg4xZhhAhl5HfoTt0B6WQB5SxVrQhbY,63
|
|
217
217
|
src/sources/tableau/source.py,sha256=zTOCwobJgE4E-3RBV-twKL_Nxrm60mBvwdI32dIDwgs,37139
|
|
218
218
|
src/sources/trino/__init__.py,sha256=GFQDJ82MG8VACM8e2XzHIj-MyXBAwoKSXPdOJx8-NW4,59
|
|
@@ -229,7 +229,7 @@ src/utils/document_columns.py,sha256=fm6lu-UQM8zr-tKsVhsoxMNarvaJDNx1vVnz1NYtfVM
|
|
|
229
229
|
src/utils/duckdb_engine.py,sha256=RunGvCvfiKJA45YP7aW9XRBvGCHuZxrTXh3U8a9e05Q,11172
|
|
230
230
|
src/utils/embedded_files.py,sha256=zXAJr_OAsZD4iI6MUuAuD1x7awvh7n91Ez4pUSmhxnY,25296
|
|
231
231
|
src/utils/external_video.py,sha256=xnp071RpBFX0xhsnUXxRlY3IKg7DsE4sH0w6B4c_e_k,11695
|
|
232
|
-
src/utils/file_metadata.py,sha256=
|
|
232
|
+
src/utils/file_metadata.py,sha256=hC4Xl_w__McWi2QKKWAcEEQcdWo1LLOHrgTUMp-fyOE,10533
|
|
233
233
|
src/utils/file_parser.py,sha256=oiWZ8SEqz1HvnUl0qoQnfE8qW6CVIN9aSsftN2hErY8,102732
|
|
234
234
|
src/utils/file_to_images.py,sha256=rU9uATckg8JDxHZLobjOJdwkrC2CZxegMS4hv76txTI,4782
|
|
235
235
|
src/utils/hashing.py,sha256=T0GL1FWtG32QJID5RN3X-TzHHkolnNK6EfADvX6sdlE,2490
|
|
@@ -254,7 +254,7 @@ src/utils/urn.py,sha256=gqSl0H0FBZZ3cJbpDWX1ewGcyZz2MrNVTIQdoFrQMM0,12622
|
|
|
254
254
|
src/utils/uv_sync.py,sha256=L4ETHuidlgFLbz4e3Vv0Ornh7w8xrkYeFQQGw0hJe8E,10214
|
|
255
255
|
src/utils/validation.py,sha256=5NHsgyZwyEONRu9_ADxUAQNPvbMnpMhKL-hpgFEVMm8,3837
|
|
256
256
|
src/utils/video_processing.py,sha256=B6Br9ybFEa_ioglJGo0P9Fmp1e2B95C24joAktwrjww,11293
|
|
257
|
-
classifyre_cli-0.9.
|
|
258
|
-
classifyre_cli-0.9.
|
|
259
|
-
classifyre_cli-0.9.
|
|
260
|
-
classifyre_cli-0.9.
|
|
257
|
+
classifyre_cli-0.9.7.dist-info/METADATA,sha256=LzjAnfU_ZQkFH2dXqaV25j_L1oxmNNIglfu20DJO17A,5841
|
|
258
|
+
classifyre_cli-0.9.7.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
259
|
+
classifyre_cli-0.9.7.dist-info/entry_points.txt,sha256=edxllyMiIFfajgCZ3dTRACXYGC34ZX1AYTezMSR5E_8,45
|
|
260
|
+
classifyre_cli-0.9.7.dist-info/RECORD,,
|
src/sources/dremio/source.py
CHANGED
|
@@ -22,7 +22,7 @@ from ...models.generated_single_asset_scan_results import AssetType as OutputAss
|
|
|
22
22
|
from ...utils.sql_lineage import table_paths_from_sql
|
|
23
23
|
from ...utils.urn import Urn, UrnError
|
|
24
24
|
from ..tabular_base import BaseTabularSource
|
|
25
|
-
from ..tabular_utils import TableRef, ViewLineage, table_format_from
|
|
25
|
+
from ..tabular_utils import ForeignKeyDetail, TableRef, ViewLineage, table_format_from
|
|
26
26
|
from .client import (
|
|
27
27
|
JOB_ROW_WINDOW,
|
|
28
28
|
DremioApiError,
|
|
@@ -624,8 +624,9 @@ class DremioSource(BaseTabularSource):
|
|
|
624
624
|
tables: list[TableRef],
|
|
625
625
|
table_hash_by_key: dict[tuple[str, ...], str],
|
|
626
626
|
fk_links: dict[tuple[str, ...], set[tuple[str, ...]]],
|
|
627
|
+
fk_details: list[ForeignKeyDetail] | None = None,
|
|
627
628
|
) -> None:
|
|
628
|
-
super()._emit_relationship_edges(tables, table_hash_by_key, fk_links)
|
|
629
|
+
super()._emit_relationship_edges(tables, table_hash_by_key, fk_links, fk_details=fk_details)
|
|
629
630
|
if not self._extraction_options().include_source_lineage:
|
|
630
631
|
return
|
|
631
632
|
for table_ref in tables:
|
src/sources/mssql/source.py
CHANGED
|
@@ -16,7 +16,7 @@ from ...models.generated_single_asset_scan_results import (
|
|
|
16
16
|
)
|
|
17
17
|
from ..dependencies import require_module
|
|
18
18
|
from ..tabular_base import BaseTabularSource
|
|
19
|
-
from ..tabular_utils import TableRef, ViewLineage
|
|
19
|
+
from ..tabular_utils import ForeignKeyDetail, TableRef, ViewLineage
|
|
20
20
|
|
|
21
21
|
logger = logging.getLogger(__name__)
|
|
22
22
|
|
|
@@ -514,28 +514,19 @@ class MSSQLSource(BaseTabularSource):
|
|
|
514
514
|
)
|
|
515
515
|
return results
|
|
516
516
|
|
|
517
|
-
def
|
|
517
|
+
def _collect_foreign_key_details(
|
|
518
518
|
self,
|
|
519
519
|
tables: list[TableRef],
|
|
520
|
-
) ->
|
|
521
|
-
# Only declared constraints: a view's dependencies are lineage, and
|
|
522
|
-
# _collect_view_lineage already emits them as FLOW.
|
|
520
|
+
) -> list[ForeignKeyDetail]:
|
|
523
521
|
if not self._include_table_lineage_enabled():
|
|
524
|
-
return
|
|
525
|
-
return self._collect_fk_links(tables)
|
|
526
|
-
|
|
527
|
-
def _collect_fk_links(
|
|
528
|
-
self,
|
|
529
|
-
tables: list[TableRef],
|
|
530
|
-
) -> dict[tuple[str, ...], set[tuple[str, ...]]]:
|
|
522
|
+
return []
|
|
531
523
|
table_keys = {t.table_key for t in tables if t.object_type == "TABLE"}
|
|
532
524
|
by_database: dict[str, set[tuple[str, ...]]] = {}
|
|
533
525
|
for t in tables:
|
|
534
|
-
if t.object_type
|
|
535
|
-
|
|
536
|
-
by_database.setdefault(t.database, set()).add(t.table_key)
|
|
526
|
+
if t.object_type == "TABLE":
|
|
527
|
+
by_database.setdefault(t.database, set()).add(t.table_key)
|
|
537
528
|
|
|
538
|
-
|
|
529
|
+
details: list[ForeignKeyDetail] = []
|
|
539
530
|
for database, scoped_keys in by_database.items():
|
|
540
531
|
try:
|
|
541
532
|
conn = self._get_cached_connection(database)
|
|
@@ -543,27 +534,69 @@ class MSSQLSource(BaseTabularSource):
|
|
|
543
534
|
cursor.execute(
|
|
544
535
|
"""
|
|
545
536
|
SELECT
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
537
|
+
fk.name AS constraint_name,
|
|
538
|
+
OBJECT_SCHEMA_NAME(fkc.parent_object_id) AS source_schema,
|
|
539
|
+
OBJECT_NAME(fkc.parent_object_id) AS source_table,
|
|
540
|
+
pc.name AS source_column,
|
|
541
|
+
OBJECT_SCHEMA_NAME(fkc.referenced_object_id) AS target_schema,
|
|
542
|
+
OBJECT_NAME(fkc.referenced_object_id) AS target_table,
|
|
543
|
+
rc.name AS target_column
|
|
550
544
|
FROM sys.foreign_keys fk
|
|
545
|
+
JOIN sys.foreign_key_columns fkc ON fkc.constraint_object_id = fk.object_id
|
|
546
|
+
JOIN sys.columns pc
|
|
547
|
+
ON pc.object_id = fkc.parent_object_id
|
|
548
|
+
AND pc.column_id = fkc.parent_column_id
|
|
549
|
+
JOIN sys.columns rc
|
|
550
|
+
ON rc.object_id = fkc.referenced_object_id
|
|
551
|
+
AND rc.column_id = fkc.referenced_column_id
|
|
552
|
+
ORDER BY fk.name, fkc.constraint_column_id
|
|
551
553
|
"""
|
|
552
554
|
)
|
|
553
555
|
for row in cursor.fetchall():
|
|
554
|
-
if not isinstance(row, tuple) or len(row) <
|
|
556
|
+
if not isinstance(row, tuple) or len(row) < 7:
|
|
555
557
|
continue
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
558
|
+
(
|
|
559
|
+
constraint_name,
|
|
560
|
+
source_schema,
|
|
561
|
+
source_table,
|
|
562
|
+
source_col,
|
|
563
|
+
target_schema,
|
|
564
|
+
target_table,
|
|
565
|
+
target_col,
|
|
566
|
+
) = row[:7]
|
|
567
|
+
if not all(
|
|
568
|
+
isinstance(v, str)
|
|
569
|
+
for v in (
|
|
570
|
+
source_schema,
|
|
571
|
+
source_table,
|
|
572
|
+
source_col,
|
|
573
|
+
target_schema,
|
|
574
|
+
target_table,
|
|
575
|
+
target_col,
|
|
576
|
+
)
|
|
577
|
+
):
|
|
560
578
|
continue
|
|
561
|
-
|
|
579
|
+
source_key = (database, source_schema, source_table)
|
|
580
|
+
target_key = (database, target_schema, target_table)
|
|
581
|
+
if source_key in scoped_keys and target_key in table_keys:
|
|
582
|
+
details.append(
|
|
583
|
+
ForeignKeyDetail(
|
|
584
|
+
source_key=source_key,
|
|
585
|
+
target_key=target_key,
|
|
586
|
+
source_column=source_col,
|
|
587
|
+
target_column=target_col,
|
|
588
|
+
constraint_name=constraint_name
|
|
589
|
+
if isinstance(constraint_name, str) and constraint_name
|
|
590
|
+
else None,
|
|
591
|
+
)
|
|
592
|
+
)
|
|
562
593
|
except Exception as exc:
|
|
563
594
|
logger.warning(
|
|
564
|
-
"Could not resolve foreign key
|
|
595
|
+
"Could not resolve MSSQL foreign key details for database %s: %s",
|
|
596
|
+
database,
|
|
597
|
+
exc,
|
|
565
598
|
)
|
|
566
|
-
return
|
|
599
|
+
return details
|
|
567
600
|
|
|
568
601
|
# ── Unsupported extraction feature warnings ──────────────────────────
|
|
569
602
|
|
src/sources/mysql/source.py
CHANGED
|
@@ -14,7 +14,7 @@ from ...models.generated_input import (
|
|
|
14
14
|
from ...utils.sql_lineage import upstream_tables_from_sql
|
|
15
15
|
from ..dependencies import require_module
|
|
16
16
|
from ..tabular_base import BaseTabularSource
|
|
17
|
-
from ..tabular_utils import TableRef, ViewLineage
|
|
17
|
+
from ..tabular_utils import ForeignKeyDetail, TableRef, ViewLineage
|
|
18
18
|
|
|
19
19
|
logger = logging.getLogger(__name__)
|
|
20
20
|
|
|
@@ -330,16 +330,16 @@ class MySQLSource(BaseTabularSource):
|
|
|
330
330
|
results.append(ViewLineage(view_key, tuple(upstreams), definition))
|
|
331
331
|
return results
|
|
332
332
|
|
|
333
|
-
def
|
|
333
|
+
def _collect_foreign_key_details(
|
|
334
334
|
self,
|
|
335
335
|
tables: list[TableRef],
|
|
336
|
-
) ->
|
|
336
|
+
) -> list[ForeignKeyDetail]:
|
|
337
337
|
all_keys = {t.table_key for t in tables}
|
|
338
338
|
by_database: dict[str, set[tuple[str, ...]]] = {}
|
|
339
339
|
for t in tables:
|
|
340
340
|
by_database.setdefault(t.database, set()).add(t.table_key)
|
|
341
341
|
|
|
342
|
-
|
|
342
|
+
details: list[ForeignKeyDetail] = []
|
|
343
343
|
for database, scoped_keys in by_database.items():
|
|
344
344
|
try:
|
|
345
345
|
conn = self._get_cached_connection(database)
|
|
@@ -347,27 +347,60 @@ class MySQLSource(BaseTabularSource):
|
|
|
347
347
|
cursor.execute(
|
|
348
348
|
"""
|
|
349
349
|
SELECT
|
|
350
|
-
|
|
351
|
-
|
|
350
|
+
CONSTRAINT_NAME AS constraint_name,
|
|
351
|
+
TABLE_SCHEMA AS source_database,
|
|
352
|
+
TABLE_NAME AS source_table,
|
|
353
|
+
COLUMN_NAME AS source_column,
|
|
352
354
|
REFERENCED_TABLE_SCHEMA AS target_database,
|
|
353
|
-
REFERENCED_TABLE_NAME AS target_table
|
|
355
|
+
REFERENCED_TABLE_NAME AS target_table,
|
|
356
|
+
REFERENCED_COLUMN_NAME AS target_column
|
|
354
357
|
FROM information_schema.KEY_COLUMN_USAGE
|
|
355
358
|
WHERE TABLE_SCHEMA = %s
|
|
356
359
|
AND REFERENCED_TABLE_SCHEMA IS NOT NULL
|
|
357
360
|
AND REFERENCED_TABLE_NAME IS NOT NULL
|
|
361
|
+
AND REFERENCED_COLUMN_NAME IS NOT NULL
|
|
362
|
+
ORDER BY CONSTRAINT_NAME, ORDINAL_POSITION
|
|
358
363
|
""",
|
|
359
364
|
(database,),
|
|
360
365
|
)
|
|
361
|
-
for
|
|
366
|
+
for row in cursor.fetchall():
|
|
367
|
+
if not isinstance(row, tuple) or len(row) < 7:
|
|
368
|
+
continue
|
|
369
|
+
(
|
|
370
|
+
constraint_name,
|
|
371
|
+
src_db,
|
|
372
|
+
src_table,
|
|
373
|
+
src_col,
|
|
374
|
+
tgt_db,
|
|
375
|
+
tgt_table,
|
|
376
|
+
tgt_col,
|
|
377
|
+
) = row[:7]
|
|
378
|
+
if not all(
|
|
379
|
+
isinstance(v, str)
|
|
380
|
+
for v in (src_db, src_table, src_col, tgt_db, tgt_table, tgt_col)
|
|
381
|
+
):
|
|
382
|
+
continue
|
|
362
383
|
source_key = (src_db, src_table)
|
|
363
384
|
target_key = (tgt_db, tgt_table)
|
|
364
385
|
if source_key in scoped_keys and target_key in all_keys:
|
|
365
|
-
|
|
386
|
+
details.append(
|
|
387
|
+
ForeignKeyDetail(
|
|
388
|
+
source_key=source_key,
|
|
389
|
+
target_key=target_key,
|
|
390
|
+
source_column=src_col,
|
|
391
|
+
target_column=tgt_col,
|
|
392
|
+
constraint_name=constraint_name
|
|
393
|
+
if isinstance(constraint_name, str) and constraint_name
|
|
394
|
+
else None,
|
|
395
|
+
)
|
|
396
|
+
)
|
|
366
397
|
except Exception as exc:
|
|
367
398
|
logger.warning(
|
|
368
|
-
"Could not resolve foreign key
|
|
399
|
+
"Could not resolve MySQL foreign key details for database %s: %s",
|
|
400
|
+
database,
|
|
401
|
+
exc,
|
|
369
402
|
)
|
|
370
|
-
return
|
|
403
|
+
return details
|
|
371
404
|
|
|
372
405
|
# ── External URL ─────────────────────────────────────────────────────
|
|
373
406
|
|
src/sources/odbc/source.py
CHANGED
|
@@ -36,7 +36,7 @@ from ...utils.odbc_connection import (
|
|
|
36
36
|
from ...utils.urn import Urn, UrnError
|
|
37
37
|
from ..dependencies import require_module
|
|
38
38
|
from ..tabular_base import BaseTabularSource
|
|
39
|
-
from ..tabular_utils import TableRef
|
|
39
|
+
from ..tabular_utils import ForeignKeyDetail, TableRef
|
|
40
40
|
|
|
41
41
|
logger = logging.getLogger(__name__)
|
|
42
42
|
|
|
@@ -415,12 +415,10 @@ class OdbcSource(BaseTabularSource):
|
|
|
415
415
|
matching.sort(key=lambda r: r[4] if len(r) > 4 and isinstance(r[4], int) else 0)
|
|
416
416
|
return [str(row[3]) for row in matching if row[3]]
|
|
417
417
|
|
|
418
|
-
def
|
|
419
|
-
self, tables: list[TableRef]
|
|
420
|
-
) -> dict[tuple[str, ...], set[tuple[str, ...]]]:
|
|
418
|
+
def _collect_foreign_key_details(self, tables: list[TableRef]) -> list[ForeignKeyDetail]:
|
|
421
419
|
if self._option("extraction", "include_foreign_keys", True) is False:
|
|
422
|
-
return
|
|
423
|
-
|
|
420
|
+
return []
|
|
421
|
+
details: list[ForeignKeyDetail] = []
|
|
424
422
|
for table_ref in tables:
|
|
425
423
|
if self._aborted:
|
|
426
424
|
break
|
|
@@ -441,17 +439,21 @@ class OdbcSource(BaseTabularSource):
|
|
|
441
439
|
finally:
|
|
442
440
|
cursor.close()
|
|
443
441
|
except Exception as exc:
|
|
444
|
-
# A driver without SQLForeignKeys: no links, not a failed scan.
|
|
445
442
|
logger.debug("No foreign keys for %s: %s", table_ref.display_name, exc)
|
|
446
443
|
if "optional feature not implemented" in str(exc).lower():
|
|
447
|
-
break
|
|
444
|
+
break
|
|
448
445
|
continue
|
|
449
446
|
for row in rows:
|
|
450
|
-
#
|
|
447
|
+
# ODBC SQLForeignKeys:
|
|
448
|
+
# (0:pkcat, 1:pkschem, 2:pktable, 3:pkcol, 4:fkcat, 5:fkschem, 6:fktable, 7:fkcol, ..., 11:fkname)
|
|
451
449
|
if len(row) < 8 or not self._same(row[6], table_ref.table):
|
|
452
450
|
continue
|
|
453
451
|
if not self._same(row[5], table_ref.schema):
|
|
454
452
|
continue
|
|
453
|
+
pk_col = str(row[3]) if row[3] else ""
|
|
454
|
+
fk_col = str(row[7]) if row[7] else ""
|
|
455
|
+
if not pk_col or not fk_col:
|
|
456
|
+
continue
|
|
455
457
|
target_schema = str(row[1]) if row[1] else None
|
|
456
458
|
target_db = str(row[0]) if row[0] else _NO_CATALOG_LABEL
|
|
457
459
|
target = (
|
|
@@ -459,9 +461,18 @@ class OdbcSource(BaseTabularSource):
|
|
|
459
461
|
if target_schema is not None
|
|
460
462
|
else (target_db, str(row[2]))
|
|
461
463
|
)
|
|
464
|
+
fk_name = str(row[11]) if len(row) > 11 and row[11] else None
|
|
462
465
|
if target != table_ref.table_key:
|
|
463
|
-
|
|
464
|
-
|
|
466
|
+
details.append(
|
|
467
|
+
ForeignKeyDetail(
|
|
468
|
+
source_key=table_ref.table_key,
|
|
469
|
+
target_key=target,
|
|
470
|
+
source_column=fk_col,
|
|
471
|
+
target_column=pk_col,
|
|
472
|
+
constraint_name=fk_name,
|
|
473
|
+
)
|
|
474
|
+
)
|
|
475
|
+
return details
|
|
465
476
|
|
|
466
477
|
# ── Dialect ──────────────────────────────────────────────────────────
|
|
467
478
|
|
src/sources/oracle/source.py
CHANGED
|
@@ -14,7 +14,7 @@ from ...models.generated_input import (
|
|
|
14
14
|
from ...utils.file_parser import render_bytes_cell
|
|
15
15
|
from ..dependencies import require_module
|
|
16
16
|
from ..tabular_base import BaseTabularSource
|
|
17
|
-
from ..tabular_utils import TableRef, ViewLineage
|
|
17
|
+
from ..tabular_utils import ForeignKeyDetail, TableRef, ViewLineage
|
|
18
18
|
|
|
19
19
|
logger = logging.getLogger(__name__)
|
|
20
20
|
|
|
@@ -560,58 +560,84 @@ class OracleSource(BaseTabularSource):
|
|
|
560
560
|
logger.debug("Could not read definition of view %s.%s: %s", owner, name, exc)
|
|
561
561
|
return None
|
|
562
562
|
|
|
563
|
-
def
|
|
563
|
+
def _collect_foreign_key_details(
|
|
564
564
|
self,
|
|
565
565
|
tables: list[TableRef],
|
|
566
|
-
) ->
|
|
567
|
-
# Only declared constraints: a view's dependencies are lineage, and
|
|
568
|
-
# _collect_view_lineage already emits them as FLOW.
|
|
566
|
+
) -> list[ForeignKeyDetail]:
|
|
569
567
|
table_keys = {t.table_key for t in tables if t.object_type == "TABLE"}
|
|
570
568
|
if not table_keys:
|
|
571
|
-
return
|
|
569
|
+
return []
|
|
572
570
|
|
|
573
|
-
|
|
571
|
+
details: list[ForeignKeyDetail] = []
|
|
574
572
|
try:
|
|
575
573
|
conn = self._get_cached_connection(self._service_name)
|
|
576
574
|
with conn.cursor() as cursor:
|
|
577
575
|
cursor.execute(
|
|
578
576
|
"""
|
|
579
577
|
SELECT
|
|
580
|
-
src.
|
|
581
|
-
src.
|
|
582
|
-
|
|
583
|
-
|
|
578
|
+
src.constraint_name AS constraint_name,
|
|
579
|
+
src.owner AS source_owner,
|
|
580
|
+
src.table_name AS source_table,
|
|
581
|
+
src_col.column_name AS source_column,
|
|
582
|
+
tgt.owner AS target_owner,
|
|
583
|
+
tgt.table_name AS target_table,
|
|
584
|
+
tgt_col.column_name AS target_column
|
|
584
585
|
FROM all_constraints src
|
|
585
586
|
JOIN all_constraints tgt
|
|
586
587
|
ON src.r_owner = tgt.owner
|
|
587
588
|
AND src.r_constraint_name = tgt.constraint_name
|
|
589
|
+
JOIN all_cons_columns src_col
|
|
590
|
+
ON src_col.owner = src.owner
|
|
591
|
+
AND src_col.constraint_name = src.constraint_name
|
|
592
|
+
JOIN all_cons_columns tgt_col
|
|
593
|
+
ON tgt_col.owner = tgt.owner
|
|
594
|
+
AND tgt_col.constraint_name = tgt.constraint_name
|
|
595
|
+
AND tgt_col.position = src_col.position
|
|
588
596
|
WHERE src.constraint_type = 'R'
|
|
597
|
+
ORDER BY src.constraint_name, src_col.position
|
|
589
598
|
"""
|
|
590
599
|
)
|
|
591
600
|
for row in cursor.fetchall():
|
|
592
|
-
if not isinstance(row, tuple) or len(row) <
|
|
601
|
+
if not isinstance(row, tuple) or len(row) < 7:
|
|
593
602
|
continue
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
603
|
+
(
|
|
604
|
+
constraint_name,
|
|
605
|
+
source_schema,
|
|
606
|
+
source_name,
|
|
607
|
+
source_col,
|
|
608
|
+
target_schema,
|
|
609
|
+
target_name,
|
|
610
|
+
target_col,
|
|
611
|
+
) = row[:7]
|
|
600
612
|
if not all(
|
|
601
613
|
isinstance(v, str)
|
|
602
|
-
for v in (
|
|
614
|
+
for v in (
|
|
615
|
+
source_schema,
|
|
616
|
+
source_name,
|
|
617
|
+
source_col,
|
|
618
|
+
target_schema,
|
|
619
|
+
target_name,
|
|
620
|
+
target_col,
|
|
621
|
+
)
|
|
603
622
|
):
|
|
604
623
|
continue
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
624
|
+
source_key = (self._service_name, source_schema.upper(), source_name)
|
|
625
|
+
target_key = (self._service_name, target_schema.upper(), target_name)
|
|
626
|
+
if source_key in table_keys and target_key in table_keys:
|
|
627
|
+
details.append(
|
|
628
|
+
ForeignKeyDetail(
|
|
629
|
+
source_key=source_key,
|
|
630
|
+
target_key=target_key,
|
|
631
|
+
source_column=source_col,
|
|
632
|
+
target_column=target_col,
|
|
633
|
+
constraint_name=constraint_name
|
|
634
|
+
if isinstance(constraint_name, str) and constraint_name
|
|
635
|
+
else None,
|
|
636
|
+
)
|
|
637
|
+
)
|
|
611
638
|
except Exception as exc:
|
|
612
|
-
logger.warning("Could not resolve Oracle foreign key
|
|
613
|
-
|
|
614
|
-
return links
|
|
639
|
+
logger.warning("Could not resolve Oracle foreign key details: %s", exc)
|
|
640
|
+
return details
|
|
615
641
|
|
|
616
642
|
# ── External URL ─────────────────────────────────────────────────────
|
|
617
643
|
|
src/sources/postgresql/source.py
CHANGED
|
@@ -11,7 +11,7 @@ from ...models.generated_input import (
|
|
|
11
11
|
)
|
|
12
12
|
from ..dependencies import require_module
|
|
13
13
|
from ..tabular_base import BaseTabularSource
|
|
14
|
-
from ..tabular_utils import TableRef, ViewLineage
|
|
14
|
+
from ..tabular_utils import ForeignKeyDetail, TableRef, ViewLineage
|
|
15
15
|
|
|
16
16
|
logger = logging.getLogger(__name__)
|
|
17
17
|
|
|
@@ -162,15 +162,15 @@ class PostgreSQLSource(BaseTabularSource):
|
|
|
162
162
|
def _urn_authority(self) -> str:
|
|
163
163
|
return f"{self.config.required.host}:{self.config.required.port}"
|
|
164
164
|
|
|
165
|
-
def
|
|
165
|
+
def _collect_foreign_key_details(
|
|
166
166
|
self,
|
|
167
167
|
tables: list[TableRef],
|
|
168
|
-
) ->
|
|
168
|
+
) -> list[ForeignKeyDetail]:
|
|
169
169
|
by_database: dict[str, set[tuple[str, ...]]] = {}
|
|
170
170
|
for t in tables:
|
|
171
171
|
by_database.setdefault(t.database, set()).add(t.table_key)
|
|
172
172
|
|
|
173
|
-
|
|
173
|
+
details: list[ForeignKeyDetail] = []
|
|
174
174
|
for database, scoped_keys in by_database.items():
|
|
175
175
|
try:
|
|
176
176
|
conn = self._get_cached_connection(database)
|
|
@@ -178,30 +178,74 @@ class PostgreSQLSource(BaseTabularSource):
|
|
|
178
178
|
cursor.execute(
|
|
179
179
|
"""
|
|
180
180
|
SELECT
|
|
181
|
+
fk.conname AS constraint_name,
|
|
181
182
|
source_ns.nspname AS source_schema,
|
|
182
183
|
source_tbl.relname AS source_table,
|
|
184
|
+
src_att.attname AS source_column,
|
|
183
185
|
target_ns.nspname AS target_schema,
|
|
184
|
-
target_tbl.relname AS target_table
|
|
186
|
+
target_tbl.relname AS target_table,
|
|
187
|
+
tgt_att.attname AS target_column
|
|
185
188
|
FROM pg_constraint AS fk
|
|
186
189
|
JOIN pg_class AS source_tbl ON source_tbl.oid = fk.conrelid
|
|
187
190
|
JOIN pg_namespace AS source_ns ON source_ns.oid = source_tbl.relnamespace
|
|
188
191
|
JOIN pg_class AS target_tbl ON target_tbl.oid = fk.confrelid
|
|
189
192
|
JOIN pg_namespace AS target_ns ON target_ns.oid = target_tbl.relnamespace
|
|
193
|
+
JOIN LATERAL unnest(fk.conkey) WITH ORDINALITY AS src_k(attnum, ord) ON TRUE
|
|
194
|
+
JOIN LATERAL unnest(fk.confkey) WITH ORDINALITY AS tgt_k(attnum, ord)
|
|
195
|
+
ON tgt_k.ord = src_k.ord
|
|
196
|
+
JOIN pg_attribute AS src_att
|
|
197
|
+
ON src_att.attrelid = fk.conrelid AND src_att.attnum = src_k.attnum
|
|
198
|
+
JOIN pg_attribute AS tgt_att
|
|
199
|
+
ON tgt_att.attrelid = fk.confrelid AND tgt_att.attnum = tgt_k.attnum
|
|
190
200
|
WHERE fk.contype = 'f'
|
|
201
|
+
ORDER BY fk.conname, src_k.ord
|
|
191
202
|
"""
|
|
192
203
|
)
|
|
193
|
-
for
|
|
204
|
+
for row in cursor.fetchall():
|
|
205
|
+
if not isinstance(row, tuple) or len(row) < 7:
|
|
206
|
+
continue
|
|
207
|
+
(
|
|
208
|
+
constraint_name,
|
|
209
|
+
src_schema,
|
|
210
|
+
src_table,
|
|
211
|
+
src_col,
|
|
212
|
+
tgt_schema,
|
|
213
|
+
tgt_table,
|
|
214
|
+
tgt_col,
|
|
215
|
+
) = row[:7]
|
|
216
|
+
if not all(
|
|
217
|
+
isinstance(v, str)
|
|
218
|
+
for v in (
|
|
219
|
+
src_schema,
|
|
220
|
+
src_table,
|
|
221
|
+
src_col,
|
|
222
|
+
tgt_schema,
|
|
223
|
+
tgt_table,
|
|
224
|
+
tgt_col,
|
|
225
|
+
)
|
|
226
|
+
):
|
|
227
|
+
continue
|
|
194
228
|
source_key = (database, src_schema, src_table)
|
|
195
229
|
target_key = (database, tgt_schema, tgt_table)
|
|
196
230
|
if source_key in scoped_keys and target_key in scoped_keys:
|
|
197
|
-
|
|
231
|
+
details.append(
|
|
232
|
+
ForeignKeyDetail(
|
|
233
|
+
source_key=source_key,
|
|
234
|
+
target_key=target_key,
|
|
235
|
+
source_column=src_col,
|
|
236
|
+
target_column=tgt_col,
|
|
237
|
+
constraint_name=constraint_name
|
|
238
|
+
if isinstance(constraint_name, str) and constraint_name
|
|
239
|
+
else None,
|
|
240
|
+
)
|
|
241
|
+
)
|
|
198
242
|
except Exception as exc:
|
|
199
243
|
logger.warning(
|
|
200
|
-
"Could not resolve foreign key
|
|
244
|
+
"Could not resolve foreign key column details for database %s: %s",
|
|
201
245
|
database,
|
|
202
246
|
exc,
|
|
203
247
|
)
|
|
204
|
-
return
|
|
248
|
+
return details
|
|
205
249
|
|
|
206
250
|
# ── View lineage (pg_depend / pg_rewrite) ────────────────────────────
|
|
207
251
|
|
src/sources/snowflake/source.py
CHANGED
|
@@ -25,7 +25,7 @@ from ...utils.file_parser import render_bytes_cell
|
|
|
25
25
|
from ...utils.sql_lineage import upstream_tables_from_sql
|
|
26
26
|
from ..dependencies import require_module
|
|
27
27
|
from ..tabular_base import BaseTabularSource
|
|
28
|
-
from ..tabular_utils import TableRef, ViewLineage, table_format_from
|
|
28
|
+
from ..tabular_utils import ForeignKeyDetail, TableRef, ViewLineage, table_format_from
|
|
29
29
|
|
|
30
30
|
logger = logging.getLogger(__name__)
|
|
31
31
|
|
|
@@ -655,67 +655,62 @@ class SnowflakeSource(BaseTabularSource):
|
|
|
655
655
|
|
|
656
656
|
# ── Foreign keys ─────────────────────────────────────────────────────
|
|
657
657
|
|
|
658
|
-
def
|
|
658
|
+
def _collect_foreign_key_details(
|
|
659
659
|
self,
|
|
660
660
|
tables: list[TableRef],
|
|
661
|
-
) ->
|
|
662
|
-
"""Declared foreign keys, read from each database's INFORMATION_SCHEMA.
|
|
663
|
-
|
|
664
|
-
Only constraints belong here. What a view selects from is lineage, and
|
|
665
|
-
_collect_view_lineage already emits it as FLOW.
|
|
666
|
-
"""
|
|
661
|
+
) -> list[ForeignKeyDetail]:
|
|
667
662
|
if not self._include_table_lineage_enabled():
|
|
668
|
-
return
|
|
663
|
+
return []
|
|
669
664
|
|
|
670
665
|
by_database: dict[str, set[tuple[str, ...]]] = {}
|
|
671
666
|
for t in tables:
|
|
672
667
|
if t.object_type == "TABLE":
|
|
673
668
|
by_database.setdefault(t.database, set()).add(t.table_key)
|
|
674
669
|
|
|
675
|
-
|
|
670
|
+
details: list[ForeignKeyDetail] = []
|
|
676
671
|
for database, table_keys in by_database.items():
|
|
677
|
-
info = f'"{database}".INFORMATION_SCHEMA'
|
|
678
672
|
try:
|
|
679
673
|
conn = self._get_cached_connection(database)
|
|
680
674
|
cursor = conn.cursor()
|
|
681
675
|
try:
|
|
682
|
-
cursor.execute(
|
|
683
|
-
f"""
|
|
684
|
-
SELECT
|
|
685
|
-
fk.TABLE_SCHEMA AS SOURCE_SCHEMA,
|
|
686
|
-
fk.TABLE_NAME AS SOURCE_TABLE,
|
|
687
|
-
pk.TABLE_SCHEMA AS TARGET_SCHEMA,
|
|
688
|
-
pk.TABLE_NAME AS TARGET_TABLE
|
|
689
|
-
FROM {info}.REFERENTIAL_CONSTRAINTS rc
|
|
690
|
-
JOIN {info}.TABLE_CONSTRAINTS fk
|
|
691
|
-
ON fk.CONSTRAINT_SCHEMA = rc.CONSTRAINT_SCHEMA
|
|
692
|
-
AND fk.CONSTRAINT_NAME = rc.CONSTRAINT_NAME
|
|
693
|
-
JOIN {info}.TABLE_CONSTRAINTS pk
|
|
694
|
-
ON pk.CONSTRAINT_SCHEMA = rc.UNIQUE_CONSTRAINT_SCHEMA
|
|
695
|
-
AND pk.CONSTRAINT_NAME = rc.UNIQUE_CONSTRAINT_NAME
|
|
696
|
-
"""
|
|
697
|
-
)
|
|
676
|
+
cursor.execute(f'SHOW IMPORTED KEYS IN DATABASE "{database}"')
|
|
698
677
|
rows = self._fetch_dict_rows(cursor)
|
|
699
678
|
finally:
|
|
700
679
|
cursor.close()
|
|
701
680
|
except Exception as exc:
|
|
702
|
-
logger.warning(
|
|
681
|
+
logger.warning(
|
|
682
|
+
"Could not resolve Snowflake foreign key details for %s: %s", database, exc
|
|
683
|
+
)
|
|
703
684
|
continue
|
|
704
685
|
|
|
705
686
|
for row in rows:
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
)
|
|
712
|
-
|
|
687
|
+
fk_schema = row.get("fk_schema_name") or row.get("FK_SCHEMA_NAME")
|
|
688
|
+
fk_table = row.get("fk_table_name") or row.get("FK_TABLE_NAME")
|
|
689
|
+
fk_col = row.get("fk_column_name") or row.get("FK_COLUMN_NAME")
|
|
690
|
+
pk_schema = row.get("pk_schema_name") or row.get("PK_SCHEMA_NAME")
|
|
691
|
+
pk_table = row.get("pk_table_name") or row.get("PK_TABLE_NAME")
|
|
692
|
+
pk_col = row.get("pk_column_name") or row.get("PK_COLUMN_NAME")
|
|
693
|
+
fk_name = row.get("fk_name") or row.get("FK_NAME")
|
|
694
|
+
if not all(
|
|
695
|
+
isinstance(v, str) and v
|
|
696
|
+
for v in (fk_schema, fk_table, fk_col, pk_schema, pk_table, pk_col)
|
|
697
|
+
):
|
|
713
698
|
continue
|
|
714
|
-
source_key = (database, str(
|
|
715
|
-
target_key = (database, str(
|
|
699
|
+
source_key = (database, str(fk_schema), str(fk_table))
|
|
700
|
+
target_key = (database, str(pk_schema), str(pk_table))
|
|
716
701
|
if source_key in table_keys and target_key in table_keys:
|
|
717
|
-
|
|
718
|
-
|
|
702
|
+
details.append(
|
|
703
|
+
ForeignKeyDetail(
|
|
704
|
+
source_key=source_key,
|
|
705
|
+
target_key=target_key,
|
|
706
|
+
source_column=str(fk_col),
|
|
707
|
+
target_column=str(pk_col),
|
|
708
|
+
constraint_name=str(fk_name)
|
|
709
|
+
if isinstance(fk_name, str) and fk_name
|
|
710
|
+
else None,
|
|
711
|
+
)
|
|
712
|
+
)
|
|
713
|
+
return details
|
|
719
714
|
|
|
720
715
|
# ── External URL ─────────────────────────────────────────────────────
|
|
721
716
|
|
src/sources/tabular_base.py
CHANGED
|
@@ -41,6 +41,7 @@ from ..utils.sql_lineage import (
|
|
|
41
41
|
from ..utils.urn import Urn, UrnError
|
|
42
42
|
from .base import BaseSource
|
|
43
43
|
from .tabular_utils import (
|
|
44
|
+
ForeignKeyDetail,
|
|
44
45
|
TableRef,
|
|
45
46
|
ViewLineage,
|
|
46
47
|
build_tabular_location,
|
|
@@ -59,6 +60,7 @@ TABULAR_METADATA_KEYS: frozenset[str] = frozenset(
|
|
|
59
60
|
"table_type",
|
|
60
61
|
"schema",
|
|
61
62
|
"columns",
|
|
63
|
+
"primary_keys",
|
|
62
64
|
"row_count",
|
|
63
65
|
"table_format",
|
|
64
66
|
}
|
|
@@ -131,6 +133,7 @@ class BaseTabularSource(BaseSource):
|
|
|
131
133
|
self._pk_columns_cache: dict[tuple[str, ...], list[str]] = {}
|
|
132
134
|
self._columns_meta_cache: dict[tuple[str, ...], list[str]] = {}
|
|
133
135
|
self._column_types_cache: dict[tuple[str, ...], dict[str, str]] = {}
|
|
136
|
+
self._column_nullability_cache: dict[tuple[str, ...], dict[str, bool]] = {}
|
|
134
137
|
# AUTOMATIC sampling: serialise cursor mutation across the concurrent
|
|
135
138
|
# per-table content tasks, and advance each table's cursor at most once
|
|
136
139
|
# per run (fetch_content and fetch_content_pages may both touch a table).
|
|
@@ -380,9 +383,25 @@ class BaseTabularSource(BaseSource):
|
|
|
380
383
|
) -> dict[tuple[str, ...], set[tuple[str, ...]]]:
|
|
381
384
|
"""Return a mapping from table-key to set of linked table-keys.
|
|
382
385
|
|
|
383
|
-
|
|
386
|
+
Derived from ``_collect_foreign_key_details`` so connectors only query
|
|
387
|
+
database FK catalogs once. Subclasses without column-level FK metadata
|
|
388
|
+
may still override this method directly as a fallback.
|
|
384
389
|
"""
|
|
385
|
-
|
|
390
|
+
links: dict[tuple[str, ...], set[tuple[str, ...]]] = {}
|
|
391
|
+
for detail in self._collect_foreign_key_details(tables):
|
|
392
|
+
links.setdefault(detail.source_key, set()).add(detail.target_key)
|
|
393
|
+
return links
|
|
394
|
+
|
|
395
|
+
def _collect_foreign_key_details(
|
|
396
|
+
self,
|
|
397
|
+
tables: list[TableRef],
|
|
398
|
+
) -> list[ForeignKeyDetail]:
|
|
399
|
+
"""Return column-level FK details between tables in this scan.
|
|
400
|
+
|
|
401
|
+
Default returns an empty list; dialects that expose FK columns and
|
|
402
|
+
constraint names override this so ER diagrams render exact links.
|
|
403
|
+
"""
|
|
404
|
+
return []
|
|
386
405
|
|
|
387
406
|
# ── Column metadata ──────────────────────────────────────────────────
|
|
388
407
|
|
|
@@ -414,11 +433,16 @@ class BaseTabularSource(BaseSource):
|
|
|
414
433
|
self._column_types_cache[key] = types
|
|
415
434
|
return types
|
|
416
435
|
|
|
436
|
+
def _cached_column_nullability(self, table_ref: TableRef) -> dict[str, bool]:
|
|
437
|
+
"""Return cached ``{column_name: nullable}`` map when populated by metadata queries."""
|
|
438
|
+
return self._column_nullability_cache.get(table_ref.table_key, {})
|
|
439
|
+
|
|
417
440
|
def _available_column_types(self, table_ref: TableRef) -> dict[str, str]:
|
|
418
441
|
"""Return ordered ``{column_name: data_type}`` via ``information_schema``.
|
|
419
442
|
|
|
420
443
|
Default works for dialects exposing ``information_schema.columns`` keyed
|
|
421
|
-
by ``table_schema``/``table_name`` (PostgreSQL, MSSQL).
|
|
444
|
+
by ``table_schema``/``table_name`` (PostgreSQL, MSSQL). Also populates
|
|
445
|
+
column nullability when ``is_nullable`` is returned. Dialects with a
|
|
422
446
|
different catalog override this; failures degrade to names-only.
|
|
423
447
|
"""
|
|
424
448
|
ph = self._param_placeholder()
|
|
@@ -426,7 +450,7 @@ class BaseTabularSource(BaseSource):
|
|
|
426
450
|
with conn.cursor() as cursor:
|
|
427
451
|
cursor.execute(
|
|
428
452
|
f"""
|
|
429
|
-
SELECT column_name, data_type
|
|
453
|
+
SELECT column_name, data_type, is_nullable
|
|
430
454
|
FROM information_schema.columns
|
|
431
455
|
WHERE table_schema = {ph} AND table_name = {ph}
|
|
432
456
|
ORDER BY ordinal_position
|
|
@@ -434,10 +458,20 @@ class BaseTabularSource(BaseSource):
|
|
|
434
458
|
(table_ref.schema, table_ref.table),
|
|
435
459
|
)
|
|
436
460
|
result: dict[str, str] = {}
|
|
461
|
+
nullability: dict[str, bool] = {}
|
|
437
462
|
for row in cursor.fetchall():
|
|
438
463
|
if not row or not isinstance(row[0], str):
|
|
439
464
|
continue
|
|
440
|
-
|
|
465
|
+
col_name = row[0]
|
|
466
|
+
result[col_name] = str(row[1]) if len(row) > 1 and row[1] is not None else ""
|
|
467
|
+
if len(row) > 2 and row[2] is not None:
|
|
468
|
+
raw_null = str(row[2]).strip().upper()
|
|
469
|
+
if raw_null in ("YES", "TRUE", "1", "Y"):
|
|
470
|
+
nullability[col_name] = True
|
|
471
|
+
elif raw_null in ("NO", "FALSE", "0", "N"):
|
|
472
|
+
nullability[col_name] = False
|
|
473
|
+
if nullability:
|
|
474
|
+
self._column_nullability_cache[table_ref.table_key] = nullability
|
|
441
475
|
return result
|
|
442
476
|
|
|
443
477
|
def _estimate_row_count(self, table_ref: TableRef) -> int | None:
|
|
@@ -980,12 +1014,25 @@ class BaseTabularSource(BaseSource):
|
|
|
980
1014
|
# Prefer the name→type map (one catalog query gives both); fall back to
|
|
981
1015
|
# names-only (empty types) for dialects without a column-types query.
|
|
982
1016
|
column_types = self._cached_column_types(table_ref)
|
|
1017
|
+
pk_columns = self._get_primary_key_columns(table_ref)
|
|
1018
|
+
nullability = self._cached_column_nullability(table_ref)
|
|
983
1019
|
if column_types:
|
|
984
|
-
columns = build_columns(
|
|
1020
|
+
columns = build_columns(
|
|
1021
|
+
list(column_types.keys()),
|
|
1022
|
+
column_types,
|
|
1023
|
+
primary_keys=pk_columns or None,
|
|
1024
|
+
nullable=nullability or None,
|
|
1025
|
+
)
|
|
985
1026
|
else:
|
|
986
|
-
columns = build_columns(
|
|
1027
|
+
columns = build_columns(
|
|
1028
|
+
self._cached_columns(table_ref),
|
|
1029
|
+
primary_keys=pk_columns or None,
|
|
1030
|
+
nullable=nullability or None,
|
|
1031
|
+
)
|
|
987
1032
|
if columns:
|
|
988
1033
|
asset_metadata["columns"] = columns
|
|
1034
|
+
if pk_columns:
|
|
1035
|
+
asset_metadata["primary_keys"] = pk_columns
|
|
989
1036
|
row_count = self._estimate_row_count(table_ref)
|
|
990
1037
|
if row_count is not None and row_count >= 0:
|
|
991
1038
|
asset_metadata["row_count"] = row_count
|
|
@@ -1022,6 +1069,7 @@ class BaseTabularSource(BaseSource):
|
|
|
1022
1069
|
tables: list[TableRef],
|
|
1023
1070
|
table_hash_by_key: dict[tuple[str, ...], str],
|
|
1024
1071
|
fk_links: dict[tuple[str, ...], set[tuple[str, ...]]],
|
|
1072
|
+
fk_details: list[ForeignKeyDetail] | None = None,
|
|
1025
1073
|
) -> None:
|
|
1026
1074
|
"""Turn what the catalog knows into typed, classified edges.
|
|
1027
1075
|
|
|
@@ -1036,14 +1084,52 @@ class BaseTabularSource(BaseSource):
|
|
|
1036
1084
|
never be a hop in a lineage path, so it is emitted as REFERENCE. These
|
|
1037
1085
|
used to be indistinguishable from every other kind of link.
|
|
1038
1086
|
"""
|
|
1087
|
+
grouped_fks: dict[tuple[str, str], list[dict[str, str]]] = {}
|
|
1088
|
+
seen_fk_items: dict[tuple[str, str], set[tuple[str, str, str]]] = {}
|
|
1089
|
+
for detail in fk_details or []:
|
|
1090
|
+
source_hash = table_hash_by_key.get(detail.source_key)
|
|
1091
|
+
target_hash = table_hash_by_key.get(detail.target_key)
|
|
1092
|
+
if not source_hash or not target_hash or source_hash == target_hash:
|
|
1093
|
+
continue
|
|
1094
|
+
pair = (source_hash, target_hash)
|
|
1095
|
+
dedupe_key = (
|
|
1096
|
+
detail.source_column.lower(),
|
|
1097
|
+
detail.target_column.lower(),
|
|
1098
|
+
detail.constraint_name or "",
|
|
1099
|
+
)
|
|
1100
|
+
seen = seen_fk_items.setdefault(pair, set())
|
|
1101
|
+
if dedupe_key in seen:
|
|
1102
|
+
continue
|
|
1103
|
+
seen.add(dedupe_key)
|
|
1104
|
+
item: dict[str, str] = {
|
|
1105
|
+
"fromColumn": detail.source_column,
|
|
1106
|
+
"toColumn": detail.target_column,
|
|
1107
|
+
}
|
|
1108
|
+
if detail.constraint_name:
|
|
1109
|
+
item["constraintName"] = detail.constraint_name
|
|
1110
|
+
grouped_fks.setdefault(pair, []).append(item)
|
|
1111
|
+
|
|
1112
|
+
emitted_pairs: set[tuple[str, str]] = set()
|
|
1113
|
+
for (source_hash, target_hash), items in sorted(grouped_fks.items()):
|
|
1114
|
+
emitted_pairs.add((source_hash, target_hash))
|
|
1115
|
+
self.add_edge(
|
|
1116
|
+
references(
|
|
1117
|
+
Ref.asset(source_hash),
|
|
1118
|
+
Ref.asset(target_hash),
|
|
1119
|
+
type=ReferenceType.FOREIGN_KEY,
|
|
1120
|
+
evidence={"foreign_keys": items},
|
|
1121
|
+
)
|
|
1122
|
+
)
|
|
1123
|
+
|
|
1039
1124
|
for source_key, target_keys in fk_links.items():
|
|
1040
1125
|
source_hash = table_hash_by_key.get(source_key)
|
|
1041
1126
|
if not source_hash:
|
|
1042
1127
|
continue
|
|
1043
1128
|
for target_key in sorted(target_keys):
|
|
1044
1129
|
target_hash = table_hash_by_key.get(target_key)
|
|
1045
|
-
if not target_hash:
|
|
1130
|
+
if not target_hash or (source_hash, target_hash) in emitted_pairs:
|
|
1046
1131
|
continue
|
|
1132
|
+
emitted_pairs.add((source_hash, target_hash))
|
|
1047
1133
|
self.add_edge(
|
|
1048
1134
|
references(
|
|
1049
1135
|
Ref.asset(source_hash),
|
|
@@ -1131,8 +1217,20 @@ class BaseTabularSource(BaseSource):
|
|
|
1131
1217
|
t.table_key: self.generate_hash_id(t.raw_id) for t in tables
|
|
1132
1218
|
}
|
|
1133
1219
|
self._declare_listing_if_whole()
|
|
1134
|
-
|
|
1135
|
-
|
|
1220
|
+
fk_details = self._collect_foreign_key_details(tables)
|
|
1221
|
+
fk_links: dict[tuple[str, ...], set[tuple[str, ...]]] = {}
|
|
1222
|
+
if fk_details:
|
|
1223
|
+
for detail in fk_details:
|
|
1224
|
+
fk_links.setdefault(detail.source_key, set()).add(detail.target_key)
|
|
1225
|
+
elif (
|
|
1226
|
+
type(self)._collect_foreign_key_links
|
|
1227
|
+
is not BaseTabularSource._collect_foreign_key_links
|
|
1228
|
+
or "_collect_foreign_key_links" in self.__dict__
|
|
1229
|
+
):
|
|
1230
|
+
# Fallback only when a subclass or test monkeypatch supplies
|
|
1231
|
+
# table-level FK links without column-level details.
|
|
1232
|
+
fk_links = self._collect_foreign_key_links(tables)
|
|
1233
|
+
self._emit_relationship_edges(tables, table_hash_by_key, fk_links, fk_details=fk_details)
|
|
1136
1234
|
|
|
1137
1235
|
batch: list[SingleAssetScanResults] = []
|
|
1138
1236
|
for table_ref in tables:
|
src/sources/tabular_utils.py
CHANGED
|
@@ -66,6 +66,17 @@ class ViewLineage:
|
|
|
66
66
|
method: Method | None = None
|
|
67
67
|
|
|
68
68
|
|
|
69
|
+
@dataclass(frozen=True)
|
|
70
|
+
class ForeignKeyDetail:
|
|
71
|
+
"""One column-level foreign key mapping between two scanned tables."""
|
|
72
|
+
|
|
73
|
+
source_key: tuple[str, ...]
|
|
74
|
+
target_key: tuple[str, ...]
|
|
75
|
+
source_column: str
|
|
76
|
+
target_column: str
|
|
77
|
+
constraint_name: str | None = None
|
|
78
|
+
|
|
79
|
+
|
|
69
80
|
@dataclass(frozen=True)
|
|
70
81
|
class TabularCellMatch:
|
|
71
82
|
row_index: int
|
src/utils/file_metadata.py
CHANGED
|
@@ -174,13 +174,31 @@ def _pdf_metadata(file_bytes: bytes) -> dict[str, Any]:
|
|
|
174
174
|
return {"page_count": len(pdf.pages)}
|
|
175
175
|
|
|
176
176
|
|
|
177
|
-
def build_columns(
|
|
178
|
-
|
|
177
|
+
def build_columns(
|
|
178
|
+
names: list[str],
|
|
179
|
+
types: dict[str, str] | None = None,
|
|
180
|
+
*,
|
|
181
|
+
primary_keys: set[str] | list[str] | None = None,
|
|
182
|
+
nullable: dict[str, bool] | None = None,
|
|
183
|
+
) -> list[dict[str, Any]]:
|
|
184
|
+
"""Build the normalized ``columns`` list of ``{name, type, ...}`` objects.
|
|
179
185
|
|
|
180
186
|
``type`` is "" when the format does not expose column types (csv/xlsx).
|
|
187
|
+
``is_primary_key`` is emitted only when True, and ``nullable`` only when known.
|
|
181
188
|
"""
|
|
182
189
|
type_map = types or {}
|
|
183
|
-
|
|
190
|
+
pk_lower = {k.lower() for k in primary_keys} if primary_keys else set()
|
|
191
|
+
null_map = {k.lower(): v for k, v in nullable.items()} if nullable else {}
|
|
192
|
+
out: list[dict[str, Any]] = []
|
|
193
|
+
for name in names:
|
|
194
|
+
entry: dict[str, Any] = {"name": name, "type": type_map.get(name, "")}
|
|
195
|
+
lower = name.lower()
|
|
196
|
+
if lower in pk_lower:
|
|
197
|
+
entry["is_primary_key"] = True
|
|
198
|
+
if lower in null_map:
|
|
199
|
+
entry["nullable"] = null_map[lower]
|
|
200
|
+
out.append(entry)
|
|
201
|
+
return out
|
|
184
202
|
|
|
185
203
|
|
|
186
204
|
def _parquet_metadata(file_bytes: bytes) -> dict[str, Any]:
|
|
File without changes
|
|
File without changes
|