Skip to content

Commit fc10fd2

Browse files
author
nullccxsy
committed
test: add test of manifestlistv1
1. PartitionTest: test partition 2. ComplexTypeTest: test complex type 3. PartitionComplexTypeTest: test partition with complex type
1 parent a13eed2 commit fc10fd2

4 files changed

+154
-0
lines changed

test/manifest_list_reader_test.cc

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,118 @@ class ManifestListReaderTest : public TempFileTestBase {
8282
return manifest_files;
8383
}
8484

85+
std::vector<ManifestFile> PrepareTestManifestListPartition() {
86+
std::vector<ManifestFile> manifest_files;
87+
std::string test_dir_prefix = "iceberg-warehouse/db/v1_partition_test/metadata/";
88+
std::vector<std::string> paths = {"eafd2972-f58e-4185-9237-6378f564787e-m1.avro",
89+
"eafd2972-f58e-4185-9237-6378f564787e-m0.avro"};
90+
std::vector<int64_t> file_size = {6185, 6113};
91+
std::vector<int64_t> snapshot_id = {7532614258660258098, 7532614258660258098};
92+
93+
std::vector<std::vector<std::uint8_t>> lower_bounds = {
94+
{0x32, 0x30, 0x32, 0x32, 0x2D, 0x30, 0x32, 0x2D, 0x32, 0x32},
95+
{0x32, 0x30, 0x32, 0x32, 0x2D, 0x32, 0x2D, 0x32, 0x32}};
96+
97+
std::vector<std::vector<std::uint8_t>> upper_bounds = {
98+
{0x32, 0x30, 0x32, 0x32, 0x2D, 0x32, 0x2D, 0x32, 0x33},
99+
{0x32, 0x30, 0x32, 0x32, 0x2D, 0x32, 0x2D, 0x32, 0x33}};
100+
101+
for (int i = 0; i < 2; ++i) {
102+
ManifestFile manifest_file;
103+
manifest_file.manifest_path = test_dir_prefix + paths[i];
104+
manifest_file.manifest_length = file_size[i];
105+
manifest_file.partition_spec_id = 0;
106+
manifest_file.added_snapshot_id = snapshot_id[i];
107+
manifest_file.added_files_count = 4 * (1 - i);
108+
manifest_file.existing_files_count = 0;
109+
manifest_file.deleted_files_count = 2 * i;
110+
manifest_file.added_rows_count = 6 * (1 - i);
111+
manifest_file.existing_rows_count = 0;
112+
manifest_file.deleted_rows_count = 6 * i;
113+
114+
PartitionFieldSummary partition;
115+
partition.contains_null = false;
116+
partition.contains_nan = false;
117+
partition.lower_bound = lower_bounds[i];
118+
partition.upper_bound = upper_bounds[i];
119+
manifest_file.partitions.emplace_back(partition);
120+
manifest_files.emplace_back(manifest_file);
121+
}
122+
return manifest_files;
123+
}
124+
125+
std::vector<ManifestFile> PrepareTestManifestListComplexType() {
126+
std::vector<ManifestFile> manifest_files;
127+
std::string test_dir_prefix = "iceberg-warehouse/db/v1_type_test/metadata/";
128+
std::vector<std::string> paths = {"aeffe099-3bac-4011-bc17-5875210d8dc0-m1.avro",
129+
"aeffe099-3bac-4011-bc17-5875210d8dc0-m0.avro"};
130+
std::vector<int64_t> file_size = {6498, 6513};
131+
std::vector<int64_t> snapshot_id = {4134160420377642835, 4134160420377642835};
132+
133+
for (int i = 0; i < 2; ++i) {
134+
ManifestFile manifest_file;
135+
manifest_file.manifest_path = test_dir_prefix + paths[i];
136+
manifest_file.manifest_length = file_size[i];
137+
manifest_file.partition_spec_id = 0;
138+
manifest_file.added_snapshot_id = snapshot_id[i];
139+
manifest_file.added_files_count = 1 - i;
140+
manifest_file.existing_files_count = 0;
141+
manifest_file.deleted_files_count = i;
142+
manifest_file.added_rows_count = 2 * (1 - i);
143+
manifest_file.existing_rows_count = 0;
144+
manifest_file.deleted_rows_count = 3 * i;
145+
manifest_files.emplace_back(manifest_file);
146+
}
147+
return manifest_files;
148+
}
149+
150+
std::vector<ManifestFile> PrepareTestManifestListPartitionComplex() {
151+
std::vector<ManifestFile> manifest_files;
152+
std::string test_dir_prefix =
153+
"iceberg-warehouse/db2/v1_complex_partition_test/metadata/";
154+
std::vector<std::string> paths = {"5d690750-8fb4-4cd1-8ae7-85c7b39abe14-m0.avro",
155+
"5d690750-8fb4-4cd1-8ae7-85c7b39abe14-m1.avro"};
156+
std::vector<int64_t> file_size = {6402, 6318};
157+
std::vector<int64_t> snapshot_id = {7522296285847100621, 7522296285847100621};
158+
159+
std::vector<std::vector<std::uint8_t>> lower_bounds = {
160+
{0x32, 0x30, 0x32, 0x32, 0x2D, 0x32, 0x2D, 0x32, 0x32},
161+
{0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
162+
{0x32, 0x30, 0x32, 0x32, 0x2D, 0x32, 0x2D, 0x32, 0x32},
163+
{0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
164+
165+
std::vector<std::vector<std::uint8_t>> upper_bounds = {
166+
{0x32, 0x30, 0x32, 0x32, 0x2D, 0x32, 0x2D, 0x32, 0x34},
167+
{0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
168+
{0x32, 0x30, 0x32, 0x32, 0x2D, 0x32, 0x2D, 0x32, 0x33},
169+
{0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
170+
171+
for (int i = 0; i < 2; ++i) {
172+
ManifestFile manifest_file;
173+
manifest_file.manifest_path = test_dir_prefix + paths[i];
174+
manifest_file.manifest_length = file_size[i];
175+
manifest_file.partition_spec_id = 0;
176+
manifest_file.added_snapshot_id = snapshot_id[i];
177+
manifest_file.added_files_count = 0;
178+
manifest_file.existing_files_count = i == 0 ? 3 : 1;
179+
manifest_file.deleted_files_count = 1;
180+
manifest_file.added_rows_count = 0;
181+
manifest_file.existing_rows_count = i == 0 ? 4 : 1;
182+
manifest_file.deleted_rows_count = i == 0 ? 2 : 1;
183+
184+
PartitionFieldSummary partition;
185+
for (int j = 0; j < 2; ++j) {
186+
partition.contains_null = false;
187+
partition.contains_nan = false;
188+
partition.lower_bound = lower_bounds[2 * i + j];
189+
partition.upper_bound = upper_bounds[2 * i + j];
190+
manifest_file.partitions.emplace_back(partition);
191+
}
192+
manifest_files.emplace_back(manifest_file);
193+
}
194+
return manifest_files;
195+
}
196+
85197
std::shared_ptr<::arrow::fs::LocalFileSystem> local_fs_;
86198
std::shared_ptr<FileIO> file_io_;
87199
};
@@ -100,4 +212,46 @@ TEST_F(ManifestListReaderTest, BasicTest) {
100212
ASSERT_EQ(read_result.value(), expected_manifest_list);
101213
}
102214

215+
TEST_F(ManifestListReaderTest, PartitionTest) {
216+
std::string path = GetResourcePath(
217+
"snap-7532614258660258098-1-eafd2972-f58e-4185-9237-6378f564787e.avro");
218+
auto manifest_reader_result = ManifestListReader::MakeReader(path, file_io_);
219+
ASSERT_EQ(manifest_reader_result.has_value(), true);
220+
auto manifest_reader = std::move(manifest_reader_result.value());
221+
auto read_result = manifest_reader->Files();
222+
ASSERT_EQ(read_result.has_value(), true);
223+
ASSERT_EQ(read_result.value().size(), 2);
224+
225+
auto expected_manifest_list = PrepareTestManifestListPartition();
226+
ASSERT_EQ(read_result.value(), expected_manifest_list);
227+
}
228+
229+
TEST_F(ManifestListReaderTest, ComplexTypeTest) {
230+
std::string path = GetResourcePath(
231+
"snap-4134160420377642835-1-aeffe099-3bac-4011-bc17-5875210d8dc0.avro");
232+
auto manifest_reader_result = ManifestListReader::MakeReader(path, file_io_);
233+
ASSERT_EQ(manifest_reader_result.has_value(), true);
234+
auto manifest_reader = std::move(manifest_reader_result.value());
235+
auto read_result = manifest_reader->Files();
236+
ASSERT_EQ(read_result.has_value(), true);
237+
ASSERT_EQ(read_result.value().size(), 2);
238+
239+
auto expected_manifest_list = PrepareTestManifestListComplexType();
240+
ASSERT_EQ(read_result.value(), expected_manifest_list);
241+
}
242+
243+
TEST_F(ManifestListReaderTest, PartitionComplexTypeTest) {
244+
std::string path = GetResourcePath(
245+
"snap-7522296285847100621-1-5d690750-8fb4-4cd1-8ae7-85c7b39abe14.avro");
246+
auto manifest_reader_result = ManifestListReader::MakeReader(path, file_io_);
247+
ASSERT_EQ(manifest_reader_result.has_value(), true);
248+
auto manifest_reader = std::move(manifest_reader_result.value());
249+
auto read_result = manifest_reader->Files();
250+
ASSERT_EQ(read_result.has_value(), true);
251+
ASSERT_EQ(read_result.value().size(), 2);
252+
253+
auto expected_manifest_list = PrepareTestManifestListPartitionComplex();
254+
ASSERT_EQ(read_result.value(), expected_manifest_list);
255+
}
256+
103257
} // namespace iceberg
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)