| 48 | |
| 49 | template <class TReadLineFunc> |
| 50 | TVector<TColumn> ReadCDImpl(TReadLineFunc readLineFunc, const TCdParserDefaults& defaults) { |
| 51 | size_t columnsCount = defaults.UseDefaultColumnCount ? SafeIntegerCast<size_t>(defaults.ColumnCount) : 0; |
| 52 | const auto defaultColumnType = defaults.DefaultColumnType.GetOrElse(EColumn()); |
| 53 | const TColumn defaultColumn{defaultColumnType, TString()}; |
| 54 | TVector<TColumn> columns(columnsCount, defaultColumn); |
| 55 | |
| 56 | TSet<size_t> parsedColumns; |
| 57 | TString line; |
| 58 | for (size_t lineNumber = 0; readLineFunc(&line); lineNumber++) { |
| 59 | TVector<TString> tokens; |
| 60 | try { |
| 61 | try { |
| 62 | StringSplitter(line).Split('\t').SkipEmpty().Collect(&tokens); |
| 63 | } catch (const yexception& e) { |
| 64 | CATBOOST_DEBUG_LOG << "Got exception " << e.what() << " while parsing feature descriptions line " |
| 65 | << line << Endl; |
| 66 | break; |
| 67 | } |
| 68 | if (tokens.empty()) { |
| 69 | continue; |
| 70 | } |
| 71 | CB_ENSURE( |
| 72 | tokens.ysize() == 2 || tokens.ysize() == 3, |
| 73 | "Each line should have two or three columns. This line has " << tokens.size() |
| 74 | ); |
| 75 | |
| 76 | TVector<TString> indexTokens; |
| 77 | |
| 78 | try { |
| 79 | StringSplitter(tokens[0]).Split('.').SkipEmpty().Collect(&indexTokens); |
| 80 | } catch (const yexception& e) { |
| 81 | CATBOOST_DEBUG_LOG << "Got exception " << e.what() << " while parsing index field " |
| 82 | << tokens[0] << Endl; |
| 83 | throw; |
| 84 | } |
| 85 | |
| 86 | if (indexTokens.ysize() == 1) { |
| 87 | size_t index = 0; |
| 88 | CB_ENSURE(TryFromString(tokens[0], index), "Invalid column index: \"" << tokens[0] << "\""); |
| 89 | if (defaults.UseDefaultColumnCount) { |
| 90 | CB_ENSURE(index < columnsCount, "Invalid column index: " LabeledOutput(index, columnsCount)); |
| 91 | } |
| 92 | ProcessColumnAfterIndex("file", defaultColumn, index, tokens, &columns, &parsedColumns); |
| 93 | } else if (indexTokens.ysize() == 2) { |
| 94 | size_t metaColumnIndex = 0; |
| 95 | CB_ENSURE( |
| 96 | TryFromString(indexTokens[0], metaColumnIndex), |
| 97 | "Invalid meta column index: \"" << indexTokens[0] << "\"" |
| 98 | ); |
| 99 | CB_ENSURE( |
| 100 | metaColumnIndex < columns.size(), |
| 101 | "Invalid meta column index: " << LabeledOutput(metaColumnIndex, columns.size()) |
| 102 | ); |
| 103 | CB_ENSURE( |
| 104 | columns[metaColumnIndex].Type == EColumn::Features, |
| 105 | "Column with index " << metaColumnIndex << " is not a Features meta column" |
| 106 | ); |
| 107 | size_t subIndex = 0; |
no test coverage detected