OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ChunkAccessorTable.h File Reference
#include <Catalog/Catalog.h>
#include <Chunk/Chunk.h>
#include <vector>
+ Include dependency graph for ChunkAccessorTable.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

using ChunkIterVector = std::vector< ChunkIter >
 
using ChunkAccessorTable = std::vector< std::tuple< size_t, std::vector< std::shared_ptr< Chunk_NS::Chunk >>, ChunkIterVector >>
 

Functions

ChunkAccessorTable getChunkAccessorTable (const Catalog_Namespace::Catalog &cat, const TableDescriptor *td, const std::vector< std::string > &columnNames)
 
ChunkIterVectorgetChunkItersAndRowOffset (ChunkAccessorTable &table, size_t rowid, size_t &rowOffset)
 

Detailed Description

Typedef Documentation

using ChunkAccessorTable = std::vector< std::tuple<size_t, std::vector<std::shared_ptr<Chunk_NS::Chunk>>, ChunkIterVector>>

Definition at line 35 of file ChunkAccessorTable.h.

using ChunkIterVector = std::vector<ChunkIter>

Definition at line 33 of file ChunkAccessorTable.h.

Function Documentation

ChunkAccessorTable getChunkAccessorTable ( const Catalog_Namespace::Catalog cat,
const TableDescriptor td,
const std::vector< std::string > &  columnNames 
)

Definition at line 24 of file ChunkAccessorTable.cpp.

References CHECK(), Data_Namespace::CPU_LEVEL, Catalog_Namespace::DBMetadata::dbId, TableDescriptor::fragmenter, Chunk_NS::Chunk::getChunk(), Catalog_Namespace::Catalog::getCurrentDB(), Catalog_Namespace::Catalog::getDataMgr(), Fragmenter_Namespace::AbstractFragmenter::getFragmentsForQuery(), Catalog_Namespace::Catalog::getMetadataForColumn(), TableDescriptor::tableId, and TableDescriptor::tableName.

Referenced by Importer_NS::RenderGroupAnalyzer::seedFromExistingTableContents().

26  {
27  ChunkAccessorTable table;
28 
29  // get fragments
30  const auto tableInfo = td->fragmenter->getFragmentsForQuery();
31  if (tableInfo.fragments.size() == 0) {
32  throw std::runtime_error("No fragments in table '" + td->tableName + "'");
33  }
34 
35  // for each fragment...
36  for (const auto& fragment : tableInfo.fragments) {
37  // add a table entry for it
38  table.emplace_back();
39  std::get<0>(table.back()) = 0;
40 
41  // for each column...
42  bool isFirstColumn = true;
43  for (const auto& columnName : columnNames) {
44  // get column descriptor
45  const auto cd = cat.getMetadataForColumn(td->tableId, columnName);
46  if (!cd) {
47  throw std::runtime_error("Failed to find physical column '" + columnName + "'");
48  }
49 
50  // find the chunk
51  ChunkKey chunkKey{
52  cat.getCurrentDB().dbId, td->tableId, cd->columnId, fragment.fragmentId};
53  auto chunkMetaIt = fragment.getChunkMetadataMap().find(cd->columnId);
54  if (chunkMetaIt == fragment.getChunkMetadataMap().end()) {
55  throw std::runtime_error("Failed to find the chunk for column: " +
56  cd->columnName + " in table: " + td->tableName +
57  ". The column was likely deleted via a table truncate.");
58  }
59 
60  // get the chunk
61  std::shared_ptr<Chunk_NS::Chunk> chunk =
63  &cat.getDataMgr(),
64  chunkKey,
66  0,
67  chunkMetaIt->second.numBytes,
68  chunkMetaIt->second.numElements);
69  CHECK(chunk);
70 
71  // the size
72  size_t chunkSize = chunkMetaIt->second.numElements;
73 
74  // and an iterator
75  ChunkIter chunkIt = chunk->begin_iterator(chunkMetaIt->second);
76 
77  // populate table entry
78  if (isFirstColumn) {
79  // store the size
80  std::get<0>(table.back()) = chunkSize;
81  isFirstColumn = false;
82  } else {
83  // all columns chunks must be the same size
84  CHECK(std::get<0>(table.back()) == chunkSize);
85  }
86  std::get<1>(table.back()).push_back(chunk);
87  std::get<2>(table.back()).push_back(chunkIt);
88  }
89  }
90 
91  // prefix-sum the per-fragment counts
92  // these are now "first row of next fragment"
93  size_t sum = 0;
94  for (auto& entry : table) {
95  sum += std::get<0>(entry);
96  std::get<0>(entry) = sum;
97  }
98 
99  // done
100  return table;
101 }
std::vector< int > ChunkKey
Definition: types.h:35
std::string tableName
Data_Namespace::DataMgr & getDataMgr() const
Definition: Catalog.h:177
CHECK(cgen_state)
virtual TableInfo getFragmentsForQuery()=0
Should get the partitions(fragments) where at least one tuple could satisfy the (optional) provided p...
const DBMetadata & getCurrentDB() const
Definition: Catalog.h:176
const ColumnDescriptor * getMetadataForColumn(int tableId, const std::string &colName) const
static std::shared_ptr< Chunk > getChunk(const ColumnDescriptor *cd, DataMgr *data_mgr, const ChunkKey &key, const MemoryLevel mem_level, const int deviceId, const size_t num_bytes, const size_t num_elems)
Definition: Chunk.cpp:28
std::vector< std::tuple< size_t, std::vector< std::shared_ptr< Chunk_NS::Chunk >>, ChunkIterVector >> ChunkAccessorTable
Fragmenter_Namespace::AbstractFragmenter * fragmenter

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ChunkIterVector& getChunkItersAndRowOffset ( ChunkAccessorTable table,
size_t  rowid,
size_t &  rowOffset 
)

Definition at line 103 of file ChunkAccessorTable.cpp.

References CHECK().

Referenced by Importer_NS::RenderGroupAnalyzer::seedFromExistingTableContents().

105  {
106  rowOffset = 0;
107  for (auto& entry : table) {
108  if (rowid < std::get<0>(entry)) {
109  return std::get<2>(entry);
110  }
111  rowOffset = std::get<0>(entry);
112  }
113  CHECK(false);
114  static ChunkIterVector emptyChunkIterVector;
115  return emptyChunkIterVector;
116 }
CHECK(cgen_state)
std::vector< ChunkIter > ChunkIterVector

+ Here is the call graph for this function:

+ Here is the caller graph for this function: