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

Method resolveTableFunction

src/Analyzer/Resolve/QueryAnalyzer.cpp:4374–4791  ·  view source on GitHub ↗

Resolve table function node in scope

Source from the content-addressed store, hash-verified

4372
4373/// Resolve table function node in scope
4374void QueryAnalyzer::resolveTableFunction(QueryTreeNodePtr & table_function_node,
4375 IdentifierResolveScope & scope,
4376 QueryExpressionsAliasVisitor & expressions_visitor,
4377 bool nested_table_function)
4378{
4379 auto & table_function_node_typed = table_function_node->as<TableFunctionNode &>();
4380
4381 if (!nested_table_function)
4382 expressions_visitor.visit(table_function_node_typed.getArgumentsNode());
4383
4384 const auto & table_function_name = table_function_node_typed.getTableFunctionName();
4385
4386 auto & scope_context = scope.context;
4387
4388 TableFunctionPtr table_function_ptr = TableFunctionFactory::instance().tryGet(table_function_name, scope_context);
4389 if (!table_function_ptr)
4390 {
4391 String database_name = scope_context->getCurrentDatabase();
4392 String table_name;
4393
4394 auto function_ast = table_function_node->toAST();
4395 Identifier table_identifier{table_function_name};
4396 if (table_identifier.getPartsSize() == 1)
4397 {
4398 table_name = table_identifier[0];
4399 }
4400 else if (table_identifier.getPartsSize() == 2)
4401 {
4402 database_name = table_identifier[0];
4403 table_name = table_identifier[1];
4404 }
4405
4406 /// Collect parameterized view arguments
4407 NameToNameMap view_params;
4408 for (const auto & argument : table_function_node_typed.getArguments())
4409 {
4410 if (auto * arg_func = argument->as<FunctionNode>())
4411 {
4412 if (arg_func->getFunctionName() != "equals")
4413 continue;
4414
4415 auto nodes = arg_func->getArguments().getNodes();
4416 if (nodes.size() != 2)
4417 continue;
4418
4419 if (auto * identifier_node = nodes[0]->as<IdentifierNode>())
4420 {
4421 resolveExpressionNode(nodes[1], scope, /* allow_lambda_expression */false, /* allow_table_function */false);
4422 if (auto * constant = nodes[1]->as<ConstantNode>())
4423 {
4424 /// Serialize the constant value using datatype specific
4425 /// interfaces to match the deserialization in ReplaceQueryParametersVistor.
4426 WriteBufferFromOwnString buf;
4427 const auto & value = constant->getValue();
4428 auto real_type = constant->getResultType();
4429 auto temporary_column = real_type->createColumn();
4430 temporary_column->insert(value);
4431 real_type->getDefaultSerialization()->serializeTextEscaped(*temporary_column, 0, buf, {});

Callers

nothing calls this directly

Calls 15

resolveTableFunctionFunction · 0.85
getCurrentDatabaseMethod · 0.80
getNodesMethod · 0.80
isTableFunctionNameMethod · 0.80
getOrdinaryMethod · 0.80
getProjectionMethod · 0.80
getMatcherTypeMethod · 0.80

Tested by

no test coverage detected