Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::TextTreeRenderer Class Reference
Inheritance diagram for duckdb::TextTreeRenderer:
Collaboration diagram for duckdb::TextTreeRenderer:

Public Member Functions

 TextTreeRenderer (TextTreeRendererConfig config_p=TextTreeRendererConfig())
string ToString (const LogicalOperator &op)
string ToString (const PhysicalOperator &op)
string ToString (const ProfilingNode &op)
string ToString (const Pipeline &op)
void Render (const LogicalOperator &op, std::ostream &ss)
void Render (const PhysicalOperator &op, std::ostream &ss)
void Render (const ProfilingNode &op, std::ostream &ss) override
void Render (const Pipeline &op, std::ostream &ss)
void ToStreamInternal (RenderTree &root, std::ostream &ss) override
void EnableDetailed ()
void EnableStandard ()
bool UsesRawKeyNames () override
Public Member Functions inherited from duckdb::TreeRenderer
void ToStream (RenderTree &root, std::ostream &ss)

Private Member Functions

string ExtraInfoSeparator ()
void RenderTopLayer (RenderTree &root, std::ostream &ss, idx_t y)
void RenderBoxContent (RenderTree &root, std::ostream &ss, idx_t y)
void RenderBottomLayer (RenderTree &root, std::ostream &ss, idx_t y)
bool CanSplitOnThisChar (char l)
bool IsPadding (char l)
string RemovePadding (string l)
void SplitUpExtraInfo (const InsertionOrderPreservingMap< string > &extra_info, vector< string > &result, idx_t max_lines)
void SplitStringBuffer (const string &source, vector< string > &result)
string FormatNumber (const string &input)

Private Attributes

TextTreeRendererConfig config
 The configuration used for rendering.

Additional Inherited Members

Static Public Member Functions inherited from duckdb::TreeRenderer
static unique_ptr< TreeRenderer > CreateRenderer (ExplainFormat format)

Constructor & Destructor Documentation

◆ TextTreeRenderer()

duckdb::TextTreeRenderer::TextTreeRenderer ( TextTreeRendererConfig config_p = TextTreeRendererConfig())
inlineexplicit
111317 : config(config_p) {
111318 }
TextTreeRendererConfig config
The configuration used for rendering.
Definition duckdb.cpp:111347

◆ ~TextTreeRenderer()

duckdb::TextTreeRenderer::~TextTreeRenderer ( )
inlineoverride
111319 {
111320 }

Member Function Documentation

◆ ToString() [1/4]

string duckdb::TextTreeRenderer::ToString ( const LogicalOperator & op)
111686 {
111687 duckdb::stringstream ss;
111688 Render(op, ss);
111689 return ss.str();
111690}

◆ ToString() [2/4]

string duckdb::TextTreeRenderer::ToString ( const PhysicalOperator & op)
111692 {
111693 duckdb::stringstream ss;
111694 Render(op, ss);
111695 return ss.str();
111696}

◆ ToString() [3/4]

string duckdb::TextTreeRenderer::ToString ( const ProfilingNode & op)
111698 {
111699 duckdb::stringstream ss;
111700 Render(op, ss);
111701 return ss.str();
111702}

◆ ToString() [4/4]

string duckdb::TextTreeRenderer::ToString ( const Pipeline & op)
111704 {
111705 duckdb::stringstream ss;
111706 Render(op, ss);
111707 return ss.str();
111708}

◆ Render() [1/4]

void duckdb::TextTreeRenderer::Render ( const LogicalOperator & op,
std::ostream & ss )
111710 {
111711 auto tree = RenderTree::CreateRenderTree(op);
111712 ToStream(*tree, ss);
111713}

◆ Render() [2/4]

void duckdb::TextTreeRenderer::Render ( const PhysicalOperator & op,
std::ostream & ss )
111715 {
111716 auto tree = RenderTree::CreateRenderTree(op);
111717 ToStream(*tree, ss);
111718}

◆ Render() [3/4]

