| 2281 | |
| 2282 | |
| 2283 | SinkToStoragePtr StorageFile::write( |
| 2284 | const ASTPtr & query, |
| 2285 | const StorageMetadataPtr & metadata_snapshot, |
| 2286 | ContextPtr context, |
| 2287 | bool /*async_insert*/) |
| 2288 | { |
| 2289 | if (!use_table_fd && archive_info.has_value()) |
| 2290 | throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Writing to archives is not supported"); |
| 2291 | |
| 2292 | if (format_name == "Distributed") |
| 2293 | throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Method write is not implemented for Distributed format"); |
| 2294 | |
| 2295 | int flags = 0; |
| 2296 | |
| 2297 | if (context->getSettingsRef()[Setting::engine_file_truncate_on_insert]) |
| 2298 | flags |= O_TRUNC; |
| 2299 | |
| 2300 | bool has_wildcards = path_for_partitioned_write.contains(PartitionedSink::PARTITION_ID_WILDCARD); |
| 2301 | const auto * insert_query = dynamic_cast<const ASTInsertQuery *>(query.get()); |
| 2302 | bool is_partitioned_implementation = insert_query && insert_query->partition_by && has_wildcards; |
| 2303 | |
| 2304 | if (is_partitioned_implementation) |
| 2305 | { |
| 2306 | if (path_for_partitioned_write.empty()) |
| 2307 | throw Exception(ErrorCodes::LOGICAL_ERROR, "Empty path for partitioned write"); |
| 2308 | |
| 2309 | auto partition_strategy = PartitionStrategyFactory::get( |
| 2310 | PartitionStrategyFactory::StrategyType::WILDCARD, |
| 2311 | insert_query->partition_by, |
| 2312 | metadata_snapshot->getColumns().getAll(), |
| 2313 | context, |
| 2314 | format_name, |
| 2315 | is_path_with_globs, |
| 2316 | has_wildcards, |
| 2317 | /* partition_columns_in_data_file */true); |
| 2318 | |
| 2319 | return std::make_shared<PartitionedStorageFileSink>( |
| 2320 | partition_strategy, |
| 2321 | metadata_snapshot, |
| 2322 | getStorageID().getNameForLogs(), |
| 2323 | std::unique_lock{rwlock, getLockTimeout(context)}, |
| 2324 | base_path, |
| 2325 | path_for_partitioned_write, |
| 2326 | chooseCompressionMethod(path_for_partitioned_write, compression_method), |
| 2327 | format_settings, |
| 2328 | format_name, |
| 2329 | context, |
| 2330 | flags); |
| 2331 | } |
| 2332 | |
| 2333 | String path; |
| 2334 | if (!paths.empty()) |
| 2335 | { |
| 2336 | if (is_path_with_globs) |
| 2337 | throw Exception(ErrorCodes::DATABASE_ACCESS_DENIED, |
| 2338 | "Table '{}' is in readonly mode because of globs in filepath", |
| 2339 | getStorageID().getNameForLogs()); |
| 2340 |
no test coverage detected