OmniSciDB  2e3a973ef4
Geospatial Namespace Reference

Namespaces

 anonymous_namespace{Types.cpp}
 

Classes

class  GeoBase
 
class  GeoGeometry
 
class  GeoGeometryCollection
 
class  GeoLineString
 
class  GeoMultiPolygon
 
class  GeoPoint
 
class  GeoPolygon
 
class  GeoTypesError
 
class  GeoTypesFactory
 

Functions

int32_t get_compression_scheme (const SQLTypeInfo &ti)
 
uint64_t compress_coord (double coord, const SQLTypeInfo &ti, bool x)
 
uint64_t compress_null_point (const SQLTypeInfo &ti, bool x)
 
std::vector< uint8_t > compress_coords (std::vector< double > &coords, const SQLTypeInfo &ti)
 
template<typename T >
void unpack_geo_vector (std::vector< T > &output, const int8_t *input_ptr, const size_t sz)
 
template<>
void unpack_geo_vector< int32_t > (std::vector< int32_t > &output, const int8_t *input_ptr, const size_t sz)
 
template<typename T >
void decompress_geo_coords_geoint32 (std::vector< T > &dec, const int8_t *enc, const size_t sz)
 
template<>
std::shared_ptr< std::vector< double > > decompress_coords< double, SQLTypeInfo > (const SQLTypeInfo &geo_ti, const int8_t *coords, const size_t coords_sz)
 
template<>
std::shared_ptr< std::vector< double > > decompress_coords< double, int32_t > (const int32_t &ic, const int8_t *coords, const size_t coords_sz)
 
bool is_null_point (const SQLTypeInfo &geo_ti, const int8_t *coords, const size_t coords_sz)
 
template<typename T , typename C >
std::shared_ptr< std::vector< T > > decompress_coords (const C &compression, const int8_t *coords, const size_t coords_sz)
 
DEVICE double decompress_longitude_coord_geoint32 (const int32_t compressed)
 
DEVICE double decompress_lattitude_coord_geoint32 (const int32_t compressed)
 
DEVICE bool is_null_point_longitude_geoint32 (const int32_t compressed)
 
DEVICE bool is_null_point_lattitude_geoint32 (const int32_t compressed)
 
DEVICE uint64_t compress_longitude_coord_geoint32 (const double coord)
 
DEVICE uint64_t compress_lattitude_coord_geoint32 (const double coord)
 
DEVICE constexpr uint64_t compress_null_point_longitude_geoint32 ()
 
DEVICE constexpr uint64_t compress_null_point_lattitude_geoint32 ()
 

Function Documentation

◆ compress_coord()

uint64_t Geospatial::compress_coord ( double  coord,
const SQLTypeInfo ti,
bool  x 
)

Definition at line 33 of file Compression.cpp.

References compress_lattitude_coord_geoint32(), compress_longitude_coord_geoint32(), SQLTypeInfo::get_comp_param(), SQLTypeInfo::get_compression(), and kENCODING_GEOINT.

Referenced by compress_coords().

33  {
34  if (ti.get_compression() == kENCODING_GEOINT && ti.get_comp_param() == 32) {
37  }
38  return *reinterpret_cast<uint64_t*>(may_alias_ptr(&coord));
39 }
DEVICE uint64_t compress_longitude_coord_geoint32(const double coord)
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:268
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:267
DEVICE uint64_t compress_lattitude_coord_geoint32(const double coord)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ compress_coords()

std::vector< uint8_t > Geospatial::compress_coords ( std::vector< double > &  coords,
const SQLTypeInfo ti 
)

Definition at line 52 of file Compression.cpp.

References CHECK, compress_coord(), compress_null_point(), SQLTypeInfo::get_comp_param(), SQLTypeInfo::get_compression(), SQLTypeInfo::get_notnull(), SQLTypeInfo::get_output_srid(), SQLTypeInfo::get_type(), is_null_point(), kENCODING_GEOINT, kPOINT, NULL_ARRAY_DOUBLE, and to_string().

Referenced by Parser::InsertValuesStmt::analyze(), import_export::import_thread_shapefile(), foreign_storage::ParquetGeospatialEncoder::processGeoElement(), foreign_storage::ParquetGeospatialEncoder::processNullGeoElement(), import_export::Importer::set_geo_physical_import_buffer(), import_export::Importer::set_geo_physical_import_buffer_columnar(), GeoPointValueConverter::toCompressedCoords(), and RelAlgTranslator::translateGeoLiteral().

