diff --git a/mindspore/ccsrc/minddata/dataset/api/datasets.cc b/mindspore/ccsrc/minddata/dataset/api/datasets.cc index f5ceed8e5ad..1b8aece8421 100644 --- a/mindspore/ccsrc/minddata/dataset/api/datasets.cc +++ b/mindspore/ccsrc/minddata/dataset/api/datasets.cc @@ -474,6 +474,10 @@ bool SchemaObj::init() { try { std::ifstream in(schema_file_); in >> js; + if (js.find("columns") == js.end()) { + MS_LOG(ERROR) << "\"columns\" node is required in the schema json file."; + return false; + } } catch (const std::exception &err) { MS_LOG(ERROR) << "Schema file failed to load"; return false; @@ -1399,10 +1403,11 @@ std::vector> RandomDataset::Build() { rand_gen_.seed(GetSeed()); // seed the random generator // If total rows was not given, then randomly pick a number std::shared_ptr schema_obj; - if (!schema_path_.empty()) schema_obj = std::make_shared(schema_path_); - - if (schema_obj != nullptr && total_rows_ == 0) { - total_rows_ = schema_obj->get_num_rows(); + if (!schema_path_.empty()) { + schema_obj = Schema(schema_path_); + if (schema_obj == nullptr) { + return {}; + } } std::string schema_json_string, schema_file_path;