Skip to content

Commit

Permalink
a few more serializers
Browse files Browse the repository at this point in the history
  • Loading branch information
paleolimbot committed Aug 7, 2024
1 parent 464af4c commit 6d3a12d
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions cpp/src/parquet/types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1638,6 +1638,14 @@ class LogicalType::Impl::Float16 final : public LogicalType::Impl::Incompatible,

GENERATE_MAKE(Float16)

#define geometry_edges_string(u___) \
((u___) == LogicalType::GeometryEdges::PLANAR \
? "planar" \
: ((u___) == LogicalType::GeometryEdges::SPHERICAL ? "spherical" : "unknown"))

#define geometry_encoding_string(u___) \
((u___) == LogicalType::GeometryEncoding::WKB ? "wkb" : "unknown")

class LogicalType::Impl::Geometry final : public LogicalType::Impl::Incompatible,
public LogicalType::Impl::SimpleApplicable {
public:
Expand Down Expand Up @@ -1671,11 +1679,32 @@ class LogicalType::Impl::Geometry final : public LogicalType::Impl::Incompatible
};

std::string LogicalType::Impl::Geometry::ToString() const {
throw std::runtime_error("not implemented");
std::stringstream type;
type << "Geometry(crs=" << crs_ << ", edges=" << geometry_edges_string(edges_)
<< ", encoding=" << geometry_encoding_string(encoding_)
<< ", metadata=" << metadata_ << ")";
return type.str();
}

std::string LogicalType::Impl::Geometry::ToJSON() const {
throw std::runtime_error("not implemented");
std::stringstream json;
json << R"({"Type": "Geometry")";

if (crs_.size() > 0) {
// TODO(paleolimbot): we'll need to escape the crs or assume that it's valid JSON
json << R"(, "crs": )" << crs_;
}

json << R"(, "edges": )" << geometry_edges_string(edges_);
json << R"(, "encoding": )" << geometry_encoding_string(encoding_);

if (metadata_.size() > 0) {
// TODO(paleolimbot): we'll need to escape the metadata or assume that it's valid JSON
json << R"(, "metadata": )" << crs_;
}

json << "}";
return json.str();
}

format::LogicalType LogicalType::Impl::Geometry::ToThrift() const {
Expand Down

0 comments on commit 6d3a12d

Please sign in to comment.