Skip to content

Commit 9be55dc

Browse files
added dj.GeneralRelvar/pair to facilitate querying pairs of tupes from a relation
1 parent 38dee75 commit 9be55dc

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

+dj/GeneralRelvar.m

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ function export(self, outfilePrefix, mbytesPerChunk)
322322
tuplesPerChunk = 1;
323323

324324
% enclose in transaction to ensure that LIMIT and OFFSET work correctly
325-
self.schema.conn.startTransaction
325+
self.conn.startTransaction
326326

327327
savedTuples = 0;
328328
savedMegaBytes = 0;
@@ -346,7 +346,7 @@ function export(self, outfilePrefix, mbytesPerChunk)
346346
fileNumber = fileNumber + 1;
347347
end
348348

349-
self.schema.conn.cancelTransaction
349+
self.conn.cancelTransaction
350350

351351
function mbytes = sizeMB(variable) %#ok<INUSD>
352352
mbytes = whos('variable');
@@ -543,18 +543,31 @@ function restrict(self, varargin)
543543
'dj.GeneralRelvar/mtimes requires another relvar as operand'))
544544
end
545545
ret = init(dj.GeneralRelvar, 'join', {self arg});
546-
end
546+
end
547547

548+
function ret = pair(self, varargin)
549+
% dj.GeneralRelvar/pair - a natural join with itself with some
550+
% attributes renamed.
551+
% This facilitates a common use case when pairs of tuples from the
552+
% relation need to be examined.
553+
554+
renamedAttrs1 = cellfun(@(s) sprintf('%s->%s1',s,s), varargin,'uni',false);
555+
renamedAttrs2 = cellfun(@(s) sprintf('%s->%s2',s,s), varargin,'uni',false);
556+
ret = self.pro(renamedAttrs1{:})*self.pro(renamedAttrs2{:});
557+
end
548558

549559

550560
%%%%% DEPRECATED RELATIIONAL OPERATORS (for backward compatibility)
551561
function ret = times(self, arg)
562+
warning 'The relational operator .* (semijoin) will be removed in a future release. Please use & instead.'
552563
ret = self & arg;
553564
end
554565
function ret = rdivide(self, arg)
566+
warning 'The relational operator / (antijoin) will be removed in a future release. Please use - instead.'
555567
ret = self - arg;
556568
end
557569
function ret = plus(self, arg)
570+
warning 'The relational operator + (union) will be removed in a future release. Please use | instead'
558571
ret = self | arg;
559572
end
560573

+dj/Schema.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ function makeClass(self, className)
110110
if numel(existingTable)
111111
fprintf(f, '%s', existingTable.re);
112112
tab = dj.Table([self.package '.' className]);
113-
parents = tab.parents;
113+
parents = cellfun(@(x) self.conn.tableToClass(x), tab.parents, 'uni', false);
114114
else
115115
fprintf(f, '%%{\n');
116116
fprintf(f, '%s.%s (%s) # my newest table\n', self.package, className, tier);

+dj/version.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
function varargout = version
22
% report DataJoint version
33

4-
v = struct('major',2,'minor',7,'bugfix',5);
4+
v = struct('major',2,'minor',7,'bugfix',6);
55

66
if nargout
77
varargout{1}=v;
88
else
99
fprintf('\nDataJoint version %d.%d.%d\n\n', v.major, v.minor, v.bugfix)
10-
end
10+
end

0 commit comments

Comments
 (0)