OmniSciDB  c1a53651b2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Parser::InsertIntoTableAsSelectStmt Class Reference

#include <ParserNode.h>

+ Inheritance diagram for Parser::InsertIntoTableAsSelectStmt:
+ Collaboration diagram for Parser::InsertIntoTableAsSelectStmt:

Public Member Functions

 InsertIntoTableAsSelectStmt (const rapidjson::Value &payload)
 
 InsertIntoTableAsSelectStmt (const std::string *table_name, const std::string *select_query, std::list< std::string * > *c)
 
void populateData (QueryStateProxy, const TableDescriptor *td, bool validate_table, bool for_CTAS=false)
 
void execute (const Catalog_Namespace::SessionInfo &session, bool read_only_mode) override
 
std::string & get_table ()
 
std::string & get_select_query ()
 
- Public Member Functions inherited from Parser::DDLStmt
void setColumnDescriptor (ColumnDescriptor &cd, const ColumnDef *coldef)
 
- Public Member Functions inherited from Parser::Node
virtual ~Node ()
 

Public Attributes

std::unique_ptr< QueryConnectorleafs_connector_
 

Protected Attributes

std::vector< std::unique_ptr
< std::string > > 
column_list_
 
std::string table_name_
 
std::string select_query_
 

Detailed Description

Definition at line 1126 of file ParserNode.h.

Constructor & Destructor Documentation

Parser::InsertIntoTableAsSelectStmt::InsertIntoTableAsSelectStmt ( const rapidjson::Value &  payload)

Definition at line 3606 of file ParserNode.cpp.

References CHECK, column_list_, json_str(), select_query_, and table_name_.

3607  {
3608  CHECK(payload.HasMember("name"));
3609  table_name_ = json_str(payload["name"]);
3610 
3611  CHECK(payload.HasMember("query"));
3612  select_query_ = json_str(payload["query"]);
3613 
3614  boost::replace_all(select_query_, "\n", " ");
3615  select_query_ = "(" + select_query_ + ")";
3616 
3617  if (payload.HasMember("columns")) {
3618  CHECK(payload["columns"].IsArray());
3619  for (auto& column : payload["columns"].GetArray()) {
3620  std::string s = json_str(column);
3621  column_list_.emplace_back(std::unique_ptr<std::string>(new std::string(s)));
3622  }
3623  }
3624 }
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:44
std::vector< std::unique_ptr< std::string > > column_list_
Definition: ParserNode.h:1159
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

Parser::InsertIntoTableAsSelectStmt::InsertIntoTableAsSelectStmt ( const std::string *  table_name,
const std::string *  select_query,
std::list< std::string * > *  c 
)
inline

Definition at line 1130 of file ParserNode.h.

References column_list_.

1133  : table_name_(*table_name), select_query_(*select_query) {
1134  if (c) {
1135  for (auto e : *c) {
1136  column_list_.emplace_back(e);
1137  }
1138  delete c;
1139  }
1140 
1141  delete table_name;
1142  delete select_query;
1143  }
std::vector< std::unique_ptr< std::string > > column_list_
Definition: ParserNode.h:1159

Member Function Documentation

void Parser::InsertIntoTableAsSelectStmt::execute ( const Catalog_Namespace::SessionInfo session,
bool  read_only_mode 
)
overridevirtual

Implements Parser::DDLStmt.

Reimplemented in Parser::CreateTableAsSelectStmt.

Definition at line 4200 of file ParserNode.cpp.

References Parser::anonymous_namespace{ParserNode.cpp}::acquire_query_table_locks(), Executor::clearExternalCaches(), query_state::QueryState::create(), legacylockmgr::ExecutorOuterLock, legacylockmgr::LockMgr< MutexType, KeyType >::getMutex(), populateData(), select_query_, STDLOG, and table_name_.

Referenced by heavydb.cursor.Cursor::executemany().

