Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
Signed-off-by: Lloyd-Pottiger <yan1579196623@gmail.com>
  • Loading branch information
Lloyd-Pottiger committed Apr 25, 2024
1 parent 05cb229 commit c2930dd
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 36 deletions.
2 changes: 1 addition & 1 deletion dbms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ check_then_add_sources_compile_flag (
src/Columns/ColumnVector.cpp
src/DataTypes/DataTypeString.cpp
src/Interpreters/Join.cpp
src/IO/Compression/CompressionCodecDelta.cpp
src/IO/Compression/CompressionCodecDeltaPFor.cpp
src/Storages/DeltaMerge/BitmapFilter/BitmapFilter.cpp
src/Storages/DeltaMerge/DMVersionFilterBlockInputStream.cpp
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <Common/BitpackingPrimitives.h>
#include <Common/Exception.h>
#include <DataTypes/IDataType.h>
#include <IO/Compression/CompressionCodecDelta.h>
#include <IO/Compression/CompressionCodecDeltaPFor.h>
#include <IO/Compression/CompressionInfo.h>
#include <common/likely.h>
#include <common/unaligned.h>
Expand All @@ -33,20 +33,20 @@ extern const int CANNOT_COMPRESS;
extern const int CANNOT_DECOMPRESS;
} // namespace ErrorCodes

CompressionCodecDelta::CompressionCodecDelta(UInt8 delta_bytes_size_)
: delta_bytes_size(delta_bytes_size_)
CompressionCodecDeltaPFor::CompressionCodecDeltaPFor(UInt8 bytes_size_)
: bytes_size(bytes_size_)
{}

UInt8 CompressionCodecDelta::getMethodByte() const
UInt8 CompressionCodecDeltaPFor::getMethodByte() const
{
return static_cast<UInt8>(CompressionMethodByte::Delta);
return static_cast<UInt8>(CompressionMethodByte::DeltaPFor);
}

UInt32 CompressionCodecDelta::getMaxCompressedDataSize(UInt32 uncompressed_size) const
UInt32 CompressionCodecDeltaPFor::getMaxCompressedDataSize(UInt32 uncompressed_size) const
{
// 1 byte for delta_bytes_size, x bytes for frame of reference, 1 byte for width.
return 1 + delta_bytes_size + sizeof(UInt8)
+ BitpackingPrimitives::getRequiredSize(uncompressed_size / delta_bytes_size, delta_bytes_size * 8);
// 1 byte for bytes_size, x bytes for frame of reference, 1 byte for width.
return 1 + bytes_size + sizeof(UInt8)
+ BitpackingPrimitives::getRequiredSize(uncompressed_size / bytes_size, bytes_size * 8);
}

namespace
Expand Down Expand Up @@ -85,7 +85,12 @@ UInt32 compressData(const char * source, UInt32 source_size, char * dest)
if (width == 0)
return sizeof(ST) + sizeof(UInt8);
auto required_size = BitpackingPrimitives::getRequiredSize(count, width);
BitpackingPrimitives::packBuffer(reinterpret_cast<unsigned char *>(dest), deltas.data(), count, width);
// after applying frame of reference, all deltas are bigger than 0.
BitpackingPrimitives::packBuffer(
reinterpret_cast<unsigned char *>(dest),
reinterpret_cast<const T *>(deltas.data()),
count,
width);
return sizeof(ST) + sizeof(UInt8) + required_size;
}

Expand Down Expand Up @@ -226,7 +231,7 @@ void PForDecode(const char * source, UInt32 source_size, unsigned char * dest, U
source += sizeof(UInt8);
const auto required_size = source_size - sizeof(ST) - sizeof(UInt8);
RUNTIME_CHECK(BitpackingPrimitives::getRequiredSize(count, width) == required_size);
BitpackingPrimitives::unPackBuffer<ST>(dest, reinterpret_cast<const unsigned char *>(source), count, width);
BitpackingPrimitives::unPackBuffer<T>(dest, reinterpret_cast<const unsigned char *>(source), count, width);
ApplyFrameOfReference(reinterpret_cast<ST *>(dest), frame_of_reference, count);
}

Expand Down Expand Up @@ -268,17 +273,13 @@ void decompressData<UInt64>(const char * source, UInt32 source_size, char * dest

} // namespace

