diff options
| -rw-r--r-- | ydb/public/lib/ydb_cli/common/format.cpp | 59 | ||||
| -rw-r--r-- | ydb/public/lib/ydb_cli/common/format.h | 4 |
2 files changed, 41 insertions, 22 deletions
diff --git a/ydb/public/lib/ydb_cli/common/format.cpp b/ydb/public/lib/ydb_cli/common/format.cpp index 75748758d80..38b70b93ae7 100644 --- a/ydb/public/lib/ydb_cli/common/format.cpp +++ b/ydb/public/lib/ydb_cli/common/format.cpp @@ -411,6 +411,8 @@ void TQueryPlanPrinter::PrintPretty(const NJson::TJsonValue& plan) { } } + + void TQueryPlanPrinter::PrintPrettyImpl(const NJson::TJsonValue& plan, TVector<TString>& offsets) { static const TString edge = "| "; static const TString noEdge = " "; @@ -549,26 +551,36 @@ TString FormatPrettyTableDouble(TString stringValue) { return ToString(stream.str()); } -void TQueryPlanPrinter::PrintPrettyTableImpl(const NJson::TJsonValue& plan, TString& offset, TPrettyTable& table) { +void TQueryPlanPrinter::PrintPrettyTableImpl(const NJson::TJsonValue& plan, TString& offset, TPrettyTable& table, bool isLast, TVector<bool> hasMore) { const auto& node = plan.GetMapSafe(); auto& newRow = table.AddRow(); NColorizer::TColors colors = NColorizer::AutoColors(Output); - TStringBuf color; - switch(offset.size() % 3) { - case 0: - color = colors.LightRed(); - break; - case 1: - color = colors.LightGreen(); - break; - case 2: - color = colors.LightBlue(); - break; - default: - color = colors.Default(); - break; + + bool hasChildren = node.contains("Plans") && !node.at("Plans").GetArraySafe().empty(); + + TStringBuilder arrowOffset; + for (size_t i = 0; i < hasMore.size(); ++i) { + if (hasMore[i]) { + arrowOffset << "│ "; + } else { + arrowOffset << " "; + } + } + + if (offset.empty()) { + arrowOffset << "┌> "; + } else { + if (isLast) { + if (hasChildren) { + arrowOffset << "└─┬> "; + } else { + arrowOffset << "└──> "; + } + } else { + arrowOffset << "├──> "; + } } if (node.contains("Operators")) { @@ -610,9 +622,9 @@ void TQueryPlanPrinter::PrintPrettyTableImpl(const NJson::TJsonValue& plan, TStr TStringBuilder operation; if (info.empty()) { - operation << offset << color << " -> " << colors.LightCyan() << op.GetMapSafe().at("Name").GetString() << colors.Default(); + operation << arrowOffset << colors.LightCyan() << op.GetMapSafe().at("Name").GetString() << colors.Default(); } else { - operation << offset << color << " -> " << colors.LightCyan() << op.GetMapSafe().at("Name").GetString() << colors.Default() + operation << arrowOffset << colors.LightCyan() << op.GetMapSafe().at("Name").GetString() << colors.Default() << " (" << JoinStrings(info, ", ") << ")"; } @@ -632,15 +644,22 @@ void TQueryPlanPrinter::PrintPrettyTableImpl(const NJson::TJsonValue& plan, TStr } } else { TStringBuilder operation; - operation << offset << color << " -> " << colors.LightCyan() << node.at("Node Type").GetString() << colors.Default(); + operation << arrowOffset << colors.LightCyan() << node.at("Node Type").GetString() << colors.Default(); newRow.Column(0, std::move(operation)); } if (node.contains("Plans")) { auto& plans = node.at("Plans").GetArraySafe(); - for (auto subplan : plans) { + for (size_t i = 0; i < plans.size(); ++i) { + bool isLastChild = (i == plans.size() - 1); + + TVector<bool> newHasMore = hasMore; + if (!offset.empty()) { + newHasMore.push_back(!isLast); + } + offset += " "; - PrintPrettyTableImpl(subplan, offset, table); + PrintPrettyTableImpl(plans[i], offset, table, isLastChild, newHasMore); offset.resize(offset.size() - 2); } } diff --git a/ydb/public/lib/ydb_cli/common/format.h b/ydb/public/lib/ydb_cli/common/format.h index 7be5c44d956..56c2538deaf 100644 --- a/ydb/public/lib/ydb_cli/common/format.h +++ b/ydb/public/lib/ydb_cli/common/format.h @@ -74,7 +74,7 @@ private: class TCommandWithOutput: virtual public TCommandWithFormat { protected: - void AddOutputFormats(TClientCommand::TConfig& config, + void AddOutputFormats(TClientCommand::TConfig& config, const TVector<EDataFormat>& allowedFormats, EDataFormat defaultFormat = EDataFormat::Pretty); void ParseOutputFormats(); @@ -158,7 +158,7 @@ private: void PrintPretty(const NJson::TJsonValue& plan); void PrintPrettyImpl(const NJson::TJsonValue& plan, TVector<TString>& offsets); void PrintPrettyTable(const NJson::TJsonValue& plan); - void PrintPrettyTableImpl(const NJson::TJsonValue& plan, TString& offset, TPrettyTable& table); + void PrintPrettyTableImpl(const NJson::TJsonValue& plan, TString& offset, TPrettyTable& table, bool isLast = true, TVector<bool> hasMore = TVector<bool>()); void PrintJson(const TString& plan); void PrintSimplifyJson(const NJson::TJsonValue& plan); TString JsonToString(const NJson::TJsonValue& jsonValue); |
