Skip to content

Commit

Permalink
remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
Tmonster committed Dec 6, 2023
1 parent 34902e9 commit 236825b
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 74 deletions.
21 changes: 0 additions & 21 deletions src/execution/operator/helper/physical_reservoir_sample.cpp
@@ -1,7 +1,5 @@
#include "duckdb/execution/operator/helper/physical_reservoir_sample.hpp"
#include "duckdb/execution/reservoir_sample.hpp"
#include "duckdb/common/atomic.hpp"
#include "iostream"

namespace duckdb {

Expand Down Expand Up @@ -112,25 +110,6 @@ SinkCombineResultType PhysicalReservoirSample::Combine(ExecutionContext &context
return SinkCombineResultType::FINISHED;
}

//static void PrintSampleCount(vector<unique_ptr<BlockingSample>> &samples) {
// idx_t total_count = 0;
// for (auto &sample : samples) {
// total_count += sample->get_sample_count();
// }
// std::cout << "samples in reservoir is " << total_count << std::endl;
//}

//static void PrintAllSeenSamples(ReservoirSamplePercentage &sample_percentage) {
// idx_t finished_samples_seen = 0;
// for (auto &sample : sample_percentage.finished_samples) {
// // auto &tmp = sample->Cast<ReservoirSamplePercentage>();
// finished_samples_seen += sample->base_reservoir_sample.num_entries_seen_total;
// D_ASSERT(sample->base_reservoir_sample.num_entries_seen_total == 100000);
// }
// finished_samples_seen += sample_percentage.current_count;
// std::cout << "this sample has seen " << finished_samples_seen << " tuples" << std::endl;
//}

SinkFinalizeType PhysicalReservoirSample::Finalize(Pipeline &pipeline, Event &event, ClientContext &context,
OperatorSinkFinalizeInput &input) const {
auto &global_state = input.global_state.Cast<SampleGlobalSinkState>();
Expand Down
40 changes: 0 additions & 40 deletions src/execution/reservoir_sample.cpp
@@ -1,6 +1,5 @@
#include "duckdb/execution/reservoir_sample.hpp"
#include "duckdb/common/pair.hpp"
#include "iostream"

namespace duckdb {

Expand Down Expand Up @@ -47,17 +46,6 @@ void ReservoirSample::AddToReservoir(DataChunk &input) {
}
}

void ReservoirSample::MergeUnfinishedSamples(unique_ptr<BlockingSample> &other) {
auto &reservoir_sample = other->Cast<ReservoirSample>();
reservoir_sample.Finalize();
throw InternalException("a normal reservoir sample should not merge unfisihed samples");
// auto chunk = reservoir_sample.GetChunk();
// while (chunk) {
// AddToReservoir(*chunk);
// chunk = other->GetChunk();
// }
}

void ReservoirSample::InitializeReservoirWeights() {
base_reservoir_sample.InitializeReservoir(num_added_samples, num_added_samples);
}
Expand Down Expand Up @@ -256,31 +244,6 @@ ReservoirSamplePercentage::ReservoirSamplePercentage(Allocator &allocator, doubl
current_sample = make_uniq<ReservoirSample>(allocator, reservoir_sample_size, random.NextRandomInteger());
}

void ReservoirSamplePercentage::MergeUnfinishedSamples(unique_ptr<BlockingSample> &other) {
auto &percentage_sample = other->Cast<ReservoirSamplePercentage>();
auto other_seen = percentage_sample.current_count;
auto other_added = percentage_sample.current_sample->num_added_samples;
auto difference = other_seen - other_added;
auto chunk = other->GetChunk();
while (chunk) {
AddToReservoir(*chunk);
chunk = other->GetChunk();
}
current_count += difference;
}

void ReservoirSamplePercentage::Merge(unique_ptr<BlockingSample> &other) {
//! We are now merging all the samples. 80% of every sample should equal 80%
//! of all rows so we set sample percentage to 1, which will means every tuple
//! in the added chunks will be added
sample_percentage = 1;
auto chunk = other->GetChunk();
while (chunk) {
AddToReservoir(*chunk);
chunk = other->GetChunk();
}
}

void ReservoirSamplePercentage::AddToReservoir(DataChunk &input) {
base_reservoir_sample.num_entries_seen_total += input.size();
if (current_count + input.size() > RESERVOIR_THRESHOLD) {
Expand Down Expand Up @@ -399,9 +362,6 @@ void BaseReservoirSampling::InitializeReservoir(idx_t cur_size, idx_t sample_siz
}
SetNextEntry();
}
if (cur_size > sample_size) {
throw InternalException("cur_size should eventually be equal to sample size right?");
}
}

void BaseReservoirSampling::SetNextEntry() {
Expand Down
13 changes: 2 additions & 11 deletions src/include/duckdb/execution/reservoir_sample.hpp
Expand Up @@ -75,8 +75,6 @@ class BlockingSample {

virtual void Merge(unique_ptr<BlockingSample> &other) = 0;

virtual void MergeUnfinishedSamples(unique_ptr<BlockingSample> &other) = 0;

virtual void InitializeReservoirWeights() = 0;

virtual idx_t get_sample_count() = 0;
Expand Down Expand Up @@ -114,9 +112,6 @@ class ReservoirSample : public BlockingSample {
//! When collecting samples in parallel, merge samples to create a final sample for the column
void Merge(unique_ptr<BlockingSample> &other) override;

//! When merging sample, unfinished sample merging requires special merging logic
virtual void MergeUnfinishedSamples(unique_ptr<BlockingSample> &other) override;

//! Fetches a chunk from the sample. Note that this method is destructive and should only be used after the
//! sample is completely built.
unique_ptr<DataChunk> GetChunk() override;
Expand Down Expand Up @@ -161,10 +156,8 @@ class ReservoirSamplePercentage : public BlockingSample {
void AddToReservoir(DataChunk &input) override;

//! When collecting samples in parallel, merge samples to create a final sample for the column
void Merge(unique_ptr<BlockingSample> &other) override;

//! When merging sample, unfinished sample merging requires special merging logic
virtual void MergeUnfinishedSamples(unique_ptr<BlockingSample> &other) override;
//! Merge should not be called on reservoir sample percentages. One sample is kept in global state.
void Merge(unique_ptr<BlockingSample> &other) override {};

//! Fetches a chunk from the sample. Note that this method is destructive and should only be used after the
//! sample is completely built.
Expand All @@ -191,7 +184,6 @@ class ReservoirSamplePercentage : public BlockingSample {
//! The fixed sample size of the sub-reservoirs
idx_t reservoir_sample_size;

public:
//! The current sample
unique_ptr<ReservoirSample> current_sample;

Expand All @@ -202,7 +194,6 @@ class ReservoirSamplePercentage : public BlockingSample {
//! Whether or not the stream is finalized. The stream is automatically finalized on the first call to GetChunk();
bool is_finalized;

void PrintSampleCount();
};

} // namespace duckdb
4 changes: 2 additions & 2 deletions test/sql/sample/reservoir_testing_rows_value.test
Expand Up @@ -11,7 +11,7 @@ statement ok
CREATE or replace TABLE t1 as select range a from range(1000);

query I
SELECT count(*) from t1 using sample 00;
SELECT count(*) from t1 using sample 0;
----
0

Expand Down Expand Up @@ -83,4 +83,4 @@ select count(*) from t1 using sample 700000;
----
700000

endloop
endloop

0 comments on commit 236825b

Please sign in to comment.