Skip to content

Commit e9e4df1

Browse files
committed
Add diagram intersection operator (*) documentation
Document the intersection operator for DataJoint Diagrams that shows only common nodes between two diagrams. This is particularly useful for finding connection paths between tables in large schemas by expanding one table downstream and another upstream, then intersecting them.
1 parent 9043e2e commit e9e4df1

File tree

1 file changed

+10
-23
lines changed

1 file changed

+10
-23
lines changed

book/30-design/060-diagrams.ipynb

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -689,28 +689,7 @@
689689
"cell_type": "markdown",
690690
"id": "cell-21",
691691
"metadata": {},
692-
"source": [
693-
"# Diagram Operations\n",
694-
"\n",
695-
"DataJoint provides operators to filter and combine diagrams for exploring large schemas:\n",
696-
"\n",
697-
"```python\n",
698-
"# Show entire schema\n",
699-
"dj.Diagram(schema)\n",
700-
"\n",
701-
"# Show specific tables\n",
702-
"dj.Diagram(Table1) + dj.Diagram(Table2)\n",
703-
"\n",
704-
"# Show table and N levels of upstream dependencies\n",
705-
"dj.Diagram(Table) - N\n",
706-
"\n",
707-
"# Show table and N levels of downstream dependents\n",
708-
"dj.Diagram(Table) + N\n",
709-
"\n",
710-
"# Combine operations\n",
711-
"(dj.Diagram(Table1) - 2) + (dj.Diagram(Table2) + 1)\n",
712-
"```"
713-
]
692+
"source": "# Diagram Operations\n\nDataJoint provides operators to filter and combine diagrams for exploring large schemas:\n\n```python\n# Show entire schema\ndj.Diagram(schema)\n\n# Show specific tables\ndj.Diagram(Table1) + dj.Diagram(Table2)\n\n# Show table and N levels of upstream dependencies\ndj.Diagram(Table) - N\n\n# Show table and N levels of downstream dependents\ndj.Diagram(Table) + N\n\n# Combine operations\n(dj.Diagram(Table1) - 2) + (dj.Diagram(Table2) + 1)\n\n# Intersection: show only common nodes between two diagrams\ndj.Diagram(Table1) * dj.Diagram(Table2)\n```\n\n## Finding Paths Between Tables\n\nThe intersection operator `*` is particularly useful for finding connection paths between two tables in a large schema.\nBy expanding one table downstream and another upstream, then taking the intersection, you reveal only the tables that form the path(s) between them:\n\n```python\n# Find all paths connecting table1 to table2 (where table2 is downstream from table1)\n(dj.Diagram(table1) + 100) * (dj.Diagram(table2) - 100)\n```\n\nThis works because:\n- `dj.Diagram(table1) + 100` includes table1 and up to 100 levels of downstream dependents\n- `dj.Diagram(table2) - 100` includes table2 and up to 100 levels of upstream dependencies\n- The intersection `*` shows only tables that appear in **both** diagrams—the connecting path(s)"
714693
},
715694
{
716695
"cell_type": "code",
@@ -723,6 +702,14 @@
723702
"dj.Diagram(schema)"
724703
]
725704
},
705+
{
706+
"cell_type": "code",
707+
"id": "tpx88p488y",
708+
"source": "# Find the path from Student to Enrollment using intersection\n# Expand Student downstream and Enrollment upstream, then intersect\n(dj.Diagram(Student) + 100) * (dj.Diagram(Enrollment) - 100)",
709+
"metadata": {},
710+
"execution_count": null,
711+
"outputs": []
712+
},
726713
{
727714
"cell_type": "markdown",
728715
"id": "cell-23",
@@ -884,4 +871,4 @@
884871
},
885872
"nbformat": 4,
886873
"nbformat_minor": 5
887-
}
874+
}

0 commit comments

Comments
 (0)