|
18 | 18 | #include "exec/sink/viceberg_delete_sink.h" |
19 | 19 |
|
20 | 20 | #include <gtest/gtest.h> |
| 21 | +#include <parquet/api/reader.h> |
| 22 | +#include <parquet/schema.h> |
21 | 23 | #include <rapidjson/document.h> |
22 | 24 |
|
23 | 25 | #include <filesystem> |
|
35 | 37 | #include "exec/common/endian.h" |
36 | 38 | #include "gen_cpp/DataSinks_types.h" |
37 | 39 | #include "gen_cpp/Types_types.h" |
| 40 | +#include "runtime/runtime_profile.h" |
38 | 41 | #include "runtime/runtime_state.h" |
| 42 | +#include "testutil/mock/mock_runtime_state.h" |
39 | 43 | #include "util/uid_util.h" |
40 | 44 |
|
41 | 45 | namespace doris { |
@@ -480,6 +484,49 @@ TEST_F(VIcebergDeleteSinkTest, TestGenerateDeleteFilePath) { |
480 | 484 | ASSERT_NE(std::string::npos, delete_file_path.find("delete_pos_")); |
481 | 485 | } |
482 | 486 |
|
| 487 | +TEST_F(VIcebergDeleteSinkTest, TestWritePositionDeleteParquetFieldIds) { |
| 488 | + std::filesystem::path temp_dir = std::filesystem::temp_directory_path() / |
| 489 | + ("iceberg_position_delete_test_" + generate_uuid_string()); |
| 490 | + ASSERT_TRUE(std::filesystem::create_directories(temp_dir)); |
| 491 | + |
| 492 | + TDataSink t_data_sink = build_local_delete_sink(temp_dir.string(), 2); |
| 493 | + VExprContextSPtrs output_exprs; |
| 494 | + auto sink = std::make_shared<VIcebergDeleteSink>(t_data_sink, output_exprs, nullptr, nullptr); |
| 495 | + ObjectPool pool; |
| 496 | + ASSERT_TRUE(sink->init_properties(&pool).ok()); |
| 497 | + |
| 498 | + MockRuntimeState state; |
| 499 | + RuntimeProfile profile("iceberg_delete_sink"); |
| 500 | + ASSERT_TRUE(sink->open(&state, &profile).ok()); |
| 501 | + |
| 502 | + std::map<std::string, IcebergFileDeletion> file_deletions; |
| 503 | + auto [file_it, inserted] = |
| 504 | + file_deletions.emplace("file1.parquet", IcebergFileDeletion(1, "[\"p=1\"]")); |
| 505 | + ASSERT_TRUE(inserted); |
| 506 | + file_it->second.rows_to_delete.add((uint32_t)10); |
| 507 | + file_it->second.rows_to_delete.add((uint32_t)20); |
| 508 | + |
| 509 | + ASSERT_TRUE(sink->_write_position_delete_files(file_deletions).ok()); |
| 510 | + ASSERT_EQ(1, sink->_commit_data_list.size()); |
| 511 | + |
| 512 | + const auto& commit_data = sink->_commit_data_list[0]; |
| 513 | + std::unique_ptr<::parquet::ParquetFileReader> parquet_reader = |
| 514 | + ::parquet::ParquetFileReader::OpenFile(commit_data.file_path, false); |
| 515 | + std::shared_ptr<::parquet::FileMetaData> file_metadata = parquet_reader->metadata(); |
| 516 | + const auto& group_node = static_cast<const ::parquet::schema::GroupNode&>( |
| 517 | + *file_metadata->schema()->group_node()); |
| 518 | + |
| 519 | + ASSERT_EQ(2, group_node.field_count()); |
| 520 | + auto file_path_field = group_node.field(0); |
| 521 | + auto pos_field = group_node.field(1); |
| 522 | + EXPECT_EQ("file_path", file_path_field->name()); |
| 523 | + EXPECT_EQ(2147483546, file_path_field->field_id()); |
| 524 | + EXPECT_EQ("pos", pos_field->name()); |
| 525 | + EXPECT_EQ(2147483545, pos_field->field_id()); |
| 526 | + |
| 527 | + ASSERT_TRUE(std::filesystem::remove_all(temp_dir) > 0); |
| 528 | +} |
| 529 | + |
483 | 530 | TEST_F(VIcebergDeleteSinkTest, TestUnsupportedDeleteType) { |
484 | 531 | // Create a TDataSink for an unsupported delete type |
485 | 532 | TDataSink t_eq_delete_sink; |
|
0 commit comments