Closed ethho closed 1 month ago
dependencies.load()
is a lazy function. If dependencies are already loaded, it returns immediately. It loads all the dependencies for all active schemas.
You can join diagrams as diag1 + diag2
. If you need to join a sequence of diagrams, you can use reduce(lambda a, b: a + b, diagram_list)
.
After reviewing with @ethho, we cleared the disconnect. This feature is unnecessary. Closing.
Feature Request
Problem
Currently,
Diagram
supports construction from a singlesource
:Table
,Schema
, or module with aschema
attribute. The use case is: when there are multiple connected (with foreign key references between their tables) schemas, and the user wishes to resolve (e.g. to view) these references. However, a user cannot construct a singleDiagram
from multiple schemas. The workaroundIs not efficient, since it scales linearly with respect the number of schemas (let this be $n$). This is because each
Diagram
constructor call loadsDependencies
:https://github.com/datajoint/datajoint-python/blob/77b75e9b11feaf35ce98e9f0afbf9289f33e08a2/datajoint/diagram.py#L103
which makes 2 queries to
INFORMATION_SCHEMA
tables to fetch primary and foreign keys:https://github.com/datajoint/datajoint-python/blob/77b75e9b11feaf35ce98e9f0afbf9289f33e08a2/datajoint/dependencies.py#L99-L135
So $2n$ queries to
INFORMATION_SCHEMA
are made.Requirements
Allow construction of a
Diagram
from multiple schema names. Construction from multiple schemas should be efficient, making $2 = O(1)$ queries (primary key and foreign key query) toINFORMATION_SCHEMA
.Justification
Adding support for this feature would enable users to efficiently view inter-schema references, even for large numbers of schemas.
Alternative Considerations
In my application, I workaround this by creating a mock class that we can pass to the
Diagram
constructor to get this behavior:This is $O(1)$ but hacky.
Environment