OmniSciDB  29e35f4d58
Importer_NS::RenderGroupAnalyzer Class Reference

#include <Importer.h>

Public Member Functions

 RenderGroupAnalyzer ()
 
void seedFromExistingTableContents (const std::unique_ptr< Loader > &loader, const std::string &geoColumnBaseName)
 
int insertBoundsAndReturnRenderGroup (const std::vector< double > &bounds)
 

Private Types

using Point = boost::geometry::model::point< double, 2, boost::geometry::cs::cartesian >
 
using BoundingBox = boost::geometry::model::box< Point >
 
using Node = std::pair< BoundingBox, int >
 
using RTree = boost::geometry::index::rtree< Node, boost::geometry::index::quadratic< 16 > >
 

Private Attributes

std::unique_ptr< RTree_rtree
 
std::mutex _rtreeMutex
 
int _numRenderGroups
 

Detailed Description

Definition at line 718 of file Importer.h.

Member Typedef Documentation

◆ BoundingBox

using Importer_NS::RenderGroupAnalyzer::BoundingBox = boost::geometry::model::box<Point>
private

Definition at line 727 of file Importer.h.

◆ Node

using Importer_NS::RenderGroupAnalyzer::Node = std::pair<BoundingBox, int>
private

Definition at line 728 of file Importer.h.

◆ Point

using Importer_NS::RenderGroupAnalyzer::Point = boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>
private

Definition at line 726 of file Importer.h.

◆ RTree

using Importer_NS::RenderGroupAnalyzer::RTree = boost::geometry::index::rtree<Node, boost::geometry::index::quadratic<16> >
private

Definition at line 730 of file Importer.h.

Constructor & Destructor Documentation

◆ RenderGroupAnalyzer()

Importer_NS::RenderGroupAnalyzer::RenderGroupAnalyzer ( )
inline

Definition at line 720 of file Importer.h.

720 : _rtree(std::make_unique<RTree>()), _numRenderGroups(0) {}
std::unique_ptr< RTree > _rtree
Definition: Importer.h:731

Member Function Documentation

◆ insertBoundsAndReturnRenderGroup()

int Importer_NS::RenderGroupAnalyzer::insertBoundsAndReturnRenderGroup ( const std::vector< double > &  bounds)

Definition at line 4992 of file Importer.cpp.

References CHECK.

Referenced by GeoPolygonValueConverter::convertToColumnarFormat(), and GeoMultiPolygonValueConverter::convertToColumnarFormat().

4993  {
4994  // validate
4995  CHECK(bounds.size() == 4);
4996 
4997  // get bounds
4998  BoundingBox bounding_box;
4999  boost::geometry::assign_inverse(bounding_box);
5000  boost::geometry::expand(bounding_box, Point(bounds[0], bounds[1]));
5001  boost::geometry::expand(bounding_box, Point(bounds[2], bounds[3]));
5002 
5003  // remainder under mutex to allow this to be multi-threaded
5004  std::lock_guard<std::mutex> guard(_rtreeMutex);
5005 
5006  // get the intersecting nodes
5007  std::vector<Node> intersects;
5008  _rtree->query(boost::geometry::index::intersects(bounding_box),
5009  std::back_inserter(intersects));
5010 
5011  // build bitset of render groups of the intersecting rectangles
5012  // clear bit means available, allows use of find_first()
5013  boost::dynamic_bitset<> bits(_numRenderGroups);
5014  bits.set();
5015  for (const auto& intersection : intersects) {
5016  CHECK(intersection.second < _numRenderGroups);
5017  bits.reset(intersection.second);
5018  }
5019 
5020  // find first available group
5021  int firstAvailableRenderGroup = 0;
5022  size_t firstSetBit = bits.find_first();
5023  if (firstSetBit == boost::dynamic_bitset<>::npos) {
5024  // all known groups represented, add a new one
5025  firstAvailableRenderGroup = _numRenderGroups;
5026  _numRenderGroups++;
5027  } else {
5028  firstAvailableRenderGroup = (int)firstSetBit;
5029  }
5030 
5031  // insert new node
5032  _rtree->insert(std::make_pair(bounding_box, firstAvailableRenderGroup));
5033 
5034  // return it
5035  return firstAvailableRenderGroup;
5036 }
boost::geometry::model::point< double, 2, boost::geometry::cs::cartesian > Point
Definition: Importer.h:726
boost::geometry::model::box< Point > BoundingBox
Definition: Importer.h:727
#define CHECK(condition)
Definition: Logger.h:193
std::unique_ptr< RTree > _rtree
Definition: Importer.h:731
+ Here is the caller graph for this function:

