2828#include < utility>
2929#include < vector>
3030
31+ #include " arrow/type.h"
3132#include " gtest/gtest.h"
33+ #include " paimon/common/utils/binary_row_partition_computer.h"
3234#include " paimon/fs/file_system.h"
3335#include " paimon/macros.h"
36+ #include " paimon/memory/memory_pool.h"
3437#include " paimon/testing/utils/testharness.h"
3538
3639namespace paimon ::test {
@@ -71,6 +74,13 @@ class RealtimeCommitPropertiesTest : public testing::Test {
7174 ASSERT_NE (nullptr , directory_);
7275 file_system_ = directory_->GetFileSystem ();
7376 ASSERT_NE (nullptr , file_system_);
77+ std::shared_ptr<arrow::Schema> schema = arrow::schema (
78+ {arrow::field (" dt" , arrow::utf8 ()), arrow::field (" region" , arrow::utf8 ())});
79+ ASSERT_OK_AND_ASSIGN (partition_computer_,
80+ BinaryRowPartitionComputer::Create (
81+ /* partition_keys=*/ {" dt" , " region" }, schema,
82+ /* default_part_value=*/ " __DEFAULT_PARTITION__" ,
83+ /* legacy_partition_name_enabled=*/ true , GetDefaultPool ()));
7484 }
7585
7686 Snapshot MakeSnapshot (
@@ -120,6 +130,7 @@ class RealtimeCommitPropertiesTest : public testing::Test {
120130
121131 std::unique_ptr<UniqueTestDirectory> directory_;
122132 std::shared_ptr<FileSystem> file_system_;
133+ std::unique_ptr<BinaryRowPartitionComputer> partition_computer_;
123134 int32_t next_file_id_ = 0 ;
124135};
125136
@@ -312,25 +323,27 @@ TEST_F(RealtimeCommitPropertiesTest, BuildRejectsInvalidProgress) {
312323 ASSERT_NOK_WITH_MSG (
313324 RealtimeCommitProperties::Build (/* properties=*/ {}, /* latest_snapshot=*/ std::nullopt ,
314325 invalid_bucket, /* reset_all_realtime_progress=*/ false ,
315- /* removed_realtime_partitions=*/ {}, file_system_ ,
316- directory_->Str (), " main" ),
326+ /* removed_realtime_partitions=*/ {}, *partition_computer_ ,
327+ file_system_, directory_->Str (), " main" ),
317328 " bucket -1 is invalid" );
318329
319330 std::map<RealtimePartitionBucket, OffsetRange> gap = {
320331 {RealtimePartitionBucket ({{" dt" , " 2" }}, /* bucket=*/ 0 ), OffsetRange (3 , 5 )}};
321- ASSERT_NOK_WITH_MSG (RealtimeCommitProperties::Build (/* properties=*/ {}, latest_snapshot, gap,
322- /* reset_all_realtime_progress=*/ false ,
323- /* removed_realtime_partitions=*/ {},
324- file_system_, directory_->Str (), " main" ),
325- " are not contiguous" );
332+ ASSERT_NOK_WITH_MSG (
333+ RealtimeCommitProperties::Build (/* properties=*/ {}, latest_snapshot, gap,
334+ /* reset_all_realtime_progress=*/ false ,
335+ /* removed_realtime_partitions=*/ {}, *partition_computer_,
336+ file_system_, directory_->Str (), " main" ),
337+ " are not contiguous" );
326338
327339 std::map<RealtimePartitionBucket, OffsetRange> overlap = {
328340 {RealtimePartitionBucket ({{" dt" , " 2" }}, /* bucket=*/ 0 ), OffsetRange (0 , 2 )}};
329- ASSERT_NOK_WITH_MSG (RealtimeCommitProperties::Build (/* properties=*/ {}, latest_snapshot, overlap,
330- /* reset_all_realtime_progress=*/ false ,
331- /* removed_realtime_partitions=*/ {},
332- file_system_, directory_->Str (), " main" ),
333- " are not contiguous" );
341+ ASSERT_NOK_WITH_MSG (
342+ RealtimeCommitProperties::Build (/* properties=*/ {}, latest_snapshot, overlap,
343+ /* reset_all_realtime_progress=*/ false ,
344+ /* removed_realtime_partitions=*/ {}, *partition_computer_,
345+ file_system_, directory_->Str (), " main" ),
346+ " are not contiguous" );
334347
335348 RealtimeOffsetMap exhausted_offsets = {{bucket0, std::numeric_limits<int64_t >::max ()}};
336349 ASSERT_OK_AND_ASSIGN (Snapshot exhausted_snapshot, MakeSnapshotWithOffsets (exhausted_offsets));
@@ -340,8 +353,8 @@ TEST_F(RealtimeCommitPropertiesTest, BuildRejectsInvalidProgress) {
340353 ASSERT_NOK_WITH_MSG (
341354 RealtimeCommitProperties::Build (/* properties=*/ {}, exhausted_snapshot, after_max,
342355 /* reset_all_realtime_progress=*/ false ,
343- /* removed_realtime_partitions=*/ {}, file_system_ ,
344- directory_->Str (), " main" ),
356+ /* removed_realtime_partitions=*/ {}, *partition_computer_ ,
357+ file_system_, directory_->Str (), " main" ),
345358 " offset range is invalid" );
346359}
347360
@@ -355,19 +368,20 @@ TEST_F(RealtimeCommitPropertiesTest, BuildWithoutProgress) {
355368 RealtimeCommitProperties::Build (
356369 properties, std::optional<Snapshot>(MakeSnapshot (latest_properties)),
357370 /* realtime_ranges=*/ {}, /* reset_all_realtime_progress=*/ false ,
358- /* removed_realtime_partitions=*/ {},
371+ /* removed_realtime_partitions=*/ {}, *partition_computer_,
359372 /* file_system=*/ nullptr ,
360373 /* table_root=*/ " " , /* branch=*/ " main" ));
361374 ASSERT_EQ (" value" , inherited.at (" custom" ));
362375 ASSERT_EQ (latest_offsets_path, inherited.at (RealtimeCommitProperties::kOffsetsKey ));
363376
364- ASSERT_OK_AND_ASSIGN (Properties unchanged, RealtimeCommitProperties::Build (
365- properties, /* latest_snapshot=*/ std::nullopt ,
366- /* realtime_ranges=*/ {},
367- /* reset_all_realtime_progress=*/ false ,
368- /* removed_realtime_partitions=*/ {},
369- /* file_system=*/ nullptr ,
370- /* table_root=*/ " " , /* branch=*/ " main" ));
377+ ASSERT_OK_AND_ASSIGN (
378+ Properties unchanged,
379+ RealtimeCommitProperties::Build (properties, /* latest_snapshot=*/ std::nullopt ,
380+ /* realtime_ranges=*/ {},
381+ /* reset_all_realtime_progress=*/ false ,
382+ /* removed_realtime_partitions=*/ {}, *partition_computer_,
383+ /* file_system=*/ nullptr ,
384+ /* table_root=*/ " " , /* branch=*/ " main" ));
371385 ASSERT_EQ (properties, unchanged);
372386
373387 Properties properties_with_stale_offset = properties;
@@ -377,7 +391,7 @@ TEST_F(RealtimeCommitPropertiesTest, BuildWithoutProgress) {
377391 RealtimeCommitProperties::Build (
378392 properties_with_stale_offset, std::optional<Snapshot>(MakeSnapshot (latest_properties)),
379393 /* realtime_ranges=*/ {}, /* reset_all_realtime_progress=*/ true ,
380- /* removed_realtime_partitions=*/ {},
394+ /* removed_realtime_partitions=*/ {}, *partition_computer_,
381395 /* file_system=*/ nullptr , /* table_root=*/ " " , /* branch=*/ " main" ));
382396 ASSERT_EQ (" value" , overwritten.at (" custom" ));
383397 ASSERT_EQ (0 , overwritten.count (RealtimeCommitProperties::kOffsetsKey ));
@@ -395,7 +409,7 @@ TEST_F(RealtimeCommitPropertiesTest, BuildRemovesOnlyOverwrittenPartitions) {
395409 RealtimeCommitProperties::Build (
396410 /* properties=*/ {}, latest_snapshot, /* realtime_ranges=*/ {},
397411 /* reset_all_realtime_progress=*/ false , removed_partitions,
398- file_system_, directory_->Str (), " main" ));
412+ *partition_computer_, file_system_, directory_->Str (), " main" ));
399413 ASSERT_OK_AND_ASSIGN (RealtimeOffsetMap actual,
400414 RealtimeCommitProperties::ReadOffsets (
401415 std::optional<Snapshot>(MakeSnapshot (properties)), file_system_));
@@ -418,7 +432,8 @@ TEST_F(RealtimeCommitPropertiesTest, BuildWritesMergedProgress) {
418432 RealtimeCommitProperties::Build (
419433 properties, std::optional<Snapshot>(MakeSnapshot (latest_properties)), ranges,
420434 /* reset_all_realtime_progress=*/ false ,
421- /* removed_realtime_partitions=*/ {}, file_system_, directory_->Str (), " main" ));
435+ /* removed_realtime_partitions=*/ {}, *partition_computer_, file_system_,
436+ directory_->Str (), " main" ));
422437 ASSERT_EQ (" value" , merged.at (" custom" ));
423438 ASSERT_NE (latest_offsets_path, merged.at (RealtimeCommitProperties::kOffsetsKey ));
424439
@@ -435,12 +450,12 @@ TEST_F(RealtimeCommitPropertiesTest, BuildWritesMergedProgress) {
435450TEST_F (RealtimeCommitPropertiesTest, BuildRequiresFileSystem) {
436451 std::map<RealtimePartitionBucket, OffsetRange> ranges = {
437452 {RealtimePartitionBucket ({{" dt" , " 2" }}, /* bucket=*/ 0 ), OffsetRange (0 , 2 )}};
438- ASSERT_NOK_WITH_MSG (
439- RealtimeCommitProperties::Build (
440- /* properties= */ {}, /* latest_snapshot =*/ std:: nullopt , ranges ,
441- /* reset_all_realtime_progress =*/ false ,
442- /* removed_realtime_partitions= */ {}, /* file_system=*/ nullptr , directory_->Str (), " main" ),
443- " file system is null" );
453+ ASSERT_NOK_WITH_MSG (RealtimeCommitProperties::Build (
454+ /* properties= */ {}, /* latest_snapshot= */ std:: nullopt , ranges,
455+ /* reset_all_realtime_progress =*/ false ,
456+ /* removed_realtime_partitions =*/ {}, *partition_computer_ ,
457+ /* file_system=*/ nullptr , directory_->Str (), " main" ),
458+ " file system is null" );
444459}
445460
446461} // namespace paimon::test
0 commit comments