25 #include <boost/dynamic_bitset.hpp>
26 #include <boost/geometry.hpp>
39 namespace import_export {
45 #define DEBUG_RENDER_GROUP_ANALYZER 0
49 const std::string& tableName,
50 const std::string& geoColumnBaseName) {
65 LOG(
INFO) <<
"DEBUG: Table is a foreign table";
67 _rtree = std::make_unique<RTree>();
73 CHECK(td->fragmenter);
74 if (td->fragmenter->getFragmentsForQuery().getPhysicalNumTuples() == 0) {
76 LOG(
INFO) <<
"DEBUG: Table is empty!";
78 _rtree = std::make_unique<RTree>();
84 const auto cd_bounds =
86 const auto cd_render_group =
88 if (!cd_bounds || !cd_render_group) {
89 throw std::runtime_error(
"RenderGroupAnalyzer: Table " + tableName +
90 " doesn't have bounds or render_group columns!");
94 if (cd_bounds->columnType.get_type() !=
kARRAY ||
95 cd_bounds->columnType.get_subtype() !=
kDOUBLE) {
96 throw std::runtime_error(
"RenderGroupAnalyzer: Table " + tableName +
97 " bounds column is wrong type!");
99 if (cd_render_group->columnType.get_type() !=
kINT) {
100 throw std::runtime_error(
"RenderGroupAnalyzer: Table " + tableName +
101 " render_group column is wrong type!");
106 cat, td, {geoColumnBaseName +
"_bounds", geoColumnBaseName +
"_render_group"});
107 const auto table_count = std::get<0>(chunkAccessorTable.back());
110 LOG(
INFO) <<
"DEBUG: Scanning existing table geo column set '" << geoColumnBaseName
114 std::vector<Node> nodes;
116 nodes.resize(table_count);
117 }
catch (
const std::exception& e) {
118 throw std::runtime_error(
"RenderGroupAnalyzer failed to reserve memory for " +
122 for (
size_t row = 0; row < table_count; row++) {
128 size_t rowOffset = 0;
130 auto& boundsChunkIter = chunkIters[0];
131 auto& renderGroupChunkIter = chunkIters[1];
137 int numBounds = (int)(ad.length /
sizeof(
double));
138 CHECK(numBounds == 4);
141 double* bounds =
reinterpret_cast<double*
>(ad.pointer);
143 boost::geometry::assign_inverse(bounding_box);
144 boost::geometry::expand(bounding_box,
Point(bounds[0], bounds[1]));
145 boost::geometry::expand(bounding_box,
Point(bounds[2], bounds[3]));
151 int renderGroup = *
reinterpret_cast<int32_t*
>(vd.
pointer);
154 if (renderGroup < 0) {
159 nodes[row] = std::make_pair(bounding_box, renderGroup);
167 LOG(
INFO) <<
"DEBUG: Existing row " << row <<
" has Render Group " << renderGroup;
173 _rtree = std::make_unique<RTree>(nodes);
175 LOG(
INFO) <<
"Scanning render groups of poly column '" << geoColumnBaseName
176 <<
"' of table '" << tableName <<
"' took " <<
timer_stop(seedTimer) <<
"ms ("
177 <<
timer_stop(bulk_load_timer) <<
" ms for tree)";
185 const std::vector<double>& bounds) {
187 CHECK(bounds.size() == 4);
191 boost::geometry::assign_inverse(bounding_box);
192 boost::geometry::expand(bounding_box,
Point(bounds[0], bounds[1]));
193 boost::geometry::expand(bounding_box,
Point(bounds[2], bounds[3]));
199 std::vector<Node> intersects;
200 _rtree->query(boost::geometry::index::intersects(bounding_box),
201 std::back_inserter(intersects));
207 for (
const auto& intersection : intersects) {
209 bits.reset(intersection.second);
213 int firstAvailableRenderGroup = 0;
214 size_t firstSetBit = bits.find_first();
215 if (firstSetBit == boost::dynamic_bitset<>::npos) {
220 firstAvailableRenderGroup = (int)firstSetBit;
224 _rtree->insert(std::make_pair(bounding_box, firstAvailableRenderGroup));
227 return firstAvailableRenderGroup;
ChunkAccessorTable getChunkAccessorTable(const Catalog_Namespace::Catalog &cat, const TableDescriptor *td, const std::vector< std::string > &columnNames)
class for a per-database catalog. also includes metadata for the current database and the current use...
TypeR::rep timer_stop(Type clock_begin)
DEVICE void ChunkIter_get_nth(ChunkIter *it, int n, bool uncompress, VarlenDatum *result, bool *is_end)
std::conditional_t< is_cuda_compiler(), DeviceArrayDatum, HostArrayDatum > ArrayDatum
This file contains the class specification and related data structures for Catalog.
ChunkIterVector & getChunkItersAndRowOffset(ChunkAccessorTable &table, size_t rowid, size_t &rowOffset)
const ColumnDescriptor * getMetadataForColumn(int tableId, const std::string &colName) const
void seedFromExistingTableContents(const Catalog_Namespace::Catalog &cat, const std::string &tableName, const std::string &geoColumnBaseName)
boost::geometry::model::box< Point > BoundingBox
std::unique_ptr< RTree > _rtree
#define DEBUG_RENDER_GROUP_ANALYZER
const TableDescriptor * getMetadataForTable(const std::string &tableName, const bool populateFragmenter=true) const
Returns a pointer to a const TableDescriptor struct matching the provided tableName.
static constexpr char const * FOREIGN_TABLE
int insertBoundsAndReturnRenderGroup(const std::vector< double > &bounds)
boost::geometry::model::point< double, 2, boost::geometry::cs::cartesian > Point