OmniSciDB  340b00dbf6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
import_export::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 712 of file Importer.h.

Member Typedef Documentation

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

Definition at line 721 of file Importer.h.

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

Definition at line 722 of file Importer.h.

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

Definition at line 720 of file Importer.h.

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

Definition at line 724 of file Importer.h.

Constructor & Destructor Documentation

import_export::RenderGroupAnalyzer::RenderGroupAnalyzer ( )
inline

Definition at line 714 of file Importer.h.

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

Member Function Documentation

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

Definition at line 5106 of file Importer.cpp.

References _numRenderGroups, _rtree, _rtreeMutex, and CHECK.

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

5107  {
5108  // validate
5109  CHECK(bounds.size() == 4);
5110 
5111  // get bounds
5112  BoundingBox bounding_box;
5113  boost::geometry::assign_inverse(bounding_box);
5114  boost::geometry::expand(bounding_box, Point(bounds[0], bounds[1]));
5115  boost::geometry::expand(bounding_box, Point(bounds[2], bounds[3]));
5116 
5117  // remainder under mutex to allow this to be multi-threaded
5118  std::lock_guard<std::mutex> guard(_rtreeMutex);
5119 
5120  // get the intersecting nodes
5121  std::vector<Node> intersects;
5122  _rtree->query(boost::geometry::index::intersects(bounding_box),
5123  std::back_inserter(intersects));
5124 
5125  // build bitset of render groups of the intersecting rectangles
5126  // clear bit means available, allows use of find_first()
5127  boost::dynamic_bitset<> bits(_numRenderGroups);
5128  bits.set();
5129  for (const auto& intersection : intersects) {
5130  CHECK(intersection.second < _numRenderGroups);
5131  bits.reset(intersection.second);
5132  }
5133 
5134  // find first available group
5135  int firstAvailableRenderGroup = 0;
5136  size_t firstSetBit = bits.find_first();
5137  if (firstSetBit == boost::dynamic_bitset<>::npos) {
5138  // all known groups represented, add a new one
5139  firstAvailableRenderGroup = _numRenderGroups;
5140  _numRenderGroups++;
5141  } else {
5142  firstAvailableRenderGroup = (int)firstSetBit;
5143  }
5144 
5145  // insert new node
5146  _rtree->insert(std::make_pair(bounding_box, firstAvailableRenderGroup));
5147 
5148  // return it
5149  return firstAvailableRenderGroup;
5150 }
boost::geometry::model::box< Point > BoundingBox
Definition: Importer.h:721
std::unique_ptr< RTree > _rtree
Definition: Importer.h:725
#define CHECK(condition)
Definition: Logger.h:197
boost::geometry::model::point< double, 2, boost::geometry::cs::cartesian > Point
Definition: Importer.h:720

+ Here is the caller graph for this function:

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

Definition at line 4969 of file Importer.cpp.

References _numRenderGroups, _rtree, cat(), CHECK, ChunkIter_get_nth(), DEBUG_RENDER_GROUP_ANALYZER, StorageType::FOREIGN_TABLE, getChunkAccessorTable(), getChunkItersAndRowOffset(), logger::INFO, kARRAY, kDOUBLE, kINT, LOG, VarlenDatum::pointer, timer_start(), timer_stop(), and to_string().

