- 
                Notifications
    You must be signed in to change notification settings 
- Fork 42
Add support for universal sets and unions #421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
stage <- master
Add support for universal sets and unions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| info % table info | ||
| attributes % array of attributes | ||
| distinct=false% whether to select all the elements or only distinct ones | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| info % table info | |
| attributes % array of attributes | |
| distinct=false% whether to select all the elements or only distinct ones | |
| info % table info | |
| attributes % array of attributes | |
| distinct=false % whether to select all the elements or only distinct ones | 
|  | ||
| % promote the keys | ||
| for iAttr = 1:numel(varargin) | ||
| %renamed attribute | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| %renamed attribute | |
| % renamed attribute | 
| if ~isempty(toks) | ||
| name = toks{1}{2}; | ||
| else | ||
| %computed attribute | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| %computed attribute | |
| % computed attribute | 
| if ~isempty(toks) | ||
| name = toks{1}{2}; | ||
| else | ||
| %regular attribute | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| %regular attribute | |
| % regular attribute | 
| assert(isa(arg, 'dj.internal.GeneralRelvar'),... | ||
| 'restriction requires a relvar as operand'); | ||
|  | ||
| % self = init(dj.internal.GeneralRelvar, 'U', {self, arg, 0}); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove all instances commented code
| % self = init(dj.internal.GeneralRelvar, 'U', {self, arg, 0}); | 
|  | ||
|  | ||
| % Unions may only share primary, but not secondary, keys | ||
| testCase.verifyError(@() count(University.Student() | University.Student()), 'DataJoint:invalidUnion'); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| testCase.verifyError(@() count(University.Student() | University.Student()), 'DataJoint:invalidUnion'); | |
| testCase.verifyError(@() count(University.Student() + University.Student()), 'DataJoint:invalidUnion'); | 
Switch | to +. We are aware that using the + operator raises a warning suggesting to use | instead. This is was due to a convention that no longer applies. We are working on officially switching to +.
| % Unions may only share primary, but not secondary, keys | ||
| testCase.verifyError(@() count(University.Student() | University.Student()), 'DataJoint:invalidUnion'); | ||
| % The primary key of each relation must be the same | ||
| testCase.verifyError(@() count(University.A() | University.Student()), 'DataJoint:invalidUnion'); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| testCase.verifyError(@() count(University.A() | University.Student()), 'DataJoint:invalidUnion'); | |
| testCase.verifyError(@() count(University.A() + University.Student()), 'DataJoint:invalidUnion'); | 
|  | ||
| % A basic union | ||
| testCase.verifyEqual(count(... | ||
| proj(University.Student() & 'student_id<2') | proj(University.Student() & 'student_id>3')),... | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| proj(University.Student() & 'student_id<2') | proj(University.Student() & 'student_id>3')),... | |
| proj(University.Student() & 'student_id<2') + proj(University.Student() & 'student_id>3')),... | 
|  | ||
| % Unions with overlapping primary keys are merged | ||
| testCase.verifyEqual(count(... | ||
| proj(University.Student() & 'student_id<3') | proj(University.Student() & 'student_id>1 AND student_id<4')),... | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| proj(University.Student() & 'student_id<3') | proj(University.Student() & 'student_id>1 AND student_id<4')),... | |
| proj(University.Student() & 'student_id<3') + proj(University.Student() & 'student_id>1 AND student_id<4')),... | 
| % Unions with disjoint secondary keys are also merged and filled with NULL | ||
| a = University.Student & 'student_id<4'; | ||
| b = proj(University.Student() & 'student_id>1','"test_val"->test_col'); | ||
| c = fetch(a | b, '*'); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| c = fetch(a | b, '*'); | |
| c = fetch(a + b, '*'); | 
#419