OmniSciDB  0264ff685a
InputMetadata.h File Reference
+ Include dependency graph for InputMetadata.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  InputTableInfo
 
class  InputTableInfoCache
 

Namespaces

 Catalog_Namespace
 

Typedefs

using TemporaryTables = std::unordered_map< int, const ResultSetPtr & >
 

Functions

ChunkMetadataMap synthesize_metadata (const ResultSet *rows)
 
size_t get_frag_count_of_table (const int table_id, Executor *executor)
 
std::vector< InputTableInfoget_table_infos (const std::vector< InputDescriptor > &input_descs, Executor *executor)
 
std::vector< InputTableInfoget_table_infos (const RelAlgExecutionUnit &ra_exe_unit, Executor *executor)
 

Typedef Documentation

◆ TemporaryTables

using TemporaryTables = std::unordered_map<int, const ResultSetPtr&>

Definition at line 31 of file InputMetadata.h.

Function Documentation

◆ get_frag_count_of_table()

size_t get_frag_count_of_table ( const int  table_id,
Executor executor 
)

Definition at line 240 of file InputMetadata.cpp.

References CHECK, and CHECK_GE.

Referenced by RelAlgExecutor::getOuterFragmentCount().

240  {
241  const auto temporary_tables = executor->getTemporaryTables();
242  CHECK(temporary_tables);
243  auto it = temporary_tables->find(table_id);
244  if (it != temporary_tables->end()) {
245  CHECK_GE(int(0), table_id);
246  return size_t(1);
247  } else {
248  const auto table_info = executor->getTableInfo(table_id);
249  return table_info.fragments.size();
250  }
251 }
#define CHECK_GE(x, y)
Definition: Logger.h:210
#define CHECK(condition)
Definition: Logger.h:197
+ Here is the caller graph for this function:

◆ get_table_infos() [1/2]

std::vector<InputTableInfo> get_table_infos ( const std::vector< InputDescriptor > &  input_descs,
Executor executor 
)

Definition at line 253 of file InputMetadata.cpp.

References anonymous_namespace{InputMetadata.cpp}::collect_table_infos().

Referenced by RelAlgExecutor::computeWindow(), RelAlgExecutor::createCompoundWorkUnit(), RelAlgExecutor::createProjectWorkUnit(), RelAlgExecutor::createTableFunctionWorkUnit(), RelAlgExecutor::createUnionWorkUnit(), RelAlgExecutor::executeDelete(), RelAlgExecutor::executeTableFunction(), RelAlgExecutor::executeUpdate(), RelAlgExecutor::executeWorkUnit(), get_table_infos(), RelAlgExecutor::getFilteredCountAll(), RelAlgExecutor::getFilterSelectivity(), RelAlgExecutor::getNDVEstimation(), RelAlgExecutor::handleOutOfMemoryRetry(), TableOptimizer::recomputeMetadata(), and RelAlgExecutor::selectFiltersToBePushedDown().

255  {
256  std::vector<InputTableInfo> table_infos;
257  collect_table_infos(table_infos, input_descs, executor);
258  return table_infos;
259 }
void collect_table_infos(std::vector< InputTableInfo > &table_infos, const std::vector< InputDescriptor > &input_descs, Executor *executor)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_table_infos() [2/2]

std::vector<InputTableInfo> get_table_infos ( const RelAlgExecutionUnit ra_exe_unit,
Executor executor 
)

Definition at line 261 of file InputMetadata.cpp.

References anonymous_namespace{InputMetadata.cpp}::collect_table_infos(), get_table_infos(), INJECT_TIMER, and RelAlgExecutionUnit::input_descs.

262  {
264  std::vector<InputTableInfo> table_infos;
265  collect_table_infos(table_infos, ra_exe_unit.input_descs, executor);
266  return table_infos;
267 }
std::vector< InputDescriptor > input_descs
#define INJECT_TIMER(DESC)
Definition: measure.h:93
std::vector< InputTableInfo > get_table_infos(const std::vector< InputDescriptor > &input_descs, Executor *executor)
void collect_table_infos(std::vector< InputTableInfo > &table_infos, const std::vector< InputDescriptor > &input_descs, Executor *executor)
+ Here is the call graph for this function:

◆ synthesize_metadata()

ChunkMetadataMap synthesize_metadata ( const ResultSet rows)

Definition at line 135 of file InputMetadata.cpp.

References CHECK, CHECK_LT, cpu_threads(), Encoder::Create(), parse_ast::end, inline_fp_null_val(), inline_int_null_val(), kDOUBLE, kFLOAT, result_set::use_parallel_algorithms(), and anonymous_namespace{InputMetadata.cpp}::uses_int_meta().

Referenced by Fragmenter_Namespace::FragmentInfo::getChunkMetadataMap().

