ClickHouse/src/Interpreters/AggregateDescription.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

125 lines
3.0 KiB
C++
Raw Normal View History

#include <Interpreters/AggregateDescription.h>
2021-06-14 04:13:35 +00:00
#include <Common/FieldVisitorToString.h>
2020-06-27 14:02:24 +00:00
#include <IO/Operators.h>
#include <Common/JSONBuilder.h>
2021-06-14 04:13:35 +00:00
namespace DB
{
2020-07-07 19:51:32 +00:00
void AggregateDescription::explain(WriteBuffer & out, size_t indent) const
{
2020-07-07 19:51:32 +00:00
String prefix(indent, ' ');
2020-06-27 14:02:24 +00:00
out << prefix << column_name << '\n';
2020-06-27 14:02:24 +00:00
auto dump_params = [&](const Array & arr)
{
2020-06-27 14:02:24 +00:00
bool first = true;
for (const auto & param : arr)
{
2020-06-27 14:02:24 +00:00
if (!first)
out << ", ";
2020-06-27 14:02:24 +00:00
first = false;
2020-06-27 14:02:24 +00:00
out << applyVisitor(FieldVisitorToString(), param);
}
};
if (function)
{
2020-07-05 16:27:54 +00:00
/// Double whitespace is intentional.
2020-06-27 14:02:24 +00:00
out << prefix << " Function: " << function->getName();
const auto & params = function->getParameters();
if (!params.empty())
{
out << "(";
dump_params(params);
out << ")";
}
out << "(";
bool first = true;
for (const auto & type : function->getArgumentTypes())
{
2020-06-27 14:02:24 +00:00
if (!first)
out << ", ";
first = false;
2020-06-27 14:02:24 +00:00
out << type->getName();
}
2022-11-28 15:02:59 +00:00
out << ") → " << function->getResultType()->getName() << "\n";
}
else
2020-06-27 14:02:24 +00:00
out << prefix << " Function: nullptr\n";
if (!parameters.empty())
2020-06-24 12:09:01 +00:00
{
2020-06-27 14:02:24 +00:00
out << prefix << " Parameters: ";
dump_params(parameters);
out << '\n';
2020-06-24 12:09:01 +00:00
}
2020-06-27 14:02:24 +00:00
out << prefix << " Arguments: ";
2020-06-24 12:09:01 +00:00
2020-06-27 14:02:24 +00:00
if (argument_names.empty())
out << "none\n";
else
2020-06-24 12:09:01 +00:00
{
2020-06-27 14:02:24 +00:00
bool first = true;
for (const auto & arg : argument_names)
{
if (!first)
out << ", ";
first = false;
2020-06-24 12:09:01 +00:00
2020-06-27 14:02:24 +00:00
out << arg;
}
out << "\n";
2020-06-24 12:09:01 +00:00
}
}
void AggregateDescription::explain(JSONBuilder::JSONMap & map) const
{
map.add("Name", column_name);
if (function)
{
auto function_map = std::make_unique<JSONBuilder::JSONMap>();
function_map->add("Name", function->getName());
const auto & params = function->getParameters();
if (!params.empty())
{
auto params_array = std::make_unique<JSONBuilder::JSONArray>();
for (const auto & param : params)
params_array->add(applyVisitor(FieldVisitorToString(), param));
function_map->add("Parameters", std::move(params_array));
}
auto args_array = std::make_unique<JSONBuilder::JSONArray>();
for (const auto & type : function->getArgumentTypes())
args_array->add(type->getName());
function_map->add("Argument Types", std::move(args_array));
2022-11-28 15:02:59 +00:00
function_map->add("Result Type", function->getResultType()->getName());
map.add("Function", std::move(function_map));
}
auto args_array = std::make_unique<JSONBuilder::JSONArray>();
for (const auto & name : argument_names)
args_array->add(name);
map.add("Arguments", std::move(args_array));
}
}