1 /** 2 * Copyright 2021 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_CONSUMERS_PULL_BASED_TREE_CONSUMER_H_ 17 #define MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_CONSUMERS_PULL_BASED_TREE_CONSUMER_H_ 18 19 #include <memory> 20 #include <string> 21 #include <unordered_map> 22 #include <utility> 23 #include <vector> 24 #include <cstddef> 25 #include "minddata/dataset/engine/tree_adapter_lite.h" 26 27 namespace mindspore::dataset { 28 29 class TreeAdapterLite; 30 class TensorRow; 31 32 /// Consumer that iterates over the dataset and returns the rows one by one as a in a pull based fashion 33 class PullBasedIteratorConsumer { 34 public: 35 /// Constructor 36 PullBasedIteratorConsumer(); 37 38 ~PullBasedIteratorConsumer() = default; 39 40 Status Init(std::shared_ptr<DatasetNode> root); 41 42 /// \brief Returns the next row in a vector format 43 /// \note This is currently a placeholder function 44 /// \param[in] num_rows the number of rows that we want to get 45 /// \return out std::vector of TensorRows 46 std::vector<TensorRow> GetRows(int64_t num_rows); 47 48 /// Returns the next row in a vector format 49 /// \param[out] out std::vector of Tensors 50 /// \return Status error code 51 Status GetNextAsVector(std::vector<TensorPtr> *const out); 52 53 /// Returns the next row in as a map 54 /// \param[out] out std::map of string to Tensor 55 /// \return Status error code 56 Status GetNextAsMap(std::unordered_map<std::string, TensorPtr> *out); 57 58 /// Returns the next row in as a vector 59 /// \param[out] vec std::vector of pairs of string to Tensor 60 /// \return Status error code 61 Status GetNextAsOrderedPair(std::vector<std::pair<std::string, std::shared_ptr<Tensor>>> *vec); 62 63 private: 64 std::unique_ptr<TreeAdapterLite> tree_adapter_lite_; 65 std::vector<std::pair<std::string, int32_t>> column_order_; // key: column name, val: column id 66 }; 67 } // namespace mindspore::dataset 68 #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_CONSUMERS_PULL_BASED_TREE_CONSUMER_H_ 69