|
50 | 50 | import org.apache.fluss.fs.FsPathAndFileName; |
51 | 51 | import org.apache.fluss.metadata.DatabaseDescriptor; |
52 | 52 | import org.apache.fluss.metadata.DatabaseInfo; |
| 53 | +import org.apache.fluss.metadata.DeleteBehavior; |
53 | 54 | import org.apache.fluss.metadata.KvFormat; |
54 | 55 | import org.apache.fluss.metadata.LogFormat; |
55 | 56 | import org.apache.fluss.metadata.PartitionInfo; |
|
86 | 87 |
|
87 | 88 | import static org.apache.fluss.config.ConfigOptions.DATALAKE_FORMAT; |
88 | 89 | import static org.apache.fluss.metadata.DataLakeFormat.PAIMON; |
| 90 | +import static org.apache.fluss.record.TestData.DATA1_SCHEMA; |
89 | 91 | import static org.apache.fluss.testutils.DataTestUtils.row; |
90 | 92 | import static org.assertj.core.api.Assertions.assertThat; |
91 | 93 | import static org.assertj.core.api.Assertions.assertThatThrownBy; |
@@ -311,6 +313,92 @@ void testCreateInvalidDatabaseAndTable() { |
311 | 313 | .hasMessageContaining("Database name null is invalid: null string is not allowed"); |
312 | 314 | } |
313 | 315 |
|
| 316 | + @Test |
| 317 | + void testCreateTableWithDeleteBehavior() { |
| 318 | + // Test 1: FIRST_ROW merge engine - should set delete behavior to IGNORE |
| 319 | + TablePath tablePath1 = TablePath.of("fluss", "test_ignore_delete_for_first_row"); |
| 320 | + Map<String, String> properties1 = new HashMap<>(); |
| 321 | + properties1.put(ConfigOptions.TABLE_MERGE_ENGINE.key(), "first_row"); |
| 322 | + |
| 323 | + TableDescriptor tableDescriptor1 = |
| 324 | + TableDescriptor.builder() |
| 325 | + .schema(DEFAULT_SCHEMA) |
| 326 | + .comment("first row merge engine table") |
| 327 | + .properties(properties1) |
| 328 | + .build(); |
| 329 | + admin.createTable(tablePath1, tableDescriptor1, false).join(); |
| 330 | + |
| 331 | + // Get the table and verify delete behavior is changed to IGNORE |
| 332 | + TableInfo tableInfo1 = admin.getTableInfo(tablePath1).join(); |
| 333 | + assertThat(tableInfo1.getTableConfig().getDeleteBehavior()).hasValue(DeleteBehavior.IGNORE); |
| 334 | + |
| 335 | + // Test 2: VERSIONED merge engine - should set delete behavior to IGNORE |
| 336 | + TablePath tablePath2 = TablePath.of("fluss", "test_ignore_delete_for_versioned"); |
| 337 | + Map<String, String> properties2 = new HashMap<>(); |
| 338 | + properties2.put(ConfigOptions.TABLE_MERGE_ENGINE.key(), "versioned"); |
| 339 | + properties2.put(ConfigOptions.TABLE_MERGE_ENGINE_VERSION_COLUMN.key(), "age"); |
| 340 | + TableDescriptor tableDescriptor2 = |
| 341 | + TableDescriptor.builder() |
| 342 | + .schema(DEFAULT_SCHEMA) |
| 343 | + .comment("versioned merge engine table") |
| 344 | + .properties(properties2) |
| 345 | + .build(); |
| 346 | + admin.createTable(tablePath2, tableDescriptor2, false).join(); |
| 347 | + // Get the table and verify delete behavior is changed to IGNORE |
| 348 | + TableInfo tableInfo2 = admin.getTableInfo(tablePath2).join(); |
| 349 | + assertThat(tableInfo2.getTableConfig().getDeleteBehavior()).hasValue(DeleteBehavior.IGNORE); |
| 350 | + |
| 351 | + // Test 3: FIRST_ROW merge engine with delete behavior explicitly set to ALLOW |
| 352 | + TablePath tablePath3 = TablePath.of("fluss", "test_allow_delete_for_first_row"); |
| 353 | + Map<String, String> properties3 = new HashMap<>(); |
| 354 | + properties3.put(ConfigOptions.TABLE_MERGE_ENGINE.key(), "first_row"); |
| 355 | + properties3.put(ConfigOptions.TABLE_DELETE_BEHAVIOR.key(), "ALLOW"); |
| 356 | + TableDescriptor tableDescriptor3 = |
| 357 | + TableDescriptor.builder() |
| 358 | + .schema(DEFAULT_SCHEMA) |
| 359 | + .comment("first row merge engine table") |
| 360 | + .properties(properties3) |
| 361 | + .build(); |
| 362 | + assertThatThrownBy(() -> admin.createTable(tablePath3, tableDescriptor3, false).join()) |
| 363 | + .hasRootCauseInstanceOf(InvalidConfigException.class) |
| 364 | + .hasMessageContaining( |
| 365 | + "Table with 'FIRST_ROW' merge engine does not support delete operations. " |
| 366 | + + "The delete behavior must be set to 'ignore' or 'disable', but got 'allow'."); |
| 367 | + |
| 368 | + // Test 4: VERSIONED merge engine with delete behavior explicitly set to ALLOW |
| 369 | + TablePath tablePath4 = TablePath.of("fluss", "test_allow_delete_for_versioned"); |
| 370 | + Map<String, String> properties4 = new HashMap<>(); |
| 371 | + properties4.put(ConfigOptions.TABLE_MERGE_ENGINE.key(), "versioned"); |
| 372 | + properties4.put(ConfigOptions.TABLE_MERGE_ENGINE_VERSION_COLUMN.key(), "age"); |
| 373 | + properties4.put(ConfigOptions.TABLE_DELETE_BEHAVIOR.key(), "ALLOW"); |
| 374 | + TableDescriptor tableDescriptor4 = |
| 375 | + TableDescriptor.builder() |
| 376 | + .schema(DEFAULT_SCHEMA) |
| 377 | + .comment("versioned merge engine table") |
| 378 | + .properties(properties4) |
| 379 | + .build(); |
| 380 | + assertThatThrownBy(() -> admin.createTable(tablePath4, tableDescriptor4, false).join()) |
| 381 | + .hasRootCauseInstanceOf(InvalidConfigException.class) |
| 382 | + .hasMessageContaining( |
| 383 | + "Table with 'VERSIONED' merge engine does not support delete operations. " |
| 384 | + + "The delete behavior must be set to 'ignore' or 'disable', but got 'allow'."); |
| 385 | + |
| 386 | + // Test 5: Log table - not allow to set delete behavior |
| 387 | + TablePath tablePath5 = TablePath.of("fluss", "test_set_delete_behavior_for_log_table"); |
| 388 | + Map<String, String> properties5 = new HashMap<>(); |
| 389 | + properties5.put(ConfigOptions.TABLE_DELETE_BEHAVIOR.key(), "IGNORE"); |
| 390 | + TableDescriptor tableDescriptor5 = |
| 391 | + TableDescriptor.builder() |
| 392 | + .schema(DATA1_SCHEMA) |
| 393 | + .comment("log table") |
| 394 | + .properties(properties5) |
| 395 | + .build(); |
| 396 | + assertThatThrownBy(() -> admin.createTable(tablePath5, tableDescriptor5, false).join()) |
| 397 | + .hasRootCauseInstanceOf(InvalidConfigException.class) |
| 398 | + .hasMessageContaining( |
| 399 | + "Delete behavior configuration is only supported for primary key tables."); |
| 400 | + } |
| 401 | + |
314 | 402 | @Test |
315 | 403 | void testCreateTableWithInvalidProperty() { |
316 | 404 | TablePath tablePath = TablePath.of(DEFAULT_TABLE_PATH.getDatabaseName(), "test_property"); |
|
0 commit comments