diff --git a/src/common/datatypes/Geography.cpp b/src/common/datatypes/Geography.cpp index d26d43e6a66..2f4639275dc 100644 --- a/src/common/datatypes/Geography.cpp +++ b/src/common/datatypes/Geography.cpp @@ -19,6 +19,30 @@ namespace nebula { +std::ostream& operator<<(std::ostream& os, const GeoShape& shape) { + switch (shape) { + case GeoShape::POINT: { + os << "POINT"; + break; + } + case GeoShape::LINESTRING: { + os << "LINESTRING"; + break; + } + case GeoShape::POLYGON: { + os << "POLYGON"; + break; + } + case GeoShape::UNKNOWN: + default: { + os << "__UNKNOWN__"; + break; + } + } + + return os; +} + constexpr double kMaxLongitude = 180.0; constexpr double kMaxLatitude = 90.0; diff --git a/src/common/datatypes/Geography.h b/src/common/datatypes/Geography.h index 5e9b92de31c..a4f20a94c9d 100644 --- a/src/common/datatypes/Geography.h +++ b/src/common/datatypes/Geography.h @@ -32,6 +32,8 @@ enum class GeoShape : uint32_t { POLYGON = 3, }; +std::ostream& operator<<(std::ostream& os, const GeoShape& shape); + // clang-format off /* static const std::unordered_map kShapeTypeToS2Region = { diff --git a/src/kvstore/RocksEngine.cpp b/src/kvstore/RocksEngine.cpp index 73bdb14e104..12db0cbf110 100644 --- a/src/kvstore/RocksEngine.cpp +++ b/src/kvstore/RocksEngine.cpp @@ -124,8 +124,8 @@ RocksEngine::RocksEngine(GraphSpaceID spaceId, } CHECK(status.ok()) << status.ToString(); db_.reset(db); - partsNum_ = allParts().size(); extractorLen_ = sizeof(PartitionID) + vIdLen; + partsNum_ = allParts().size(); LOG(INFO) << "open rocksdb on " << path; backup(); diff --git a/src/kvstore/test/RocksEngineTest.cpp b/src/kvstore/test/RocksEngineTest.cpp index 66eddedff2c..09903a4f6de 100644 --- a/src/kvstore/test/RocksEngineTest.cpp +++ b/src/kvstore/test/RocksEngineTest.cpp @@ -734,6 +734,8 @@ TEST(RebuildPrefixBloomFilter, RebuildPrefixBloomFilter) { EXPECT_EQ("123", value); }; + auto checkSystemPart = [&]() { EXPECT_EQ(10, engine->allParts().size()); }; + checkVertexPrefix(1, "1"); checkVertexPrefix(1, "2"); checkVertexPrefix(2, "3"); @@ -748,11 +750,16 @@ TEST(RebuildPrefixBloomFilter, RebuildPrefixBloomFilter) { checkEdgePartPrefix(2); checkRangeWithPartPrefix(1); checkRangeWithPartPrefix(2); + checkSystemPart(); checkSystemCommit(1); checkSystemCommit(2); }; auto writeData = [&engine] { + for (PartitionID partId = 1; partId <= 10; partId++) { + engine->addPart(partId); + } + LOG(INFO) << "Write some data"; std::vector data; for (TagID tagId = 0; tagId < 10; tagId++) { diff --git a/src/meta/processors/schema/SchemaUtil.cpp b/src/meta/processors/schema/SchemaUtil.cpp index a135ad4df27..8fe1a24d3c3 100644 --- a/src/meta/processors/schema/SchemaUtil.cpp +++ b/src/meta/processors/schema/SchemaUtil.cpp @@ -158,13 +158,23 @@ bool SchemaUtil::checkType(std::vector& columns) { return false; } break; - case cpp2::PropertyType::GEOGRAPHY: + case cpp2::PropertyType::GEOGRAPHY: { if (!value.isGeography()) { // TODO(jie) LOG(ERROR) << "Invalid default value for ` " << name << "', value type is " << value.type(); return false; } + meta::cpp2::GeoShape columnGeoShape = + column.get_type().geo_shape_ref().value_or(meta::cpp2::GeoShape::ANY); + GeoShape defaultExprGeoShape = value.getGeography().shape(); + if (columnGeoShape != meta::cpp2::GeoShape::ANY && + folly::to(columnGeoShape) != folly::to(defaultExprGeoShape)) { + LOG(ERROR) << "Invalid default value for ` " << name << "', value type is " + << value.type() << ", geo shape is " << defaultExprGeoShape; + return false; + } break; + } default: LOG(ERROR) << "Unsupported type"; return false; diff --git a/tests/tck/features/geo/GeoBase.feature b/tests/tck/features/geo/GeoBase.feature index 1110c17c9f1..ef3847b2968 100644 --- a/tests/tck/features/geo/GeoBase.feature +++ b/tests/tck/features/geo/GeoBase.feature @@ -67,6 +67,48 @@ Feature: Geo base Then the result should be, in any order: | Tag | Create Tag | | "only_point" | 'CREATE TAG `only_point` (\n `geo` geography(point) NULL\n) ttl_duration = 0, ttl_col = ""' | + # Test default property value + When executing query: + """ + CREATE TAG test_1(geo geography DEFAULT ST_Point(3, 8)); + """ + Then the execution should be successful + When executing query: + """ + CREATE EDGE test_2(geo geography DEFAULT ST_GeogFromText("LINESTRING(0 1, 2 3)")); + """ + Then the execution should be successful + When executing query: + """ + CREATE EDGE test_2(geo geography DEFAULT ST_GeogFromText("LINESTRING(0 1, 2xxxx")); + """ + Then a ExecutionError should be raised at runtime: Invalid parm! + When executing query: + """ + CREATE TAG test_3(geo geography(point) DEFAULT ST_GeogFromText("LineString(0 1, 2 3)")); + """ + Then a ExecutionError should be raised at runtime: Invalid parm! + When executing query: + """ + CREATE TAG test_3(geo geography(linestring) DEFAULT ST_GeogFromText("LineString(0 1, 2 3)")); + """ + Then the execution should be successful + And wait 3 seconds + When executing query: + """ + INSERT VERTEX test_1() VALUES "test_101":() + """ + Then the execution should be successful + When executing query: + """ + INSERT EDGE test_2() VALUES "test_101"->"test_102":() + """ + Then the execution should be successful + When executing query: + """ + INSERT VERTEX test_3() VALUES "test_103":() + """ + Then the execution should be successful Scenario: test geo CURD # Any geo shape(point/linestring/polygon) is allowed to insert to the column geography