194083 {
194084 auto global_lock = lock.GetExclusiveLock();
194085
194088
194089 active_write_entry->second->active_writes++;
194090 return *active_write_entry->second;
194091 }
194092
194094
194096 if (entry.second->active_writes == 0) {
194097
194098 FinalizePartition(context.client, op, *entry.second);
194099 ++previous_partitions[entry.first];
194101 break;
194102 }
194103 }
194104 }
194106 if (op.hive_file_pattern) {
194107 auto prev_offset = previous_partitions.find(values);
194108 if (prev_offset != previous_partitions.end()) {
194109 offset = prev_offset->second;
194110 }
194111 } else {
194112 offset = global_offset++;
194113 }
194114 auto &fs = FileSystem::GetFileSystem(context.client);
194115
194116 auto trimmed_path = op.GetTrimmedPath(context.client);
194117 string hive_path =
194118 GetOrCreateDirectory(op.partition_columns, op.hive_file_pattern, op.names, values, trimmed_path, fs);
194119 string full_path(op.filename_pattern.CreateFilename(fs, hive_path, op.file_extension, offset));
194120 if (op.overwrite_mode == CopyOverwriteMode::COPY_APPEND) {
194121
194122 while (fs.FileExists(full_path)) {
194123
194124 if (!op.filename_pattern.HasUUID()) {
194125 throw InternalException("CopyOverwriteMode::COPY_APPEND without {uuid} - and file exists");
194126 }
194127 full_path = op.filename_pattern.CreateFilename(fs, hive_path, op.file_extension, offset);
194128 }
194129 }
194131 optional_ptr<CopyToFileInfo> written_file_info;
194132 if (op.return_type != CopyFunctionReturnType::CHANGED_ROWS) {
194133 written_file_info = AddFile(*global_lock, full_path, op.return_type);
194134 }
194135
194136 auto info = make_uniq<PartitionWriteInfo>();
194137 info->global_state = op.function.copy_to_initialize_global(context.client, *op.bind_data, full_path);
194138 if (written_file_info) {
194139
194140 op.function.copy_to_get_written_statistics(context.client, *op.bind_data, *info->global_state,
194141 *written_file_info->file_stats);
194142
194143
194144 vector<Value> partition_keys;
194145 vector<Value> partition_values;
194146 for (
idx_t i = 0; i < op.partition_columns.size(); i++) {
194147 const auto &partition_col_name = op.names[op.partition_columns[i]];
194148 const auto &partition_value = values[i];
194149 partition_keys.emplace_back(partition_col_name);
194150 partition_values.push_back(partition_value.DefaultCastAs(LogicalType::VARCHAR));
194151 }
194152 written_file_info->partition_keys =
Value::MAP(LogicalType::VARCHAR, LogicalType::VARCHAR,
194153 std::move(partition_keys), std::move(partition_values));
194154 }
194155 if (op.function.initialize_operator) {
194156 op.function.initialize_operator(*info->global_state, op);
194157 }
194158 auto &result = *info;
194159 info->active_writes = 1;
194160
194162 return result;
194163 }
static DUCKDB_API Value MAP(const LogicalType &child_type, vector< Value > values)
Create a map value with the given entries.
Definition duckdb.cpp:132466