| 307 | }; |
| 308 | |
| 309 | KeyAndValueInput extractKeyAndValueInput(const ColumnsWithTypeAndName & arguments) const |
| 310 | { |
| 311 | KeyAndValueInput input; |
| 312 | |
| 313 | size_t max_key_argument_index = 0; |
| 314 | |
| 315 | auto first_argument_column = arguments[0].column->convertToFullColumnIfConst(); |
| 316 | ColumnPtr second_argument_array_column; |
| 317 | |
| 318 | if (const auto * key_argument_array_column = typeid_cast<const ColumnArray *>(first_argument_column.get())) |
| 319 | { |
| 320 | const ColumnArray * value_argument_array_column = nullptr; |
| 321 | |
| 322 | if (1 < arguments.size()) |
| 323 | { |
| 324 | second_argument_array_column = arguments[1].column->convertToFullColumnIfConst(); |
| 325 | value_argument_array_column = typeid_cast<const ColumnArray *>(second_argument_array_column.get()); |
| 326 | } |
| 327 | |
| 328 | if (!value_argument_array_column) |
| 329 | throw Exception(ErrorCodes::BAD_ARGUMENTS, |
| 330 | "Function {} if array argument is passed as key, additional array argument as value must be passed", |
| 331 | getName()); |
| 332 | |
| 333 | input.key_series_type = assert_cast<const DataTypeArray &>(*arguments[0].type).getNestedType(); |
| 334 | input.key_column = key_argument_array_column->getDataPtr(); |
| 335 | const auto & key_offsets = key_argument_array_column->getOffsets(); |
| 336 | |
| 337 | input.value_series_type = assert_cast<const DataTypeArray &>(*arguments[1].type).getNestedType(); |
| 338 | input.value_column = value_argument_array_column->getDataPtr(); |
| 339 | const auto & value_offsets = value_argument_array_column->getOffsets(); |
| 340 | |
| 341 | if (key_offsets != value_offsets) |
| 342 | throw Exception( |
| 343 | ErrorCodes::BAD_ARGUMENTS, |
| 344 | "Function {} key and value array should have same amount of elements", |
| 345 | getName()); |
| 346 | |
| 347 | input.offsets_column = key_argument_array_column->getOffsetsPtr(); |
| 348 | max_key_argument_index = 2; |
| 349 | } |
| 350 | else if (const auto * key_argument_map_column = typeid_cast<const ColumnMap *>(first_argument_column.get())) |
| 351 | { |
| 352 | const auto & nested_array = key_argument_map_column->getNestedColumn(); |
| 353 | const auto & nested_data_column = key_argument_map_column->getNestedData(); |
| 354 | |
| 355 | const auto & map_argument_type = assert_cast<const DataTypeMap &>(*arguments[0].type); |
| 356 | input.key_series_type = map_argument_type.getKeyType(); |
| 357 | input.value_series_type = map_argument_type.getValueType(); |
| 358 | |
| 359 | input.key_column = nested_data_column.getColumnPtr(0); |
| 360 | input.value_column = nested_data_column.getColumnPtr(1); |
| 361 | input.offsets_column = nested_array.getOffsetsPtr(); |
| 362 | |
| 363 | max_key_argument_index = 1; |
| 364 | } |
| 365 | else |
| 366 | throw Exception( |
no test coverage detected