| 757 | } |
| 758 | |
| 759 | std::vector<std::string> DatasetLoader::LoadTextDataToMemory(const char* filename, const Metadata& metadata, |
| 760 | int rank, int num_machines, int* num_global_data, |
| 761 | std::vector<data_size_t>* used_data_indices) { |
| 762 | TextReader<data_size_t> text_reader(filename, config_.header, config_.file_load_progress_interval_bytes); |
| 763 | used_data_indices->clear(); |
| 764 | if (num_machines == 1 || config_.pre_partition) { |
| 765 | // read all lines |
| 766 | *num_global_data = text_reader.ReadAllLines(); |
| 767 | } else { // need partition data |
| 768 | // get query data |
| 769 | const data_size_t* query_boundaries = metadata.query_boundaries(); |
| 770 | |
| 771 | if (query_boundaries == nullptr) { |
| 772 | // if not contain query data, minimal sample unit is one record |
| 773 | *num_global_data = text_reader.ReadAndFilterLines([this, rank, num_machines](data_size_t) { |
| 774 | if (random_.NextShort(0, num_machines) == rank) { |
| 775 | return true; |
| 776 | } else { |
| 777 | return false; |
| 778 | } |
| 779 | }, used_data_indices); |
| 780 | } else { |
| 781 | // if contain query data, minimal sample unit is one query |
| 782 | data_size_t num_queries = metadata.num_queries(); |
| 783 | data_size_t qid = -1; |
| 784 | bool is_query_used = false; |
| 785 | *num_global_data = text_reader.ReadAndFilterLines( |
| 786 | [this, rank, num_machines, &qid, &query_boundaries, &is_query_used, num_queries] |
| 787 | (data_size_t line_idx) { |
| 788 | if (qid >= num_queries) { |
| 789 | Log::Fatal("Current query exceeds the range of the query file,\n" |
| 790 | "please ensure the query file is correct"); |
| 791 | } |
| 792 | if (line_idx >= query_boundaries[qid + 1]) { |
| 793 | // if is new query |
| 794 | is_query_used = false; |
| 795 | if (random_.NextShort(0, num_machines) == rank) { |
| 796 | is_query_used = true; |
| 797 | } |
| 798 | ++qid; |
| 799 | } |
| 800 | return is_query_used; |
| 801 | }, used_data_indices); |
| 802 | } |
| 803 | } |
| 804 | return std::move(text_reader.Lines()); |
| 805 | } |
| 806 | |
| 807 | std::vector<std::string> DatasetLoader::SampleTextDataFromMemory(const std::vector<std::string>& data) { |
| 808 | int sample_cnt = config_.bin_construct_sample_cnt; |
nothing calls this directly
no test coverage detected