|
20 | 20 |
|
21 | 21 | #include <memory> |
22 | 22 | #include <optional> |
| 23 | +#include <set> |
23 | 24 | #include <string> |
24 | 25 | #include <vector> |
25 | 26 |
|
@@ -218,17 +219,107 @@ TEST_F(IndexManifestFileHandlerTest, GlobalCombinerOverwritesDuplicateAddedEntri |
218 | 219 | ASSERT_EQ(written_entries[0].index_file->RowCount(), 20); |
219 | 220 | } |
220 | 221 |
|
221 | | -TEST_F(IndexManifestFileHandlerTest, DvWithBucketUnawareModeReturnsNotImplemented) { |
| 222 | +TEST_F(IndexManifestFileHandlerTest, GlobalDvCombinerReplacesIndexFileInBucketUnawareMode) { |
222 | 223 | ASSERT_OK_AND_ASSIGN(auto index_manifest_file, CreateManifestFile(/*bucket_mode=*/-1)); |
223 | 224 |
|
224 | 225 | auto partition = BinaryRow::EmptyRow(); |
| 226 | + // an unaware bucket table writes every index file under bucket 0, so only the index file |
| 227 | + // name tells the two entries apart |
| 228 | + std::vector<IndexManifestEntry> previous_entries = { |
| 229 | + MakeDvEntry(FileKind::Add(), partition, /*bucket=*/0, "dv-0", {"data-0.orc"}, 1), |
| 230 | + MakeDvEntry(FileKind::Add(), partition, /*bucket=*/0, "dv-1", {"data-1.orc"}, 1)}; |
| 231 | + |
| 232 | + ASSERT_OK_AND_ASSIGN(std::string previous_manifest, |
| 233 | + IndexManifestFileHandler::Write( |
| 234 | + /*previous_index_manifest=*/std::nullopt, previous_entries, |
| 235 | + /*bucket_mode=*/-1, index_manifest_file.get())); |
| 236 | + |
| 237 | + // updating the vector of data-0.orc replaces its index file, and the data file it covers |
| 238 | + // moves to the new one |
225 | 239 | std::vector<IndexManifestEntry> new_entries = { |
| 240 | + MakeDvEntry(FileKind::Delete(), partition, /*bucket=*/0, "dv-0", {"data-0.orc"}, 1), |
| 241 | + MakeDvEntry(FileKind::Add(), partition, /*bucket=*/0, "dv-0-new", {"data-0.orc"}, 2)}; |
| 242 | + |
| 243 | + ASSERT_OK_AND_ASSIGN( |
| 244 | + std::string current_manifest, |
| 245 | + IndexManifestFileHandler::Write(previous_manifest, new_entries, |
| 246 | + /*bucket_mode=*/-1, index_manifest_file.get())); |
| 247 | + |
| 248 | + std::vector<IndexManifestEntry> written_entries; |
| 249 | + ASSERT_OK(index_manifest_file->Read(current_manifest, /*filter=*/nullptr, &written_entries)); |
| 250 | + ASSERT_EQ(written_entries.size(), 2); |
| 251 | + std::set<std::string> written_file_names; |
| 252 | + for (const auto& entry : written_entries) { |
| 253 | + written_file_names.insert(entry.index_file->FileName()); |
| 254 | + } |
| 255 | + ASSERT_EQ(written_file_names, (std::set<std::string>{"dv-0-new", "dv-1"})); |
| 256 | + |
| 257 | + // the same replacement with the added entry listed first: the delta carries no order the |
| 258 | + // commit path is bound to, so the added entry must not be read as a second vector for |
| 259 | + // data-0.orc just because its delete trails it |
| 260 | + std::vector<IndexManifestEntry> reordered_entries = { |
| 261 | + MakeDvEntry(FileKind::Add(), partition, /*bucket=*/0, "dv-0-newer", {"data-0.orc"}, 3), |
| 262 | + MakeDvEntry(FileKind::Delete(), partition, /*bucket=*/0, "dv-0-new", {"data-0.orc"}, 2)}; |
| 263 | + |
| 264 | + ASSERT_OK_AND_ASSIGN( |
| 265 | + std::string reordered_manifest, |
| 266 | + IndexManifestFileHandler::Write(current_manifest, reordered_entries, |
| 267 | + /*bucket_mode=*/-1, index_manifest_file.get())); |
| 268 | + |
| 269 | + written_entries.clear(); |
| 270 | + ASSERT_OK(index_manifest_file->Read(reordered_manifest, /*filter=*/nullptr, &written_entries)); |
| 271 | + ASSERT_EQ(written_entries.size(), 2); |
| 272 | + written_file_names.clear(); |
| 273 | + for (const auto& entry : written_entries) { |
| 274 | + written_file_names.insert(entry.index_file->FileName()); |
| 275 | + } |
| 276 | + ASSERT_EQ(written_file_names, (std::set<std::string>{"dv-0-newer", "dv-1"})); |
| 277 | +} |
| 278 | + |
| 279 | +TEST_F(IndexManifestFileHandlerTest, GlobalDvCombinerRejectsInconsistentDelta) { |
| 280 | + ASSERT_OK_AND_ASSIGN(auto index_manifest_file, CreateManifestFile(/*bucket_mode=*/-1)); |
| 281 | + |
| 282 | + auto partition = BinaryRow::EmptyRow(); |
| 283 | + std::vector<IndexManifestEntry> previous_entries = { |
226 | 284 | MakeDvEntry(FileKind::Add(), partition, /*bucket=*/0, "dv-0", {"data-0.orc"}, 1)}; |
227 | 285 |
|
228 | | - ASSERT_NOK_WITH_MSG(IndexManifestFileHandler::Write( |
229 | | - /*previous_index_manifest=*/std::nullopt, new_entries, |
230 | | - /*bucket_mode=*/-1, index_manifest_file.get()), |
231 | | - "not yet support dv with BUCKET_UNAWARE mode"); |
| 286 | + ASSERT_OK_AND_ASSIGN(std::string previous_manifest, |
| 287 | + IndexManifestFileHandler::Write( |
| 288 | + /*previous_index_manifest=*/std::nullopt, previous_entries, |
| 289 | + /*bucket_mode=*/-1, index_manifest_file.get())); |
| 290 | + |
| 291 | + // every delta below was built against a base the previous manifest is not, so applying it |
| 292 | + // would leave the read either with two vectors for one data file or with none |
| 293 | + { |
| 294 | + // adding a vector for data-0.orc without dropping the one it already has |
| 295 | + std::vector<IndexManifestEntry> new_entries = { |
| 296 | + MakeDvEntry(FileKind::Add(), partition, /*bucket=*/0, "dv-1", {"data-0.orc"}, 1)}; |
| 297 | + |
| 298 | + ASSERT_NOK_WITH_MSG( |
| 299 | + IndexManifestFileHandler::Write(previous_manifest, new_entries, |
| 300 | + /*bucket_mode=*/-1, index_manifest_file.get()), |
| 301 | + "Trying to add a second deletion vector for data file data-0.orc"); |
| 302 | + } |
| 303 | + { |
| 304 | + // adding an index file the manifest already holds |
| 305 | + std::vector<IndexManifestEntry> new_entries = { |
| 306 | + MakeDvEntry(FileKind::Add(), partition, /*bucket=*/0, "dv-0", {"data-1.orc"}, 1)}; |
| 307 | + |
| 308 | + ASSERT_NOK_WITH_MSG( |
| 309 | + IndexManifestFileHandler::Write(previous_manifest, new_entries, |
| 310 | + /*bucket_mode=*/-1, index_manifest_file.get()), |
| 311 | + "Trying to add deletion vector index file dv-0 which is already added."); |
| 312 | + } |
| 313 | + { |
| 314 | + // deleting an index file the manifest does not hold |
| 315 | + std::vector<IndexManifestEntry> new_entries = { |
| 316 | + MakeDvEntry(FileKind::Delete(), partition, /*bucket=*/0, "dv-1", {"data-1.orc"}, 1)}; |
| 317 | + |
| 318 | + ASSERT_NOK_WITH_MSG( |
| 319 | + IndexManifestFileHandler::Write(previous_manifest, new_entries, |
| 320 | + /*bucket_mode=*/-1, index_manifest_file.get()), |
| 321 | + "Trying to delete deletion vector index file dv-1 which does not exist."); |
| 322 | + } |
232 | 323 | } |
233 | 324 |
|
234 | 325 | } // namespace paimon::test |
0 commit comments