1515// specific language governing permissions and limitations
1616// under the License.
1717
18+ #include < arrow/memory_pool.h>
1819#include < gtest/gtest.h>
1920
2021#include < optional>
2122
23+ #include " core/data_type/data_type_number.h"
2224#include " exec/sink/writer/iceberg/viceberg_partition_writer.h"
2325#include " exec/sink/writer/iceberg/viceberg_sort_writer.h"
26+ #include " format/table/iceberg/schema_parser.h"
27+ #include " format/transformer/viceberg_parquet_writer.h"
2428#include " io/fs/local_file_system.h"
29+ #include " runtime/exec_env.h"
2530#include " testutil/mock/mock_descriptors.h"
2631#include " testutil/mock/mock_runtime_state.h"
2732#include " testutil/mock/mock_slot_ref.h"
33+ #include " util/defer_op.h"
34+ #include " util/timezone_utils.h"
35+ #include " util/uid_util.h"
2836
2937namespace doris {
3038
@@ -73,13 +81,14 @@ class VIcebergPartitionWriterTest : public testing::Test {
7381 static std::unique_ptr<VIcebergPartitionWriter> make_writer (
7482 const TDataSink& sink, const VExprContextSPtrs& output_exprs,
7583 const iceberg::Schema& schema, const std::string* schema_json,
76- const std::map<std::string, std::string>& hadoop_conf) {
84+ const std::map<std::string, std::string>& hadoop_conf,
85+ TFileFormatType::type format = TFileFormatType::FORMAT_ORC ) {
7786 IPartitionWriterBase::WriteInfo write_info;
7887 write_info.file_type = TFileType::FILE_LOCAL ;
7988 return std::make_unique<VIcebergPartitionWriter>(
8089 sink, std::vector<std::string> {}, output_exprs, schema, schema_json,
81- std::vector<std::string> {}, std::move (write_info), " data" , 0 ,
82- TFileFormatType:: FORMAT_ORC , TFileCompressType::ZLIB , hadoop_conf);
90+ std::vector<std::string> {}, std::move (write_info), " data" , 0 , format,
91+ TFileCompressType::ZLIB , hadoop_conf);
8392 }
8493
8594 static void install_fake_transformer (VIcebergPartitionWriter* writer,
@@ -90,6 +99,11 @@ class VIcebergPartitionWriterTest : public testing::Test {
9099 output_exprs, std::move (close_status), destroyed);
91100 }
92101
102+ static void install_parquet_transformer (VIcebergPartitionWriter* writer,
103+ std::unique_ptr<VIcebergParquetWriter> transformer) {
104+ writer->_file_format_transformer = std::move (transformer);
105+ }
106+
93107 static Status build_commit_data (VIcebergPartitionWriter* writer,
94108 TIcebergCommitData* commit_data) {
95109 return writer->_build_iceberg_commit_data (commit_data);
@@ -114,6 +128,51 @@ TEST_F(VIcebergPartitionWriterTest, OrcSkipsFooterCollectionWhenMetricsAreDisabl
114128 EXPECT_FALSE (commit_data.__isset .column_stats );
115129}
116130
131+ TEST_F (VIcebergPartitionWriterTest, ParquetKeepsSplitOffsetsWhenColumnMetricsAreDisabled) {
132+ TimezoneUtils::load_timezones_to_cache ();
133+ auto * env = ExecEnv::GetInstance ();
134+ auto * previous_pool = env->_arrow_memory_pool ;
135+ env->_arrow_memory_pool = arrow::default_memory_pool ();
136+ const auto path = " ./iceberg_split_offsets_" + UniqueId::gen_uid ().to_string () + " .parquet" ;
137+ auto fs = io::global_local_filesystem ();
138+ Defer cleanup ([&] {
139+ env->_arrow_memory_pool = previous_pool;
140+ static_cast <void >(fs->delete_file (path));
141+ });
142+ auto type = std::make_shared<DataTypeInt32>();
143+ auto output_exprs = MockSlotRef::create_mock_contexts (DataTypes {type});
144+ const std::string json =
145+ R"( {"type":"struct","fields":[{"id":1,"name":"value","required":true,"type":"int"}]})" ;
146+ auto schema = iceberg::SchemaParser::from_json (json);
147+ io::FileWriterPtr file_writer;
148+ ASSERT_TRUE (fs->create_file (path, &file_writer).ok ());
149+ RuntimeState state;
150+ state.set_timezone (" UTC" );
151+ ParquetFileOptions options {.compression_type = TParquetCompressionType::SNAPPY ,
152+ .parquet_version = TParquetVersion::PARQUET_1_0 ,
153+ .parquet_disable_dictionary = false ,
154+ .enable_int96_timestamps = false };
155+ auto transformer = std::make_unique<VIcebergParquetWriter>(
156+ &state, file_writer.get (), output_exprs, std::vector<std::string> {" value" }, false ,
157+ options, &json, *schema);
158+ ASSERT_TRUE (transformer->open ().ok ());
159+ auto column = type->create_column ();
160+ column->insert (Field::create_field<TYPE_INT >(7 ));
161+ Block block;
162+ block.insert ({std::move (column), type, " value" });
163+ ASSERT_TRUE (transformer->write (block).ok ());
164+ ASSERT_TRUE (transformer->close ().ok ());
165+ auto writer = make_writer (make_table_sink (false ), output_exprs, *schema, &json, {},
166+ TFileFormatType::FORMAT_PARQUET );
167+ install_parquet_transformer (writer.get (), std::move (transformer));
168+ TIcebergCommitData commit;
169+ ASSERT_TRUE (build_commit_data (writer.get (), &commit).ok ());
170+ EXPECT_FALSE (commit.__isset .column_stats );
171+ ASSERT_TRUE (commit.__isset .split_offsets );
172+ ASSERT_EQ (1 , commit.split_offsets .size ());
173+ EXPECT_EQ (4 , commit.split_offsets [0 ]);
174+ }
175+
117176TEST_F (VIcebergPartitionWriterTest, MissingPolicyKeepsCollectionEnabledForRollingUpgrade) {
118177 VExprContextSPtrs output_exprs;
119178 iceberg::Schema schema (std::vector<iceberg::NestedField> {});
0 commit comments