From 618f63d6c7ec4d92a742bd974c9a611a2fccce2f Mon Sep 17 00:00:00 2001 From: Smita Kulkarni Date: Wed, 28 Sep 2022 10:00:12 +0200 Subject: [PATCH] Updated executeTableFunctions in Context.cpp to check for table/view & fallback to function to fix test fails - 40907 Parameterized views as table functions --- src/Interpreters/Context.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/Interpreters/Context.cpp b/src/Interpreters/Context.cpp index 45a73e09909..136d2b1283f 100644 --- a/src/Interpreters/Context.cpp +++ b/src/Interpreters/Context.cpp @@ -1129,7 +1129,17 @@ StoragePtr Context::executeTableFunction(const ASTPtr & table_expression) { if (const auto * function = table_expression->as()) { - if (TableFunctionFactory::instance().isTableFunctionName(function->name)) + if (DatabaseCatalog::instance().isTableExist({getCurrentDatabase(), function->name}, getQueryContext())) + { + StoragePtr res = DatabaseCatalog::instance().getTable({getCurrentDatabase(), function->name}, getQueryContext()); + if (res.get()->isView() && res->as()->isParameterizedView()) + return res; + else + { + throw Exception(ErrorCodes::BAD_ARGUMENTS, "Not a parameterized view `{}`", function->name); + } + } + else { auto hash = table_expression->getTreeHash(); String key = toString(hash.first) + '_' + toString(hash.second); @@ -1163,17 +1173,6 @@ StoragePtr Context::executeTableFunction(const ASTPtr & table_expression) } return res; } - else if (DatabaseCatalog::instance().isTableExist({getCurrentDatabase(), function->name}, getQueryContext())) - { - StoragePtr res = DatabaseCatalog::instance().getTable({getCurrentDatabase(), function->name}, getQueryContext()); - if (res.get()->isView() && res->as()->isParameterizedView()) - return res; - else - { - throw Exception(ErrorCodes::BAD_ARGUMENTS, "Not a parameterized view `{}`", function->name); - } - } - throw Exception(ErrorCodes::UNKNOWN_FUNCTION, "Unknown table function or incorrect parameterized view: `{}`", function->name); } throw Exception(ErrorCodes::LOGICAL_ERROR, "Unable to fetch function from query"); }