Skip to content

Commit

Permalink
backport getColumnsContent
Browse files Browse the repository at this point in the history
Signed-off-by: JaySon-Huang <[email protected]>
  • Loading branch information
JaySon-Huang committed Sep 23, 2022
1 parent 063e7f4 commit e337612
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class RegionBlockReaderTest : public ::testing::Test
{
public:
RegionBlockReaderTest()
: logger(Logger::get("RegionBlockReaderTest"))
: logger(&Poco::Logger::get("RegionBlockReaderTest"))
{}

protected:
Expand All @@ -43,7 +43,7 @@ class RegionBlockReaderTest : public ::testing::Test
RegionDataReadInfoList data_list_read;
std::unordered_map<ColumnID, Field> fields_map;

LoggerPtr logger;
Poco::Logger * logger;

enum RowEncodeVersion
{
Expand Down
54 changes: 54 additions & 0 deletions dbms/src/TestUtils/FunctionTestUtils.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <Common/FmtUtils.h>
#include <Core/ColumnNumbers.h>
#include <DataTypes/DataTypeNothing.h>
#include <Functions/FunctionFactory.h>
Expand Down Expand Up @@ -154,5 +155,58 @@ ColumnWithTypeAndName createDateTimeColumnConst(size_t size, const MyDateTime &
return {std::move(col), data_type_ptr, "datetime"};
}

String getColumnsContent(const ColumnsWithTypeAndName & cols)
{
if (cols.empty())
return "";
return getColumnsContent(cols, 0, cols[0].column->size());
}

String getColumnsContent(const ColumnsWithTypeAndName & cols, size_t begin, size_t end)
{
const size_t col_num = cols.size();
if (col_num <= 0)
return "";

const size_t col_size = cols[0].column->size();
assert(begin <= end);
assert(col_size >= end);
assert(col_size > begin);

bool is_same = true;

for (size_t i = 1; i < col_num; ++i)
{
if (cols[i].column->size() != col_size)
is_same = false;
}

assert(is_same); /// Ensure the sizes of columns in cols are the same

std::vector<std::pair<size_t, String>> col_content;
FmtBuffer fmt_buf;
for (size_t i = 0; i < col_num; ++i)
{
/// Push the column name
fmt_buf.append(fmt::format("{}: (", cols[i].name));
for (size_t j = begin; j < end; ++j)
col_content.push_back(std::make_pair(j, (*cols[i].column)[j].toString()));

/// Add content
fmt_buf.joinStr(
col_content.begin(),
col_content.end(),
[](const auto & content, FmtBuffer & fmt_buf) {
fmt_buf.append(fmt::format("{}: {}", content.first, content.second));
},
", ");

fmt_buf.append(")\n");
col_content.clear();
}

return fmt_buf.toString();
}

} // namespace tests
} // namespace DB
5 changes: 5 additions & 0 deletions dbms/src/TestUtils/FunctionTestUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,11 @@ ColumnWithTypeAndName createConstColumn(
return createConstColumn<T>(data_type_args, size, InferredFieldType<T>(std::nullopt), name);
}

String getColumnsContent(const ColumnsWithTypeAndName & cols);

/// We can designate the range of columns printed with begin and end. range: [begin, end)
String getColumnsContent(const ColumnsWithTypeAndName & cols, size_t begin, size_t end);

::testing::AssertionResult dataTypeEqual(
const DataTypePtr & expected,
const DataTypePtr & actual);
Expand Down

0 comments on commit e337612

Please sign in to comment.