paleolimbot commented on code in PR #45459:
URL: https://github.com/apache/arrow/pull/45459#discussion_r1974511246
##########
cpp/src/parquet/arrow/schema_internal.cc:
##########
@@ -110,8 +111,62 @@ Result<std::shared_ptr<ArrowType>>
MakeArrowTimestamp(const LogicalType& logical
}
}
+Result<std::string> MakeGeoArrowCrsMetadata(
+ const std::string& crs,
+ const std::shared_ptr<const ::arrow::KeyValueMetadata>& metadata) {
+ std::string srid_prefix{"srid:"};
+ std::string projjson_prefix{"projjson:"};
+
+ if (crs.empty()) {
+ return R"("crs": "OGC:CRS84", "crs_type": "authority_code")";
+ } else if (crs.rfind(srid_prefix, 0) == 0) {
+ return R"("crs": ")" + crs.substr(srid_prefix.size()) + R"(", "crs_type":
"srid")";
+ } else if (crs.rfind(projjson_prefix, 0) == 0) {
+ std::string metadata_field = crs.substr(projjson_prefix.size());
+ if (metadata && metadata->Contains(metadata_field)) {
+ ARROW_ASSIGN_OR_RAISE(std::string projjson_value,
metadata->Get(metadata_field));
+ return R"("crs": )" + projjson_value + R"(, "crs_type": "projjson")";
+ } else {
+ // Pass on the value of the field so the user can sort this out if needed
+ return R"("crs": )" + metadata_field + R"(, "crs_type": "projjson")";
+ }
+ } else {
+ return Status::Invalid("Can't convert invalid Parquet CRS string to
GeoArrow: ", crs);
+ }
+}
+
+Result<std::shared_ptr<ArrowType>> MakeGeoArrowGeometryType(
+ const LogicalType& logical_type,
+ const std::shared_ptr<const ::arrow::KeyValueMetadata>& metadata) {
+ // Check if we have a registered GeoArrow type to read into
+ std::shared_ptr<::arrow::ExtensionType> maybe_geoarrow_wkb =
+ ::arrow::GetExtensionType("geoarrow.wkb");
+ if (!maybe_geoarrow_wkb) {
+ return ::arrow::binary();
+ }
+
+ if (logical_type.is_geometry()) {
+ const auto& geospatial_type = checked_cast<const
GeometryLogicalType&>(logical_type);
+ ARROW_ASSIGN_OR_RAISE(std::string crs_metadata,
+ MakeGeoArrowCrsMetadata(geospatial_type.crs(),
metadata));
+
+ std::string serialized_data = std::string("{") + crs_metadata + "}";
+ return maybe_geoarrow_wkb->Deserialize(::arrow::binary(), serialized_data);
Review Comment:
Yes, the extension type implementation takes the JSON its given and
(usually) parses/validates it into some non-serialized structure. (We don't
really care what that is here, we just need the `shared_ptr<DataType>` 🙂 )
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]