Skip to content

Commit

Permalink
fix ParseStringToValueOfFieldType error
Browse files Browse the repository at this point in the history
  • Loading branch information
hanwen-sun committed Sep 20, 2023
1 parent 691a4cd commit bee171e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
5 changes: 3 additions & 2 deletions include/lgraph/lgraph_spatial.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
* TODO:
* 1. 进一步通过测试样例检查ParseStringToValueOfFieldType与TryFieldDataToValueOfFieldType
* 实现的正确性(空间数据与string数据的转换);
* 2. FieldType2CType无法实现空间数据相关功能, 目前绕开实现。
* 3. 确认line与Polygon调用_SetVariableLengthValue实现正确。
* 2. EWKB的压缩格式, 空间数据在schema层面的压缩存储, 如果易于计算;
* 3. 更完善易读的注释;
* 4. 利用FieldType2CType更简洁实现空间数据相关功能;
*/

#pragma once
Expand Down
8 changes: 4 additions & 4 deletions src/core/field_extractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ void FieldExtractor::ParseAndSet(Value& record, const FieldData& data) const {
throw ParseFieldDataException(Name(), data, Type());
FMA_DBG_ASSERT(!is_vfield_);
if (!::lgraph_api::TryDecodeEWKB(*data.data.buf, ::lgraph_api::SpatialType::POINT))
throw ParseStringException(Name(), *data.data.buf, FieldType::SPATIAL);

throw ParseStringException(Name(), *data.data.buf, FieldType::POINTWGS84);
// TODO(shw): throw pointwgs84 or cartesian?
record.Resize(record.Size());
char* ptr = (char*)record.Data() + offset_.data_off;
memcpy(ptr, (*data.data.buf).data(), 50);
Expand All @@ -248,7 +248,7 @@ void FieldExtractor::ParseAndSet(Value& record, const FieldData& data) const {
FieldType::LINESTRINGCARTESIAN && data.type != FieldType::STRING)
throw ParseFieldDataException(Name(), data, Type());
if (!::lgraph_api::TryDecodeEWKB(*data.data.buf, ::lgraph_api::SpatialType::LINESTRING))
throw ParseStringException(Name(), *data.data.buf, FieldType::SPATIAL);
throw ParseStringException(Name(), *data.data.buf, FieldType::LINESTRINGWGS84);

return _SetVariableLengthValue(record, Value::ConstRef(*data.data.buf));
}
Expand All @@ -259,7 +259,7 @@ void FieldExtractor::ParseAndSet(Value& record, const FieldData& data) const {
&& data.type != FieldType::STRING)
throw ParseFieldDataException(Name(), data, Type());
if (!::lgraph_api::TryDecodeEWKB(*data.data.buf, ::lgraph_api::SpatialType::POLYGON))
throw ParseStringException(Name(), *data.data.buf, FieldType::SPATIAL);
throw ParseStringException(Name(), *data.data.buf, FieldType::POLYGONWGS84);

return _SetVariableLengthValue(record, Value::ConstRef(*data.data.buf));
}
Expand Down
12 changes: 8 additions & 4 deletions test/test_field_data_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,16 @@ TEST_F(TestFieldDataHelper, ParseStringToValueOfFieldType) {
_TEST_PARSE_TO_V_OF_FT(DATETIME, "1000-01-01 01:01:01",
DateTime("1000-01-01 01:01:01").MicroSecondsSinceEpoch());
_TEST_PARSE_TO_V_OF_FT(BLOB, "aGVsbG9zdHJpbmc=", "hellostring");
UT_LOG() << "Testing point";
_TEST_PARSE_TO_V_OF_FT(POINTWGS84, "0101000020E6100000000000000000F03F0000000000000040",
"0101000020E6100000000000000000F03F0000000000000040");
_TEST_PARSE_TO_V_OF_FT(LINESTRINGCARTESIAN, "0102000020231C00000300000000000000000000000000"
"0000000000000000000000000040000000000000004000000000000008400000000",
"0102000020231C00000300000000000000000000000000"
"0000000000000000000000000040000000000000004000000000000008400000000");
UT_LOG() << "Testing linestring";
_TEST_PARSE_TO_V_OF_FT(LINESTRINGCARTESIAN,
"0102000020231C00000300000000000000000000000000000000000000000"
"000000000004000000000000000400000000000000840000000000000F03F",
"0102000020231C00000300000000000000000000000000000000000000000"
"000000000004000000000000000400000000000000840000000000000F03F");
UT_LOG() << "Testing Polygon";
_TEST_PARSE_TO_V_OF_FT(POLYGONWGS84, "0103000020E6100000010000000500000000000000000000000000"
"00000000000000000000000000000000000000001C400000000000001040000000000"
"00000400000000000000040000000000000000000000000000000000000000000000",
Expand Down

0 comments on commit bee171e

Please sign in to comment.