void duckdb::TextTreeRenderer::Render ( const ProfilingNode & op,
std::ostream & ss )
overridevirtual

Reimplemented from duckdb::TreeRenderer.

111720 {
111721 auto tree = RenderTree::CreateRenderTree(op);
111722 ToStream(*tree, ss);
111723}

◆ Render() [4/4]

void duckdb::TextTreeRenderer::Render ( const Pipeline & op,
std::ostream & ss )
111725 {
111726 auto tree = RenderTree::CreateRenderTree(op);
111727 ToStream(*tree, ss);
111728}

◆ ToStreamInternal()

void duckdb::TextTreeRenderer::ToStreamInternal ( RenderTree & root,
std::ostream & ss )
overridevirtual

Implements duckdb::TreeRenderer.

111730 {
111731 while (root.width * config.node_render_width > config.maximum_render_width) {
111732 if (config.node_render_width - 2 < config.minimum_render_width) {
111733 break;
111734 }
111735 config.node_render_width -= 2;
111736 }
111737
111738 for (idx_t y = 0; y < root.height; y++) {
111739 // start by rendering the top layer
111740 RenderTopLayer(root, ss, y);
111741 // now we render the content of the boxes
111742 RenderBoxContent(root, ss, y);
111743 // render the bottom layer of each of the boxes
111744 RenderBottomLayer(root, ss, y);
111745 }
111746}
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ EnableDetailed()

void duckdb::TextTreeRenderer::EnableDetailed ( )
inline
111335 {
111336 config.EnableDetailed();
111337 }

◆ EnableStandard()

void duckdb::TextTreeRenderer::EnableStandard ( )
inline
111338 {
111339 config.EnableStandard();
111340 }

◆ UsesRawKeyNames()

bool duckdb::TextTreeRenderer::UsesRawKeyNames ( )
inlineoverridevirtual

Reimplemented from duckdb::TreeRenderer.

111341 {
111342 return true;
111343 }

◆ ExtraInfoSeparator()

string duckdb::TextTreeRenderer::ExtraInfoSeparator ( )
private
111891 {
111892 return StringUtil::Repeat(string(config.HORIZONTAL), (config.node_render_width - 9));
111893}
static DUCKDB_API string Repeat(const string &str, const idx_t n)
Repeat a string multiple times.
Definition duckdb.cpp:109391

◆ RenderTopLayer()

void duckdb::TextTreeRenderer::RenderTopLayer ( RenderTree & root,
std::ostream & ss,
idx_t y )
private
111393 {
111394 for (idx_t x = 0; x < root.width; x++) {
111395 if (x * config.node_render_width >= config.maximum_render_width) {
111396 break;
111397 }
111398 if (root.HasNode(x, y)) {
111399 ss << config.LTCORNER;
111400 ss << StringUtil::Repeat(config.HORIZONTAL, config.node_render_width / 2 - 1);
111401 if (y == 0) {
111402 // top level node: no node above this one
111403 ss << config.HORIZONTAL;
111404 } else {
111405 // render connection to node above this one
111406 ss << config.DMIDDLE;
111407 }
111408 ss << StringUtil::Repeat(config.HORIZONTAL, config.node_render_width / 2 - 1);
111409 ss << config.RTCORNER;
111410 } else {
111411 bool has_adjacent_nodes = false;
111412 for (idx_t i = 0; x + i < root.width; i++) {
111413 has_adjacent_nodes = has_adjacent_nodes || root.HasNode(x + i, y);
111414 }
111415 if (!has_adjacent_nodes) {
111416 // There are no nodes to the right side of this position
111417 // no need to fill the empty space
111418 continue;
111419 }
111420 // there are nodes next to this, fill the space
111421 ss << StringUtil::Repeat(" ", config.node_render_width);
111422 }
111423 }
111424 ss << '\n';
111425}

◆ RenderBoxContent()

