ClickHouse/src/TableFunctions/ITableFunction.cpp

35 lines
1.2 KiB
C++
Raw Normal View History

#include <TableFunctions/ITableFunction.h>
#include <Interpreters/Context.h>
#include <Storages/StorageFactory.h>
#include <Storages/StorageTableFunction.h>
#include <Access/AccessFlags.h>
#include <Common/ProfileEvents.h>
namespace ProfileEvents
{
extern const Event TableFunctionExecute;
}
namespace DB
{
2020-09-01 14:41:49 +00:00
StoragePtr ITableFunction::execute(const ASTPtr & ast_function, const Context & context, const std::string & table_name, ColumnsDescription cached_columns) const
{
ProfileEvents::increment(ProfileEvents::TableFunctionExecute);
context.checkAccess(AccessType::CREATE_TEMPORARY_TABLE | StorageFactory::instance().getSourceAccessType(getStorageTypeName()));
2020-09-01 14:41:49 +00:00
bool no_conversion_required = hasStaticStructure() && cached_columns == getActualTableStructure(context);
if (cached_columns.empty() || no_conversion_required)
return executeImpl(ast_function, context, table_name);
auto get_storage = [=, tf = shared_from_this()]() -> StoragePtr
{
return tf->executeImpl(ast_function, context, table_name);
};
2020-09-01 14:41:49 +00:00
return std::make_shared<StorageTableFunctionProxy>(StorageID(getDatabaseName(), table_name), std::move(get_storage), std::move(cached_columns));
}
}