Skip to content

Commit 34f63f5

Browse files
Merge pull request #395 from datajoint/stage2
add function to dj.config to read values with 32-bit dimensions
2 parents ad36667 + df822ed commit 34f63f5

File tree

9 files changed

+67
-11
lines changed

9 files changed

+67
-11
lines changed

+dj/+internal/Settings.m

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
'queryPopulate_check', true, ...
2020
'queryPopulate_ancestors', false, ...
2121
'queryBigint_to_double', false, ...
22-
'queryIgnore_extra_insert_fields', false ... when false, throws an error in `insert(self, tuple)` when tuple has extra fields.
22+
'queryIgnore_extra_insert_fields', false, ... when false, throws an error in `insert(self, tuple)` when tuple has extra fields.
23+
'use_32bit_dims', false ...
2324
)
2425
end
2526
properties
@@ -58,6 +59,10 @@
5859
if nargin == 2
5960
new_state = subsasgn(current_state, subscript, value);
6061
stateAccess('set', new_state);
62+
if strcmp(subscript(1).subs, 'use_32bit_dims')
63+
ternary = @(varargin)varargin{end-varargin{1}};
64+
setenv('MYM_USE_32BIT_DIMS', ternary(value, 'true', 'false'));
65+
end
6166
end
6267
end
6368
function out = restore()

+dj/Relvar.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function cleanup(self)
9292
@(x) strcmp(x.from, rels(ix).fullTableName), ...
9393
self.schema.conn.foreignKeys, 'uni', true);
9494
fks = self.schema.conn.foreignKeys(fk_index);
95-
if ~all(fks.aliased)
95+
if ~all([fks.aliased])
9696
% If matched foreign keys are not aliased, no renaming
9797
% necessary. Restrict table based on normal projection.
9898
rels(ix).restrict(proj(rels(i)));

+dj/version.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function varargout = version
22
% report DataJoint version
33

4-
v = struct('major', 3, 'minor', 4, 'bugfix', 3);
4+
v = struct('major', 3, 'minor', 5, 'bugfix', 0);
55

66
if nargout
77
varargout{1}=v;

