| 1 | #include "duckdb/storage/string_uncompressed.hpp" |
| 2 | #include "duckdb/common/types/value.hpp" |
| 3 | #include "duckdb/common/fsst.hpp" |
| 4 | #include "fsst.h" |
| 5 | |
| 6 | namespace duckdb { |
| 7 | |
| 8 | string_t FSSTPrimitives::DecompressValue(void *duckdb_fsst_decoder, Vector &result, const char *compressed_string, |
| 9 | idx_t compressed_string_len) { |
| 10 | D_ASSERT(result.GetVectorType() == VectorType::FLAT_VECTOR); |
| 11 | unsigned char decompress_buffer[StringUncompressed::STRING_BLOCK_LIMIT + 1]; |
| 12 | auto fsst_decoder = reinterpret_cast<duckdb_fsst_decoder_t *>(duckdb_fsst_decoder); |
| 13 | auto compressed_string_ptr = (unsigned char *)compressed_string; // NOLINT |
| 14 | auto decompressed_string_size = |
| 15 | duckdb_fsst_decompress(decoder: fsst_decoder, lenIn: compressed_string_len, strIn: compressed_string_ptr, |
| 16 | size: StringUncompressed::STRING_BLOCK_LIMIT + 1, output: &decompress_buffer[0]); |
| 17 | D_ASSERT(decompressed_string_size <= StringUncompressed::STRING_BLOCK_LIMIT); |
| 18 | |
| 19 | return StringVector::AddStringOrBlob(vector&: result, data: const_char_ptr_cast(src: decompress_buffer), len: decompressed_string_size); |
| 20 | } |
| 21 | |
| 22 | Value FSSTPrimitives::DecompressValue(void *duckdb_fsst_decoder, const char *compressed_string, |
| 23 | idx_t compressed_string_len) { |
| 24 | unsigned char decompress_buffer[StringUncompressed::STRING_BLOCK_LIMIT + 1]; |
| 25 | auto compressed_string_ptr = (unsigned char *)compressed_string; // NOLINT |
| 26 | auto fsst_decoder = reinterpret_cast<duckdb_fsst_decoder_t *>(duckdb_fsst_decoder); |
| 27 | auto decompressed_string_size = |
| 28 | duckdb_fsst_decompress(decoder: fsst_decoder, lenIn: compressed_string_len, strIn: compressed_string_ptr, |
| 29 | size: StringUncompressed::STRING_BLOCK_LIMIT + 1, output: &decompress_buffer[0]); |
| 30 | D_ASSERT(decompressed_string_size <= StringUncompressed::STRING_BLOCK_LIMIT); |
| 31 | |
| 32 | return Value(string(char_ptr_cast(src: decompress_buffer), decompressed_string_size)); |
| 33 | } |
| 34 | |
| 35 | } // namespace duckdb |
| 36 | |