paleolimbot commented on code in PR #45459: URL: https://github.com/apache/arrow/pull/45459#discussion_r2007889283
########## cpp/src/parquet/types.cc: ########## @@ -1619,6 +1668,204 @@ class LogicalType::Impl::Float16 final : public LogicalType::Impl::Incompatible, GENERATE_MAKE(Float16) +class LogicalType::Impl::Geometry final : public LogicalType::Impl::Incompatible, + public LogicalType::Impl::SimpleApplicable { + public: + friend class GeometryLogicalType; + + std::string ToString() const override; + std::string ToJSON() const override; + format::LogicalType ToThrift() const override; + bool Equals(const LogicalType& other) const override; + + const std::string& crs() const { return crs_; } + + private: + explicit Geometry(std::string crs) + : LogicalType::Impl(LogicalType::Type::GEOMETRY, SortOrder::UNKNOWN), + LogicalType::Impl::SimpleApplicable(parquet::Type::BYTE_ARRAY), + crs_(std::move(crs)) {} + + std::string crs_; +}; + +std::string LogicalType::Impl::Geometry::ToString() const { + std::stringstream type; + type << "Geometry(crs=" << crs_ << ")"; + return type.str(); +} + +std::string LogicalType::Impl::Geometry::ToJSON() const { + std::stringstream json; + json << R"({"Type": "Geometry")"; + + if (!crs_.empty()) { + // TODO(paleolimbot): For documented cases the CRS shouldn't contain quotes, + // but we should probably escape the value of crs_ for backslash and quotes + // to be safe. + json << R"(, "crs": ")" << crs_ << R"(")"; + } + + json << "}"; + return json.str(); +} + +format::LogicalType LogicalType::Impl::Geometry::ToThrift() const { + format::LogicalType type; + format::GeometryType geometry_type; + + // Canonially export crs of "" as an unset CRS + if (!crs_.empty()) { + geometry_type.__set_crs(crs_); + } + + type.__set_GEOMETRY(geometry_type); + return type; +} + +bool LogicalType::Impl::Geometry::Equals(const LogicalType& other) const { + if (other.is_geometry()) { + const auto& other_geometry = checked_cast<const GeometryLogicalType&>(other); + return crs() == other_geometry.crs(); + } else { + return false; + } +} + +const std::string& GeometryLogicalType::crs() const { + return (dynamic_cast<const LogicalType::Impl::Geometry&>(*impl_)).crs(); Review Comment: I wasn't able to get this to work in mingw (but am open to suggestions if I'm missing something obvious!) ``` In file included from D:/a/arrow/arrow/cpp/src/parquet/types.cc:25: D:/a/arrow/arrow/cpp/src/arrow/util/checked_cast.h:36:10: error: cannot cast 'const parquet::LogicalType::Impl' to 'const parquet::LogicalType::Impl::Geometry &' via virtual base 'parquet::LogicalType::Impl' 36 | return static_cast<OutputType>(value); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ D:/a/arrow/arrow/cpp/src/parquet/types.cc:1726:10: note: in instantiation of function template specialization 'arrow::internal::checked_cast<const parquet::LogicalType::Impl::Geometry &, const parquet::LogicalType::Impl &>' requested here 1726 | return checked_cast<const LogicalType::Impl::Geometry&>(*impl_).crs(); | ^ In file included from D:/a/arrow/arrow/cpp/src/parquet/types.cc:25: D:/a/arrow/arrow/cpp/src/arrow/util/checked_cast.h:36:10: error: cannot cast 'const parquet::LogicalType::Impl' to 'const parquet::LogicalType::Impl::Geography &' via virtual base 'parquet::LogicalType::Impl' 36 | return static_cast<OutputType>(value); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ D:/a/arrow/arrow/cpp/src/parquet/types.cc:1830:10: note: in instantiation of function template specialization 'arrow::internal::checked_cast<const parquet::LogicalType::Impl::Geography &, const parquet::LogicalType::Impl &>' requested here 1830 | return checked_cast<const LogicalType::Impl::Geography&>(*impl_).crs(); | ^ 2 errors generated. ``` -- 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: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org