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 17 #ifndef MINDSPORE_CCSRC_MINDDATA_MINDRECORD_INCLUDE_SHARD_SCHEMA_H_ 18 #define MINDSPORE_CCSRC_MINDDATA_MINDRECORD_INCLUDE_SHARD_SCHEMA_H_ 19 20 #include <iostream> 21 #include <memory> 22 #include <string> 23 #include <vector> 24 25 #include "minddata/mindrecord/include/common/log_adapter.h" 26 #include "minddata/mindrecord/include/common/shard_pybind.h" 27 #include "minddata/mindrecord/include/common/shard_utils.h" 28 #include "minddata/mindrecord/include/mindrecord_macro.h" 29 #include "minddata/mindrecord/include/shard_error.h" 30 #include "pybind11/pybind11.h" 31 32 namespace mindspore { 33 namespace mindrecord { 34 class MINDRECORD_API Schema { 35 public: 36 ~Schema() = default; 37 38 /// \brief obtain the json schema ,its description, its block fields 39 /// \param[in] desc the description of the schema 40 /// \param[in] schema the schema's json 41 static std::shared_ptr<Schema> Build(std::string desc, const json &schema); 42 43 /// \brief compare two schema to judge if they are equal 44 /// \param b another schema to be judged 45 /// \return true if they are equal,false if not 46 bool operator==(const Schema &b) const; 47 48 /// \brief get the schema and its description 49 /// \return the json format of the schema and its description 50 std::string GetDesc() const; 51 52 /// \brief get the schema and its description 53 /// \return the json format of the schema and its description 54 json GetSchema() const; 55 56 /// set the schema id 57 /// \param[in] id the id need to be set 58 void SetSchemaID(int64_t id); 59 60 /// get the schema id 61 /// \return the int64 schema id 62 int64_t GetSchemaID() const; 63 64 /// get the blob fields 65 /// \return the vector<string> blob fields 66 std::vector<std::string> GetBlobFields() const; 67 68 private: 69 Schema() = default; 70 static bool ValidateNumberShape(const json &it_value); 71 static bool Validate(json schema); 72 static std::vector<std::string> PopulateBlobFields(json schema); 73 74 std::string desc_; 75 json schema_; 76 std::vector<std::string> blob_fields_; 77 int64_t schema_id_ = -1; 78 }; 79 } // namespace mindrecord 80 } // namespace mindspore 81 82 #endif // MINDSPORE_CCSRC_MINDDATA_MINDRECORD_INCLUDE_SHARD_SCHEMA_H_ 83