You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add functional dependency check for aggregation operator
In A.aggr(B, ...), ensures every entry in B matches exactly one entry in A:
- B must have all of A's primary key attributes
- Primary key attributes must be homologous (same lineage)
- Clear error messages for missing attributes or non-homologous lineage
Updated docstrings for:
- Aggregation.create()
- QueryExpression.aggr()
- U.aggr()
Updated spec document with:
- Functional dependency requirements
- Error message examples
- Additional test cases
Co-authored-by: dimitri-yatsenko <dimitri@datajoint.com>
- Group attributes retain their lineage from the group operand
441
+
In `A.aggr(B, ...)`, entries from B are grouped by A's primary key and aggregate functions are computed.
442
+
443
+
**Functional Dependency Requirement**: Every entry in B must match exactly one entry in A. This requires:
444
+
445
+
1.**B must have all of A's primary key attributes**: If A's primary key is `(a, b)`, then B must contain attributes named `a` and `b`.
446
+
447
+
2.**Primary key attributes must be homologous**: The namesake attributes in B must have the same lineage as in A. This ensures they represent the same entity.
448
+
449
+
```python
450
+
# Valid: Session.aggr(Trial, ...) where Trial has session_id from Session
451
+
Session.aggr(Trial, n='count(*)') # OK - Trial.session_id traces to Session.session_id
452
+
453
+
# Invalid: Missing primary key attribute
454
+
Session.aggr(Stimulus, n='count(*)') # Error if Stimulus lacks session_id
455
+
456
+
# Invalid: Non-homologous primary key
457
+
TableA.aggr(TableB, n='count(*)') # Error if TableB.id has different lineage than TableA.id
458
+
```
459
+
460
+
**Result lineage**:
461
+
- Group attributes retain their lineage from the grouping expression (A)
443
462
- Aggregated attributes have `lineage=None` (they are computations)
444
463
445
464
### Union (`+`)
@@ -470,6 +489,22 @@ DataJointError: dj.U(...) * table is deprecated in DataJoint 2.0.
470
489
Use dj.U(...) & table instead.
471
490
```
472
491
492
+
### Aggregation Missing Primary Key
493
+
494
+
```
495
+
DataJointError: Aggregation requires functional dependency: `group` must have all primary key
496
+
attributes of the grouping expression. Missing: {'session_id'}.
497
+
Use .proj() to add the missing attributes or verify the schema design.
0 commit comments