-
Notifications
You must be signed in to change notification settings - Fork 99
feat(puffin): add basic data structures and constants #588
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
zhaoxuan1994
wants to merge
1
commit into
apache:main
Choose a base branch
from
zhaoxuan1994:feat/puffin-basic-types
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.
+278
−0
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # 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. | ||
|
|
||
| iceberg_install_all_headers(iceberg/puffin) |
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,118 @@ | ||
| /* | ||
| * 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/puffin/file_metadata.h" | ||
|
|
||
| #include <format> | ||
| #include <utility> | ||
|
|
||
| #include "iceberg/util/formatter_internal.h" | ||
|
|
||
| namespace iceberg::puffin { | ||
|
|
||
| namespace { | ||
| constexpr std::string_view kLz4CodecName = "lz4"; | ||
| constexpr std::string_view kZstdCodecName = "zstd"; | ||
| } // namespace | ||
|
|
||
| std::string_view CodecName(PuffinCompressionCodec codec) { | ||
| switch (codec) { | ||
| case PuffinCompressionCodec::kNone: | ||
| return ""; | ||
| case PuffinCompressionCodec::kLz4: | ||
| return kLz4CodecName; | ||
| case PuffinCompressionCodec::kZstd: | ||
| return kZstdCodecName; | ||
| } | ||
| std::unreachable(); | ||
| } | ||
|
|
||
| Result<PuffinCompressionCodec> PuffinCompressionCodecFromName( | ||
| std::string_view codec_name) { | ||
| if (codec_name.empty()) { | ||
| return PuffinCompressionCodec::kNone; | ||
| } | ||
| if (codec_name == kLz4CodecName) { | ||
| return PuffinCompressionCodec::kLz4; | ||
| } | ||
| if (codec_name == kZstdCodecName) { | ||
| return PuffinCompressionCodec::kZstd; | ||
| } | ||
| return InvalidArgument("Unknown codec name: {}", codec_name); | ||
| } | ||
|
|
||
| std::string ToString(PuffinCompressionCodec codec) { | ||
| return std::string(CodecName(codec)); | ||
| } | ||
|
|
||
| std::string ToString(const Blob& blob) { | ||
| std::string repr = "Blob["; | ||
| std::format_to(std::back_inserter(repr), "type='{}',inputFields={},", blob.type, | ||
| blob.input_fields); | ||
| std::format_to(std::back_inserter(repr), "snapshotId={},sequenceNumber={},", | ||
| blob.snapshot_id, blob.sequence_number); | ||
| std::format_to(std::back_inserter(repr), "dataSize={}", blob.data.size()); | ||
| if (blob.requested_compression.has_value()) { | ||
| std::format_to(std::back_inserter(repr), ",requestedCompression={}", | ||
| ToString(*blob.requested_compression)); | ||
| } | ||
| if (!blob.properties.empty()) { | ||
| std::format_to(std::back_inserter(repr), ",properties={}", blob.properties); | ||
| } | ||
| std::format_to(std::back_inserter(repr), "]"); | ||
| return repr; | ||
| } | ||
|
|
||
| std::string ToString(const BlobMetadata& blob_metadata) { | ||
| std::string repr = "BlobMetadata["; | ||
| std::format_to(std::back_inserter(repr), "type='{}',inputFields={},", | ||
| blob_metadata.type, blob_metadata.input_fields); | ||
| std::format_to(std::back_inserter(repr), "snapshotId={},sequenceNumber={},", | ||
| blob_metadata.snapshot_id, blob_metadata.sequence_number); | ||
| std::format_to(std::back_inserter(repr), "offset={},length={}", blob_metadata.offset, | ||
| blob_metadata.length); | ||
| if (!blob_metadata.compression_codec.empty()) { | ||
| std::format_to(std::back_inserter(repr), ",compressionCodec='{}'", | ||
| blob_metadata.compression_codec); | ||
| } | ||
| if (!blob_metadata.properties.empty()) { | ||
| std::format_to(std::back_inserter(repr), ",properties={}", blob_metadata.properties); | ||
| } | ||
| std::format_to(std::back_inserter(repr), "]"); | ||
| return repr; | ||
| } | ||
|
|
||
| std::string ToString(const FileMetadata& file_metadata) { | ||
| std::string repr = "FileMetadata["; | ||
| std::format_to(std::back_inserter(repr), "blobs=["); | ||
| for (size_t i = 0; i < file_metadata.blobs.size(); ++i) { | ||
| if (i > 0) { | ||
| std::format_to(std::back_inserter(repr), ","); | ||
| } | ||
| std::format_to(std::back_inserter(repr), "{}", ToString(file_metadata.blobs[i])); | ||
| } | ||
| std::format_to(std::back_inserter(repr), "]"); | ||
| if (!file_metadata.properties.empty()) { | ||
| std::format_to(std::back_inserter(repr), ",properties={}", file_metadata.properties); | ||
| } | ||
| std::format_to(std::back_inserter(repr), "]"); | ||
| return repr; | ||
| } | ||
|
|
||
| } // namespace iceberg::puffin |
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,120 @@ | ||
| /* | ||
| * 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 | ||
|
|
||
| /// \file iceberg/puffin/file_metadata.h | ||
| /// Data structures for Puffin files. | ||
|
|
||
| #include <cstdint> | ||
| #include <optional> | ||
| #include <string> | ||
| #include <string_view> | ||
| #include <unordered_map> | ||
| #include <vector> | ||
|
|
||
| #include "iceberg/iceberg_export.h" | ||
| #include "iceberg/result.h" | ||
|
|
||
| namespace iceberg::puffin { | ||
|
|
||
| /// \brief Compression codecs supported by Puffin files. | ||
| enum class PuffinCompressionCodec { | ||
| kNone, | ||
| kLz4, | ||
| kZstd, | ||
| }; | ||
|
|
||
| ICEBERG_EXPORT std::string_view CodecName(PuffinCompressionCodec codec); | ||
|
|
||
| ICEBERG_EXPORT Result<PuffinCompressionCodec> PuffinCompressionCodecFromName( | ||
| std::string_view codec_name); | ||
|
|
||
| ICEBERG_EXPORT std::string ToString(PuffinCompressionCodec codec); | ||
|
|
||
| /// \brief Standard blob types defined by the Iceberg specification. | ||
| struct StandardBlobTypes { | ||
| /// A serialized form of a "compact" Theta sketch produced by the | ||
| /// Apache DataSketches library. | ||
| static constexpr std::string_view kApacheDatasketchesThetaV1 = | ||
| "apache-datasketches-theta-v1"; | ||
|
|
||
| /// A serialized deletion vector according to the Iceberg spec. | ||
| static constexpr std::string_view kDeletionVectorV1 = "deletion-vector-v1"; | ||
| }; | ||
|
|
||
| /// \brief Standard file-level properties for Puffin files. | ||
| struct StandardPuffinProperties { | ||
| /// Human-readable identification of the application writing the file, | ||
| /// along with its version. | ||
| static constexpr std::string_view kCreatedBy = "created-by"; | ||
| }; | ||
|
|
||
| /// \brief A blob in a Puffin file. | ||
| struct ICEBERG_EXPORT Blob { | ||
| /// See StandardBlobTypes for known types. | ||
| std::string type; | ||
| /// Ordered list of field IDs the blob was computed from. | ||
| std::vector<int32_t> input_fields; | ||
| /// ID of the Iceberg table's snapshot the blob was computed from. | ||
| int64_t snapshot_id; | ||
| /// Sequence number of the Iceberg table's snapshot the blob was computed from. | ||
| int64_t sequence_number; | ||
| std::vector<uint8_t> data; | ||
| /// If not set, the writer's default codec will be used. | ||
| std::optional<PuffinCompressionCodec> requested_compression; | ||
| std::unordered_map<std::string, std::string> properties; | ||
|
|
||
| friend bool operator==(const Blob& lhs, const Blob& rhs) = default; | ||
| }; | ||
|
|
||
| ICEBERG_EXPORT std::string ToString(const Blob& blob); | ||
|
|
||
| /// \brief Metadata about a blob stored in a Puffin file footer. | ||
| struct ICEBERG_EXPORT BlobMetadata { | ||
| /// See StandardBlobTypes for known types. | ||
| std::string type; | ||
| /// Ordered list of field IDs the blob was computed from. | ||
| std::vector<int32_t> input_fields; | ||
| /// ID of the Iceberg table's snapshot the blob was computed from. | ||
| int64_t snapshot_id; | ||
| /// Sequence number of the Iceberg table's snapshot the blob was computed from. | ||
| int64_t sequence_number; | ||
| int64_t offset; | ||
| int64_t length; | ||
| /// Codec name (e.g. "lz4", "zstd"), or empty if not compressed. | ||
| std::string compression_codec; | ||
| std::unordered_map<std::string, std::string> properties; | ||
|
|
||
| friend bool operator==(const BlobMetadata& lhs, const BlobMetadata& rhs) = default; | ||
| }; | ||
|
|
||
| ICEBERG_EXPORT std::string ToString(const BlobMetadata& blob_metadata); | ||
|
|
||
| /// \brief Metadata about a Puffin file. | ||
wgtmac marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| struct ICEBERG_EXPORT FileMetadata { | ||
| std::vector<BlobMetadata> blobs; | ||
| std::unordered_map<std::string, std::string> properties; | ||
|
|
||
| friend bool operator==(const FileMetadata& lhs, const FileMetadata& rhs) = default; | ||
| }; | ||
|
|
||
| ICEBERG_EXPORT std::string ToString(const FileMetadata& file_metadata); | ||
|
|
||
| } // namespace iceberg::puffin | ||
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,18 @@ | ||
| # 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. | ||
|
|
||
| install_headers(['file_metadata.h'], subdir: 'iceberg/puffin') |
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.
It seems that we can also include both
types.handpuffin_compression_codec.hto this file as they are unlikely to be used individually.