docs-parts/intro/Releases_lang1.rst

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
3.5.0 -- March 21, 2022
2+
--------------------------
3+
* Bugfix: Cascading delete for renamed foreign keys (#379) PR #386
4+
* Minor: Add renaming the same attribute multiple times within a single projection PR #386
5+
* Minor: Add config for reading values with 32-bit dimensions (datajoint/mym#86) PR #395
6+
17
3.4.3 -- May 28, 2021
28
--------------------------
39
* Bugfix: `dj.config` omits default values when loading new config immediately after MATLAB boot (#359) PR #369

tests/Main.m

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
TestRelationalOperand & ...
1313
TestSchema & ...
1414
TestTls & ...
15-
TestUuid
15+
TestUuid & ...
16+
TestBlob
1617
end

tests/TestBlob.m

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
classdef TestBlob < Prep
2+
methods (Test)
3+
function TestBlob_test32BitRead(testCase)
4+
st = dbstack;
5+
disp(['---------------' st(1).name '---------------']);
6+
value = ['6D596D005302000000010000000100000004000000686974730073696465730074' ...
7+
'61736B73007374616765004D00000041020000000100000007000000060000000000000' ...
8+
'0000000000000F8FF000000000000F03F000000000000F03F0000000000000000000000' ...
9+
'000000F03F0000000000000000000000000000F8FF23000000410200000001000000070' ...
10+
'0000004000000000000006C006C006C006C00720072006C002300000041020000000100' ...
11+
'00000700000004000000000000006400640064006400640064006400250000004102000' ...
12+
'0000100000008000000040000000000000053007400610067006500200031003000'];
13+
hexstring = value';
14+
reshapedString = reshape(hexstring,2,length(value)/2);
15+
hexMtx = reshapedString.';
16+
decMtx = hex2dec(hexMtx);
17+
packed = uint8(decMtx);
18+
19+
data = struct;
20+
data.stage = 'Stage 10';
21+
data.tasks = 'ddddddd';
22+
data.sides = 'llllrrl';
23+
data.hits = [NaN,1,1,0,1,0,NaN];
24+
25+
dj.config('use_32bit_dims', true);
26+
unpacked = mym('deserialize', packed);
27+
dj.config('use_32bit_dims', false);
28+
29+
testCase.verifyEqual(unpacked, data);
30+
end
31+
end
32+
end

tests/TestConfig.m

+10
Original file line numberDiff line numberDiff line change
@@ -247,5 +247,15 @@ function validateEnvVarConfig(type, values)
247247
setenv('DJ_INIT', '');
248248
dj.config.restore;
249249
end
250+
function TestConfig_testUse32BitDims(testCase)
251+
st = dbstack;
252+
disp(['---------------' st(1).name '---------------']);
253+
dj.config('use_32bit_dims', true);
254+
testCase.verifyEqual(getenv('MYM_USE_32BIT_DIMS'), 'true');
255+
dj.config('use_32bit_dims', false);
256+
testCase.verifyEqual(getenv('MYM_USE_32BIT_DIMS'), 'false');
257+
258+
dj.config.restore;
259+
end
250260
end
251261
end

tests/TestDelete.m

+8-7
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function TestDelete_testRenamedDelete(testCase)
3636
testCase.verifyEqual(...
3737
length(fetch(Company.Machine & struct('employee_id', 'shan'))), 0);
3838
end
39-
function TestDelete_testTwoFKOnePK(testCase)
39+
function TestDelete_testThreeFKOnePK(testCase)
4040
st = dbstack;
4141
disp(['---------------' st(1).name '---------------']);
4242
% https:%github.com/datajoint/datajoint-matlab/issues/379
@@ -46,23 +46,24 @@ function TestDelete_testTwoFKOnePK(testCase)
4646
dj.createSchema(package,[testCase.test_root '/test_schemas'], ...
4747
[testCase.PREFIX '_testlab']);
4848

49-
users = [{'user0'; 'user1'; 'user2'}];
49+
users = [{'user0'; 'user1'; 'user2'; 'user3'}];
5050

5151
insert(TestLab.User, users);
5252

53-
duty = [{'2020-01-01','user0','user1'},
54-
{'2020-01-02','user1','user2'},
55-
{'2020-12-31','user0','user2'}];
53+
duty = [{'2020-01-01','user0','user2', 'user1'},
54+
{'2020-01-02','user0','user1', 'user2'},
55+
{'2020-12-30','user1','user2', 'user0'},
56+
{'2020-12-31','user0','user2', 'user3'}];
5657

5758
insert(TestLab.Duty, duty);
5859

5960
key.user_id = 'user1';
6061
del(TestLab.User & key);
6162

62-
testCase.verifyEqual(length(fetch(TestLab.User)), 2);
63+
testCase.verifyEqual(length(fetch(TestLab.User)), 3);
6364
testCase.verifyEqual(length(fetch(TestLab.Duty)), 1);
6465
testCase.verifyEqual(length(fetch(TestLab.User & 'user_id = "user1"')), 0);
65-
testCase.verifyEqual(length(fetch(TestLab.Duty & 'duty_first = "user1" OR duty_second = "user1"')), 0);
66+
testCase.verifyEqual(length(fetch(TestLab.Duty & 'duty_first = "user1" OR duty_second = "user1" OR duty_third = "user1"')), 0);
6667
end
6768
end
6869
end

tests/test_schemas/+TestLab/Duty.m

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
-----
44
(duty_first) -> TestLab.User(user_id)
55
(duty_second) -> TestLab.User(user_id)
6+
(duty_third) -> TestLab.User(user_id)
67
%}
78

89
classdef Duty < dj.Manual

0 commit comments

Comments
 (0)