diff --git a/src/clients/meta/MetaClient.cpp b/src/clients/meta/MetaClient.cpp index 7446ab95f12..e04cb91214e 100644 --- a/src/clients/meta/MetaClient.cpp +++ b/src/clients/meta/MetaClient.cpp @@ -828,6 +828,8 @@ Status MetaClient::handleResponse(const RESP& resp) { return Status::Error("No hosts!"); case nebula::cpp2::ErrorCode::E_EXISTED: return Status::Error("Existed!"); + case nebula::cpp2::ErrorCode::E_HISTORY_CONFLICT: + return Status::Error("Schema exisited before!"); case nebula::cpp2::ErrorCode::E_SPACE_NOT_FOUND: return Status::SpaceNotFound("Space not existed!"); case nebula::cpp2::ErrorCode::E_TAG_NOT_FOUND: diff --git a/src/common/graph/Response.h b/src/common/graph/Response.h index 7989548d565..8ce83a78bf6 100644 --- a/src/common/graph/Response.h +++ b/src/common/graph/Response.h @@ -77,6 +77,7 @@ X(E_WRONGCLUSTER, -2010) \ X(E_ZONE_NOT_ENOUGH, -2011) \ X(E_ZONE_IS_EMPTY, -2012) \ + X(E_HISTORY_CONFLICT, -2018) \ \ X(E_STORE_FAILURE, -2021) \ X(E_STORE_SEGMENT_ILLEGAL, -2022) \ diff --git a/src/interface/common.thrift b/src/interface/common.thrift index 0bdf5d44f94..7a87b1fb807 100644 --- a/src/interface/common.thrift +++ b/src/interface/common.thrift @@ -376,6 +376,7 @@ enum ErrorCode { E_RELATED_INDEX_EXISTS = -2015, // There are still indexes related to tag or edge, cannot drop it E_RELATED_SPACE_EXISTS = -2016, // There are still some space on the host, cannot drop it E_RELATED_FULLTEXT_INDEX_EXISTS = -2017, // There are still fulltext index on tag/edge + E_HISTORY_CONFLICT = -2018, // Existed before (e.g., schema) E_STORE_FAILURE = -2021, // Failed to store data E_STORE_SEGMENT_ILLEGAL = -2022, // Illegal storage segment diff --git a/src/meta/MetaServiceUtils.cpp b/src/meta/MetaServiceUtils.cpp index 4a23439dc1e..6e864731a53 100644 --- a/src/meta/MetaServiceUtils.cpp +++ b/src/meta/MetaServiceUtils.cpp @@ -87,11 +87,20 @@ nebula::cpp2::ErrorCode MetaServiceUtils::alterColumnDefs( bool isEdge) { switch (op) { case cpp2::AlterSchemaOp::ADD: + // Check the current schema first. Then check all schemas. + for (auto it = cols.begin(); it != cols.end(); ++it) { + if (it->get_name() == col.get_name()) { + LOG(ERROR) << "Column existing: " << col.get_name(); + return nebula::cpp2::ErrorCode::E_EXISTED; + } + } + // There won't any two columns having the same name across all schemas. If there is a column + // having the same name with the intended change, it must be from history schemas. for (auto& versionedCols : allVersionedCols) { for (auto it = versionedCols.begin(); it != versionedCols.end(); ++it) { if (it->get_name() == col.get_name()) { - LOG(ERROR) << "Column currently or previously existing: " << col.get_name(); - return nebula::cpp2::ErrorCode::E_EXISTED; + LOG(ERROR) << "Column previously existing: " << col.get_name(); + return nebula::cpp2::ErrorCode::E_HISTORY_CONFLICT; } } } diff --git a/tests/tck/features/ddl/Ddl.feature b/tests/tck/features/ddl/Ddl.feature index bb9eb495fa8..70083f4c864 100644 --- a/tests/tck/features/ddl/Ddl.feature +++ b/tests/tck/features/ddl/Ddl.feature @@ -83,7 +83,7 @@ Feature: DDL test ALTER TAG B ADD (name string) """ # IMHO, this is really confusing. https://github.com/vesoft-inc/nebula/issues/2671 - Then a ExecutionError should be raised at runtime: Existed! + Then a ExecutionError should be raised at runtime: Schema exisited before! When executing query: """ ALTER TAG B ADD (namex string) @@ -225,7 +225,7 @@ Feature: DDL test """ ALTER EDGE E2 ADD (name string) """ - Then a ExecutionError should be raised at runtime: Existed! + Then a ExecutionError should be raised at runtime: Schema exisited before! When executing query: """ ALTER EDGE E2 ADD (namex string) diff --git a/tests/tck/features/schema/Schema.feature b/tests/tck/features/schema/Schema.feature index 6ac6c6f35ac..fc386184eaf 100644 --- a/tests/tck/features/schema/Schema.feature +++ b/tests/tck/features/schema/Schema.feature @@ -956,7 +956,7 @@ Feature: Insert string vid of vertex and edge CREATE TAG person(name string, age int); """ Then the execution should be successful - And wait 3 seconds + And wait 10 seconds When executing query: """ INSERT VERTEX person values "1":("Tom", 23); @@ -974,7 +974,7 @@ Feature: Insert string vid of vertex and edge ALTER TAG person DROP (age); """ Then the execution should be successful - And wait 3 seconds + And wait 10 seconds When executing query: """ FETCH PROP ON person "1" yield properties(vertex) AS props; @@ -986,4 +986,4 @@ Feature: Insert string vid of vertex and edge """ ALTER TAG person ADD (age int); """ - Then a ExecutionError should be raised at runtime: Existed + Then a ExecutionError should be raised at runtime: Schema exisited before!