Skip to content

Commit

Permalink
Cherry pick v2.6.0 1022 (vesoft-inc#3188)
Browse files Browse the repository at this point in the history
* fix crash when drop space (vesoft-inc#3185)

* fix geography default value check (vesoft-inc#3189)

Co-authored-by: Doodle <13706157+critical27@users.noreply.github.com>
Co-authored-by: jie.wang <38901892+jievince@users.noreply.github.com>
  • Loading branch information
3 people committed Oct 22, 2021
1 parent 2080890 commit 3ba41bd
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 2 deletions.
24 changes: 24 additions & 0 deletions src/common/datatypes/Geography.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions src/common/datatypes/Geography.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<GeoShape, S2Region> kShapeTypeToS2Region = {
Expand Down
2 changes: 1 addition & 1 deletion src/kvstore/RocksEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 7 additions & 0 deletions src/kvstore/test/RocksEngineTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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<KV> data;
for (TagID tagId = 0; tagId < 10; tagId++) {
Expand Down
12 changes: 11 additions & 1 deletion src/meta/processors/schema/SchemaUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,23 @@ bool SchemaUtil::checkType(std::vector<cpp2::ColumnDef>& 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<uint32_t>(columnGeoShape) != folly::to<uint32_t>(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;
Expand Down
42 changes: 42 additions & 0 deletions tests/tck/features/geo/GeoBase.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3ba41bd

Please sign in to comment.