Skip to content

Commit

Permalink
fix
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 Jul 9, 2024
1 parent 5698e49 commit 5dacd44
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion dbms/src/IO/Compression/CompressionCodecFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ CompressionCodecPtr CompressionCodecFactory::create(const CompressionSetting & s
if constexpr (!IS_DECOMPRESS)
{
if (setting.data_type == CompressionDataType::String || setting.data_type == CompressionDataType::Float32
|| setting.data_type == CompressionDataType::Float64)
|| setting.data_type == CompressionDataType::Float64 || setting.data_type == CompressionDataType::Unknown)
return getStaticCodec<CompressionCodecLZ4>(setting);
}

Expand Down
2 changes: 2 additions & 0 deletions dbms/src/IO/Compression/CompressionCodecLightweight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ UInt32 CompressionCodecLightweight::doCompressData(const char * source, UInt32 s
case CompressionDataType::Float32:
case CompressionDataType::Float64:
case CompressionDataType::String:
case CompressionDataType::Unknown:
return 1 + compressDataForNonInteger(source, source_size, dest);
default:
throw Exception(
Expand Down Expand Up @@ -118,6 +119,7 @@ void CompressionCodecLightweight::doDecompressData(
case CompressionDataType::Float32:
case CompressionDataType::Float64:
case CompressionDataType::String:
case CompressionDataType::Unknown:
decompressDataForNonInteger(&source[1], source_size_no_header, dest, uncompressed_size);
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ void CompressionCodecLightweight::IntegerCompressContext::analyze(std::span<cons
{
// Check CONSTANT_DELTA

// If values.size() == 1, mode will be CONSTANT_DELTA
// so values.size() must be greater than 1 here.
// If values.size() == 1, mode will be CONSTANT
// so values.size() must be greater than 1 here and deltas must be non empty.
deltas.reserve(values.size() - 1);
for (size_t i = 1; i < values.size(); ++i)
{
Expand Down
11 changes: 8 additions & 3 deletions dbms/src/IO/Compression/CompressionCodecRunLength.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ UInt32 CompressionCodecRunLength::compressDataForInteger(const char * source, UI

if (DB::Compression::runLengthPairsByteSize<T>(rle_vec) >= source_size)
{
// treat as string
dest[0] = magic_enum::enum_integer(CompressionDataType::String);
// treat as unknown data type, and compress as LZ4
dest[0] = magic_enum::enum_integer(CompressionDataType::Unknown);
dest += 1;
auto success = LZ4_compress_fast(
source,
Expand Down Expand Up @@ -141,10 +141,15 @@ void CompressionCodecRunLength::doDecompressData(
case CompressionDataType::Int64:
DB::Compression::runLengthDecoding<UInt64>(&source[1], source_size - 1, dest, uncompressed_size);
break;
default:
case CompressionDataType::Unknown:
if (unlikely(LZ4_decompress_safe(&source[1], dest, source_size - 1, uncompressed_size) < 0))
throw Exception("Cannot LZ4_decompress_safe", ErrorCodes::CANNOT_DECOMPRESS);
break;
default:
throw Exception(
ErrorCodes::CANNOT_DECOMPRESS,
"Cannot decompress RunLength-encoded data. Unknown data type {}",
bytes_size);
}
}

Expand Down
1 change: 1 addition & 0 deletions dbms/src/IO/Compression/CompressionInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ enum class CompressionMethodByte : UInt8

enum class CompressionDataType : UInt8
{
Unknown = 0,
// These enum values are used to represent the number of bytes of the type
Int8 = 1, // Int8/UInt8
Int16 = 2, // Int16/UInt16
Expand Down
4 changes: 2 additions & 2 deletions dbms/src/IO/Compression/CompressionSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ CompressionSetting CompressionSetting::create(T method, int level, const IDataTy
if (data_type.has_value())
setting.data_type = data_type.value();
else
setting.data_type = CompressionDataType::String;
setting.data_type = CompressionDataType::Unknown;
}
else if (type.isFloatingPoint() && type.getSizeOfValueInMemory() == 4)
setting.data_type = CompressionDataType::Float32;
else if (type.isFloatingPoint() && type.getSizeOfValueInMemory() == 8)
setting.data_type = CompressionDataType::Float64;
else
setting.data_type = CompressionDataType::String;
setting.data_type = CompressionDataType::Unknown;
setting.level = level;
return setting;
}
Expand Down
13 changes: 7 additions & 6 deletions dbms/src/IO/Compression/CompressionSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,32 +49,33 @@ const std::unordered_map<CompressionMethodByte, CompressionMethod> method_map =
struct CompressionSetting
{
CompressionMethod method;
CompressionMethodByte method_byte;
int level;
// The type of data to be compressed.
// I
CompressionDataType data_type = CompressionDataType::String;
// It may be used to determine the codec to use.
CompressionDataType data_type = CompressionDataType::Unknown;
// Always use method_byte to determine the codec to use except for LZ4HC codec
CompressionMethodByte method_byte;

CompressionSetting()
: CompressionSetting(CompressionMethod::LZ4)
{}

explicit CompressionSetting(CompressionMethod method_)
: method(method_)
, method_byte(method_byte_map[static_cast<size_t>(method_)])
, level(getDefaultLevel(method))
, method_byte(method_byte_map[static_cast<size_t>(method_)])
{}

explicit CompressionSetting(CompressionMethodByte method_byte_)
: method(method_map.at(method_byte_))
, method_byte(method_byte_)
, level(getDefaultLevel(method))
, method_byte(method_byte_)
{}

CompressionSetting(CompressionMethod method_, int level_)
: method(method_)
, method_byte(method_byte_map[static_cast<size_t>(method_)])
, level(level_)
, method_byte(method_byte_map[static_cast<size_t>(method_)])
{}

explicit CompressionSetting(const Settings & settings);
Expand Down

0 comments on commit 5dacd44

Please sign in to comment.