OmniSciDB  04ee39c94c
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 856 of file Importer.h.

Member Typedef Documentation

◆ BoundingBox

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

Definition at line 865 of file Importer.h.

◆ Node

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

Definition at line 866 of file Importer.h.

◆ Point

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

Definition at line 864 of file Importer.h.

◆ RTree

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

Definition at line 868 of file Importer.h.

Constructor & Destructor Documentation

◆ RenderGroupAnalyzer()

Importer_NS::RenderGroupAnalyzer::RenderGroupAnalyzer ( )
inline

Definition at line 858 of file Importer.h.

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

Member Function Documentation

◆ insertBoundsAndReturnRenderGroup()

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

Definition at line 4896 of file Importer.cpp.

References CHECK.

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

4897  {
4898  // validate
4899  CHECK(bounds.size() == 4);
4900 
4901  // get bounds
4902  BoundingBox bounding_box;
4903  boost::geometry::assign_inverse(bounding_box);
4904  boost::geometry::expand(bounding_box, Point(bounds[0], bounds[1]));
4905  boost::geometry::expand(bounding_box, Point(bounds[2], bounds[3]));
4906 
4907  // remainder under mutex to allow this to be multi-threaded
4908  std::lock_guard<std::mutex> guard(_rtreeMutex);
4909 
4910  // get the intersecting nodes
4911  std::vector<Node> intersects;
4912  _rtree->query(boost::geometry::index::intersects(bounding_box),
4913  std::back_inserter(intersects));
4914 
4915  // build bitset of render groups of the intersecting rectangles
4916  // clear bit means available, allows use of find_first()
4917  boost::dynamic_bitset<> bits(_numRenderGroups);
4918  bits.set();
4919  for (const auto& intersection : intersects) {
4920  CHECK(intersection.second < _numRenderGroups);
4921  bits.reset(intersection.second);
4922  }
4923 
4924  // find first available group
4925  int firstAvailableRenderGroup = 0;
4926  size_t firstSetBit = bits.find_first();
4927  if (firstSetBit == boost::dynamic_bitset<>::npos) {
4928  // all known groups represented, add a new one
4929  firstAvailableRenderGroup = _numRenderGroups;
4930  _numRenderGroups++;
4931  } else {
4932  firstAvailableRenderGroup = (int)firstSetBit;
4933  }
4934 
4935  // insert new node
4936  _rtree->insert(std::make_pair(bounding_box, firstAvailableRenderGroup));
4937 
4938  // return it
4939  return firstAvailableRenderGroup;
4940 }
boost::geometry::model::point< double, 2, boost::geometry::cs::cartesian > Point
Definition: Importer.h:864
boost::geometry::model::box< Point > BoundingBox
Definition: Importer.h:865
#define CHECK(condition)
Definition: Logger.h:187
std::unique_ptr< RTree > _rtree
Definition: Importer.h:869
+ 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 4772 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().