UInt32 CompressionCodecDelta::doCompressData(const char * source, UInt32 source_size, char * dest) const
UInt32 CompressionCodecDeltaPFor::doCompressData(const char * source, UInt32 source_size, char * dest) const
{
if unlikely (source_size % delta_bytes_size != 0)
throw Exception(
ErrorCodes::CANNOT_DECOMPRESS,
"source size {} is not aligned to {}",
source_size,
delta_bytes_size);
dest[0] = delta_bytes_size;
if unlikely (source_size % bytes_size != 0)
throw Exception(ErrorCodes::CANNOT_DECOMPRESS, "source size {} is not aligned to {}", source_size, bytes_size);
dest[0] = bytes_size;
size_t start_pos = 1;
switch (delta_bytes_size)
switch (bytes_size)
{
case 1:
return 1 + compressData<UInt8>(source, source_size, &dest[start_pos]);
Expand All @@ -293,7 +294,7 @@ UInt32 CompressionCodecDelta::doCompressData(const char * source, UInt32 source_
}
}

void CompressionCodecDelta::doDecompressData(
void CompressionCodecDeltaPFor::doDecompressData(
const char * source,
UInt32 source_size,
char * dest,
Expand Down Expand Up @@ -333,7 +334,11 @@ void CompressionCodecDelta::doDecompressData(
}
}

void CompressionCodecDelta::ordinaryDecompress(const char * source, UInt32 source_size, char * dest, UInt32 dest_size)
void CompressionCodecDeltaPFor::ordinaryDecompress(
const char * source,
UInt32 source_size,
char * dest,
UInt32 dest_size)
{
if unlikely (source_size < 2)
throw Exception(ErrorCodes::CANNOT_DECOMPRESS, "Cannot decompress delta-encoded data. File has wrong header");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
namespace DB
{

class CompressionCodecDelta : public ICompressionCodec
class CompressionCodecDeltaPFor : public ICompressionCodec
{
public:
explicit CompressionCodecDelta(UInt8 delta_bytes_size_);
explicit CompressionCodecDeltaPFor(UInt8 bytes_size_);

UInt8 getMethodByte() const override;

Expand All @@ -42,7 +42,7 @@ class CompressionCodecDelta : public ICompressionCodec
bool isGenericCompression() const override { return false; }

private:
const UInt8 delta_bytes_size;
const UInt8 bytes_size;
};

} // namespace DB
6 changes: 3 additions & 3 deletions dbms/src/IO/Compression/CompressionFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#pragma once

#include <Common/config.h>
#include <IO/Compression/CompressionCodecDelta.h>
#include <IO/Compression/CompressionCodecDeltaPFor.h>
#include <IO/Compression/CompressionCodecLZ4.h>
#include <IO/Compression/CompressionCodecMultiple.h>
#include <IO/Compression/CompressionCodecNone.h>
Expand Down Expand Up @@ -57,8 +57,8 @@ class CompressionFactory
}
switch (setting.method_byte)
{
case CompressionMethodByte::Delta:
return std::make_unique<CompressionCodecDelta>(setting.type_bytes_size);
case CompressionMethodByte::DeltaPFor:
return std::make_unique<CompressionCodecDeltaPFor>(setting.type_bytes_size);
case CompressionMethodByte::RLE:
return std::make_unique<CompressionCodecRLE>(setting.type_bytes_size);
case CompressionMethodByte::NONE:
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/IO/Compression/CompressionInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ enum class CompressionMethodByte : UInt8
QPL = 0x88,
ZSTD = 0x90,
Multiple = 0x91,
Delta = 0x92,
DeltaPFor = 0x92,
RLE = 0x93,
// COL_END is not a compreesion method, but a flag of column end used in compact file.
COL_END = 0x66,
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/IO/Compression/CompressionSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const std::unordered_map<CompressionMethodByte, CompressionMethod> method_map =
{CompressionMethodByte::ZSTD, CompressionMethod::ZSTD},
{CompressionMethodByte::QPL, CompressionMethod::QPL},
{CompressionMethodByte::NONE, CompressionMethod::NONE},
{CompressionMethodByte::Delta, CompressionMethod::NONE},
{CompressionMethodByte::DeltaPFor, CompressionMethod::NONE},
{CompressionMethodByte::RLE, CompressionMethod::NONE},
};

Expand Down
8 changes: 4 additions & 4 deletions dbms/src/IO/Compression/tests/bench_codec_delta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

#include <Core/Defines.h>
#include <IO/Compression/CompressionCodecDelta.h>
#include <IO/Compression/CompressionCodecDeltaPFor.h>
#include <benchmark/benchmark.h>

#include <vector>
Expand All @@ -27,7 +27,7 @@ static void codecDeltaOrdinaryBM(benchmark::State & state)
std::vector<T> v(DEFAULT_MERGE_BLOCK_SIZE);
for (auto & i : v)
i = random();
CompressionCodecDelta codec(sizeof(T));
CompressionCodecDeltaPFor codec(sizeof(T));
char dest[sizeof(T) * DEFAULT_MERGE_BLOCK_SIZE + 1];
for (auto _ : state)
{
Expand All @@ -52,7 +52,7 @@ static void codecDeltaSpecializedUInt64BM(benchmark::State & state)
std::vector<UInt64> v(DEFAULT_MERGE_BLOCK_SIZE);
for (auto & i : v)
i = random();
CompressionCodecDelta codec(sizeof(UInt64));
CompressionCodecDeltaPFor codec(sizeof(UInt64));
char dest[sizeof(UInt64) * DEFAULT_MERGE_BLOCK_SIZE + 1];
for (auto _ : state)
{
Expand All @@ -67,7 +67,7 @@ static void codecDeltaSpecializedUInt32BM(benchmark::State & state)
std::vector<UInt32> v(DEFAULT_MERGE_BLOCK_SIZE);
for (auto & i : v)
i = random();
CompressionCodecDelta codec(sizeof(UInt32));
CompressionCodecDeltaPFor codec(sizeof(UInt32));
char dest[sizeof(UInt32) * DEFAULT_MERGE_BLOCK_SIZE + 1];
for (auto _ : state)
{
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/IO/Compression/tests/gtest_codec_compression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ std::vector<CodecTestSequence> generatePyramidOfSequences(
#define G(generator) generator, #generator

const auto IntegerCodecsToTest = ::testing::Values(
CompressionMethodByte::Delta,
CompressionMethodByte::DeltaPFor,
CompressionMethodByte::RLE
#if USE_QPL
,
Expand Down

0 comments on commit c2930dd

Please sign in to comment.