mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-04 13:32:13 +00:00
Fixed issues executeTableFunctions in Context.cpp to fall back on TableFunction if not parameterized view & updated test - 40907 Parameterized views as table functions
This commit is contained in:
parent
e6672832b9
commit
f78f846503
@ -1133,19 +1133,22 @@ StoragePtr Context::executeTableFunction(const ASTPtr & table_expression)
|
||||
StoragePtr res = DatabaseCatalog::instance().getTable({getCurrentDatabase(), function->name}, getQueryContext());
|
||||
if (res.get()->isView() && res->as<StorageView>()->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);
|
||||
StoragePtr & res = table_function_results[key];
|
||||
if (!res)
|
||||
{
|
||||
TableFunctionPtr table_function_ptr = TableFunctionFactory::instance().get(table_expression, shared_from_this());
|
||||
TableFunctionPtr table_function_ptr;
|
||||
try
|
||||
{
|
||||
table_function_ptr = TableFunctionFactory::instance().get(table_expression, shared_from_this());
|
||||
}
|
||||
catch (Exception & e)
|
||||
{
|
||||
e.addMessage(" or incorrect parameterized view");
|
||||
throw;
|
||||
}
|
||||
if (getSettingsRef().use_structure_from_insertion_table_in_table_functions && table_function_ptr->needStructureHint())
|
||||
{
|
||||
const auto & insertion_table = getInsertionTable();
|
||||
@ -1172,7 +1175,6 @@ StoragePtr Context::executeTableFunction(const ASTPtr & table_expression)
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
throw Exception(ErrorCodes::LOGICAL_ERROR, "Unable to fetch function from query");
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ SELECT Price FROM v1(price=20);
|
||||
SELECT Price FROM v123(price=20); -- { serverError UNKNOWN_FUNCTION }
|
||||
|
||||
CREATE VIEW v10 AS SELECT * FROM Catalog WHERE Price=10;
|
||||
SELECT Price FROM v10(price=10); -- { serverError BAD_ARGUMENTS }
|
||||
SELECT Price FROM v10(price=10); -- { serverError UNKNOWN_FUNCTION }
|
||||
|
||||
|
||||
CREATE VIEW v2 AS SELECT * FROM Catalog WHERE Price={price:UInt64} AND Quantity={quantity:UInt64};
|
||||
|
Loading…
Reference in New Issue
Block a user