Skip to content

Commit dc06285

Browse files
Fixing 01086_odbc_roundtrip with analyzer.
1 parent a102481 commit dc06285

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/Storages/transformQueryForExternalDatabaseAnalyzer.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include <Parsers/ASTSubquery.h>
2+
#include <Parsers/queryToString.h>
13
#include <Storages/transformQueryForExternalDatabaseAnalyzer.h>
24

35
#include <Parsers/ASTSelectWithUnionQuery.h>
@@ -61,11 +63,15 @@ ASTPtr getASTForExternalDatabaseFromQueryTree(const QueryTreeNodePtr & query_tre
6163
visitor.visit(new_tree);
6264
const auto * query_node = new_tree->as<QueryNode>();
6365

64-
const auto & query_node_ast = query_node->toAST({ .add_cast_for_constants = false, .fully_qualified_identifiers = false });
66+
auto query_node_ast = query_node->toAST({ .add_cast_for_constants = false, .fully_qualified_identifiers = false });
67+
const IAST * ast = query_node_ast.get();
6568

66-
const auto * union_ast = query_node_ast->as<ASTSelectWithUnionQuery>();
69+
if (const auto * ast_subquery = ast->as<ASTSubquery>())
70+
ast = ast_subquery->children.at(0).get();
71+
72+
const auto * union_ast = ast->as<ASTSelectWithUnionQuery>();
6773
if (!union_ast)
68-
throw Exception(ErrorCodes::UNSUPPORTED_METHOD, "QueryNode AST is not a ASTSelectWithUnionQuery");
74+
throw Exception(ErrorCodes::UNSUPPORTED_METHOD, "QueryNode AST ({}) is not a ASTSelectWithUnionQuery", query_node_ast->getID());
6975

7076
if (union_ast->list_of_selects->children.size() != 1)
7177
throw Exception(ErrorCodes::UNSUPPORTED_METHOD, "QueryNode AST is not a single ASTSelectQuery, got {}", union_ast->list_of_selects->children.size());

0 commit comments

Comments
 (0)