Resolve function node in scope. * During function node resolve, function node can be replaced with another expression (if it match lambda or sql user defined function), * with constant (if it allow constant folding), or with expression list. It is caller responsibility to handle such cases appropriately. * * Steps: * 1. Resolve function parameters. Validate that each function parameter m
| 312 | * 9. If function is suitable for constant folding, try to perform constant folding for function node. |
| 313 | */ |
| 314 | ProjectionNames QueryAnalyzer::resolveFunction(QueryTreeNodePtr & node, IdentifierResolveScope & scope, bool allow_niladic_functions) |
| 315 | { |
| 316 | FunctionNodePtr function_node_ptr = std::static_pointer_cast<FunctionNode>(node); |
| 317 | auto function_name = function_node_ptr->getFunctionName(); |
| 318 | |
| 319 | /// Resolve function parameters |
| 320 | |
| 321 | auto parameters_projection_names = resolveExpressionNodeList( |
| 322 | function_node_ptr->getParametersNode(), |
| 323 | scope, |
| 324 | false /*allow_lambda_expression*/, |
| 325 | false /*allow_table_expression*/, |
| 326 | allow_niladic_functions); |
| 327 | |
| 328 | /// Convert function parameters into constant parameters array |
| 329 | |
| 330 | Array parameters; |
| 331 | |
| 332 | auto & parameters_nodes = function_node_ptr->getParameters().getNodes(); |
| 333 | parameters.reserve(parameters_nodes.size()); |
| 334 | |
| 335 | for (auto & parameter_node : parameters_nodes) |
| 336 | { |
| 337 | const auto * constant_node = parameter_node->as<ConstantNode>(); |
| 338 | if (!constant_node) |
| 339 | throw Exception(ErrorCodes::BAD_ARGUMENTS, |
| 340 | "Parameter for function '{}' expected to have constant value. Actual: {}. In scope {}", |
| 341 | function_name, |
| 342 | parameter_node->formatASTForErrorMessage(), |
| 343 | scope.scope_node->formatASTForErrorMessage()); |
| 344 | |
| 345 | parameters.push_back(constant_node->getValue()); |
| 346 | } |
| 347 | |
| 348 | //// If function node is not window function try to lookup function node name as lambda identifier. |
| 349 | QueryTreeNodePtr lambda_expression_untyped; |
| 350 | if (!function_node_ptr->isWindowFunction()) |
| 351 | { |
| 352 | auto function_lookup_result = tryResolveIdentifier({Identifier{function_name}, IdentifierLookupContext::FUNCTION}, scope, { .allow_to_resolve_niladic_functions = allow_niladic_functions }); |
| 353 | lambda_expression_untyped = function_lookup_result.resolved_identifier; |
| 354 | } |
| 355 | |
| 356 | bool is_special_function_in = false; |
| 357 | bool is_special_function_dict_get = false; |
| 358 | bool is_special_function_join_get = false; |
| 359 | bool is_special_function_exists = false; |
| 360 | bool is_special_function_if = false; |
| 361 | bool is_special_function_multi_if = false; |
| 362 | |
| 363 | if (!lambda_expression_untyped) |
| 364 | { |
| 365 | is_special_function_in = isNameOfInFunction(function_name); |
| 366 | is_special_function_dict_get = functionIsDictGet(function_name); |
| 367 | is_special_function_join_get = functionIsJoinGet(function_name); |
| 368 | is_special_function_exists = function_name == "exists"; |
| 369 | is_special_function_if = function_name == "if"; |
| 370 | is_special_function_multi_if = function_name == "multiIf"; |
| 371 |
nothing calls this directly
no test coverage detected