2020-06-23 16:06:56 +00:00
|
|
|
#include <Interpreters/AggregateDescription.h>
|
|
|
|
#include <Common/FieldVisitors.h>
|
2020-06-27 14:02:24 +00:00
|
|
|
#include <IO/Operators.h>
|
2020-06-23 16:06:56 +00:00
|
|
|
|
2021-04-14 14:07:56 +00:00
|
|
|
#include <Common/JSONBuilder.h>
|
|
|
|
|
2020-06-23 16:06:56 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2020-07-07 19:51:32 +00:00
|
|
|
void AggregateDescription::explain(WriteBuffer & out, size_t indent) const
|
2020-06-23 16:06:56 +00:00
|
|
|
{
|
2020-07-07 19:51:32 +00:00
|
|
|
String prefix(indent, ' ');
|
2020-06-23 16:06:56 +00:00
|
|
|
|
2020-06-27 14:02:24 +00:00
|
|
|
out << prefix << column_name << '\n';
|
2020-06-23 16:06:56 +00:00
|
|
|
|
2020-06-27 14:02:24 +00:00
|
|
|
auto dump_params = [&](const Array & arr)
|
2020-06-23 16:06:56 +00:00
|
|
|
{
|
2020-06-27 14:02:24 +00:00
|
|
|
bool first = true;
|
2020-06-23 16:06:56 +00:00
|
|
|
for (const auto & param : arr)
|
|
|
|
{
|
2020-06-27 14:02:24 +00:00
|
|
|
if (!first)
|
|
|
|
out << ", ";
|
2020-06-23 16:06:56 +00:00
|
|
|
|
2020-06-27 14:02:24 +00:00
|
|
|
first = false;
|
2020-06-23 16:06:56 +00:00
|
|
|
|
2020-06-27 14:02:24 +00:00
|
|
|
out << applyVisitor(FieldVisitorToString(), param);
|
|
|
|
}
|
2020-06-23 16:06:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
2020-06-23 16:06:56 +00:00
|
|
|
for (const auto & type : function->getArgumentTypes())
|
|
|
|
{
|
2020-06-27 14:02:24 +00:00
|
|
|
if (!first)
|
|
|
|
out << ", ";
|
|
|
|
first = false;
|
2020-06-23 16:06:56 +00:00
|
|
|
|
2020-06-27 14:02:24 +00:00
|
|
|
out << type->getName();
|
2020-06-23 16:06:56 +00:00
|
|
|
}
|
|
|
|
|
2020-06-29 20:23:34 +00:00
|
|
|
out << ") → " << function->getReturnType()->getName() << "\n";
|
2020-06-23 16:06:56 +00:00
|
|
|
}
|
|
|
|
else
|
2020-06-27 14:02:24 +00:00
|
|
|
out << prefix << " Function: nullptr\n";
|
2020-06-23 16:06:56 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-06-27 14:02:24 +00:00
|
|
|
out << prefix << " Argument positions: ";
|
2020-06-24 12:09:01 +00:00
|
|
|
|
2020-06-27 14:02:24 +00:00
|
|
|
if (arguments.empty())
|
|
|
|
out << "none\n";
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bool first = true;
|
|
|
|
for (auto arg : arguments)
|
|
|
|
{
|
|
|
|
if (!first)
|
|
|
|
out << ", ";
|
|
|
|
first = false;
|
2020-06-23 16:06:56 +00:00
|
|
|
|
2020-06-27 14:02:24 +00:00
|
|
|
out << arg;
|
|
|
|
}
|
|
|
|
out << '\n';
|
|
|
|
}
|
2020-06-23 16:06:56 +00:00
|
|
|
}
|
|
|
|
|
2021-04-14 14:07:56 +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));
|
|
|
|
function_map->add("Result Type", function->getReturnType()->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));
|
|
|
|
|
|
|
|
if (!arguments.empty())
|
|
|
|
{
|
|
|
|
auto args_pos_array = std::make_unique<JSONBuilder::JSONArray>();
|
|
|
|
for (auto pos : arguments)
|
|
|
|
args_pos_array->add(pos);
|
|
|
|
|
|
|
|
map.add("Argument Positions", std::move(args_pos_array));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-23 16:06:56 +00:00
|
|
|
}
|