diff --git a/src/codec/RowWriterV2.cpp b/src/codec/RowWriterV2.cpp index d25506d84bf..1e4245559fa 100644 --- a/src/codec/RowWriterV2.cpp +++ b/src/codec/RowWriterV2.cpp @@ -656,11 +656,17 @@ WriteResult RowWriterV2::write(ssize_t index, const char* v) { return write(index, folly::StringPiece(v)); } -WriteResult RowWriterV2::write(ssize_t index, folly::StringPiece v) { +WriteResult RowWriterV2::write(ssize_t index, folly::StringPiece v, bool isWKB) { auto field = schema_->field(index); auto offset = headerLen_ + numNullBytes_ + field->offset(); switch (field->type()) { - case PropertyType::GEOGRAPHY: // write wkb + case PropertyType::GEOGRAPHY: { + // If v is a not a WKB string, we need report error. + if (!isWKB) { + return WriteResult::TYPE_MISMATCH; + } + [[fallthrough]]; + } case PropertyType::STRING: { if (isSet_[index]) { // 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) { folly::to(geoShape) != folly::to(v.shape())) { return WriteResult::TYPE_MISMATCH; } + // Geography is stored as WKB format. + // WKB is a binary string. std::string wkb = v.asWKB(); - return write(index, folly::StringPiece(wkb)); + return write(index, folly::StringPiece(wkb), true); } WriteResult RowWriterV2::checkUnsetFields() { diff --git a/src/codec/RowWriterV2.h b/src/codec/RowWriterV2.h index 2d46d6b505a..6c544d0c392 100644 --- a/src/codec/RowWriterV2.h +++ b/src/codec/RowWriterV2.h @@ -254,7 +254,7 @@ class RowWriterV2 { WriteResult write(ssize_t index, uint64_t v); WriteResult write(ssize_t index, const std::string& v); - WriteResult write(ssize_t index, folly::StringPiece v); + WriteResult write(ssize_t index, folly::StringPiece v, bool isWKB = false); WriteResult write(ssize_t index, const char* v); WriteResult write(ssize_t index, const Date& v); diff --git a/tests/tck/features/geo/GeoBase.feature b/tests/tck/features/geo/GeoBase.feature index 0c7a0640a7e..35861c365b4 100644 --- a/tests/tck/features/geo/GeoBase.feature +++ b/tests/tck/features/geo/GeoBase.feature @@ -127,6 +127,14 @@ Feature: Geo base INSERT VERTEX any_shape(geo) VALUES "103":(ST_GeogFromText("POLYGON((0 1, 1 2, 2 3, 0 1))")); """ Then the execution should be successful + # "POINT(3 8)" is a string not a geography literal. + # We must use some geography costructor function to construct a geography literal. + # e.g.`ST_GeogFromText("POINT(3 8)")` + When executing query: + """ + INSERT VERTEX any_shape(geo) VALUES "104":("POINT(3 8)"); + """ + Then a ExecutionError should be raised at runtime: Storage Error: The data type does not meet the requirements. Use the correct type of data. # Only point is allowed to insert to the column geograph(point) When executing query: """