4971  {
4972  // start timer
4973  auto seedTimer = timer_start();
4974 
4975  // start with a fresh tree
4976  _rtree = nullptr;
4977  _numRenderGroups = 0;
4978 
4979  // get the table descriptor
4980  const auto& cat = loader->getCatalog();
4981  if (loader->getTableDesc()->storageType == StorageType::FOREIGN_TABLE) {
4983  LOG(INFO) << "DEBUG: Table is a foreign table";
4984  }
4985  _rtree = std::make_unique<RTree>();
4986  CHECK(_rtree);
4987  return;
4988  }
4989 
4990  const std::string& tableName = loader->getTableDesc()->tableName;
4991  const auto td = cat.getMetadataForTable(tableName);
4992  CHECK(td);
4993  CHECK(td->fragmenter);
4994 
4995  // if the table is empty, just make an empty tree
4996  if (td->fragmenter->getFragmentsForQuery().getPhysicalNumTuples() == 0) {
4998  LOG(INFO) << "DEBUG: Table is empty!";
4999  }
5000  _rtree = std::make_unique<RTree>();
5001  CHECK(_rtree);
5002  return;
5003  }
5004 
5005  // no seeding possible without these two columns
5006  const auto cd_bounds =
5007  cat.getMetadataForColumn(td->tableId, geoColumnBaseName + "_bounds");
5008  const auto cd_render_group =
5009  cat.getMetadataForColumn(td->tableId, geoColumnBaseName + "_render_group");
5010  if (!cd_bounds || !cd_render_group) {
5011  throw std::runtime_error("RenderGroupAnalyzer: Table " + tableName +
5012  " doesn't have bounds or render_group columns!");
5013  }
5014 
5015  // and validate their types
5016  if (cd_bounds->columnType.get_type() != kARRAY ||
5017  cd_bounds->columnType.get_subtype() != kDOUBLE) {
5018  throw std::runtime_error("RenderGroupAnalyzer: Table " + tableName +
5019  " bounds column is wrong type!");
5020  }
5021  if (cd_render_group->columnType.get_type() != kINT) {
5022  throw std::runtime_error("RenderGroupAnalyzer: Table " + tableName +
5023  " render_group column is wrong type!");
5024  }
5025 
5026  // get chunk accessor table
5027  auto chunkAccessorTable = getChunkAccessorTable(
5028  cat, td, {geoColumnBaseName + "_bounds", geoColumnBaseName + "_render_group"});
5029  const auto table_count = std::get<0>(chunkAccessorTable.back());
5030 
5032  LOG(INFO) << "DEBUG: Scanning existing table geo column set '" << geoColumnBaseName
5033  << "'";
5034  }
5035 
5036  std::vector<Node> nodes;
5037  try {
5038  nodes.resize(table_count);
5039  } catch (const std::exception& e) {
5040  throw std::runtime_error("RenderGroupAnalyzer failed to reserve memory for " +
5041  std::to_string(table_count) + " rows");
5042  }
5043 
5044  for (size_t row = 0; row < table_count; row++) {
5045  ArrayDatum ad;
5046  VarlenDatum vd;
5047  bool is_end;
5048 
5049  // get ChunkIters and fragment row offset
5050  size_t rowOffset = 0;
5051  auto& chunkIters = getChunkItersAndRowOffset(chunkAccessorTable, row, rowOffset);
5052  auto& boundsChunkIter = chunkIters[0];
5053  auto& renderGroupChunkIter = chunkIters[1];
5054 
5055  // get bounds values
5056  ChunkIter_get_nth(&boundsChunkIter, row - rowOffset, &ad, &is_end);
5057  CHECK(!is_end);
5058  CHECK(ad.pointer);
5059  int numBounds = (int)(ad.length / sizeof(double));
5060  CHECK(numBounds == 4);
5061 
5062  // convert to bounding box
5063  double* bounds = reinterpret_cast<double*>(ad.pointer);
5064  BoundingBox bounding_box;
5065  boost::geometry::assign_inverse(bounding_box);
5066  boost::geometry::expand(bounding_box, Point(bounds[0], bounds[1]));
5067  boost::geometry::expand(bounding_box, Point(bounds[2], bounds[3]));
5068 
5069  // get render group
5070  ChunkIter_get_nth(&renderGroupChunkIter, row - rowOffset, false, &vd, &is_end);
5071  CHECK(!is_end);
5072  CHECK(vd.pointer);
5073  int renderGroup = *reinterpret_cast<int32_t*>(vd.pointer);
5074 
5075  // skip rows with invalid render groups (e.g. EMPTY geometry)
5076  if (renderGroup < 0) {
5077  continue;
5078  }
5079 
5080  // store
5081  nodes[row] = std::make_pair(bounding_box, renderGroup);
5082 
5083  // how many render groups do we have now?
5084  if (renderGroup >= _numRenderGroups) {
5085  _numRenderGroups = renderGroup + 1;
5086  }
5087 
5089  LOG(INFO) << "DEBUG: Existing row " << row << " has Render Group " << renderGroup;
5090  }
5091  }
5092 
5093  // bulk-load the tree
5094  auto bulk_load_timer = timer_start();
5095  _rtree = std::make_unique<RTree>(nodes);
5096  CHECK(_rtree);
5097  LOG(INFO) << "Scanning render groups of poly column '" << geoColumnBaseName
5098  << "' of table '" << tableName << "' took " << timer_stop(seedTimer) << "ms ("
5099  << timer_stop(bulk_load_timer) << " ms for tree)";
5100 
5102  LOG(INFO) << "DEBUG: Done! Now have " << _numRenderGroups << " Render Groups";
5103  }
5104 }
ChunkAccessorTable getChunkAccessorTable(const Catalog_Namespace::Catalog &cat, const TableDescriptor *td, const std::vector< std::string > &columnNames)
std::string cat(Ts &&...args)
#define LOG(tag)
Definition: Logger.h:188
TypeR::rep timer_stop(Type clock_begin)
Definition: measure.h:48
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:146
std::conditional_t< is_cuda_compiler(), DeviceArrayDatum, HostArrayDatum > ArrayDatum
Definition: sqltypes.h:202
ChunkIterVector & getChunkItersAndRowOffset(ChunkAccessorTable &table, size_t rowid, size_t &rowOffset)
#define DEBUG_RENDER_GROUP_ANALYZER
Definition: Importer.cpp:138
boost::geometry::model::box< Point > BoundingBox
Definition: Importer.h:721
std::unique_ptr< RTree > _rtree
Definition: Importer.h:725
#define CHECK(condition)
Definition: Logger.h:197
Definition: sqltypes.h:47
static constexpr char const * FOREIGN_TABLE
Type timer_start()
Definition: measure.h:42
boost::geometry::model::point< double, 2, boost::geometry::cs::cartesian > Point
Definition: Importer.h:720

+ Here is the call graph for this function:

Member Data Documentation

int import_export::RenderGroupAnalyzer::_numRenderGroups
private

Definition at line 727 of file Importer.h.

Referenced by insertBoundsAndReturnRenderGroup(), and seedFromExistingTableContents().

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

Definition at line 725 of file Importer.h.

Referenced by insertBoundsAndReturnRenderGroup(), and seedFromExistingTableContents().

std::mutex import_export::RenderGroupAnalyzer::_rtreeMutex
private

Definition at line 726 of file Importer.h.

Referenced by insertBoundsAndReturnRenderGroup().


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