1 /** 2 * Copyright 2019-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_DATASETOPS_PROJECT_OP_H_ 17 #define MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_DATASETOPS_PROJECT_OP_H_ 18 19 #include <memory> 20 #include <string> 21 #include <vector> 22 23 #include "minddata/dataset/engine/datasetops/pipeline_op.h" 24 25 namespace mindspore { 26 namespace dataset { 27 class ProjectOp : public PipelineOp { 28 public: 29 // Constructor of the ProjectOp. 30 // @param columnsToProject - 31 explicit ProjectOp(const std::vector<std::string> &columns_to_project); 32 33 // Destructor. 34 ~ProjectOp() = default; 35 36 // A print method typically used for debugging. 37 // @param out - The output stream to write output to. 38 // @param show_all - A bool to control if you want to show all info or just a summary. 39 void Print(std::ostream &out, bool show_all) const override; 40 41 // << Stream output operator overload. 42 // @notes This allows you to write the debug print info using stream operators. 43 // @param out - reference to the output stream being overloaded. 44 // @param project_op - reference to the ProjectOp to display. 45 // @return - the output stream must be returned. 46 friend std::ostream &operator<<(std::ostream &out, const ProjectOp &project_op) { 47 project_op.Print(out, false); 48 return out; 49 } 50 51 // Class functor operator () override. 52 // Most dataset ops operate by launching a thread (see ExecutionTree). 53 // However, the ProjectOp is defined as a inlined operator, so it is invalid to launch the 54 // functor since this op runs inlined inside another operator. The function is overloaded to 55 // ensure that it is not called by mistake (it will generate an error). 56 // @return Status The status code returned 57 Status operator()() override; 58 59 // Gets a row from the child node and projects that row. The caller is typically our parent node. 60 // @param row - output pointer to the projected row. 61 // @param worker_id - The worker id 62 Status GetNextRow(TensorRow *row, int32_t worker_id, bool retry_if_eoe) override; 63 64 // Base-class override. Return the number of workers in the first parent. 65 // @param workerId - The worker id 66 int32_t NumConsumers() const override; 67 68 // Base-class override. Return the number of producers in the first child. 69 // @param workerId - The worker id 70 int32_t NumProducers() const override; 71 72 // Base-class override for special eoe handler. 73 // Inline operators must override this because there is no connector to push eoe onto. 74 // @return Status The status code returned 75 Status EoeReceived(int32_t worker_id) override; 76 77 // Base-class override for special eof handler. 78 // Inline operators must override this because there is no connector to push eof onto. 79 // @return Status The status code returned 80 Status EofReceived(int32_t worker_id) override; 81 82 /// \brief Gets the next row 83 /// \param row[out] - Fetched TensorRow 84 /// \return Status The status code returned 85 Status GetNextRowPullMode(TensorRow *const row) override; 86 87 // Op name getter 88 // @return Name of the current Op Name()89 std::string Name() const override { return kProjectOp; } 90 91 private: 92 std::vector<std::string> columns_to_project_; 93 std::vector<int32_t> projected_column_indices_; 94 95 TensorRow Project(const TensorRow &row); 96 97 // Computing the assignment of the column name map. 98 // @return - Status 99 Status ComputeColMap() override; 100 }; 101 } // namespace dataset 102 } // namespace mindspore 103 104 #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_DATASETOPS_PROJECT_OP_H_ 105