52  {
53  CHECK(!coords.empty()) << "Coord compression received no data";
54  bool is_null_point = false;
55  if (!ti.get_notnull()) {
56  is_null_point = (ti.get_type() == kPOINT && coords[0] == NULL_ARRAY_DOUBLE);
57  }
58 
59  bool x = true;
60  bool is_geoint32 =
61  (ti.get_compression() == kENCODING_GEOINT && ti.get_comp_param() == 32);
62  size_t coord_data_size = (is_geoint32) ? (ti.get_comp_param() / 8) : sizeof(double);
63  std::vector<uint8_t> compressed_coords;
64  compressed_coords.reserve(coords.size() * coord_data_size);
65  for (auto coord : coords) {
66  uint64_t coord_data;
67  if (is_null_point) {
68  coord_data = compress_null_point(ti, x);
69  } else {
70  if (ti.get_output_srid() == 4326) {
71  if (x) {
72  if (coord < -180.0 || coord > 180.0) {
73  throw std::runtime_error("WGS84 longitude " + std::to_string(coord) +
74  " is out of bounds");
75  }
76  } else {
77  if (coord < -90.0 || coord > 90.0) {
78  throw std::runtime_error("WGS84 latitude " + std::to_string(coord) +
79  " is out of bounds");
80  }
81  }
82  }
83  if (is_geoint32) {
84  coord_data = compress_coord(coord, ti, x);
85  } else {
86  auto coord_data_ptr = reinterpret_cast<uint64_t*>(&coord);
87  coord_data = *coord_data_ptr;
88  }
89  }
90  for (size_t i = 0; i < coord_data_size; i++) {
91  compressed_coords.push_back(coord_data & 0xFF);
92  coord_data >>= 8;
93  }
94  x = !x;
95  }
96  return compressed_coords;
97 }
#define NULL_ARRAY_DOUBLE
Definition: sqltypes.h:194
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:268
bool is_null_point(const SQLTypeInfo &geo_ti, const int8_t *coords, const size_t coords_sz)
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:267
std::string to_string(char const *&&v)
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:266
HOST DEVICE int get_output_srid() const
Definition: sqltypes.h:265
#define CHECK(condition)
Definition: Logger.h:197
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:259
uint64_t compress_coord(double coord, const SQLTypeInfo &ti, bool x)
Definition: Compression.cpp:33
uint64_t compress_null_point(const SQLTypeInfo &ti, bool x)
Definition: Compression.cpp:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ compress_lattitude_coord_geoint32()

DEVICE uint64_t Geospatial::compress_lattitude_coord_geoint32 ( const double  coord)
inline

Definition at line 68 of file CompressionRuntime.h.

Referenced by compress_coord().

68  {
69  // compress latitude: -90..90 ---> -2,147,483,647..2,147,483,647
70  int32_t compressed_coord = static_cast<int32_t>(coord * (2147483647.0 / 90.0));
71  return static_cast<uint64_t>(*reinterpret_cast<uint32_t*>(&compressed_coord));
72 }
+ Here is the caller graph for this function:

◆ compress_longitude_coord_geoint32()

DEVICE uint64_t Geospatial::compress_longitude_coord_geoint32 ( const double  coord)
inline

Definition at line 62 of file CompressionRuntime.h.

Referenced by compress_coord().

62  {
63  // compress longitude: -180..180 ---> -2,147,483,647..2,147,483,647
64  int32_t compressed_coord = static_cast<int32_t>(coord * (2147483647.0 / 180.0));
65  return static_cast<uint64_t>(*reinterpret_cast<uint32_t*>(&compressed_coord));
66 }
+ Here is the caller graph for this function:

◆ compress_null_point()

uint64_t Geospatial::compress_null_point ( const SQLTypeInfo ti,
bool  x 
)

Definition at line 41 of file Compression.cpp.

References compress_null_point_lattitude_geoint32(), compress_null_point_longitude_geoint32(), SQLTypeInfo::get_comp_param(), SQLTypeInfo::get_compression(), kENCODING_GEOINT, NULL_ARRAY_DOUBLE, and NULL_DOUBLE.

