|
| 1 | +/** |
| 2 | + * @file sc-53791.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 | + |
| 29 | +#include <stdio.h> |
| 30 | +#include <stdlib.h> |
| 31 | +#include <tiledb/tiledb.h> |
| 32 | +#include <tiledb/tiledb> |
| 33 | +#include <tiledb/tiledb_experimental> |
| 34 | +#include <vector> |
| 35 | + |
| 36 | +#include <catch2/catch_template_test_macros.hpp> |
| 37 | + |
| 38 | +using namespace tiledb; |
| 39 | + |
| 40 | +static void create_array(Context& ctx, const char* array_name) { |
| 41 | + auto dx = Dimension::create<uint64_t>(ctx, "x", {{1, 100}}, 10); |
| 42 | + |
| 43 | + // Create domain |
| 44 | + Domain domain(ctx); |
| 45 | + domain.add_dimension(dx); |
| 46 | + |
| 47 | + // Create a single attribute "a" so each (i,j) cell can store a character |
| 48 | + Attribute a(ctx, "a", TILEDB_UINT64); |
| 49 | + a.set_cell_val_num(TILEDB_VAR_NUM); |
| 50 | + a.set_nullable(true); |
| 51 | + |
| 52 | + // Create array schema |
| 53 | + ArraySchema schema(ctx, TILEDB_SPARSE); |
| 54 | + schema.set_domain(domain); |
| 55 | + schema.set_cell_order(TILEDB_ROW_MAJOR); |
| 56 | + schema.set_tile_order(TILEDB_ROW_MAJOR); |
| 57 | + schema.add_attribute(a); |
| 58 | + |
| 59 | + // Create array |
| 60 | + Array::create(array_name, schema); |
| 61 | +} |
| 62 | + |
| 63 | +static void write_array(Context& ctx, const char* array_name) { |
| 64 | + // Open array for writing |
| 65 | + Array array(ctx, array_name, TILEDB_WRITE); |
| 66 | + |
| 67 | + // Data |
| 68 | + std::vector<uint64_t> x = {1}; |
| 69 | + std::vector<uint64_t> a = {0}; |
| 70 | + std::vector<uint64_t> a_offsets = {0}; |
| 71 | + std::vector<uint8_t> a_validity = {1}; |
| 72 | + |
| 73 | + Query query(ctx, array); |
| 74 | + query.set_data_buffer("x", x) |
| 75 | + .set_data_buffer("a", a) |
| 76 | + .set_offsets_buffer("a", a_offsets) |
| 77 | + .set_validity_buffer("a", a_validity); |
| 78 | + |
| 79 | + query.submit(); |
| 80 | + query.finalize(); |
| 81 | + array.close(); |
| 82 | +} |
| 83 | + |
| 84 | +static std::pair<uint64_t, uint64_t> query_null_count( |
| 85 | + Context& ctx, const char* array_name) { |
| 86 | + // note, use C API because the CPP API doesn't seem to have Min yet |
| 87 | + Array array(ctx, array_name, TILEDB_READ); |
| 88 | + |
| 89 | + Query query(ctx, array); |
| 90 | + query.set_layout(TILEDB_UNORDERED); |
| 91 | + |
| 92 | + QueryChannel default_channel = QueryExperimental::get_default_channel(query); |
| 93 | + default_channel.apply_aggregate("Count", CountOperation()); |
| 94 | + ChannelOperation operation = |
| 95 | + QueryExperimental::create_unary_aggregate<NullCountOperator>(query, "a"); |
| 96 | + default_channel.apply_aggregate("Null Count", operation); |
| 97 | + |
| 98 | + std::vector<uint64_t> count(1); |
| 99 | + query.set_data_buffer("Count", count); |
| 100 | + |
| 101 | + std::vector<uint64_t> null_count(1); |
| 102 | + query.set_data_buffer("Null Count", null_count); |
| 103 | + |
| 104 | + /* |
| 105 | + * FIXME: this gives an error |
| 106 | + * |
| 107 | + * Error: Caught std::exception: FragmentMetadata: Trying to |
| 108 | + * access tile min metadata that's not present |
| 109 | + */ |
| 110 | + query.submit(); |
| 111 | + query.finalize(); |
| 112 | + |
| 113 | + return std::make_pair(count[0], null_count[0]); |
| 114 | +} |
| 115 | + |
| 116 | +bool array_exists(Context& ctx, const char* uri); |
| 117 | + |
| 118 | +TEST_CASE( |
| 119 | + "SC-53791 var value TILEDB_UINT64 does not work", |
| 120 | + "[regression][bug][sc-53791][!shouldfail]") { |
| 121 | + Context ctx; |
| 122 | + std::string uri("sc-53791-uint64-var"); |
| 123 | + |
| 124 | + if (!array_exists(ctx, uri.c_str())) { |
| 125 | + create_array(ctx, uri.c_str()); |
| 126 | + write_array(ctx, uri.c_str()); |
| 127 | + } |
| 128 | + |
| 129 | + /* |
| 130 | + * See the FIXME above. `submit` throws an exception |
| 131 | + * due to missing data but we expect it to return normally. |
| 132 | + * |
| 133 | + * When the bug is fixed, delete `CHECK_NOTHROW` and `if (false)`. |
| 134 | + */ |
| 135 | + CHECK_NOTHROW(query_null_count(ctx, uri.c_str())); |
| 136 | + if (false) { |
| 137 | + const auto counts = query_null_count(ctx, uri.c_str()); |
| 138 | + REQUIRE(counts.first == 1); |
| 139 | + REQUIRE(counts.second == 0); |
| 140 | + } |
| 141 | +} |
0 commit comments