Skip to content

Commit 35b5d30

Browse files
committed
Fix buffer exclusion when specifying attribute subset
1 parent 163705c commit 35b5d30

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

tiledb/core.cc

+3
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,9 @@ class PyQuery {
566566
// schema.attributes() is unordered, but we need to return ordered results
567567
for (size_t attr_idx = 0; attr_idx < schema.attribute_num(); attr_idx++) {
568568
auto attr = schema.attribute(attr_idx);
569+
if (std::find(attrs_.begin(), attrs_.end(), attr.name()) == attrs_.end()) {
570+
continue;
571+
}
569572
alloc_buffer(attr.name());
570573
}
571574

tiledb/multirange_indexing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def __getitem__(self, idx):
110110

111111
schema = self.schema
112112
dom = self.schema.domain
113-
attr_names = tuple(self.schema.attr(i).name for i in range(self.schema.nattr))
113+
attr_names = tuple(self.schema.attr(i)._internal_name for i in range(self.schema.nattr))
114114

115115
coords = None
116116
order = 'C' # TILEDB_ROW_MAJOR

tiledb/tests/test_libtiledb.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,7 @@ def test_multiple_attributes(self):
11311131
with tiledb.DenseArray(self.path("foo"), mode='w', ctx=ctx) as T:
11321132
T[:] = V
11331133

1134+
import tiledb.core as core
11341135
with tiledb.DenseArray(self.path("foo"), mode='r', ctx=ctx) as T:
11351136
R = T[:]
11361137
assert_array_equal(V["ints"], R["ints"])
@@ -1155,6 +1156,16 @@ def test_multiple_attributes(self):
11551156
with self.assertRaises(tiledb.TileDBError):
11561157
T.query(attrs=("unknown"))[:]
11571158

1159+
# Ensure that query only returns specified attributes
1160+
q = core.PyQuery(ctx, T, ("ints",), False, 0)
1161+
q.set_ranges([[(0,1)]])
1162+
q.submit()
1163+
r = q.results()
1164+
self.assertTrue("ints" in r)
1165+
self.assertTrue("floats" not in r)
1166+
del q
1167+
1168+
11581169
with tiledb.DenseArray(self.path("foo"), mode='w', ctx=ctx) as T:
11591170
# check error ncells length
11601171
V["ints"] = V["ints"][1:2].copy()
@@ -1166,6 +1177,7 @@ def test_multiple_attributes(self):
11661177
with self.assertRaises(tiledb.TileDBError):
11671178
T[:] = V
11681179

1180+
11691181
def test_array_2d_s1(self):
11701182
# This array is currently read back with dtype object
11711183
A = np.array([['A', 'B'], ['C', '']], dtype='S')
@@ -2835,7 +2847,6 @@ def test_tiledb_py_0_6_anon_attr(self):
28352847
os.path.join(fragment_path, "_attr_.tdb"),
28362848
os.path.join(fragment_path, "__attr.tdb")
28372849
)
2838-
28392850
with tiledb.open(path) as A:
28402851
self.assertEqual(A.schema.attr(0).name, "")
28412852
self.assertEqual(A.schema.attr(0)._internal_name, "__attr")

tiledb/tests/test_multi_index.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ def test_multirange_1d_dense_vectorized(self):
583583
dom = tiledb.Domain(tiledb.Dim(domain=(0, 999), tile=1000,
584584
dtype=np.uint32, ctx=ctx),
585585
ctx=ctx)
586-
attrs = tiledb.Attr(name="U", dtype=np.float64, ctx=ctx)
586+
attrs = tiledb.Attr(name='', dtype=np.float64, ctx=ctx)
587587

588588
schema = tiledb.ArraySchema(domain=dom, attrs=(attrs,), sparse=False, ctx=ctx)
589589
tiledb.DenseArray.create(path, schema)
@@ -600,7 +600,7 @@ def test_multirange_1d_dense_vectorized(self):
600600
res = A.multi_index[idxs]
601601
assert_array_equal(
602602
data[idxs],
603-
res['U']
603+
res['']
604604
)
605605

606606
def test_multirange_2d_dense_float(self):

0 commit comments

Comments
 (0)