Skip to content

Commit

Permalink
cleanup lazy initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
samansmink committed Feb 7, 2025
1 parent f41d101 commit 413f7c9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 33 deletions.
54 changes: 21 additions & 33 deletions src/functions/delta_scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,7 @@ void DeltaSnapshot::Bind(vector<LogicalType> &return_types, vector<string> &name
return;
}

if (!initialized_snapshot) {
InitializeSnapshot();
}
EnsureSnapshotInitialized();

unique_ptr<SchemaVisitor::FieldList> schema;

Expand All @@ -446,13 +444,7 @@ void DeltaSnapshot::Bind(vector<LogicalType> &return_types, vector<string> &name
}

string DeltaSnapshot::GetFileInternal(idx_t i) const {
if (!initialized_snapshot) {
InitializeSnapshot();
}

if (!initialized_scan) {
InitializeScan();
}
EnsureScanInitialized();

// We already have this file
if (i < resolved_files.size()) {
Expand Down Expand Up @@ -545,6 +537,19 @@ void DeltaSnapshot::InitializeScan() const {
initialized_scan = true;
}

void DeltaSnapshot::EnsureSnapshotInitialized() const {
if (!initialized_snapshot) {
InitializeSnapshot();
}
}

void DeltaSnapshot::EnsureScanInitialized() const {
EnsureSnapshotInitialized();
if (!initialized_scan) {
InitializeScan();
}
}

unique_ptr<DeltaSnapshot> DeltaSnapshot::PushdownInternal(ClientContext &context, TableFilterSet filters) const {
auto filtered_list = make_uniq<DeltaSnapshot>(context, paths[0]);

Expand Down Expand Up @@ -622,12 +627,7 @@ void DeltaSnapshot::ReportFilterPushdown(ClientContext &context, DeltaSnapshot &
// reworked to clean this up
{
unique_lock<mutex> lck(lock);
if (!initialized_snapshot) {
InitializeSnapshot();
}
if (!initialized_scan) {
InitializeScan();
}
EnsureScanInitialized();
old_total = GetTotalFileCountInternal();
}
new_total = new_list.GetTotalFileCount();
Expand Down Expand Up @@ -778,33 +778,21 @@ unique_ptr<NodeStatistics> DeltaSnapshot::GetCardinality(ClientContext &context)

idx_t DeltaSnapshot::GetVersion() {
unique_lock<mutex> lck(lock);
// TODO: does this make sense? we are initializing a scan just to get the version here
if (!initialized_snapshot) {
InitializeSnapshot();
}
if (!initialized_scan) {
InitializeScan();
}

EnsureScanInitialized();
return version;
}

DeltaFileMetaData &DeltaSnapshot::GetMetaData(idx_t index) const {
unique_lock<mutex> lck(lock);
if (index >= metadata.size()) {
throw InternalException("Attempted to fetch metadata for nonexistent file in DeltaSnapshot");
}
return *metadata[index];
}

vector<string> DeltaSnapshot::GetPartitionColumns() {
unique_lock<mutex> lck(lock);

if (!initialized_snapshot) {
InitializeSnapshot();
}

if (!initialized_scan) {
InitializeScan();
}

EnsureScanInitialized();
return partitions;
}

Expand Down
3 changes: 3 additions & 0 deletions src/include/functions/delta_scan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ struct DeltaSnapshot : public MultiFileList {
void InitializeSnapshot() const;
void InitializeScan() const;

void EnsureSnapshotInitialized() const;
void EnsureScanInitialized() const;

void ReportFilterPushdown(ClientContext &context, DeltaSnapshot &new_list, const vector<column_t> &column_ids,
const char *log_type, optional_ptr<MultiFilePushdownInfo> mfr_info) const;

Expand Down

0 comments on commit 413f7c9

Please sign in to comment.