4201  {
4202  if (read_only_mode) {
4203  throw std::runtime_error("INSERT INTO TABLE invalid in read only mode.");
4204  }
4205  auto session_copy = session;
4206  auto session_ptr = std::shared_ptr<Catalog_Namespace::SessionInfo>(
4207  &session_copy, boost::null_deleter());
4208  auto query_state = query_state::QueryState::create(session_ptr, select_query_);
4209  auto stdlog = STDLOG(query_state);
4210  auto& catalog = session_ptr->getCatalog();
4211 
4212  const auto execute_read_lock =
4216 
4217  if (catalog.getMetadataForTable(table_name_) == nullptr) {
4218  throw std::runtime_error("ITAS failed: table " + table_name_ + " does not exist.");
4219  }
4220 
4221  auto locks = acquire_query_table_locks(
4222  catalog.name(), select_query_, query_state->createQueryStateProxy(), table_name_);
4223  const TableDescriptor* td = catalog.getMetadataForTable(table_name_);
4224 
4225  Executor::clearExternalCaches(true, td, catalog.getCurrentDB().dbId);
4226 
4227  try {
4228  populateData(query_state->createQueryStateProxy(), td, true, false);
4229  } catch (...) {
4230  throw;
4231  }
4232 }
static std::shared_ptr< WrapperType< MutexType > > getMutex(const LockType lockType, const KeyType &key)
void populateData(QueryStateProxy, const TableDescriptor *td, bool validate_table, bool for_CTAS=false)
static std::shared_ptr< QueryState > create(ARGS &&...args)
Definition: QueryState.h:148
std::shared_lock< T > shared_lock
lockmgr::LockedTableDescriptors acquire_query_table_locks(const std::string &insert_table_db_name, const std::string &query_str, const QueryStateProxy &query_state_proxy, const std::optional< std::string > &insert_table_name={})
static void clearExternalCaches(bool for_update, const TableDescriptor *td, const int current_db_id)
Definition: Execute.h:388
#define STDLOG(...)
Definition: QueryState.h:234

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string& Parser::InsertIntoTableAsSelectStmt::get_select_query ( )
inline

Definition at line 1154 of file ParserNode.h.

References select_query_.

1154 { return select_query_; }
std::string& Parser::InsertIntoTableAsSelectStmt::get_table ( )
inline

Definition at line 1152 of file ParserNode.h.

References table_name_.

1152 { return table_name_; }
void Parser::InsertIntoTableAsSelectStmt::populateData ( QueryStateProxy  query_state_proxy,
const TableDescriptor td,
bool  validate_table,
bool  for_CTAS = false 
)

Definition at line 3626 of file ParserNode.cpp.

References threading_serial::async(), CHECK, Parser::check_session_interrupted(), column_list_, ColumnDescriptor::columnName, ColumnDescriptor::columnType, TargetValueConverterFactory::create(), Fragmenter_Namespace::InsertData::databaseId, logger::ERROR, import_export::fill_missing_columns(), g_cluster, g_enable_assign_render_groups, g_enable_non_kernel_time_query_interrupt, g_enable_string_functions, ResultSet::GeoTargetValue, SQLTypeInfo::get_compression(), SQLTypeInfo::get_dimension(), SQLTypeInfo::get_elem_type(), SQLTypeInfo::get_scale(), SQLTypeInfo::get_size(), SQLTypeInfo::get_subtype(), SQLTypeInfo::get_type(), SQLTypeInfo::get_type_name(), Parser::LocalQueryConnector::getColumnDescriptors(), query_state::QueryState::getConstSessionInfo(), Executor::getExecutor(), query_state::QueryState::getQuerySubmittedTime(), AccessPrivileges::INSERT_INTO_TABLE, Fragmenter_Namespace::InsertDataLoader::insertData(), SQLTypeInfo::is_array(), SQLTypeInfo::is_date(), SQLTypeInfo::is_decimal(), IS_GEO_POLY, SQLTypeInfo::is_geometry(), SQLTypeInfo::is_integer(), SQLTypeInfo::is_string(), SQLTypeInfo::is_time(), SQLTypeInfo::is_timestamp(), TableDescriptor::isView, leafs_connector_, LOG, Fragmenter_Namespace::InsertData::numRows, Parser::LocalQueryConnector::query(), run_benchmark_import::res, run_benchmark_import::result, select_query_, run_benchmark_import::start_time, table_is_temporary(), table_name_, TableDBObjectType, TableDescriptor::tableId, Fragmenter_Namespace::InsertData::tableId, logger::thread_id(), timer_start(), timer_stop(), Executor::UNITARY_EXECUTOR_ID, UNLIKELY, foreign_storage::validate_non_foreign_table_write(), and VLOG.

