Skip to content

Commit e64e7a0

Browse files
committed
Update documentation and docstrings for semantic matching
- Update spec document to match actual implementation: - assert_join_compatibility only checks if expr1 is U (not expr2) - Error message includes .join(semantic_check=False) suggestion - Use create_lineage_table function name - Add complete parameter documentation to all lineage.py functions
1 parent 6c63625 commit e64e7a0

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

docs/src/design/semantic-matching-spec.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ def assert_join_compatibility(expr1, expr2):
306306
307307
Raises DataJointError if non-homologous namesakes are detected.
308308
"""
309-
if isinstance(expr1, U) or isinstance(expr2, U):
309+
if isinstance(expr1, U):
310310
return # U is always compatible
311311

312312
# Find namesake attributes (same name in both)
@@ -320,7 +320,8 @@ def assert_join_compatibility(expr1, expr2):
320320
raise DataJointError(
321321
f"Cannot join on attribute `{name}`: "
322322
f"different lineages ({lineage1} vs {lineage2}). "
323-
f"Use .proj() to rename one of the attributes."
323+
f"Use .proj() to rename one of the attributes or "
324+
f".join(semantic_check=False) to force a natural join."
324325
)
325326
```
326327

@@ -415,7 +416,7 @@ For existing schemas without `~lineage` tables:
415416
```python
416417
def migrate_schema_lineage(schema):
417418
"""Populate ~lineage table for all tables in schema."""
418-
create_lineage_table_if_not_exists(schema)
419+
create_lineage_table(schema)
419420

420421
for table in schema.list_tables():
421422
populate_lineage_from_dependencies(schema, table)
@@ -452,7 +453,7 @@ Union requires all namesake attributes to have matching lineage (enforced via `a
452453
```
453454
DataJointError: Cannot join on attribute `id`: different lineages
454455
(university.student.id vs university.course.id).
455-
Use .proj() to rename one of the attributes.
456+
Use .proj() to rename one of the attributes or .join(semantic_check=False) to force a natural join.
456457
```
457458

458459
### Deprecated `@` Operator

src/datajoint/lineage.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@
2020

2121

2222
def create_lineage_table(connection, database):
23-
"""Create the ~lineage table if it doesn't exist."""
23+
"""
24+
Create the ~lineage table if it doesn't exist.
25+
26+
:param connection: database connection
27+
:param database: schema/database name
28+
"""
2429
connection.query(
2530
f"""
2631
CREATE TABLE IF NOT EXISTS `{database}`.`{LINEAGE_TABLE_NAME}` (
@@ -37,8 +42,11 @@ def get_lineage(connection, database, table_name, attribute_name):
3742
"""
3843
Get lineage for an attribute from the ~lineage table.
3944
40-
Returns the lineage string if found, None otherwise (indicating no lineage
41-
or attribute is a native secondary).
45+
:param connection: database connection
46+
:param database: schema/database name
47+
:param table_name: name of the table
48+
:param attribute_name: name of the attribute
49+
:return: lineage string if found, None otherwise (no lineage or native secondary)
4250
"""
4351
try:
4452
result = connection.query(
@@ -59,8 +67,10 @@ def get_all_lineages(connection, database, table_name):
5967
"""
6068
Get all lineage entries for a table.
6169
62-
Returns a dict mapping attribute_name -> lineage.
63-
Attributes not in the dict have no lineage (native secondary).
70+
:param connection: database connection
71+
:param database: schema/database name
72+
:param table_name: name of the table
73+
:return: dict mapping attribute_name -> lineage (attributes not in dict have no lineage)
6474
"""
6575
try:
6676
result = connection.query(
@@ -77,7 +87,13 @@ def get_all_lineages(connection, database, table_name):
7787

7888

7989
def delete_lineage_entries(connection, database, table_name):
80-
"""Delete all lineage entries for a table."""
90+
"""
91+
Delete all lineage entries for a table.
92+
93+
:param connection: database connection
94+
:param database: schema/database name
95+
:param table_name: name of the table
96+
"""
8197
try:
8298
connection.query(
8399
f"""
@@ -95,6 +111,8 @@ def insert_lineage_entries(connection, database, entries):
95111
"""
96112
Insert lineage entries for a table.
97113
114+
:param connection: database connection
115+
:param database: schema/database name
98116
:param entries: list of (table_name, attribute_name, lineage) tuples
99117
"""
100118
if not entries:

0 commit comments

Comments
 (0)