4774  {
4775  // start timer
4776  auto seedTimer = timer_start();
4777 
4778  // get the table descriptor
4779  const auto& cat = loader->getCatalog();
4780  const std::string& tableName = loader->getTableDesc()->tableName;
4781  const auto td = cat.getMetadataForTable(tableName);
4782  CHECK(td);
4783  CHECK(td->fragmenter);
4784 
4785  // start with a fresh tree
4786  _rtree = nullptr;
4787  _numRenderGroups = 0;
4788 
4789  // if the table is empty, just make an empty tree
4790  if (td->fragmenter->getFragmentsForQuery().getPhysicalNumTuples() == 0) {
4792  LOG(INFO) << "DEBUG: Table is empty!";
4793  }
4794  _rtree = std::make_unique<RTree>();
4795  CHECK(_rtree);
4796  return;
4797  }
4798 
4799  // no seeding possible without these two columns
4800  const auto cd_bounds =
4801  cat.getMetadataForColumn(td->tableId, geoColumnBaseName + "_bounds");
4802  const auto cd_render_group =
4803  cat.getMetadataForColumn(td->tableId, geoColumnBaseName + "_render_group");
4804  if (!cd_bounds || !cd_render_group) {
4805  throw std::runtime_error("RenderGroupAnalyzer: Table " + tableName +
4806  " doesn't have bounds or render_group columns!");
4807  }
4808 
4809  // and validate their types
4810  if (cd_bounds->columnType.get_type() != kARRAY ||
4811  cd_bounds->columnType.get_subtype() != kDOUBLE) {
4812  throw std::runtime_error("RenderGroupAnalyzer: Table " + tableName +
4813  " bounds column is wrong type!");
4814  }
4815  if (cd_render_group->columnType.get_type() != kINT) {
4816  throw std::runtime_error("RenderGroupAnalyzer: Table " + tableName +
4817  " render_group column is wrong type!");
4818  }
4819 
4820  // get chunk accessor table
4821  auto chunkAccessorTable = getChunkAccessorTable(
4822  cat, td, {geoColumnBaseName + "_bounds", geoColumnBaseName + "_render_group"});
4823  const auto table_count = std::get<0>(chunkAccessorTable.back());
4824 
4826  LOG(INFO) << "DEBUG: Scanning existing table geo column set '" << geoColumnBaseName
4827  << "'";
4828  }
4829 
4830  std::vector<Node> nodes;
4831  try {
4832  nodes.resize(table_count);
4833  } catch (const std::exception& e) {
4834  throw std::runtime_error("RenderGroupAnalyzer failed to reserve memory for " +
4835  std::to_string(table_count) + " rows");
4836  }
4837 
4838  for (size_t row = 0; row < table_count; row++) {
4839  ArrayDatum ad;
4840  VarlenDatum vd;
4841  bool is_end;
4842 
4843  // get ChunkIters and fragment row offset
4844  size_t rowOffset = 0;
4845  auto& chunkIters = getChunkItersAndRowOffset(chunkAccessorTable, row, rowOffset);
4846  auto& boundsChunkIter = chunkIters[0];
4847  auto& renderGroupChunkIter = chunkIters[1];
4848 
4849  // get bounds values
4850  ChunkIter_get_nth(&boundsChunkIter, row - rowOffset, &ad, &is_end);
4851  CHECK(!is_end);
4852  CHECK(ad.pointer);
4853  int numBounds = (int)(ad.length / sizeof(double));
4854  CHECK(numBounds == 4);
4855 
4856  // convert to bounding box
4857  double* bounds = reinterpret_cast<double*>(ad.pointer);
4858  BoundingBox bounding_box;
4859  boost::geometry::assign_inverse(bounding_box);
4860  boost::geometry::expand(bounding_box, Point(bounds[0], bounds[1]));
4861  boost::geometry::expand(bounding_box, Point(bounds[2], bounds[3]));
4862 
4863  // get render group
4864  ChunkIter_get_nth(&renderGroupChunkIter, row - rowOffset, false, &vd, &is_end);
4865  CHECK(!is_end);
4866  CHECK(vd.pointer);
4867  int renderGroup = *reinterpret_cast<int32_t*>(vd.pointer);
4868  CHECK_GE(renderGroup, 0);
4869 
4870  // store
4871  nodes[row] = std::make_pair(bounding_box, renderGroup);
4872 
4873  // how many render groups do we have now?
4874  if (renderGroup >= _numRenderGroups) {
4875  _numRenderGroups = renderGroup + 1;
4876  }
4877 
4879  LOG(INFO) << "DEBUG: Existing row " << row << " has Render Group " << renderGroup;
4880  }
4881  }
4882 
4883  // bulk-load the tree
4884  auto bulk_load_timer = timer_start();
4885  _rtree = std::make_unique<RTree>(nodes);
4886  CHECK(_rtree);
4887  LOG(INFO) << "Scanning render groups of poly column '" << geoColumnBaseName
4888  << "' of table '" << tableName << "' took " << timer_stop(seedTimer) << "ms ("
4889  << timer_stop(bulk_load_timer) << " ms for tree)";
4890 
4892  LOG(INFO) << "DEBUG: Done! Now have " << _numRenderGroups << " Render Groups";
4893  }
4894 }
ChunkAccessorTable getChunkAccessorTable(const Catalog_Namespace::Catalog &cat, const TableDescriptor *td, const std::vector< std::string > &columnNames)
#define LOG(tag)
Definition: Logger.h:182
#define CHECK_GE(x, y)
Definition: Logger.h:200
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:864
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:72
ChunkIterVector & getChunkItersAndRowOffset(ChunkAccessorTable &table, size_t rowid, size_t &rowOffset)
boost::geometry::model::box< Point > BoundingBox
Definition: Importer.h:865
#define DEBUG_RENDER_GROUP_ANALYZER
Definition: Importer.cpp:136
#define CHECK(condition)
Definition: Logger.h:187
Definition: sqltypes.h:47
std::unique_ptr< RTree > _rtree
Definition: Importer.h:869
Type timer_start()
Definition: measure.h:40
std::conditional_t< isCudaCC(), DeviceArrayDatum, HostArrayDatum > ArrayDatum
Definition: sqltypes.h:119
+ Here is the call graph for this function:

Member Data Documentation

◆ _numRenderGroups

int Importer_NS::RenderGroupAnalyzer::_numRenderGroups
private

Definition at line 871 of file Importer.h.

◆ _rtree

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

Definition at line 869 of file Importer.h.

◆ _rtreeMutex

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

Definition at line 870 of file Importer.h.


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