* @brief Create a TileDB array with the following characteristics. * - Two dimensions called rows and cols. Each dimension is of type * int, and has a lower bound of 1 and a higher bound of 20, inclusive. * - Two attributes called "a" (of type int) and "b" (of type float). * - Tile size of 4. * * The data in the array is set as follows. On attribute a, each cell's value * is 0 if the column
| 94 | * @param array_uri URI of array to create. |
| 95 | */ |
| 96 | void create_array( |
| 97 | Context& ctx, |
| 98 | tiledb_array_type_t array_type, |
| 99 | bool set_dups, |
| 100 | bool add_utf8_attr, |
| 101 | std::vector<int>& a_data_read, |
| 102 | std::vector<float>& b_data_read, |
| 103 | const std::string& array_uri = array_name) { |
| 104 | Domain domain(ctx); |
| 105 | domain.add_dimension(Dimension::create<int>(ctx, "rows", {{1, num_rows}}, 4)) |
| 106 | .add_dimension(Dimension::create<int>(ctx, "cols", {{1, num_rows}}, 4)); |
| 107 | ArraySchema schema(ctx, array_type); |
| 108 | if (set_dups) { |
| 109 | schema.set_allows_dups(true); |
| 110 | } |
| 111 | schema.set_domain(domain).set_order({{TILEDB_ROW_MAJOR, TILEDB_ROW_MAJOR}}); |
| 112 | Attribute attr_a = Attribute::create<int>(ctx, "a"); |
| 113 | Attribute attr_b = Attribute::create<float>(ctx, "b"); |
| 114 | if (array_type == TILEDB_DENSE) { |
| 115 | attr_a.set_fill_value(&a_fill_value, sizeof(int)); |
| 116 | attr_b.set_fill_value(&b_fill_value, sizeof(float)); |
| 117 | } else { |
| 118 | schema.set_capacity(16); |
| 119 | } |
| 120 | schema.add_attribute(attr_a); |
| 121 | schema.add_attribute(attr_b); |
| 122 | if (add_utf8_attr) { |
| 123 | Attribute attr_c = Attribute::create(ctx, "c", TILEDB_STRING_UTF8); |
| 124 | attr_c.set_cell_val_num(TILEDB_VAR_NUM); |
| 125 | attr_c.set_nullable(true); |
| 126 | schema.add_attribute(attr_c); |
| 127 | } |
| 128 | Array::create(array_uri, schema); |
| 129 | |
| 130 | // Write some initial data and close the array. |
| 131 | std::vector<int> row_dims; |
| 132 | std::vector<int> col_dims; |
| 133 | std::vector<int> a_data; |
| 134 | std::vector<float> b_data; |
| 135 | std::vector<char> c_data; |
| 136 | std::vector<uint64_t> c_offsets; |
| 137 | std::vector<uint8_t> c_validity; |
| 138 | |
| 139 | std::vector<std::string> c_choices = { |
| 140 | std::string("bird"), |
| 141 | std::string("bunny"), |
| 142 | std::string("cat"), |
| 143 | std::string("dog")}; |
| 144 | |
| 145 | for (int i = 0; i < num_rows * num_rows; ++i) { |
| 146 | int row = (i / num_rows) + 1; |
| 147 | int col = (i % num_rows) + 1; |
| 148 | int a = i % 2 == 1 ? 0 : 1; |
| 149 | float b; |
| 150 | std::string c_str; |
| 151 | if (i % 8 == 0) { |
| 152 | // b = 3.4 |
| 153 | b = 3.4f; |
no test coverage detected