| 119 | } |
| 120 | |
| 121 | void TpchQueryBuilder::initialize(const std::string& dataPath) { |
| 122 | for (const auto& [tableName, columns] : kTables_) { |
| 123 | const fs::path tablePath{dataPath + "/" + tableName}; |
| 124 | std::error_code error; |
| 125 | bool anyFound = false; |
| 126 | for (auto const& dirEntry : fs::directory_iterator{ |
| 127 | tablePath, std::filesystem::directory_options(), error}) { |
| 128 | if (!dirEntry.is_regular_file()) { |
| 129 | continue; |
| 130 | } |
| 131 | // Ignore hidden files. |
| 132 | if (dirEntry.path().filename().c_str()[0] == '.') { |
| 133 | continue; |
| 134 | } |
| 135 | if (tableMetadata_[tableName].dataFiles.empty()) { |
| 136 | anyFound = true; |
| 137 | readFileSchema(tableName, dirEntry.path().string(), columns); |
| 138 | } |
| 139 | tableMetadata_[tableName].dataFiles.push_back(dirEntry.path()); |
| 140 | } |
| 141 | if (!anyFound && error) { |
| 142 | std::ifstream file(tablePath); |
| 143 | std::string line; |
| 144 | while (std::getline(file, line)) { |
| 145 | if (tableMetadata_[tableName].dataFiles.empty()) { |
| 146 | readFileSchema(tableName, line, columns); |
| 147 | } |
| 148 | tableMetadata_[tableName].dataFiles.push_back(line); |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | const std::vector<std::string>& TpchQueryBuilder::getTableNames() { |
| 155 | return kTableNames_; |