From d30f4d5a6ceb344366be1417371f0f8845685a0e Mon Sep 17 00:00:00 2001 From: xiefangqi Date: Wed, 2 Sep 2020 16:54:14 +0800 Subject: [PATCH] fix randomdata schema issue --- mindspore/ccsrc/minddata/dataset/api/datasets.cc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mindspore/ccsrc/minddata/dataset/api/datasets.cc b/mindspore/ccsrc/minddata/dataset/api/datasets.cc index 2a31f300158..425db540843 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;