You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

rename_op.h 4.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /**
  2. * Copyright 2019 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 DATASET_ENGINE_DATASETOPS_RENAME_OP_H_
  17. #define DATASET_ENGINE_DATASETOPS_RENAME_OP_H_
  18. #include <memory>
  19. #include <queue>
  20. #include <string>
  21. #include <vector>
  22. #include "dataset/core/tensor.h"
  23. #include "dataset/engine/datasetops/pipeline_op.h"
  24. #include "dataset/util/status.h"
  25. namespace mindspore {
  26. namespace dataset {
  27. // forward declare
  28. class DataBuffer;
  29. class RenameOp : public PipelineOp {
  30. public:
  31. // The nested builder class inside of the RenameOp is used to help manage all of
  32. // the arguments for constructing it. Use the builder by setting each argument
  33. // with the provided set methods, and then finally call the build method to execute
  34. // the actual construction.
  35. class Builder {
  36. public:
  37. // Builder constructor. Creates the builder object.
  38. // @note No default args
  39. // @return This is a constructor.
  40. Builder();
  41. // Default destructor
  42. ~Builder() = default;
  43. // Setter method.
  44. // @return Builder setter method returns reference to the builder.
  45. Builder &SetInColNames(const std::vector<std::string> &in_col_names) {
  46. builder_in_columns_ = in_col_names;
  47. return *this;
  48. }
  49. // Setter method.
  50. // @return Builder setter method returns reference to the builder.
  51. Builder &SetOutColNames(const std::vector<std::string> &out_col_names) {
  52. builder_out_columns_ = out_col_names;
  53. return *this;
  54. }
  55. // Setter method.
  56. // @return Builder setter method returns reference to the builder.
  57. Builder &SetOpConnectorSize(int32_t op_connector_size) {
  58. builder_op_connector_size_ = op_connector_size;
  59. return *this;
  60. }
  61. // The builder "build" method creates the ZipOp dataset Operator.
  62. // @return shared_ptr to the new StorageOp object
  63. Status Build(std::shared_ptr<RenameOp> *);
  64. private:
  65. std::vector<std::string> builder_in_columns_;
  66. std::vector<std::string> builder_out_columns_;
  67. int32_t builder_op_connector_size_;
  68. Status SanityCheck() const;
  69. };
  70. // Constructor for RenameOp
  71. // @param in_col_names names of columns to rename
  72. // @param out_col_names names of columns after rename
  73. // @param op_connector_size connector size
  74. RenameOp(const std::vector<std::string> &in_col_names, // In: Col names to consume
  75. const std::vector<std::string> &out_col_names, // In: Col names to produce
  76. int32_t op_connector_size);
  77. // Destructor
  78. ~RenameOp();
  79. Status EofReceived(int32_t) override;
  80. Status EoeReceived(int32_t) override;
  81. // Print function for Rename
  82. // @param out output stream to print to
  83. // @param show_all if it should print everything
  84. void Print(std::ostream &out, bool show_all) const override;
  85. // Provide stream operator for displaying it
  86. friend std::ostream &operator<<(std::ostream &out, const RenameOp &ro) {
  87. ro.Print(out, false);
  88. return out;
  89. }
  90. // Class functor operator () override.
  91. // All dataset ops operate by launching a thread (see ExecutionTree). This class functor will
  92. // provide the master loop that drives the logic for performing the work
  93. // @return Status - The error code return
  94. Status operator()() override;
  95. protected:
  96. // Rename core functionality
  97. // @param input_buffer buffer to run rename on
  98. Status RenameBuffer(std::unique_ptr<DataBuffer> *input_buffer);
  99. // Variable to store the input column names
  100. std::vector<std::string> in_columns_;
  101. // Variable to store the output column names
  102. std::vector<std::string> out_columns_;
  103. };
  104. } // namespace dataset
  105. } // namespace mindspore
  106. #endif // DATASET_ENGINE_DATASETOPS_RENAME_OP_H_