void duckdb::TextTreeRenderer::RenderBoxContent ( RenderTree & root,
std::ostream & ss,
idx_t y )
private
111562 {
111563 // we first need to figure out how high our boxes are going to be
111564 vector<vector<string>> extra_info;
111565 idx_t extra_height = 0;
111566 extra_info.resize(root.width);
111567 for (idx_t x = 0; x < root.width; x++) {
111568 auto node = root.GetNode(x, y);
111569 if (node) {
111570 SplitUpExtraInfo(node->extra_text, extra_info[x], config.max_extra_lines);
111571 if (extra_info[x].size() > extra_height) {
111572 extra_height = extra_info[x].size();
111573 }
111574 }
111575 }
111576 idx_t halfway_point = (extra_height + 1) / 2;
111577 // now we render the actual node
111578 for (idx_t render_y = 0; render_y <= extra_height; render_y++) {
111579 for (idx_t x = 0; x < root.width; x++) {
111580 if (x * config.node_render_width >= config.maximum_render_width) {
111581 break;
111582 }
111583 bool has_adjacent_nodes = false;
111584 for (idx_t i = 0; x + i < root.width; i++) {
111585 has_adjacent_nodes = has_adjacent_nodes || root.HasNode(x + i, y);
111586 }
111587 auto node = root.GetNode(x, y);
111588 if (!node) {
111589 if (render_y == halfway_point) {
111590 bool has_child_to_the_right = ShouldRenderWhitespace(root, x, y);
111591 if (root.HasNode(x, y + 1)) {
111592 // node right below this one
111593 ss << StringUtil::Repeat(config.HORIZONTAL, config.node_render_width / 2);
111594 if (has_child_to_the_right) {
111595 ss << config.TMIDDLE;
111596 // but we have another child to the right! keep rendering the line
111597 ss << StringUtil::Repeat(config.HORIZONTAL, config.node_render_width / 2);
111598 } else {
111599 ss << config.RTCORNER;
111600 if (has_adjacent_nodes) {
111601 // only a child below this one: fill the rest with spaces
111602 ss << StringUtil::Repeat(" ", config.node_render_width / 2);
111603 }
111604 }
111605 } else if (has_child_to_the_right) {
111606 // child to the right, but no child right below this one: render a full line
111607 ss << StringUtil::Repeat(config.HORIZONTAL, config.node_render_width);
111608 } else {
111609 if (has_adjacent_nodes) {
111610 // empty spot: render spaces
111611 ss << StringUtil::Repeat(" ", config.node_render_width);
111612 }
111613 }
111614 } else if (render_y >= halfway_point) {
111615 if (root.HasNode(x, y + 1)) {
111616 // we have a node below this empty spot: render a vertical line
111617 ss << StringUtil::Repeat(" ", config.node_render_width / 2);
111618 ss << config.VERTICAL;
111619 if (has_adjacent_nodes || ShouldRenderWhitespace(root, x, y)) {
111620 ss << StringUtil::Repeat(" ", config.node_render_width / 2);
111621 }
111622 } else {
111623 if (has_adjacent_nodes || ShouldRenderWhitespace(root, x, y)) {
111624 // empty spot: render spaces
111625 ss << StringUtil::Repeat(" ", config.node_render_width);
111626 }
111627 }
111628 } else {
111629 if (has_adjacent_nodes) {
111630 // empty spot: render spaces
111631 ss << StringUtil::Repeat(" ", config.node_render_width);
111632 }
111633 }
111634 } else {
111635 ss << config.VERTICAL;
111636 // figure out what to render
111637 string render_text;
111638 if (render_y == 0) {
111639 render_text = node->name;
111640 } else {
111641 if (render_y <= extra_info[x].size()) {
111642 render_text = extra_info[x][render_y - 1];
111643 }
111644 }
111645 if (render_y + 1 == extra_height && render_text.empty()) {
111646 auto entry = node->extra_text.find(RenderTreeNode::CARDINALITY);
111647 if (entry != node->extra_text.end()) {
111648 render_text = FormatNumber(entry->second) + " row" + (entry->second == "1" ? "" : "s");
111649 }
111650 }
111651 if (render_y == extra_height && render_text.empty()) {
111652 auto timing_entry = node->extra_text.find(RenderTreeNode::TIMING);
111653 if (timing_entry != node->extra_text.end()) {
111654 render_text = "(" + timing_entry->second + ")";
111655 } else if (node->extra_text.find(RenderTreeNode::CARDINALITY) == node->extra_text.end()) {
111656 // we only render estimated cardinality if there is no real cardinality
111657 auto entry = node->extra_text.find(RenderTreeNode::ESTIMATED_CARDINALITY);
111658 if (entry != node->extra_text.end()) {
111659 render_text =
111660 "~" + FormatNumber(entry->second) + " row" + (entry->second == "1" ? "" : "s");
111661 }
111662 }
111663 if (node->extra_text.find(RenderTreeNode::CARDINALITY) == node->extra_text.end()) {
111664 // we only render estimated cardinality if there is no real cardinality
111665 auto entry = node->extra_text.find(RenderTreeNode::ESTIMATED_CARDINALITY);
111666 if (entry != node->extra_text.end()) {
111667 render_text =
111668 "~" + FormatNumber(entry->second) + " row" + (entry->second == "1" ? "" : "s");
111669 }
111670 }
111671 }
111672 render_text = AdjustTextForRendering(render_text, config.node_render_width - 2);
111673 ss << render_text;
111674
111675 if (render_y == halfway_point && NodeHasMultipleChildren(*node)) {
111676 ss << config.LMIDDLE;
111677 } else {
111678 ss << config.VERTICAL;
111679 }
111680 }
111681 }
111682 ss << '\n';
111683 }
111684}
GOpaque< Size > size(const GMat &src)

