Repository navigation
docs(query-algebra): join key follows determination; full operator table; lineage and 2.3.6 notes - #320
Open
dimitri-yatsenko wants to merge 6 commits into
Open
docs(query-algebra): join key follows determination; full operator table; lineage and 2.3.6 notes#320dimitri-yatsenko wants to merge 6 commits into
dimitri-yatsenko wants to merge 6 commits into
Conversation
…neage Session * Trial is keyed by Trial, because Trial determines Session; the pages and the queries tutorial stated the direction backward, and two specs gave Session.join(Trial, left=True) as a valid left join, which the library rejects. The operator tables now list anti-restriction, extension, union, and both forms of the universal set with their keys and entity types. A secondary attribute declared in a table has no lineage and is never matched; the lineage-error section quotes the messages the library raises. Restriction by a query expression matches on every shared attribute. Aggregation examples count a key attribute of the right operand, since count(*) counts the padded row of an unmatched entity. Union combines operands with the same primary key and disjoint secondary attributes, and an entity in both carries the attributes of both.
- Extension: through 2.3.6 a restriction on the right operand drops the unmatched entities of the left operand (also aggregation and union of operands with secondary attributes); version note on the explanation page and in the queries tutorial. - Semantic matching: through 2.3.6 a namesake without lineage raises the "lineage missing on one side" message; version notes on the explanation and spec pages. - Primary keys: the abstract examples state that shared attributes are inherited through a foreign key; the dependency arrows that meant something other than "determines" are reworded. - Explanation page: the restriction section heading names both operators.
A shared attribute in the examples is a copy of one declared primary key attribute: declared in one operand and inherited by the other, or inherited by both from a common parent. Session declares session_id and only Trial inherits it, so the premise as written excluded the page's own Session * Trial example.
…enter in the tutorial
Relabel the three version notes "Changed in 2.3.7" and date the extension
change in the queries tutorial. Replace the tutorial's dj.U('experimenter_id')
aggregation with Experimenter.aggr, which the guidance in this PR recommends;
the stored output is unchanged apart from the key column's tooltip. State that
dj.U grouping over a nullable reference also returns one NULL group.
MilagrosMarin
left a comment
Collaborator
There was a problem hiding this comment.
Thanks @dimitri-yatsenko, this is a careful cleanup, and the determination framing is much easier to follow than "functional dependencies."
I checked the claims against datajoint-python master and v2.3.6 and ran them on MySQL 8.0:
Session * TrialandTrial * Sessionare both keyed by Trial's primary key;Session.join(Trial, left=True)raises with exactly the message quoted in primary-keys.md;Trial.join(Session, left=True)is keyed by Trial.COUNT(*)returns 1 for an unmatched entity, and counting an attribute shared with the left operand also returns 1, as spec 5.7 now says.- Union,
dj.U(both forms, including the NULL group on a nullable reference), andExperimenter.aggr(Session, ...)behave as described. - On master,
extend,aggrand union with a restricted right operand keep the unmatched rows; on 2.3.6 they drop them, as the "Changed in 2.3.7" notes say. Both namesake-without-lineage messages matchcondition.pyexactly, and the 2.3.6 message in the note is verbatim. mkdocs build --strictpasses with the same warnings as main.
A few points on timing and overlap:
- Both changes (datajoint/datajoint-python#1655 and datajoint/datajoint-python#1642) are on master but not in a release yet. Is the plan to merge this after 2.3.7 is tagged, or now, with the version notes covering the gap?
- Two open library PRs in the v2.4 milestone would change statements added here: datajoint/datajoint-python#1774 makes
COUNT(*)return 0 for unmatched rows (the "returns 1" sentence is on about six pages, including the tutorial), and datajoint/datajoint-python#1710 makesdj.Urefuse nullable attributes (the NULL-group sentence is on three pages). Worth tracking so those passages get a 2.4 note. - #305 documents the same lineage-message change in the same two files, labels it "Changed in 2.4", and conflicts with this PR. It looks superseded; should it be closed or rebased onto this?
- Tutorial nit: the new comment says "with 0 for one who has no sessions", but the tutorial data has no such experimenter (the output is alice 3, bob 2), so the reader never sees the 0. Adding an experimenter without sessions, or dropping that clause, would fix it. Also, "a valid primary key determined by which operand determines the other" reads a little circular.
- Small one: the PR description says "behaviours"; "behaviors" would match the rest of the docs.
Once the 2.3.7 timing is settled, the corrected Session * Trial direction and the full operator table will make these pages much easier to trust.
Member
Author
|
Thanks for the careful check against master and v2.3.6. Answers in order:
|
dimitri-yatsenko
requested review from
MilagrosMarin,
lum-agilyti and
ttngu207
December 1, 2026 23:18
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR corrects the query-algebra pages where they contradicted the library or each other. It touches the explanation, reference, how-to, and spec pages, and the queries tutorial.
Primary key of a join
Said: the primary key of
A * Bis the union of both primary keys, andSession * Trialis keyed by both.Says:
AdeterminesBwhen every primary-key attribute ofBis an attribute ofA.A → B, the join is keyed byA.B → A, it is keyed byB.Session * Trialis keyed byTrial, becauseTrialdeterminesSession. A table of the three cases replaces the old statement on the explanation, operator-reference, and primary-key spec pages.Why: the pages and the tutorial gave the direction backward.
Two specs gave
Session.join(Trial, left=True)as a valid left join, which the library rejects. Those examples are corrected.Premise of the abstract examples (
primary-keys.md): a shared attribute is a copy of one declared primary-key attribute. Either one operand declares it and the other inherits it, or both inherit it from a common parent. The previous premise excluded the page's ownSession * Trialexample.The operator set
A & ckeeps the entities ofAthat matchc, andA - ckeeps those that do not. The headings "Include" and "Exclude" become "Restriction" and "Anti-restriction"..extend()) is stated as a left join that keeps every entity of the left operand, with NULL where nothing matches, keyed by the left operand. It equals the join when every entity has a match.COUNT(trial_num)).COUNT(*)returns 1 for an entity with no match, because it counts the row the underlying left join pads with NULLs.dj.U) get their own section. It covers both forms (restricted by a query expression, and the left operand of an aggregation), and when to aggregate over a table instead. The queries tutorial now counts sessions per experimenter withExperimenter.aggr(Session, ...), and the pages note that grouping bydj.Uover a nullable reference also returns one NULL group.Lineage and semantic matching
Version notes
Two behaviors change in 2.3.7. Each gets a
version-changednote, "Changed in 2.3.7", on the pages that describe it:Also
Overlap
#305 also edits
semantic-matching.md. #307 also editsquery-algebra.md(explanation and spec),operators.md,query-data.md, and the semantic-matching spec. Whichever of these merges later needs a rebase.Checks
mkdocs build --strict,scripts/check_links.pyon the built site,scripts/check_markdown_lists.py, and codespell pass.