| 125 | /* ****************************** */ |
| 126 | |
| 127 | shared_ptr<ArraySchema> ArraySchemaEvolution::evolve_schema( |
| 128 | const shared_ptr<const ArraySchema>& orig_schema) { |
| 129 | std::lock_guard<std::mutex> lock(mtx_); |
| 130 | if (orig_schema == nullptr) { |
| 131 | throw ArraySchemaEvolutionException( |
| 132 | "Cannot evolve schema; Input array schema is null"); |
| 133 | } |
| 134 | |
| 135 | auto schema = orig_schema->clone(); |
| 136 | |
| 137 | // Add enumerations. Must be done before attributes so that any attributes |
| 138 | // referencing enumerations won't fail to be added. |
| 139 | for (auto& enmr : enumerations_to_add_map_) { |
| 140 | schema->add_enumeration(enmr.second); |
| 141 | } |
| 142 | |
| 143 | for (auto& enmr : enumerations_to_extend_map_) { |
| 144 | schema->extend_enumeration(enmr.second); |
| 145 | } |
| 146 | |
| 147 | // Add attributes. |
| 148 | for (auto& attr : attributes_to_add_) { |
| 149 | schema->add_attribute(attr, false); |
| 150 | } |
| 151 | |
| 152 | // Drop attributes. |
| 153 | for (auto& attr_name : attributes_to_drop_) { |
| 154 | const bool has_attr = schema->has_attribute(attr_name); |
| 155 | if (!has_attr) { |
| 156 | throw ArraySchemaEvolutionException( |
| 157 | "Cannot drop attribute; Input attribute name refers to a dimension " |
| 158 | "or does not exist"); |
| 159 | } |
| 160 | schema->drop_attribute(attr_name); |
| 161 | } |
| 162 | |
| 163 | // Drop enumerations |
| 164 | for (auto& enmr_name : enumerations_to_drop_) { |
| 165 | if (schema->has_enumeration(enmr_name)) { |
| 166 | schema->drop_enumeration(enmr_name); |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | // Set timestamp, if specified |
| 171 | if (std::get<0>(timestamp_range_) != 0) { |
| 172 | schema->generate_uri(timestamp_range_); |
| 173 | } else { |
| 174 | // Generate new schema URI |
| 175 | schema->generate_uri(); |
| 176 | } |
| 177 | |
| 178 | // Get expanded current domain |
| 179 | if (current_domain_to_expand_) { |
| 180 | schema->expand_current_domain(current_domain_to_expand_); |
| 181 | } |
| 182 | |
| 183 | schema->check_without_config(); |
| 184 |
no test coverage detected