-
Notifications
You must be signed in to change notification settings - Fork 4.3k
GH-50891: [C++][Parquet] DON'T MERGE NOW: Support FILE logical type #50892
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
Open
HuaHuaY
wants to merge
2
commits into
apache:main
Choose a base branch
from
HuaHuaY:implement_file_type
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| // 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 "arrow/extension/parquet_file.h" | ||
|
|
||
| #include "arrow/extension_type.h" | ||
| #include "arrow/result.h" | ||
| #include "arrow/status.h" | ||
| #include "arrow/type.h" | ||
| #include "arrow/type_traits.h" | ||
| #include "arrow/util/logging_internal.h" | ||
|
|
||
| namespace arrow::extension { | ||
|
|
||
| namespace { | ||
|
|
||
| bool IsSupportedField(const std::shared_ptr<Field>& field) { | ||
| if (!field->nullable()) { | ||
| return false; | ||
| } | ||
| if (field->name() == "uri" || field->name() == "content_type" || | ||
| field->name() == "checksum") { | ||
| return ::arrow::is_string_or_string_view(field->type()->id()); | ||
| } | ||
| if (field->name() == "offset" || field->name() == "size") { | ||
| return field->type()->id() == Type::INT64; | ||
| } | ||
| if (field->name() == "inline") { | ||
| return ::arrow::is_binary_or_binary_view(field->type()->id()); | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| FileExtensionType::FileExtensionType(const std::shared_ptr<DataType>& storage_type) | ||
| : ExtensionType(storage_type) { | ||
| for (const auto& field : storage_type->fields()) { | ||
| if (field->name() == "uri") { | ||
| uri_ = field; | ||
| } else if (field->name() == "offset") { | ||
| offset_ = field; | ||
| } else if (field->name() == "size") { | ||
| size_ = field; | ||
| } else if (field->name() == "content_type") { | ||
| content_type_ = field; | ||
| } else if (field->name() == "checksum") { | ||
| checksum_ = field; | ||
| } else if (field->name() == "inline") { | ||
| inline_bytes_ = field; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| bool FileExtensionType::ExtensionEquals(const ExtensionType& other) const { | ||
| return other.extension_name() == extension_name() && | ||
| other.storage_type()->Equals(*storage_type()); | ||
| } | ||
|
|
||
| Result<std::shared_ptr<DataType>> FileExtensionType::Deserialize( | ||
| std::shared_ptr<DataType> storage_type, const std::string& serialized) const { | ||
| if (!serialized.empty()) { | ||
| return Status::Invalid("Unexpected serialized metadata: '", serialized, "'"); | ||
| } | ||
| return FileExtensionType::Make(std::move(storage_type)); | ||
| } | ||
|
|
||
| std::string FileExtensionType::Serialize() const { return ""; } | ||
|
|
||
| std::shared_ptr<Array> FileExtensionType::MakeArray( | ||
| std::shared_ptr<ArrayData> data) const { | ||
| DCHECK_EQ(data->type->id(), Type::EXTENSION); | ||
| DCHECK_EQ(kFileExtensionName, | ||
| internal::checked_cast<const ExtensionType&>(*data->type).extension_name()); | ||
| return std::make_shared<FileArray>(std::move(data)); | ||
| } | ||
|
|
||
| bool FileExtensionType::IsSupportedStorageType( | ||
| const std::shared_ptr<DataType>& storage_type) { | ||
| if (!storage_type || storage_type->id() != Type::STRUCT || | ||
| storage_type->fields().empty()) { | ||
| return false; | ||
| } | ||
|
|
||
| for (const auto& field : storage_type->fields()) { | ||
| if (!IsSupportedField(field)) { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| for (int i = 0; i < storage_type->num_fields(); ++i) { | ||
| for (int j = i + 1; j < storage_type->num_fields(); ++j) { | ||
| if (storage_type->field(i)->name() == storage_type->field(j)->name()) { | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| Result<std::shared_ptr<DataType>> FileExtensionType::Make( | ||
| std::shared_ptr<DataType> storage_type) { | ||
| if (!IsSupportedStorageType(storage_type)) { | ||
| return Status::Invalid("Invalid storage type for FileExtensionType: ", | ||
| storage_type ? storage_type->ToString() : "null"); | ||
| } | ||
| return std::make_shared<FileExtensionType>(std::move(storage_type)); | ||
| } | ||
|
|
||
| std::shared_ptr<DataType> file(std::shared_ptr<DataType> storage_type) { | ||
| return FileExtensionType::Make(std::move(storage_type)).ValueOrDie(); | ||
| } | ||
|
|
||
| } // namespace arrow::extension |
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,76 @@ | ||
| // 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 <memory> | ||
| #include <string> | ||
| #include <string_view> | ||
|
|
||
| #include "arrow/extension_type.h" | ||
| #include "arrow/util/visibility.h" | ||
|
|
||
| namespace arrow::extension { | ||
|
|
||
| /// \brief The extension name for the File extension type. | ||
| inline constexpr std::string_view kFileExtensionName = "parquet.file.experimental.v1"; | ||
|
|
||
| class ARROW_EXPORT FileArray : public ExtensionArray { | ||
| public: | ||
| using ExtensionArray::ExtensionArray; | ||
| }; | ||
|
|
||
| class ARROW_EXPORT FileExtensionType : public ExtensionType { | ||
| public: | ||
| explicit FileExtensionType(const std::shared_ptr<DataType>& storage_type); | ||
|
|
||
| std::string extension_name() const override { return std::string(kFileExtensionName); } | ||
|
|
||
| bool ExtensionEquals(const ExtensionType& other) const override; | ||
|
|
||
| Result<std::shared_ptr<DataType>> Deserialize( | ||
| std::shared_ptr<DataType> storage_type, | ||
| const std::string& serialized_data) const override; | ||
|
|
||
| std::string Serialize() const override; | ||
|
|
||
| std::shared_ptr<Array> MakeArray(std::shared_ptr<ArrayData> data) const override; | ||
|
|
||
| static Result<std::shared_ptr<DataType>> Make(std::shared_ptr<DataType> storage_type); | ||
|
|
||
| static bool IsSupportedStorageType(const std::shared_ptr<DataType>& storage_type); | ||
|
|
||
| std::shared_ptr<Field> uri() const { return uri_; } | ||
| std::shared_ptr<Field> offset() const { return offset_; } | ||
| std::shared_ptr<Field> size() const { return size_; } | ||
| std::shared_ptr<Field> content_type() const { return content_type_; } | ||
| std::shared_ptr<Field> checksum() const { return checksum_; } | ||
| std::shared_ptr<Field> inline_bytes() const { return inline_bytes_; } | ||
|
|
||
| private: | ||
| std::shared_ptr<Field> uri_; | ||
| std::shared_ptr<Field> offset_; | ||
| std::shared_ptr<Field> size_; | ||
| std::shared_ptr<Field> content_type_; | ||
| std::shared_ptr<Field> checksum_; | ||
| std::shared_ptr<Field> inline_bytes_; | ||
| }; | ||
|
|
||
| /// \brief Return a FileExtensionType instance. | ||
| ARROW_EXPORT std::shared_ptr<DataType> file(std::shared_ptr<DataType> storage_type); | ||
|
|
||
| } // namespace arrow::extension |
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. | ||
|
|
||
| #include <vector> | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| #include "arrow/extension/parquet_file.h" | ||
| #include "arrow/testing/gtest_util.h" | ||
| #include "arrow/type.h" | ||
|
|
||
| namespace arrow::extension { | ||
|
|
||
| TEST(FileType, InvalidStorage) { | ||
| // FILE storage fields must use one of the six recognized names. | ||
| ASSERT_NOT_OK(FileExtensionType::Make(struct_({field("unknown", binary())}))); | ||
|
|
||
| // Every FILE storage field must be nullable. | ||
| ASSERT_NOT_OK( | ||
| FileExtensionType::Make(struct_({field("uri", utf8(), /*nullable=*/false)}))); | ||
|
|
||
| // The offset and size fields must use INT64 storage. | ||
| ASSERT_NOT_OK(FileExtensionType::Make(struct_({field("offset", int32())}))); | ||
|
|
||
| // The inline field must use a binary storage family. | ||
| ASSERT_NOT_OK(FileExtensionType::Make(struct_({field("inline", utf8())}))); | ||
|
|
||
| // FILE storage field names must be unique. | ||
| ASSERT_NOT_OK( | ||
| FileExtensionType::Make(struct_({field("uri", utf8()), field("uri", utf8())}))); | ||
| } | ||
|
|
||
| } // namespace arrow::extension | ||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other test ideas:
REQUIREDfield among otherwise-valid onescontent_type/checksum/size(onlyuri/offset/inlinetype-errors are tested)