From 9664dc36b69f37b0ae606ff2ae5117c298428205 Mon Sep 17 00:00:00 2001 From: Dmitry Novik Date: Wed, 20 Nov 2024 21:05:08 +0100 Subject: [PATCH] Fix enable_global_with_statement setting support --- src/Analyzer/Resolve/QueryAnalyzer.cpp | 30 +++++++++++++++----------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/Analyzer/Resolve/QueryAnalyzer.cpp b/src/Analyzer/Resolve/QueryAnalyzer.cpp index 6f6c64f1197..3164a9aa38f 100644 --- a/src/Analyzer/Resolve/QueryAnalyzer.cpp +++ b/src/Analyzer/Resolve/QueryAnalyzer.cpp @@ -1323,17 +1323,26 @@ IdentifierResolveResult QueryAnalyzer::tryResolveIdentifierInParentScopes(const * * Example: SELECT arrayMap(x -> test_table.* EXCEPT value, [1,2,3]) FROM test_table; */ - if (identifier_lookup.isTableExpressionLookup() && initial_scope_is_query) + if (initial_scope_is_query) { - new_resolve_context.allow_to_check_join_tree = false; + if (identifier_lookup.isTableExpressionLookup()) + { + new_resolve_context.allow_to_check_join_tree = false; - /** From parent scopes we can resolve table identifiers only as CTE. - * Example: SELECT (SELECT 1 FROM a) FROM test_table AS a; - * - * During child scope table identifier resolve a, table node test_table with alias a from parent scope - * is invalid. - */ - new_resolve_context.allow_to_check_aliases = false; + /** From parent scopes we can resolve table identifiers only as CTE. + * Example: SELECT (SELECT 1 FROM a) FROM test_table AS a; + * + * During child scope table identifier resolve a, table node test_table with alias a from parent scope + * is invalid. + */ + new_resolve_context.allow_to_check_aliases = false; + } + + if (!scope.context->getSettingsRef()[Setting::enable_global_with_statement]) + { + new_resolve_context.allow_to_check_aliases = false; + new_resolve_context.allow_to_check_cte = false; + } } new_resolve_context.allow_to_check_database_catalog = false; @@ -1348,9 +1357,6 @@ IdentifierResolveResult QueryAnalyzer::tryResolveIdentifierInParentScopes(const LOG_DEBUG(&Poco::Logger::get("resolveInParentScope"), "Resolved indetifier '{}':\n{}", identifier_lookup.dump(), resolved_identifier->dumpTree()); - if (!scope.context->getSettingsRef()[Setting::enable_global_with_statement] && (resolve_result.isResolvedFromAliases() || resolve_result.isResolvedFromCTEs())) - return {}; - /** From parent scopes we can resolve table identifiers only as CTE. * Example: SELECT (SELECT 1 FROM a) FROM test_table AS a; *