From 039afc5cfe1abf49fde8650ec80509f06eb03657 Mon Sep 17 00:00:00 2001 From: zzsmdfj Date: Wed, 22 Dec 2021 16:17:18 +0800 Subject: [PATCH] #15182_MaterializeMySQL_support_bit_type-improve bit2Uint64 function --- src/Core/MySQL/MySQLReplication.cpp | 10 +++------- src/Core/MySQL/MySQLReplication.h | 13 ++++--------- src/Processors/Sources/MySQLSource.cpp | 9 ++++----- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/Core/MySQL/MySQLReplication.cpp b/src/Core/MySQL/MySQLReplication.cpp index 70446573718..d6094b0b212 100644 --- a/src/Core/MySQL/MySQLReplication.cpp +++ b/src/Core/MySQL/MySQLReplication.cpp @@ -589,13 +589,9 @@ namespace MySQLReplication { UInt32 bits = ((meta >> 8) * 8) + (meta & 0xff); UInt32 size = (bits + 7) / 8; - - Bitmap bitmap_value; - String byte_buffer; - byte_buffer.resize(size); - readBigEndianStrict(payload, reinterpret_cast(byte_buffer.data()), size); - readBitmapFromStr(byte_buffer.c_str(), bitmap_value, size); - row.push_back(Field{UInt64{bitmap_value.to_ulong()}}); + UInt64 val = 0UL; + readBigEndianStrict(payload, reinterpret_cast(&val), size); + row.push_back(val); break; } case MYSQL_TYPE_VARCHAR: diff --git a/src/Core/MySQL/MySQLReplication.h b/src/Core/MySQL/MySQLReplication.h index 38c099bb2f9..cb67ce73de9 100644 --- a/src/Core/MySQL/MySQLReplication.h +++ b/src/Core/MySQL/MySQLReplication.h @@ -78,8 +78,11 @@ namespace MySQLReplication } } - inline void readBitmapFromStr(const char * byte_buffer, Bitmap & bitmap, size_t bitmap_size) + inline void readBitmap(ReadBuffer & payload, Bitmap & bitmap, size_t bitmap_size) { + String byte_buffer; + byte_buffer.resize(bitmap_size); + payload.readStrict(reinterpret_cast(byte_buffer.data()), bitmap_size); bitmap.resize(bitmap_size * 8, false); for (size_t i = 0; i < bitmap_size; ++i) { @@ -106,14 +109,6 @@ namespace MySQLReplication } } - inline void readBitmap(ReadBuffer & payload, Bitmap & bitmap, size_t bitmap_size) - { - String byte_buffer; - byte_buffer.resize(bitmap_size); - payload.readStrict(reinterpret_cast(byte_buffer.data()), bitmap_size); - readBitmapFromStr(byte_buffer.c_str(), bitmap, bitmap_size); - } - class EventBase; using BinlogEventPtr = std::shared_ptr; diff --git a/src/Processors/Sources/MySQLSource.cpp b/src/Processors/Sources/MySQLSource.cpp index 94440fd7cdd..b0cb62340e9 100644 --- a/src/Processors/Sources/MySQLSource.cpp +++ b/src/Processors/Sources/MySQLSource.cpp @@ -149,11 +149,10 @@ namespace if (static_cast(mysql_type) == 16) { size_t n = value.size(); - char *start = const_cast(value.data()), *end = start + n; - std::reverse(start, end); - MySQLReplication::Bitmap bitmap; - MySQLReplication::readBitmapFromStr(value.data(), bitmap, n); - assert_cast(column).insertValue(bitmap.to_ulong()); + UInt64 val = 0UL; + ReadBufferFromMemory payload(const_cast(value.data()), n); + MySQLReplication::readBigEndianStrict(payload, reinterpret_cast(&val), n); + assert_cast(column).insertValue(val); read_bytes_size += n; } else