OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 shared::TableKey &table_key, 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)
 
Fragmenter_Namespace::TableInfo build_table_info (const std::vector< const TableDescriptor * > &shard_tables)
 

Typedef Documentation

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

Definition at line 31 of file InputMetadata.h.

Function Documentation

Fragmenter_Namespace::TableInfo build_table_info ( const std::vector< const TableDescriptor * > &  shard_tables)

Definition at line 44 of file InputMetadata.cpp.

References CHECK, Fragmenter_Namespace::TableInfo::fragments, and Fragmenter_Namespace::TableInfo::setPhysicalNumTuples().

Referenced by InputTableInfoCache::getTableInfo().

45  {
46  size_t total_number_of_tuples{0};
47  Fragmenter_Namespace::TableInfo table_info_all_shards;
48  for (const TableDescriptor* shard_table : shard_tables) {
49  CHECK(shard_table->fragmenter);
50  const auto& shard_metainfo = shard_table->fragmenter->getFragmentsForQuery();
51  total_number_of_tuples += shard_metainfo.getPhysicalNumTuples();
52  table_info_all_shards.fragments.reserve(table_info_all_shards.fragments.size() +
53  shard_metainfo.fragments.size());
54  table_info_all_shards.fragments.insert(table_info_all_shards.fragments.end(),
55  shard_metainfo.fragments.begin(),
56  shard_metainfo.fragments.end());
57  }
58  table_info_all_shards.setPhysicalNumTuples(total_number_of_tuples);
59  return table_info_all_shards;
60 }
std::vector< FragmentInfo > fragments
Definition: Fragmenter.h:171
#define CHECK(condition)
Definition: Logger.h:291
void setPhysicalNumTuples(const size_t physNumTuples)
Definition: Fragmenter.h:166

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t get_frag_count_of_table ( const shared::TableKey table_key,
Executor executor 
)

Definition at line 500 of file InputMetadata.cpp.

References CHECK, CHECK_GE, and shared::TableKey::table_id.

Referenced by RelAlgExecutor::getOuterFragmentCount().

500  {
501  const auto temporary_tables = executor->getTemporaryTables();
502  CHECK(temporary_tables);
503  auto it = temporary_tables->find(table_key.table_id);
504  if (it != temporary_tables->end()) {
505  CHECK_GE(int(0), table_key.table_id);
506  return size_t(1);
507  } else {
508  const auto table_info = executor->getTableInfo(table_key);
509  return table_info.fragments.size();
510  }
511 }
#define CHECK_GE(x, y)
Definition: Logger.h:306
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the caller graph for this function:

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

Definition at line 513 of file InputMetadata.cpp.

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

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

515  {
516  std::vector<InputTableInfo> table_infos;
517  collect_table_infos(table_infos, input_descs, executor);
518  return table_infos;
519 }
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:

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

Definition at line 521 of file InputMetadata.cpp.

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

522  {
523  std::vector<InputTableInfo> table_infos;
524  collect_table_infos(table_infos, ra_exe_unit.input_descs, executor);
525  return table_infos;
526 }
std::vector< InputDescriptor > input_descs
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:

ChunkMetadataMap synthesize_metadata ( const ResultSet rows)

Definition at line 368 of file InputMetadata.cpp.

References CHECK, CHECK_LT, cpu_threads(), Encoder::Create(), DEBUG_TIMER, inline_fp_null_val(), inline_int_null_val(), kDOUBLE, kFLOAT, threading_serial::parallel_for(), report::rows, synthesize_metadata_table_function(), heavyai::TableFunction, result_set::use_parallel_algorithms(), and anonymous_namespace{InputMetadata.cpp}::uses_int_meta().

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

