MCPcopy Create free account
hub / github.com/dmlc/xgboost / ValidateFileFormat

Function ValidateFileFormat

src/data/file_iterator.cc:20–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18
19namespace xgboost::data {
20std::string ValidateFileFormat(std::string const& uri) {
21 std::vector<std::string> name_args_cache = common::Split(uri, '#');
22 CHECK_LE(name_args_cache.size(), 2)
23 << "Only one `#` is allowed in file path for cachefile specification";
24
25 std::vector<std::string> name_args = common::Split(name_args_cache[0], '?');
26 StringView msg{"URI parameter `format` is required for loading text data: filename?format=csv"};
27 CHECK_EQ(name_args.size(), 2) << msg;
28
29 std::map<std::string, std::string> args;
30 std::vector<std::string> arg_list = common::Split(name_args[1], '&');
31 for (size_t i = 0; i < arg_list.size(); ++i) {
32 std::istringstream is(arg_list[i]);
33 std::pair<std::string, std::string> kv;
34 CHECK(std::getline(is, kv.first, '='))
35 << "Invalid uri argument format" << " for key in arg " << i + 1;
36 CHECK(std::getline(is, kv.second))
37 << "Invalid uri argument format" << " for value in arg " << i + 1;
38 args.insert(kv);
39 }
40 if (args.find("format") == args.cend()) {
41 LOG(FATAL) << msg;
42 }
43
44 auto path = common::Split(uri, '?')[0];
45
46 namespace fs = std::filesystem;
47 name_args[0] = fs::weakly_canonical(fs::u8path(path)).string();
48 if (name_args_cache.size() == 1) {
49 return name_args[0] + "?" + name_args[1];
50 } else {
51 return name_args[0] + "?" + name_args[1] + '#' + name_args_cache[1];
52 }
53}
54
55int FileIterator::Next() {
56 CHECK(parser_);

Callers 2

LoadMethod · 0.85
FileIteratorMethod · 0.85

Calls 3

SplitFunction · 0.85
sizeMethod · 0.45
cendMethod · 0.45

Tested by

no test coverage detected