Skip to content

Commit

Permalink
remove some unneded parts of geometry_util_internal
Browse files Browse the repository at this point in the history
  • Loading branch information
paleolimbot committed Feb 13, 2025
1 parent 2931a24 commit 35ec0c6
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 96 deletions.
18 changes: 0 additions & 18 deletions cpp/src/parquet/geometry_statistics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,6 @@ class GeospatialStatisticsImpl {
return out;
}

std::string EncodeMin() const {
const double* mins = bounder_.Bounds().min;
bool has_z = !std::isinf(mins[2]);
bool has_m = !std::isinf(mins[3]);
return geometry::MakeWKBPoint(mins, has_z, has_m);
}

std::string EncodeMax() const {
const double* maxes = bounder_.Bounds().max;
bool has_z = !std::isinf(maxes[2]);
bool has_m = !std::isinf(maxes[3]);
return geometry::MakeWKBPoint(maxes, has_z, has_m);
}

void Update(const EncodedGeospatialStatistics& encoded) {
if (!is_valid_) {
return;
Expand Down Expand Up @@ -245,10 +231,6 @@ EncodedGeospatialStatistics GeospatialStatistics::Encode() const {
return impl_->Encode();
}

std::string GeospatialStatistics::EncodeMin() const { return impl_->EncodeMin(); }

std::string GeospatialStatistics::EncodeMax() const { return impl_->EncodeMax(); }

void GeospatialStatistics::Decode(const EncodedGeospatialStatistics& encoded) {
impl_->Update(encoded);
}
Expand Down
6 changes: 0 additions & 6 deletions cpp/src/parquet/geometry_statistics.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@

#pragma once

#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <string>
#include <utility>

#include "parquet/platform.h"
#include "parquet/types.h"
Expand Down Expand Up @@ -81,8 +77,6 @@ class PARQUET_EXPORT GeospatialStatistics {
void Reset();

EncodedGeospatialStatistics Encode() const;
std::string EncodeMin() const;
std::string EncodeMax() const;

bool is_valid() const;

Expand Down
67 changes: 0 additions & 67 deletions cpp/src/parquet/geometry_util_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,42 +109,6 @@ struct GeometryType {
}
}

static uint32_t ToWKB(geometry_type geometry_type, bool has_z, bool has_m) {
uint32_t wkb_geom_type = 0;
switch (geometry_type) {
case geometry_type::POINT:
wkb_geom_type = 1;
break;
case geometry_type::LINESTRING:
wkb_geom_type = 2;
break;
case geometry_type::POLYGON:
wkb_geom_type = 3;
break;
case geometry_type::MULTIPOINT:
wkb_geom_type = 4;
break;
case geometry_type::MULTILINESTRING:
wkb_geom_type = 5;
break;
case geometry_type::MULTIPOLYGON:
wkb_geom_type = 6;
break;
case geometry_type::GEOMETRYCOLLECTION:
wkb_geom_type = 7;
break;
default:
throw ParquetException("Invalid geometry_type");
}
if (has_z) {
wkb_geom_type += 1000;
}
if (has_m) {
wkb_geom_type += 2000;
}
return wkb_geom_type;
}

static std::string ToString(geometry_type geometry_type) {
switch (geometry_type) {
case geometry_type::POINT:
Expand Down Expand Up @@ -432,35 +396,4 @@ class WKBGeometryBounder {
}
};

#if defined(ARROW_LITTLE_ENDIAN)
static constexpr int kWkbNativeEndianness = geometry::WKBBuffer::WKB_LITTLE_ENDIAN;
#else
static constexpr int kWkbNativeEndianness = geometry::WKBBuffer::WKB_BIG_ENDIAN;
#endif

static inline std::string MakeWKBPoint(const double* xyzm, bool has_z, bool has_m) {
// 1:endianness + 4:type + 8:x + 8:y
int num_bytes = 21 + (has_z ? 8 : 0) + (has_m ? 8 : 0);
std::string wkb(num_bytes, 0);
char* ptr = wkb.data();

ptr[0] = kWkbNativeEndianness;
uint32_t geom_type = geometry::GeometryType::ToWKB(
geometry::GeometryType::geometry_type::POINT, has_z, has_m);
std::memcpy(&ptr[1], &geom_type, 4);
std::memcpy(&ptr[5], &xyzm[0], 8);
std::memcpy(&ptr[13], &xyzm[1], 8);
ptr += 21;

if (has_z) {
std::memcpy(ptr, &xyzm[2], 8);
ptr += 8;
}
if (has_m) {
std::memcpy(ptr, &xyzm[3], 8);
}

return wkb;
}

} // namespace parquet::geometry
3 changes: 2 additions & 1 deletion cpp/src/parquet/geometry_util_internal_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <cstring>

#include "parquet/geometry_util_internal.h"
#include "parquet/test_util.h"

namespace parquet::geometry {

Expand Down Expand Up @@ -473,7 +474,7 @@ class MakeWKBPointTestFixture : public testing::TestWithParam<MakeWKBPointTestCa

TEST_P(MakeWKBPointTestFixture, MakeWKBPoint) {
auto param = GetParam();
std::string wkb = MakeWKBPoint(param.xyzm, param.has_z, param.has_m);
std::string wkb = test::MakeWKBPoint(param.xyzm, param.has_z, param.has_m);
WKBGeometryBounder bounder;
WKBBuffer buf(reinterpret_cast<uint8_t*>(wkb.data()), wkb.size());
bounder.ReadGeometry(&buf);
Expand Down
48 changes: 44 additions & 4 deletions cpp/src/parquet/test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -842,12 +842,52 @@ static constexpr int kWkbNativeEndianness = geometry::WKBBuffer::WKB_LITTLE_ENDI
static constexpr int kWkbNativeEndianness = geometry::WKBBuffer::WKB_BIG_ENDIAN;
#endif

static uint32_t GeometryTypeToWKB(geometry::GeometryType::geometry_type geometry_type,
bool has_z, bool has_m) {
auto wkb_geom_type = static_cast<uint32_t>(geometry_type);

if (has_z) {
wkb_geom_type += 1000;
}

if (has_m) {
wkb_geom_type += 2000;
}

return wkb_geom_type;
}

static inline std::string MakeWKBPoint(const double* xyzm, bool has_z, bool has_m) {
// 1:endianness + 4:type + 8:x + 8:y
int num_bytes = 21 + (has_z ? 8 : 0) + (has_m ? 8 : 0);
std::string wkb(num_bytes, 0);
char* ptr = wkb.data();

ptr[0] = kWkbNativeEndianness;
uint32_t geom_type =
GeometryTypeToWKB(geometry::GeometryType::geometry_type::POINT, has_z, has_m);
std::memcpy(&ptr[1], &geom_type, 4);
std::memcpy(&ptr[5], &xyzm[0], 8);
std::memcpy(&ptr[13], &xyzm[1], 8);
ptr += 21;

if (has_z) {
std::memcpy(ptr, &xyzm[2], 8);
ptr += 8;
}
if (has_m) {
std::memcpy(ptr, &xyzm[3], 8);
}

return wkb;
}

static constexpr int kWkbPointSize = 21; // 1:endianness + 4:type + 8:x + 8:y

inline void GenerateWKBPoint(uint8_t* ptr, double x, double y) {
double xyzm[] = {x, y, geometry::kInf, geometry::kInf};
std::string wkb = geometry::MakeWKBPoint(xyzm, false, false);
memcpy(ptr, wkb.data(), kWkbPointSize);
std::string wkb = MakeWKBPoint(xyzm, false, false);
std::memcpy(ptr, wkb.data(), kWkbPointSize);
}

inline bool GetWKBPointCoordinate(const ByteArray& value, double* out_x, double* out_y) {
Expand All @@ -857,8 +897,8 @@ inline bool GetWKBPointCoordinate(const ByteArray& value, double* out_x, double*
if (value.ptr[0] != kWkbNativeEndianness) {
return false;
}
uint32_t expected_geom_type = geometry::GeometryType::ToWKB(
geometry::GeometryType::geometry_type::POINT, false, false);
uint32_t expected_geom_type =
GeometryTypeToWKB(geometry::GeometryType::geometry_type::POINT, false, false);
uint32_t geom_type = 0;
memcpy(&geom_type, &value.ptr[1], 4);
if (geom_type != expected_geom_type) {
Expand Down

0 comments on commit 35ec0c6

Please sign in to comment.