From 4343db4dc3ea26dd32b246cdc29765b2c495ca3b Mon Sep 17 00:00:00 2001 From: Dmitry Novik Date: Thu, 14 Nov 2024 15:22:17 +0100 Subject: [PATCH] Improve dump() methods output readability --- src/Analyzer/Resolve/ExpressionsStack.h | 4 +- .../Resolve/IdentifierResolveScope.cpp | 81 ++++++++++--------- src/Analyzer/Resolve/IdentifierResolveScope.h | 3 - src/Analyzer/Resolve/QueryAnalyzer.cpp | 4 - src/Analyzer/Resolve/TableExpressionData.h | 15 ++-- 5 files changed, 52 insertions(+), 55 deletions(-) diff --git a/src/Analyzer/Resolve/ExpressionsStack.h b/src/Analyzer/Resolve/ExpressionsStack.h index 82a27aa8b83..3391c9d3e3f 100644 --- a/src/Analyzer/Resolve/ExpressionsStack.h +++ b/src/Analyzer/Resolve/ExpressionsStack.h @@ -92,11 +92,11 @@ public: void dump(WriteBuffer & buffer) const { - buffer << expressions.size() << '\n'; + buffer << "Expression resolve process stack size: " << expressions.size() << '\n'; for (const auto & expression : expressions) { - buffer << "Expression "; + buffer << " Expression "; buffer << expression->formatASTForErrorMessage(); const auto & alias = expression->getAlias(); diff --git a/src/Analyzer/Resolve/IdentifierResolveScope.cpp b/src/Analyzer/Resolve/IdentifierResolveScope.cpp index cd05ce469e3..ba77cfed043 100644 --- a/src/Analyzer/Resolve/IdentifierResolveScope.cpp +++ b/src/Analyzer/Resolve/IdentifierResolveScope.cpp @@ -114,6 +114,21 @@ void IdentifierResolveScope::popExpressionNode() expressions_in_resolve_process_stack.pop(); } +namespace +{ + +void dump_mapping(WriteBuffer & buffer, const String & mapping_name, const std::unordered_map & mapping) +{ + if (mapping.empty()) + return; + + buffer << mapping_name << " table size: " << mapping.size() << '\n'; + for (const auto & [alias_name, node] : mapping) + buffer << " { '" << alias_name << "' : " << node->formatASTForErrorMessage() << " }\n"; +} + +} + /// Dump identifier resolve scope [[maybe_unused]] void IdentifierResolveScope::dump(WriteBuffer & buffer) const { @@ -137,55 +152,45 @@ void IdentifierResolveScope::popExpressionNode() buffer << "Identifier lookup to resolve state " << identifier_in_lookup_process.size() << '\n'; for (const auto & [identifier, state] : identifier_in_lookup_process) { - buffer << "Identifier " << identifier.dump() << " count "; + buffer << " { '" << identifier.dump() << "' : "; buffer << state.count; - buffer << '\n'; + buffer << " }\n"; } - buffer << "Expression argument name to node " << expression_argument_name_to_node.size() << '\n'; - for (const auto & [alias_name, node] : expression_argument_name_to_node) - buffer << "Alias name " << alias_name << " node " << node->formatASTForErrorMessage() << '\n'; + dump_mapping(buffer, "Expression argument name to node", expression_argument_name_to_node); + dump_mapping(buffer, "Alias name to expression node", aliases.alias_name_to_expression_node); + dump_mapping(buffer, "Alias name to function node", aliases.alias_name_to_lambda_node); + dump_mapping(buffer, "Alias name to table expression node", aliases.alias_name_to_table_expression_node); + dump_mapping(buffer, "CTE name to query node", cte_name_to_query_node); + dump_mapping(buffer, "WINDOW name to window node", window_name_to_window_node); - buffer << "Alias name to expression node table size " << aliases.alias_name_to_expression_node.size() << '\n'; - for (const auto & [alias_name, node] : aliases.alias_name_to_expression_node) - buffer << "Alias name " << alias_name << " expression node " << node->dumpTree() << '\n'; + if (!aliases.nodes_with_duplicated_aliases.empty()) + { + buffer << "Nodes with duplicated aliases size " << aliases.nodes_with_duplicated_aliases.size() << '\n'; + for (const auto & node : aliases.nodes_with_duplicated_aliases) + buffer << " { " << node->formatASTForErrorMessage() << " }\n"; + } - buffer << "Alias name to function node table size " << aliases.alias_name_to_lambda_node.size() << '\n'; - for (const auto & [alias_name, node] : aliases.alias_name_to_lambda_node) - buffer << "Alias name " << alias_name << " lambda node " << node->formatASTForErrorMessage() << '\n'; - - buffer << "Alias name to table expression node table size " << aliases.alias_name_to_table_expression_node.size() << '\n'; - for (const auto & [alias_name, node] : aliases.alias_name_to_table_expression_node) - buffer << "Alias name " << alias_name << " node " << node->formatASTForErrorMessage() << '\n'; - - buffer << "CTE name to query node table size " << cte_name_to_query_node.size() << '\n'; - for (const auto & [cte_name, node] : cte_name_to_query_node) - buffer << "CTE name " << cte_name << " node " << node->formatASTForErrorMessage() << '\n'; - - buffer << "WINDOW name to window node table size " << window_name_to_window_node.size() << '\n'; - for (const auto & [window_name, node] : window_name_to_window_node) - buffer << "CTE name " << window_name << " node " << node->formatASTForErrorMessage() << '\n'; - - buffer << "Nodes with duplicated aliases size " << aliases.nodes_with_duplicated_aliases.size() << '\n'; - for (const auto & node : aliases.nodes_with_duplicated_aliases) - buffer << "Alias name " << node->getAlias() << " node " << node->formatASTForErrorMessage() << '\n'; - - buffer << "Expression resolve process stack " << '\n'; expressions_in_resolve_process_stack.dump(buffer); - buffer << "Table expressions in resolve process size " << table_expressions_in_resolve_process.size() << '\n'; - for (const auto & node : table_expressions_in_resolve_process) - buffer << "Table expression " << node->formatASTForErrorMessage() << '\n'; + if (!table_expressions_in_resolve_process.empty()) + { + buffer << "Table expressions in resolve process size " << table_expressions_in_resolve_process.size() << '\n'; + for (const auto & node : table_expressions_in_resolve_process) + buffer << " { " << node->formatASTForErrorMessage() << " }\n"; + } - buffer << "Non cached identifier lookups during expression resolve " << non_cached_identifier_lookups_during_expression_resolve.size() << '\n'; - for (const auto & identifier_lookup : non_cached_identifier_lookups_during_expression_resolve) - buffer << "Identifier lookup " << identifier_lookup.dump() << '\n'; + if (!non_cached_identifier_lookups_during_expression_resolve.empty()) + { + buffer << "Non cached identifier lookups during expression resolve " << non_cached_identifier_lookups_during_expression_resolve.size() << '\n'; + for (const auto & identifier_lookup : non_cached_identifier_lookups_during_expression_resolve) + buffer << "Identifier lookup " << identifier_lookup.dump() << " }\n"; + } - buffer << "Table expression node to data " << table_expression_node_to_data.size() << '\n'; + buffer << "Table expression node to data: " << table_expression_node_to_data.size() << '\n'; for (const auto & [table_expression_node, table_expression_data] : table_expression_node_to_data) - buffer << "Table expression node " << table_expression_node->formatASTForErrorMessage() << " data " << table_expression_data.dump() << '\n'; + buffer << " { " << table_expression_node->formatASTForErrorMessage() << " data:\n " << table_expression_data.dump() << " }\n"; - buffer << "Use identifier lookup to result cache " << use_identifier_lookup_to_result_cache << '\n'; buffer << "Subquery depth " << subquery_depth << '\n'; } diff --git a/src/Analyzer/Resolve/IdentifierResolveScope.h b/src/Analyzer/Resolve/IdentifierResolveScope.h index fecd98e396e..89772553270 100644 --- a/src/Analyzer/Resolve/IdentifierResolveScope.h +++ b/src/Analyzer/Resolve/IdentifierResolveScope.h @@ -180,9 +180,6 @@ struct IdentifierResolveScope */ QueryTreeNodePtrWithHashMap join_columns_with_changed_types; - /// Use identifier lookup to result cache - bool use_identifier_lookup_to_result_cache = true; - /// Apply nullability to aggregation keys bool group_by_use_nulls = false; /// Join retutns NULLs instead of default values diff --git a/src/Analyzer/Resolve/QueryAnalyzer.cpp b/src/Analyzer/Resolve/QueryAnalyzer.cpp index 843a3dedd6a..d54a29aff20 100644 --- a/src/Analyzer/Resolve/QueryAnalyzer.cpp +++ b/src/Analyzer/Resolve/QueryAnalyzer.cpp @@ -5458,7 +5458,6 @@ void QueryAnalyzer::resolveQuery(const QueryTreeNodePtr & query_node, Identifier * In first join expression ON t1.id = t2.id t1.id is resolved into test_table.id column. * In second join expression ON t1.id = t3.id t1.id must be resolved into test_table.id column after first JOIN. */ - scope.use_identifier_lookup_to_result_cache = false; if (query_node_typed.getJoinTree()) { @@ -5471,9 +5470,6 @@ void QueryAnalyzer::resolveQuery(const QueryTreeNodePtr & query_node, Identifier resolveQueryJoinTreeNode(query_node_typed.getJoinTree(), scope, visitor); } - if (!scope.group_by_use_nulls) - scope.use_identifier_lookup_to_result_cache = true; - /// Resolve query node sections. NamesAndTypes projection_columns; diff --git a/src/Analyzer/Resolve/TableExpressionData.h b/src/Analyzer/Resolve/TableExpressionData.h index 6770672d0c2..bbedad69cfe 100644 --- a/src/Analyzer/Resolve/TableExpressionData.h +++ b/src/Analyzer/Resolve/TableExpressionData.h @@ -54,22 +54,21 @@ struct AnalysisTableExpressionData [[maybe_unused]] void dump(WriteBuffer & buffer) const { - buffer << "Table expression name " << table_expression_name; + buffer << " Table expression name '" << table_expression_name << "'"; if (!table_expression_description.empty()) - buffer << " table expression description " << table_expression_description; + buffer << ", description '" << table_expression_description << "'\n"; if (!database_name.empty()) - buffer << " database name " << database_name; + buffer << " database name '" << database_name << "'\n"; if (!table_name.empty()) - buffer << " table name " << table_name; - - buffer << " should qualify columns " << should_qualify_columns; - buffer << " columns size " << column_name_to_column_node.size() << '\n'; + buffer << " table name '" << table_name << "'\n"; + buffer << " Should qualify columns " << should_qualify_columns << "\n"; + buffer << " Columns size " << column_name_to_column_node.size() << "\n"; for (const auto & [column_name, column_node] : column_name_to_column_node) - buffer << "Column name " << column_name << " column node " << column_node->dumpTree() << '\n'; + buffer << " { " << column_name << " : " << column_node->dumpTree() << " }\n"; } [[maybe_unused]] String dump() const