◆ RenderBottomLayer()

void duckdb::TextTreeRenderer::RenderBottomLayer ( RenderTree & root,
std::ostream & ss,
idx_t y )
private
111453 {
111454 for (idx_t x = 0; x <= root.width; x++) {
111455 if (x * config.node_render_width >= config.maximum_render_width) {
111456 break;
111457 }
111458 bool has_adjacent_nodes = false;
111459 for (idx_t i = 0; x + i < root.width; i++) {
111460 has_adjacent_nodes = has_adjacent_nodes || root.HasNode(x + i, y);
111461 }
111462 auto node = root.GetNode(x, y);
111463 if (node) {
111464 ss << config.LDCORNER;
111465 ss << StringUtil::Repeat(config.HORIZONTAL, config.node_render_width / 2 - 1);
111466 if (root.HasNode(x, y + 1)) {
111467 // node below this one: connect to that one
111468 ss << config.TMIDDLE;
111469 } else {
111470 // no node below this one: end the box
111471 ss << config.HORIZONTAL;
111472 }
111473 ss << StringUtil::Repeat(config.HORIZONTAL, config.node_render_width / 2 - 1);
111474 ss << config.RDCORNER;
111475 } else if (root.HasNode(x, y + 1)) {
111476 ss << StringUtil::Repeat(" ", config.node_render_width / 2);
111477 ss << config.VERTICAL;
111478 if (has_adjacent_nodes || ShouldRenderWhitespace(root, x, y)) {
111479 ss << StringUtil::Repeat(" ", config.node_render_width / 2);
111480 }
111481 } else {
111482 if (has_adjacent_nodes || ShouldRenderWhitespace(root, x, y)) {
111483 ss << StringUtil::Repeat(" ", config.node_render_width);
111484 }
111485 }
111486 }
111487 ss << '\n';
111488}

◆ CanSplitOnThisChar()

bool duckdb::TextTreeRenderer::CanSplitOnThisChar ( char l)
private
111748 {
111749 return (l < '0' || (l > '9' && l < 'A') || (l > 'Z' && l < 'a')) && l != '_';
111750}

◆ IsPadding()

