Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions cpp-ch/local-engine/Common/ArrayJoinHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <Processors/QueryPlan/IQueryPlanStep.h>
#include <Processors/QueryPlan/QueryPlan.h>
#include <Poco/Logger.h>
#include <Common/DebugUtils.h>
#include <Common/logger_useful.h>

namespace DB
Expand Down Expand Up @@ -110,11 +111,11 @@ addArrayJoinStep(DB::ContextPtr context, DB::QueryPlan & plan, const DB::Actions
{
/// If generator in generate rel is explode/posexplode, transform arrayJoin function to ARRAY JOIN STEP to apply max_block_size
/// which avoids OOM when several lateral view explode/posexplode is used in spark sqls
LOG_DEBUG(logger, "original actions_dag:{}", actions_dag.dumpDAG());
LOG_TEST(logger, "original actions_dag:\n{}", debug::dumpActionsDAG(actions_dag));
auto splitted_actions_dags = splitActionsDAGInGenerate(actions_dag);
LOG_DEBUG(logger, "actions_dag before arrayJoin:{}", splitted_actions_dags.before_array_join.dumpDAG());
LOG_DEBUG(logger, "actions_dag during arrayJoin:{}", splitted_actions_dags.array_join.dumpDAG());
LOG_DEBUG(logger, "actions_dag after arrayJoin:{}", splitted_actions_dags.after_array_join.dumpDAG());
LOG_TEST(logger, "actions_dag before arrayJoin:\n{}", debug::dumpActionsDAG(splitted_actions_dags.before_array_join));
LOG_TEST(logger, "actions_dag during arrayJoin:\n{}", debug::dumpActionsDAG(splitted_actions_dags.array_join));
LOG_TEST(logger, "actions_dag after arrayJoin:\n{}", debug::dumpActionsDAG(splitted_actions_dags.after_array_join));

auto ignore_actions_dag = [](const DB::ActionsDAG & actions_dag_) -> bool
{
Expand Down
72 changes: 72 additions & 0 deletions cpp-ch/local-engine/Common/DebugUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include <Common/QueryContext.h>
#include <Common/formatReadable.h>
#include <Common/logger_useful.h>
#include "Functions/IFunction.h"
#include <Interpreters/ActionsDAG.h>

namespace pb_util = google::protobuf::util;

Expand Down Expand Up @@ -396,4 +398,74 @@ std::string showString(const DB::Block & block, size_t numRows, size_t truncate,
[](const DB::ColumnWithTypeAndName & col) { return std::make_pair(col.name, col.column); });
return Utils::showString(name_and_columns, numRows, truncate, vertical);
}

std::string dumpActionsDAG(const DB::ActionsDAG & dag)
{
std::stringstream ss;
ss << "digraph ActionsDAG {\n";
ss << " rankdir=BT;\n"; // Invert the vertical direction
ss << " nodesep=0.1;\n"; // Reduce space between nodes
ss << " ranksep=0.1;\n"; // Reduce space between ranks
ss << " margin=0.1;\n"; // Reduce graph margin

std::unordered_map<const DB::ActionsDAG::Node *, size_t> node_to_id;
size_t id = 0;
for (const auto & node : dag.getNodes())
node_to_id[&node] = id++;

std::unordered_set<const DB::ActionsDAG::Node *> output_nodes(dag.getOutputs().begin(), dag.getOutputs().end());

for (const auto & node : dag.getNodes())
{
ss << " n" << node_to_id[&node] << " [label=\"";

ss << "id:" << node_to_id[&node] << "\\l";
switch (node.type)
{
case DB::ActionsDAG::ActionType::COLUMN:
ss << "column:"
<< (node.column && DB::isColumnConst(*node.column)
? toString(assert_cast<const DB::ColumnConst &>(*node.column).getField())
: "null")
<< "\\l";
break;
case DB::ActionsDAG::ActionType::ALIAS:
ss << "alias" << "\\l";
break;
case DB::ActionsDAG::ActionType::FUNCTION:
ss << "function: " << (node.function_base ? node.function_base->getName() : "null");
if (node.is_function_compiled)
ss << " [compiled]";
ss << "\\l";
break;
case DB::ActionsDAG::ActionType::ARRAY_JOIN:
ss << "array join" << "\\l";
break;
case DB::ActionsDAG::ActionType::INPUT:
ss << "input" << "\\l";
break;
}

ss << "result type: " << (node.result_type ? node.result_type->getName() : "null") << "\\l";

ss << "children:";
for (const auto * child : node.children)
ss << " " << node_to_id[child];
ss << "\\l";

ss << "\"";
if (output_nodes.contains(&node))
ss << ", shape=doublecircle";

ss << "];\n";
}

for (const auto & node : dag.getNodes())
for (const auto * child : node.children)
ss << " n" << node_to_id[child] << " -> n" << node_to_id[&node] << ";\n";

ss << "}\n";
return ss.str();
}

}
2 changes: 2 additions & 0 deletions cpp-ch/local-engine/Common/DebugUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Message;
namespace DB
{
class QueryPlan;
class ActionsDAG;
}
namespace debug
{
Expand All @@ -41,5 +42,6 @@ inline std::string verticalShowString(const DB::Block & block, size_t numRows =
{
return showString(block, numRows, truncate, true);
}
std::string dumpActionsDAG(const DB::ActionsDAG & dag);

}
1 change: 1 addition & 0 deletions cpp-ch/local-engine/Parser/AggregateFunctionParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <Parser/TypeParser.h>
#include <Common/CHUtil.h>
#include <Common/Exception.h>
#include <Common/logger_useful.h>

namespace DB
{
Expand Down