| 84 | } // namespace |
| 85 | |
| 86 | void TpchQueryBuilder::readFileSchema( |
| 87 | const std::string& tableName, |
| 88 | const std::string& filePath, |
| 89 | const std::vector<std::string>& columns) { |
| 90 | dwio::common::ReaderOptions readerOptions{pool_.get()}; |
| 91 | readerOptions.setFileFormat(format_); |
| 92 | auto uniqueReadFile = |
| 93 | filesystems::getFileSystem(filePath, nullptr)->openFileForRead(filePath); |
| 94 | std::shared_ptr<ReadFile> readFile; |
| 95 | readFile.reset(uniqueReadFile.release()); |
| 96 | auto input = std::make_unique<dwio::common::BufferedInput>( |
| 97 | readFile, readerOptions.getMemoryPool()); |
| 98 | std::unique_ptr<dwio::common::Reader> reader = |
| 99 | dwio::common::getReaderFactory(readerOptions.getFileFormat()) |
| 100 | ->createReader(std::move(input), readerOptions); |
| 101 | const auto fileType = reader->rowType(); |
| 102 | const auto fileColumnNames = fileType->names(); |
| 103 | // There can be extra columns in the file towards the end. |
| 104 | BOLT_CHECK_GE(fileColumnNames.size(), columns.size()); |
| 105 | std::unordered_map<std::string, std::string> fileColumnNamesMap( |
| 106 | columns.size()); |
| 107 | std::transform( |
| 108 | columns.begin(), |
| 109 | columns.end(), |
| 110 | fileColumnNames.begin(), |
| 111 | std::inserter(fileColumnNamesMap, fileColumnNamesMap.begin()), |
| 112 | [](std::string a, std::string b) { return std::make_pair(a, b); }); |
| 113 | auto columnNames = columns; |
| 114 | auto types = fileType->children(); |
| 115 | types.resize(columnNames.size()); |
| 116 | tableMetadata_[tableName].type = |
| 117 | std::make_shared<RowType>(std::move(columnNames), std::move(types)); |
| 118 | tableMetadata_[tableName].fileColumnNames = std::move(fileColumnNamesMap); |
| 119 | } |
| 120 | |
| 121 | void TpchQueryBuilder::initialize(const std::string& dataPath) { |
| 122 | for (const auto& [tableName, columns] : kTables_) { |
nothing calls this directly
no test coverage detected