135  {
136  rows->moveToBegin();
137  std::vector<std::vector<std::unique_ptr<Encoder>>> dummy_encoders;
138  const size_t worker_count =
140  for (size_t worker_idx = 0; worker_idx < worker_count; ++worker_idx) {
141  dummy_encoders.emplace_back();
142  for (size_t i = 0; i < rows->colCount(); ++i) {
143  const auto& col_ti = rows->getColType(i);
144  dummy_encoders.back().emplace_back(Encoder::Create(nullptr, col_ti));
145  }
146  }
147  const auto do_work = [rows](const std::vector<TargetValue>& crt_row,
148  std::vector<std::unique_ptr<Encoder>>& dummy_encoders) {
149  for (size_t i = 0; i < rows->colCount(); ++i) {
150  const auto& col_ti = rows->getColType(i);
151  const auto& col_val = crt_row[i];
152  const auto scalar_col_val = boost::get<ScalarTargetValue>(&col_val);
153  CHECK(scalar_col_val);
154  if (uses_int_meta(col_ti)) {
155  const auto i64_p = boost::get<int64_t>(scalar_col_val);
156  CHECK(i64_p);
157  dummy_encoders[i]->updateStats(*i64_p, *i64_p == inline_int_null_val(col_ti));
158  } else if (col_ti.is_fp()) {
159  switch (col_ti.get_type()) {
160  case kFLOAT: {
161  const auto float_p = boost::get<float>(scalar_col_val);
162  CHECK(float_p);
163  dummy_encoders[i]->updateStats(*float_p,
164  *float_p == inline_fp_null_val(col_ti));
165  break;
166  }
167  case kDOUBLE: {
168  const auto double_p = boost::get<double>(scalar_col_val);
169  CHECK(double_p);
170  dummy_encoders[i]->updateStats(*double_p,
171  *double_p == inline_fp_null_val(col_ti));
172  break;
173  }
174  default:
175  CHECK(false);
176  }
177  } else {
178  throw std::runtime_error(col_ti.get_type_name() +
179  " is not supported in temporary table.");
180  }
181  }
182  };
184  const size_t worker_count = cpu_threads();
185  std::vector<std::future<void>> compute_stats_threads;
186  const auto entry_count = rows->entryCount();
187  for (size_t i = 0,
188  start_entry = 0,
189  stride = (entry_count + worker_count - 1) / worker_count;
190  i < worker_count && start_entry < entry_count;
191  ++i, start_entry += stride) {
192  const auto end_entry = std::min(start_entry + stride, entry_count);
193  compute_stats_threads.push_back(std::async(
194  std::launch::async,
195  [rows, &do_work, &dummy_encoders](
196  const size_t start, const size_t end, const size_t worker_idx) {
197  for (size_t i = start; i < end; ++i) {
198  const auto crt_row = rows->getRowAtNoTranslations(i);
199  if (!crt_row.empty()) {
200  do_work(crt_row, dummy_encoders[worker_idx]);
201  }
202  }
203  },
204  start_entry,
205  end_entry,
206  i));
207  }
208  for (auto& child : compute_stats_threads) {
209  child.wait();
210  }
211  for (auto& child : compute_stats_threads) {
212  child.get();
213  }
214  } else {
215  while (true) {
216  auto crt_row = rows->getNextRow(false, false);
217  if (crt_row.empty()) {
218  break;
219  }
220  do_work(crt_row, dummy_encoders[0]);
221  }
222  rows->moveToBegin();
223  }
224  ChunkMetadataMap metadata_map;
225  for (size_t worker_idx = 1; worker_idx < worker_count; ++worker_idx) {
226  CHECK_LT(worker_idx, dummy_encoders.size());
227  const auto& worker_encoders = dummy_encoders[worker_idx];
228  for (size_t i = 0; i < rows->colCount(); ++i) {
229  dummy_encoders[0][i]->reduceStats(*worker_encoders[i]);
230  }
231  }
232  for (size_t i = 0; i < rows->colCount(); ++i) {
233  const auto it_ok =
234  metadata_map.emplace(i, dummy_encoders[0][i]->getMetadata(rows->getColType(i)));
235  CHECK(it_ok.second);
236  }
237  return metadata_map;
238 }
std::map< int, std::shared_ptr< ChunkMetadata > > ChunkMetadataMap
static Encoder * Create(Data_Namespace::AbstractBuffer *buffer, const SQLTypeInfo sqlType)
Definition: Encoder.cpp:26
double inline_fp_null_val(const SQL_TYPE_INFO &ti)
bool use_parallel_algorithms(const ResultSet &rows)
Definition: ResultSet.cpp:1063
bool uses_int_meta(const SQLTypeInfo &col_ti)
#define CHECK_LT(x, y)
Definition: Logger.h:207
#define CHECK(condition)
Definition: Logger.h:197
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)
int cpu_threads()
Definition: thread_count.h:24
+ Here is the call graph for this function:
+ Here is the caller graph for this function: