Skip to content

Commit

Permalink
refine log for CodecUtils (#8670)
Browse files Browse the repository at this point in the history
ref #8601
  • Loading branch information
SeaRise authored Jan 5, 2024
1 parent 1305bae commit 1aa8fcd
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 17 deletions.
6 changes: 3 additions & 3 deletions dbms/src/DataStreams/NativeBlockInputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ Block NativeBlockInputStream::readImpl()
}

if (header)
CodecUtils::checkColumnSize(header.columns(), columns);
CodecUtils::checkColumnSize("NativeBlockInputStream", header.columns(), columns);
else if (!output_names.empty())
CodecUtils::checkColumnSize(output_names.size(), columns);
CodecUtils::checkColumnSize("NativeBlockInputStream", output_names.size(), columns);

for (size_t i = 0; i < columns; ++i)
{
Expand All @@ -182,7 +182,7 @@ Block NativeBlockInputStream::readImpl()
readBinary(type_name, istr);
if (header)
{
CodecUtils::checkDataTypeName(i, header_datatypes[i].name, type_name);
CodecUtils::checkDataTypeName("NativeBlockInputStream", i, header_datatypes[i].name, type_name);
column.type = header_datatypes[i].type;
}
else
Expand Down
6 changes: 3 additions & 3 deletions dbms/src/Flash/Coprocessor/CHBlockChunkCodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ void CHBlockChunkCodec::readBlockMeta(ReadBuffer & istr, size_t & columns, size_
readVarUInt(rows, istr);

if (header)
CodecUtils::checkColumnSize(header.columns(), columns);
CodecUtils::checkColumnSize("CHBlockChunkCodec", header.columns(), columns);
else if (!output_names.empty())
CodecUtils::checkColumnSize(output_names.size(), columns);
CodecUtils::checkColumnSize("CHBlockChunkCodec", output_names.size(), columns);
}

void CHBlockChunkCodec::readColumnMeta(size_t i, ReadBuffer & istr, ColumnWithTypeAndName & column)
Expand All @@ -213,7 +213,7 @@ void CHBlockChunkCodec::readColumnMeta(size_t i, ReadBuffer & istr, ColumnWithTy
const DataTypeFactory & data_type_factory = DataTypeFactory::instance();
if (header)
{
CodecUtils::checkDataTypeName(i, header_datatypes[i].name, type_name);
CodecUtils::checkDataTypeName("CHBlockChunkCodec", i, header_datatypes[i].name, type_name);
column.type = header_datatypes[i].type;
}
else
Expand Down
16 changes: 12 additions & 4 deletions dbms/src/Flash/Coprocessor/CHBlockChunkCodecV1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Block DecodeHeader(ReadBuffer & istr, const Block & header, size_t & total_rows)
readVarUInt(total_rows, istr);
}
if (header)
CodecUtils::checkColumnSize(header.columns(), columns);
CodecUtils::checkColumnSize("CHBlockChunkCodecV1", header.columns(), columns);

for (size_t i = 0; i < columns; ++i)
{
Expand All @@ -75,7 +75,11 @@ Block DecodeHeader(ReadBuffer & istr, const Block & header, size_t & total_rows)
readBinary(type_name, istr);
if (header)
{
CodecUtils::checkDataTypeName(i, header.getByPosition(i).type->getName(), type_name);
CodecUtils::checkDataTypeName(
"CHBlockChunkCodecV1",
i,
header.getByPosition(i).type->getName(),
type_name);
column.type = header.getByPosition(i).type;
}
else
Expand Down Expand Up @@ -431,11 +435,15 @@ CHBlockChunkCodecV1::CHBlockChunkCodecV1(const Block & header_)

static void checkSchema(const Block & header, const Block & block)
{
CodecUtils::checkColumnSize(header.columns(), block.columns());
CodecUtils::checkColumnSize("CHBlockChunkCodecV1", header.columns(), block.columns());
for (size_t column_index = 0; column_index < header.columns(); ++column_index)
{
auto && type_name = block.getByPosition(column_index).type->getName();
CodecUtils::checkDataTypeName(column_index, header.getByPosition(column_index).type->getName(), type_name);
CodecUtils::checkDataTypeName(
"CHBlockChunkCodecV1",
column_index,
header.getByPosition(column_index).type->getName(),
type_name);
}
}

Expand Down
9 changes: 5 additions & 4 deletions dbms/src/Flash/Coprocessor/CodecUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,21 @@ extern const int LOGICAL_ERROR;

namespace CodecUtils
{
void checkColumnSize(size_t expected, size_t actual)
void checkColumnSize(const String & identifier, size_t expected, size_t actual)
{
if unlikely (expected != actual)
throw Exception(
fmt::format("NativeBlockInputStream schema mismatch, expected {}, actual {}.", expected, actual),
fmt::format("{} schema size mismatch, expected {}, actual {}.", identifier, expected, actual),
ErrorCodes::LOGICAL_ERROR);
}

void checkDataTypeName(size_t column_index, const String & expected, const String & actual)
void checkDataTypeName(const String & identifier, size_t column_index, const String & expected, const String & actual)
{
if unlikely (expected != actual)
throw Exception(
fmt::format(
"NativeBlockInputStream schema mismatch at column {}, expected {}, actual {}",
"{} schema mismatch at column {}, expected {}, actual {}",
identifier,
column_index,
expected,
actual),
Expand Down
6 changes: 3 additions & 3 deletions dbms/src/Flash/Coprocessor/CodecUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct DataTypeWithTypeName
String name;
};

void checkColumnSize(size_t expected, size_t actual);
void checkDataTypeName(size_t column_index, const String & expected, const String & actual);
void checkColumnSize(const String & identifier, size_t expected, size_t actual);
void checkDataTypeName(const String & identifier, size_t column_index, const String & expected, const String & actual);
} // namespace CodecUtils
} // namespace DB
} // namespace DB

0 comments on commit 1aa8fcd

Please sign in to comment.