| 53 | } |
| 54 | |
| 55 | StoragePtr ITableFunction::execute(const ASTPtr & ast_function, ContextPtr context, const std::string & table_name, |
| 56 | ColumnsDescription cached_columns, bool use_global_context, bool is_insert_query) const |
| 57 | { |
| 58 | ProfileEvents::increment(ProfileEvents::TableFunctionExecute); |
| 59 | |
| 60 | checkSourceAccess(context, is_insert_query); |
| 61 | |
| 62 | auto table_function_properties = TableFunctionFactory::instance().tryGetProperties(getName()); |
| 63 | if (is_insert_query || !(table_function_properties && table_function_properties->allow_readonly)) |
| 64 | context->checkAccess(AccessType::CREATE_TEMPORARY_TABLE); |
| 65 | |
| 66 | auto context_to_use = use_global_context ? context->getGlobalContext() : context; |
| 67 | |
| 68 | if (cached_columns.empty()) |
| 69 | return executeImpl(ast_function, context, table_name, std::move(cached_columns), is_insert_query); |
| 70 | |
| 71 | if (hasStaticStructure() && cached_columns == getActualTableStructure(context, is_insert_query)) |
| 72 | return executeImpl(ast_function, context_to_use, table_name, std::move(cached_columns), is_insert_query); |
| 73 | |
| 74 | auto this_table_function = shared_from_this(); |
| 75 | auto get_storage = [=]() -> StoragePtr |
| 76 | { |
| 77 | return this_table_function->executeImpl(ast_function, context_to_use, table_name, cached_columns, is_insert_query); |
| 78 | }; |
| 79 | |
| 80 | /// It will request actual table structure and create underlying storage lazily |
| 81 | return std::make_shared<StorageTableFunctionProxy>(StorageID(getDatabaseName(), table_name), std::move(get_storage), |
| 82 | std::move(cached_columns), needStructureConversion()); |
| 83 | } |
| 84 | |
| 85 | String ITableFunction::getFunctionURINormalized() const |
| 86 | { |
no test coverage detected