|
| 1 | +/** |
| 2 | + * @file sc-53970.cc |
| 3 | + * |
| 4 | + * @section LICENSE |
| 5 | + * |
| 6 | + * The MIT License |
| 7 | + * |
| 8 | + * @copyright Copyright (c) 2024 TileDB, Inc. |
| 9 | + * |
| 10 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 11 | + * of this software and associated documentation files (the "Software"), to deal |
| 12 | + * in the Software without restriction, including without limitation the rights |
| 13 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 14 | + * copies of the Software, and to permit persons to whom the Software is |
| 15 | + * furnished to do so, subject to the following conditions: |
| 16 | + * |
| 17 | + * The above copyright notice and this permission notice shall be included in |
| 18 | + * all copies or substantial portions of the Software. |
| 19 | + * |
| 20 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 21 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 22 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 23 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 24 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 25 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 26 | + * THE SOFTWARE. |
| 27 | + * |
| 28 | + * @section DESCRIPTION |
| 29 | + */ |
| 30 | +#include <climits> |
| 31 | + |
| 32 | +#include <tiledb/tiledb> |
| 33 | +#include <tiledb/tiledb_experimental> |
| 34 | + |
| 35 | +#include <test/support/tdb_catch.h> |
| 36 | + |
| 37 | +using namespace tiledb; |
| 38 | + |
| 39 | +static void create_array(const std::string& array_uri); |
| 40 | +static void write_array(const std::string& array_uri); |
| 41 | + |
| 42 | +TEST_CASE( |
| 43 | + "Subarray range expansion bug", |
| 44 | + "[bug][sc53970][subarray-range-expansion][!shouldfail]") { |
| 45 | + std::string array_uri = "test_array_schema_dump"; |
| 46 | + |
| 47 | + // Test setup |
| 48 | + create_array(array_uri); |
| 49 | + write_array(array_uri); |
| 50 | + |
| 51 | + Context ctx; |
| 52 | + Array array(ctx, array_uri, TILEDB_READ); |
| 53 | + |
| 54 | + std::vector<int64_t> dim = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; |
| 55 | + std::vector<float> attr = { |
| 56 | + -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0}; |
| 57 | + |
| 58 | + Query query(ctx, array, TILEDB_READ); |
| 59 | + |
| 60 | + Config cfg; |
| 61 | + cfg["sm.var_offsets.bitsize"] = "64"; |
| 62 | + cfg["sm.var_offsets.mode"] = "elements"; |
| 63 | + cfg["sm.var_offsets.extra_element"] = "true"; |
| 64 | + query.set_config(cfg); |
| 65 | + |
| 66 | + int64_t range1[] = {-1374262780975110845, -1374262780975110845}; |
| 67 | + int64_t range2[] = {-6603679540125901718, 0}; |
| 68 | + |
| 69 | + Subarray subarray(ctx, array); |
| 70 | + subarray.add_range(0, range1[0], range1[1]) |
| 71 | + .add_range(0, range2[0], range2[1]); |
| 72 | + |
| 73 | + query.set_layout(TILEDB_UNORDERED) |
| 74 | + .set_subarray(subarray) |
| 75 | + .set_data_buffer("dim", dim) |
| 76 | + .set_data_buffer("attr", attr); |
| 77 | + REQUIRE(query.submit() == Query::Status::COMPLETE); |
| 78 | + |
| 79 | + // The expected result are a single matching cell of (0, 1507468.6) |
| 80 | + REQUIRE(dim[0] == 0); |
| 81 | + REQUIRE(abs(attr[0] - 1507468.6) < 0.00000005); |
| 82 | + |
| 83 | + // Check we didn't get any extra results |
| 84 | + REQUIRE(dim[1] == -1); |
| 85 | + REQUIRE(attr[1] == -1.0); |
| 86 | +} |
| 87 | + |
| 88 | +void create_array(const std::string& array_uri) { |
| 89 | + Context ctx; |
| 90 | + |
| 91 | + auto obj = Object::object(ctx, array_uri); |
| 92 | + if (obj.type() != Object::Type::Invalid) { |
| 93 | + Object::remove(ctx, array_uri); |
| 94 | + } |
| 95 | + |
| 96 | + auto dim = |
| 97 | + Dimension::create<int64_t>(ctx, "dim", {{INT64_MIN, INT64_MAX - 1}}); |
| 98 | + |
| 99 | + Domain dom(ctx); |
| 100 | + dom.add_dimension(dim); |
| 101 | + |
| 102 | + auto attr = Attribute::create<float>(ctx, "attr"); |
| 103 | + |
| 104 | + ArraySchema schema(ctx, TILEDB_SPARSE); |
| 105 | + |
| 106 | + schema.set_order({{TILEDB_COL_MAJOR, TILEDB_COL_MAJOR}}) |
| 107 | + .set_domain(dom) |
| 108 | + .add_attribute(attr) |
| 109 | + .set_capacity(1713) |
| 110 | + .set_allows_dups(true); |
| 111 | + |
| 112 | + Array::create(array_uri, schema); |
| 113 | +} |
| 114 | + |
| 115 | +void write_array(const std::string& array_uri) { |
| 116 | + Context ctx; |
| 117 | + Array array(ctx, array_uri, TILEDB_WRITE); |
| 118 | + Query query(ctx, array, TILEDB_WRITE); |
| 119 | + |
| 120 | + std::vector<int64_t> dim = {0, -8672700570587565350}; |
| 121 | + std::vector<float> attr = {1507468.6f, -0.0f}; |
| 122 | + |
| 123 | + query.set_layout(TILEDB_UNORDERED) |
| 124 | + .set_data_buffer("dim", dim) |
| 125 | + .set_data_buffer("attr", attr); |
| 126 | + REQUIRE(query.submit() == Query::Status::COMPLETE); |
| 127 | +} |
0 commit comments