Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print content of columns for gtest #5243

Merged
merged 18 commits into from
Jul 11, 2022
49 changes: 49 additions & 0 deletions dbms/src/TestUtils/FunctionTestUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,5 +275,54 @@ ColumnWithTypeAndName toNullableDatetimeVec(String name, const std::vector<Strin
DataTypePtr data_type = makeNullable(std::make_shared<DataTypeMyDateTime>(fsp));
return {makeColumn<Nullable<MyDateTime>>(data_type, vec), data_type, name, 0};
}

void printColumns(const ColumnsWithTypeAndName & cols)
{
if (cols.size() <= 0)
return;
printColumns(cols, 0, cols[0].column->size() - 1);
}

void printColumns(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

String output;
for (size_t i = 0; i < col_num; ++i)
{
/// Push the column name
output = fmt::format("{}{}: (", output, cols[i].name);
for (size_t j = begin; j <= end; ++j)
{
if (j != begin)
output = fmt::format("{}, ", output); /// Add comma to seperate different values

/// Add value
output = fmt::format("{}{}: {}", output, j, (*cols[i].column)[j].toString());
}

output = fmt::format("{})\n", output);
}

std::cout << output << std::endl;
JaySon-Huang marked this conversation as resolved.
Show resolved Hide resolved
}

} // 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 @@ -514,6 +514,11 @@ ColumnWithTypeAndName createConstColumn(
return createConstColumn<T>(data_type_args, size, InferredFieldType<T>(std::nullopt), name);
}

void printColumns(const ColumnsWithTypeAndName & cols);

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

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