github-actions[bot] commented on code in PR #25030: URL: https://github.com/apache/doris/pull/25030#discussion_r1341967980
########## be/src/geo/geo_tobinary.cpp: ########## @@ -69,29 +81,56 @@ bool toBinary::write(GeoShape* shape, ToBinaryContext* ctx) { bool toBinary::writeGeoPoint(GeoPoint* point, ToBinaryContext* ctx) { writeByteOrder(ctx); writeGeometryType(wkbType::wkbPoint, ctx); - GeoCoordinateList p = point->to_coords(); - - writeCoordinateList(p, false, ctx); + if (point->is_empty()) { + GeoCoordinate c(DoubleNotANumber, DoubleNotANumber); Review Comment: warning: no matching constructor for initialization of 'doris::GeoCoordinate' [clang-diagnostic-error] ```cpp GeoCoordinate c(DoubleNotANumber, DoubleNotANumber); ^ ``` <details> <summary>Additional context</summary> **be/src/geo/wkt_parse_type.h:24:** candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 2 were provided ```cpp struct GeoCoordinate { ^ ``` **be/src/geo/wkt_parse_type.h:24:** candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 2 were provided ```cpp struct GeoCoordinate { ^ ``` **be/src/geo/wkt_parse_type.h:24:** candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 2 were provided ```cpp struct GeoCoordinate { ^ ``` </details> ########## be/src/geo/geo_tojson.h: ########## @@ -0,0 +1,78 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include <rapidjson/allocators.h> Review Comment: warning: 'rapidjson/allocators.h' file not found [clang-diagnostic-error] ```cpp #include <rapidjson/allocators.h> ^ ``` ########## be/src/geo/geojson_parse.cpp: ########## @@ -0,0 +1,259 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "geojson_parse.h" + +#include <stdint.h> + +#include <memory> + +#include "rapidjson/document.h" +#include "util/GeoCollection.h" +#include "util/GeoLineString.h" +#include "util/GeoMultiLineString.h" +#include "util/GeoMultiPoint.h" +#include "util/GeoMultiPolygon.h" +#include "util/GeoPoint.h" +#include "util/GeoPolygon.h" +#include "util/GeoShape.h" + +namespace doris { +GeoParseStatus GeoJsonParse::parse_geojson(std::string& geojson, GeoShape** shape) { + rapidjson::Document document; + document.Parse(geojson.c_str()); + + // 判断解析是否成功 + if (document.HasParseError()) { + return GEO_PARSE_GEOJSON_SYNTAX_ERROR; + } + GeoParseStatus parse_status; + + *shape = read_geometry(document, parse_status).release(); + + return parse_status; +} + +std::unique_ptr<GeoShape> GeoJsonParse::read_geometry(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoShape> shape; + if (document.HasMember("type") && document["type"].IsString()) { + std::string type = document["type"].GetString(); + if (type == "Point") { + shape.reset(read_point(document, parse_status).release()); + } else if (type == "LineString") { + shape.reset(read_linestring(document, parse_status).release()); + } else if (type == "Polygon") { + shape.reset(read_polygon(document, parse_status).release()); + } else if (type == "MultiPoint") { + shape.reset(read_multi_point(document, parse_status).release()); + } else if (type == "MultiLineString") { + shape.reset(read_multi_linestring(document, parse_status).release()); + } else if (type == "MultiPolygon") { + shape.reset(read_multi_polygon(document, parse_status).release()); + } else if (type == "GeometryCollection") { + shape.reset(read_geometry_collection(document, parse_status).release()); + } else { + return nullptr; + } + } + return shape; +} + +std::unique_ptr<GeoPoint> GeoJsonParse::read_point(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoPoint> point = GeoPoint::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + point->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinate> coord = + read_coordinate(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = point->from_coord(*coord); + } + } + } + return point; +} + +std::unique_ptr<GeoLineString> GeoJsonParse::read_linestring(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoLineString> linestring = GeoLineString::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + linestring->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinates> coords = + read_coordinates(document["coordinates"], parse_status); Review Comment: warning: variable 'coords' is not initialized [cppcoreguidelines-init-variables] ```suggestion nates> coords = 0 = ``` ########## be/src/geo/geo_tobinary.cpp: ########## @@ -135,5 +173,23 @@ void toBinary::writeCoordinate(GeoCoordinate& coords, ToBinaryContext* ctx) { ByteOrderValues::putDouble(coords.y, ctx->buf, ctx->byteOrder); ctx->outStream->write(reinterpret_cast<char*>(ctx->buf), 8); } +std::string toBinary::to_hex(std::string binary) { + std::stringstream wkb_binary; + const char* data = binary.data(); + + for (int i = 0; i < binary.size(); ++i) { + wkb_binary << *data; + data++; + } + + std::stringstream hex_stream; + hex_stream << std::hex << std::setfill('0'); + wkb_binary.seekg(0); + unsigned char c; Review Comment: warning: variable 'c' is not initialized [cppcoreguidelines-init-variables] ```suggestion unsigned char c = 0; ``` ########## be/src/geo/geojson_parse.cpp: ########## @@ -0,0 +1,259 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "geojson_parse.h" + +#include <stdint.h> + +#include <memory> + +#include "rapidjson/document.h" +#include "util/GeoCollection.h" +#include "util/GeoLineString.h" +#include "util/GeoMultiLineString.h" +#include "util/GeoMultiPoint.h" +#include "util/GeoMultiPolygon.h" +#include "util/GeoPoint.h" +#include "util/GeoPolygon.h" +#include "util/GeoShape.h" + +namespace doris { +GeoParseStatus GeoJsonParse::parse_geojson(std::string& geojson, GeoShape** shape) { + rapidjson::Document document; + document.Parse(geojson.c_str()); + + // 判断解析是否成功 + if (document.HasParseError()) { + return GEO_PARSE_GEOJSON_SYNTAX_ERROR; + } + GeoParseStatus parse_status; + + *shape = read_geometry(document, parse_status).release(); Review Comment: warning: variable 'parse_status' is not initialized [cppcoreguidelines-init-variables] ```cpp parse_status; ^ ``` ########## be/src/geo/geojson_parse.cpp: ########## @@ -0,0 +1,259 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "geojson_parse.h" + +#include <stdint.h> + +#include <memory> + +#include "rapidjson/document.h" +#include "util/GeoCollection.h" +#include "util/GeoLineString.h" +#include "util/GeoMultiLineString.h" +#include "util/GeoMultiPoint.h" +#include "util/GeoMultiPolygon.h" +#include "util/GeoPoint.h" +#include "util/GeoPolygon.h" +#include "util/GeoShape.h" + +namespace doris { +GeoParseStatus GeoJsonParse::parse_geojson(std::string& geojson, GeoShape** shape) { + rapidjson::Document document; + document.Parse(geojson.c_str()); + + // 判断解析是否成功 + if (document.HasParseError()) { + return GEO_PARSE_GEOJSON_SYNTAX_ERROR; + } + GeoParseStatus parse_status; + + *shape = read_geometry(document, parse_status).release(); + + return parse_status; +} + +std::unique_ptr<GeoShape> GeoJsonParse::read_geometry(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoShape> shape; + if (document.HasMember("type") && document["type"].IsString()) { Review Comment: warning: variable 'shape' is not initialized [cppcoreguidelines-init-variables] ```suggestion eoShape> shape = 0; ``` ########## be/src/geo/geojson_parse.cpp: ########## @@ -0,0 +1,259 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "geojson_parse.h" + +#include <stdint.h> + +#include <memory> + +#include "rapidjson/document.h" +#include "util/GeoCollection.h" +#include "util/GeoLineString.h" +#include "util/GeoMultiLineString.h" +#include "util/GeoMultiPoint.h" +#include "util/GeoMultiPolygon.h" +#include "util/GeoPoint.h" +#include "util/GeoPolygon.h" +#include "util/GeoShape.h" + +namespace doris { +GeoParseStatus GeoJsonParse::parse_geojson(std::string& geojson, GeoShape** shape) { + rapidjson::Document document; Review Comment: warning: variable 'document' is not initialized [cppcoreguidelines-init-variables] ```suggestion rapidjson::Document document = 0; ``` ########## be/src/geo/geojson_parse.cpp: ########## @@ -0,0 +1,259 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "geojson_parse.h" + +#include <stdint.h> + +#include <memory> + +#include "rapidjson/document.h" +#include "util/GeoCollection.h" +#include "util/GeoLineString.h" +#include "util/GeoMultiLineString.h" +#include "util/GeoMultiPoint.h" +#include "util/GeoMultiPolygon.h" +#include "util/GeoPoint.h" +#include "util/GeoPolygon.h" +#include "util/GeoShape.h" + +namespace doris { +GeoParseStatus GeoJsonParse::parse_geojson(std::string& geojson, GeoShape** shape) { + rapidjson::Document document; + document.Parse(geojson.c_str()); + + // 判断解析是否成功 + if (document.HasParseError()) { + return GEO_PARSE_GEOJSON_SYNTAX_ERROR; + } + GeoParseStatus parse_status; + + *shape = read_geometry(document, parse_status).release(); + + return parse_status; +} + +std::unique_ptr<GeoShape> GeoJsonParse::read_geometry(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoShape> shape; + if (document.HasMember("type") && document["type"].IsString()) { + std::string type = document["type"].GetString(); + if (type == "Point") { + shape.reset(read_point(document, parse_status).release()); + } else if (type == "LineString") { + shape.reset(read_linestring(document, parse_status).release()); + } else if (type == "Polygon") { + shape.reset(read_polygon(document, parse_status).release()); + } else if (type == "MultiPoint") { + shape.reset(read_multi_point(document, parse_status).release()); + } else if (type == "MultiLineString") { + shape.reset(read_multi_linestring(document, parse_status).release()); + } else if (type == "MultiPolygon") { + shape.reset(read_multi_polygon(document, parse_status).release()); + } else if (type == "GeometryCollection") { + shape.reset(read_geometry_collection(document, parse_status).release()); + } else { + return nullptr; + } + } + return shape; +} + +std::unique_ptr<GeoPoint> GeoJsonParse::read_point(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoPoint> point = GeoPoint::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + point->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinate> coord = + read_coordinate(document["coordinates"], parse_status); Review Comment: warning: variable 'coord' is not initialized [cppcoreguidelines-init-variables] ```suggestion dinate> coord = 0 = ``` ########## be/src/geo/geojson_parse.cpp: ########## @@ -0,0 +1,259 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "geojson_parse.h" + +#include <stdint.h> + +#include <memory> + +#include "rapidjson/document.h" +#include "util/GeoCollection.h" +#include "util/GeoLineString.h" +#include "util/GeoMultiLineString.h" +#include "util/GeoMultiPoint.h" +#include "util/GeoMultiPolygon.h" +#include "util/GeoPoint.h" +#include "util/GeoPolygon.h" +#include "util/GeoShape.h" + +namespace doris { +GeoParseStatus GeoJsonParse::parse_geojson(std::string& geojson, GeoShape** shape) { + rapidjson::Document document; + document.Parse(geojson.c_str()); + + // 判断解析是否成功 + if (document.HasParseError()) { + return GEO_PARSE_GEOJSON_SYNTAX_ERROR; + } + GeoParseStatus parse_status; + + *shape = read_geometry(document, parse_status).release(); + + return parse_status; +} + +std::unique_ptr<GeoShape> GeoJsonParse::read_geometry(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoShape> shape; + if (document.HasMember("type") && document["type"].IsString()) { + std::string type = document["type"].GetString(); + if (type == "Point") { + shape.reset(read_point(document, parse_status).release()); + } else if (type == "LineString") { + shape.reset(read_linestring(document, parse_status).release()); + } else if (type == "Polygon") { + shape.reset(read_polygon(document, parse_status).release()); + } else if (type == "MultiPoint") { + shape.reset(read_multi_point(document, parse_status).release()); + } else if (type == "MultiLineString") { + shape.reset(read_multi_linestring(document, parse_status).release()); + } else if (type == "MultiPolygon") { + shape.reset(read_multi_polygon(document, parse_status).release()); + } else if (type == "GeometryCollection") { + shape.reset(read_geometry_collection(document, parse_status).release()); + } else { + return nullptr; + } + } + return shape; +} + +std::unique_ptr<GeoPoint> GeoJsonParse::read_point(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoPoint> point = GeoPoint::create_unique(); Review Comment: warning: variable 'point' is not initialized [cppcoreguidelines-init-variables] ```suggestion parse_status) { = 0 ``` ########## be/src/geo/geojson_parse.cpp: ########## @@ -0,0 +1,259 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "geojson_parse.h" + +#include <stdint.h> + +#include <memory> + +#include "rapidjson/document.h" +#include "util/GeoCollection.h" +#include "util/GeoLineString.h" +#include "util/GeoMultiLineString.h" +#include "util/GeoMultiPoint.h" +#include "util/GeoMultiPolygon.h" +#include "util/GeoPoint.h" +#include "util/GeoPolygon.h" +#include "util/GeoShape.h" + +namespace doris { +GeoParseStatus GeoJsonParse::parse_geojson(std::string& geojson, GeoShape** shape) { + rapidjson::Document document; + document.Parse(geojson.c_str()); + + // 判断解析是否成功 + if (document.HasParseError()) { + return GEO_PARSE_GEOJSON_SYNTAX_ERROR; + } + GeoParseStatus parse_status; + + *shape = read_geometry(document, parse_status).release(); + + return parse_status; +} + +std::unique_ptr<GeoShape> GeoJsonParse::read_geometry(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoShape> shape; + if (document.HasMember("type") && document["type"].IsString()) { + std::string type = document["type"].GetString(); + if (type == "Point") { + shape.reset(read_point(document, parse_status).release()); + } else if (type == "LineString") { + shape.reset(read_linestring(document, parse_status).release()); + } else if (type == "Polygon") { + shape.reset(read_polygon(document, parse_status).release()); + } else if (type == "MultiPoint") { + shape.reset(read_multi_point(document, parse_status).release()); + } else if (type == "MultiLineString") { + shape.reset(read_multi_linestring(document, parse_status).release()); + } else if (type == "MultiPolygon") { + shape.reset(read_multi_polygon(document, parse_status).release()); + } else if (type == "GeometryCollection") { + shape.reset(read_geometry_collection(document, parse_status).release()); + } else { + return nullptr; + } + } + return shape; +} + +std::unique_ptr<GeoPoint> GeoJsonParse::read_point(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoPoint> point = GeoPoint::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + point->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinate> coord = + read_coordinate(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = point->from_coord(*coord); + } + } + } + return point; +} + +std::unique_ptr<GeoLineString> GeoJsonParse::read_linestring(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoLineString> linestring = GeoLineString::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + linestring->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinates> coords = + read_coordinates(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = linestring->from_coords(*coords); + } + } + } + return linestring; +} + +std::unique_ptr<GeoPolygon> GeoJsonParse::read_polygon(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoPolygon> polygon = GeoPolygon::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + polygon->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinateLists> coords_list = + read_coords_list(document["coordinates"], parse_status); Review Comment: warning: variable 'coords_list' is not initialized [cppcoreguidelines-init-variables] ```suggestion > coords_list = 0 = ``` ########## be/src/geo/geojson_parse.cpp: ########## @@ -0,0 +1,259 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "geojson_parse.h" + +#include <stdint.h> + +#include <memory> + +#include "rapidjson/document.h" +#include "util/GeoCollection.h" +#include "util/GeoLineString.h" +#include "util/GeoMultiLineString.h" +#include "util/GeoMultiPoint.h" +#include "util/GeoMultiPolygon.h" +#include "util/GeoPoint.h" +#include "util/GeoPolygon.h" +#include "util/GeoShape.h" + +namespace doris { +GeoParseStatus GeoJsonParse::parse_geojson(std::string& geojson, GeoShape** shape) { + rapidjson::Document document; + document.Parse(geojson.c_str()); + + // 判断解析是否成功 + if (document.HasParseError()) { + return GEO_PARSE_GEOJSON_SYNTAX_ERROR; + } + GeoParseStatus parse_status; + + *shape = read_geometry(document, parse_status).release(); + + return parse_status; +} + +std::unique_ptr<GeoShape> GeoJsonParse::read_geometry(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoShape> shape; + if (document.HasMember("type") && document["type"].IsString()) { + std::string type = document["type"].GetString(); + if (type == "Point") { + shape.reset(read_point(document, parse_status).release()); + } else if (type == "LineString") { + shape.reset(read_linestring(document, parse_status).release()); + } else if (type == "Polygon") { + shape.reset(read_polygon(document, parse_status).release()); + } else if (type == "MultiPoint") { + shape.reset(read_multi_point(document, parse_status).release()); + } else if (type == "MultiLineString") { + shape.reset(read_multi_linestring(document, parse_status).release()); + } else if (type == "MultiPolygon") { + shape.reset(read_multi_polygon(document, parse_status).release()); + } else if (type == "GeometryCollection") { + shape.reset(read_geometry_collection(document, parse_status).release()); + } else { + return nullptr; + } + } + return shape; +} + +std::unique_ptr<GeoPoint> GeoJsonParse::read_point(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoPoint> point = GeoPoint::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + point->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinate> coord = + read_coordinate(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = point->from_coord(*coord); + } + } + } + return point; +} + +std::unique_ptr<GeoLineString> GeoJsonParse::read_linestring(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoLineString> linestring = GeoLineString::create_unique(); Review Comment: warning: variable 'linestring' is not initialized [cppcoreguidelines-init-variables] ```suggestion parse_status) { = 0 ``` ########## be/src/geo/geojson_parse.cpp: ########## @@ -0,0 +1,259 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "geojson_parse.h" + +#include <stdint.h> + +#include <memory> + +#include "rapidjson/document.h" +#include "util/GeoCollection.h" +#include "util/GeoLineString.h" +#include "util/GeoMultiLineString.h" +#include "util/GeoMultiPoint.h" +#include "util/GeoMultiPolygon.h" +#include "util/GeoPoint.h" +#include "util/GeoPolygon.h" +#include "util/GeoShape.h" + +namespace doris { +GeoParseStatus GeoJsonParse::parse_geojson(std::string& geojson, GeoShape** shape) { + rapidjson::Document document; + document.Parse(geojson.c_str()); + + // 判断解析是否成功 + if (document.HasParseError()) { + return GEO_PARSE_GEOJSON_SYNTAX_ERROR; + } + GeoParseStatus parse_status; + + *shape = read_geometry(document, parse_status).release(); + + return parse_status; +} + +std::unique_ptr<GeoShape> GeoJsonParse::read_geometry(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoShape> shape; + if (document.HasMember("type") && document["type"].IsString()) { + std::string type = document["type"].GetString(); + if (type == "Point") { + shape.reset(read_point(document, parse_status).release()); + } else if (type == "LineString") { + shape.reset(read_linestring(document, parse_status).release()); + } else if (type == "Polygon") { + shape.reset(read_polygon(document, parse_status).release()); + } else if (type == "MultiPoint") { + shape.reset(read_multi_point(document, parse_status).release()); + } else if (type == "MultiLineString") { + shape.reset(read_multi_linestring(document, parse_status).release()); + } else if (type == "MultiPolygon") { + shape.reset(read_multi_polygon(document, parse_status).release()); + } else if (type == "GeometryCollection") { + shape.reset(read_geometry_collection(document, parse_status).release()); + } else { + return nullptr; + } + } + return shape; +} + +std::unique_ptr<GeoPoint> GeoJsonParse::read_point(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoPoint> point = GeoPoint::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + point->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinate> coord = + read_coordinate(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = point->from_coord(*coord); + } + } + } + return point; +} + +std::unique_ptr<GeoLineString> GeoJsonParse::read_linestring(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoLineString> linestring = GeoLineString::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + linestring->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinates> coords = + read_coordinates(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = linestring->from_coords(*coords); + } + } + } + return linestring; +} + +std::unique_ptr<GeoPolygon> GeoJsonParse::read_polygon(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoPolygon> polygon = GeoPolygon::create_unique(); Review Comment: warning: variable 'polygon' is not initialized [cppcoreguidelines-init-variables] ```suggestion parse_status) { = 0 ``` ########## be/src/geo/geojson_parse.cpp: ########## @@ -0,0 +1,259 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "geojson_parse.h" + +#include <stdint.h> + +#include <memory> + +#include "rapidjson/document.h" +#include "util/GeoCollection.h" +#include "util/GeoLineString.h" +#include "util/GeoMultiLineString.h" +#include "util/GeoMultiPoint.h" +#include "util/GeoMultiPolygon.h" +#include "util/GeoPoint.h" +#include "util/GeoPolygon.h" +#include "util/GeoShape.h" + +namespace doris { +GeoParseStatus GeoJsonParse::parse_geojson(std::string& geojson, GeoShape** shape) { + rapidjson::Document document; + document.Parse(geojson.c_str()); + + // 判断解析是否成功 + if (document.HasParseError()) { + return GEO_PARSE_GEOJSON_SYNTAX_ERROR; + } + GeoParseStatus parse_status; + + *shape = read_geometry(document, parse_status).release(); + + return parse_status; +} + +std::unique_ptr<GeoShape> GeoJsonParse::read_geometry(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoShape> shape; + if (document.HasMember("type") && document["type"].IsString()) { + std::string type = document["type"].GetString(); + if (type == "Point") { + shape.reset(read_point(document, parse_status).release()); + } else if (type == "LineString") { + shape.reset(read_linestring(document, parse_status).release()); + } else if (type == "Polygon") { + shape.reset(read_polygon(document, parse_status).release()); + } else if (type == "MultiPoint") { + shape.reset(read_multi_point(document, parse_status).release()); + } else if (type == "MultiLineString") { + shape.reset(read_multi_linestring(document, parse_status).release()); + } else if (type == "MultiPolygon") { + shape.reset(read_multi_polygon(document, parse_status).release()); + } else if (type == "GeometryCollection") { + shape.reset(read_geometry_collection(document, parse_status).release()); + } else { + return nullptr; + } + } + return shape; +} + +std::unique_ptr<GeoPoint> GeoJsonParse::read_point(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoPoint> point = GeoPoint::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + point->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinate> coord = + read_coordinate(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = point->from_coord(*coord); + } + } + } + return point; +} + +std::unique_ptr<GeoLineString> GeoJsonParse::read_linestring(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoLineString> linestring = GeoLineString::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + linestring->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinates> coords = + read_coordinates(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = linestring->from_coords(*coords); + } + } + } + return linestring; +} + +std::unique_ptr<GeoPolygon> GeoJsonParse::read_polygon(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoPolygon> polygon = GeoPolygon::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + polygon->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinateLists> coords_list = + read_coords_list(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = polygon->from_coords(*coords_list); + } + } + } + return polygon; +} + +std::unique_ptr<GeoMultiPoint> GeoJsonParse::read_multi_point(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoMultiPoint> multi_point = GeoMultiPoint::create_unique(); Review Comment: warning: variable 'multi_point' is not initialized [cppcoreguidelines-init-variables] ```suggestion parse_status) { = 0 ``` ########## be/src/geo/geojson_parse.cpp: ########## @@ -0,0 +1,259 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "geojson_parse.h" + +#include <stdint.h> + +#include <memory> + +#include "rapidjson/document.h" +#include "util/GeoCollection.h" +#include "util/GeoLineString.h" +#include "util/GeoMultiLineString.h" +#include "util/GeoMultiPoint.h" +#include "util/GeoMultiPolygon.h" +#include "util/GeoPoint.h" +#include "util/GeoPolygon.h" +#include "util/GeoShape.h" + +namespace doris { +GeoParseStatus GeoJsonParse::parse_geojson(std::string& geojson, GeoShape** shape) { + rapidjson::Document document; + document.Parse(geojson.c_str()); + + // 判断解析是否成功 + if (document.HasParseError()) { + return GEO_PARSE_GEOJSON_SYNTAX_ERROR; + } + GeoParseStatus parse_status; + + *shape = read_geometry(document, parse_status).release(); + + return parse_status; +} + +std::unique_ptr<GeoShape> GeoJsonParse::read_geometry(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoShape> shape; + if (document.HasMember("type") && document["type"].IsString()) { + std::string type = document["type"].GetString(); + if (type == "Point") { + shape.reset(read_point(document, parse_status).release()); + } else if (type == "LineString") { + shape.reset(read_linestring(document, parse_status).release()); + } else if (type == "Polygon") { + shape.reset(read_polygon(document, parse_status).release()); + } else if (type == "MultiPoint") { + shape.reset(read_multi_point(document, parse_status).release()); + } else if (type == "MultiLineString") { + shape.reset(read_multi_linestring(document, parse_status).release()); + } else if (type == "MultiPolygon") { + shape.reset(read_multi_polygon(document, parse_status).release()); + } else if (type == "GeometryCollection") { + shape.reset(read_geometry_collection(document, parse_status).release()); + } else { + return nullptr; + } + } + return shape; +} + +std::unique_ptr<GeoPoint> GeoJsonParse::read_point(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoPoint> point = GeoPoint::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + point->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinate> coord = + read_coordinate(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = point->from_coord(*coord); + } + } + } + return point; +} + +std::unique_ptr<GeoLineString> GeoJsonParse::read_linestring(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoLineString> linestring = GeoLineString::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + linestring->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinates> coords = + read_coordinates(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = linestring->from_coords(*coords); + } + } + } + return linestring; +} + +std::unique_ptr<GeoPolygon> GeoJsonParse::read_polygon(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoPolygon> polygon = GeoPolygon::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + polygon->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinateLists> coords_list = + read_coords_list(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = polygon->from_coords(*coords_list); + } + } + } + return polygon; +} + +std::unique_ptr<GeoMultiPoint> GeoJsonParse::read_multi_point(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoMultiPoint> multi_point = GeoMultiPoint::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + multi_point->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinates> coords = + read_coordinates(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = multi_point->from_coords(*coords); + } + } + } + return multi_point; +} + +std::unique_ptr<GeoMultiLineString> GeoJsonParse::read_multi_linestring( + rapidjson::Document& document, GeoParseStatus& parse_status) { + std::unique_ptr<GeoMultiLineString> multi_linestring = GeoMultiLineString::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + multi_linestring->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinateLists> coords_list = + read_coords_list(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = multi_linestring->from_coords(*coords_list); + } + } + } + return multi_linestring; +} + +std::unique_ptr<GeoMultiPolygon> GeoJsonParse::read_multi_polygon(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoMultiPolygon> multi_polygon = GeoMultiPolygon::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + multi_polygon->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinateListCollections> coords_list_collections = Review Comment: warning: variable 'coords_list_collections' is not initialized [cppcoreguidelines-init-variables] be/src/geo/geojson_parse.cpp:174: ```diff - t_collections = + t_collections = 0 = ``` ########## be/src/geo/geojson_parse.cpp: ########## @@ -0,0 +1,259 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "geojson_parse.h" + +#include <stdint.h> + +#include <memory> + +#include "rapidjson/document.h" +#include "util/GeoCollection.h" +#include "util/GeoLineString.h" +#include "util/GeoMultiLineString.h" +#include "util/GeoMultiPoint.h" +#include "util/GeoMultiPolygon.h" +#include "util/GeoPoint.h" +#include "util/GeoPolygon.h" +#include "util/GeoShape.h" + +namespace doris { +GeoParseStatus GeoJsonParse::parse_geojson(std::string& geojson, GeoShape** shape) { + rapidjson::Document document; + document.Parse(geojson.c_str()); + + // 判断解析是否成功 + if (document.HasParseError()) { + return GEO_PARSE_GEOJSON_SYNTAX_ERROR; + } + GeoParseStatus parse_status; + + *shape = read_geometry(document, parse_status).release(); + + return parse_status; +} + +std::unique_ptr<GeoShape> GeoJsonParse::read_geometry(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoShape> shape; + if (document.HasMember("type") && document["type"].IsString()) { + std::string type = document["type"].GetString(); + if (type == "Point") { + shape.reset(read_point(document, parse_status).release()); + } else if (type == "LineString") { + shape.reset(read_linestring(document, parse_status).release()); + } else if (type == "Polygon") { + shape.reset(read_polygon(document, parse_status).release()); + } else if (type == "MultiPoint") { + shape.reset(read_multi_point(document, parse_status).release()); + } else if (type == "MultiLineString") { + shape.reset(read_multi_linestring(document, parse_status).release()); + } else if (type == "MultiPolygon") { + shape.reset(read_multi_polygon(document, parse_status).release()); + } else if (type == "GeometryCollection") { + shape.reset(read_geometry_collection(document, parse_status).release()); + } else { + return nullptr; + } + } + return shape; +} + +std::unique_ptr<GeoPoint> GeoJsonParse::read_point(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoPoint> point = GeoPoint::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + point->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinate> coord = + read_coordinate(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = point->from_coord(*coord); + } + } + } + return point; +} + +std::unique_ptr<GeoLineString> GeoJsonParse::read_linestring(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoLineString> linestring = GeoLineString::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + linestring->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinates> coords = + read_coordinates(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = linestring->from_coords(*coords); + } + } + } + return linestring; +} + +std::unique_ptr<GeoPolygon> GeoJsonParse::read_polygon(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoPolygon> polygon = GeoPolygon::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + polygon->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinateLists> coords_list = + read_coords_list(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = polygon->from_coords(*coords_list); + } + } + } + return polygon; +} + +std::unique_ptr<GeoMultiPoint> GeoJsonParse::read_multi_point(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoMultiPoint> multi_point = GeoMultiPoint::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + multi_point->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinates> coords = + read_coordinates(document["coordinates"], parse_status); Review Comment: warning: variable 'coords' is not initialized [cppcoreguidelines-init-variables] ```suggestion nates> coords = 0 = ``` ########## be/src/geo/geojson_parse.cpp: ########## @@ -0,0 +1,259 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "geojson_parse.h" + +#include <stdint.h> + +#include <memory> + +#include "rapidjson/document.h" +#include "util/GeoCollection.h" +#include "util/GeoLineString.h" +#include "util/GeoMultiLineString.h" +#include "util/GeoMultiPoint.h" +#include "util/GeoMultiPolygon.h" +#include "util/GeoPoint.h" +#include "util/GeoPolygon.h" +#include "util/GeoShape.h" + +namespace doris { +GeoParseStatus GeoJsonParse::parse_geojson(std::string& geojson, GeoShape** shape) { + rapidjson::Document document; + document.Parse(geojson.c_str()); + + // 判断解析是否成功 + if (document.HasParseError()) { + return GEO_PARSE_GEOJSON_SYNTAX_ERROR; + } + GeoParseStatus parse_status; + + *shape = read_geometry(document, parse_status).release(); + + return parse_status; +} + +std::unique_ptr<GeoShape> GeoJsonParse::read_geometry(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoShape> shape; + if (document.HasMember("type") && document["type"].IsString()) { + std::string type = document["type"].GetString(); + if (type == "Point") { + shape.reset(read_point(document, parse_status).release()); + } else if (type == "LineString") { + shape.reset(read_linestring(document, parse_status).release()); + } else if (type == "Polygon") { + shape.reset(read_polygon(document, parse_status).release()); + } else if (type == "MultiPoint") { + shape.reset(read_multi_point(document, parse_status).release()); + } else if (type == "MultiLineString") { + shape.reset(read_multi_linestring(document, parse_status).release()); + } else if (type == "MultiPolygon") { + shape.reset(read_multi_polygon(document, parse_status).release()); + } else if (type == "GeometryCollection") { + shape.reset(read_geometry_collection(document, parse_status).release()); + } else { + return nullptr; + } + } + return shape; +} + +std::unique_ptr<GeoPoint> GeoJsonParse::read_point(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoPoint> point = GeoPoint::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + point->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinate> coord = + read_coordinate(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = point->from_coord(*coord); + } + } + } + return point; +} + +std::unique_ptr<GeoLineString> GeoJsonParse::read_linestring(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoLineString> linestring = GeoLineString::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + linestring->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinates> coords = + read_coordinates(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = linestring->from_coords(*coords); + } + } + } + return linestring; +} + +std::unique_ptr<GeoPolygon> GeoJsonParse::read_polygon(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoPolygon> polygon = GeoPolygon::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + polygon->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinateLists> coords_list = + read_coords_list(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = polygon->from_coords(*coords_list); + } + } + } + return polygon; +} + +std::unique_ptr<GeoMultiPoint> GeoJsonParse::read_multi_point(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoMultiPoint> multi_point = GeoMultiPoint::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + multi_point->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinates> coords = + read_coordinates(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = multi_point->from_coords(*coords); + } + } + } + return multi_point; +} + +std::unique_ptr<GeoMultiLineString> GeoJsonParse::read_multi_linestring( + rapidjson::Document& document, GeoParseStatus& parse_status) { + std::unique_ptr<GeoMultiLineString> multi_linestring = GeoMultiLineString::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + multi_linestring->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinateLists> coords_list = + read_coords_list(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = multi_linestring->from_coords(*coords_list); + } + } + } + return multi_linestring; +} + +std::unique_ptr<GeoMultiPolygon> GeoJsonParse::read_multi_polygon(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoMultiPolygon> multi_polygon = GeoMultiPolygon::create_unique(); Review Comment: warning: variable 'multi_polygon' is not initialized [cppcoreguidelines-init-variables] ```suggestion parse_status) { = 0 ``` ########## be/src/geo/geojson_parse.cpp: ########## @@ -0,0 +1,259 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "geojson_parse.h" + +#include <stdint.h> + +#include <memory> + +#include "rapidjson/document.h" +#include "util/GeoCollection.h" +#include "util/GeoLineString.h" +#include "util/GeoMultiLineString.h" +#include "util/GeoMultiPoint.h" +#include "util/GeoMultiPolygon.h" +#include "util/GeoPoint.h" +#include "util/GeoPolygon.h" +#include "util/GeoShape.h" + +namespace doris { +GeoParseStatus GeoJsonParse::parse_geojson(std::string& geojson, GeoShape** shape) { + rapidjson::Document document; + document.Parse(geojson.c_str()); + + // 判断解析是否成功 + if (document.HasParseError()) { + return GEO_PARSE_GEOJSON_SYNTAX_ERROR; + } + GeoParseStatus parse_status; + + *shape = read_geometry(document, parse_status).release(); + + return parse_status; +} + +std::unique_ptr<GeoShape> GeoJsonParse::read_geometry(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoShape> shape; + if (document.HasMember("type") && document["type"].IsString()) { + std::string type = document["type"].GetString(); + if (type == "Point") { + shape.reset(read_point(document, parse_status).release()); + } else if (type == "LineString") { + shape.reset(read_linestring(document, parse_status).release()); + } else if (type == "Polygon") { + shape.reset(read_polygon(document, parse_status).release()); + } else if (type == "MultiPoint") { + shape.reset(read_multi_point(document, parse_status).release()); + } else if (type == "MultiLineString") { + shape.reset(read_multi_linestring(document, parse_status).release()); + } else if (type == "MultiPolygon") { + shape.reset(read_multi_polygon(document, parse_status).release()); + } else if (type == "GeometryCollection") { + shape.reset(read_geometry_collection(document, parse_status).release()); + } else { + return nullptr; + } + } + return shape; +} + +std::unique_ptr<GeoPoint> GeoJsonParse::read_point(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoPoint> point = GeoPoint::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + point->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinate> coord = + read_coordinate(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = point->from_coord(*coord); + } + } + } + return point; +} + +std::unique_ptr<GeoLineString> GeoJsonParse::read_linestring(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoLineString> linestring = GeoLineString::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + linestring->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinates> coords = + read_coordinates(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = linestring->from_coords(*coords); + } + } + } + return linestring; +} + +std::unique_ptr<GeoPolygon> GeoJsonParse::read_polygon(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoPolygon> polygon = GeoPolygon::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + polygon->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinateLists> coords_list = + read_coords_list(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = polygon->from_coords(*coords_list); + } + } + } + return polygon; +} + +std::unique_ptr<GeoMultiPoint> GeoJsonParse::read_multi_point(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoMultiPoint> multi_point = GeoMultiPoint::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + multi_point->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinates> coords = + read_coordinates(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = multi_point->from_coords(*coords); + } + } + } + return multi_point; +} + +std::unique_ptr<GeoMultiLineString> GeoJsonParse::read_multi_linestring( + rapidjson::Document& document, GeoParseStatus& parse_status) { + std::unique_ptr<GeoMultiLineString> multi_linestring = GeoMultiLineString::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + multi_linestring->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinateLists> coords_list = + read_coords_list(document["coordinates"], parse_status); Review Comment: warning: variable 'coords_list' is not initialized [cppcoreguidelines-init-variables] ```suggestion > coords_list = 0 = ``` ########## be/src/geo/geojson_parse.cpp: ########## @@ -0,0 +1,259 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "geojson_parse.h" + +#include <stdint.h> + +#include <memory> + +#include "rapidjson/document.h" +#include "util/GeoCollection.h" +#include "util/GeoLineString.h" +#include "util/GeoMultiLineString.h" +#include "util/GeoMultiPoint.h" +#include "util/GeoMultiPolygon.h" +#include "util/GeoPoint.h" +#include "util/GeoPolygon.h" +#include "util/GeoShape.h" + +namespace doris { +GeoParseStatus GeoJsonParse::parse_geojson(std::string& geojson, GeoShape** shape) { + rapidjson::Document document; + document.Parse(geojson.c_str()); + + // 判断解析是否成功 + if (document.HasParseError()) { + return GEO_PARSE_GEOJSON_SYNTAX_ERROR; + } + GeoParseStatus parse_status; + + *shape = read_geometry(document, parse_status).release(); + + return parse_status; +} + +std::unique_ptr<GeoShape> GeoJsonParse::read_geometry(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoShape> shape; + if (document.HasMember("type") && document["type"].IsString()) { + std::string type = document["type"].GetString(); + if (type == "Point") { + shape.reset(read_point(document, parse_status).release()); + } else if (type == "LineString") { + shape.reset(read_linestring(document, parse_status).release()); + } else if (type == "Polygon") { + shape.reset(read_polygon(document, parse_status).release()); + } else if (type == "MultiPoint") { + shape.reset(read_multi_point(document, parse_status).release()); + } else if (type == "MultiLineString") { + shape.reset(read_multi_linestring(document, parse_status).release()); + } else if (type == "MultiPolygon") { + shape.reset(read_multi_polygon(document, parse_status).release()); + } else if (type == "GeometryCollection") { + shape.reset(read_geometry_collection(document, parse_status).release()); + } else { + return nullptr; + } + } + return shape; +} + +std::unique_ptr<GeoPoint> GeoJsonParse::read_point(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoPoint> point = GeoPoint::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + point->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinate> coord = + read_coordinate(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = point->from_coord(*coord); + } + } + } + return point; +} + +std::unique_ptr<GeoLineString> GeoJsonParse::read_linestring(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoLineString> linestring = GeoLineString::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + linestring->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinates> coords = + read_coordinates(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = linestring->from_coords(*coords); + } + } + } + return linestring; +} + +std::unique_ptr<GeoPolygon> GeoJsonParse::read_polygon(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoPolygon> polygon = GeoPolygon::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + polygon->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinateLists> coords_list = + read_coords_list(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = polygon->from_coords(*coords_list); + } + } + } + return polygon; +} + +std::unique_ptr<GeoMultiPoint> GeoJsonParse::read_multi_point(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoMultiPoint> multi_point = GeoMultiPoint::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + multi_point->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinates> coords = + read_coordinates(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = multi_point->from_coords(*coords); + } + } + } + return multi_point; +} + +std::unique_ptr<GeoMultiLineString> GeoJsonParse::read_multi_linestring( + rapidjson::Document& document, GeoParseStatus& parse_status) { + std::unique_ptr<GeoMultiLineString> multi_linestring = GeoMultiLineString::create_unique(); Review Comment: warning: variable 'multi_linestring' is not initialized [cppcoreguidelines-init-variables] ```suggestion parse_status) { = 0 ``` ########## be/src/geo/geojson_parse.cpp: ########## @@ -0,0 +1,259 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "geojson_parse.h" + +#include <stdint.h> + +#include <memory> + +#include "rapidjson/document.h" +#include "util/GeoCollection.h" +#include "util/GeoLineString.h" +#include "util/GeoMultiLineString.h" +#include "util/GeoMultiPoint.h" +#include "util/GeoMultiPolygon.h" +#include "util/GeoPoint.h" +#include "util/GeoPolygon.h" +#include "util/GeoShape.h" + +namespace doris { +GeoParseStatus GeoJsonParse::parse_geojson(std::string& geojson, GeoShape** shape) { + rapidjson::Document document; + document.Parse(geojson.c_str()); + + // 判断解析是否成功 + if (document.HasParseError()) { + return GEO_PARSE_GEOJSON_SYNTAX_ERROR; + } + GeoParseStatus parse_status; + + *shape = read_geometry(document, parse_status).release(); + + return parse_status; +} + +std::unique_ptr<GeoShape> GeoJsonParse::read_geometry(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoShape> shape; + if (document.HasMember("type") && document["type"].IsString()) { + std::string type = document["type"].GetString(); + if (type == "Point") { + shape.reset(read_point(document, parse_status).release()); + } else if (type == "LineString") { + shape.reset(read_linestring(document, parse_status).release()); + } else if (type == "Polygon") { + shape.reset(read_polygon(document, parse_status).release()); + } else if (type == "MultiPoint") { + shape.reset(read_multi_point(document, parse_status).release()); + } else if (type == "MultiLineString") { + shape.reset(read_multi_linestring(document, parse_status).release()); + } else if (type == "MultiPolygon") { + shape.reset(read_multi_polygon(document, parse_status).release()); + } else if (type == "GeometryCollection") { + shape.reset(read_geometry_collection(document, parse_status).release()); + } else { + return nullptr; + } + } + return shape; +} + +std::unique_ptr<GeoPoint> GeoJsonParse::read_point(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoPoint> point = GeoPoint::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + point->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinate> coord = + read_coordinate(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = point->from_coord(*coord); + } + } + } + return point; +} + +std::unique_ptr<GeoLineString> GeoJsonParse::read_linestring(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoLineString> linestring = GeoLineString::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + linestring->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinates> coords = + read_coordinates(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = linestring->from_coords(*coords); + } + } + } + return linestring; +} + +std::unique_ptr<GeoPolygon> GeoJsonParse::read_polygon(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoPolygon> polygon = GeoPolygon::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + polygon->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinateLists> coords_list = + read_coords_list(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = polygon->from_coords(*coords_list); + } + } + } + return polygon; +} + +std::unique_ptr<GeoMultiPoint> GeoJsonParse::read_multi_point(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoMultiPoint> multi_point = GeoMultiPoint::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + multi_point->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinates> coords = + read_coordinates(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = multi_point->from_coords(*coords); + } + } + } + return multi_point; +} + +std::unique_ptr<GeoMultiLineString> GeoJsonParse::read_multi_linestring( + rapidjson::Document& document, GeoParseStatus& parse_status) { + std::unique_ptr<GeoMultiLineString> multi_linestring = GeoMultiLineString::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + multi_linestring->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinateLists> coords_list = + read_coords_list(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = multi_linestring->from_coords(*coords_list); + } + } + } + return multi_linestring; +} + +std::unique_ptr<GeoMultiPolygon> GeoJsonParse::read_multi_polygon(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoMultiPolygon> multi_polygon = GeoMultiPolygon::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + multi_polygon->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinateListCollections> coords_list_collections = + read_coords_list_collections(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = multi_polygon->from_coords(*coords_list_collections); + } + } + } + return multi_polygon; +} + +std::unique_ptr<GeoCollection> GeoJsonParse::read_geometry_collection( + rapidjson::Document& document, GeoParseStatus& parse_status) { + std::unique_ptr<GeoCollection> collection = GeoCollection::create_unique(); + if (document.HasMember("geometries") && document["geometries"].IsArray()) { + if (document["geometries"].Size() == 0) { + collection->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + for (std::size_t i = 0; i < document["geometries"].Size(); ++i) { + rapidjson::Document doc; + doc.CopyFrom(document["geometries"][i], doc.GetAllocator()); Review Comment: warning: variable 'doc' is not initialized [cppcoreguidelines-init-variables] ```suggestion ::Document doc = 0; ``` ########## be/src/geo/geojson_parse.cpp: ########## @@ -0,0 +1,259 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "geojson_parse.h" + +#include <stdint.h> + +#include <memory> + +#include "rapidjson/document.h" +#include "util/GeoCollection.h" +#include "util/GeoLineString.h" +#include "util/GeoMultiLineString.h" +#include "util/GeoMultiPoint.h" +#include "util/GeoMultiPolygon.h" +#include "util/GeoPoint.h" +#include "util/GeoPolygon.h" +#include "util/GeoShape.h" + +namespace doris { +GeoParseStatus GeoJsonParse::parse_geojson(std::string& geojson, GeoShape** shape) { + rapidjson::Document document; + document.Parse(geojson.c_str()); + + // 判断解析是否成功 + if (document.HasParseError()) { + return GEO_PARSE_GEOJSON_SYNTAX_ERROR; + } + GeoParseStatus parse_status; + + *shape = read_geometry(document, parse_status).release(); + + return parse_status; +} + +std::unique_ptr<GeoShape> GeoJsonParse::read_geometry(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoShape> shape; + if (document.HasMember("type") && document["type"].IsString()) { + std::string type = document["type"].GetString(); + if (type == "Point") { + shape.reset(read_point(document, parse_status).release()); + } else if (type == "LineString") { + shape.reset(read_linestring(document, parse_status).release()); + } else if (type == "Polygon") { + shape.reset(read_polygon(document, parse_status).release()); + } else if (type == "MultiPoint") { + shape.reset(read_multi_point(document, parse_status).release()); + } else if (type == "MultiLineString") { + shape.reset(read_multi_linestring(document, parse_status).release()); + } else if (type == "MultiPolygon") { + shape.reset(read_multi_polygon(document, parse_status).release()); + } else if (type == "GeometryCollection") { + shape.reset(read_geometry_collection(document, parse_status).release()); + } else { + return nullptr; + } + } + return shape; +} + +std::unique_ptr<GeoPoint> GeoJsonParse::read_point(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoPoint> point = GeoPoint::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + point->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinate> coord = + read_coordinate(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = point->from_coord(*coord); + } + } + } + return point; +} + +std::unique_ptr<GeoLineString> GeoJsonParse::read_linestring(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoLineString> linestring = GeoLineString::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + linestring->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinates> coords = + read_coordinates(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = linestring->from_coords(*coords); + } + } + } + return linestring; +} + +std::unique_ptr<GeoPolygon> GeoJsonParse::read_polygon(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoPolygon> polygon = GeoPolygon::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + polygon->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinateLists> coords_list = + read_coords_list(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = polygon->from_coords(*coords_list); + } + } + } + return polygon; +} + +std::unique_ptr<GeoMultiPoint> GeoJsonParse::read_multi_point(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoMultiPoint> multi_point = GeoMultiPoint::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + multi_point->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinates> coords = + read_coordinates(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = multi_point->from_coords(*coords); + } + } + } + return multi_point; +} + +std::unique_ptr<GeoMultiLineString> GeoJsonParse::read_multi_linestring( + rapidjson::Document& document, GeoParseStatus& parse_status) { + std::unique_ptr<GeoMultiLineString> multi_linestring = GeoMultiLineString::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + multi_linestring->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinateLists> coords_list = + read_coords_list(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = multi_linestring->from_coords(*coords_list); + } + } + } + return multi_linestring; +} + +std::unique_ptr<GeoMultiPolygon> GeoJsonParse::read_multi_polygon(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoMultiPolygon> multi_polygon = GeoMultiPolygon::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + multi_polygon->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinateListCollections> coords_list_collections = + read_coords_list_collections(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = multi_polygon->from_coords(*coords_list_collections); + } + } + } + return multi_polygon; +} + +std::unique_ptr<GeoCollection> GeoJsonParse::read_geometry_collection( + rapidjson::Document& document, GeoParseStatus& parse_status) { + std::unique_ptr<GeoCollection> collection = GeoCollection::create_unique(); Review Comment: warning: variable 'collection' is not initialized [cppcoreguidelines-init-variables] ```suggestion parse_status) { = 0 ``` ########## be/src/geo/geojson_parse.cpp: ########## @@ -0,0 +1,259 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "geojson_parse.h" + +#include <stdint.h> + +#include <memory> + +#include "rapidjson/document.h" +#include "util/GeoCollection.h" +#include "util/GeoLineString.h" +#include "util/GeoMultiLineString.h" +#include "util/GeoMultiPoint.h" +#include "util/GeoMultiPolygon.h" +#include "util/GeoPoint.h" +#include "util/GeoPolygon.h" +#include "util/GeoShape.h" + +namespace doris { +GeoParseStatus GeoJsonParse::parse_geojson(std::string& geojson, GeoShape** shape) { + rapidjson::Document document; + document.Parse(geojson.c_str()); + + // 判断解析是否成功 + if (document.HasParseError()) { + return GEO_PARSE_GEOJSON_SYNTAX_ERROR; + } + GeoParseStatus parse_status; + + *shape = read_geometry(document, parse_status).release(); + + return parse_status; +} + +std::unique_ptr<GeoShape> GeoJsonParse::read_geometry(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoShape> shape; + if (document.HasMember("type") && document["type"].IsString()) { + std::string type = document["type"].GetString(); + if (type == "Point") { + shape.reset(read_point(document, parse_status).release()); + } else if (type == "LineString") { + shape.reset(read_linestring(document, parse_status).release()); + } else if (type == "Polygon") { + shape.reset(read_polygon(document, parse_status).release()); + } else if (type == "MultiPoint") { + shape.reset(read_multi_point(document, parse_status).release()); + } else if (type == "MultiLineString") { + shape.reset(read_multi_linestring(document, parse_status).release()); + } else if (type == "MultiPolygon") { + shape.reset(read_multi_polygon(document, parse_status).release()); + } else if (type == "GeometryCollection") { + shape.reset(read_geometry_collection(document, parse_status).release()); + } else { + return nullptr; + } + } + return shape; +} + +std::unique_ptr<GeoPoint> GeoJsonParse::read_point(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoPoint> point = GeoPoint::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + point->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinate> coord = + read_coordinate(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = point->from_coord(*coord); + } + } + } + return point; +} + +std::unique_ptr<GeoLineString> GeoJsonParse::read_linestring(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoLineString> linestring = GeoLineString::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + linestring->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinates> coords = + read_coordinates(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = linestring->from_coords(*coords); + } + } + } + return linestring; +} + +std::unique_ptr<GeoPolygon> GeoJsonParse::read_polygon(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoPolygon> polygon = GeoPolygon::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + polygon->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinateLists> coords_list = + read_coords_list(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = polygon->from_coords(*coords_list); + } + } + } + return polygon; +} + +std::unique_ptr<GeoMultiPoint> GeoJsonParse::read_multi_point(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoMultiPoint> multi_point = GeoMultiPoint::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + multi_point->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinates> coords = + read_coordinates(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = multi_point->from_coords(*coords); + } + } + } + return multi_point; +} + +std::unique_ptr<GeoMultiLineString> GeoJsonParse::read_multi_linestring( + rapidjson::Document& document, GeoParseStatus& parse_status) { + std::unique_ptr<GeoMultiLineString> multi_linestring = GeoMultiLineString::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + multi_linestring->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinateLists> coords_list = + read_coords_list(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = multi_linestring->from_coords(*coords_list); + } + } + } + return multi_linestring; +} + +std::unique_ptr<GeoMultiPolygon> GeoJsonParse::read_multi_polygon(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoMultiPolygon> multi_polygon = GeoMultiPolygon::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + multi_polygon->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinateListCollections> coords_list_collections = + read_coords_list_collections(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = multi_polygon->from_coords(*coords_list_collections); + } + } + } + return multi_polygon; +} + +std::unique_ptr<GeoCollection> GeoJsonParse::read_geometry_collection( + rapidjson::Document& document, GeoParseStatus& parse_status) { + std::unique_ptr<GeoCollection> collection = GeoCollection::create_unique(); + if (document.HasMember("geometries") && document["geometries"].IsArray()) { + if (document["geometries"].Size() == 0) { + collection->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + for (std::size_t i = 0; i < document["geometries"].Size(); ++i) { + rapidjson::Document doc; + doc.CopyFrom(document["geometries"][i], doc.GetAllocator()); + auto status = + collection->add_one_geometry(read_geometry(doc, parse_status).release()); + if (parse_status != GEO_PARSE_OK || status != GEO_PARSE_OK) { + return nullptr; + } + } + } + } + return collection; +} + +std::unique_ptr<GeoCoordinateListCollections> GeoJsonParse::read_coords_list_collections( + rapidjson::Value& coords_array, GeoParseStatus& parse_status) { + std::unique_ptr<GeoCoordinateListCollections> coords_list_collections( Review Comment: warning: variable 'coords_list_collections' is not initialized [cppcoreguidelines-init-variables] be/src/geo/geojson_parse.cpp:208: ```diff - st_collections( + st_collections = 0( ``` ########## be/src/geo/geojson_parse.cpp: ########## @@ -0,0 +1,259 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "geojson_parse.h" + +#include <stdint.h> + +#include <memory> + +#include "rapidjson/document.h" +#include "util/GeoCollection.h" +#include "util/GeoLineString.h" +#include "util/GeoMultiLineString.h" +#include "util/GeoMultiPoint.h" +#include "util/GeoMultiPolygon.h" +#include "util/GeoPoint.h" +#include "util/GeoPolygon.h" +#include "util/GeoShape.h" + +namespace doris { +GeoParseStatus GeoJsonParse::parse_geojson(std::string& geojson, GeoShape** shape) { + rapidjson::Document document; + document.Parse(geojson.c_str()); + + // 判断解析是否成功 + if (document.HasParseError()) { + return GEO_PARSE_GEOJSON_SYNTAX_ERROR; + } + GeoParseStatus parse_status; + + *shape = read_geometry(document, parse_status).release(); + + return parse_status; +} + +std::unique_ptr<GeoShape> GeoJsonParse::read_geometry(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoShape> shape; + if (document.HasMember("type") && document["type"].IsString()) { + std::string type = document["type"].GetString(); + if (type == "Point") { + shape.reset(read_point(document, parse_status).release()); + } else if (type == "LineString") { + shape.reset(read_linestring(document, parse_status).release()); + } else if (type == "Polygon") { + shape.reset(read_polygon(document, parse_status).release()); + } else if (type == "MultiPoint") { + shape.reset(read_multi_point(document, parse_status).release()); + } else if (type == "MultiLineString") { + shape.reset(read_multi_linestring(document, parse_status).release()); + } else if (type == "MultiPolygon") { + shape.reset(read_multi_polygon(document, parse_status).release()); + } else if (type == "GeometryCollection") { + shape.reset(read_geometry_collection(document, parse_status).release()); + } else { + return nullptr; + } + } + return shape; +} + +std::unique_ptr<GeoPoint> GeoJsonParse::read_point(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoPoint> point = GeoPoint::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + point->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinate> coord = + read_coordinate(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = point->from_coord(*coord); + } + } + } + return point; +} + +std::unique_ptr<GeoLineString> GeoJsonParse::read_linestring(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoLineString> linestring = GeoLineString::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + linestring->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinates> coords = + read_coordinates(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = linestring->from_coords(*coords); + } + } + } + return linestring; +} + +std::unique_ptr<GeoPolygon> GeoJsonParse::read_polygon(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoPolygon> polygon = GeoPolygon::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + polygon->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinateLists> coords_list = + read_coords_list(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = polygon->from_coords(*coords_list); + } + } + } + return polygon; +} + +std::unique_ptr<GeoMultiPoint> GeoJsonParse::read_multi_point(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoMultiPoint> multi_point = GeoMultiPoint::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + multi_point->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinates> coords = + read_coordinates(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = multi_point->from_coords(*coords); + } + } + } + return multi_point; +} + +std::unique_ptr<GeoMultiLineString> GeoJsonParse::read_multi_linestring( + rapidjson::Document& document, GeoParseStatus& parse_status) { + std::unique_ptr<GeoMultiLineString> multi_linestring = GeoMultiLineString::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + multi_linestring->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinateLists> coords_list = + read_coords_list(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = multi_linestring->from_coords(*coords_list); + } + } + } + return multi_linestring; +} + +std::unique_ptr<GeoMultiPolygon> GeoJsonParse::read_multi_polygon(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoMultiPolygon> multi_polygon = GeoMultiPolygon::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + multi_polygon->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinateListCollections> coords_list_collections = + read_coords_list_collections(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = multi_polygon->from_coords(*coords_list_collections); + } + } + } + return multi_polygon; +} + +std::unique_ptr<GeoCollection> GeoJsonParse::read_geometry_collection( + rapidjson::Document& document, GeoParseStatus& parse_status) { + std::unique_ptr<GeoCollection> collection = GeoCollection::create_unique(); + if (document.HasMember("geometries") && document["geometries"].IsArray()) { + if (document["geometries"].Size() == 0) { + collection->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + for (std::size_t i = 0; i < document["geometries"].Size(); ++i) { + rapidjson::Document doc; + doc.CopyFrom(document["geometries"][i], doc.GetAllocator()); + auto status = + collection->add_one_geometry(read_geometry(doc, parse_status).release()); + if (parse_status != GEO_PARSE_OK || status != GEO_PARSE_OK) { + return nullptr; + } + } + } + } + return collection; +} + +std::unique_ptr<GeoCoordinateListCollections> GeoJsonParse::read_coords_list_collections( + rapidjson::Value& coords_array, GeoParseStatus& parse_status) { + std::unique_ptr<GeoCoordinateListCollections> coords_list_collections( + new GeoCoordinateListCollections()); + for (int i = 0; i < coords_array.Size(); ++i) { + std::unique_ptr<GeoCoordinateLists> coords_list = + read_coords_list(coords_array[i], parse_status); + if (parse_status != GEO_PARSE_OK) { + return nullptr; + } + coords_list_collections->add(coords_list.release()); + } + return coords_list_collections; +} + +std::unique_ptr<GeoCoordinateLists> GeoJsonParse::read_coords_list(rapidjson::Value& coords_array, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoCoordinateLists> coords_list(new GeoCoordinateLists()); + for (int i = 0; i < coords_array.Size(); ++i) { + std::unique_ptr<GeoCoordinates> coords = read_coordinates(coords_array[i], parse_status); + if (parse_status != GEO_PARSE_OK) { + return nullptr; + } + coords_list->add(coords.release()); + } + return coords_list; +} + +std::unique_ptr<GeoCoordinates> GeoJsonParse::read_coordinates(rapidjson::Value& coords_array, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoCoordinates> coords(new GeoCoordinates()); Review Comment: warning: variable 'coords' is not initialized [cppcoreguidelines-init-variables] ```suggestion parse_status) { = 0 ``` ########## be/src/geo/geojson_parse.cpp: ########## @@ -0,0 +1,259 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "geojson_parse.h" + +#include <stdint.h> + +#include <memory> + +#include "rapidjson/document.h" +#include "util/GeoCollection.h" +#include "util/GeoLineString.h" +#include "util/GeoMultiLineString.h" +#include "util/GeoMultiPoint.h" +#include "util/GeoMultiPolygon.h" +#include "util/GeoPoint.h" +#include "util/GeoPolygon.h" +#include "util/GeoShape.h" + +namespace doris { +GeoParseStatus GeoJsonParse::parse_geojson(std::string& geojson, GeoShape** shape) { + rapidjson::Document document; + document.Parse(geojson.c_str()); + + // 判断解析是否成功 + if (document.HasParseError()) { + return GEO_PARSE_GEOJSON_SYNTAX_ERROR; + } + GeoParseStatus parse_status; + + *shape = read_geometry(document, parse_status).release(); + + return parse_status; +} + +std::unique_ptr<GeoShape> GeoJsonParse::read_geometry(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoShape> shape; + if (document.HasMember("type") && document["type"].IsString()) { + std::string type = document["type"].GetString(); + if (type == "Point") { + shape.reset(read_point(document, parse_status).release()); + } else if (type == "LineString") { + shape.reset(read_linestring(document, parse_status).release()); + } else if (type == "Polygon") { + shape.reset(read_polygon(document, parse_status).release()); + } else if (type == "MultiPoint") { + shape.reset(read_multi_point(document, parse_status).release()); + } else if (type == "MultiLineString") { + shape.reset(read_multi_linestring(document, parse_status).release()); + } else if (type == "MultiPolygon") { + shape.reset(read_multi_polygon(document, parse_status).release()); + } else if (type == "GeometryCollection") { + shape.reset(read_geometry_collection(document, parse_status).release()); + } else { + return nullptr; + } + } + return shape; +} + +std::unique_ptr<GeoPoint> GeoJsonParse::read_point(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoPoint> point = GeoPoint::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + point->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinate> coord = + read_coordinate(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = point->from_coord(*coord); + } + } + } + return point; +} + +std::unique_ptr<GeoLineString> GeoJsonParse::read_linestring(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoLineString> linestring = GeoLineString::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + linestring->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinates> coords = + read_coordinates(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = linestring->from_coords(*coords); + } + } + } + return linestring; +} + +std::unique_ptr<GeoPolygon> GeoJsonParse::read_polygon(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoPolygon> polygon = GeoPolygon::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + polygon->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinateLists> coords_list = + read_coords_list(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = polygon->from_coords(*coords_list); + } + } + } + return polygon; +} + +std::unique_ptr<GeoMultiPoint> GeoJsonParse::read_multi_point(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoMultiPoint> multi_point = GeoMultiPoint::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + multi_point->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinates> coords = + read_coordinates(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = multi_point->from_coords(*coords); + } + } + } + return multi_point; +} + +std::unique_ptr<GeoMultiLineString> GeoJsonParse::read_multi_linestring( + rapidjson::Document& document, GeoParseStatus& parse_status) { + std::unique_ptr<GeoMultiLineString> multi_linestring = GeoMultiLineString::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + multi_linestring->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinateLists> coords_list = + read_coords_list(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = multi_linestring->from_coords(*coords_list); + } + } + } + return multi_linestring; +} + +std::unique_ptr<GeoMultiPolygon> GeoJsonParse::read_multi_polygon(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoMultiPolygon> multi_polygon = GeoMultiPolygon::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + multi_polygon->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinateListCollections> coords_list_collections = + read_coords_list_collections(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = multi_polygon->from_coords(*coords_list_collections); + } + } + } + return multi_polygon; +} + +std::unique_ptr<GeoCollection> GeoJsonParse::read_geometry_collection( + rapidjson::Document& document, GeoParseStatus& parse_status) { + std::unique_ptr<GeoCollection> collection = GeoCollection::create_unique(); + if (document.HasMember("geometries") && document["geometries"].IsArray()) { + if (document["geometries"].Size() == 0) { + collection->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + for (std::size_t i = 0; i < document["geometries"].Size(); ++i) { + rapidjson::Document doc; + doc.CopyFrom(document["geometries"][i], doc.GetAllocator()); + auto status = + collection->add_one_geometry(read_geometry(doc, parse_status).release()); + if (parse_status != GEO_PARSE_OK || status != GEO_PARSE_OK) { + return nullptr; + } + } + } + } + return collection; +} + +std::unique_ptr<GeoCoordinateListCollections> GeoJsonParse::read_coords_list_collections( + rapidjson::Value& coords_array, GeoParseStatus& parse_status) { + std::unique_ptr<GeoCoordinateListCollections> coords_list_collections( + new GeoCoordinateListCollections()); + for (int i = 0; i < coords_array.Size(); ++i) { + std::unique_ptr<GeoCoordinateLists> coords_list = + read_coords_list(coords_array[i], parse_status); + if (parse_status != GEO_PARSE_OK) { + return nullptr; + } + coords_list_collections->add(coords_list.release()); + } + return coords_list_collections; +} + +std::unique_ptr<GeoCoordinateLists> GeoJsonParse::read_coords_list(rapidjson::Value& coords_array, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoCoordinateLists> coords_list(new GeoCoordinateLists()); + for (int i = 0; i < coords_array.Size(); ++i) { + std::unique_ptr<GeoCoordinates> coords = read_coordinates(coords_array[i], parse_status); Review Comment: warning: variable 'coords' is not initialized [cppcoreguidelines-init-variables] ```suggestion .Size(); ++i) { = 0 ``` ########## be/src/geo/geojson_parse.cpp: ########## @@ -0,0 +1,259 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "geojson_parse.h" + +#include <stdint.h> + +#include <memory> + +#include "rapidjson/document.h" +#include "util/GeoCollection.h" +#include "util/GeoLineString.h" +#include "util/GeoMultiLineString.h" +#include "util/GeoMultiPoint.h" +#include "util/GeoMultiPolygon.h" +#include "util/GeoPoint.h" +#include "util/GeoPolygon.h" +#include "util/GeoShape.h" + +namespace doris { +GeoParseStatus GeoJsonParse::parse_geojson(std::string& geojson, GeoShape** shape) { + rapidjson::Document document; + document.Parse(geojson.c_str()); + + // 判断解析是否成功 + if (document.HasParseError()) { + return GEO_PARSE_GEOJSON_SYNTAX_ERROR; + } + GeoParseStatus parse_status; + + *shape = read_geometry(document, parse_status).release(); + + return parse_status; +} + +std::unique_ptr<GeoShape> GeoJsonParse::read_geometry(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoShape> shape; + if (document.HasMember("type") && document["type"].IsString()) { + std::string type = document["type"].GetString(); + if (type == "Point") { + shape.reset(read_point(document, parse_status).release()); + } else if (type == "LineString") { + shape.reset(read_linestring(document, parse_status).release()); + } else if (type == "Polygon") { + shape.reset(read_polygon(document, parse_status).release()); + } else if (type == "MultiPoint") { + shape.reset(read_multi_point(document, parse_status).release()); + } else if (type == "MultiLineString") { + shape.reset(read_multi_linestring(document, parse_status).release()); + } else if (type == "MultiPolygon") { + shape.reset(read_multi_polygon(document, parse_status).release()); + } else if (type == "GeometryCollection") { + shape.reset(read_geometry_collection(document, parse_status).release()); + } else { + return nullptr; + } + } + return shape; +} + +std::unique_ptr<GeoPoint> GeoJsonParse::read_point(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoPoint> point = GeoPoint::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + point->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinate> coord = + read_coordinate(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = point->from_coord(*coord); + } + } + } + return point; +} + +std::unique_ptr<GeoLineString> GeoJsonParse::read_linestring(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoLineString> linestring = GeoLineString::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + linestring->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinates> coords = + read_coordinates(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = linestring->from_coords(*coords); + } + } + } + return linestring; +} + +std::unique_ptr<GeoPolygon> GeoJsonParse::read_polygon(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoPolygon> polygon = GeoPolygon::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + polygon->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinateLists> coords_list = + read_coords_list(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = polygon->from_coords(*coords_list); + } + } + } + return polygon; +} + +std::unique_ptr<GeoMultiPoint> GeoJsonParse::read_multi_point(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoMultiPoint> multi_point = GeoMultiPoint::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + multi_point->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinates> coords = + read_coordinates(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = multi_point->from_coords(*coords); + } + } + } + return multi_point; +} + +std::unique_ptr<GeoMultiLineString> GeoJsonParse::read_multi_linestring( + rapidjson::Document& document, GeoParseStatus& parse_status) { + std::unique_ptr<GeoMultiLineString> multi_linestring = GeoMultiLineString::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + multi_linestring->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinateLists> coords_list = + read_coords_list(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = multi_linestring->from_coords(*coords_list); + } + } + } + return multi_linestring; +} + +std::unique_ptr<GeoMultiPolygon> GeoJsonParse::read_multi_polygon(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoMultiPolygon> multi_polygon = GeoMultiPolygon::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + multi_polygon->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinateListCollections> coords_list_collections = + read_coords_list_collections(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = multi_polygon->from_coords(*coords_list_collections); + } + } + } + return multi_polygon; +} + +std::unique_ptr<GeoCollection> GeoJsonParse::read_geometry_collection( + rapidjson::Document& document, GeoParseStatus& parse_status) { + std::unique_ptr<GeoCollection> collection = GeoCollection::create_unique(); + if (document.HasMember("geometries") && document["geometries"].IsArray()) { + if (document["geometries"].Size() == 0) { + collection->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + for (std::size_t i = 0; i < document["geometries"].Size(); ++i) { + rapidjson::Document doc; + doc.CopyFrom(document["geometries"][i], doc.GetAllocator()); + auto status = + collection->add_one_geometry(read_geometry(doc, parse_status).release()); + if (parse_status != GEO_PARSE_OK || status != GEO_PARSE_OK) { + return nullptr; + } + } + } + } + return collection; +} + +std::unique_ptr<GeoCoordinateListCollections> GeoJsonParse::read_coords_list_collections( + rapidjson::Value& coords_array, GeoParseStatus& parse_status) { + std::unique_ptr<GeoCoordinateListCollections> coords_list_collections( + new GeoCoordinateListCollections()); + for (int i = 0; i < coords_array.Size(); ++i) { + std::unique_ptr<GeoCoordinateLists> coords_list = + read_coords_list(coords_array[i], parse_status); + if (parse_status != GEO_PARSE_OK) { + return nullptr; + } + coords_list_collections->add(coords_list.release()); + } + return coords_list_collections; +} + +std::unique_ptr<GeoCoordinateLists> GeoJsonParse::read_coords_list(rapidjson::Value& coords_array, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoCoordinateLists> coords_list(new GeoCoordinateLists()); Review Comment: warning: variable 'coords_list' is not initialized [cppcoreguidelines-init-variables] ```suggestion parse_status) { = 0 ``` ########## be/src/geo/geojson_parse.cpp: ########## @@ -0,0 +1,259 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "geojson_parse.h" + +#include <stdint.h> + +#include <memory> + +#include "rapidjson/document.h" +#include "util/GeoCollection.h" +#include "util/GeoLineString.h" +#include "util/GeoMultiLineString.h" +#include "util/GeoMultiPoint.h" +#include "util/GeoMultiPolygon.h" +#include "util/GeoPoint.h" +#include "util/GeoPolygon.h" +#include "util/GeoShape.h" + +namespace doris { +GeoParseStatus GeoJsonParse::parse_geojson(std::string& geojson, GeoShape** shape) { + rapidjson::Document document; + document.Parse(geojson.c_str()); + + // 判断解析是否成功 + if (document.HasParseError()) { + return GEO_PARSE_GEOJSON_SYNTAX_ERROR; + } + GeoParseStatus parse_status; + + *shape = read_geometry(document, parse_status).release(); + + return parse_status; +} + +std::unique_ptr<GeoShape> GeoJsonParse::read_geometry(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoShape> shape; + if (document.HasMember("type") && document["type"].IsString()) { + std::string type = document["type"].GetString(); + if (type == "Point") { + shape.reset(read_point(document, parse_status).release()); + } else if (type == "LineString") { + shape.reset(read_linestring(document, parse_status).release()); + } else if (type == "Polygon") { + shape.reset(read_polygon(document, parse_status).release()); + } else if (type == "MultiPoint") { + shape.reset(read_multi_point(document, parse_status).release()); + } else if (type == "MultiLineString") { + shape.reset(read_multi_linestring(document, parse_status).release()); + } else if (type == "MultiPolygon") { + shape.reset(read_multi_polygon(document, parse_status).release()); + } else if (type == "GeometryCollection") { + shape.reset(read_geometry_collection(document, parse_status).release()); + } else { + return nullptr; + } + } + return shape; +} + +std::unique_ptr<GeoPoint> GeoJsonParse::read_point(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoPoint> point = GeoPoint::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + point->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinate> coord = + read_coordinate(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = point->from_coord(*coord); + } + } + } + return point; +} + +std::unique_ptr<GeoLineString> GeoJsonParse::read_linestring(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoLineString> linestring = GeoLineString::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + linestring->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinates> coords = + read_coordinates(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = linestring->from_coords(*coords); + } + } + } + return linestring; +} + +std::unique_ptr<GeoPolygon> GeoJsonParse::read_polygon(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoPolygon> polygon = GeoPolygon::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + polygon->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinateLists> coords_list = + read_coords_list(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = polygon->from_coords(*coords_list); + } + } + } + return polygon; +} + +std::unique_ptr<GeoMultiPoint> GeoJsonParse::read_multi_point(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoMultiPoint> multi_point = GeoMultiPoint::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + multi_point->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinates> coords = + read_coordinates(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = multi_point->from_coords(*coords); + } + } + } + return multi_point; +} + +std::unique_ptr<GeoMultiLineString> GeoJsonParse::read_multi_linestring( + rapidjson::Document& document, GeoParseStatus& parse_status) { + std::unique_ptr<GeoMultiLineString> multi_linestring = GeoMultiLineString::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + multi_linestring->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinateLists> coords_list = + read_coords_list(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = multi_linestring->from_coords(*coords_list); + } + } + } + return multi_linestring; +} + +std::unique_ptr<GeoMultiPolygon> GeoJsonParse::read_multi_polygon(rapidjson::Document& document, + GeoParseStatus& parse_status) { + std::unique_ptr<GeoMultiPolygon> multi_polygon = GeoMultiPolygon::create_unique(); + if (document.HasMember("coordinates") && document["coordinates"].IsArray()) { + if (document["coordinates"].Size() == 0) { + multi_polygon->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + std::unique_ptr<GeoCoordinateListCollections> coords_list_collections = + read_coords_list_collections(document["coordinates"], parse_status); + if (parse_status == GEO_PARSE_OK) { + parse_status = multi_polygon->from_coords(*coords_list_collections); + } + } + } + return multi_polygon; +} + +std::unique_ptr<GeoCollection> GeoJsonParse::read_geometry_collection( + rapidjson::Document& document, GeoParseStatus& parse_status) { + std::unique_ptr<GeoCollection> collection = GeoCollection::create_unique(); + if (document.HasMember("geometries") && document["geometries"].IsArray()) { + if (document["geometries"].Size() == 0) { + collection->set_empty(); + parse_status = GEO_PARSE_OK; + } else { + for (std::size_t i = 0; i < document["geometries"].Size(); ++i) { + rapidjson::Document doc; + doc.CopyFrom(document["geometries"][i], doc.GetAllocator()); + auto status = + collection->add_one_geometry(read_geometry(doc, parse_status).release()); + if (parse_status != GEO_PARSE_OK || status != GEO_PARSE_OK) { + return nullptr; + } + } + } + } + return collection; +} + +std::unique_ptr<GeoCoordinateListCollections> GeoJsonParse::read_coords_list_collections( + rapidjson::Value& coords_array, GeoParseStatus& parse_status) { + std::unique_ptr<GeoCoordinateListCollections> coords_list_collections( + new GeoCoordinateListCollections()); + for (int i = 0; i < coords_array.Size(); ++i) { + std::unique_ptr<GeoCoordinateLists> coords_list = + read_coords_list(coords_array[i], parse_status); Review Comment: warning: variable 'coords_list' is not initialized [cppcoreguidelines-init-variables] ```suggestion > coords_list = 0 = ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org