Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hive partitioning: Fix preprocessing of CreateDirectories #9535

Merged
merged 4 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Hive partitioning: Fix creation of directories
Invariant would be that CreateDirectories will only be called while holding the global lock,
and the same global lock will be held while iterating on what partitions needs to be created.
  • Loading branch information
carlopi committed Nov 1, 2023
commit 85256c323e935616457955326c9a9bfa685e71bf
8 changes: 0 additions & 8 deletions src/common/hive_partitioning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,6 @@ std::map<idx_t, const HivePartitionKey *> HivePartitionedColumnData::GetReverseM
return ret;
}

std::map<idx_t, const HivePartitionKey *> GlobalHivePartitionState::GetReverseMap() {
std::map<idx_t, const HivePartitionKey *> ret;
for (const auto &pair : partition_map) {
ret[pair.second] = &(pair.first);
}
return ret;
}

void HivePartitionedColumnData::GrowAllocators() {
unique_lock<mutex> lck_gstate(allocators->lock);

Expand Down
14 changes: 7 additions & 7 deletions src/execution/operator/persistent/physical_copy_to_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CopyToFunctionGlobalState : public GlobalSinkState {
idx_t rows_copied;
idx_t last_file_offset;
unique_ptr<GlobalFunctionData> global_state;
bool created_directories = false;
idx_t created_directories = 0;

//! shared state for HivePartitionedColumnData
shared_ptr<GlobalHivePartitionState> partition_state;
Expand Down Expand Up @@ -122,13 +122,13 @@ SinkCombineResultType PhysicalCopyToFile::Combine(ExecutionContext &context, Ope
{
// create directories
lock_guard<mutex> global_lock(g.lock);
if (!g.created_directories) {
auto global_partition_key_map = g.partition_state->GetReverseMap();
for (auto &it : global_partition_key_map) {
CreateDirectories(partition_columns, names, it.second->values, trimmed_path, fs);
}
g.created_directories = true;
const auto &global_partitions = g.partition_state->partitions;
// global_partitions have partitions added only at the back, so it's fine to only traverse the last part

for (idx_t i = g.created_directories; i < global_partitions.size(); i++) {
CreateDirectories(partition_columns, names, global_partitions[i]->first.values, trimmed_path, fs);
}
g.created_directories = global_partitions.size();
}

for (idx_t i = 0; i < partitions.size(); i++) {
Expand Down
1 change: 0 additions & 1 deletion src/include/duckdb/common/hive_partitioning.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ class GlobalHivePartitionState {
hive_partition_map_t partition_map;
//! Used for incremental updating local copies of the partition map;
vector<hive_partition_map_t::const_iterator> partitions;
std::map<idx_t, const HivePartitionKey *> GetReverseMap();
};

class HivePartitionedColumnData : public PartitionedColumnData {
Expand Down
Loading