boost::uint32_t IteratorBase::myReadBlocks(PointBuffer& user_buffer) { boost::uint32_t numPointsRead = 0; std::string const& query = getReader().getOptions().getValueOrThrow<std::string>("query"); ::soci::row block; ::soci::indicator ind = ::soci::i_null; ::soci::statement blocks = (m_session->prepare << query, ::soci::into(block, ind)); blocks.execute(); bool bDidRead = blocks.fetch(); // if (ind == ::soci::i_null) // { // // We have no points to return // getReader().log()->get(logDEBUG) << "Query returned no points" << std::endl; // return 0; // } // // size_t size = block.size(); // for (size_t i = 0; i < size; ++i) // { // getReader().log()->get(logDEBUG3) << "column: " << block.get_properties(i).get_name() << std::endl; // } if (!m_active_buffer) { m_active_buffer = fetchPointBuffer(block.get<int>("cloud_id"), block.get<std::string>("schema"), user_buffer.getCapacity()); m_active_cloud_id = block.get<int>("cloud_id"); } // // This shouldn't ever happen int num_points = block.get<int>("num_points"); if (num_points > static_cast<boost::int32_t>(m_active_buffer->getCapacity())) { std::ostringstream oss; oss << "Block size, " << num_points <<", is too large to fit in " << "buffer of size " << user_buffer.getCapacity() <<". Increase buffer capacity with writer's \"chunk_size\" option " << "or increase the read buffer size"; throw buffer_too_small(oss.str()); } while (bDidRead) { boost::uint32_t numReadThisBlock = static_cast<boost::uint32_t>(block.get<int>("num_points")); boost::uint32_t numSpaceLeftThisBuffer = user_buffer.getCapacity() - user_buffer.getNumPoints(); getReader().log()->get(logDEBUG4) << "IteratorBase::myReadBlocks:" "numReadThisBlock: " << numReadThisBlock << " numSpaceLeftThisBlock: " << numSpaceLeftThisBuffer << " total numPointsRead: " << numPointsRead << std::endl; numPointsRead = numPointsRead + numReadThisBlock; readBlob(block, (std::min)(numReadThisBlock, numSpaceLeftThisBuffer)); fillUserBuffer(user_buffer); bDidRead = blocks.fetch(); // if (!bDidRead) // return user_buffer.getNumPoints(); boost::int32_t const& current_cloud_id = block.get<int>("cloud_id"); if (current_cloud_id != m_active_cloud_id) { getReader().log()->get(logDEBUG3) << "IteratorBase::myReadBlocks: current_cloud_id: " << current_cloud_id << " m_active_cloud_id: " << m_active_cloud_id << std::endl; m_active_buffer = fetchPointBuffer(current_cloud_id, block.get<std::string>("schema"), user_buffer.getCapacity()); m_active_cloud_id = current_cloud_id; return user_buffer.getNumPoints(); } } return numPointsRead; }
boost::uint32_t IteratorBase::myReadBlocks(PointBuffer& user_buffer) { boost::uint32_t numPointsRead = 0; user_buffer.setNumPoints(0); bool bDidRead = false; if (!m_oracle_buffer) { m_oracle_buffer = fetchPointBuffer(m_initialQueryStatement, m_block->pc); if (!m_oracle_buffer) throw pdal_error("m_oracle_buffer was NULL!"); m_dimension_map = fetchDimensionMap(m_initialQueryStatement, m_block->pc, *m_oracle_buffer, user_buffer); boost::int32_t current_cloud_id(0); current_cloud_id = m_initialQueryStatement->GetInteger(&m_block->pc->pc_id); m_active_cloud_id = current_cloud_id; } // This shouldn't ever happen if (m_block->num_points > static_cast<boost::int32_t>(m_oracle_buffer->getCapacity())) { m_oracle_buffer->resize(m_block->num_points); } if (!m_block->num_points) { // We still have a block of data from the last readBuffer call // that was partially read. getReader().log()->get(logDEBUG3) << "IteratorBase::myReadBlocks: fetching first block" << std::endl; bDidRead = m_initialQueryStatement->Fetch(); if (!bDidRead) { m_at_end = true; return 0; } user_buffer.setSpatialBounds(getBounds(m_initialQueryStatement, m_block)); } else { // Our read was already "done" last readBuffer call, but if we're done, // we're done if (m_at_end) getReader().log()->get(logDEBUG3) << "IteratorBase::myReadBlocks: we are at end of the blocks;" << std::endl; else getReader().log()->get(logDEBUG3) << "IteratorBase::myReadBlocks: we have points left to read on this block" << std::endl; if (m_at_end) return 0; bDidRead = true; } while (bDidRead) { boost::uint32_t numReadThisBlock = m_block->num_points; boost::uint32_t numSpaceLeftThisBuffer = user_buffer.getCapacity() - user_buffer.getNumPoints(); getReader().log()->get(logDEBUG4) << "IteratorBase::myReadBlocks:" "numReadThisBlock: " << numReadThisBlock << " numSpaceLeftThisBlock: " << numSpaceLeftThisBuffer << " total numPointsRead: " << numPointsRead << std::endl; numPointsRead = numPointsRead + numReadThisBlock; readBlob(m_initialQueryStatement, m_block, m_block->num_points); fillUserBuffer(user_buffer); if (m_buffer_position != 0) { return user_buffer.getNumPoints(); } else { bDidRead = m_initialQueryStatement->Fetch(); if (!bDidRead) { getReader().log()->get(logDEBUG3) << "IteratorBase::myReadBlocks: done reading block. Read " << numPointsRead << " points" << std::endl; m_at_end = true; return user_buffer.getNumPoints(); } } boost::int32_t current_cloud_id(0); current_cloud_id = m_initialQueryStatement->GetInteger(&m_block->pc->pc_id); getReader().log()->get(logDEBUG3) << "IteratorBase::myReadBlocks: current_cloud_id: " << current_cloud_id << " m_active_cloud_id: " << m_active_cloud_id << std::endl; if (current_cloud_id != m_active_cloud_id) { m_oracle_buffer = fetchPointBuffer(m_initialQueryStatement, m_block->pc); if (!m_oracle_buffer) throw pdal_error("m_oracle_buffer was NULL!"); m_dimension_map = fetchDimensionMap(m_initialQueryStatement, m_block->pc, *m_oracle_buffer, user_buffer); m_active_cloud_id = current_cloud_id; return user_buffer.getNumPoints(); } } return numPointsRead; }