mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 01:25:21 +00:00
Merge pull request #40008 from HarryLeeIBM/hlee-s390x-codec
Fix Endian issues in Codec for s390x
This commit is contained in:
commit
11cd21630a
@ -292,7 +292,7 @@ UInt32 compressDataForType(const char * source, UInt32 source_size, char * dest)
|
||||
const char * dest_start = dest;
|
||||
|
||||
const UInt32 items_count = source_size / sizeof(ValueType);
|
||||
unalignedStore<UInt32>(dest, items_count);
|
||||
unalignedStoreLE<UInt32>(dest, items_count);
|
||||
dest += sizeof(items_count);
|
||||
|
||||
ValueType prev_value{};
|
||||
@ -300,8 +300,8 @@ UInt32 compressDataForType(const char * source, UInt32 source_size, char * dest)
|
||||
|
||||
if (source < source_end)
|
||||
{
|
||||
prev_value = unalignedLoad<ValueType>(source);
|
||||
unalignedStore<ValueType>(dest, prev_value);
|
||||
prev_value = unalignedLoadLE<ValueType>(source);
|
||||
unalignedStoreLE<ValueType>(dest, prev_value);
|
||||
|
||||
source += sizeof(prev_value);
|
||||
dest += sizeof(prev_value);
|
||||
@ -309,10 +309,10 @@ UInt32 compressDataForType(const char * source, UInt32 source_size, char * dest)
|
||||
|
||||
if (source < source_end)
|
||||
{
|
||||
const ValueType curr_value = unalignedLoad<ValueType>(source);
|
||||
const ValueType curr_value = unalignedLoadLE<ValueType>(source);
|
||||
|
||||
prev_delta = curr_value - prev_value;
|
||||
unalignedStore<UnsignedDeltaType>(dest, prev_delta);
|
||||
unalignedStoreLE<UnsignedDeltaType>(dest, prev_delta);
|
||||
|
||||
source += sizeof(curr_value);
|
||||
dest += sizeof(prev_delta);
|
||||
@ -324,7 +324,7 @@ UInt32 compressDataForType(const char * source, UInt32 source_size, char * dest)
|
||||
int item = 2;
|
||||
for (; source < source_end; source += sizeof(ValueType), ++item)
|
||||
{
|
||||
const ValueType curr_value = unalignedLoad<ValueType>(source);
|
||||
const ValueType curr_value = unalignedLoadLE<ValueType>(source);
|
||||
|
||||
const UnsignedDeltaType delta = curr_value - prev_value;
|
||||
const UnsignedDeltaType double_delta = delta - prev_delta;
|
||||
@ -368,7 +368,7 @@ void decompressDataForType(const char * source, UInt32 source_size, char * dest,
|
||||
if (source + sizeof(UInt32) > source_end)
|
||||
return;
|
||||
|
||||
const UInt32 items_count = unalignedLoad<UInt32>(source);
|
||||
const UInt32 items_count = unalignedLoadLE<UInt32>(source);
|
||||
source += sizeof(items_count);
|
||||
|
||||
ValueType prev_value{};
|
||||
@ -378,10 +378,10 @@ void decompressDataForType(const char * source, UInt32 source_size, char * dest,
|
||||
if (source + sizeof(ValueType) > source_end || items_count < 1)
|
||||
return;
|
||||
|
||||
prev_value = unalignedLoad<ValueType>(source);
|
||||
prev_value = unalignedLoadLE<ValueType>(source);
|
||||
if (dest + sizeof(prev_value) > output_end)
|
||||
throw Exception(ErrorCodes::CANNOT_DECOMPRESS, "Cannot decompress the data");
|
||||
unalignedStore<ValueType>(dest, prev_value);
|
||||
unalignedStoreLE<ValueType>(dest, prev_value);
|
||||
|
||||
source += sizeof(prev_value);
|
||||
dest += sizeof(prev_value);
|
||||
@ -390,11 +390,11 @@ void decompressDataForType(const char * source, UInt32 source_size, char * dest,
|
||||
if (source + sizeof(UnsignedDeltaType) > source_end || items_count < 2)
|
||||
return;
|
||||
|
||||
prev_delta = unalignedLoad<UnsignedDeltaType>(source);
|
||||
prev_delta = unalignedLoadLE<UnsignedDeltaType>(source);
|
||||
prev_value = prev_value + static_cast<ValueType>(prev_delta);
|
||||
if (dest + sizeof(prev_value) > output_end)
|
||||
throw Exception(ErrorCodes::CANNOT_DECOMPRESS, "Cannot decompress the data");
|
||||
unalignedStore<ValueType>(dest, prev_value);
|
||||
unalignedStoreLE<ValueType>(dest, prev_value);
|
||||
|
||||
source += sizeof(prev_delta);
|
||||
dest += sizeof(prev_value);
|
||||
@ -427,7 +427,7 @@ void decompressDataForType(const char * source, UInt32 source_size, char * dest,
|
||||
const ValueType curr_value = prev_value + delta;
|
||||
if (dest + sizeof(curr_value) > output_end)
|
||||
throw Exception(ErrorCodes::CANNOT_DECOMPRESS, "Cannot decompress the data");
|
||||
unalignedStore<ValueType>(dest, curr_value);
|
||||
unalignedStoreLE<ValueType>(dest, curr_value);
|
||||
dest += sizeof(curr_value);
|
||||
|
||||
prev_delta = curr_value - prev_value;
|
||||
|
@ -208,7 +208,7 @@ UInt32 compressDataForType(const char * source, UInt32 source_size, char * dest,
|
||||
|
||||
const UInt32 items_count = source_size / sizeof(T);
|
||||
|
||||
unalignedStore<UInt32>(dest, items_count);
|
||||
unalignedStoreLE<UInt32>(dest, items_count);
|
||||
dest += sizeof(items_count);
|
||||
|
||||
T prev_value{};
|
||||
@ -217,8 +217,8 @@ UInt32 compressDataForType(const char * source, UInt32 source_size, char * dest,
|
||||
|
||||
if (source < source_end)
|
||||
{
|
||||
prev_value = unalignedLoad<T>(source);
|
||||
unalignedStore<T>(dest, prev_value);
|
||||
prev_value = unalignedLoadLE<T>(source);
|
||||
unalignedStoreLE<T>(dest, prev_value);
|
||||
|
||||
source += sizeof(prev_value);
|
||||
dest += sizeof(prev_value);
|
||||
@ -228,7 +228,7 @@ UInt32 compressDataForType(const char * source, UInt32 source_size, char * dest,
|
||||
|
||||
while (source < source_end)
|
||||
{
|
||||
const T curr_value = unalignedLoad<T>(source);
|
||||
const T curr_value = unalignedLoadLE<T>(source);
|
||||
source += sizeof(curr_value);
|
||||
|
||||
const auto xored_data = curr_value ^ prev_value;
|
||||
@ -274,7 +274,7 @@ void decompressDataForType(const char * source, UInt32 source_size, char * dest)
|
||||
if (source + sizeof(UInt32) > source_end)
|
||||
return;
|
||||
|
||||
const UInt32 items_count = unalignedLoad<UInt32>(source);
|
||||
const UInt32 items_count = unalignedLoadLE<UInt32>(source);
|
||||
source += sizeof(items_count);
|
||||
|
||||
T prev_value{};
|
||||
@ -283,8 +283,8 @@ void decompressDataForType(const char * source, UInt32 source_size, char * dest)
|
||||
if (source + sizeof(T) > source_end || items_count < 1)
|
||||
return;
|
||||
|
||||
prev_value = unalignedLoad<T>(source);
|
||||
unalignedStore<T>(dest, prev_value);
|
||||
prev_value = unalignedLoadLE<T>(source);
|
||||
unalignedStoreLE<T>(dest, prev_value);
|
||||
|
||||
source += sizeof(prev_value);
|
||||
dest += sizeof(prev_value);
|
||||
@ -326,7 +326,7 @@ void decompressDataForType(const char * source, UInt32 source_size, char * dest)
|
||||
}
|
||||
// else: 0b0 prefix - use prev_value
|
||||
|
||||
unalignedStore<T>(dest, curr_value);
|
||||
unalignedStoreLE<T>(dest, curr_value);
|
||||
dest += sizeof(curr_value);
|
||||
|
||||
prev_xored_info = curr_xored_info;
|
||||
|
@ -86,8 +86,8 @@ UInt32 ICompressionCodec::compress(const char * source, UInt32 source_size, char
|
||||
UInt8 header_size = getHeaderSize();
|
||||
/// Write data from header_size
|
||||
UInt32 compressed_bytes_written = doCompressData(source, source_size, &dest[header_size]);
|
||||
unalignedStore<UInt32>(&dest[1], compressed_bytes_written + header_size);
|
||||
unalignedStore<UInt32>(&dest[5], source_size);
|
||||
unalignedStoreLE<UInt32>(&dest[1], compressed_bytes_written + header_size);
|
||||
unalignedStoreLE<UInt32>(&dest[5], source_size);
|
||||
return header_size + compressed_bytes_written;
|
||||
}
|
||||
|
||||
@ -112,7 +112,7 @@ UInt32 ICompressionCodec::decompress(const char * source, UInt32 source_size, ch
|
||||
|
||||
UInt32 ICompressionCodec::readCompressedBlockSize(const char * source)
|
||||
{
|
||||
UInt32 compressed_block_size = unalignedLoad<UInt32>(&source[1]);
|
||||
UInt32 compressed_block_size = unalignedLoadLE<UInt32>(&source[1]);
|
||||
if (compressed_block_size == 0)
|
||||
throw Exception(ErrorCodes::CORRUPTED_DATA, "Can't decompress data: header is corrupt with compressed block size 0");
|
||||
return compressed_block_size;
|
||||
@ -121,7 +121,7 @@ UInt32 ICompressionCodec::readCompressedBlockSize(const char * source)
|
||||
|
||||
UInt32 ICompressionCodec::readDecompressedBlockSize(const char * source)
|
||||
{
|
||||
UInt32 decompressed_block_size = unalignedLoad<UInt32>(&source[5]);
|
||||
UInt32 decompressed_block_size = unalignedLoadLE<UInt32>(&source[5]);
|
||||
if (decompressed_block_size == 0)
|
||||
throw Exception(ErrorCodes::CORRUPTED_DATA, "Can't decompress data: header is corrupt with decompressed block size 0");
|
||||
return decompressed_block_size;
|
||||
|
@ -175,7 +175,7 @@ private:
|
||||
throw std::runtime_error("No more data to read");
|
||||
}
|
||||
|
||||
current_value = unalignedLoad<T>(data);
|
||||
current_value = unalignedLoadLE<T>(data);
|
||||
data = reinterpret_cast<const char *>(data) + sizeof(T);
|
||||
}
|
||||
};
|
||||
@ -371,7 +371,7 @@ CodecTestSequence makeSeq(Args && ... args)
|
||||
char * write_pos = data.data();
|
||||
for (const auto & v : vals)
|
||||
{
|
||||
unalignedStore<T>(write_pos, v);
|
||||
unalignedStoreLE<T>(write_pos, v);
|
||||
write_pos += sizeof(v);
|
||||
}
|
||||
|
||||
@ -393,7 +393,7 @@ CodecTestSequence generateSeq(Generator gen, const char* gen_name, B Begin = 0,
|
||||
{
|
||||
const T v = gen(static_cast<T>(i));
|
||||
|
||||
unalignedStore<T>(write_pos, v);
|
||||
unalignedStoreLE<T>(write_pos, v);
|
||||
write_pos += sizeof(v);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user