368  {
369  auto timer = DEBUG_TIMER(__func__);
370  ChunkMetadataMap metadata_map;
371 
372  // If the ResultSet has no rows, fill with dummy metadata and return early.
373  if (rows->definitelyHasNoRows()) {
374  // resultset has no valid storage, so we fill dummy metadata and return early
375  std::vector<std::unique_ptr<Encoder>> decoders;
376  for (size_t i = 0; i < rows->colCount(); ++i) {
377  decoders.emplace_back(Encoder::Create(nullptr, rows->getColType(i)));
378  const auto it_ok =
379  metadata_map.emplace(i, decoders.back()->getMetadata(rows->getColType(i)));
380  CHECK(it_ok.second);
381  }
382  return metadata_map;
383  }
384 
385  // Create a vector of Encoder vectors for each worker.
386  std::vector<std::vector<std::unique_ptr<Encoder>>> dummy_encoders;
387  const size_t worker_count =
389  for (size_t worker_idx = 0; worker_idx < worker_count; ++worker_idx) {
390  dummy_encoders.emplace_back();
391  for (size_t i = 0; i < rows->colCount(); ++i) {
392  const auto& col_ti = rows->getColType(i);
393  dummy_encoders.back().emplace_back(Encoder::Create(nullptr, col_ti));
394  }
395  }
396 
397  // For TableFunctions, call the optimized function we have for this format.
398  if (rows->getQueryMemDesc().getQueryDescriptionType() ==
401  }
402  rows->moveToBegin();
403 
404  std::vector<SQLTypeInfo> row_col_ti;
405  std::vector<Number64> col_null_vals(rows->colCount());
406  for (size_t i = 0; i < rows->colCount(); i++) {
407  auto const col_ti = rows->getColType(i);
408  row_col_ti.push_back(col_ti);
409  if (uses_int_meta(col_ti)) {
410  col_null_vals[i].as_int64 = inline_int_null_val(col_ti);
411  } else if (col_ti.is_fp()) {
412  col_null_vals[i].as_double = inline_fp_null_val(col_ti);
413  } else {
414  throw std::runtime_error(col_ti.get_type_name() +
415  " is not supported in temporary table.");
416  }
417  }
418 
419  // Code in the do_work lambda runs for and processes each row.
420  const auto do_work = [rows, &row_col_ti, &col_null_vals](
421  const std::vector<TargetValue>& crt_row,
422  std::vector<std::unique_ptr<Encoder>>& dummy_encoders) {
423  for (size_t i = 0; i < rows->colCount(); ++i) {
424  const auto& col_ti = row_col_ti[i];
425  const auto& col_val = crt_row[i];
426  const auto scalar_col_val = boost::get<ScalarTargetValue>(&col_val);
427  CHECK(scalar_col_val);
428  if (uses_int_meta(col_ti)) {
429  const auto i64_p = boost::get<int64_t>(scalar_col_val);
430  CHECK(i64_p);
431  dummy_encoders[i]->updateStats(*i64_p, *i64_p == col_null_vals[i].as_int64);
432  } else {
433  CHECK(col_ti.is_fp());
434  switch (col_ti.get_type()) {
435  case kFLOAT: {
436  const auto float_p = boost::get<float>(scalar_col_val);
437  CHECK(float_p);
438  dummy_encoders[i]->updateStats(*float_p,
439  *float_p == col_null_vals[i].as_double);
440  break;
441  }
442  case kDOUBLE: {
443  const auto double_p = boost::get<double>(scalar_col_val);
444  CHECK(double_p);
445  dummy_encoders[i]->updateStats(*double_p,
446  *double_p == col_null_vals[i].as_double);
447  break;
448  }
449  default:
450  CHECK(false);
451  }
452  }
453  }
454  };
455 
456  // Parallelize the processing using TBB if parallel algorithms are enabled.
458  const size_t entry_count = rows->entryCount();
460  tbb::blocked_range<size_t>(0, entry_count),
461  [&do_work, &rows, &dummy_encoders](const tbb::blocked_range<size_t>& range) {
462  const size_t worker_idx = tbb::this_task_arena::current_thread_index();
463  for (size_t i = range.begin(); i < range.end(); ++i) {
464  const auto crt_row = rows->getRowAtNoTranslations(i);
465  if (!crt_row.empty()) {
466  do_work(crt_row, dummy_encoders[worker_idx]);
467  }
468  }
469  });
470 
471  } else {
472  // If parallel algorithms are not enabled, process the rows sequentially.
473  while (true) {
474  auto crt_row = rows->getNextRow(false, false);
475  if (crt_row.empty()) {
476  break;
477  }
478  do_work(crt_row, dummy_encoders[0]);
479  }
480  }
481  rows->moveToBegin();
482 
483  // Reduce the results from each worker.
484  for (size_t worker_idx = 1; worker_idx < worker_count; ++worker_idx) {
485  CHECK_LT(worker_idx, dummy_encoders.size());
486  const auto& worker_encoders = dummy_encoders[worker_idx];
487  for (size_t i = 0; i < rows->colCount(); ++i) {
488  dummy_encoders[0][i]->reduceStats(*worker_encoders[i]);
489  }
490  }
491  // Add each column's results to the metadata map.
492  for (size_t i = 0; i < rows->colCount(); ++i) {
493  const auto it_ok =
494  metadata_map.emplace(i, dummy_encoders[0][i]->getMetadata(rows->getColType(i)));
495  CHECK(it_ok.second);
496  }
497  return metadata_map;
498 }
ChunkMetadataMap synthesize_metadata_table_function(const ResultSet *rows)
static Encoder * Create(Data_Namespace::AbstractBuffer *buffer, const SQLTypeInfo sqlType)
Definition: Encoder.cpp:26
double inline_fp_null_val(const SQL_TYPE_INFO &ti)
std::map< int, std::shared_ptr< ChunkMetadata >> ChunkMetadataMap
bool use_parallel_algorithms(const ResultSet &rows)
Definition: ResultSet.cpp:1600
TableFunction
Definition: enums.h:58
tuple rows
Definition: report.py:114
bool uses_int_meta(const SQLTypeInfo &col_ti)
#define CHECK_LT(x, y)
Definition: Logger.h:303
void parallel_for(const blocked_range< Int > &range, const Body &body, const Partitioner &p=Partitioner())
#define CHECK(condition)
Definition: Logger.h:291
#define DEBUG_TIMER(name)
Definition: Logger.h:412
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)
int cpu_threads()
Definition: thread_count.h:25

+ Here is the call graph for this function:

+ Here is the caller graph for this function: