mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-04 21:42:39 +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,45 +1133,47 @@ StoragePtr Context::executeTableFunction(const ASTPtr & table_expression)
|
|||||||
StoragePtr res = DatabaseCatalog::instance().getTable({getCurrentDatabase(), function->name}, getQueryContext());
|
StoragePtr res = DatabaseCatalog::instance().getTable({getCurrentDatabase(), function->name}, getQueryContext());
|
||||||
if (res.get()->isView() && res->as<StorageView>()->isParameterizedView())
|
if (res.get()->isView() && res->as<StorageView>()->isParameterizedView())
|
||||||
return res;
|
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)
|
||||||
{
|
{
|
||||||
auto hash = table_expression->getTreeHash();
|
TableFunctionPtr table_function_ptr;
|
||||||
String key = toString(hash.first) + '_' + toString(hash.second);
|
try
|
||||||
StoragePtr & res = table_function_results[key];
|
|
||||||
if (!res)
|
|
||||||
{
|
{
|
||||||
TableFunctionPtr table_function_ptr = TableFunctionFactory::instance().get(table_expression, shared_from_this());
|
table_function_ptr = TableFunctionFactory::instance().get(table_expression, shared_from_this());
|
||||||
if (getSettingsRef().use_structure_from_insertion_table_in_table_functions && table_function_ptr->needStructureHint())
|
}
|
||||||
|
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();
|
||||||
|
if (!insertion_table.empty())
|
||||||
{
|
{
|
||||||
const auto & insertion_table = getInsertionTable();
|
const auto & structure_hint
|
||||||
if (!insertion_table.empty())
|
= DatabaseCatalog::instance().getTable(insertion_table, shared_from_this())->getInMemoryMetadataPtr()->columns;
|
||||||
{
|
table_function_ptr->setStructureHint(structure_hint);
|
||||||
const auto & structure_hint
|
|
||||||
= DatabaseCatalog::instance().getTable(insertion_table, shared_from_this())->getInMemoryMetadataPtr()->columns;
|
|
||||||
table_function_ptr->setStructureHint(structure_hint);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
res = table_function_ptr->execute(table_expression, shared_from_this(), table_function_ptr->getName());
|
|
||||||
|
|
||||||
/// Since ITableFunction::parseArguments() may change table_expression, i.e.:
|
|
||||||
///
|
|
||||||
/// remote('127.1', system.one) -> remote('127.1', 'system.one'),
|
|
||||||
///
|
|
||||||
auto new_hash = table_expression->getTreeHash();
|
|
||||||
if (hash != new_hash)
|
|
||||||
{
|
|
||||||
key = toString(new_hash.first) + '_' + toString(new_hash.second);
|
|
||||||
table_function_results[key] = res;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res;
|
|
||||||
|
res = table_function_ptr->execute(table_expression, shared_from_this(), table_function_ptr->getName());
|
||||||
|
|
||||||
|
/// Since ITableFunction::parseArguments() may change table_expression, i.e.:
|
||||||
|
///
|
||||||
|
/// remote('127.1', system.one) -> remote('127.1', 'system.one'),
|
||||||
|
///
|
||||||
|
auto new_hash = table_expression->getTreeHash();
|
||||||
|
if (hash != new_hash)
|
||||||
|
{
|
||||||
|
key = toString(new_hash.first) + '_' + toString(new_hash.second);
|
||||||
|
table_function_results[key] = res;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
throw Exception(ErrorCodes::LOGICAL_ERROR, "Unable to fetch function from query");
|
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 }
|
SELECT Price FROM v123(price=20); -- { serverError UNKNOWN_FUNCTION }
|
||||||
|
|
||||||
CREATE VIEW v10 AS SELECT * FROM Catalog WHERE Price=10;
|
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};
|
CREATE VIEW v2 AS SELECT * FROM Catalog WHERE Price={price:UInt64} AND Quantity={quantity:UInt64};
|
||||||
|
Loading…
Reference in New Issue
Block a user