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