Skip to content

Commit 6a1d778

Browse files
committed
Add test for non-global order writes
1 parent bb667d8 commit 6a1d778

1 file changed

Lines changed: 75 additions & 0 deletions

File tree

tiledb/tests/test_query.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,78 @@ def test_global_order_write_multiple_submits(self, sparse):
150150
result = A[1:20]
151151
expected_data = np.arange(100, 120, dtype=np.int64)
152152
np.testing.assert_array_equal(result["a1"], expected_data[:-1])
153+
154+
@pytest.mark.parametrize(
155+
"sparse,order",
156+
[
157+
(True, "U"), # Sparse arrays support unordered
158+
(False, "C"), # Dense arrays support row-major
159+
(False, "F"), # Dense arrays support col-major
160+
],
161+
)
162+
def test_non_global_order_writes(self, sparse, order):
163+
"""Test writing in non-global-order modes where each submit creates a new fragment.
164+
165+
For row-major (C), col-major (F), and unordered (U) modes, finalize is not needed.
166+
Each submit creates a separate fragment - incremental writes are not possible.
167+
168+
Note: C/F (row/col-major) only work for dense arrays, U (unordered) only for sparse.
169+
"""
170+
uri = self.path(
171+
f"test_{order}_order_multiple_{'sparse' if sparse else 'dense'}"
172+
)
173+
174+
# Create schema
175+
dim = tiledb.Dim("d1", domain=(1, 100), tile=10, dtype=np.int32)
176+
dom = tiledb.Domain(dim)
177+
att = tiledb.Attr("a1", dtype=np.int64)
178+
schema = tiledb.ArraySchema(domain=dom, attrs=(att,), sparse=sparse)
179+
tiledb.Array.create(uri, schema)
180+
181+
# Write using Query with multiple submits (each creates a fragment)
182+
with tiledb.open(uri, "w") as A:
183+
if sparse:
184+
# First submit
185+
q1 = tiledb.Query(A, order=order)
186+
coords_batch1 = np.array([1, 5, 10], dtype=np.int32)
187+
data_batch1 = np.array([100, 200, 300], dtype=np.int64)
188+
q1.set_data({"d1": coords_batch1, "a1": data_batch1})
189+
q1.submit()
190+
191+
# Second submit - creates a new fragment
192+
q2 = tiledb.Query(A, order=order)
193+
coords_batch2 = np.array([15, 20], dtype=np.int32)
194+
data_batch2 = np.array([400, 500], dtype=np.int64)
195+
q2.set_data({"d1": coords_batch2, "a1": data_batch2})
196+
q2.submit()
197+
else:
198+
# First submit
199+
q1 = tiledb.Query(A, order=order)
200+
q1.set_subarray_ranges([(1, 10)])
201+
data_batch1 = np.arange(100, 110, dtype=np.int64)
202+
q1.set_data({"a1": data_batch1})
203+
q1.submit()
204+
205+
# Second submit - creates a new fragment
206+
q2 = tiledb.Query(A, order=order)
207+
q2.set_subarray_ranges([(11, 20)])
208+
data_batch2 = np.arange(110, 120, dtype=np.int64)
209+
q2.set_data({"a1": data_batch2})
210+
q2.submit()
211+
212+
# Verify two fragments were created (one per submit)
213+
fragments_info = tiledb.array_fragments(uri)
214+
assert len(fragments_info) == 2
215+
216+
# Verify data
217+
with tiledb.open(uri, "r") as A:
218+
if sparse:
219+
result = A[:]
220+
expected_data = np.array([100, 200, 300, 400, 500], dtype=np.int64)
221+
expected_coords = np.array([1, 5, 10, 15, 20], dtype=np.int32)
222+
np.testing.assert_array_equal(result["a1"], expected_data)
223+
np.testing.assert_array_equal(result["d1"], expected_coords)
224+
else:
225+
result = A[1:20]
226+
expected_data = np.arange(100, 120, dtype=np.int64)
227+
np.testing.assert_array_equal(result["a1"], expected_data[:-1])

0 commit comments

Comments
 (0)