2020-09-15 09:55:57 +00:00
|
|
|
#include <common/types.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Common/Exception.h>
|
|
|
|
#include <IO/ReadBuffer.h>
|
|
|
|
#include <IO/WriteBuffer.h>
|
|
|
|
#include <IO/VarInt.h>
|
|
|
|
#include <IO/ReadHelpers.h>
|
|
|
|
#include <IO/WriteHelpers.h>
|
|
|
|
#include <Core/BlockInfo.h>
|
2016-06-07 08:23:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
extern const int UNKNOWN_BLOCK_INFO_FIELD;
|
2016-06-07 08:23:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-26 01:20:25 +00:00
|
|
|
/// Write values in binary form. NOTE: You could use protobuf, but it would be overkill for this case.
|
2016-06-07 08:23:15 +00:00
|
|
|
void BlockInfo::write(WriteBuffer & out) const
|
|
|
|
{
|
2018-05-07 02:01:11 +00:00
|
|
|
/// Set of pairs `FIELD_NUM`, value in binary form. Then 0.
|
2016-06-07 08:23:15 +00:00
|
|
|
#define WRITE_FIELD(TYPE, NAME, DEFAULT, FIELD_NUM) \
|
2017-04-01 07:20:54 +00:00
|
|
|
writeVarUInt(FIELD_NUM, out); \
|
|
|
|
writeBinary(NAME, out);
|
2016-06-07 08:23:15 +00:00
|
|
|
|
2019-01-04 14:14:48 +00:00
|
|
|
APPLY_FOR_BLOCK_INFO_FIELDS(WRITE_FIELD)
|
2016-06-07 08:23:15 +00:00
|
|
|
|
|
|
|
#undef WRITE_FIELD
|
2017-04-01 07:20:54 +00:00
|
|
|
writeVarUInt(0, out);
|
2016-06-07 08:23:15 +00:00
|
|
|
}
|
|
|
|
|
2017-03-26 01:20:25 +00:00
|
|
|
/// Read values in binary form.
|
2016-06-07 08:23:15 +00:00
|
|
|
void BlockInfo::read(ReadBuffer & in)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
UInt64 field_num = 0;
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
readVarUInt(field_num, in);
|
|
|
|
if (field_num == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch (field_num)
|
|
|
|
{
|
|
|
|
#define READ_FIELD(TYPE, NAME, DEFAULT, FIELD_NUM) \
|
|
|
|
case FIELD_NUM: \
|
|
|
|
readBinary(NAME, in); \
|
|
|
|
break;
|
|
|
|
|
2019-01-04 14:14:48 +00:00
|
|
|
APPLY_FOR_BLOCK_INFO_FIELDS(READ_FIELD)
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
#undef READ_FIELD
|
|
|
|
default:
|
|
|
|
throw Exception("Unknown BlockInfo field number: " + toString(field_num), ErrorCodes::UNKNOWN_BLOCK_INFO_FIELD);
|
|
|
|
}
|
|
|
|
}
|
2016-06-07 08:23:15 +00:00
|
|
|
}
|
|
|
|
|
2018-11-15 15:57:20 +00:00
|
|
|
void BlockMissingValues::setBit(size_t column_idx, size_t row_idx)
|
2018-07-04 17:02:47 +00:00
|
|
|
{
|
2018-12-04 20:10:43 +00:00
|
|
|
RowsBitMask & mask = rows_mask_by_column_id[column_idx];
|
2018-07-04 17:02:47 +00:00
|
|
|
mask.resize(row_idx + 1);
|
|
|
|
mask[row_idx] = true;
|
|
|
|
}
|
|
|
|
|
2018-11-15 15:57:20 +00:00
|
|
|
const BlockMissingValues::RowsBitMask & BlockMissingValues::getDefaultsBitmask(size_t column_idx) const
|
2018-07-04 17:02:47 +00:00
|
|
|
{
|
2018-07-11 14:11:47 +00:00
|
|
|
static RowsBitMask none;
|
2018-12-04 20:10:43 +00:00
|
|
|
auto it = rows_mask_by_column_id.find(column_idx);
|
|
|
|
if (it != rows_mask_by_column_id.end())
|
2018-07-04 17:02:47 +00:00
|
|
|
return it->second;
|
|
|
|
return none;
|
|
|
|
}
|
|
|
|
|
2020-03-03 14:25:28 +00:00
|
|
|
bool BlockMissingValues::hasDefaultBits(size_t column_idx) const
|
|
|
|
{
|
|
|
|
auto it = rows_mask_by_column_id.find(column_idx);
|
|
|
|
if (it == rows_mask_by_column_id.end())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const auto & col_mask = it->second;
|
|
|
|
return std::find(col_mask.begin(), col_mask.end(), true) != col_mask.end();
|
|
|
|
}
|
2016-06-07 08:23:15 +00:00
|
|
|
}
|