diff --git a/src/functions/delta_scan.cpp b/src/functions/delta_scan.cpp index 30304ea..70b93a8 100644 --- a/src/functions/delta_scan.cpp +++ b/src/functions/delta_scan.cpp @@ -424,9 +424,7 @@ void DeltaSnapshot::Bind(vector &return_types, vector &name return; } - if (!initialized_snapshot) { - InitializeSnapshot(); - } + EnsureSnapshotInitialized(); unique_ptr schema; @@ -446,13 +444,7 @@ void DeltaSnapshot::Bind(vector &return_types, vector &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()) { @@ -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::PushdownInternal(ClientContext &context, TableFilterSet filters) const { auto filtered_list = make_uniq(context, paths[0]); @@ -622,12 +627,7 @@ void DeltaSnapshot::ReportFilterPushdown(ClientContext &context, DeltaSnapshot & // reworked to clean this up { unique_lock lck(lock); - if (!initialized_snapshot) { - InitializeSnapshot(); - } - if (!initialized_scan) { - InitializeScan(); - } + EnsureScanInitialized(); old_total = GetTotalFileCountInternal(); } new_total = new_list.GetTotalFileCount(); @@ -778,33 +778,21 @@ unique_ptr DeltaSnapshot::GetCardinality(ClientContext &context) idx_t DeltaSnapshot::GetVersion() { unique_lock 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 lck(lock); + if (index >= metadata.size()) { + throw InternalException("Attempted to fetch metadata for nonexistent file in DeltaSnapshot"); + } return *metadata[index]; } vector DeltaSnapshot::GetPartitionColumns() { unique_lock lck(lock); - - if (!initialized_snapshot) { - InitializeSnapshot(); - } - - if (!initialized_scan) { - InitializeScan(); - } - + EnsureScanInitialized(); return partitions; } diff --git a/src/include/functions/delta_scan.hpp b/src/include/functions/delta_scan.hpp index 3d605b3..a3db2ee 100644 --- a/src/include/functions/delta_scan.hpp +++ b/src/include/functions/delta_scan.hpp @@ -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_ids, const char *log_type, optional_ptr mfr_info) const;