converts tuple to array with proper type handling
| 229 | |
| 230 | /// converts tuple to array with proper type handling |
| 231 | QueryTreeNodePtr QueryAnalyzer::convertTupleToArray( |
| 232 | const QueryTreeNodes & tuple_args, |
| 233 | const QueryTreeNodePtr & in_first_argument, |
| 234 | IdentifierResolveScope & scope) |
| 235 | { |
| 236 | auto array_function_node = std::make_shared<FunctionNode>("array"); |
| 237 | auto array_arguments_list = std::make_shared<ListNode>(); |
| 238 | |
| 239 | /// Use the supertype of the LHS and all tuple elements, to support cases like |
| 240 | /// `toUInt8(232) IN (1000, number)`. If no supertype exists, keep the old |
| 241 | /// behaviour and let per-element CAST handle (or reject) the mismatch |
| 242 | DataTypes arg_types; |
| 243 | arg_types.reserve(tuple_args.size() + 1); |
| 244 | arg_types.push_back(in_first_argument->getResultType()); |
| 245 | for (const auto & arg : tuple_args) |
| 246 | arg_types.push_back(arg->getResultType()); |
| 247 | |
| 248 | DataTypePtr common_type = tryGetLeastSupertype(arg_types); |
| 249 | if (!common_type) |
| 250 | common_type = in_first_argument->getResultType(); |
| 251 | |
| 252 | bool has_null = std::any_of(tuple_args.begin(), tuple_args.end(), |
| 253 | [](const auto & arg) { return isNullConstant(arg); }); |
| 254 | |
| 255 | if ((has_null || !scope.context->getSettingsRef()[Setting::transform_null_in]) && !isNullableOrLowCardinalityNullable(common_type)) |
| 256 | common_type = makeNullableOrLowCardinalityNullable(common_type); |
| 257 | |
| 258 | for (const auto & arg : tuple_args) |
| 259 | array_arguments_list->getNodes().push_back(castNodeToType(arg, common_type, scope)); |
| 260 | |
| 261 | array_function_node->getArgumentsNode() = array_arguments_list; |
| 262 | QueryTreeNodePtr array_node = array_function_node; |
| 263 | resolveExpressionNode(array_node, scope, false /*allow_lambda_expression*/, true /*allow_table_expression*/); |
| 264 | |
| 265 | return array_node; |
| 266 | } |
| 267 | |
| 268 | /// casts node to target type with appropriate method (toString for strings, CAST for others) |
| 269 | QueryTreeNodePtr QueryAnalyzer::castNodeToType( |
nothing calls this directly
no test coverage detected