◆ seedFromExistingTableContents()

void Importer_NS::RenderGroupAnalyzer::seedFromExistingTableContents ( const std::unique_ptr< Loader > &  loader,
const std::string &  geoColumnBaseName 
)

Definition at line 4868 of file Importer.cpp.

References CHECK, CHECK_GE, ChunkIter_get_nth(), DEBUG_RENDER_GROUP_ANALYZER, getChunkAccessorTable(), getChunkItersAndRowOffset(), logger::INFO, kARRAY, kDOUBLE, kINT, LOG, VarlenDatum::pointer, timer_start(), timer_stop(), and to_string().

4870  {
4871  // start timer
4872  auto seedTimer = timer_start();
4873 
4874  // get the table descriptor
4875  const auto& cat = loader->getCatalog();
4876  const std::string& tableName = loader->getTableDesc()->tableName;
4877  const auto td = cat.getMetadataForTable(tableName);
4878  CHECK(td);
4879  CHECK(td->fragmenter);
4880 
4881  // start with a fresh tree
4882  _rtree = nullptr;
4883  _numRenderGroups = 0;
4884 
4885  // if the table is empty, just make an empty tree
4886  if (td->fragmenter->getFragmentsForQuery().getPhysicalNumTuples() == 0) {
4888  LOG(INFO) << "DEBUG: Table is empty!";
4889  }
4890  _rtree = std::make_unique<RTree>();
4891  CHECK(_rtree);
4892  return;
4893  }
4894 
4895  // no seeding possible without these two columns
4896  const auto cd_bounds =
4897  cat.getMetadataForColumn(td->tableId, geoColumnBaseName + "_bounds");
4898  const auto cd_render_group =
4899  cat.getMetadataForColumn(td->tableId, geoColumnBaseName + "_render_group");
4900  if (!cd_bounds || !cd_render_group) {
4901  throw std::runtime_error("RenderGroupAnalyzer: Table " + tableName +
4902  " doesn't have bounds or render_group columns!");
4903  }
4904 
4905  // and validate their types
4906  if (cd_bounds->columnType.get_type() != kARRAY ||
4907  cd_bounds->columnType.get_subtype() != kDOUBLE) {
4908  throw std::runtime_error("RenderGroupAnalyzer: Table " + tableName +
4909  " bounds column is wrong type!");
4910  }
4911  if (cd_render_group->columnType.get_type() != kINT) {
4912  throw std::runtime_error("RenderGroupAnalyzer: Table " + tableName +
4913  " render_group column is wrong type!");
4914  }
4915 
4916  // get chunk accessor table
4917  auto chunkAccessorTable = getChunkAccessorTable(
4918  cat, td, {geoColumnBaseName + "_bounds", geoColumnBaseName + "_render_group"});
4919  const auto table_count = std::get<0>(chunkAccessorTable.back());
4920 
4922  LOG(INFO) << "DEBUG: Scanning existing table geo column set '" << geoColumnBaseName
4923  << "'";
4924  }
4925 
4926  std::vector<Node> nodes;
4927  try {
4928  nodes.resize(table_count);
4929  } catch (const std::exception& e) {
4930  throw std::runtime_error("RenderGroupAnalyzer failed to reserve memory for " +
4931  std::to_string(table_count) + " rows");
4932  }
4933 
4934  for (size_t row = 0; row < table_count; row++) {
4935  ArrayDatum ad;
4936  VarlenDatum vd;
4937  bool is_end;
4938 
4939  // get ChunkIters and fragment row offset
4940  size_t rowOffset = 0;
4941  auto& chunkIters = getChunkItersAndRowOffset(chunkAccessorTable, row, rowOffset);
4942  auto& boundsChunkIter = chunkIters[0];
4943  auto& renderGroupChunkIter = chunkIters[1];
4944 
4945  // get bounds values
4946  ChunkIter_get_nth(&boundsChunkIter, row - rowOffset, &ad, &is_end);
4947  CHECK(!is_end);
4948  CHECK(ad.pointer);
4949  int numBounds = (int)(ad.length / sizeof(double));
4950  CHECK(numBounds == 4);
4951 
4952  // convert to bounding box
4953  double* bounds = reinterpret_cast<double*>(ad.pointer);
4954  BoundingBox bounding_box;
4955  boost::geometry::assign_inverse(bounding_box);
4956  boost::geometry::expand(bounding_box, Point(bounds[0], bounds[1]));
4957  boost::geometry::expand(bounding_box, Point(bounds[2], bounds[3]));
4958 
4959  // get render group
4960  ChunkIter_get_nth(&renderGroupChunkIter, row - rowOffset, false, &vd, &is_end);
4961  CHECK(!is_end);
4962  CHECK(vd.pointer);
4963  int renderGroup = *reinterpret_cast<int32_t*>(vd.pointer);
4964  CHECK_GE(renderGroup, 0);
4965 
4966  // store
4967  nodes[row] = std::make_pair(bounding_box, renderGroup);
4968 
4969  // how many render groups do we have now?
4970  if (renderGroup >= _numRenderGroups) {
4971  _numRenderGroups = renderGroup + 1;
4972  }
4973 
4975  LOG(INFO) << "DEBUG: Existing row " << row << " has Render Group " << renderGroup;
4976  }
4977  }
4978 
4979  // bulk-load the tree
4980  auto bulk_load_timer = timer_start();
4981  _rtree = std::make_unique<RTree>(nodes);
4982  CHECK(_rtree);
4983  LOG(INFO) << "Scanning render groups of poly column '" << geoColumnBaseName
4984  << "' of table '" << tableName << "' took " << timer_stop(seedTimer) << "ms ("
4985  << timer_stop(bulk_load_timer) << " ms for tree)";
4986 
4988  LOG(INFO) << "DEBUG: Done! Now have " << _numRenderGroups << " Render Groups";
4989  }
4990 }
ChunkAccessorTable getChunkAccessorTable(const Catalog_Namespace::Catalog &cat, const TableDescriptor *td, const std::vector< std::string > &columnNames)
#define LOG(tag)
Definition: Logger.h:188
#define CHECK_GE(x, y)
Definition: Logger.h:206
TypeR::rep timer_stop(Type clock_begin)
Definition: measure.h:46
boost::geometry::model::point< double, 2, boost::geometry::cs::cartesian > Point
Definition: Importer.h:726
DEVICE void ChunkIter_get_nth(ChunkIter *it, int n, bool uncompress, VarlenDatum *result, bool *is_end)
Definition: ChunkIter.cpp:181
std::string to_string(char const *&&v)
int8_t * pointer
Definition: sqltypes.h:75
ChunkIterVector & getChunkItersAndRowOffset(ChunkAccessorTable &table, size_t rowid, size_t &rowOffset)
boost::geometry::model::box< Point > BoundingBox
Definition: Importer.h:727
#define DEBUG_RENDER_GROUP_ANALYZER
Definition: Importer.cpp:139
#define CHECK(condition)
Definition: Logger.h:193
Definition: sqltypes.h:48
std::unique_ptr< RTree > _rtree
Definition: Importer.h:731
Type timer_start()
Definition: measure.h:40
std::conditional_t< isCudaCC(), DeviceArrayDatum, HostArrayDatum > ArrayDatum
Definition: sqltypes.h:122
+ Here is the call graph for this function:

Member Data Documentation

◆ _numRenderGroups

int Importer_NS::RenderGroupAnalyzer::_numRenderGroups
private

Definition at line 733 of file Importer.h.

◆ _rtree

std::unique_ptr<RTree> Importer_NS::RenderGroupAnalyzer::_rtree
private

Definition at line 731 of file Importer.h.

◆ _rtreeMutex

std::mutex Importer_NS::RenderGroupAnalyzer::_rtreeMutex
private

Definition at line 732 of file Importer.h.


The documentation for this class was generated from the following files: