|
28 | 28 | import org.apache.paimon.table.FileStoreTable; |
29 | 29 | import org.apache.paimon.table.FileStoreTableFactory; |
30 | 30 | import org.apache.paimon.types.DataField; |
| 31 | +import org.apache.paimon.types.DataType; |
31 | 32 | import org.apache.paimon.types.DataTypes; |
32 | 33 | import org.apache.paimon.utils.TypeUtils; |
33 | 34 | import org.junit.jupiter.api.AfterEach; |
|
36 | 37 | import org.junit.jupiter.api.Test; |
37 | 38 | import org.junit.jupiter.api.io.TempDir; |
38 | 39 |
|
| 40 | +import java.nio.charset.StandardCharsets; |
39 | 41 | import java.nio.file.Path; |
40 | 42 | import java.time.Instant; |
41 | 43 | import java.time.OffsetDateTime; |
@@ -148,15 +150,40 @@ public void staticLtzPartitionOutsideAnOverlapRoundTripsThroughPaimon(@TempDir P |
148 | 150 | } |
149 | 151 |
|
150 | 152 | @Test |
151 | | - public void staticPartitionNullUsesTheDefaultPartitionName(@TempDir Path warehouse) { |
152 | | - FileStoreTable table = partitionedTable(warehouse, |
153 | | - Collections.singletonMap("partition.default-name", DEFAULT_NAME), |
154 | | - new DataField(1, "part", DataTypes.INT())); |
155 | | - ConnectorWriteHandle write = handle(true, Collections.singletonMap("part", "NULL"), |
156 | | - Collections::emptyMap, Collections.singleton("part")); |
| 153 | + public void staticOverwriteRejectsABinaryPartitionValue(@TempDir Path warehouse) { |
| 154 | + // Paimon's static overwrite takes the UTF-8 bytes of a value's string: "0x4142" names the partition of |
| 155 | + // those six bytes, not of the two bytes 41 42 the rows carry, so an overwrite without rows would report |
| 156 | + // success and leave the partition it was given in place. The check comes before the values are cast, |
| 157 | + // which a binary value may not survive. MUTATION: dropping the check -> red. |
| 158 | + Assertions.assertArrayEquals("0x4142".getBytes(StandardCharsets.UTF_8), |
| 159 | + (byte[]) TypeUtils.castFromString("0x4142", DataTypes.BYTES())); |
| 160 | + for (DataType type : Arrays.asList(DataTypes.BYTES(), DataTypes.VARBINARY(2), DataTypes.BINARY(2))) { |
| 161 | + FileStoreTable table = partitionedTable(warehouse, Collections.emptyMap(), |
| 162 | + new DataField(1, "part", type)); |
| 163 | + ConnectorWriteHandle overwrite = handle(true, Collections.singletonMap("part", "0x4142"), () -> { |
| 164 | + throw new AssertionError("a binary static partition value must be rejected before it is cast"); |
| 165 | + }, Collections.emptySet()); |
157 | 166 |
|
158 | | - Assertions.assertEquals(DEFAULT_NAME, |
159 | | - PaimonWriteBinding.resolveStaticPartition(table, write).get("part")); |
| 167 | + DorisConnectorException error = Assertions.assertThrows(DorisConnectorException.class, |
| 168 | + () -> PaimonWriteBinding.resolveStaticPartition(table, overwrite)); |
| 169 | + Assertions.assertTrue(error.getMessage().contains("binary partition column 'part'"), |
| 170 | + error.getMessage()); |
| 171 | + } |
| 172 | + } |
| 173 | + |
| 174 | + @Test |
| 175 | + public void staticPartitionNullUsesTheDefaultPartitionName(@TempDir Path warehouse) { |
| 176 | + // A binary column too: SQL NULL names its partition by partition.default-name, not by bytes. |
| 177 | + for (DataType type : Arrays.asList(DataTypes.INT(), DataTypes.BYTES())) { |
| 178 | + FileStoreTable table = partitionedTable(warehouse, |
| 179 | + Collections.singletonMap("partition.default-name", DEFAULT_NAME), |
| 180 | + new DataField(1, "part", type)); |
| 181 | + ConnectorWriteHandle write = handle(true, Collections.singletonMap("part", "NULL"), |
| 182 | + Collections::emptyMap, Collections.singleton("part")); |
| 183 | + |
| 184 | + Assertions.assertEquals(DEFAULT_NAME, |
| 185 | + PaimonWriteBinding.resolveStaticPartition(table, write).get("part"), type.toString()); |
| 186 | + } |
160 | 187 | } |
161 | 188 |
|
162 | 189 | @Test |
|
0 commit comments