bool duckdb::TextTreeRenderer::IsPadding ( char l)
private
111752 {
111753 return l == ' ' || l == '\t' || l == '\n' || l == '\r';
111754}

◆ RemovePadding()

string duckdb::TextTreeRenderer::RemovePadding ( string l)
private
111756 {
111757 idx_t start = 0, end = l.size();
111758 while (start < l.size() && IsPadding(l[start])) {
111759 start++;
111760 }
111761 while (end > 0 && IsPadding(l[end - 1])) {
111762 end--;
111763 }
111764 return l.substr(start, end - start);
111765}

◆ SplitUpExtraInfo()

void duckdb::TextTreeRenderer::SplitUpExtraInfo ( const InsertionOrderPreservingMap< string > & extra_info,
vector< string > & result,
idx_t max_lines )
private
111809 {
111810 if (extra_info.empty()) {
111811 return;
111812 }
111813 for (auto &item : extra_info) {
111814 auto &text = item.second;
111815 if (!Utf8Proc::IsValid(text.c_str(), text.size())) {
111816 return;
111817 }
111818 }
111819 result.push_back(ExtraInfoSeparator());
111820
111821 bool requires_padding = false;
111822 bool was_inlined = false;
111823 for (auto &item : extra_info) {
111824 string str = RemovePadding(item.second);
111825 if (str.empty()) {
111826 continue;
111827 }
111828 bool is_inlined = false;
111829 if (!StringUtil::StartsWith(item.first, "__")) {
111830 // the name is not internal (i.e. not __text__) - so we display the name in addition to the entry
111831 const idx_t available_width = (config.node_render_width - 7);
111832 idx_t total_size = item.first.size() + str.size() + 2;
111833 bool is_multiline = StringUtil::Contains(str, "\n");
111834 if (!is_multiline && total_size < available_width) {
111835 // we can inline the full entry - no need for any separators unless the previous entry explicitly
111836 // requires it
111837 str = item.first + ": " + str;
111838 is_inlined = true;
111839 } else {
111840 str = item.first + ":\n" + str;
111841 }
111842 }
111843 if (is_inlined && was_inlined) {
111844 // we can skip the padding if we have multiple inlined entries in a row
111845 requires_padding = false;
111846 }
111847 if (requires_padding) {
111848 result.emplace_back();
111849 }
111850 // cardinality, timing and estimated cardinality are rendered separately
111851 // this is to allow alignment horizontally across nodes
111852 if (item.first == RenderTreeNode::CARDINALITY) {
111853 // cardinality - need to reserve space for cardinality AND timing
111854 result.emplace_back();
111855 if (extra_info.find(RenderTreeNode::TIMING) != extra_info.end()) {
111856 result.emplace_back();
111857 }
111858 continue;
111859 }
111860 if (item.first == RenderTreeNode::ESTIMATED_CARDINALITY) {
111861 // estimated cardinality - reserve space for estimate
111862 if (extra_info.find(RenderTreeNode::CARDINALITY) != extra_info.end()) {
111863 // if we have a true cardinality render that instead of the estimate
111864 result.pop_back();
111865 continue;
111866 }
111867 result.emplace_back();
111868 continue;
111869 }
111870 auto splits = StringUtil::Split(str, "\n");
111871 if (splits.size() > max_lines) {
111872 // truncate this entry
111873 vector<string> truncated_splits;
111874 for (idx_t i = 0; i < max_lines / 2; i++) {
111875 truncated_splits.push_back(std::move(splits[i]));
111876 }
111877 truncated_splits.push_back("...");
111878 for (idx_t i = splits.size() - max_lines / 2; i < splits.size(); i++) {
111879 truncated_splits.push_back(std::move(splits[i]));
111880 }
111881 splits = std::move(truncated_splits);
111882 }
111883 for (auto &split : splits) {
111884 SplitStringBuffer(split, result);
111885 }
111886 requires_padding = true;
111887 was_inlined = is_inlined;
111888 }
111889}
static DUCKDB_API bool Contains(const string &haystack, const string &needle)
Returns true if the needle string exists in the haystack.
Definition duckdb.cpp:109323
static DUCKDB_API vector< string > Split(const string &str, char delimiter)
Split the input string based on newline char.
Definition duckdb.cpp:109734
static DUCKDB_API bool StartsWith(string str, string prefix)
Returns true if the target string starts with the given prefix.
Definition duckdb.cpp:109377
static bool IsValid(const char *s, size_t len)
Returns whether or not the UTF8 string is valid.
Definition duckdb.cpp:507383

