-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backwards compatibility: handle 0 chunk var tiles. (#4310)
* Backwards compatibility: handle 0 chunk var tiles. In arrays with format version earlier than 10, it was possible to create a var file with zero chunks when all cells had an empty string value. This caused segfaults with later versions of the library and is fixed with this change. --- TYPE: BUG DESC: Backwards compatibility: handle 0 chunk var tiles. * Add unit tests. * Adding array creation code. * Move test to regression tests. * Adding note for mac m1. * Update test/regression/CMakeLists.txt Co-authored-by: Isaiah Norton <[email protected]> * Update test/regression/targets/sc-33480.cc Co-authored-by: Isaiah Norton <[email protected]> --------- Co-authored-by: Isaiah Norton <[email protected]>
- Loading branch information
Showing
16 changed files
with
242 additions
and
35 deletions.
There are no files selected for viewing
Empty file.
Binary file added
BIN
+1.55 KB
...__1693562063524_1693562063524_0fcdefaa40d34ff2a4b09153472fbdc2_10/__fragment_metadata.tdb
Binary file not shown.
Binary file added
BIN
+24 Bytes
...o_var_chunks_v10/__1693562063524_1693562063524_0fcdefaa40d34ff2a4b09153472fbdc2_10/a0.tdb
Binary file not shown.
Binary file added
BIN
+53 Bytes
...o_var_chunks_v10/__1693562063524_1693562063524_0fcdefaa40d34ff2a4b09153472fbdc2_10/d0.tdb
Binary file not shown.
Binary file added
BIN
+8 Bytes
...r_chunks_v10/__1693562063524_1693562063524_0fcdefaa40d34ff2a4b09153472fbdc2_10/d0_var.tdb
Binary file not shown.
Empty file.
Binary file added
BIN
+152 Bytes
...ro_var_chunks_v10/__schema/__1693562063520_1693562063520_87f6551825c94139b3000f0d6b7c0ac0
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#include <tiledb/tiledb> | ||
|
||
#include <test/support/tdb_catch.h> | ||
|
||
using namespace tiledb; | ||
|
||
TEST_CASE("0 var chunks", "[unfiltering][bug][sc33480]") { | ||
// NOTE: This regression test will not fail on a Mac M1 because on that | ||
// platform, a division by 0 will not generate a segfault but return 0. | ||
|
||
// The following code created the zero_var_chunks_v10 array for this test. | ||
// #include <tiledb/tiledb> | ||
// using namespace tiledb; | ||
|
||
// int main() { | ||
// Context ctx; | ||
|
||
// Domain domain(ctx); | ||
// domain.add_dimension( | ||
// Dimension::create(ctx, "d", TILEDB_STRING_ASCII, nullptr, nullptr)); | ||
// ArraySchema schema(ctx, TILEDB_SPARSE); | ||
// schema.set_domain(domain).set_order({{TILEDB_ROW_MAJOR, | ||
// TILEDB_ROW_MAJOR}}); schema.add_attribute(Attribute::create<int32_t>(ctx, | ||
// "a")); Array::create("zero_var_chunks_v10", schema); | ||
|
||
// std::vector<char> d = {}; | ||
// std::vector<uint64_t> d_offsets = {0}; | ||
// std::vector<int32_t> data = {1}; | ||
|
||
// Array array(ctx, "zero_var_chunks_v10", TILEDB_WRITE); | ||
// Query query(ctx, array, TILEDB_WRITE); | ||
// query.set_layout(TILEDB_UNORDERED) | ||
// .set_data_buffer("a", data) | ||
// .set_data_buffer("d", d) | ||
// .set_offsets_buffer("d", d_offsets); | ||
// query.submit(); | ||
// array.close(); | ||
// return 0; | ||
// } | ||
|
||
// This array has a var file for the "d" dimension with 0 chunks. This was | ||
// only possible if a fragment had all empty values for a variable string in | ||
// versions earlier than v10. | ||
std::string array_name( | ||
std::string(TILEDB_TEST_INPUTS_DIR) + "/arrays/zero_var_chunks_v10"); | ||
Context ctx; | ||
|
||
// Prepare the array for reading. | ||
Array array(ctx, array_name, TILEDB_READ); | ||
|
||
// Prepare the query. | ||
Query query(ctx, array, TILEDB_READ); | ||
|
||
// Prepare the vector that will hold the result. | ||
std::vector<char> d(10); | ||
std::vector<uint64_t> d_offsets(10); | ||
std::vector<int32_t> a(10); | ||
query.set_layout(TILEDB_UNORDERED) | ||
.set_data_buffer("d", d) | ||
.set_offsets_buffer("d", d_offsets) | ||
.set_data_buffer("a", a); | ||
|
||
// Submit the query and close the array. | ||
query.submit(); | ||
array.close(); | ||
|
||
// Validate the results. This array has one cell at coordinate '' with | ||
// value 1. | ||
auto res = query.result_buffer_elements(); | ||
CHECK(res["d"].first == 1); | ||
CHECK(res["d"].second == 0); | ||
CHECK(res["a"].first == 0); | ||
CHECK(res["a"].second == 1); | ||
CHECK(d_offsets[0] == 0); | ||
CHECK(a[0] == 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,3 +28,5 @@ include(common NO_POLICY_SCOPE) | |
include(object_library) | ||
|
||
add_subdirectory(aggregators) | ||
|
||
add_test_subdirectory() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# | ||
# tiledb/sm/query/readers/test/CMakeLists.txt | ||
# | ||
# The MIT License | ||
# | ||
# Copyright (c) 2023 TileDB, Inc. | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in | ||
# all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
# THE SOFTWARE. | ||
# | ||
|
||
include(unit_test) | ||
|
||
commence(unit_test readers) | ||
this_target_sources(main.cc unit_reader_base.cc) | ||
conclude(unit_test) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/** | ||
* @file unit_reader_base.cc | ||
* | ||
* @section LICENSE | ||
* | ||
* The MIT License | ||
* | ||
* @copyright Copyright (c) 2023 TileDB, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
* | ||
* @section DESCRIPTION | ||
* | ||
* Tests the `ReaderBase` class. | ||
*/ | ||
|
||
#include "tiledb/common/common.h" | ||
#include "tiledb/sm/query/readers/reader_base.h" | ||
|
||
#include <test/support/tdb_catch.h> | ||
|
||
using namespace tiledb::sm; | ||
|
||
TEST_CASE( | ||
"ReaderBase::compute_chunk_min_max valid inputs", | ||
"[readerbase][compute_chunk_min_max][valid]") { | ||
uint64_t num_chunks{0}; | ||
uint64_t num_range_threads{2}; | ||
uint64_t thread_idx{0}; | ||
std::tuple<uint64_t, uint64_t> expected_min_max{0, 0}; | ||
|
||
SECTION("Three chunks first thread") { | ||
num_chunks = 3; | ||
thread_idx = 0; | ||
expected_min_max = {0, 2}; | ||
} | ||
|
||
SECTION("Three chunks second thread") { | ||
num_chunks = 3; | ||
thread_idx = 1; | ||
expected_min_max = {2, 3}; | ||
} | ||
|
||
SECTION("0 chunks") { | ||
num_chunks = 0; | ||
thread_idx = 1; | ||
expected_min_max = {0, 0}; | ||
} | ||
|
||
auto res = ReaderBase::compute_chunk_min_max( | ||
num_chunks, num_range_threads, thread_idx); | ||
CHECK(res == expected_min_max); | ||
} | ||
|
||
TEST_CASE( | ||
"ReaderBase::compute_chunk_min_max invalid inputs", | ||
"[readerbase][compute_chunk_min_max][invalid]") { | ||
SECTION("No range threads") { | ||
CHECK_THROWS_WITH( | ||
ReaderBase::compute_chunk_min_max(10, 0, 0), | ||
"Number of range thread value is 0"); | ||
} | ||
|
||
SECTION("Invalid range thread index") { | ||
CHECK_THROWS_WITH( | ||
ReaderBase::compute_chunk_min_max(10, 1, 1), | ||
"Range thread index is greater than number of range threads"); | ||
} | ||
} |