Skip to content

Commit

Permalink
use enum class for EdgeInterpolationAlgorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
paleolimbot committed Feb 27, 2025
1 parent 7560131 commit 416f831
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 28 deletions.
10 changes: 6 additions & 4 deletions cpp/src/parquet/thrift_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ static inline EncodedGeoStatistics FromThrift(
}

static inline format::EdgeInterpolationAlgorithm::type ToThrift(
LogicalType::EdgeInterpolationAlgorithm::algorithm algorithm) {
LogicalType::EdgeInterpolationAlgorithm algorithm) {
switch (algorithm) {
case LogicalType::EdgeInterpolationAlgorithm::SPHERICAL:
return format::EdgeInterpolationAlgorithm::SPHERICAL;
Expand All @@ -270,11 +270,12 @@ static inline format::EdgeInterpolationAlgorithm::type ToThrift(
case LogicalType::EdgeInterpolationAlgorithm::KARNEY:
return format::EdgeInterpolationAlgorithm::KARNEY;
default:
throw ParquetException("Unknown value for geometry algorithm: ", algorithm);
throw ParquetException("Unknown value for geometry algorithm: ",
static_cast<int>(algorithm));
}
}

static inline LogicalType::EdgeInterpolationAlgorithm::algorithm FromThrift(
static inline LogicalType::EdgeInterpolationAlgorithm FromThrift(
const format::EdgeInterpolationAlgorithm::type algorithm) {
switch (algorithm) {
case format::EdgeInterpolationAlgorithm::SPHERICAL:
Expand All @@ -288,7 +289,8 @@ static inline LogicalType::EdgeInterpolationAlgorithm::algorithm FromThrift(
case format::EdgeInterpolationAlgorithm::KARNEY:
return LogicalType::EdgeInterpolationAlgorithm::KARNEY;
default:
throw ParquetException("Unknown value for geometry algorithm: ", algorithm);
throw ParquetException("Unknown value for geometry algorithm: ",
static_cast<int>(algorithm));
}
}

Expand Down
19 changes: 8 additions & 11 deletions cpp/src/parquet/types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ std::shared_ptr<const LogicalType> LogicalType::FromThrift(
crs = type.GEOGRAPHY.crs;
}

LogicalType::EdgeInterpolationAlgorithm::algorithm algorithm;
LogicalType::EdgeInterpolationAlgorithm algorithm;
if (!type.GEOGRAPHY.__isset.algorithm) {
algorithm = LogicalType::EdgeInterpolationAlgorithm::SPHERICAL;
} else {
Expand Down Expand Up @@ -563,7 +563,7 @@ std::shared_ptr<const LogicalType> LogicalType::Geometry(std::string crs) {
}

std::shared_ptr<const LogicalType> LogicalType::Geography(
std::string crs, LogicalType::EdgeInterpolationAlgorithm::algorithm algorithm) {
std::string crs, LogicalType::EdgeInterpolationAlgorithm algorithm) {
return GeographyLogicalType::Make(std::move(crs), algorithm);
}

Expand Down Expand Up @@ -1723,7 +1723,7 @@ bool LogicalType::Impl::Geometry::Equals(const LogicalType& other) const {
}

const std::string& GeometryLogicalType::crs() const {
return (dynamic_cast<const LogicalType::Impl::Geometry&>(*impl_)).crs();
return checked_cast<const LogicalType::Impl::Geometry&>(*impl_).crs();
}

std::shared_ptr<const LogicalType> GeometryLogicalType::Make(std::string crs) {
Expand All @@ -1743,9 +1743,7 @@ class LogicalType::Impl::Geography final : public LogicalType::Impl::Incompatibl
bool Equals(const LogicalType& other) const override;

const std::string& crs() const { return crs_; }
LogicalType::EdgeInterpolationAlgorithm::algorithm algorithm() const {
return algorithm_;
}
LogicalType::EdgeInterpolationAlgorithm algorithm() const { return algorithm_; }

std::string_view algorithm_name() const {
switch (algorithm_) {
Expand All @@ -1765,14 +1763,14 @@ class LogicalType::Impl::Geography final : public LogicalType::Impl::Incompatibl
}

private:
Geography(std::string crs, LogicalType::EdgeInterpolationAlgorithm::algorithm algorithm)
Geography(std::string crs, LogicalType::EdgeInterpolationAlgorithm algorithm)
: LogicalType::Impl(LogicalType::Type::GEOGRAPHY, SortOrder::UNKNOWN),
LogicalType::Impl::SimpleApplicable(parquet::Type::BYTE_ARRAY),
crs_(std::move(crs)),
algorithm_(algorithm) {}

std::string crs_;
LogicalType::EdgeInterpolationAlgorithm::algorithm algorithm_;
LogicalType::EdgeInterpolationAlgorithm algorithm_;
};

std::string LogicalType::Impl::Geography::ToString() const {
Expand Down Expand Up @@ -1832,8 +1830,7 @@ const std::string& GeographyLogicalType::crs() const {
return (dynamic_cast<const LogicalType::Impl::Geography&>(*impl_)).crs();
}

LogicalType::EdgeInterpolationAlgorithm::algorithm GeographyLogicalType::algorithm()
const {
LogicalType::EdgeInterpolationAlgorithm GeographyLogicalType::algorithm() const {
return (dynamic_cast<const LogicalType::Impl::Geography&>(*impl_)).algorithm();
}

Expand All @@ -1842,7 +1839,7 @@ std::string_view GeographyLogicalType::algorithm_name() const {
}

std::shared_ptr<const LogicalType> GeographyLogicalType::Make(
std::string crs, LogicalType::EdgeInterpolationAlgorithm::algorithm algorithm) {
std::string crs, LogicalType::EdgeInterpolationAlgorithm algorithm) {
auto* logical_type = new GeographyLogicalType();
logical_type->impl_.reset(new LogicalType::Impl::Geography(std::move(crs), algorithm));
return std::shared_ptr<const LogicalType>(logical_type);
Expand Down
22 changes: 10 additions & 12 deletions cpp/src/parquet/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,13 @@ class PARQUET_EXPORT LogicalType {
enum unit { UNKNOWN = 0, MILLIS = 1, MICROS, NANOS };
};

struct EdgeInterpolationAlgorithm {
enum algorithm {
UNKNOWN = 0,
SPHERICAL = 1,
VINCENTY = 2,
THOMAS = 3,
ANDOYER = 4,
KARNEY = 5
};
enum class EdgeInterpolationAlgorithm {
UNKNOWN = 0,
SPHERICAL = 1,
VINCENTY = 2,
THOMAS = 3,
ANDOYER = 4,
KARNEY = 5
};

/// \brief If possible, return a logical type equivalent to the given legacy
Expand Down Expand Up @@ -229,7 +227,7 @@ class PARQUET_EXPORT LogicalType {
static std::shared_ptr<const LogicalType> Geometry(std::string crs = "");

static std::shared_ptr<const LogicalType> Geography(
std::string crs = "", LogicalType::EdgeInterpolationAlgorithm::algorithm algorithm =
std::string crs = "", LogicalType::EdgeInterpolationAlgorithm algorithm =
EdgeInterpolationAlgorithm::SPHERICAL);

/// \brief Create a placeholder for when no logical type is specified
Expand Down Expand Up @@ -480,11 +478,11 @@ class PARQUET_EXPORT GeometryLogicalType : public LogicalType {
class PARQUET_EXPORT GeographyLogicalType : public LogicalType {
public:
static std::shared_ptr<const LogicalType> Make(
std::string crs = "", LogicalType::EdgeInterpolationAlgorithm::algorithm algorithm =
std::string crs = "", LogicalType::EdgeInterpolationAlgorithm algorithm =
EdgeInterpolationAlgorithm::SPHERICAL);

const std::string& crs() const;
LogicalType::EdgeInterpolationAlgorithm::algorithm algorithm() const;
LogicalType::EdgeInterpolationAlgorithm algorithm() const;
std::string_view algorithm_name() const;

private:
Expand Down
2 changes: 1 addition & 1 deletion python/pyarrow/_parquet.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ cdef extern from "parquet/api/schema.h" namespace "parquet" nogil:
ParquetTimeUnit_MICROS" parquet::LogicalType::TimeUnit::MICROS"
ParquetTimeUnit_NANOS" parquet::LogicalType::TimeUnit::NANOS"

enum ParquetEdgeInterpolationAlgorithm" parquet::LogicalType::EdgeInterpolationAlgorithm::algorithm":
enum ParquetEdgeInterpolationAlgorithm" parquet::LogicalType::EdgeInterpolationAlgorithm":
ParquetEdgeInterpolationAlgorithm_UNKNOWN" parquet::LogicalType::EdgeInterpolationAlgorithm::UNKNOWN"
ParquetEdgeInterpolationAlgorithm_SPHERICAL" parquet::LogicalType::EdgeInterpolationAlgorithm::SPHERICAL"
ParquetEdgeInterpolationAlgorithm_VINCENTY" parquet::LogicalType::EdgeInterpolationAlgorithm::VINCENTY"
Expand Down

0 comments on commit 416f831

Please sign in to comment.