mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 17:12:03 +00:00
Fix error
This commit is contained in:
parent
b7011f4f9c
commit
634be2b933
@ -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);
|
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");
|
throw Exception(ErrorCodes::CANNOT_COMPRESS, "Cannot compress column");
|
||||||
|
|
||||||
/// If compression is inefficient.
|
/// 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 {};
|
return {};
|
||||||
|
|
||||||
/// Shrink to fit.
|
/// Shrink to fit.
|
||||||
|
@ -65,8 +65,9 @@ public:
|
|||||||
|
|
||||||
/// Helper methods for compression.
|
/// 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.
|
/// If data is not worth to be compressed and not 'always_compress' - returns nullptr.
|
||||||
static std::shared_ptr<Memory<>> compressBuffer(const void * data, size_t data_size);
|
/// 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(
|
static void decompressBuffer(
|
||||||
const void * compressed_data, void * decompressed_data, size_t compressed_size, size_t decompressed_size);
|
const void * compressed_data, void * decompressed_data, size_t compressed_size, size_t decompressed_size);
|
||||||
|
@ -356,7 +356,7 @@ ColumnPtr ColumnDecimal<T>::compress() const
|
|||||||
if (source_size < 4096) /// A wild guess.
|
if (source_size < 4096) /// A wild guess.
|
||||||
return ColumnCompressed::wrap(this->getPtr());
|
return ColumnCompressed::wrap(this->getPtr());
|
||||||
|
|
||||||
auto compressed = ColumnCompressed::compressBuffer(data.data(), source_size);
|
auto compressed = ColumnCompressed::compressBuffer(data.data(), source_size, false);
|
||||||
|
|
||||||
if (!compressed)
|
if (!compressed)
|
||||||
return ColumnCompressed::wrap(this->getPtr());
|
return ColumnCompressed::wrap(this->getPtr());
|
||||||
|
@ -449,13 +449,13 @@ void ColumnFixedString::getExtremes(Field & min, Field & max) const
|
|||||||
|
|
||||||
ColumnPtr ColumnFixedString::compress() const
|
ColumnPtr ColumnFixedString::compress() const
|
||||||
{
|
{
|
||||||
size_t source_size = chars.size() * n;
|
size_t source_size = chars.size();
|
||||||
|
|
||||||
/// Don't compress small blocks.
|
/// Don't compress small blocks.
|
||||||
if (source_size < 4096) /// A wild guess.
|
if (source_size < 4096) /// A wild guess.
|
||||||
return ColumnCompressed::wrap(this->getPtr());
|
return ColumnCompressed::wrap(this->getPtr());
|
||||||
|
|
||||||
auto compressed = ColumnCompressed::compressBuffer(chars.data(), source_size);
|
auto compressed = ColumnCompressed::compressBuffer(chars.data(), source_size, false);
|
||||||
|
|
||||||
if (!compressed)
|
if (!compressed)
|
||||||
return ColumnCompressed::wrap(this->getPtr());
|
return ColumnCompressed::wrap(this->getPtr());
|
||||||
|
@ -535,24 +535,13 @@ ColumnPtr ColumnString::compress() const
|
|||||||
if (source_chars_size < 4096) /// A wild guess.
|
if (source_chars_size < 4096) /// A wild guess.
|
||||||
return ColumnCompressed::wrap(this->getPtr());
|
return ColumnCompressed::wrap(this->getPtr());
|
||||||
|
|
||||||
auto chars_compressed = ColumnCompressed::compressBuffer(chars.data(), source_chars_size);
|
auto chars_compressed = ColumnCompressed::compressBuffer(chars.data(), source_chars_size, false);
|
||||||
auto offsets_compressed = ColumnCompressed::compressBuffer(offsets.data(), source_offsets_size);
|
|
||||||
|
|
||||||
/// Return original column if not compressable.
|
/// Return original column if not compressable.
|
||||||
if (!chars_compressed && !offsets_compressed)
|
if (!chars_compressed)
|
||||||
return ColumnCompressed::wrap(this->getPtr());
|
return ColumnCompressed::wrap(this->getPtr());
|
||||||
|
|
||||||
if (!chars_compressed)
|
auto offsets_compressed = ColumnCompressed::compressBuffer(offsets.data(), source_offsets_size, true);
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ColumnCompressed::create(offsets.size(), chars_compressed->size() + offsets_compressed->size(),
|
return ColumnCompressed::create(offsets.size(), chars_compressed->size() + offsets_compressed->size(),
|
||||||
[
|
[
|
||||||
@ -575,7 +564,6 @@ ColumnPtr ColumnString::compress() const
|
|||||||
|
|
||||||
return res;
|
return res;
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -533,7 +533,7 @@ ColumnPtr ColumnVector<T>::compress() const
|
|||||||
if (source_size < 4096) /// A wild guess.
|
if (source_size < 4096) /// A wild guess.
|
||||||
return ColumnCompressed::wrap(this->getPtr());
|
return ColumnCompressed::wrap(this->getPtr());
|
||||||
|
|
||||||
auto compressed = ColumnCompressed::compressBuffer(data.data(), source_size);
|
auto compressed = ColumnCompressed::compressBuffer(data.data(), source_size, false);
|
||||||
|
|
||||||
if (!compressed)
|
if (!compressed)
|
||||||
return ColumnCompressed::wrap(this->getPtr());
|
return ColumnCompressed::wrap(this->getPtr());
|
||||||
|
Loading…
Reference in New Issue
Block a user