Fix error

This commit is contained in:
Alexey Milovidov 2021-02-18 03:52:09 +03:00
parent b7011f4f9c
commit 634be2b933
6 changed files with 12 additions and 23 deletions

View File

@ -15,7 +15,7 @@ namespace ErrorCodes
}
std::shared_ptr<Memory<>> ColumnCompressed::compressBuffer(const void * data, size_t data_size)
std::shared_ptr<Memory<>> ColumnCompressed::compressBuffer(const void * data, size_t data_size, bool always_compress)
{
size_t max_dest_size = LZ4_COMPRESSBOUND(data_size);
@ -34,7 +34,7 @@ std::shared_ptr<Memory<>> ColumnCompressed::compressBuffer(const void * data, si
throw Exception(ErrorCodes::CANNOT_COMPRESS, "Cannot compress column");
/// If compression is inefficient.
if (static_cast<size_t>(compressed_size) * 2 > data_size)
if (!always_compress && static_cast<size_t>(compressed_size) * 2 > data_size)
return {};
/// Shrink to fit.

View File

@ -65,8 +65,9 @@ public:
/// Helper methods for compression.
/// If data is not worth to be compressed - returns nullptr. Note: shared_ptr is to allow to be captured by std::function.
static std::shared_ptr<Memory<>> compressBuffer(const void * data, size_t data_size);
/// If data is not worth to be compressed and not 'always_compress' - returns nullptr.
/// Note: shared_ptr is to allow to be captured by std::function.
static std::shared_ptr<Memory<>> compressBuffer(const void * data, size_t data_size, bool always_compress);
static void decompressBuffer(
const void * compressed_data, void * decompressed_data, size_t compressed_size, size_t decompressed_size);

View File

@ -356,7 +356,7 @@ ColumnPtr ColumnDecimal<T>::compress() const
if (source_size < 4096) /// A wild guess.
return ColumnCompressed::wrap(this->getPtr());
auto compressed = ColumnCompressed::compressBuffer(data.data(), source_size);
auto compressed = ColumnCompressed::compressBuffer(data.data(), source_size, false);
if (!compressed)
return ColumnCompressed::wrap(this->getPtr());

View File

@ -449,13 +449,13 @@ void ColumnFixedString::getExtremes(Field & min, Field & max) const
ColumnPtr ColumnFixedString::compress() const
{
size_t source_size = chars.size() * n;
size_t source_size = chars.size();
/// Don't compress small blocks.
if (source_size < 4096) /// A wild guess.
return ColumnCompressed::wrap(this->getPtr());
auto compressed = ColumnCompressed::compressBuffer(chars.data(), source_size);
auto compressed = ColumnCompressed::compressBuffer(chars.data(), source_size, false);
if (!compressed)
return ColumnCompressed::wrap(this->getPtr());

View File

@ -535,24 +535,13 @@ ColumnPtr ColumnString::compress() const
if (source_chars_size < 4096) /// A wild guess.
return ColumnCompressed::wrap(this->getPtr());
auto chars_compressed = ColumnCompressed::compressBuffer(chars.data(), source_chars_size);
auto offsets_compressed = ColumnCompressed::compressBuffer(offsets.data(), source_offsets_size);
auto chars_compressed = ColumnCompressed::compressBuffer(chars.data(), source_chars_size, false);
/// Return original column if not compressable.
if (!chars_compressed && !offsets_compressed)
if (!chars_compressed)
return ColumnCompressed::wrap(this->getPtr());
if (!chars_compressed)
{
chars_compressed = std::make_shared<Memory<>>(source_chars_size);
memcpy(chars_compressed->data(), chars.data(), source_chars_size);
}
if (!offsets_compressed)
{
offsets_compressed = std::make_shared<Memory<>>(source_offsets_size);
memcpy(offsets_compressed->data(), offsets.data(), source_offsets_size);
}
auto offsets_compressed = ColumnCompressed::compressBuffer(offsets.data(), source_offsets_size, true);
return ColumnCompressed::create(offsets.size(), chars_compressed->size() + offsets_compressed->size(),
[
@ -575,7 +564,6 @@ ColumnPtr ColumnString::compress() const
return res;
});
}

View File

@ -533,7 +533,7 @@ ColumnPtr ColumnVector<T>::compress() const
if (source_size < 4096) /// A wild guess.
return ColumnCompressed::wrap(this->getPtr());
auto compressed = ColumnCompressed::compressBuffer(data.data(), source_size);
auto compressed = ColumnCompressed::compressBuffer(data.data(), source_size, false);
if (!compressed)
return ColumnCompressed::wrap(this->getPtr());