|
18 | 18 |
|
19 | 19 | package org.apache.paimon; |
20 | 20 |
|
| 21 | +import org.apache.paimon.append.dataevolution.DataEvolutionCompactCoordinator; |
| 22 | +import org.apache.paimon.append.dataevolution.DataEvolutionCompactTask; |
21 | 23 | import org.apache.paimon.catalog.Catalog; |
22 | 24 | import org.apache.paimon.catalog.CatalogContext; |
23 | 25 | import org.apache.paimon.catalog.CatalogFactory; |
|
48 | 50 | import org.apache.paimon.table.sink.BatchTableCommit; |
49 | 51 | import org.apache.paimon.table.sink.BatchTableWrite; |
50 | 52 | import org.apache.paimon.table.sink.BatchWriteBuilder; |
| 53 | +import org.apache.paimon.table.sink.CommitMessage; |
51 | 54 | import org.apache.paimon.table.sink.InnerTableCommit; |
52 | 55 | import org.apache.paimon.table.sink.StreamTableCommit; |
53 | 56 | import org.apache.paimon.table.sink.StreamTableWrite; |
| 57 | +import org.apache.paimon.table.source.EndOfScanException; |
54 | 58 | import org.apache.paimon.table.source.ReadBuilder; |
55 | 59 | import org.apache.paimon.table.source.Split; |
56 | 60 | import org.apache.paimon.table.source.TableRead; |
@@ -937,6 +941,71 @@ protected GenericRow createRow3ColsWithKind(RowKind rowKind, Object... values) { |
937 | 941 | return GenericRow.ofKind(rowKind, values[0], values[1], values[2]); |
938 | 942 | } |
939 | 943 |
|
| 944 | + /** Step 1: Write 5 base files for compact conflict test. */ |
| 945 | + @Test |
| 946 | + @EnabledIfSystemProperty(named = "run.e2e.tests", matches = "true") |
| 947 | + public void testCompactConflictWriteBase() throws Exception { |
| 948 | + Identifier id = identifier("compact_conflict_test"); |
| 949 | + try { |
| 950 | + catalog.dropTable(id, true); |
| 951 | + } catch (Exception ignore) { |
| 952 | + } |
| 953 | + Schema schema = |
| 954 | + Schema.newBuilder() |
| 955 | + .column("f0", DataTypes.INT()) |
| 956 | + .column("f1", DataTypes.STRING()) |
| 957 | + .column("f2", DataTypes.STRING()) |
| 958 | + .option(ROW_TRACKING_ENABLED.key(), "true") |
| 959 | + .option(DATA_EVOLUTION_ENABLED.key(), "true") |
| 960 | + .option(BUCKET.key(), "-1") |
| 961 | + .build(); |
| 962 | + catalog.createTable(id, schema, false); |
| 963 | + |
| 964 | + RowType fullType = schema.rowType().project(Arrays.asList("f0", "f1")); |
| 965 | + |
| 966 | + for (int fileIdx = 0; fileIdx < 5; fileIdx++) { |
| 967 | + int startId = fileIdx * 200; |
| 968 | + FileStoreTable t = (FileStoreTable) catalog.getTable(id); |
| 969 | + BatchWriteBuilder builder = t.newBatchWriteBuilder(); |
| 970 | + try (BatchTableWrite w = builder.newWrite().withWriteType(fullType)) { |
| 971 | + for (int i = 0; i < 200; i++) { |
| 972 | + w.write( |
| 973 | + GenericRow.of( |
| 974 | + startId + i, BinaryString.fromString("n" + (startId + i)))); |
| 975 | + } |
| 976 | + builder.newCommit().commit(w.prepareCommit()); |
| 977 | + } |
| 978 | + } |
| 979 | + LOG.info("compact_conflict_test: 5 base files written (200 rows each, total 1000)"); |
| 980 | + } |
| 981 | + |
| 982 | + /** Step 3: Run compact on compact_conflict_test table. */ |
| 983 | + @Test |
| 984 | + @EnabledIfSystemProperty(named = "run.e2e.tests", matches = "true") |
| 985 | + public void testCompactConflictRunCompact() throws Exception { |
| 986 | + Identifier id = identifier("compact_conflict_test"); |
| 987 | + doDataEvolutionCompact((FileStoreTable) catalog.getTable(id)); |
| 988 | + LOG.info("compact_conflict_test: compact done, 5 files merged into 1 (1000 rows)"); |
| 989 | + } |
| 990 | + |
| 991 | + private void doDataEvolutionCompact(FileStoreTable table) throws Exception { |
| 992 | + DataEvolutionCompactCoordinator coordinator = |
| 993 | + new DataEvolutionCompactCoordinator(table, false, false); |
| 994 | + List<CommitMessage> messages = new ArrayList<>(); |
| 995 | + try { |
| 996 | + List<DataEvolutionCompactTask> tasks; |
| 997 | + while (!(tasks = coordinator.plan()).isEmpty()) { |
| 998 | + for (DataEvolutionCompactTask task : tasks) { |
| 999 | + messages.add(task.doCompact(table, "test-compact")); |
| 1000 | + } |
| 1001 | + } |
| 1002 | + } catch (EndOfScanException ignore) { |
| 1003 | + } |
| 1004 | + if (!messages.isEmpty()) { |
| 1005 | + table.newBatchWriteBuilder().newCommit().commit(messages); |
| 1006 | + } |
| 1007 | + } |
| 1008 | + |
940 | 1009 | private static String rowToStringWithStruct(InternalRow row, RowType type) { |
941 | 1010 | StringBuilder build = new StringBuilder(); |
942 | 1011 | build.append(row.getRowKind().shortString()).append("["); |
|
0 commit comments