Referenced by compress_coords().

41  {
42  if (ti.get_compression() == kENCODING_GEOINT && ti.get_comp_param() == 32) {
45  }
46  double n = x ? NULL_ARRAY_DOUBLE : NULL_DOUBLE;
47  auto u = *reinterpret_cast<uint64_t*>(may_alias_ptr(&n));
48  return u;
49 }
#define NULL_DOUBLE
Definition: sqltypes.h:186
#define NULL_ARRAY_DOUBLE
Definition: sqltypes.h:194
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:268
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:267
DEVICE constexpr uint64_t compress_null_point_lattitude_geoint32()
DEVICE constexpr uint64_t compress_null_point_longitude_geoint32()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ compress_null_point_lattitude_geoint32()

DEVICE constexpr uint64_t Geospatial::compress_null_point_lattitude_geoint32 ( )

Definition at line 79 of file CompressionRuntime.h.

Referenced by compress_null_point().

79  {
80  // compress null point latitude: NULL ---> -2,147,483,648
81  return 0x0000000080000000ULL;
82 }
+ Here is the caller graph for this function:

◆ compress_null_point_longitude_geoint32()

DEVICE constexpr uint64_t Geospatial::compress_null_point_longitude_geoint32 ( )

Definition at line 74 of file CompressionRuntime.h.

Referenced by compress_null_point().

74  {
75  // compress null point longitude: NULL ---> -2,147,483,648
76  return 0x0000000080000000ULL;
77 }
+ Here is the caller graph for this function:

◆ decompress_coords()

template<typename T , typename C >
std::shared_ptr<std::vector<T> > Geospatial::decompress_coords ( const C &  compression,
const int8_t *  coords,
const size_t  coords_sz 
)

◆ decompress_coords< double, int32_t >()

template<>
std::shared_ptr<std::vector<double> > Geospatial::decompress_coords< double, int32_t > ( const int32_t &  ic,
const int8_t *  coords,
const size_t  coords_sz 
)

Definition at line 164 of file Compression.cpp.

References CHECK_EQ, COMPRESSION_GEOINT32, COMPRESSION_NONE, decompress_geo_coords_geoint32(), and unpack_geo_vector().

