MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / executeTableFunction

Method executeTableFunction

src/Interpreters/Context.cpp:2836–3053  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2834}
2835
2836StoragePtr Context::executeTableFunction(const ASTPtr & table_expression, const ASTSelectQuery * select_query_hint)
2837{
2838 ASTFunction * function = assert_cast<ASTFunction *>(table_expression.get());
2839 String database_name = getCurrentDatabase();
2840 String table_name = function->name;
2841
2842 if (function->isCompoundName())
2843 {
2844 std::vector<std::string> parts;
2845 splitInto<'.'>(parts, function->name);
2846
2847 if (parts.size() == 2)
2848 {
2849 database_name = std::move(parts[0]);
2850 table_name = std::move(parts[1]);
2851 }
2852 }
2853
2854 StoragePtr table = DatabaseCatalog::instance().tryGetTable({database_name, table_name}, getQueryContext());
2855 if (table)
2856 {
2857 if (table.get()->isView() && table->as<StorageView>() && table->as<StorageView>()->isParameterizedView())
2858 {
2859 auto view_metadata = table->getInMemoryMetadataPtr(getQueryContext(), false);
2860 auto query = view_metadata->getSelectQuery().inner_query->clone();
2861 NameToNameMap parameterized_view_values = analyzeFunctionParamValues(table_expression, getQueryContext());
2862 StorageView::replaceQueryParametersIfParameterizedView(query, parameterized_view_values);
2863
2864 ASTCreateQuery create;
2865 create.set(create.select, query);
2866 auto sample_block = InterpreterSelectWithUnionQuery::getSampleBlock(query, getQueryContext());
2867 auto res = std::make_shared<StorageView>(StorageID(database_name, table_name),
2868 create,
2869 ColumnsDescription(sample_block->getNamesAndTypesList()),
2870 /* comment */ "",
2871 /* is_parameterized_view */ true);
2872 res->startup();
2873 function->setPreferSubqueryToFunctionFormatting(true);
2874 return res;
2875 }
2876 }
2877 auto hash = table_expression->getTreeHash(/*ignore_aliases=*/ true);
2878 auto key = toString(hash);
2879
2880 StoragePtr res;
2881 {
2882 std::lock_guard lock(table_function_results_mutex);
2883 res = table_function_results[key];
2884 }
2885
2886 if (!res)
2887 {
2888 TableFunctionPtr table_function_ptr;
2889 try
2890 {
2891 table_function_ptr = TableFunctionFactory::instance().get(table_expression, shared_from_this());
2892 }
2893 catch (Exception & e)

Callers 7

resolveTableFunctionMethod · 0.80
getLeftTableStorageMethod · 0.80
executeQueryImplFunction · 0.80
executeImplMethod · 0.80
interpretSubqueryFunction · 0.80
TESTFunction · 0.80

Calls 15

applyVisitorFunction · 0.85
FieldVisitorHashClass · 0.85
isCompoundNameMethod · 0.80
getOrdinaryMethod · 0.80
getSampleBlockFunction · 0.70
StorageIDClass · 0.70
ColumnsDescriptionClass · 0.70
toStringFunction · 0.70
ExceptionClass · 0.70

Tested by 1

TESTFunction · 0.64