OmniSciDB  06b3bd477c
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
geospatial Namespace Reference

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)
 

Function Documentation

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

Definition at line 33 of file geo_compression.cpp.

References Geo_namespace::compress_lattitude_coord_geoint32(), Geo_namespace::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) {
36  : Geo_namespace::compress_lattitude_coord_geoint32(coord);
37  }
38  return *reinterpret_cast<uint64_t*>(may_alias_ptr(&coord));
39 }
DEVICE uint64_t compress_longitude_coord_geoint32(const double coord)
DEVICE uint64_t compress_lattitude_coord_geoint32(const double coord)
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:266
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:267

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 52 of file geo_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(), 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  std::vector<uint8_t> compressed_coords;
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  for (auto coord : coords) {
64  uint64_t coord_data;
65  if (is_null_point) {
66  coord_data = compress_null_point(ti, x);
67  } else {
68  if (ti.get_output_srid() == 4326) {
69  if (x) {
70  if (coord < -180.0 || coord > 180.0) {
71  throw std::runtime_error("WGS84 longitude " + std::to_string(coord) +
72  " is out of bounds");
73  }
74  } else {
75  if (coord < -90.0 || coord > 90.0) {
76  throw std::runtime_error("WGS84 latitude " + std::to_string(coord) +
77  " is out of bounds");
78  }
79  }
80  }
81  if (is_geoint32) {
82  coord_data = compress_coord(coord, ti, x);
83  } else {
84  auto coord_data_ptr = reinterpret_cast<uint64_t*>(&coord);
85  coord_data = *coord_data_ptr;
86  }
87  }
88  for (size_t i = 0; i < coord_data_size; i++) {
89  compressed_coords.push_back(coord_data & 0xFF);
90  coord_data >>= 8;
91  }
92  x = !x;
93  }
94  return compressed_coords;
95 }
uint64_t compress_null_point(const SQLTypeInfo &ti, bool x)
#define NULL_ARRAY_DOUBLE
Definition: sqltypes.h:193
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:258
std::string to_string(char const *&&v)
CHECK(cgen_state)
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:266
uint64_t compress_coord(double coord, const SQLTypeInfo &ti, bool x)
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:267
bool is_null_point(const SQLTypeInfo &geo_ti, const int8_t *coords, const size_t coords_sz)
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:265
HOST DEVICE int get_output_srid() const
Definition: sqltypes.h:264

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 41 of file geo_compression.cpp.

References Geo_namespace::compress_null_point_lattitude_geoint32(), Geo_namespace::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) {
44  : Geo_namespace::compress_null_point_lattitude_geoint32();
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:185
#define NULL_ARRAY_DOUBLE
Definition: sqltypes.h:193
DEVICE constexpr uint64_t compress_null_point_lattitude_geoint32()
DEVICE constexpr uint64_t compress_null_point_longitude_geoint32()
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:266
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:267

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 
)
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 162 of file geo_compression.cpp.

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

165  {
166  auto decompressed_coords_ptr = std::make_shared<std::vector<double>>();
167  if (ic == COMPRESSION_GEOINT32) {
168  decompress_geo_coords_geoint32(*decompressed_coords_ptr, coords, coords_sz);
169  } else {
171  unpack_geo_vector(*decompressed_coords_ptr, coords, coords_sz);
172  }
173  return decompressed_coords_ptr;
174 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
#define COMPRESSION_NONE
void unpack_geo_vector(std::vector< T > &output, const int8_t *input_ptr, const size_t sz)
#define COMPRESSION_GEOINT32
void decompress_geo_coords_geoint32(std::vector< T > &dec, const int8_t *enc, const size_t sz)

+ Here is the call graph for this function:

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 145 of file geo_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().

148  {
149  auto decompressed_coords_ptr = std::make_shared<std::vector<double>>();
150  if (geo_ti.get_compression() == kENCODING_GEOINT) {
151  if (geo_ti.get_comp_param() == 32) {
152  decompress_geo_coords_geoint32(*decompressed_coords_ptr, coords, coords_sz);
153  }
154  } else {
156  unpack_geo_vector(*decompressed_coords_ptr, coords, coords_sz);
157  }
158  return decompressed_coords_ptr;
159 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
void unpack_geo_vector(std::vector< T > &output, const int8_t *input_ptr, const size_t sz)
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:266
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:267
void decompress_geo_coords_geoint32(std::vector< T > &dec, const int8_t *enc, const size_t sz)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 128 of file geo_compression.cpp.

References Geo_namespace::decompress_lattitude_coord_geoint32(), and Geo_namespace::decompress_longitude_coord_geoint32().

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

130  {
131  if (sz == 0) {
132  return;
133  }
134  const auto compressed_coords = reinterpret_cast<const int32_t*>(enc);
135  const auto num_coords = sz / sizeof(int32_t);
136  dec.resize(num_coords);
137  for (size_t i = 0; i < num_coords; i += 2) {
138  dec[i] = Geo_namespace::decompress_longitude_coord_geoint32(compressed_coords[i]);
139  dec[i + 1] =
140  Geo_namespace::decompress_lattitude_coord_geoint32(compressed_coords[i + 1]);
141  }
142 }
DEVICE double decompress_lattitude_coord_geoint32(const int32_t compressed)
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:

int32_t geospatial::get_compression_scheme ( const SQLTypeInfo ti)

Definition at line 23 of file geo_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(), 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 EncodingType get_compression() const
Definition: sqltypes.h:266
#define COMPRESSION_GEOINT32
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:267

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 176 of file geo_compression.cpp.

References CHECK_EQ, SQLTypeInfo::get_comp_param(), SQLTypeInfo::get_compression(), SQLTypeInfo::get_notnull(), SQLTypeInfo::get_type(), Geo_namespace::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().

178  {
179  if (geo_ti.get_type() == kPOINT && !geo_ti.get_notnull()) {
180  if (geo_ti.get_compression() == kENCODING_GEOINT) {
181  if (geo_ti.get_comp_param() == 32) {
182  return Geo_namespace::is_null_point_longitude_geoint32(*((int32_t*)coords));
183  }
184  } else {
186  return *((double*)coords) == NULL_ARRAY_DOUBLE;
187  }
188  }
189  return false;
190 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
#define NULL_ARRAY_DOUBLE
Definition: sqltypes.h:193
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:258
DEVICE bool is_null_point_longitude_geoint32(const int32_t compressed)
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:266
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:267
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:265

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 98 of file geo_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().

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

+ Here is the caller graph for this function:

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 112 of file geo_compression.cpp.

References CHECK_EQ.

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