Skip to content

Commit 74f1589

Browse files
committed
add test
1 parent 2c42234 commit 74f1589

File tree

1 file changed

+76
-3
lines changed

1 file changed

+76
-3
lines changed

test/manifest_reader_test.cc

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class ManifestReaderV2Test : public TempFileTestBase {
131131
avro::RegisterLogicalTypes();
132132
}
133133

134-
std::vector<ManifestEntry> PrepareV2NonPartitionedManifestEntries() {
134+
std::vector<ManifestEntry> prepareV2NonPartitionedManifestEntries() {
135135
std::vector<ManifestEntry> manifest_entries;
136136
std::string test_dir_prefix = "/tmp/db/db/v2_manifest_non_partitioned/data/";
137137

@@ -180,14 +180,87 @@ class ManifestReaderV2Test : public TempFileTestBase {
180180
return manifest_entries;
181181
}
182182

183+
std::vector<ManifestEntry> prepareV2ManifestEntryMetadataInheritance() {
184+
std::vector<ManifestEntry> manifest_entries;
185+
std::string test_dir_prefix = "/tmp/db/db/v2_manifest_non_partitioned/data/";
186+
187+
std::vector<std::string> paths = {
188+
"00000-0-b0f98903-6d21-45fd-9e0b-afbd4963e365-0-00001.parquet"};
189+
190+
std::vector<int64_t> file_sizes = {1344};
191+
std::vector<int64_t> record_counts = {4};
192+
193+
std::vector<std::map<int32_t, std::vector<uint8_t>>> lower_bounds = {
194+
{{1, {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
195+
{2, {'r', 'e', 'c', 'o', 'r', 'd', '_', 'f', 'o', 'u', 'r'}},
196+
{3, {'d', 'a', 't', 'a', '_', 'c', 'o', 'n', 't', 'e', 'n', 't', '_', '1'}},
197+
{4, {0xcd, 0xcc, 0xcc, 0xcc, 0xcc, 0xdc, 0x5e, 0x40}}}};
198+
199+
std::vector<std::map<int32_t, std::vector<uint8_t>>> upper_bounds = {
200+
{{1, {0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
201+
{2, {'r', 'e', 'c', 'o', 'r', 'd', '_', 't', 'w', 'o'}},
202+
{3, {'d', 'a', 't', 'a', '_', 'c', 'o', 'n', 't', 'e', 'n', 't', '_', '4'}},
203+
{4, {0x14, 0xae, 0x47, 0xe1, 0x7a, 0x8c, 0x7c, 0x40}}}};
204+
205+
manifest_entries.emplace_back(
206+
ManifestEntry{.status = ManifestStatus::kAdded,
207+
.snapshot_id = 679879563479918846LL,
208+
.sequence_number = 15,
209+
.file_sequence_number = 15,
210+
.data_file = std::make_shared<DataFile>(
211+
DataFile{.file_path = test_dir_prefix + paths[0],
212+
.file_format = FileFormatType::kParquet,
213+
.record_count = record_counts[0],
214+
.file_size_in_bytes = file_sizes[0],
215+
.column_sizes = {{1, 56}, {2, 73}, {3, 66}, {4, 67}},
216+
.value_counts = {{1, 4}, {2, 4}, {3, 4}, {4, 4}},
217+
.null_value_counts = {{1, 0}, {2, 0}, {3, 0}, {4, 0}},
218+
.nan_value_counts = {{4, 0}},
219+
.lower_bounds = lower_bounds[0],
220+
.upper_bounds = upper_bounds[0],
221+
.key_metadata = {},
222+
.split_offsets = {4},
223+
.equality_ids = {},
224+
.sort_order_id = 0,
225+
.partition_spec_id = 12, // inherit from manifest
226+
.first_row_id = std::nullopt,
227+
.referenced_data_file = std::nullopt,
228+
.content_offset = std::nullopt,
229+
.content_size_in_bytes = std::nullopt})});
230+
return manifest_entries;
231+
}
232+
183233
std::shared_ptr<::arrow::fs::LocalFileSystem> local_fs_;
184234
std::shared_ptr<FileIO> file_io_;
185235
};
186236

187237
TEST_F(ManifestReaderV2Test, V2NonPartitionedBasicTest) {
188238
std::string path = GetResourcePath("2ddf1bc9-830b-4015-aced-c060df36f150-m0.avro");
189239

190-
auto manifest_reader_result = ManifestReader::MakeReader(path, file_io_, nullptr);
240+
auto manifest_reader_result = ManifestReader::Make(path, file_io_, nullptr);
241+
ASSERT_EQ(manifest_reader_result.has_value(), true)
242+
<< manifest_reader_result.error().message;
243+
244+
auto manifest_reader = std::move(manifest_reader_result.value());
245+
auto read_result = manifest_reader->Entries();
246+
ASSERT_EQ(read_result.has_value(), true) << read_result.error().message;
247+
ASSERT_EQ(read_result.value().size(), 1);
248+
249+
auto expected_entries = prepareV2NonPartitionedManifestEntries();
250+
ASSERT_EQ(read_result.value(), expected_entries);
251+
}
252+
253+
TEST_F(ManifestReaderV2Test, V2ManifestEntryMetadataInheritanceTest) {
254+
std::string path = GetResourcePath("2ddf1bc9-830b-4015-aced-c060df36f150-m0.avro");
255+
ManifestFile manifest_file{
256+
.manifest_path = path,
257+
.manifest_length = 100,
258+
.partition_spec_id = 12,
259+
.content = ManifestFile::Content::kData,
260+
.sequence_number = 15,
261+
.added_snapshot_id = 679879563479918846LL,
262+
};
263+
auto manifest_reader_result = ManifestReader::Make(manifest_file, file_io_, nullptr);
191264
ASSERT_EQ(manifest_reader_result.has_value(), true)
192265
<< manifest_reader_result.error().message;
193266

@@ -196,7 +269,7 @@ TEST_F(ManifestReaderV2Test, V2NonPartitionedBasicTest) {
196269
ASSERT_EQ(read_result.has_value(), true) << read_result.error().message;
197270
ASSERT_EQ(read_result.value().size(), 1);
198271

199-
auto expected_entries = PrepareV2NonPartitionedManifestEntries();
272+
auto expected_entries = prepareV2ManifestEntryMetadataInheritance();
200273
ASSERT_EQ(read_result.value(), expected_entries);
201274
}
202275

0 commit comments

Comments
 (0)