MCPcopy Create free account
hub / github.com/bytedance/bolt / readFileSchema

Method readFileSchema

bolt/exec/tests/utils/TpchQueryBuilder.cpp:86–119  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

84} // namespace
85
86void 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
121void TpchQueryBuilder::initialize(const std::string& dataPath) {
122 for (const auto& [tableName, columns] : kTables_) {

Callers

nothing calls this directly

Calls 15

getFileSystemFunction · 0.85
getReaderFactoryFunction · 0.85
getFileFormatMethod · 0.80
getMethod · 0.45
openFileForReadMethod · 0.45
resetMethod · 0.45
releaseMethod · 0.45
createReaderMethod · 0.45
rowTypeMethod · 0.45
namesMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected