HuaHuaY commented on code in PR #48865:
URL: https://github.com/apache/arrow/pull/48865#discussion_r2695189171
##########
cpp/src/arrow/util/compression_zstd.cc:
##########
@@ -207,24 +198,24 @@ class ZSTDCodec : public Codec {
Result<int64_t> Compress(int64_t input_len, const uint8_t* input,
int64_t output_buffer_len, uint8_t* output_buffer)
override {
- size_t ret = ZSTD_compress(output_buffer,
static_cast<size_t>(output_buffer_len),
- input, static_cast<size_t>(input_len),
compression_level_);
+ ARROW_ASSIGN_OR_RAISE(auto cctx, CreateCCtx());
+ size_t ret = ZSTD_compressCCtx(cctx.get(), output_buffer,
+ static_cast<size_t>(output_buffer_len),
input,
+ static_cast<size_t>(input_len),
compression_level_);
Review Comment:
After I read the Zstd's document again, I think there is a mistake here. We
need to use `ZSTD_compress2` instead of `ZSTD_compressCCtx` because
`ZSTD_compressCCtx` will reset other parameters. Thank for your good attention!
```cpp
/*! ZSTD_compressCCtx() :
* Same as ZSTD_compress(), using an explicit ZSTD_CCtx.
* Important : in order to mirror `ZSTD_compress()` behavior,
* this function compresses at the requested compression level,
* __ignoring any other advanced parameter__ .
* If any advanced parameter was set using the advanced API,
* they will all be reset. Only @compressionLevel remains.
*/
ZSTDLIB_API size_t ZSTD_compressCCtx(ZSTD_CCtx* cctx,
void* dst, size_t dstCapacity,
const void* src, size_t srcSize,
int compressionLevel);
/*! ZSTD_compress2() :
* Behave the same as ZSTD_compressCCtx(), but compression parameters are
set using the advanced API.
* (note that this entry point doesn't even expose a compression level
parameter).
* ZSTD_compress2() always starts a new frame.
* Should cctx hold data from a previously unfinished frame, everything
about it is forgotten.
* - Compression parameters are pushed into CCtx before starting
compression, using ZSTD_CCtx_set*()
* - The function is always blocking, returns when compression is completed.
* NOTE: Providing `dstCapacity >= ZSTD_compressBound(srcSize)` guarantees
that zstd will have
* enough space to successfully compress the data, though it is
possible it fails for other reasons.
* @return : compressed size written into `dst` (<= `dstCapacity),
* or an error code if it fails (which can be tested using
ZSTD_isError()).
*/
ZSTDLIB_API size_t ZSTD_compress2( ZSTD_CCtx* cctx,
void* dst, size_t dstCapacity,
const void* src, size_t srcSize);
```
--
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]