wgtmac commented on code in PR #1198:
URL: https://github.com/apache/iceberg-cpp/pull/1198#discussion_r4750245836
##########
src/iceberg/puffin/puffin_format.cc:
##########
@@ -69,8 +89,32 @@ Result<std::vector<std::byte>>
Decompress(PuffinCompressionCodec codec,
return std::vector<std::byte>(input.begin(), input.end());
case PuffinCompressionCodec::kLz4:
return NotSupported("LZ4 decompression is not yet supported");
- case PuffinCompressionCodec::kZstd:
- return NotSupported("Zstd decompression is not yet supported");
+ case PuffinCompressionCodec::kZstd: {
+ const uint64_t frame_size = ZSTD_getFrameContentSize(input.data(),
input.size());
+ if (frame_size == ZSTD_CONTENTSIZE_ERROR) {
+ return DecompressError("Content size of the compressed data is
invalid");
+ }
+ if (frame_size == ZSTD_CONTENTSIZE_UNKNOWN) {
+ return DecompressError("Content size of the compressed data is
unknown");
+ }
+ if (frame_size > std::numeric_limits<int32_t>::max()) {
+ // Matches Java, which rejects content sizes beyond the int range.
+ return DecompressError("Content size of the compressed data is too
large");
+ }
+
+ std::vector<std::byte> output(frame_size);
+ const size_t decompressed_size =
+ ZSTD_decompress(output.data(), output.size(), input.data(),
input.size());
Review Comment:
The [Puffin
spec](https://github.com/apache/iceberg/blob/93b755334ef470ba52f1c474c736feb20a00b658/format/puffin-spec.md#compression-codecs)
requires one Zstd frame. An extra empty frame still passes this size check.
Can we check that a single standard frame spans the entire blob and add a
regression test?
##########
cmake_modules/IcebergThirdpartyToolchain.cmake:
##########
@@ -902,16 +902,86 @@ endfunction()
# ----------------------------------------------------------------------
# Zstd
+#
function(resolve_zstd_dependency)
- find_package(zstd CONFIG)
- if(zstd_FOUND)
+ prepare_fetchcontent()
+
+ set(ZSTD_BUILD_PROGRAMS OFF)
+ set(ZSTD_BUILD_TESTS OFF)
+ set(ZSTD_BUILD_SHARED OFF)
+ set(ZSTD_BUILD_STATIC ON)
+ set(ZSTD_MULTITHREAD_SUPPORT OFF)
+
+ set(ICEBERG_ZSTD_BUILD_VERSION "1.5.7")
+ set(ICEBERG_ZSTD_BUILD_SHA256_CHECKSUM
+ "eb33e51f49a15e023950cd7825ca74a4a2b43db8354825ac24fc1b7ee09e6fa3")
+
+ if(DEFINED ENV{ICEBERG_ZSTD_URL})
+ set(ZSTD_URL "$ENV{ICEBERG_ZSTD_URL}")
+ else()
+ set(ZSTD_URL
+
"https://github.com/facebook/zstd/releases/download/v${ICEBERG_ZSTD_BUILD_VERSION}/zstd-${ICEBERG_ZSTD_BUILD_VERSION}.tar.gz"
+ )
+ endif()
+
+ fetchcontent_declare(zstd
+ ${FC_DECLARE_COMMON_OPTIONS}
+ URL ${ZSTD_URL}
+ URL_HASH "SHA256=${ICEBERG_ZSTD_BUILD_SHA256_CHECKSUM}"
+ SOURCE_SUBDIR
+ build/cmake
+ FIND_PACKAGE_ARGS
+ NAMES
+ zstd
+ CONFIG)
+ fetchcontent_makeavailable(zstd)
+
+ if(zstd_SOURCE_DIR)
+ set(ZSTD_VENDORED TRUE)
+ set_target_properties(libzstd_static PROPERTIES OUTPUT_NAME
"iceberg_vendored_zstd"
+ POSITION_INDEPENDENT_CODE
ON)
+ install(TARGETS libzstd_static
Review Comment:
nit: please install zstd's BSD license with it.
##########
cmake_modules/IcebergThirdpartyToolchain.cmake:
##########
@@ -902,16 +902,86 @@ endfunction()
# ----------------------------------------------------------------------
# Zstd
+#
function(resolve_zstd_dependency)
- find_package(zstd CONFIG)
- if(zstd_FOUND)
+ prepare_fetchcontent()
+
+ set(ZSTD_BUILD_PROGRAMS OFF)
+ set(ZSTD_BUILD_TESTS OFF)
+ set(ZSTD_BUILD_SHARED OFF)
+ set(ZSTD_BUILD_STATIC ON)
+ set(ZSTD_MULTITHREAD_SUPPORT OFF)
+
+ set(ICEBERG_ZSTD_BUILD_VERSION "1.5.7")
+ set(ICEBERG_ZSTD_BUILD_SHA256_CHECKSUM
+ "eb33e51f49a15e023950cd7825ca74a4a2b43db8354825ac24fc1b7ee09e6fa3")
+
+ if(DEFINED ENV{ICEBERG_ZSTD_URL})
+ set(ZSTD_URL "$ENV{ICEBERG_ZSTD_URL}")
+ else()
+ set(ZSTD_URL
+
"https://github.com/facebook/zstd/releases/download/v${ICEBERG_ZSTD_BUILD_VERSION}/zstd-${ICEBERG_ZSTD_BUILD_VERSION}.tar.gz"
+ )
+ endif()
+
+ fetchcontent_declare(zstd
+ ${FC_DECLARE_COMMON_OPTIONS}
+ URL ${ZSTD_URL}
+ URL_HASH "SHA256=${ICEBERG_ZSTD_BUILD_SHA256_CHECKSUM}"
+ SOURCE_SUBDIR
+ build/cmake
+ FIND_PACKAGE_ARGS
+ NAMES
+ zstd
+ CONFIG)
+ fetchcontent_makeavailable(zstd)
Review Comment:
CMake 3.25–3.27 also installs zstd's own package files. `libzstd.pc` still
points to `-lzstd` after the archive is renamed. Can we skip the upstream
install rules?
##########
src/iceberg/test/resources/puffin/v1/README.md:
##########
@@ -0,0 +1,5 @@
+# Puffin fixtures from Apache Iceberg Java
Review Comment:
RAT treats the two uncompressed `.bin` fixtures as text. Please add
`src/iceberg/test/resources/puffin/v1/*.bin` to
`dev/release/rat_exclude_files.txt` and add the ASF header here.
##########
cmake_modules/IcebergThirdpartyToolchain.cmake:
##########
@@ -902,16 +902,86 @@ endfunction()
# ----------------------------------------------------------------------
# Zstd
+#
function(resolve_zstd_dependency)
- find_package(zstd CONFIG)
- if(zstd_FOUND)
+ prepare_fetchcontent()
+
+ set(ZSTD_BUILD_PROGRAMS OFF)
+ set(ZSTD_BUILD_TESTS OFF)
+ set(ZSTD_BUILD_SHARED OFF)
+ set(ZSTD_BUILD_STATIC ON)
+ set(ZSTD_MULTITHREAD_SUPPORT OFF)
+
+ set(ICEBERG_ZSTD_BUILD_VERSION "1.5.7")
+ set(ICEBERG_ZSTD_BUILD_SHA256_CHECKSUM
+ "eb33e51f49a15e023950cd7825ca74a4a2b43db8354825ac24fc1b7ee09e6fa3")
+
+ if(DEFINED ENV{ICEBERG_ZSTD_URL})
+ set(ZSTD_URL "$ENV{ICEBERG_ZSTD_URL}")
+ else()
+ set(ZSTD_URL
+
"https://github.com/facebook/zstd/releases/download/v${ICEBERG_ZSTD_BUILD_VERSION}/zstd-${ICEBERG_ZSTD_BUILD_VERSION}.tar.gz"
+ )
+ endif()
+
+ fetchcontent_declare(zstd
+ ${FC_DECLARE_COMMON_OPTIONS}
+ URL ${ZSTD_URL}
+ URL_HASH "SHA256=${ICEBERG_ZSTD_BUILD_SHA256_CHECKSUM}"
+ SOURCE_SUBDIR
+ build/cmake
+ FIND_PACKAGE_ARGS
+ NAMES
+ zstd
+ CONFIG)
+ fetchcontent_makeavailable(zstd)
+
+ if(zstd_SOURCE_DIR)
+ set(ZSTD_VENDORED TRUE)
+ set_target_properties(libzstd_static PROPERTIES OUTPUT_NAME
"iceberg_vendored_zstd"
+ POSITION_INDEPENDENT_CODE
ON)
+ install(TARGETS libzstd_static
+ EXPORT iceberg_targets
+ RUNTIME DESTINATION "${ICEBERG_INSTALL_BINDIR}"
+ ARCHIVE DESTINATION "${ICEBERG_INSTALL_LIBDIR}"
+ LIBRARY DESTINATION "${ICEBERG_INSTALL_LIBDIR}")
+ set(ICEBERG_ZSTD_STATIC_TARGET libzstd_static)
+ set(ICEBERG_ZSTD_SHARED_TARGET libzstd_static)
+ else()
+ set(ZSTD_VENDORED FALSE)
list(APPEND ICEBERG_SYSTEM_DEPENDENCIES zstd)
message(STATUS "Found zstd, version: ${zstd_VERSION}")
- set(ICEBERG_SYSTEM_DEPENDENCIES
- ${ICEBERG_SYSTEM_DEPENDENCIES}
- PARENT_SCOPE)
+ # zstd exports libzstd_static and libzstd_shared; vcpkg may only provide
the
+ # unified zstd::libzstd target.
+ if(TARGET zstd::libzstd_static)
Review Comment:
Do we need separate zstd targets for the static and shared builds? Could we
pick one target and use it for both, like we do with `ZLIB::ZLIB`?
##########
src/iceberg/puffin/puffin_format.cc:
##########
@@ -69,8 +91,47 @@ Result<std::vector<std::byte>>
Decompress(PuffinCompressionCodec codec,
return std::vector<std::byte>(input.begin(), input.end());
case PuffinCompressionCodec::kLz4:
return NotSupported("LZ4 decompression is not yet supported");
- case PuffinCompressionCodec::kZstd:
- return NotSupported("Zstd decompression is not yet supported");
+ case PuffinCompressionCodec::kZstd: {
Review Comment:
Could we move the zstd code into two small internal functions, like we do
for gzip? That would keep the Puffin switch focused on choosing the codec.
Perhaps we can also abstract out a `CompressionCodec` class?
--
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]