#15182_MaterializeMySQL_support_bit_type-improve bit2Uint64 function

This commit is contained in:
zzsmdfj 2021-12-22 16:17:18 +08:00
parent 4a0554c963
commit 039afc5cfe
3 changed files with 11 additions and 21 deletions

View File

@ -589,13 +589,9 @@ namespace MySQLReplication
{ {
UInt32 bits = ((meta >> 8) * 8) + (meta & 0xff); UInt32 bits = ((meta >> 8) * 8) + (meta & 0xff);
UInt32 size = (bits + 7) / 8; UInt32 size = (bits + 7) / 8;
UInt64 val = 0UL;
Bitmap bitmap_value; readBigEndianStrict(payload, reinterpret_cast<char *>(&val), size);
String byte_buffer; row.push_back(val);
byte_buffer.resize(size);
readBigEndianStrict(payload, reinterpret_cast<char *>(byte_buffer.data()), size);
readBitmapFromStr(byte_buffer.c_str(), bitmap_value, size);
row.push_back(Field{UInt64{bitmap_value.to_ulong()}});
break; break;
} }
case MYSQL_TYPE_VARCHAR: case MYSQL_TYPE_VARCHAR:

View File

@ -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<char *>(byte_buffer.data()), bitmap_size);
bitmap.resize(bitmap_size * 8, false); bitmap.resize(bitmap_size * 8, false);
for (size_t i = 0; i < bitmap_size; ++i) 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<char *>(byte_buffer.data()), bitmap_size);
readBitmapFromStr(byte_buffer.c_str(), bitmap, bitmap_size);
}
class EventBase; class EventBase;
using BinlogEventPtr = std::shared_ptr<EventBase>; using BinlogEventPtr = std::shared_ptr<EventBase>;

View File

@ -149,11 +149,10 @@ namespace
if (static_cast<int>(mysql_type) == 16) if (static_cast<int>(mysql_type) == 16)
{ {
size_t n = value.size(); size_t n = value.size();
char *start = const_cast<char *>(value.data()), *end = start + n; UInt64 val = 0UL;
std::reverse(start, end); ReadBufferFromMemory payload(const_cast<char *>(value.data()), n);
MySQLReplication::Bitmap bitmap; MySQLReplication::readBigEndianStrict(payload, reinterpret_cast<char *>(&val), n);
MySQLReplication::readBitmapFromStr(value.data(), bitmap, n); assert_cast<ColumnUInt64 &>(column).insertValue(val);
assert_cast<ColumnUInt64 &>(column).insertValue(bitmap.to_ulong());
read_bytes_size += n; read_bytes_size += n;
} }
else else