Skip to content

Commit

Permalink
handle if HLL file was deleted or corrupted
Browse files Browse the repository at this point in the history
  • Loading branch information
MyrtheW committed Aug 17, 2023
1 parent f234a3b commit b8e067a
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions include/chopper/sketch/toolbox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <robin_hood.h>

#include <chopper/sketch/hyperloglog.hpp>
#include "execute.hpp"

namespace chopper::sketch
{
Expand Down Expand Up @@ -106,11 +107,21 @@ class toolbox
std::sort(positions.begin(), positions.end(), cardinality_compare);
}


static void read_hll_files_into(std::filesystem::path const & hll_dir,
std::vector<std::string> const & target_filenames,
std::vector<hyperloglog> & target)
{
chopper::configuration config; // Create default configuration
read_hll_files_into(hll_dir, target_filenames, target, config);
}

/*!\brief Restore the HLL sketches from the files in hll_dir and target_filenames into target container.
*/
static void read_hll_files_into(std::filesystem::path const & hll_dir,
std::vector<std::string> const & target_filenames,
std::vector<hyperloglog> & target)
std::vector<hyperloglog> & target,
chopper::configuration & config)
{
assert(std::filesystem::exists(hll_dir) && !std::filesystem::is_empty(hll_dir)); // checked in chopper_layout

Expand All @@ -120,18 +131,21 @@ class toolbox
{
for (auto const & filename : target_filenames)
{
if (std::filesystem::path(filename).extension() != ".empty_bin")
{ //Myrthe
if (std::filesystem::path(filename).extension() != ".empty_bin") { //Myrthe

std::filesystem::path path = hll_dir / std::filesystem::path(filename).stem();
path += ".hll";
std::ifstream hll_fin(path, std::ios::binary);
try {
if (!hll_fin.good())
throw std::runtime_error{"Could not open file " + path.string()};

if (!hll_fin.good())
throw std::runtime_error{"Could not open file " + path.string()};

// the sketch bits will be automatically read from the files
target.emplace_back().restore(hll_fin);
target.emplace_back().restore(hll_fin); // the sketch bits will be automatically read from the files
}
catch (std::runtime_error const & ) {
auto filename_input = std::vector<std::string> {filename};
chopper::sketch::execute(config, filename_input, target);
}
}
}
}
Expand Down

0 comments on commit b8e067a

Please sign in to comment.