-
Notifications
You must be signed in to change notification settings - Fork 70
feat: support manifest reader #150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ce30233
feat: support manifest reader
1b41460
add string util case
23e1024
fix inline
76a5131
fallback to use transform since gcc13 do not support range
a116bcf
fix type
d4dc829
merge same macros and seperate avro type register
a4afb26
fix string util
6244509
fix string util ns
f5ff4c2
fix comments
eb6c2f5
fix include
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <algorithm> | ||
| #include <ranges> | ||
| #include <string> | ||
|
|
||
| namespace iceberg::internal { | ||
|
|
||
| class StringUtils { | ||
dongxiao1198 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public: | ||
| static std::string ToLower(std::string_view str) { | ||
| std::string input(str); | ||
| // TODO(xiao.dong) gcc 13.3 didn't support std::ranges::to | ||
| std::transform(input.begin(), input.end(), input.begin(), // NOLINT | ||
| [](char c) { return std::tolower(c); }); // NOLINT | ||
| return input; | ||
| } | ||
|
|
||
| static std::string ToUpper(std::string_view str) { | ||
| std::string input(str); | ||
| // TODO(xiao.dong) gcc 13.3 didn't support std::ranges::to | ||
| std::transform(input.begin(), input.end(), input.begin(), // NOLINT | ||
| [](char c) { return std::toupper(c); }); // NOLINT | ||
| return input; | ||
| } | ||
| }; | ||
|
|
||
| } // namespace iceberg::internal | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| #include "iceberg/manifest_reader.h" | ||
|
|
||
| #include <arrow/filesystem/localfs.h> | ||
| #include <gtest/gtest.h> | ||
|
|
||
| #include "iceberg/arrow/arrow_fs_file_io.h" | ||
| #include "iceberg/avro/avro_reader.h" | ||
| #include "iceberg/avro/avro_schema_util_internal.h" | ||
| #include "iceberg/manifest_entry.h" | ||
| #include "iceberg/schema.h" | ||
| #include "temp_file_test_base.h" | ||
| #include "test_common.h" | ||
|
|
||
| namespace iceberg { | ||
|
|
||
| class ManifestReaderTest : public TempFileTestBase { | ||
| protected: | ||
| static void SetUpTestSuite() { avro::AvroReader::Register(); } | ||
|
|
||
| void SetUp() override { | ||
| TempFileTestBase::SetUp(); | ||
| local_fs_ = std::make_shared<::arrow::fs::LocalFileSystem>(); | ||
| file_io_ = std::make_shared<iceberg::arrow::ArrowFileSystemFileIO>(local_fs_); | ||
|
|
||
| avro::RegisterLogicalTypes(); | ||
| } | ||
|
|
||
| std::vector<ManifestEntry> prepare_manifest_entries() { | ||
| std::vector<ManifestEntry> manifest_entries; | ||
| std::string test_dir_prefix = "/tmp/db/db/iceberg_test/data/"; | ||
| std::vector<std::string> paths = { | ||
| "order_ts_hour=2021-01-27-00/" | ||
| "00000-2-d5ae78b7-4449-45ec-adb7-c0e9c0bdb714-0-00001.parquet", | ||
| "order_ts_hour=2024-01-27-00/" | ||
| "00000-2-d5ae78b7-4449-45ec-adb7-c0e9c0bdb714-0-00002.parquet", | ||
| "order_ts_hour=2023-01-26-00/" | ||
| "00000-2-d5ae78b7-4449-45ec-adb7-c0e9c0bdb714-0-00003.parquet", | ||
| "order_ts_hour=2021-01-26-00/" | ||
| "00000-2-d5ae78b7-4449-45ec-adb7-c0e9c0bdb714-0-00004.parquet"}; | ||
| std::vector<int64_t> partitions = {447696, 473976, 465192, 447672}; | ||
| std::vector<std::map<int32_t, std::vector<uint8_t>>> bounds = { | ||
| {{1, {0xd2, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}, | ||
| {2, {'.', 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}, | ||
| {3, {0x12, 0xe2}}, | ||
| {4, {0xc0, 'y', 0xe7, 0x98, 0xd6, 0xb9, 0x05, 0x00}}}, | ||
| {{1, {0xd2, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}, | ||
| {2, {'.', 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}, | ||
| {3, {0x12, 0xe3}}, | ||
| {4, {0xc0, 0x19, '#', '=', 0xe2, 0x0f, 0x06, 0x00}}}, | ||
| {{1, {'{', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}, | ||
| {2, {0xc8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}, | ||
| {3, {0x0e, '"'}}, | ||
| {4, {0xc0, 0xd9, '7', 0x93, 0x1f, 0xf3, 0x05, 0x00}}}, | ||
| {{1, {'{', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}, | ||
| {2, {0xc8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}, | ||
| {3, {0x0e, '!'}}, | ||
| {4, {0xc0, 0x19, 0x10, '{', 0xc2, 0xb9, 0x05, 0x00}}}, | ||
| }; | ||
| for (int i = 0; i < 4; ++i) { | ||
| ManifestEntry entry; | ||
| entry.status = ManifestStatus::kAdded; | ||
| entry.snapshot_id = 6387266376565973956; | ||
| entry.data_file = std::make_shared<DataFile>(); | ||
| entry.data_file->file_path = test_dir_prefix + paths[i]; | ||
| entry.data_file->file_format = FileFormatType::kParquet; | ||
| entry.data_file->partition.emplace_back(Literal::Int(partitions[i])); | ||
| entry.data_file->record_count = 1; | ||
| entry.data_file->file_size_in_bytes = 1375; | ||
| entry.data_file->column_sizes = {{1, 49}, {2, 49}, {3, 49}, {4, 49}}; | ||
| entry.data_file->value_counts = {{1, 1}, {2, 1}, {3, 1}, {4, 1}}; | ||
| entry.data_file->null_value_counts = {{1, 0}, {2, 0}, {3, 0}, {4, 0}}; | ||
| entry.data_file->split_offsets = {4}; | ||
| entry.data_file->sort_order_id = 0; | ||
| entry.data_file->upper_bounds = bounds[i]; | ||
| entry.data_file->lower_bounds = bounds[i]; | ||
| manifest_entries.emplace_back(entry); | ||
| } | ||
| return manifest_entries; | ||
| } | ||
|
|
||
| std::shared_ptr<::arrow::fs::LocalFileSystem> local_fs_; | ||
| std::shared_ptr<FileIO> file_io_; | ||
| }; | ||
|
|
||
| TEST_F(ManifestReaderTest, BasicTest) { | ||
| iceberg::SchemaField partition_field(1000, "order_ts_hour", iceberg::int32(), true); | ||
| auto partition_schema = | ||
| std::make_shared<Schema>(std::vector<SchemaField>({partition_field})); | ||
| std::string path = GetResourcePath("56357cd7-391f-4df8-aa24-e7e667da8870-m4.avro"); | ||
| auto manifest_reader_result = | ||
| ManifestReader::MakeReader(path, file_io_, partition_schema); | ||
| ASSERT_EQ(manifest_reader_result.has_value(), true) | ||
| << manifest_reader_result.error().message; | ||
| auto manifest_reader = std::move(manifest_reader_result.value()); | ||
| auto read_result = manifest_reader->Entries(); | ||
| ASSERT_EQ(read_result.has_value(), true) << read_result.error().message; | ||
|
|
||
| auto expected_entries = prepare_manifest_entries(); | ||
| ASSERT_EQ(read_result.value(), expected_entries); | ||
| } | ||
|
|
||
| } // namespace iceberg |
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| #include "iceberg/util/string_utils.h" | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| namespace iceberg { | ||
|
|
||
| TEST(StringUtilsTest, ToLower) { | ||
| ASSERT_EQ(internal::StringUtils::ToLower("AbC"), "abc"); | ||
| ASSERT_EQ(internal::StringUtils::ToLower("A-bC"), "a-bc"); | ||
| ASSERT_EQ(internal::StringUtils::ToLower("A_bC"), "a_bc"); | ||
| ASSERT_EQ(internal::StringUtils::ToLower(""), ""); | ||
| ASSERT_EQ(internal::StringUtils::ToLower(" "), " "); | ||
| ASSERT_EQ(internal::StringUtils::ToLower("123"), "123"); | ||
| } | ||
|
|
||
| TEST(StringUtilsTest, ToUpper) { | ||
| ASSERT_EQ(internal::StringUtils::ToUpper("abc"), "ABC"); | ||
| ASSERT_EQ(internal::StringUtils::ToUpper("A-bC"), "A-BC"); | ||
| ASSERT_EQ(internal::StringUtils::ToUpper("A_bC"), "A_BC"); | ||
| ASSERT_EQ(internal::StringUtils::ToUpper(""), ""); | ||
| ASSERT_EQ(internal::StringUtils::ToUpper(" "), " "); | ||
| ASSERT_EQ(internal::StringUtils::ToUpper("123"), "123"); | ||
| } | ||
|
|
||
| } // namespace iceberg |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.