Skip to content

Commit

Permalink
fixed issue #30. dj.AutoPopulate can now populate ancestor tables rec…
Browse files Browse the repository at this point in the history
…ursively.
  • Loading branch information
dimitri-yatsenko committed Apr 14, 2014
1 parent 4287636 commit 04e1f61
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 12 deletions.
43 changes: 34 additions & 9 deletions +dj/AutoPopulate.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,29 @@
% [failedKeys, errs] = populate(tp.OriMaps); % skip errors and return their list
%
% See also dj.AutoPopulate/parpopulate

if ~dj.set('populateAncestors')
rels = self;
else
% get all ancestors to be populated before self
assert(nargout==0, ...
'parpopulate cannot return output when populateAncestors is true')
rels = cellfun(@feval, self.ancestors, 'uni', false);
rels = rels(cellfun(@(x) isa(x,'dj.AutoPopulate'), rels));
end

self.schema.conn.cancelTransaction % rollback any unfinished transaction
self.useReservations = false;
self.populateSanityChecks
self.executionEngine = @(key, fun, args) fun(args{:});
[varargout{1:nargout}] = self.populate_(varargin{:});

for i=1:length(rels)
rels{i}.useReservations = false;
rels{i}.populateSanityChecks
rels{i}.executionEngine = @(key, fun, args) fun(args{:});
[varargout{1:nargout}] = rels{i}.populate_(varargin{:});
end
end


function varargout = parpopulate(self, varargin)
function parpopulate(self, varargin)
% dj.AutoPopulate/parpopulate works identically to dj.AutoPopulate/populate
% except that it uses a job reservation mechanism to enable multiple
% processes to populate the same table in parallel without collision.
Expand Down Expand Up @@ -124,13 +137,25 @@
%
% See also dj.AutoPopulate/populate

if ~dj.set('populateAncestors')
rels = self;
else
% get all ancestors to be populated before self
rels = cellfun(@feval, self.ancestors, 'uni', false);
rels = rels(cellfun(@(x) isa(x,'dj.AutoPopulate'), rels));
end

self.schema.conn.cancelTransaction % rollback any unfinished transaction
self.useReservations = true;
self.populateSanityChecks
self.executionEngine = @(key, fun, args) fun(args{:});
[varargout{1:nargout}] = self.populate_(varargin{:});

for i=1:length(rels)
rels{i}.useReservations = true;
rels{i}.populateSanityChecks
rels{i}.executionEngine = @(key, fun, args) fun(args{:});
rels{i}.populate_(varargin{:});
end
end


function taskCore(self, key)
% The work unit that is submitted to the cluster
% or executed locally
Expand Down
11 changes: 11 additions & 0 deletions +dj/Relvar.m
Original file line number Diff line number Diff line change
Expand Up @@ -282,5 +282,16 @@ function update(self, attrname, value)
self.schema.conn.query(queryStr, value{:})
end


function export(self, declarationFile, dataFile, varargin)
[limit, args] = makeLimitClause(varargin{:});
self = self.pro(args{:});
[header, sql] = self.compile;
ret = self.conn.query(sprintf('SELECT %s FROM %s%s', ...
header.sql, sql, limit));
ret = dj.struct.fromFields(ret);

end

end
end
2 changes: 1 addition & 1 deletion +dj/Table.m
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
map = containers.Map('KeyType','char','ValueType','uint16');
recurse(self,0)
levels = map.values;
[~,order] = sort([levels{:}]);
[~,order] = sort([levels{:}],'descend');
list = map.keys;
list = list(order);

Expand Down
3 changes: 2 additions & 1 deletion +dj/set.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
'reconnectTimedoutTransaction', true, ...
'populateCheck', true, ...
'tableErdRadius', [2 1], ...
'verbose', false ...
'verbose', false, ...
'populateAncestors', false ...
);
end

Expand Down
2 changes: 1 addition & 1 deletion +dj/version.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function varargout = version
% report DataJoint version

v = struct('major',2,'minor',7,'bugfix',3);
v = struct('major',2,'minor',7,'bugfix',4);

if nargout
varargout{1}=v;
Expand Down

0 comments on commit 04e1f61

Please sign in to comment.