OmniSciDB  6686921089
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
S3FilePathUtil.cpp
Go to the documentation of this file.
2 
3 namespace foreign_storage {
4 namespace {
5 std::vector<Aws::S3::Model::Object> s3_objects_regex_file_filter(
6  const std::string& pattern,
7  const std::vector<Aws::S3::Model::Object>& objects_list) {
8  boost::regex regex_pattern(pattern);
9  std::vector<Aws::S3::Model::Object> matched_objects_list;
10  for (const auto& object : objects_list) {
11  if (boost::regex_match(object.GetKey(), regex_pattern)) {
12  matched_objects_list.emplace_back(object);
13  }
14  }
15  if (matched_objects_list.empty()) {
17  }
18  return matched_objects_list;
19 }
20 } // namespace
21 
22 std::vector<Aws::S3::Model::Object> s3_objects_filter_sort_files(
23  const std::vector<Aws::S3::Model::Object>& file_paths,
24  const std::optional<std::string>& filter_regex,
25  const std::optional<std::string>& sort_by,
26  const std::optional<std::string>& sort_regex) {
27  auto result_files = filter_regex.has_value()
28  ? s3_objects_regex_file_filter(filter_regex.value(), file_paths)
29  : file_paths;
30  // initial lexicographical order ensures a determinisitc ordering for files not matching
31  // sort_regex
32  auto initial_file_order = FileOrderS3(std::nullopt, shared::PATHNAME_ORDER_TYPE);
33  auto lexi_comp = initial_file_order.getFileComparator();
34  std::stable_sort(result_files.begin(), result_files.end(), lexi_comp);
35 
36  auto file_order = FileOrderS3(sort_regex, sort_by);
37  auto comp = file_order.getFileComparator();
38  std::stable_sort(result_files.begin(), result_files.end(), comp);
39  return result_files;
40 }
41 } // namespace foreign_storage
void throw_no_filter_match(const std::string &pattern)
std::vector< Aws::S3::Model::Object > s3_objects_regex_file_filter(const std::string &pattern, const std::vector< Aws::S3::Model::Object > &objects_list)
const std::string PATHNAME_ORDER_TYPE
std::vector< Aws::S3::Model::Object > s3_objects_filter_sort_files(const std::vector< Aws::S3::Model::Object > &file_paths, const std::optional< std::string > &filter_regex, const std::optional< std::string > &sort_by, const std::optional< std::string > &sort_regex)