|
25 | 25 | import org.apache.paimon.deletionvectors.BucketedDvMaintainer; |
26 | 26 | import org.apache.paimon.fs.Path; |
27 | 27 | import org.apache.paimon.fs.local.LocalFileIO; |
| 28 | +import org.apache.paimon.index.GlobalIndexMeta; |
28 | 29 | import org.apache.paimon.index.IndexFileHandler; |
29 | 30 | import org.apache.paimon.index.IndexFileMeta; |
30 | 31 | import org.apache.paimon.io.CompactIncrement; |
@@ -541,6 +542,82 @@ public void testStrictModeForOverwrite() throws Exception { |
541 | 542 | commit2.close(); |
542 | 543 | } |
543 | 544 |
|
| 545 | + @Test |
| 546 | + public void testStrictModeIgnoresIndexOnlyCompact() throws Exception { |
| 547 | + String path = tempDir.toString(); |
| 548 | + RowType rowType = |
| 549 | + RowType.of( |
| 550 | + new DataType[] {DataTypes.INT(), DataTypes.INT(), DataTypes.BIGINT()}, |
| 551 | + new String[] {"pt", "k", "v"}); |
| 552 | + |
| 553 | + Options options = new Options(); |
| 554 | + options.set(CoreOptions.PATH, path); |
| 555 | + options.set(CoreOptions.BUCKET, 1); |
| 556 | + options.set(CoreOptions.BUCKET_KEY, "k"); |
| 557 | + options.set(CoreOptions.NUM_SORTED_RUNS_COMPACTION_TRIGGER, 10); |
| 558 | + TableSchema tableSchema = |
| 559 | + SchemaUtils.forceCommit( |
| 560 | + new SchemaManager(LocalFileIO.create(), new Path(path)), |
| 561 | + new Schema( |
| 562 | + rowType.getFields(), |
| 563 | + Collections.singletonList("pt"), |
| 564 | + Collections.emptyList(), |
| 565 | + options.toMap(), |
| 566 | + "")); |
| 567 | + FileStoreTable table = |
| 568 | + FileStoreTableFactory.create( |
| 569 | + LocalFileIO.create(), |
| 570 | + new Path(path), |
| 571 | + tableSchema, |
| 572 | + CatalogEnvironment.empty()); |
| 573 | + BinaryRow pt1 = partitionRow(1); |
| 574 | + |
| 575 | + String user1 = UUID.randomUUID().toString(); |
| 576 | + TableWriteImpl<?> write1 = table.newWrite(user1); |
| 577 | + TableCommitImpl commit1 = table.newCommit(user1); |
| 578 | + write1.write(GenericRow.of(1, 0, 0L)); |
| 579 | + commit1.commit(1, write1.prepareCommit(false, 1)); |
| 580 | + |
| 581 | + String user2 = UUID.randomUUID().toString(); |
| 582 | + FileStoreTable tableWithStrict = |
| 583 | + table.copy(singletonMap(COMMIT_STRICT_MODE_LAST_SAFE_SNAPSHOT.key(), "1")); |
| 584 | + TableWriteImpl<?> write2 = tableWithStrict.newWrite(user2); |
| 585 | + TableCommitImpl commit2 = tableWithStrict.newCommit(user2); |
| 586 | + write2.write(GenericRow.of(1, 1, 1L)); |
| 587 | + write2.compact(pt1, 0, true); |
| 588 | + |
| 589 | + IndexFileMeta btreeIndex = |
| 590 | + new IndexFileMeta( |
| 591 | + "btree", |
| 592 | + "index-only-compact", |
| 593 | + 1, |
| 594 | + 1, |
| 595 | + new GlobalIndexMeta(0, 0, 1, null, null), |
| 596 | + null); |
| 597 | + commit1.commit( |
| 598 | + 2, |
| 599 | + Collections.singletonList( |
| 600 | + new CommitMessageImpl( |
| 601 | + pt1, |
| 602 | + 0, |
| 603 | + 1, |
| 604 | + DataIncrement.emptyIncrement(), |
| 605 | + new CompactIncrement( |
| 606 | + Collections.emptyList(), |
| 607 | + Collections.emptyList(), |
| 608 | + Collections.emptyList(), |
| 609 | + Collections.singletonList(btreeIndex), |
| 610 | + Collections.emptyList())))); |
| 611 | + |
| 612 | + assertThatCode(() -> commit2.commit(1, write2.prepareCommit(true, 1))) |
| 613 | + .doesNotThrowAnyException(); |
| 614 | + |
| 615 | + write1.close(); |
| 616 | + commit1.close(); |
| 617 | + write2.close(); |
| 618 | + commit2.close(); |
| 619 | + } |
| 620 | + |
544 | 621 | @Test |
545 | 622 | public void testStrictModeForDvOnlyOverwrite() throws Exception { |
546 | 623 | // Regression test for the partition-overlap check on DV-only OVERWRITE |
|
0 commit comments