wgtmac commented on code in PR #588: URL: https://github.com/apache/iceberg-cpp/pull/588#discussion_r2973774329
########## src/iceberg/puffin/file_metadata.h: ########## @@ -0,0 +1,100 @@ +/* + * 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: Blob, BlobMetadata, and FileMetadata. + +#include <cstdint> +#include <optional> +#include <string> +#include <unordered_map> +#include <vector> + +#include "iceberg/iceberg_export.h" +#include "iceberg/puffin/puffin_compression_codec.h" + +namespace iceberg::puffin { + +/// \brief A blob in a Puffin file. +struct ICEBERG_EXPORT Blob { + /// \brief Type of the blob. See StandardBlobTypes for known types. + std::string type; + /// \brief List of field IDs the blob was computed for. + std::vector<int32_t> input_fields; + /// \brief ID of the Iceberg table's snapshot the blob was computed from. + int64_t snapshot_id; + /// \brief Sequence number of the Iceberg table's snapshot the blob was computed from. + int64_t sequence_number; + /// \brief The uncompressed blob data. + std::vector<uint8_t> data; + /// \brief Requested compression codec. If not set, the writer's default will be used. + std::optional<PuffinCompressionCodec> requested_compression; Review Comment: It seems that we can also include both `types.h` and `puffin_compression_codec.h` to this file as they are unlikely to be used individually. ########## src/iceberg/puffin/puffin_compression_codec.cc: ########## @@ -0,0 +1,66 @@ +/* + * 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/puffin_compression_codec.h" + +#include <format> +#include <utility> + +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) { + auto name = CodecName(codec); + if (!name.empty()) { + return std::string(name); + } + return "none"; Review Comment: This breaks the roundtrip with PuffinCompressionCodecFromName. Is this intentional? Should we return empty string as is? ########## src/iceberg/puffin/puffin_compression_codec.h: ########## @@ -0,0 +1,57 @@ +/* + * 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/puffin_compression_codec.h +/// Compression codec definitions for Puffin files. + +#include <string> +#include <string_view> + +#include "iceberg/iceberg_export.h" +#include "iceberg/result.h" + +namespace iceberg::puffin { + +/// \brief Compression codecs supported by Puffin files. +enum class PuffinCompressionCodec { + /// No compression + kNone, + /// LZ4 single compression frame with content size present + kLz4, + /// Zstandard single compression frame with content size present + kZstd, +}; + +/// \brief Get the codec name for a compression codec. +/// +/// Returns an empty string for kNone. +ICEBERG_EXPORT std::string_view CodecName(PuffinCompressionCodec codec); + +/// \brief Get the compression codec from a codec name. +/// +/// An empty string is interpreted as kNone. Review Comment: ```suggestion ``` ########## src/iceberg/puffin/puffin_compression_codec.h: ########## @@ -0,0 +1,57 @@ +/* + * 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/puffin_compression_codec.h +/// Compression codec definitions for Puffin files. + +#include <string> +#include <string_view> + +#include "iceberg/iceberg_export.h" +#include "iceberg/result.h" + +namespace iceberg::puffin { + +/// \brief Compression codecs supported by Puffin files. +enum class PuffinCompressionCodec { + /// No compression + kNone, + /// LZ4 single compression frame with content size present + kLz4, + /// Zstandard single compression frame with content size present + kZstd, +}; + +/// \brief Get the codec name for a compression codec. +/// +/// Returns an empty string for kNone. Review Comment: ```suggestion ``` ########## src/iceberg/puffin/file_metadata.cc: ########## @@ -0,0 +1,82 @@ +/* + * 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 "iceberg/util/formatter_internal.h" + +namespace iceberg::puffin { + +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={}", + iceberg::puffin::ToString(*blob.requested_compression)); Review Comment: ```suggestion ToString(*blob.requested_compression)); ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
