|
31 | 31 | import org.apache.paimon.table.source.TableRead; |
32 | 32 | import org.apache.paimon.types.DataTypes; |
33 | 33 |
|
34 | | -import org.junit.jupiter.api.BeforeEach; |
35 | 34 | import org.junit.jupiter.params.ParameterizedTest; |
36 | 35 | import org.junit.jupiter.params.provider.Arguments; |
37 | 36 | import org.junit.jupiter.params.provider.MethodSource; |
|
42 | 41 | import java.util.List; |
43 | 42 | import java.util.Map; |
44 | 43 |
|
| 44 | +import static org.apache.paimon.CoreOptions.BUCKET; |
45 | 45 | import static org.apache.paimon.table.SimpleTableTestBase.getResult; |
46 | 46 | import static org.assertj.core.api.Assertions.assertThat; |
47 | 47 | import static org.junit.jupiter.params.provider.Arguments.arguments; |
48 | 48 |
|
49 | 49 | /** Unit tests for overwrite table. */ |
50 | 50 | public class OverwriteTableTest extends TableTestBase { |
51 | 51 |
|
52 | | - private Table bucketsTable; |
53 | | - |
54 | | - @BeforeEach |
55 | | - public void before() throws Exception { |
56 | | - Identifier identifier = identifier("T"); |
57 | | - Schema schema = |
58 | | - Schema.newBuilder() |
59 | | - .column("pk", DataTypes.INT()) |
60 | | - .column("pt0", DataTypes.INT()) |
61 | | - .column("pt1", DataTypes.STRING()) |
62 | | - .column("v", DataTypes.STRING()) |
63 | | - .partitionKeys("pt0", "pt1") |
64 | | - .build(); |
65 | | - catalog.createTable(identifier, schema, true); |
| 52 | + @ParameterizedTest(name = "dynamic = {0}, partition={2}") |
| 53 | + @MethodSource("overwriteTestData") |
| 54 | + public void testOverwriteAppend( |
| 55 | + boolean dynamicPartitionOverwrite, |
| 56 | + List<InternalRow> overwriteData, |
| 57 | + Map<String, String> overwritePartition, |
| 58 | + List<String> expected) |
| 59 | + throws Exception { |
| 60 | + innerTestOverwrite( |
| 61 | + false, dynamicPartitionOverwrite, overwriteData, overwritePartition, expected); |
66 | 62 | } |
67 | 63 |
|
68 | 64 | @ParameterizedTest(name = "dynamic = {0}, partition={2}") |
69 | 65 | @MethodSource("overwriteTestData") |
70 | | - public void testOverwriteNothing( |
| 66 | + public void testOverwritePrimaryKey( |
71 | 67 | boolean dynamicPartitionOverwrite, |
72 | 68 | List<InternalRow> overwriteData, |
73 | 69 | Map<String, String> overwritePartition, |
74 | 70 | List<String> expected) |
75 | 71 | throws Exception { |
| 72 | + innerTestOverwrite( |
| 73 | + true, dynamicPartitionOverwrite, overwriteData, overwritePartition, expected); |
| 74 | + } |
| 75 | + |
| 76 | + private void innerTestOverwrite( |
| 77 | + boolean withPrimaryKey, |
| 78 | + boolean dynamicPartitionOverwrite, |
| 79 | + List<InternalRow> overwriteData, |
| 80 | + Map<String, String> overwritePartition, |
| 81 | + List<String> expected) |
| 82 | + throws Exception { |
| 83 | + Identifier identifier = identifier("T"); |
| 84 | + Schema.Builder builder = |
| 85 | + Schema.newBuilder() |
| 86 | + .column("pk", DataTypes.INT()) |
| 87 | + .column("pt0", DataTypes.INT()) |
| 88 | + .column("pt1", DataTypes.STRING()) |
| 89 | + .column("v", DataTypes.STRING()) |
| 90 | + .partitionKeys("pt0", "pt1"); |
| 91 | + if (withPrimaryKey) { |
| 92 | + builder = builder.primaryKey("pk", "pt0", "pt1"); |
| 93 | + builder.option(BUCKET.key(), "1"); |
| 94 | + } |
| 95 | + catalog.createTable(identifier, builder.build(), true); |
76 | 96 | Table originTable = catalog.getTable(identifier("T")); |
77 | 97 | FileStoreTable table = (FileStoreTable) originTable; |
78 | 98 | if (!dynamicPartitionOverwrite) { |
|
0 commit comments