Referenced by execute(), and Parser::CreateTableAsSelectStmt::execute().

3629  {
3630  auto const session = query_state_proxy->getConstSessionInfo();
3631  auto& catalog = session->getCatalog();
3633  bool populate_table = false;
3634 
3635  if (leafs_connector_) {
3636  populate_table = true;
3637  } else {
3638  leafs_connector_ = std::make_unique<LocalQueryConnector>();
3639  if (!g_cluster) {
3640  populate_table = true;
3641  }
3642  }
3643 
3644  auto get_target_column_descriptors = [this, &catalog](const TableDescriptor* td) {
3645  std::vector<const ColumnDescriptor*> target_column_descriptors;
3646  if (column_list_.empty()) {
3647  auto list = catalog.getAllColumnMetadataForTable(td->tableId, false, false, false);
3648  target_column_descriptors = {std::begin(list), std::end(list)};
3649  } else {
3650  for (auto& c : column_list_) {
3651  const ColumnDescriptor* cd = catalog.getMetadataForColumn(td->tableId, *c);
3652  if (cd == nullptr) {
3653  throw std::runtime_error("Column " + *c + " does not exist.");
3654  }
3655  target_column_descriptors.push_back(cd);
3656  }
3657  }
3658 
3659  return target_column_descriptors;
3660  };
3661 
3662  bool is_temporary = table_is_temporary(td);
3663 
3664  if (validate_table) {
3665  // check access privileges
3666  if (!td) {
3667  throw std::runtime_error("Table " + table_name_ + " does not exist.");
3668  }
3669  if (td->isView) {
3670  throw std::runtime_error("Insert to views is not supported yet.");
3671  }
3672 
3673  if (!session->checkDBAccessPrivileges(DBObjectType::TableDBObjectType,
3675  table_name_)) {
3676  throw std::runtime_error("User has no insert privileges on " + table_name_ + ".");
3677  }
3678 
3679  // only validate the select query so we get the target types
3680  // correctly, but do not populate the result set
3681  LocalQueryConnector local_connector;
3682  auto result = local_connector.query(query_state_proxy, select_query_, {}, true, true);
3683  auto source_column_descriptors = local_connector.getColumnDescriptors(result, false);
3684 
3685  std::vector<const ColumnDescriptor*> target_column_descriptors =
3686  get_target_column_descriptors(td);
3687 
3688  if (source_column_descriptors.size() != target_column_descriptors.size()) {
3689  throw std::runtime_error("The number of source and target columns does not match.");
3690  }
3691 
3692  for (int i = 0; i < source_column_descriptors.size(); i++) {
3693  const ColumnDescriptor* source_cd =
3694  &(*std::next(source_column_descriptors.begin(), i));
3695  const ColumnDescriptor* target_cd = target_column_descriptors.at(i);
3696 
3697  if (source_cd->columnType.get_type() != target_cd->columnType.get_type()) {
3698  auto type_cannot_be_cast = [](const auto& col_type) {
3699  return (col_type.is_time() || col_type.is_geometry() || col_type.is_array() ||
3700  col_type.is_boolean());
3701  };
3702 
3703  if (type_cannot_be_cast(source_cd->columnType) ||
3704  type_cannot_be_cast(target_cd->columnType)) {
3705  throw std::runtime_error("Source '" + source_cd->columnName + " " +
3706  source_cd->columnType.get_type_name() +
3707  "' and target '" + target_cd->columnName + " " +
3708  target_cd->columnType.get_type_name() +
3709  "' column types do not match.");
3710  }
3711  }
3712  if (source_cd->columnType.is_array()) {
3713  if (source_cd->columnType.get_subtype() != target_cd->columnType.get_subtype()) {
3714  throw std::runtime_error("Source '" + source_cd->columnName + " " +
3715  source_cd->columnType.get_type_name() +
3716  "' and target '" + target_cd->columnName + " " +
3717  target_cd->columnType.get_type_name() +
3718  "' array column element types do not match.");
3719  }
3720  }
3721 
3722  if (target_cd->columnType.is_string() && !source_cd->columnType.is_string()) {
3723  throw std::runtime_error("Source '" + source_cd->columnName + " " +
3724  source_cd->columnType.get_type_name() +
3725  "' and target '" + target_cd->columnName + " " +
3726  target_cd->columnType.get_type_name() +
3727  "' column types do not match.");
3728  }
3729 
3730  if (source_cd->columnType.is_decimal() ||
3731  source_cd->columnType.get_elem_type().is_decimal()) {
3732  SQLTypeInfo sourceType = source_cd->columnType;
3733  SQLTypeInfo targetType = target_cd->columnType;
3734 
3735  if (source_cd->columnType.is_array()) {
3736  sourceType = source_cd->columnType.get_elem_type();
3737  targetType = target_cd->columnType.get_elem_type();
3738  }
3739 
3740  if (sourceType.get_scale() != targetType.get_scale()) {
3741  throw std::runtime_error("Source '" + source_cd->columnName + " " +
3742  source_cd->columnType.get_type_name() +
3743  "' and target '" + target_cd->columnName + " " +
3744  target_cd->columnType.get_type_name() +
3745  "' decimal columns scales do not match.");
3746  }
3747  }
3748 
3749  if (source_cd->columnType.is_string()) {
3750  if (!target_cd->columnType.is_string()) {
3751  throw std::runtime_error("Source '" + source_cd->columnName + " " +
3752  source_cd->columnType.get_type_name() +
3753  "' and target '" + target_cd->columnName + " " +
3754  target_cd->columnType.get_type_name() +
3755  "' column types do not match.");
3756  }
3757  if (source_cd->columnType.get_compression() !=
3758  target_cd->columnType.get_compression()) {
3759  throw std::runtime_error("Source '" + source_cd->columnName + " " +
3760  source_cd->columnType.get_type_name() +
3761  "' and target '" + target_cd->columnName + " " +
3762  target_cd->columnType.get_type_name() +
3763  "' columns string encodings do not match.");
3764  }
3765  }
3766 
3767  if (source_cd->columnType.is_timestamp() && target_cd->columnType.is_timestamp()) {
3768  if (source_cd->columnType.get_dimension() !=
3769  target_cd->columnType.get_dimension()) {
3770  throw std::runtime_error("Source '" + source_cd->columnName + " " +
3771  source_cd->columnType.get_type_name() +
3772  "' and target '" + target_cd->columnName + " " +
3773  target_cd->columnType.get_type_name() +
3774  "' timestamp column precisions do not match.");
3775  }
3776  }
3777 
3778  if (!source_cd->columnType.is_string() && !source_cd->columnType.is_geometry() &&
3779  !source_cd->columnType.is_integer() && !source_cd->columnType.is_decimal() &&
3780  !source_cd->columnType.is_date() && !source_cd->columnType.is_time() &&
3781  !source_cd->columnType.is_timestamp() &&
3782  source_cd->columnType.get_size() > target_cd->columnType.get_size()) {
3783  throw std::runtime_error("Source '" + source_cd->columnName + " " +
3784  source_cd->columnType.get_type_name() +
3785  "' and target '" + target_cd->columnName + " " +
3786  target_cd->columnType.get_type_name() +
3787  "' column encoding sizes do not match.");
3788  }
3789  }
3790  }
3791 
3792  if (!populate_table) {
3793  return;
3794  }
3795 
3796  int64_t total_row_count = 0;
3797  int64_t total_source_query_time_ms = 0;
3798  int64_t total_target_value_translate_time_ms = 0;
3799  int64_t total_data_load_time_ms = 0;
3800 
3802  auto target_column_descriptors = get_target_column_descriptors(td);
3803  auto outer_frag_count =
3804  leafs_connector_->getOuterFragmentCount(query_state_proxy, select_query_);
3805 
3806  size_t outer_frag_end = outer_frag_count == 0 ? 1 : outer_frag_count;
3807  auto query_session = session ? session->get_session_id() : "";
3809  std::string work_type_str = for_CTAS ? "CTAS" : "ITAS";
3810  try {
3811  for (size_t outer_frag_idx = 0; outer_frag_idx < outer_frag_end; outer_frag_idx++) {
3812  std::vector<size_t> allowed_outer_fragment_indices;
3813 
3814  if (outer_frag_count) {
3815  allowed_outer_fragment_indices.push_back(outer_frag_idx);
3816  }
3817 
3818  const auto query_clock_begin = timer_start();
3819  std::vector<AggregatedResult> query_results =
3820  leafs_connector_->query(query_state_proxy,
3821  select_query_,
3822  allowed_outer_fragment_indices,
3824  total_source_query_time_ms += timer_stop(query_clock_begin);
3825 
3826  auto start_time = query_state_proxy->getQuerySubmittedTime();
3827  auto query_str = "INSERT_DATA for " + work_type_str;
3829  // In the clean-up phase of the query execution for collecting aggregated result
3830  // of SELECT query, we remove its query session info, so we need to enroll the
3831  // session info again
3832  executor->enrollQuerySession(query_session,
3833  query_str,
3834  start_time,
3836  QuerySessionStatus::QueryStatus::RUNNING_IMPORTER);
3837  }
3838 
3839  ScopeGuard clearInterruptStatus = [executor, &query_session, &start_time] {
3840  // this data population is non-kernel operation, so we manually cleanup
3841  // the query session info in the cleanup phase
3843  executor->clearQuerySessionStatus(query_session, start_time);
3844  }
3845  };
3846 
3847  for (auto& res : query_results) {
3848  if (UNLIKELY(check_session_interrupted(query_session, executor))) {
3849  throw std::runtime_error(
3850  "Query execution has been interrupted while performing " + work_type_str);
3851  }
3852  auto& result_rows = res.rs;
3853  result_rows->setGeoReturnType(ResultSet::GeoReturnType::GeoTargetValue);
3854  const auto num_rows = result_rows->rowCount();
3855 
3856  if (0 == num_rows) {
3857  continue;
3858  }
3859 
3860  total_row_count += num_rows;
3861 
3862  size_t leaf_count = leafs_connector_->leafCount();
3863 
3864  // ensure that at least 1 row is processed per block up to a maximum of 65536 rows
3865  const size_t rows_per_block =
3866  std::max(std::min(num_rows / leaf_count, size_t(64 * 1024)), size_t(1));
3867 
3868  std::vector<std::unique_ptr<TargetValueConverter>> value_converters;
3869 
3871 
3872  const int num_worker_threads = std::thread::hardware_concurrency();
3873 
3874  std::vector<size_t> thread_start_idx(num_worker_threads),
3875  thread_end_idx(num_worker_threads);
3876  bool can_go_parallel = !result_rows->isTruncated() && rows_per_block > 20000;
3877 
3878  std::atomic<size_t> crt_row_idx{0};
3879 
3880  auto do_work = [&result_rows, &value_converters, &crt_row_idx](
3881  const size_t idx,
3882  const size_t block_end,
3883  const size_t num_cols,
3884  const size_t thread_id,
3885  bool& stop_convert) {
3886  const auto result_row = result_rows->getRowAtNoTranslations(idx);
3887  if (!result_row.empty()) {
3888  size_t target_row = crt_row_idx.fetch_add(1);
3889  if (target_row >= block_end) {
3890  stop_convert = true;
3891  return;
3892  }
3893  for (unsigned int col = 0; col < num_cols; col++) {
3894  const auto& mapd_variant = result_row[col];
3895  value_converters[col]->convertToColumnarFormat(target_row, &mapd_variant);
3896  }
3897  }
3898  };
3899 
3900  auto convert_function = [&thread_start_idx,
3901  &thread_end_idx,
3902  &value_converters,
3903  &executor,
3904  &query_session,
3905  &work_type_str,
3906  &do_work](const int thread_id, const size_t block_end) {
3907  const int num_cols = value_converters.size();
3908  const size_t start = thread_start_idx[thread_id];
3909  const size_t end = thread_end_idx[thread_id];
3910  size_t idx = 0;
3911  bool stop_convert = false;
3913  size_t local_idx = 0;
3914  for (idx = start; idx < end; ++idx, ++local_idx) {
3915  if (UNLIKELY((local_idx & 0xFFFF) == 0 &&
3916  check_session_interrupted(query_session, executor))) {
3917  throw std::runtime_error(
3918  "Query execution has been interrupted while performing " +
3919  work_type_str);
3920  }
3921  do_work(idx, block_end, num_cols, thread_id, stop_convert);
3922  if (stop_convert) {
3923  break;
3924  }
3925  }
3926  } else {
3927  for (idx = start; idx < end; ++idx) {
3928  do_work(idx, block_end, num_cols, thread_id, stop_convert);
3929  if (stop_convert) {
3930  break;
3931  }
3932  }
3933  }
3934  thread_start_idx[thread_id] = idx;
3935  };
3936 
3937  auto single_threaded_value_converter =
3938  [&crt_row_idx, &value_converters, &result_rows](const size_t idx,
3939  const size_t block_end,
3940  const size_t num_cols,
3941  bool& stop_convert) {
3942  size_t target_row = crt_row_idx.fetch_add(1);
3943  if (target_row >= block_end) {
3944  stop_convert = true;
3945  return;
3946  }
3947  const auto result_row = result_rows->getNextRow(false, false);
3948  CHECK(!result_row.empty());
3949  for (unsigned int col = 0; col < num_cols; col++) {
3950  const auto& mapd_variant = result_row[col];
3951  value_converters[col]->convertToColumnarFormat(target_row, &mapd_variant);
3952  }
3953  };
3954 
3955  auto single_threaded_convert_function = [&value_converters,
3956  &thread_start_idx,
3957  &thread_end_idx,
3958  &executor,
3959  &query_session,
3960  &work_type_str,
3961  &single_threaded_value_converter](
3962  const int thread_id,
3963  const size_t block_end) {
3964  const int num_cols = value_converters.size();
3965  const size_t start = thread_start_idx[thread_id];
3966  const size_t end = thread_end_idx[thread_id];
3967  size_t idx = 0;
3968  bool stop_convert = false;
3970  size_t local_idx = 0;
3971  for (idx = start; idx < end; ++idx, ++local_idx) {
3972  if (UNLIKELY((local_idx & 0xFFFF) == 0 &&
3973  check_session_interrupted(query_session, executor))) {
3974  throw std::runtime_error(
3975  "Query execution has been interrupted while performing " +
3976  work_type_str);
3977  }
3978  single_threaded_value_converter(idx, block_end, num_cols, stop_convert);
3979  if (stop_convert) {
3980  break;
3981  }
3982  }
3983  } else {
3984  for (idx = start; idx < end; ++idx) {
3985  single_threaded_value_converter(idx, end, num_cols, stop_convert);
3986  if (stop_convert) {
3987  break;
3988  }
3989  }
3990  }
3991  thread_start_idx[thread_id] = idx;
3992  };
3993 
3994  if (can_go_parallel) {
3995  const size_t entry_count = result_rows->entryCount();
3996  for (size_t
3997  i = 0,
3998  start_entry = 0,
3999  stride = (entry_count + num_worker_threads - 1) / num_worker_threads;
4000  i < num_worker_threads && start_entry < entry_count;
4001  ++i, start_entry += stride) {
4002  const auto end_entry = std::min(start_entry + stride, entry_count);
4003  thread_start_idx[i] = start_entry;
4004  thread_end_idx[i] = end_entry;
4005  }
4006  } else {
4007  thread_start_idx[0] = 0;
4008  thread_end_idx[0] = result_rows->entryCount();
4009  }
4010 
4011  RenderGroupAnalyzerMap render_group_analyzer_map;
4012 
4013  for (size_t block_start = 0; block_start < num_rows;
4014  block_start += rows_per_block) {
4015  const auto num_rows_this_itr = block_start + rows_per_block < num_rows
4016  ? rows_per_block
4017  : num_rows - block_start;
4018  crt_row_idx = 0; // reset block tracker
4019  value_converters.clear();
4020  int colNum = 0;
4021  for (const auto targetDescriptor : target_column_descriptors) {
4022  auto sourceDataMetaInfo = res.targets_meta[colNum++];
4024  num_rows_this_itr,
4025  sourceDataMetaInfo,
4026  targetDescriptor,
4027  catalog,
4028  targetDescriptor->columnType,
4029  !targetDescriptor->columnType.get_notnull(),
4030  result_rows->getRowSetMemOwner()->getLiteralStringDictProxy(),
4032  sourceDataMetaInfo.get_type_info().is_dict_encoded_string()
4033  ? executor->getStringDictionaryProxy(
4034  sourceDataMetaInfo.get_type_info().getStringDictKey(),
4035  result_rows->getRowSetMemOwner(),
4036  true)
4037  : nullptr,
4038  IS_GEO_POLY(targetDescriptor->columnType.get_type()) &&
4040  ? &render_group_analyzer_map
4041  : nullptr};
4042  auto converter = factory.create(param);
4043  value_converters.push_back(std::move(converter));
4044  }
4045 
4046  const auto translate_clock_begin = timer_start();
4047  if (can_go_parallel) {
4048  std::vector<std::future<void>> worker_threads;
4049  for (int i = 0; i < num_worker_threads; ++i) {
4050  worker_threads.push_back(
4051  std::async(std::launch::async, convert_function, i, num_rows_this_itr));
4052  }
4053 
4054  for (auto& child : worker_threads) {
4055  child.wait();
4056  }
4057  for (auto& child : worker_threads) {
4058  child.get();
4059  }
4060 
4061  } else {
4062  single_threaded_convert_function(0, num_rows_this_itr);
4063  }
4064 
4065  // finalize the insert data
4066  auto finalizer_func =
4067  [](std::unique_ptr<TargetValueConverter>::pointer targetValueConverter) {
4068  targetValueConverter->finalizeDataBlocksForInsertData();
4069  };
4070 
4071  std::vector<std::future<void>> worker_threads;
4072  for (auto& converterPtr : value_converters) {
4073  worker_threads.push_back(
4074  std::async(std::launch::async, finalizer_func, converterPtr.get()));
4075  }
4076 
4077  for (auto& child : worker_threads) {
4078  child.wait();
4079  }
4080  for (auto& child : worker_threads) {
4081  child.get();
4082  }
4083 
4085  insert_data.databaseId = catalog.getCurrentDB().dbId;
4086  CHECK(td);
4087  insert_data.tableId = td->tableId;
4088  insert_data.numRows = num_rows_this_itr;
4089 
4090  for (int col_idx = 0; col_idx < target_column_descriptors.size(); col_idx++) {
4092  check_session_interrupted(query_session, executor))) {
4093  throw std::runtime_error(
4094  "Query execution has been interrupted while performing " +
4095  work_type_str);
4096  }
4097  value_converters[col_idx]->addDataBlocksToInsertData(insert_data);
4098  }
4099  total_target_value_translate_time_ms += timer_stop(translate_clock_begin);
4100 
4101  const auto data_load_clock_begin = timer_start();
4102  auto data_memory_holder =
4103  import_export::fill_missing_columns(&catalog, insert_data);
4104  insertDataLoader.insertData(*session, insert_data);
4105  total_data_load_time_ms += timer_stop(data_load_clock_begin);
4106  }
4107  }
4108  }
4109  } catch (...) {
4110  try {
4111  leafs_connector_->rollback(*session, td->tableId);
4112  } catch (std::exception& e) {
4113  LOG(ERROR) << "An error occurred during ITAS rollback attempt. Table id: "
4114  << td->tableId << ", Error: " << e.what();
4115  }
4116  throw;
4117  }
4118 
4119  int64_t total_time_ms = total_source_query_time_ms +
4120  total_target_value_translate_time_ms + total_data_load_time_ms;
4121 
4122  VLOG(1) << "CTAS/ITAS " << total_row_count << " rows loaded in " << total_time_ms
4123  << "ms (outer_frag_count=" << outer_frag_count
4124  << ", query_time=" << total_source_query_time_ms
4125  << "ms, translation_time=" << total_target_value_translate_time_ms
4126  << "ms, data_load_time=" << total_data_load_time_ms
4127  << "ms)\nquery: " << select_query_;
4128 
4129  if (!is_temporary) {
4130  leafs_connector_->checkpoint(*session, td->tableId);
4131  }
4132 }
void validate_non_foreign_table_write(const TableDescriptor *table_descriptor)
Definition: FsiUtils.h:22
HOST DEVICE SQLTypes get_subtype() const
Definition: sqltypes.h:382
HOST DEVICE int get_size() const
Definition: sqltypes.h:393
bool is_timestamp() const
Definition: sqltypes.h:1014
#define LOG(tag)
Definition: Logger.h:285
HOST DEVICE int get_scale() const
Definition: sqltypes.h:386
static const AccessPrivileges INSERT_INTO_TABLE
Definition: DBObject.h:161
std::vector< std::unique_ptr< TypedImportBuffer > > fill_missing_columns(const Catalog_Namespace::Catalog *cat, Fragmenter_Namespace::InsertData &insert_data)
Definition: Importer.cpp:6230
TypeR::rep timer_stop(Type clock_begin)
Definition: measure.h:48
bool g_enable_non_kernel_time_query_interrupt
Definition: Execute.cpp:126
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:381
bool is_time() const
Definition: sqltypes.h:586
bool g_enable_string_functions
int tableId
identifies the database into which the data is being inserted
Definition: Fragmenter.h:70
static std::shared_ptr< Executor > getExecutor(const ExecutorId id, const std::string &debug_dir="", const std::string &debug_file="", const SystemParameters &system_parameters=SystemParameters())
Definition: Execute.cpp:475
size_t numRows
a vector of column ids for the row(s) being inserted
Definition: Fragmenter.h:72
future< Result > async(Fn &&fn, Args &&...args)
std::unique_ptr< QueryConnector > leafs_connector_
Definition: ParserNode.h:1156
bool g_enable_assign_render_groups
bool is_integer() const
Definition: sqltypes.h:582
specifies the content in-memory of a row in the column metadata table
bool check_session_interrupted(const QuerySessionId &query_session, Executor *executor)
Definition: ParserNode.cpp:103
#define UNLIKELY(x)
Definition: likely.h:25
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:389
bool table_is_temporary(const TableDescriptor *const td)
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:383
std::string get_type_name() const
Definition: sqltypes.h:507
std::vector< std::unique_ptr< std::string > > column_list_
Definition: ParserNode.h:1159
ThreadId thread_id()
Definition: Logger.cpp:871
#define CHECK(condition)
Definition: Logger.h:291
bool is_geometry() const
Definition: sqltypes.h:592
bool g_cluster
The data to be inserted using the fragment manager.
Definition: Fragmenter.h:68
std::map< int, import_export::RenderGroupAnalyzer > RenderGroupAnalyzerMap
SQLTypeInfo columnType
bool is_string() const
Definition: sqltypes.h:580
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:963
bool is_decimal() const
Definition: sqltypes.h:583
std::string columnName
std::shared_ptr< Catalog_Namespace::SessionInfo const > getConstSessionInfo() const
Definition: QueryState.cpp:84
bool is_date() const
Definition: sqltypes.h:998
bool is_array() const
Definition: sqltypes.h:588
const std::string getQuerySubmittedTime() const
Definition: QueryState.cpp:101
#define VLOG(n)
Definition: Logger.h:387
Type timer_start()
Definition: measure.h:42
std::unique_ptr< TargetValueConverter > create(ConverterCreateParameter param)
static const ExecutorId UNITARY_EXECUTOR_ID
Definition: Execute.h:373
#define IS_GEO_POLY(T)
Definition: sqltypes.h:305

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

std::vector<std::unique_ptr<std::string> > Parser::InsertIntoTableAsSelectStmt::column_list_
protected

Definition at line 1159 of file ParserNode.h.

Referenced by InsertIntoTableAsSelectStmt(), and populateData().

std::unique_ptr<QueryConnector> Parser::InsertIntoTableAsSelectStmt::leafs_connector_

Definition at line 1156 of file ParserNode.h.

Referenced by Parser::CreateTableAsSelectStmt::execute(), and populateData().

std::string Parser::InsertIntoTableAsSelectStmt::select_query_
protected
std::string Parser::InsertIntoTableAsSelectStmt::table_name_
protected

The documentation for this class was generated from the following files: