Skip to content

Commit

Permalink
Merge pull request #33628 from ClickHouse/fix-block-perf-context-desc…
Browse files Browse the repository at this point in the history
…ription

do not construct std::string if there is no error
  • Loading branch information
kitaisreal committed Jan 15, 2022
2 parents d4f5028 + db0c48d commit dfe64a2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
22 changes: 11 additions & 11 deletions src/Core/Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ static ReturnType onError(const std::string & message [[maybe_unused]], int code

template <typename ReturnType>
static ReturnType checkColumnStructure(const ColumnWithTypeAndName & actual, const ColumnWithTypeAndName & expected,
const std::string & context_description, bool allow_materialize, int code)
std::string_view context_description, bool allow_materialize, int code)
{
if (actual.name != expected.name)
return onError<ReturnType>("Block structure mismatch in " + context_description + " stream: different names of columns:\n"
return onError<ReturnType>("Block structure mismatch in " + std::string(context_description) + " stream: different names of columns:\n"
+ actual.dumpStructure() + "\n" + expected.dumpStructure(), code);

if (!actual.type->equals(*expected.type))
return onError<ReturnType>("Block structure mismatch in " + context_description + " stream: different types:\n"
return onError<ReturnType>("Block structure mismatch in " + std::string(context_description) + " stream: different types:\n"
+ actual.dumpStructure() + "\n" + expected.dumpStructure(), code);

if (!actual.column || !expected.column)
Expand All @@ -66,7 +66,7 @@ static ReturnType checkColumnStructure(const ColumnWithTypeAndName & actual, con
}

if (actual_column->getName() != expected.column->getName())
return onError<ReturnType>("Block structure mismatch in " + context_description + " stream: different columns:\n"
return onError<ReturnType>("Block structure mismatch in " + std::string(context_description) + " stream: different columns:\n"
+ actual.dumpStructure() + "\n" + expected.dumpStructure(), code);

if (isColumnConst(*actual.column) && isColumnConst(*expected.column))
Expand All @@ -75,7 +75,7 @@ static ReturnType checkColumnStructure(const ColumnWithTypeAndName & actual, con
Field expected_value = assert_cast<const ColumnConst &>(*expected.column).getField();

if (actual_value != expected_value)
return onError<ReturnType>("Block structure mismatch in " + context_description + " stream: different values of constants, actual: "
return onError<ReturnType>("Block structure mismatch in " + std::string(context_description) + " stream: different values of constants, actual: "
+ applyVisitor(FieldVisitorToString(), actual_value) + ", expected: " + applyVisitor(FieldVisitorToString(), expected_value),
code);
}
Expand All @@ -85,11 +85,11 @@ static ReturnType checkColumnStructure(const ColumnWithTypeAndName & actual, con


template <typename ReturnType>
static ReturnType checkBlockStructure(const Block & lhs, const Block & rhs, const std::string & context_description, bool allow_materialize)
static ReturnType checkBlockStructure(const Block & lhs, const Block & rhs, std::string_view context_description, bool allow_materialize)
{
size_t columns = rhs.columns();
if (lhs.columns() != columns)
return onError<ReturnType>("Block structure mismatch in " + context_description + " stream: different number of columns:\n"
return onError<ReturnType>("Block structure mismatch in " + std::string(context_description) + " stream: different number of columns:\n"
+ lhs.dumpStructure() + "\n" + rhs.dumpStructure(), ErrorCodes::LOGICAL_ERROR);

for (size_t i = 0; i < columns; ++i)
Expand Down Expand Up @@ -604,23 +604,23 @@ Names Block::getDataTypeNames() const

bool blocksHaveEqualStructure(const Block & lhs, const Block & rhs)
{
return checkBlockStructure<bool>(lhs, rhs, {}, false);
return checkBlockStructure<bool>(lhs, rhs, "", false);
}


void assertBlocksHaveEqualStructure(const Block & lhs, const Block & rhs, const std::string & context_description)
void assertBlocksHaveEqualStructure(const Block & lhs, const Block & rhs, std::string_view context_description)
{
checkBlockStructure<void>(lhs, rhs, context_description, false);
}


bool isCompatibleHeader(const Block & actual, const Block & desired)
{
return checkBlockStructure<bool>(actual, desired, {}, true);
return checkBlockStructure<bool>(actual, desired, "", true);
}


void assertCompatibleHeader(const Block & actual, const Block & desired, const std::string & context_description)
void assertCompatibleHeader(const Block & actual, const Block & desired, std::string_view context_description)
{
checkBlockStructure<void>(actual, desired, context_description, true);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Block.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,13 @@ using ExtraBlockPtr = std::shared_ptr<ExtraBlock>;
bool blocksHaveEqualStructure(const Block & lhs, const Block & rhs);

/// Throw exception when blocks are different.
void assertBlocksHaveEqualStructure(const Block & lhs, const Block & rhs, const std::string & context_description);
void assertBlocksHaveEqualStructure(const Block & lhs, const Block & rhs, std::string_view context_description);

/// Actual header is compatible to desired if block have equal structure except constants.
/// It is allowed when column from actual header is constant, but in desired is not.
/// If both columns are constant, it is checked that they have the same value.
bool isCompatibleHeader(const Block & actual, const Block & desired);
void assertCompatibleHeader(const Block & actual, const Block & desired, const std::string & context_description);
void assertCompatibleHeader(const Block & actual, const Block & desired, std::string_view context_description);

/// Calculate difference in structure of blocks and write description into output strings. NOTE It doesn't compare values of constant columns.
void getBlocksDifference(const Block & lhs, const Block & rhs, std::string & out_lhs_diff, std::string & out_rhs_diff);
Expand Down

0 comments on commit dfe64a2

Please sign in to comment.