File: queries.cpp

package info (click to toggle)
poco 1.14.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 56,460 kB
  • sloc: cpp: 340,542; ansic: 245,601; makefile: 1,742; yacc: 1,005; sh: 698; sql: 312; lex: 282; xml: 128; perl: 29; python: 24
file content (47 lines) | stat: -rw-r--r-- 1,197 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "queries.h"

#include <filesystem>
#include <algorithm>
#include <iostream>
#include <regex>

#include "benchmark_utils.h"

namespace filesystem = std::filesystem;

std::string getQueryName(unsigned i) {
  if (sql_queries[i].first.empty()) {
    std::string name = "#" + std::to_string(i + 1);
    return name;
  }
  return std::string("") + sql_queries[i].first;
}

std::vector<SQLQuery> getQueriesFromDirectory(const std::string& dir_path) {
  std::regex query_file_regex("\\.sql$");
  std::vector<std::string> files;

  for (auto& entry : filesystem::directory_iterator(dir_path)) {
    if (filesystem::is_regular_file(entry)) {
      std::string path_str = filesystem::path(entry);

      if (std::regex_search(path_str, query_file_regex)) {
        files.push_back(path_str);
      }
    }
  }

  std::sort(files.begin(), files.end());

  std::vector<SQLQuery> queries;
  for (const std::string& file_path : files) {
    const filesystem::path p(file_path);
    const std::string query = readFileContents(file_path);
    queries.emplace_back(p.filename(), query);
  }
  return queries;
}

std::vector<SQLQuery> getTPCHQueries() {
  return getQueriesFromDirectory("test/queries/");
}