167  {
168  auto decompressed_coords_ptr = std::make_shared<std::vector<double>>();
169  if (ic == COMPRESSION_GEOINT32) {
170  decompress_geo_coords_geoint32(*decompressed_coords_ptr, coords, coords_sz);
171  } else {
173  unpack_geo_vector(*decompressed_coords_ptr, coords, coords_sz);
174  }
175  return decompressed_coords_ptr;
176 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
#define COMPRESSION_NONE
void decompress_geo_coords_geoint32(std::vector< T > &dec, const int8_t *enc, const size_t sz)
#define COMPRESSION_GEOINT32
void unpack_geo_vector(std::vector< T > &output, const int8_t *input_ptr, const size_t sz)
+ Here is the call graph for this function:

◆ decompress_coords< double, SQLTypeInfo >()

template<>
std::shared_ptr<std::vector<double> > Geospatial::decompress_coords< double, SQLTypeInfo > ( const SQLTypeInfo geo_ti,
const int8_t *  coords,
const size_t  coords_sz 
)

Definition at line 147 of file Compression.cpp.

References CHECK_EQ, decompress_geo_coords_geoint32(), kENCODING_GEOINT, kENCODING_NONE, and unpack_geo_vector().

Referenced by GeoTargetValueSerializer< kPOINT >::serialize(), GeoWktSerializer< kPOINT >::serialize(), GeoTargetValueSerializer< kLINESTRING >::serialize(), GeoWktSerializer< kLINESTRING >::serialize(), GeoTargetValueSerializer< kPOLYGON >::serialize(), GeoWktSerializer< kPOLYGON >::serialize(), GeoTargetValueSerializer< kMULTIPOLYGON >::serialize(), and GeoWktSerializer< kMULTIPOLYGON >::serialize().

150  {
151  auto decompressed_coords_ptr = std::make_shared<std::vector<double>>();
152  if (geo_ti.get_compression() == kENCODING_GEOINT) {
153  if (geo_ti.get_comp_param() == 32) {
154  decompress_geo_coords_geoint32(*decompressed_coords_ptr, coords, coords_sz);
155  }
156  } else {
158  unpack_geo_vector(*decompressed_coords_ptr, coords, coords_sz);
159  }
160  return decompressed_coords_ptr;
161 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
void decompress_geo_coords_geoint32(std::vector< T > &dec, const int8_t *enc, const size_t sz)
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:268
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:267
void unpack_geo_vector(std::vector< T > &output, const int8_t *input_ptr, const size_t sz)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ decompress_geo_coords_geoint32()

template<typename T >
void Geospatial::decompress_geo_coords_geoint32 ( std::vector< T > &  dec,
const int8_t *  enc,
const size_t  sz 
)

Definition at line 130 of file Compression.cpp.

References decompress_lattitude_coord_geoint32(), and decompress_longitude_coord_geoint32().

Referenced by decompress_coords< double, int32_t >(), and decompress_coords< double, SQLTypeInfo >().

132  {
133  if (sz == 0) {
134  return;
135  }
136  const auto compressed_coords = reinterpret_cast<const int32_t*>(enc);
137  const auto num_coords = sz / sizeof(int32_t);
138  dec.resize(num_coords);
139  for (size_t i = 0; i < num_coords; i += 2) {
140  dec[i] = Geospatial::decompress_longitude_coord_geoint32(compressed_coords[i]);
141  dec[i + 1] =
142  Geospatial::decompress_lattitude_coord_geoint32(compressed_coords[i + 1]);
143  }
144 }
DEVICE double decompress_lattitude_coord_geoint32(const int32_t compressed)
int64_t const int32_t sz
DEVICE double decompress_longitude_coord_geoint32(const int32_t compressed)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ decompress_lattitude_coord_geoint32()

DEVICE double Geospatial::decompress_lattitude_coord_geoint32 ( const int32_t  compressed)
inline

Definition at line 46 of file CompressionRuntime.h.

Referenced by decompress_coord(), decompress_geo_coords_geoint32(), and get_bucket_key_for_range_compressed_impl().

46  {
47  // decompress latitude: -2,147,483,647..2,147,483,647 ---> -90..90
48  return static_cast<double>(compressed) *
49  4.1909515877212172e-08; // // (90.0 / 2147483647.0)
50 }
+ Here is the caller graph for this function:

◆ decompress_longitude_coord_geoint32()

DEVICE double Geospatial::decompress_longitude_coord_geoint32 ( const int32_t  compressed)
inline

Definition at line 40 of file CompressionRuntime.h.

Referenced by decompress_coord(), decompress_geo_coords_geoint32(), and get_bucket_key_for_range_compressed_impl().

40  {
41  // decompress longitude: -2,147,483,647..2,147,483,647 ---> -180..180
42  return static_cast<double>(compressed) *
43  8.3819031754424345e-08; // (180.0 / 2147483647.0)
44 }
+ Here is the caller graph for this function:

◆ get_compression_scheme()

int32_t Geospatial::get_compression_scheme ( const SQLTypeInfo ti)

Definition at line 23 of file Compression.cpp.

References COMPRESSION_GEOINT32, COMPRESSION_NONE, SQLTypeInfo::get_comp_param(), SQLTypeInfo::get_compression(), kENCODING_GEOINT, and kENCODING_NONE.

Referenced by CodeGenerator::codegenGeoBinOper(), CodeGenerator::codegenGeoUOper(), RelAlgTranslator::translateBinaryGeoFunction(), RelAlgTranslator::translateFunctionWithGeoArg(), RelAlgTranslator::translateGeoFunctionArg(), and RelAlgTranslator::translateUnaryGeoFunction().

23  {
24  if (ti.get_compression() == kENCODING_GEOINT && ti.get_comp_param() == 32) {
25  return COMPRESSION_GEOINT32;
26  }
27  if (ti.get_compression() != kENCODING_NONE) {
28  throw std::runtime_error("Invalid compression");
29  }
30  return COMPRESSION_NONE;
31 }
#define COMPRESSION_NONE
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:268
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:267
#define COMPRESSION_GEOINT32
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ is_null_point()

bool Geospatial::is_null_point ( const SQLTypeInfo geo_ti,
const int8_t *  coords,
const size_t  coords_sz 
)

Definition at line 178 of file Compression.cpp.

References CHECK_EQ, SQLTypeInfo::get_comp_param(), SQLTypeInfo::get_compression(), SQLTypeInfo::get_notnull(), SQLTypeInfo::get_type(), is_null_point_longitude_geoint32(), kENCODING_GEOINT, kENCODING_NONE, kPOINT, and NULL_ARRAY_DOUBLE.

Referenced by compress_coords(), anonymous_namespace{ResultSetIteration.cpp}::GeoLazyFetchHandler::fetch(), anonymous_namespace{ResultSetIteration.cpp}::GeoQueryOutputFetchHandler::fetch(), import_export::Importer::set_geo_physical_import_buffer(), and import_export::Importer::set_geo_physical_import_buffer_columnar().

180  {
181  if (geo_ti.get_type() == kPOINT && !geo_ti.get_notnull()) {
182  if (geo_ti.get_compression() == kENCODING_GEOINT) {
183  if (geo_ti.get_comp_param() == 32) {
184  return Geospatial::is_null_point_longitude_geoint32(*((int32_t*)coords));
185  }
186  } else {
188  return *((double*)coords) == NULL_ARRAY_DOUBLE;
189  }
190  }
191  return false;
192 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
#define NULL_ARRAY_DOUBLE
Definition: sqltypes.h:194
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:268
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:267
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:266
DEVICE bool is_null_point_longitude_geoint32(const int32_t compressed)
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:259
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ is_null_point_lattitude_geoint32()

DEVICE bool Geospatial::is_null_point_lattitude_geoint32 ( const int32_t  compressed)
inline

Definition at line 57 of file CompressionRuntime.h.

57  {
58  // check compressed null point latitude: -2,147,483,648 ---> NULL
59  return (*reinterpret_cast<const uint32_t*>(&compressed) == 0x80000000U);
60 }

◆ is_null_point_longitude_geoint32()

DEVICE bool Geospatial::is_null_point_longitude_geoint32 ( const int32_t  compressed)
inline

Definition at line 52 of file CompressionRuntime.h.

Referenced by is_null_point().

52  {
53  // check compressed null point longitude: -2,147,483,648 ---> NULL
54  return (*reinterpret_cast<const uint32_t*>(&compressed) == 0x80000000U);
55 }
+ Here is the caller graph for this function:

◆ unpack_geo_vector()

template<typename T >
void Geospatial::unpack_geo_vector ( std::vector< T > &  output,
const int8_t *  input_ptr,
const size_t  sz 
)

Definition at line 100 of file Compression.cpp.

References CHECK_EQ.

Referenced by decompress_coords< double, int32_t >(), decompress_coords< double, SQLTypeInfo >(), GeoTargetValueSerializer< kPOLYGON >::serialize(), GeoWktSerializer< kPOLYGON >::serialize(), GeoTargetValueSerializer< kMULTIPOLYGON >::serialize(), and GeoWktSerializer< kMULTIPOLYGON >::serialize().

100  {
101  if (sz == 0) {
102  return;
103  }
104  auto elems = reinterpret_cast<const T*>(input_ptr);
105  CHECK_EQ(size_t(0), sz % sizeof(T));
106  const size_t num_elems = sz / sizeof(T);
107  output.resize(num_elems);
108  for (size_t i = 0; i < num_elems; i++) {
109  output[i] = elems[i];
110  }
111 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
int64_t const int32_t sz
+ Here is the caller graph for this function:

◆ unpack_geo_vector< int32_t >()

template<>
void Geospatial::unpack_geo_vector< int32_t > ( std::vector< int32_t > &  output,
const int8_t *  input_ptr,
const size_t  sz 
)

Definition at line 114 of file Compression.cpp.

References CHECK_EQ, and sz.

116  {
117  if (sz == 0) {
118  return;
119  }
120  auto elems = reinterpret_cast<const int32_t*>(input_ptr);
121  CHECK_EQ(size_t(0), sz % sizeof(int32_t));
122  const size_t num_elems = sz / sizeof(int32_t);
123  output.resize(num_elems);
124  for (size_t i = 0; i < num_elems; i++) {
125  output[i] = elems[i];
126  }
127 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
int64_t const int32_t sz