◆ SplitStringBuffer()

void duckdb::TextTreeRenderer::SplitStringBuffer ( const string & source,
vector< string > & result )
private
111767 {
111768 D_ASSERT(Utf8Proc::IsValid(source.c_str(), source.size()));
111769 const idx_t max_line_render_size = config.node_render_width - 2;
111770 // utf8 in prompt, get render width
111771 idx_t character_pos = 0;
111772 idx_t start_pos = 0;
111773 idx_t render_width = 0;
111774 idx_t last_possible_split = 0;
111775
111776 const idx_t size = source.size();
111777 const char *input = source.c_str();
111778
111779 while (character_pos < size) {
111780 size_t char_render_width = Utf8Proc::RenderWidth(input, size, character_pos);
111781 idx_t next_character_pos = Utf8Proc::NextGraphemeCluster(input, size, character_pos);
111782
111783 // Does the next character make us exceed the line length?
111784 if (render_width + char_render_width > max_line_render_size) {
111785 if (start_pos + 8 > last_possible_split) {
111786 // The last character we can split on is one of the first 8 characters of the line
111787 // to not create very small lines we instead split on the current character
111788 last_possible_split = character_pos;
111789 }
111790 result.push_back(source.substr(start_pos, last_possible_split - start_pos));
111791 render_width = character_pos - last_possible_split;
111792 start_pos = last_possible_split;
111793 character_pos = last_possible_split;
111794 }
111795 // check if we can split on this character
111796 if (CanSplitOnThisChar(source[character_pos])) {
111797 last_possible_split = character_pos;
111798 }
111799 character_pos = next_character_pos;
111800 render_width += char_render_width;
111801 }
111802 if (size > start_pos) {
111803 // append the remainder of the input
111804 result.push_back(source.substr(start_pos, size - start_pos));
111805 }
111806}
static size_t RenderWidth(const char *s, size_t len, size_t pos)
Returns the render width of a single character in a string.
Definition duckdb.cpp:507613
static size_t NextGraphemeCluster(const char *s, size_t len, size_t pos)
Returns the position (in bytes) of the next grapheme cluster.
Definition duckdb.cpp:507427

◆ FormatNumber()

string duckdb::TextTreeRenderer::FormatNumber ( const string & input)
private
111527 {
111528 if (config.decimal_separator == '\0' && config.thousand_separator == '\0') {
111529 // no thousand separator
111530 return input;
111531 }
111532 // first check how many digits there are (preceding any decimal point)
111533 idx_t character_count = 0;
111534 for (auto c : input) {
111535 if (!StringUtil::CharacterIsDigit(c)) {
111536 break;
111537 }
111538 character_count++;
111539 }
111540 // find the position of the first thousand separator
111541 idx_t separator_position = character_count % 3 == 0 ? 3 : character_count % 3;
111542 // now add the thousand separators
111543 string result;
111544 for (idx_t c = 0; c < character_count; c++) {
111545 if (c == separator_position && config.thousand_separator != '\0') {
111546 result += config.thousand_separator;
111547 separator_position += 3;
111548 }
111549 result += input[c];
111550 }
111551 // add any remaining characters
111552 for (idx_t c = character_count; c < input.size(); c++) {
111553 if (input[c] == '.' && config.decimal_separator != '\0') {
111554 result += config.decimal_separator;
111555 } else {
111556 result += input[c];
111557 }
111558 }
111559 return result;
111560}

The documentation for this class was generated from the following file: