Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2cf81d1

Browse files
authored
Add the type check when inserting geography value (vesoft-inc#5460)
1 parent c053e0f commit 2cf81d1

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

src/codec/RowWriterV2.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -656,11 +656,17 @@ WriteResult RowWriterV2::write(ssize_t index, const char* v) {
656656
return write(index, folly::StringPiece(v));
657657
}
658658

659-
WriteResult RowWriterV2::write(ssize_t index, folly::StringPiece v) {
659+
WriteResult RowWriterV2::write(ssize_t index, folly::StringPiece v, bool isWKB) {
660660
auto field = schema_->field(index);
661661
auto offset = headerLen_ + numNullBytes_ + field->offset();
662662
switch (field->type()) {
663-
case PropertyType::GEOGRAPHY: // write wkb
663+
case PropertyType::GEOGRAPHY: {
664+
// If v is a not a WKB string, we need report error.
665+
if (!isWKB) {
666+
return WriteResult::TYPE_MISMATCH;
667+
}
668+
[[fallthrough]];
669+
}
664670
case PropertyType::STRING: {
665671
if (isSet_[index]) {
666672
// The string value has already been set, we need to turn it
@@ -809,8 +815,10 @@ WriteResult RowWriterV2::write(ssize_t index, const Geography& v) {
809815
folly::to<uint32_t>(geoShape) != folly::to<uint32_t>(v.shape())) {
810816
return WriteResult::TYPE_MISMATCH;
811817
}
818+
// Geography is stored as WKB format.
819+
// WKB is a binary string.
812820
std::string wkb = v.asWKB();
813-
return write(index, folly::StringPiece(wkb));
821+
return write(index, folly::StringPiece(wkb), true);
814822
}
815823

816824
WriteResult RowWriterV2::checkUnsetFields() {

src/codec/RowWriterV2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ class RowWriterV2 {
254254
WriteResult write(ssize_t index, uint64_t v);
255255

256256
WriteResult write(ssize_t index, const std::string& v);
257-
WriteResult write(ssize_t index, folly::StringPiece v);
257+
WriteResult write(ssize_t index, folly::StringPiece v, bool isWKB = false);
258258
WriteResult write(ssize_t index, const char* v);
259259

260260
WriteResult write(ssize_t index, const Date& v);

tests/tck/features/geo/GeoBase.feature

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,14 @@ Feature: Geo base
127127
INSERT VERTEX any_shape(geo) VALUES "103":(ST_GeogFromText("POLYGON((0 1, 1 2, 2 3, 0 1))"));
128128
"""
129129
Then the execution should be successful
130+
# "POINT(3 8)" is a string not a geography literal.
131+
# We must use some geography costructor function to construct a geography literal.
132+
# e.g.`ST_GeogFromText("POINT(3 8)")`
133+
When executing query:
134+
"""
135+
INSERT VERTEX any_shape(geo) VALUES "104":("POINT(3 8)");
136+
"""
137+
Then a ExecutionError should be raised at runtime: Storage Error: The data type does not meet the requirements. Use the correct type of data.
130138
# Only point is allowed to insert to the column geograph(point)
131139
When executing query:
132140
"""

0 commit comments

Comments
 (0)