OmniSciDB  04ee39c94c
MapDHandler Class Reference

#include <MapDHandler.h>

+ Inheritance diagram for MapDHandler:
+ Collaboration diagram for MapDHandler:

Public Member Functions

 MapDHandler (const std::vector< LeafHostInfo > &db_leaves, const std::vector< LeafHostInfo > &string_leaves, const std::string &base_data_path, const bool cpu_only, const bool allow_multifrag, const bool jit_debug, const bool intel_jit_profile, const bool read_only, const bool allow_loop_joins, const bool enable_rendering, const bool enable_spirv, const bool enable_auto_clear_render_mem, const int render_oom_retry_threshold, const size_t render_mem_bytes, const int num_gpus, const int start_gpu, const size_t reserved_gpu_mem, const size_t num_reader_threads, const AuthMetadata &authMetadata, const MapDParameters &mapd_parameters, const bool legacy_syntax, const int idle_session_duration, const int max_session_duration, const bool enable_runtime_udf_registration, const std::string &udf_filename)
 
 ~MapDHandler () override
 
void connect (TSessionId &session, const std::string &username, const std::string &passwd, const std::string &dbname) override
 
void disconnect (const TSessionId &session) override
 
void switch_database (const TSessionId &session, const std::string &dbname) override
 
void get_server_status (TServerStatus &_return, const TSessionId &session) override
 
void get_status (std::vector< TServerStatus > &_return, const TSessionId &session) override
 
void get_hardware_info (TClusterHardwareInfo &_return, const TSessionId &session) override
 
bool hasTableAccessPrivileges (const TableDescriptor *td, const TSessionId &session)
 
void get_tables (std::vector< std::string > &_return, const TSessionId &session) override
 
void get_physical_tables (std::vector< std::string > &_return, const TSessionId &session) override
 
void get_views (std::vector< std::string > &_return, const TSessionId &session) override
 
void get_tables_meta (std::vector< TTableMeta > &_return, const TSessionId &session) override
 
void get_table_details (TTableDetails &_return, const TSessionId &session, const std::string &table_name) override
 
void get_internal_table_details (TTableDetails &_return, const TSessionId &session, const std::string &table_name) override
 
void get_users (std::vector< std::string > &_return, const TSessionId &session) override
 
void get_databases (std::vector< TDBInfo > &_return, const TSessionId &session) override
 
void get_version (std::string &_return) override
 
void start_heap_profile (const TSessionId &session) override
 
void stop_heap_profile (const TSessionId &session) override
 
void get_heap_profile (std::string &_return, const TSessionId &session) override
 
void get_memory (std::vector< TNodeMemoryInfo > &_return, const TSessionId &session, const std::string &memory_level) override
 
void clear_cpu_memory (const TSessionId &session) override
 
void clear_gpu_memory (const TSessionId &session) override
 
void set_table_epoch (const TSessionId &session, const int db_id, const int table_id, const int new_epoch) override
 
void set_table_epoch_by_name (const TSessionId &session, const std::string &table_name, const int new_epoch) override
 
int32_t get_table_epoch (const TSessionId &session, const int32_t db_id, const int32_t table_id) override
 
int32_t get_table_epoch_by_name (const TSessionId &session, const std::string &table_name) override
 
void get_session_info (TSessionInfo &_return, const TSessionId &session) override
 
void sql_execute (TQueryResult &_return, const TSessionId &session, const std::string &query, const bool column_format, const std::string &nonce, const int32_t first_n, const int32_t at_most_n) override
 
void get_completion_hints (std::vector< TCompletionHint > &hints, const TSessionId &session, const std::string &sql, const int cursor) override
 
void sql_execute_df (TDataFrame &_return, const TSessionId &session, const std::string &query, const TDeviceType::type device_type, const int32_t device_id, const int32_t first_n) override
 
void sql_execute_gdf (TDataFrame &_return, const TSessionId &session, const std::string &query, const int32_t device_id, const int32_t first_n) override
 
void deallocate_df (const TSessionId &session, const TDataFrame &df, const TDeviceType::type device_type, const int32_t device_id) override
 
void interrupt (const TSessionId &session) override
 
void sql_validate (TTableDescriptor &_return, const TSessionId &session, const std::string &query) override
 
void set_execution_mode (const TSessionId &session, const TExecuteMode::type mode) override
 
void render_vega (TRenderResult &_return, const TSessionId &session, const int64_t widget_id, const std::string &vega_json, const int32_t compression_level, const std::string &nonce) override
 
void get_result_row_for_pixel (TPixelTableRowResult &_return, const TSessionId &session, const int64_t widget_id, const TPixel &pixel, const std::map< std::string, std::vector< std::string >> &table_col_names, const bool column_format, const int32_t pixel_radius, const std::string &nonce) override
 
void get_dashboard (TDashboard &_return, const TSessionId &session, int32_t dashboard_id) override
 
void get_dashboards (std::vector< TDashboard > &_return, const TSessionId &session) override
 
int32_t create_dashboard (const TSessionId &session, const std::string &dashboard_name, const std::string &dashboard_state, const std::string &image_hash, const std::string &dashboard_metadata) override
 
void replace_dashboard (const TSessionId &session, const int32_t dashboard_id, const std::string &dashboard_name, const std::string &dashboard_owner, const std::string &dashboard_state, const std::string &image_hash, const std::string &dashboard_metadata) override
 
void delete_dashboard (const TSessionId &session, const int32_t dashboard_id) override
 
void share_dashboard (const TSessionId &session, const int32_t dashboard_id, const std::vector< std::string > &groups, const std::vector< std::string > &objects, const TDashboardPermissions &permissions, const bool grant_role) override
 
void unshare_dashboard (const TSessionId &session, const int32_t dashboard_id, const std::vector< std::string > &groups, const std::vector< std::string > &objects, const TDashboardPermissions &permissions) override
 
void get_dashboard_grantees (std::vector< TDashboardGrantees > &_return, const TSessionId &session, int32_t dashboard_id) override
 
void get_link_view (TFrontendView &_return, const TSessionId &session, const std::string &link) override
 
void create_link (std::string &_return, const TSessionId &session, const std::string &view_state, const std::string &view_metadata) override
 
void load_table_binary (const TSessionId &session, const std::string &table_name, const std::vector< TRow > &rows) override
 
void prepare_columnar_loader (const Catalog_Namespace::SessionInfo &session_info, const std::string &table_name, size_t num_cols, std::unique_ptr< Importer_NS::Loader > *loader, std::vector< std::unique_ptr< Importer_NS::TypedImportBuffer >> *import_buffers)
 
void load_table_binary_columnar (const TSessionId &session, const std::string &table_name, const std::vector< TColumn > &cols) override
 
void load_table_binary_arrow (const TSessionId &session, const std::string &table_name, const std::string &arrow_stream) override
 
void load_table (const TSessionId &session, const std::string &table_name, const std::vector< TStringRow > &rows) override
 
void detect_column_types (TDetectResult &_return, const TSessionId &session, const std::string &file_name, const TCopyParams &copy_params) override
 
void create_table (const TSessionId &session, const std::string &table_name, const TRowDescriptor &row_desc, const TFileType::type file_type, const TCreateParams &create_params) override
 
void import_table (const TSessionId &session, const std::string &table_name, const std::string &file_name, const TCopyParams &copy_params) override
 
void import_geo_table (const TSessionId &session, const std::string &table_name, const std::string &file_name, const TCopyParams &copy_params, const TRowDescriptor &row_desc, const TCreateParams &create_params) override
 
void import_table_status (TImportStatus &_return, const TSessionId &session, const std::string &import_id) override
 
void get_first_geo_file_in_archive (std::string &_return, const TSessionId &session, const std::string &archive_path, const TCopyParams &copy_params) override
 
void get_all_files_in_archive (std::vector< std::string > &_return, const TSessionId &session, const std::string &archive_path, const TCopyParams &copy_params) override
 
void get_layers_in_geo_file (std::vector< TGeoFileLayerInfo > &_return, const TSessionId &session, const std::string &file_name, const TCopyParams &copy_params) override
 
void check_table_consistency (TTableMeta &_return, const TSessionId &session, const int32_t table_id) override
 
void start_query (TPendingQuery &_return, const TSessionId &session, const std::string &query_ra, const bool just_explain) override
 
void execute_first_step (TStepResult &_return, const TPendingQuery &pending_query) override
 
void broadcast_serialized_rows (const TSerializedRows &serialized_rows, const TRowDescriptor &row_desc, const TQueryId query_id) override
 
void start_render_query (TPendingRenderQuery &_return, const TSessionId &session, const int64_t widget_id, const int16_t node_idx, const std::string &vega_json) override
 
void execute_next_render_step (TRenderStepResult &_return, const TPendingRenderQuery &pending_render, const TRenderAggDataMap &merged_data) override
 
void insert_data (const TSessionId &session, const TInsertData &insert_data) override
 
void checkpoint (const TSessionId &session, const int32_t db_id, const int32_t table_id) override
 
void get_roles (std::vector< std::string > &_return, const TSessionId &session) override
 
bool has_object_privilege (const TSessionId &sessionId, const std::string &granteeName, const std::string &objectName, const TDBObjectType::type object_type, const TDBObjectPermissions &permissions) override
 
void get_db_objects_for_grantee (std::vector< TDBObject > &_return, const TSessionId &session, const std::string &roleName) override
 
void get_db_object_privs (std::vector< TDBObject > &_return, const TSessionId &session, const std::string &objectName, const TDBObjectType::type type) override
 
void get_all_roles_for_user (std::vector< std::string > &_return, const TSessionId &session, const std::string &granteeName) override
 
std::vector< std::string > get_valid_groups (const TSessionId &session, int32_t dashboard_id, std::vector< std::string > groups)
 
void set_license_key (TLicenseInfo &_return, const TSessionId &session, const std::string &key, const std::string &nonce) override
 
void get_license_claims (TLicenseInfo &_return, const TSessionId &session, const std::string &nonce) override
 
void get_device_parameters (std::map< std::string, std::string > &_return) override
 
void register_runtime_udf (const TSessionId &session, const std::string &signatures, const std::map< std::string, std::string > &device_ir_map) override
 
void shutdown ()
 
void emergency_shutdown ()
 
TSessionId getInvalidSessionId () const
 
void internal_connect (TSessionId &session, const std::string &username, const std::string &dbname)
 
Catalog_Namespace::SessionInfo get_session_copy (const TSessionId &session)
 
std::shared_ptr< Catalog_Namespace::SessionInfoget_session_copy_ptr (const TSessionId &session)
 

Static Public Member Functions

static size_t max_bytes_for_thrift ()
 

Public Attributes

std::shared_ptr< Data_Namespace::DataMgrdata_mgr_
 
LeafAggregator leaf_aggregator_
 
const std::vector< LeafHostInfostring_leaves_
 
const std::string base_data_path_
 
boost::filesystem::path import_path_
 
ExecutorDeviceType executor_device_type_
 
std::default_random_engine random_gen_
 
std::uniform_int_distribution< int64_t > session_id_dist_
 
const bool jit_debug_
 
const bool intel_jit_profile_
 
bool allow_multifrag_
 
const bool read_only_
 
const bool allow_loop_joins_
 
bool cpu_mode_only_
 
mapd_shared_mutex sessions_mutex_
 
std::mutex render_mutex_
 
int64_t start_time_
 
const AuthMetadataauthMetadata_
 
const MapDParametersmapd_parameters_
 
std::unique_ptr< MapDRenderHandlerrender_handler_
 
std::unique_ptr< MapDAggHandleragg_handler_
 
std::unique_ptr< MapDLeafHandlerleaf_handler_
 
std::shared_ptr< Calcitecalcite_
 
const bool legacy_syntax_
 

Private Member Functions

void connect_impl (TSessionId &session, const std::string &passwd, const std::string &dbname, Catalog_Namespace::UserMetadata &user_meta, std::shared_ptr< Catalog_Namespace::Catalog > cat, LogSession &)
 
void disconnect_impl (const SessionMap::iterator &session_it)
 
void check_table_load_privileges (const TSessionId &session, const std::string &table_name)
 
void check_table_load_privileges (const Catalog_Namespace::SessionInfo &session_info, const std::string &table_name)
 
void get_tables_impl (std::vector< std::string > &table_names, const TSessionId &session, const GetTablesType get_tables_type)
 
void get_table_details_impl (TTableDetails &_return, const TSessionId &session, const std::string &table_name, const bool get_system, const bool get_physical)
 
void check_read_only (const std::string &str)
 
void check_session_exp_unsafe (const SessionMap::iterator &session_it)
 
std::shared_ptr< const Catalog_Namespace::SessionInfoget_const_session_ptr (const TSessionId &session)
 
std::shared_ptr< Catalog_Namespace::SessionInfoget_session_ptr (const TSessionId &session_id)
 
SessionMap::iterator get_session_it_unsafe (const TSessionId &session)
 
std::string parse_to_ra (const std::string &query_str, const std::vector< TFilterPushDownInfo > &filter_push_down_info, const Catalog_Namespace::SessionInfo &session_info, OptionalTableMap tableNames, const MapDParameters mapd_parameters, RenderInfo *render_info=nullptr)
 
void sql_execute_impl (TQueryResult &_return, const Catalog_Namespace::SessionInfo &session_info, const std::string &query_str, const bool column_format, const std::string &nonce, const ExecutorDeviceType executor_device_type, const int32_t first_n, const int32_t at_most_n)
 
bool user_can_access_table (const Catalog_Namespace::SessionInfo &, const TableDescriptor *td, const AccessPrivileges acess_priv)
 
void execute_distributed_copy_statement (Parser::CopyTableStmt *, const Catalog_Namespace::SessionInfo &session_info)
 
void validate_rel_alg (TTableDescriptor &_return, const std::string &query_str, const Catalog_Namespace::SessionInfo &session_info)
 
std::vector< PushedDownFilterInfoexecute_rel_alg (TQueryResult &_return, const std::string &query_ra, const bool column_format, const Catalog_Namespace::SessionInfo &session_info, const ExecutorDeviceType executor_device_type, const int32_t first_n, const int32_t at_most_n, const bool just_explain, const bool just_validate, const bool find_push_down_candidates, const bool just_calcite_explain, const bool explain_optimized_ir) const
 
void execute_rel_alg_with_filter_push_down (TQueryResult &_return, std::string &query_ra, const bool column_format, const Catalog_Namespace::SessionInfo &session_info, const ExecutorDeviceType executor_device_type, const int32_t first_n, const int32_t at_most_n, const bool just_explain, const bool just_calcite_explain, const std::string &query_str, const std::vector< PushedDownFilterInfo > filter_push_down_requests)
 
void execute_rel_alg_df (TDataFrame &_return, const std::string &query_ra, const Catalog_Namespace::SessionInfo &session_info, const ExecutorDeviceType device_type, const size_t device_id, const int32_t first_n) const
 
TColumnType populateThriftColumnType (const Catalog_Namespace::Catalog *cat, const ColumnDescriptor *cd)
 
TRowDescriptor fixup_row_descriptor (const TRowDescriptor &row_desc, const Catalog_Namespace::Catalog &cat)
 
void set_execution_mode_nolock (Catalog_Namespace::SessionInfo *session_ptr, const TExecuteMode::type mode)
 
char unescape_char (std::string str)
 
Importer_NS::CopyParams thrift_to_copyparams (const TCopyParams &cp)
 
TCopyParams copyparams_to_thrift (const Importer_NS::CopyParams &cp)
 
void check_geospatial_files (const boost::filesystem::path file_path, const Importer_NS::CopyParams &copy_params)
 
void render_rel_alg (TRenderResult &_return, const std::string &query_ra, const std::string &query_str, const Catalog_Namespace::SessionInfo &session_info, const std::string &render_type, const bool is_projection_query)
 
TColumnType create_geo_column (const TDatumType::type type, const std::string &name, const bool is_array)
 
void convert_explain (TQueryResult &_return, const ResultSet &results, const bool column_format) const
 
void convert_result (TQueryResult &_return, const ResultSet &results, const bool column_format) const
 
template<class R >
void convert_rows (TQueryResult &_return, const std::vector< TargetMetaInfo > &targets, const R &results, const bool column_format, const int32_t first_n, const int32_t at_most_n) const
 
void create_simple_result (TQueryResult &_return, const ResultSet &results, const bool column_format, const std::string label) const
 
void execute_root_plan (TQueryResult &_return, const Planner::RootPlan *root_plan, const bool column_format, const Catalog_Namespace::SessionInfo &session_info, const ExecutorDeviceType executor_device_type, const int32_t first_n) const
 
std::vector< TargetMetaInfogetTargetMetaInfo (const std::vector< std::shared_ptr< Analyzer::TargetEntry >> &targets) const
 
std::vector< std::string > getTargetNames (const std::vector< TargetMetaInfo > &targets) const
 
std::vector< std::string > getTargetNames (const std::vector< std::shared_ptr< Analyzer::TargetEntry >> &targets) const
 
TColumnType convert_target_metainfo (const TargetMetaInfo &target, const size_t idx) const
 
TRowDescriptor convert_target_metainfo (const std::vector< TargetMetaInfo > &targets) const
 
void get_completion_hints_unsorted (std::vector< TCompletionHint > &hints, std::vector< std::string > &visible_tables, const TSessionId &session, const std::string &sql, const int cursor)
 
void get_token_based_completions (std::vector< TCompletionHint > &hints, const TSessionId &session, const std::vector< std::string > &visible_tables, const std::string &sql, const int cursor)
 
Planner::RootPlanparse_to_plan (const std::string &query_str, const Catalog_Namespace::SessionInfo &session_info)
 
Planner::RootPlanparse_to_plan_legacy (const std::string &query_str, const Catalog_Namespace::SessionInfo &session_info, const std::string &action)
 
std::unordered_map< std::string, std::unordered_set< std::string > > fill_column_names_by_table (const std::vector< std::string > &table_names, const TSessionId &session)
 
std::unordered_set< std::string > get_uc_compatible_table_names_by_column (const std::unordered_set< std::string > &uc_column_names, const std::vector< std::string > &table_names, const TSessionId &session)
 
void check_and_invalidate_sessions (Parser::DDLStmt *ddl)
 
template<typename STMT_TYPE >
void invalidate_sessions (std::string &name, STMT_TYPE *stmt)
 

Static Private Member Functions

static void value_to_thrift_column (const TargetValue &tv, const SQLTypeInfo &ti, TColumn &column)
 
static TDatum value_to_thrift (const TargetValue &tv, const SQLTypeInfo &ti)
 
static std::string apply_copy_to_shim (const std::string &query_str)
 
static bool has_database_permission (const AccessPrivileges &privs, const TDBObjectPermissions &permissions)
 
static bool has_table_permission (const AccessPrivileges &privs, const TDBObjectPermissions &permission)
 
static bool has_dashboard_permission (const AccessPrivileges &privs, const TDBObjectPermissions &permissions)
 
static bool has_view_permission (const AccessPrivileges &privs, const TDBObjectPermissions &permissions)
 

Private Attributes

SessionMap sessions_
 
bool super_user_rights_
 
const int idle_session_duration_
 
const int max_session_duration_
 
const bool runtime_udf_registration_enabled_
 
bool _was_geo_copy_from
 
std::string _geo_copy_from_table
 
std::string _geo_copy_from_file_name
 
Importer_NS::CopyParams _geo_copy_from_copy_params
 
std::string _geo_copy_from_partitions
 
std::mutex handle_to_dev_ptr_mutex_
 
std::unordered_map< std::string, int8_t * > ipc_handle_to_dev_ptr_
 
std::map< const std::string, const permissionFuncPtrpermissionFuncMap_
 

Friends

class LogSession
 
class MapDRenderHandler
 
class MapDAggHandler
 
class MapDLeafHandler
 
void run_warmup_queries (mapd::shared_ptr< MapDHandler > handler, std::string base_path, std::string query_file_path)
 

Detailed Description

Definition at line 120 of file MapDHandler.h.

Constructor & Destructor Documentation

◆ MapDHandler()

MapDHandler::MapDHandler ( const std::vector< LeafHostInfo > &  db_leaves,
const std::vector< LeafHostInfo > &  string_leaves,
const std::string &  base_data_path,
const bool  cpu_only,
const bool  allow_multifrag,
const bool  jit_debug,
const bool  intel_jit_profile,
const bool  read_only,
const bool  allow_loop_joins,
const bool  enable_rendering,
const bool  enable_spirv,
const bool  enable_auto_clear_render_mem,
const int  render_oom_retry_threshold,
const size_t  render_mem_bytes,
const int  num_gpus,
const int  start_gpu,
const size_t  reserved_gpu_mem,
const size_t  num_reader_threads,
const AuthMetadata authMetadata,
const MapDParameters mapd_parameters,
const bool  legacy_syntax,
const int  idle_session_duration,
const int  max_session_duration,
const bool  enable_runtime_udf_registration,
const std::string &  udf_filename 
)

Definition at line 136 of file MapDHandler.cpp.

References _was_geo_copy_from, ExtensionFunctionsWhitelist::add(), ExtensionFunctionsWhitelist::addUdfs(), agg_handler_, allow_loop_joins_, allow_multifrag_, authMetadata_, base_data_path_, calcite_, UdfCompiler::compileUdf(), CPU, cpu_mode_only_, data_mgr_, logger::ERROR, executor_device_type_, g_cluster, generate_random_string(), UdfCompiler::getAstFileName(), GPU, idle_session_duration_, import_path_, logger::INFO, intel_jit_profile_, jit_debug_, leaf_aggregator_, leaf_handler_, LeafAggregator::leafCount(), legacy_syntax_, LOG, mapd_parameters_, MAPD_RELEASE, MapDAggHandler, MapDLeafHandler, MapDRenderHandler, max_session_duration_, read_only_, render_handler_, runtime_udf_registration_enabled_, session_id_dist_, start_time_, string_leaves_, and super_user_rights_.

161  : leaf_aggregator_(db_leaves)
162  , string_leaves_(string_leaves)
163  , base_data_path_(base_data_path)
164  , random_gen_(std::random_device{}())
165  , session_id_dist_(0, INT32_MAX)
166  , jit_debug_(jit_debug)
167  , intel_jit_profile_(intel_jit_profile)
168  , allow_multifrag_(allow_multifrag)
169  , read_only_(read_only)
170  , allow_loop_joins_(allow_loop_joins)
171  , authMetadata_(authMetadata)
172  , mapd_parameters_(mapd_parameters)
173  , legacy_syntax_(legacy_syntax)
174  , super_user_rights_(false)
175  , idle_session_duration_(idle_session_duration * 60)
176  , max_session_duration_(max_session_duration * 60)
177  , runtime_udf_registration_enabled_(enable_runtime_udf_registration)
178  , _was_geo_copy_from(false) {
179  LOG(INFO) << "OmniSci Server " << MAPD_RELEASE;
180  bool is_rendering_enabled = enable_rendering;
181  if (cpu_only) {
182  is_rendering_enabled = false;
184  cpu_mode_only_ = true;
185  } else {
186 #ifdef HAVE_CUDA
188  cpu_mode_only_ = false;
189 #else
191  LOG(ERROR) << "This build isn't CUDA enabled, will run on CPU";
192  cpu_mode_only_ = true;
193  is_rendering_enabled = false;
194 #endif
195  }
196 
197  const auto data_path = boost::filesystem::path(base_data_path_) / "mapd_data";
198  // calculate the total amount of memory we need to reserve from each gpu that the Buffer
199  // manage cannot ask for
200  size_t total_reserved = reserved_gpu_mem;
201  if (is_rendering_enabled) {
202  total_reserved += render_mem_bytes;
203  }
204  data_mgr_.reset(new Data_Namespace::DataMgr(data_path.string(),
205  mapd_parameters,
207  num_gpus,
208  start_gpu,
209  total_reserved,
210  num_reader_threads));
211 
212  std::string udf_ast_filename("");
213 
214  if (!udf_filename.empty()) {
215  UdfCompiler compiler(udf_filename);
216  int compile_result = compiler.compileUdf();
217 
218  if (compile_result == 0) {
219  udf_ast_filename = compiler.getAstFileName();
220  }
221  }
222 
223  std::string calcite_session_prefix = "calcite-" + generate_random_string(64);
224 
225  calcite_ = std::make_shared<Calcite>(
226  mapd_parameters, base_data_path_, calcite_session_prefix, udf_ast_filename);
227 
228  ExtensionFunctionsWhitelist::add(calcite_->getExtensionFunctionWhitelist());
229  if (!udf_filename.empty()) {
230  ExtensionFunctionsWhitelist::addUdfs(calcite_->getUserDefinedFunctionWhitelist());
231  }
232 
233  if (!data_mgr_->gpusPresent() && !cpu_mode_only_) {
235  LOG(ERROR) << "No GPUs detected, falling back to CPU mode";
236  cpu_mode_only_ = true;
237  }
238 
239  switch (executor_device_type_) {
241  LOG(INFO) << "Started in GPU mode" << std::endl;
242  break;
244  LOG(INFO) << "Started in CPU mode" << std::endl;
245  break;
246  }
247  SysCatalog::instance().init(base_data_path_,
248  data_mgr_,
249  authMetadata,
250  calcite_,
251  false,
252  !db_leaves.empty(),
254  import_path_ = boost::filesystem::path(base_data_path_) / "mapd_import";
255  start_time_ = std::time(nullptr);
256 
257  if (is_rendering_enabled) {
258  try {
260  this, render_mem_bytes, num_gpus, start_gpu, mapd_parameters_));
261  } catch (const std::exception& e) {
262  LOG(ERROR) << "Backend rendering disabled: " << e.what();
263  }
264  }
265 
266  if (leaf_aggregator_.leafCount() > 0) {
267  try {
268  agg_handler_.reset(new MapDAggHandler(this));
269  } catch (const std::exception& e) {
270  LOG(ERROR) << "Distributed aggregator support disabled: " << e.what();
271  }
272  } else if (g_cluster) {
273  try {
274  leaf_handler_.reset(new MapDLeafHandler(this));
275  } catch (const std::exception& e) {
276  LOG(ERROR) << "Distributed leaf support disabled: " << e.what();
277  }
278  }
279 }
friend class MapDRenderHandler
Definition: MapDHandler.h:693
const bool allow_loop_joins_
Definition: MapDHandler.h:450
static void addUdfs(const std::string &json_func_sigs)
std::unique_ptr< MapDRenderHandler > render_handler_
Definition: MapDHandler.h:457
boost::filesystem::path import_path_
Definition: MapDHandler.h:442
#define LOG(tag)
Definition: Logger.h:182
static void add(const std::string &json_func_sigs)
friend class MapDAggHandler
Definition: MapDHandler.h:694
std::unique_ptr< MapDAggHandler > agg_handler_
Definition: MapDHandler.h:458
bool cpu_mode_only_
Definition: MapDHandler.h:451
const bool runtime_udf_registration_enabled_
Definition: MapDHandler.h:676
const bool intel_jit_profile_
Definition: MapDHandler.h:447
int64_t start_time_
Definition: MapDHandler.h:454
const int idle_session_duration_
Definition: MapDHandler.h:673
const MapDParameters & mapd_parameters_
Definition: MapDHandler.h:456
bool allow_multifrag_
Definition: MapDHandler.h:448
std::string generate_random_string(const size_t len)
const bool read_only_
Definition: MapDHandler.h:449
const std::vector< LeafHostInfo > string_leaves_
Definition: MapDHandler.h:440
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:439
std::shared_ptr< Calcite > calcite_
Definition: MapDHandler.h:460
bool _was_geo_copy_from
Definition: MapDHandler.h:678
std::shared_ptr< Data_Namespace::DataMgr > data_mgr_
Definition: MapDHandler.h:437
ExecutorDeviceType executor_device_type_
Definition: MapDHandler.h:443
std::uniform_int_distribution< int64_t > session_id_dist_
Definition: MapDHandler.h:445
friend class MapDLeafHandler
Definition: MapDHandler.h:695
const AuthMetadata & authMetadata_
Definition: MapDHandler.h:455
bool g_cluster
std::unique_ptr< MapDLeafHandler > leaf_handler_
Definition: MapDHandler.h:459
size_t leafCount() const
static const std::string MAPD_RELEASE
Definition: release.h:43
const int max_session_duration_
Definition: MapDHandler.h:674
const bool jit_debug_
Definition: MapDHandler.h:446
bool super_user_rights_
Definition: MapDHandler.h:671
std::default_random_engine random_gen_
Definition: MapDHandler.h:444
const bool legacy_syntax_
Definition: MapDHandler.h:461
const std::string base_data_path_
Definition: MapDHandler.h:441
+ Here is the call graph for this function:

◆ ~MapDHandler()

MapDHandler::~MapDHandler ( )
override

Definition at line 281 of file MapDHandler.cpp.

281 {}

Member Function Documentation

◆ apply_copy_to_shim()

std::string MapDHandler::apply_copy_to_shim ( const std::string &  query_str)
staticprivate

Definition at line 942 of file MapDHandler.cpp.

References apply_shim(), and run-benchmark-import::result.

Referenced by sql_execute_impl().

942  {
943  auto result = query_str;
944  {
945  // boost::regex copy_to{R"(COPY\s\((.*)\)\sTO\s(.*))", boost::regex::extended |
946  // boost::regex::icase};
947  boost::regex copy_to{R"(COPY\s*\(([^#])(.+)\)\s+TO\s)",
948  boost::regex::extended | boost::regex::icase};
949  apply_shim(result, copy_to, [](std::string& result, const boost::smatch& what) {
950  result.replace(
951  what.position(), what.length(), "COPY (#~#" + what[1] + what[2] + "#~#) TO ");
952  });
953  }
954  return result;
955 }
void apply_shim(std::string &result, const boost::regex &reg_expr, const std::function< void(std::string &, const boost::smatch &)> &shim_fn)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ broadcast_serialized_rows()

void MapDHandler::broadcast_serialized_rows ( const TSerializedRows &  serialized_rows,
const TRowDescriptor &  row_desc,
const TQueryId  query_id 
)
override

Definition at line 5296 of file MapDHandler.cpp.

References measure< TimeT >::execution(), logger::INFO, leaf_handler_, LOG, run-benchmark::query_id, and THROW_MAPD_EXCEPTION.

5298  {
5299  if (!leaf_handler_) {
5300  THROW_MAPD_EXCEPTION("Distributed support is disabled.");
5301  }
5302  LOG(INFO) << "BROADCAST-SERIALIZED-ROWS id:" << query_id;
5303  auto time_ms = measure<>::execution([&]() {
5304  try {
5305  leaf_handler_->broadcast_serialized_rows(serialized_rows, row_desc, query_id);
5306  } catch (std::exception& e) {
5307  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
5308  }
5309  });
5310  LOG(INFO) << "BROADCAST-SERIALIZED-ROWS COMPLETED " << time_ms << "ms";
5311 }
#define LOG(tag)
Definition: Logger.h:182
#define THROW_MAPD_EXCEPTION(errstr)
std::unique_ptr< MapDLeafHandler > leaf_handler_
Definition: MapDHandler.h:459
static TimeT::rep execution(F func, Args &&... args)
Definition: sample.cpp:29
+ Here is the call graph for this function:

◆ check_and_invalidate_sessions()

void MapDHandler::check_and_invalidate_sessions ( Parser::DDLStmt ddl)
private

Definition at line 4690 of file MapDHandler.cpp.

References invalidate_sessions().

Referenced by sql_execute_impl().

4690  {
4691  const auto drop_db_stmt = dynamic_cast<Parser::DropDBStmt*>(ddl);
4692  if (drop_db_stmt) {
4693  invalidate_sessions(*drop_db_stmt->getDatabaseName(), drop_db_stmt);
4694  return;
4695  }
4696  const auto rename_db_stmt = dynamic_cast<Parser::RenameDatabaseStmt*>(ddl);
4697  if (rename_db_stmt) {
4698  invalidate_sessions(*rename_db_stmt->getPreviousDatabaseName(), rename_db_stmt);
4699  return;
4700  }
4701  const auto drop_user_stmt = dynamic_cast<Parser::DropUserStmt*>(ddl);
4702  if (drop_user_stmt) {
4703  invalidate_sessions(*drop_user_stmt->getUserName(), drop_user_stmt);
4704  return;
4705  }
4706  const auto rename_user_stmt = dynamic_cast<Parser::RenameUserStmt*>(ddl);
4707  if (rename_user_stmt) {
4708  invalidate_sessions(*rename_user_stmt->getOldUserName(), rename_user_stmt);
4709  return;
4710  }
4711 }
void invalidate_sessions(std::string &name, STMT_TYPE *stmt)
Definition: MapDHandler.h:706
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ check_geospatial_files()

void MapDHandler::check_geospatial_files ( const boost::filesystem::path  file_path,
const Importer_NS::CopyParams copy_params 
)
private

Definition at line 3347 of file MapDHandler.cpp.

References Importer_NS::Importer::gdalFileExists().

Referenced by detect_column_types(), and import_geo_table().

3348  {
3349  const std::list<std::string> shp_ext{".shp", ".shx", ".dbf"};
3350  if (std::find(shp_ext.begin(),
3351  shp_ext.end(),
3352  boost::algorithm::to_lower_copy(file_path.extension().string())) !=
3353  shp_ext.end()) {
3354  for (auto ext : shp_ext) {
3355  auto aux_file = file_path;
3357  aux_file.replace_extension(boost::algorithm::to_upper_copy(ext)).string(),
3358  copy_params) &&
3359  !Importer_NS::Importer::gdalFileExists(aux_file.replace_extension(ext).string(),
3360  copy_params)) {
3361  throw std::runtime_error("required file for shapefile does not exist: " +
3362  aux_file.filename().string());
3363  }
3364  }
3365  }
3366 }
static bool gdalFileExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:4367
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ check_read_only()

void MapDHandler::check_read_only ( const std::string &  str)
private

Definition at line 283 of file MapDHandler.cpp.

References read_only_, and THROW_MAPD_EXCEPTION.

Referenced by create_dashboard(), create_table(), delete_dashboard(), detect_column_types(), import_geo_table(), import_table(), load_table(), load_table_binary(), load_table_binary_arrow(), load_table_binary_columnar(), replace_dashboard(), set_license_key(), share_dashboard(), sql_execute_impl(), and unshare_dashboard().

283  {
285  THROW_MAPD_EXCEPTION(str + " disabled: server running in read-only mode.");
286  }
287 }
#define THROW_MAPD_EXCEPTION(errstr)
const bool read_only_
Definition: MapDHandler.h:449
+ Here is the caller graph for this function:

◆ check_session_exp_unsafe()

void MapDHandler::check_session_exp_unsafe ( const SessionMap::iterator &  session_it)
private

Definition at line 4202 of file MapDHandler.cpp.

References disconnect_impl(), idle_session_duration_, max_session_duration_, run-benchmark-import::start_time, and THROW_MAPD_EXCEPTION.

Referenced by get_session_it_unsafe().

4202  {
4203  if (session_it->second.use_count() > 2) {
4204  // SessionInfo is being used in more than one active operation. Original copy + one
4205  // stored in LogSession. Skip the checks.
4206  return;
4207  }
4208  time_t last_used_time = session_it->second->get_last_used_time();
4209  time_t start_time = session_it->second->get_start_time();
4210  if ((time(0) - last_used_time) > idle_session_duration_) {
4212  session_it); // Already checked session existance in get_session_it_unsafe
4213  THROW_MAPD_EXCEPTION("Idle Session Timeout. User should re-authenticate.")
4214  } else if ((time(0) - start_time) > max_session_duration_) {
4216  session_it); // Already checked session existance in get_session_it_unsafe
4217  THROW_MAPD_EXCEPTION("Maximum active Session Timeout. User should re-authenticate.")
4218  }
4219 }
const int idle_session_duration_
Definition: MapDHandler.h:673
#define THROW_MAPD_EXCEPTION(errstr)
void disconnect_impl(const SessionMap::iterator &session_it)
const int max_session_duration_
Definition: MapDHandler.h:674
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ check_table_consistency()

void MapDHandler::check_table_consistency ( TTableMeta &  _return,
const TSessionId &  session,
const int32_t  table_id 
)
override

Definition at line 5245 of file MapDHandler.cpp.

References leaf_handler_, LOG_SESSION, and THROW_MAPD_EXCEPTION.

5247  {
5249  if (!leaf_handler_) {
5250  THROW_MAPD_EXCEPTION("Distributed support is disabled.");
5251  }
5252  try {
5253  leaf_handler_->check_table_consistency(_return, session, table_id);
5254  } catch (std::exception& e) {
5255  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
5256  }
5257 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
#define THROW_MAPD_EXCEPTION(errstr)
std::unique_ptr< MapDLeafHandler > leaf_handler_
Definition: MapDHandler.h:459
TSessionId session

◆ check_table_load_privileges() [1/2]

void MapDHandler::check_table_load_privileges ( const TSessionId &  session,
const std::string &  table_name 
)
private

Definition at line 4303 of file MapDHandler.cpp.

References get_session_copy().

Referenced by import_geo_table(), import_table(), load_table(), load_table_binary(), and prepare_columnar_loader().

4304  {
4305  const auto session_info = get_session_copy(session);
4306  check_table_load_privileges(session_info, table_name);
4307 }
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
void check_table_load_privileges(const TSessionId &session, const std::string &table_name)
TSessionId session
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ check_table_load_privileges() [2/2]

void MapDHandler::check_table_load_privileges ( const Catalog_Namespace::SessionInfo session_info,
const std::string &  table_name 
)
private

Definition at line 4286 of file MapDHandler.cpp.

References Catalog_Namespace::SessionInfo::get_currentUser(), Catalog_Namespace::SessionInfo::getCatalog(), AccessPrivileges::INSERT_INTO_TABLE, DBObject::loadKey(), anonymous_namespace{DBObjectPrivilegesTest.cpp}::privObjects, DBObject::setPrivileges(), TableDBObjectType, and THROW_MAPD_EXCEPTION.

4288  {
4289  auto user_metadata = session_info.get_currentUser();
4290  auto& cat = session_info.getCatalog();
4291  DBObject dbObject(table_name, TableDBObjectType);
4292  dbObject.loadKey(cat);
4293  dbObject.setPrivileges(AccessPrivileges::INSERT_INTO_TABLE);
4294  std::vector<DBObject> privObjects;
4295  privObjects.push_back(dbObject);
4296  if (!SysCatalog::instance().checkPrivileges(user_metadata, privObjects)) {
4297  THROW_MAPD_EXCEPTION("Violation of access privileges: user " +
4298  user_metadata.userName + " has no insert privileges for table " +
4299  table_name + ".");
4300  }
4301 }
static const AccessPrivileges INSERT_INTO_TABLE
Definition: DBObject.h:154
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:93
#define THROW_MAPD_EXCEPTION(errstr)
Catalog & getCatalog() const
Definition: SessionInfo.h:90
+ Here is the call graph for this function:

◆ checkpoint()

void MapDHandler::checkpoint ( const TSessionId &  session,
const int32_t  db_id,
const int32_t  table_id 
)
override

Definition at line 5444 of file MapDHandler.cpp.

References get_session_copy(), and LOG_SESSION.

5446  {
5448  const auto session_info = get_session_copy(session);
5449  auto& cat = session_info.getCatalog();
5450  cat.getDataMgr().checkpoint(db_id, table_id);
5451 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
TSessionId session
+ Here is the call graph for this function:

◆ clear_cpu_memory()

void MapDHandler::clear_cpu_memory ( const TSessionId &  session)
override

Definition at line 1911 of file MapDHandler.cpp.

References LeafAggregator::clear_leaf_cpu_memory(), Executor::clearMemory(), Data_Namespace::CPU_LEVEL, get_session_copy(), leaf_aggregator_, LeafAggregator::leafCount(), LOG_SESSION, render_handler_, and THROW_MAPD_EXCEPTION.

1911  {
1913  const auto session_info = get_session_copy(session);
1914  if (!session_info.get_currentUser().isSuper) {
1915  THROW_MAPD_EXCEPTION("Superuser privilege is required to run clear_cpu_memory");
1916  }
1917  try {
1919  } catch (const std::exception& e) {
1920  THROW_MAPD_EXCEPTION(e.what());
1921  }
1922  if (render_handler_) {
1923  render_handler_->clear_cpu_memory();
1924  }
1925 
1926  if (leaf_aggregator_.leafCount() > 0) {
1928  }
1929 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
std::unique_ptr< MapDRenderHandler > render_handler_
Definition: MapDHandler.h:457
static void clearMemory(const Data_Namespace::MemoryLevel memory_level)
Definition: Execute.cpp:155
#define THROW_MAPD_EXCEPTION(errstr)
void clear_leaf_cpu_memory(const TSessionId session)
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:439
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
size_t leafCount() const
TSessionId session
+ Here is the call graph for this function:

◆ clear_gpu_memory()

void MapDHandler::clear_gpu_memory ( const TSessionId &  session)
override

Definition at line 1891 of file MapDHandler.cpp.

References LeafAggregator::clear_leaf_gpu_memory(), Executor::clearMemory(), get_session_copy(), Data_Namespace::GPU_LEVEL, leaf_aggregator_, LeafAggregator::leafCount(), LOG_SESSION, render_handler_, and THROW_MAPD_EXCEPTION.

1891  {
1893  const auto session_info = get_session_copy(session);
1894  if (!session_info.get_currentUser().isSuper) {
1895  THROW_MAPD_EXCEPTION("Superuser privilege is required to run clear_gpu_memory");
1896  }
1897  try {
1899  } catch (const std::exception& e) {
1900  THROW_MAPD_EXCEPTION(e.what());
1901  }
1902  if (render_handler_) {
1903  render_handler_->clear_gpu_memory();
1904  }
1905 
1906  if (leaf_aggregator_.leafCount() > 0) {
1908  }
1909 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
std::unique_ptr< MapDRenderHandler > render_handler_
Definition: MapDHandler.h:457
void clear_leaf_gpu_memory(const TSessionId session)
static void clearMemory(const Data_Namespace::MemoryLevel memory_level)
Definition: Execute.cpp:155
#define THROW_MAPD_EXCEPTION(errstr)
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:439
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
size_t leafCount() const
TSessionId session
+ Here is the call graph for this function:

◆ connect()

void MapDHandler::connect ( TSessionId &  session,
const std::string &  username,
const std::string &  passwd,
const std::string &  dbname 
)
override

Definition at line 318 of file MapDHandler.cpp.

References AccessPrivileges::ACCESS, connect_impl(), DatabaseDBObjectType, LOG_SESSION, sessions_mutex_, super_user_rights_, and THROW_MAPD_EXCEPTION.

321  {
322  LOG_SESSION(session); // session not assumed valid here
323 
324  mapd_lock_guard<mapd_shared_mutex> write_lock(sessions_mutex_);
325  std::string username2 = username; // login() may reset username given as argument
326  std::string dbname2 = dbname; // login() may reset dbname given as argument
328  std::shared_ptr<Catalog> cat = nullptr;
329  try {
330  cat = SysCatalog::instance().login(
331  dbname2, username2, passwd, user_meta, !super_user_rights_);
332  } catch (std::exception& e) {
333  THROW_MAPD_EXCEPTION(e.what());
334  }
335 
336  DBObject dbObject(dbname2, DatabaseDBObjectType);
337  dbObject.loadKey(*cat);
338  dbObject.setPrivileges(AccessPrivileges::ACCESS);
339  std::vector<DBObject> dbObjects;
340  dbObjects.push_back(dbObject);
341  if (!SysCatalog::instance().checkPrivileges(user_meta, dbObjects)) {
342  THROW_MAPD_EXCEPTION("Unauthorized Access: user " + username +
343  " is not allowed to access database " + dbname2 + ".");
344  }
345  connect_impl(session, passwd, dbname2, user_meta, cat, log_session);
346 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
void connect_impl(TSessionId &session, const std::string &passwd, const std::string &dbname, Catalog_Namespace::UserMetadata &user_meta, std::shared_ptr< Catalog_Namespace::Catalog > cat, LogSession &)
mapd_shared_mutex sessions_mutex_
Definition: MapDHandler.h:452
#define THROW_MAPD_EXCEPTION(errstr)
static const AccessPrivileges ACCESS
Definition: DBObject.h:146
TSessionId session
bool super_user_rights_
Definition: MapDHandler.h:671
+ Here is the call graph for this function:

◆ connect_impl()

void MapDHandler::connect_impl ( TSessionId &  session,
const std::string &  passwd,
const std::string &  dbname,
Catalog_Namespace::UserMetadata user_meta,
std::shared_ptr< Catalog_Namespace::Catalog cat,
LogSession log_session 
)
private

Definition at line 348 of file MapDHandler.cpp.

References LogSession::append_name_value_pairs(), CHECK, LeafAggregator::connect(), executor_device_type_, generate_random_string(), logger::INFO, join(), leaf_aggregator_, LeafAggregator::leafCount(), LOG, sessions_, LogSession::set_session(), super_user_rights_, and Catalog_Namespace::UserMetadata::userName.

Referenced by connect(), and internal_connect().

353  {
354  do {
356  } while (sessions_.find(session) != sessions_.end());
357  std::pair<SessionMap::iterator, bool> emplace_retval =
358  sessions_.emplace(session,
359  std::make_shared<Catalog_Namespace::SessionInfo>(
360  cat, user_meta, executor_device_type_, session));
361  CHECK(emplace_retval.second);
362  SessionMap::mapped_type session_ptr = emplace_retval.first->second;
363  log_session.set_session(session_ptr);
364  if (!super_user_rights_) { // no need to connect to leaf_aggregator_ at this time while
365  // doing warmup
366  if (leaf_aggregator_.leafCount() > 0) {
367  const auto parent_session_info_ptr = session_ptr;
368  CHECK(parent_session_info_ptr);
370  *parent_session_info_ptr, user_meta.userName, passwd, dbname);
371  return;
372  }
373  }
374  auto const roles = session_ptr->get_currentUser().isSuper
375  ? std::vector<std::string>{{"super"}}
376  : SysCatalog::instance().getRoles(
377  false, false, session_ptr->get_currentUser().userName);
378  log_session.append_name_value_pairs("roles", boost::algorithm::join(roles, ","));
379  LOG(INFO) << "User " << user_meta.userName << " connected to database " << dbname
380  << " with public_session_id " << session_ptr->get_public_session_id();
381 }
SessionMap sessions_
Definition: MapDHandler.h:669
#define LOG(tag)
Definition: Logger.h:182
std::string join(T const &container, std::string const &delim)
void connect(const Catalog_Namespace::SessionInfo &parent_session_info, const std::string &user, const std::string &passwd, const std::string &dbname)
std::string generate_random_string(const size_t len)
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:439
void set_session(SessionMap::mapped_type &session_ptr)
void append_name_value_pairs(Pairs &&... pairs)
Definition: MapDHandler.h:793
ExecutorDeviceType executor_device_type_
Definition: MapDHandler.h:443
#define CHECK(condition)
Definition: Logger.h:187
size_t leafCount() const
TSessionId session
bool super_user_rights_
Definition: MapDHandler.h:671
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ convert_explain()

void MapDHandler::convert_explain ( TQueryResult &  _return,
const ResultSet results,
const bool  column_format 
) const
private

Definition at line 4662 of file MapDHandler.cpp.

References create_simple_result().

Referenced by execute_rel_alg(), execute_rel_alg_with_filter_push_down(), execute_root_plan(), and sql_execute_impl().

4664  {
4665  create_simple_result(_return, results, column_format, "Explanation");
4666 }
void create_simple_result(TQueryResult &_return, const ResultSet &results, const bool column_format, const std::string label) const
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ convert_result()

void MapDHandler::convert_result ( TQueryResult &  _return,
const ResultSet results,
const bool  column_format 
) const
private

Definition at line 4668 of file MapDHandler.cpp.

References create_simple_result().

Referenced by sql_execute_impl().

4670  {
4671  create_simple_result(_return, results, column_format, "Result");
4672 }
void create_simple_result(TQueryResult &_return, const ResultSet &results, const bool column_format, const std::string label) const
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ convert_rows()

template<class R >
void MapDHandler::convert_rows ( TQueryResult &  _return,
const std::vector< TargetMetaInfo > &  targets,
const R &  results,
const bool  column_format,
const int32_t  first_n,
const int32_t  at_most_n 
) const
private

Definition at line 4556 of file MapDHandler.cpp.

References convert_target_metainfo(), INJECT_TIMER, THROW_MAPD_EXCEPTION, to_string(), value_to_thrift(), and value_to_thrift_column().

Referenced by execute_rel_alg(), and execute_root_plan().

4561  {
4563  _return.row_set.row_desc = convert_target_metainfo(targets);
4564  int32_t fetched{0};
4565  if (column_format) {
4566  _return.row_set.is_columnar = true;
4567  std::vector<TColumn> tcolumns(results.colCount());
4568  while (first_n == -1 || fetched < first_n) {
4569  const auto crt_row = results.getNextRow(true, true);
4570  if (crt_row.empty()) {
4571  break;
4572  }
4573  ++fetched;
4574  if (at_most_n >= 0 && fetched > at_most_n) {
4575  THROW_MAPD_EXCEPTION("The result contains more rows than the specified cap of " +
4576  std::to_string(at_most_n));
4577  }
4578  for (size_t i = 0; i < results.colCount(); ++i) {
4579  const auto agg_result = crt_row[i];
4580  value_to_thrift_column(agg_result, targets[i].get_type_info(), tcolumns[i]);
4581  }
4582  }
4583  for (size_t i = 0; i < results.colCount(); ++i) {
4584  _return.row_set.columns.push_back(tcolumns[i]);
4585  }
4586  } else {
4587  _return.row_set.is_columnar = false;
4588  while (first_n == -1 || fetched < first_n) {
4589  const auto crt_row = results.getNextRow(true, true);
4590  if (crt_row.empty()) {
4591  break;
4592  }
4593  ++fetched;
4594  if (at_most_n >= 0 && fetched > at_most_n) {
4595  THROW_MAPD_EXCEPTION("The result contains more rows than the specified cap of " +
4596  std::to_string(at_most_n));
4597  }
4598  TRow trow;
4599  trow.cols.reserve(results.colCount());
4600  for (size_t i = 0; i < results.colCount(); ++i) {
4601  const auto agg_result = crt_row[i];
4602  trow.cols.push_back(value_to_thrift(agg_result, targets[i].get_type_info()));
4603  }
4604  _return.row_set.rows.push_back(trow);
4605  }
4606  }
4607 }
static TDatum value_to_thrift(const TargetValue &tv, const SQLTypeInfo &ti)
TColumnType convert_target_metainfo(const TargetMetaInfo &target, const size_t idx) const
std::string to_string(char const *&&v)
#define THROW_MAPD_EXCEPTION(errstr)
#define INJECT_TIMER(DESC)
Definition: measure.h:91
void convert_rows(TQueryResult &_return, const std::vector< TargetMetaInfo > &targets, const R &results, const bool column_format, const int32_t first_n, const int32_t at_most_n) const
static void value_to_thrift_column(const TargetValue &tv, const SQLTypeInfo &ti, TColumn &column)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ convert_target_metainfo() [1/2]

TColumnType MapDHandler::convert_target_metainfo ( const TargetMetaInfo target,
const size_t  idx 
) const
private

Definition at line 4515 of file MapDHandler.cpp.

References encoding_to_thrift(), anonymous_namespace{MapDHandler.cpp}::fixup_geo_column_descriptor(), TargetMetaInfo::get_resname(), TargetMetaInfo::get_type_info(), IS_GEO, kARRAY, kDATE, to_string(), SQLTypeInfoCore< TYPE_FACET_PACK >::type, and type_to_thrift().

Referenced by convert_rows(), and convert_target_metainfo().

4516  {
4517  TColumnType proj_info;
4518  proj_info.col_name = target.get_resname();
4519  if (proj_info.col_name.empty()) {
4520  proj_info.col_name = "result_" + std::to_string(idx + 1);
4521  }
4522  const auto& target_ti = target.get_type_info();
4523  proj_info.col_type.type = type_to_thrift(target_ti);
4524  proj_info.col_type.encoding = encoding_to_thrift(target_ti);
4525  proj_info.col_type.nullable = !target_ti.get_notnull();
4526  proj_info.col_type.is_array = target_ti.get_type() == kARRAY;
4527  if (IS_GEO(target_ti.get_type())) {
4529  proj_info, target_ti.get_subtype(), target_ti.get_output_srid());
4530  } else {
4531  proj_info.col_type.precision = target_ti.get_precision();
4532  proj_info.col_type.scale = target_ti.get_scale();
4533  }
4534  if (target_ti.get_type() == kDATE) {
4535  proj_info.col_type.size = target_ti.get_size();
4536  }
4537  proj_info.col_type.comp_param =
4538  (target_ti.is_date_in_days() && target_ti.get_comp_param() == 0)
4539  ? 32
4540  : target_ti.get_comp_param();
4541  return proj_info;
4542 }
TDatumType::type type_to_thrift(const SQLTypeInfo &type_info)
std::string to_string(char const *&&v)
void fixup_geo_column_descriptor(TColumnType &col_type, const SQLTypes subtype, const int output_srid)
Definition: sqltypes.h:55
const std::string & get_resname() const
SQLTypes type
Definition: sqltypes.h:642
#define IS_GEO(T)
Definition: sqltypes.h:164
const SQLTypeInfo & get_type_info() const
TEncodingType::type encoding_to_thrift(const SQLTypeInfo &type_info)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ convert_target_metainfo() [2/2]

TRowDescriptor MapDHandler::convert_target_metainfo ( const std::vector< TargetMetaInfo > &  targets) const
private

Definition at line 4544 of file MapDHandler.cpp.

References convert_target_metainfo().

4545  {
4546  TRowDescriptor row_desc;
4547  size_t i = 0;
4548  for (const auto target : targets) {
4549  row_desc.push_back(convert_target_metainfo(target, i));
4550  ++i;
4551  }
4552  return row_desc;
4553 }
TColumnType convert_target_metainfo(const TargetMetaInfo &target, const size_t idx) const
+ Here is the call graph for this function:

◆ copyparams_to_thrift()

TCopyParams MapDHandler::copyparams_to_thrift ( const Importer_NS::CopyParams cp)
private

Definition at line 2540 of file MapDHandler.cpp.

References Importer_NS::CopyParams::array_begin, Importer_NS::CopyParams::array_delim, Importer_NS::CopyParams::array_end, Importer_NS::AUTODETECT, CHECK, Importer_NS::CopyParams::delimiter, Importer_NS::CopyParams::escape, Importer_NS::CopyParams::file_type, Importer_NS::CopyParams::geo_coords_comp_param, Importer_NS::CopyParams::geo_coords_encoding, Importer_NS::CopyParams::geo_coords_srid, Importer_NS::CopyParams::geo_coords_type, Importer_NS::CopyParams::geo_layer_name, Importer_NS::HAS_HEADER, Importer_NS::CopyParams::has_header, kENCODING_GEOINT, kGEOGRAPHY, kGEOMETRY, Importer_NS::CopyParams::line_delim, Importer_NS::NO_HEADER, NONE, Importer_NS::CopyParams::null_str, Importer_NS::POLYGON, Importer_NS::CopyParams::quote, Importer_NS::CopyParams::quoted, Importer_NS::CopyParams::s3_access_key, Importer_NS::CopyParams::s3_endpoint, Importer_NS::CopyParams::s3_region, Importer_NS::CopyParams::s3_secret_key, Importer_NS::CopyParams::sanitize_column_names, and Importer_NS::CopyParams::threads.

Referenced by detect_column_types(), and sql_execute().

2540  {
2541  TCopyParams copy_params;
2542  copy_params.delimiter = cp.delimiter;
2543  copy_params.null_str = cp.null_str;
2544  switch (cp.has_header) {
2546  copy_params.has_header = TImportHeaderRow::AUTODETECT;
2547  break;
2549  copy_params.has_header = TImportHeaderRow::NO_HEADER;
2550  break;
2552  copy_params.has_header = TImportHeaderRow::HAS_HEADER;
2553  break;
2554  default:
2555  CHECK(false);
2556  break;
2557  }
2558  copy_params.quoted = cp.quoted;
2559  copy_params.quote = cp.quote;
2560  copy_params.escape = cp.escape;
2561  copy_params.line_delim = cp.line_delim;
2562  copy_params.array_delim = cp.array_delim;
2563  copy_params.array_begin = cp.array_begin;
2564  copy_params.array_end = cp.array_end;
2565  copy_params.threads = cp.threads;
2566  copy_params.s3_access_key = cp.s3_access_key;
2567  copy_params.s3_secret_key = cp.s3_secret_key;
2568  copy_params.s3_region = cp.s3_region;
2569  copy_params.s3_endpoint = cp.s3_endpoint;
2570  switch (cp.file_type) {
2572  copy_params.file_type = TFileType::POLYGON;
2573  break;
2574  default:
2575  copy_params.file_type = TFileType::DELIMITED;
2576  break;
2577  }
2578  switch (cp.geo_coords_encoding) {
2579  case kENCODING_GEOINT:
2580  copy_params.geo_coords_encoding = TEncodingType::GEOINT;
2581  break;
2582  default:
2583  copy_params.geo_coords_encoding = TEncodingType::NONE;
2584  break;
2585  }
2586  copy_params.geo_coords_comp_param = cp.geo_coords_comp_param;
2587  switch (cp.geo_coords_type) {
2588  case kGEOGRAPHY:
2589  copy_params.geo_coords_type = TDatumType::GEOGRAPHY;
2590  break;
2591  case kGEOMETRY:
2592  copy_params.geo_coords_type = TDatumType::GEOMETRY;
2593  break;
2594  default:
2595  CHECK(false);
2596  break;
2597  }
2598  copy_params.geo_coords_srid = cp.geo_coords_srid;
2599  copy_params.sanitize_column_names = cp.sanitize_column_names;
2600  copy_params.geo_layer_name = cp.geo_layer_name;
2601  return copy_params;
2602 }
std::string null_str
Definition: Importer.h:100
SQLTypes geo_coords_type
Definition: Importer.h:128
EncodingType geo_coords_encoding
Definition: Importer.h:126
std::string s3_access_key
Definition: Importer.h:115
ImportHeaderRow has_header
Definition: Importer.h:101
std::string s3_endpoint
Definition: Importer.h:118
std::string s3_region
Definition: Importer.h:117
std::string geo_layer_name
Definition: Importer.h:131
#define CHECK(condition)
Definition: Logger.h:187
std::string s3_secret_key
Definition: Importer.h:116
int32_t geo_coords_comp_param
Definition: Importer.h:127
+ Here is the caller graph for this function:

◆ create_dashboard()

int32_t MapDHandler::create_dashboard ( const TSessionId &  session,
const std::string &  dashboard_name,
const std::string &  dashboard_state,
const std::string &  image_hash,
const std::string &  dashboard_metadata 
)
override

Definition at line 3051 of file MapDHandler.cpp.

References check_read_only(), AccessPrivileges::CREATE_DASHBOARD, DashboardDBObjectType, DashboardDescriptor::dashboardMetadata, DashboardDescriptor::dashboardName, DashboardDescriptor::dashboardState, get_session_copy(), DashboardDescriptor::imageHash, LOG_SESSION, THROW_MAPD_EXCEPTION, to_string(), DashboardDescriptor::user, and DashboardDescriptor::userId.

3055  {
3057  check_read_only("create_dashboard");
3058  const auto session_info = get_session_copy(session);
3059  auto& cat = session_info.getCatalog();
3060 
3061  if (!session_info.checkDBAccessPrivileges(DBObjectType::DashboardDBObjectType,
3063  THROW_MAPD_EXCEPTION("Not enough privileges to create a dashboard.");
3064  }
3065 
3066  auto dash = cat.getMetadataForDashboard(
3067  std::to_string(session_info.get_currentUser().userId), dashboard_name);
3068  if (dash) {
3069  THROW_MAPD_EXCEPTION("Dashboard with name: " + dashboard_name + " already exists.");
3070  }
3071 
3073  dd.dashboardName = dashboard_name;
3074  dd.dashboardState = dashboard_state;
3075  dd.imageHash = image_hash;
3076  dd.dashboardMetadata = dashboard_metadata;
3077  dd.userId = session_info.get_currentUser().userId;
3078  dd.user = session_info.get_currentUser().userName;
3079 
3080  try {
3081  auto id = cat.createDashboard(dd);
3082  // TODO: transactionally unsafe
3083  SysCatalog::instance().createDBObject(
3084  session_info.get_currentUser(), dashboard_name, DashboardDBObjectType, cat, id);
3085  return id;
3086  } catch (const std::exception& e) {
3087  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
3088  }
3089 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
static const AccessPrivileges CREATE_DASHBOARD
Definition: DBObject.h:163
std::string to_string(char const *&&v)
#define THROW_MAPD_EXCEPTION(errstr)
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
void check_read_only(const std::string &str)
TSessionId session
+ Here is the call graph for this function:

◆ create_geo_column()

TColumnType MapDHandler::create_geo_column ( const TDatumType::type  type,
const std::string &  name,
const bool  is_array 
)
private

Definition at line 3337 of file MapDHandler.cpp.

References run-benchmark-import::type.

3339  {
3340  TColumnType ct;
3341  ct.col_name = name;
3342  ct.col_type.type = type;
3343  ct.col_type.is_array = is_array;
3344  return ct;
3345 }

◆ create_link()

void MapDHandler::create_link ( std::string &  _return,
const TSessionId &  session,
const std::string &  view_state,
const std::string &  view_metadata 
)
override

Definition at line 3316 of file MapDHandler.cpp.

References get_session_copy(), LOG_SESSION, THROW_MAPD_EXCEPTION, LinkDescriptor::userId, LinkDescriptor::viewMetadata, and LinkDescriptor::viewState.

3319  {
3321  // check_read_only("create_link");
3322  const auto session_info = get_session_copy(session);
3323  auto& cat = session_info.getCatalog();
3324 
3325  LinkDescriptor ld;
3326  ld.userId = session_info.get_currentUser().userId;
3327  ld.viewState = view_state;
3328  ld.viewMetadata = view_metadata;
3329 
3330  try {
3331  _return = cat.createLink(ld, 6);
3332  } catch (const std::exception& e) {
3333  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
3334  }
3335 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
#define THROW_MAPD_EXCEPTION(errstr)
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
TSessionId session
+ Here is the call graph for this function:

◆ create_simple_result()

void MapDHandler::create_simple_result ( TQueryResult &  _return,
const ResultSet results,
const bool  column_format,
const std::string  label 
) const
private

Definition at line 4625 of file MapDHandler.cpp.

References CHECK, CHECK_EQ, and run-benchmark-import::label.

Referenced by convert_explain(), and convert_result().

4628  {
4629  CHECK_EQ(size_t(1), results.rowCount());
4630  TColumnType proj_info;
4631  proj_info.col_name = label;
4632  proj_info.col_type.type = TDatumType::STR;
4633  proj_info.col_type.nullable = false;
4634  proj_info.col_type.is_array = false;
4635  _return.row_set.row_desc.push_back(proj_info);
4636  const auto crt_row = results.getNextRow(true, true);
4637  const auto tv = crt_row[0];
4638  CHECK(results.getNextRow(true, true).empty());
4639  const auto scalar_tv = boost::get<ScalarTargetValue>(&tv);
4640  CHECK(scalar_tv);
4641  const auto s_n = boost::get<NullableString>(scalar_tv);
4642  CHECK(s_n);
4643  const auto s = boost::get<std::string>(s_n);
4644  CHECK(s);
4645  if (column_format) {
4646  TColumn tcol;
4647  tcol.data.str_col.push_back(*s);
4648  tcol.nulls.push_back(false);
4649  _return.row_set.is_columnar = true;
4650  _return.row_set.columns.push_back(tcol);
4651  } else {
4652  TDatum explanation;
4653  explanation.val.str_val = *s;
4654  explanation.is_null = false;
4655  TRow trow;
4656  trow.cols.push_back(explanation);
4657  _return.row_set.is_columnar = false;
4658  _return.row_set.rows.push_back(trow);
4659  }
4660 }
#define CHECK_EQ(x, y)
Definition: Logger.h:195
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the caller graph for this function:

◆ create_table()

void MapDHandler::create_table ( const TSessionId &  session,
const std::string &  table_name,
const TRowDescriptor &  row_desc,
const TFileType::type  file_type,
const TCreateParams &  create_params 
)
override

Definition at line 3368 of file MapDHandler.cpp.

References check_read_only(), ImportHelpers::is_reserved_name(), join(), kENCODING_DICT, kENCODING_FIXED, kENCODING_GEOINT, kENCODING_NONE, LOG_SESSION, ImportHelpers::sanitize_name(), sql_execute(), thrift_to_encoding(), thrift_to_encoding_name(), thrift_to_name(), THROW_MAPD_EXCEPTION, and to_string().

Referenced by import_geo_table().

3372  {
3373  // sql_execute() below also logs session info.
3374  LOG_SESSION(session, "table_name", table_name);
3375  check_read_only("create_table");
3376 
3377  if (ImportHelpers::is_reserved_name(table_name)) {
3378  THROW_MAPD_EXCEPTION("Invalid table name (reserved keyword): " + table_name);
3379  } else if (table_name != ImportHelpers::sanitize_name(table_name)) {
3380  THROW_MAPD_EXCEPTION("Invalid characters in table name: " + table_name);
3381  }
3382 
3383  auto rds = rd;
3384 
3385  // no longer need to manually add the poly column for a TFileType::POLYGON table
3386  // a column of the correct geo type has already been added
3387  // @TODO simon.eves rename TFileType::POLYGON to TFileType::GEO or something!
3388 
3389  std::string stmt{"CREATE TABLE " + table_name};
3390  std::vector<std::string> col_stmts;
3391 
3392  for (auto col : rds) {
3393  if (ImportHelpers::is_reserved_name(col.col_name)) {
3394  THROW_MAPD_EXCEPTION("Invalid column name (reserved keyword): " + col.col_name);
3395  } else if (col.col_name != ImportHelpers::sanitize_name(col.col_name)) {
3396  THROW_MAPD_EXCEPTION("Invalid characters in column name: " + col.col_name);
3397  }
3398  if (col.col_type.type == TDatumType::INTERVAL_DAY_TIME ||
3399  col.col_type.type == TDatumType::INTERVAL_YEAR_MONTH) {
3400  THROW_MAPD_EXCEPTION("Unsupported type: " + thrift_to_name(col.col_type) +
3401  " for column: " + col.col_name);
3402  }
3403 
3404  if (col.col_type.type == TDatumType::DECIMAL) {
3405  // if no precision or scale passed in set to default 14,7
3406  if (col.col_type.precision == 0 && col.col_type.scale == 0) {
3407  col.col_type.precision = 14;
3408  col.col_type.scale = 7;
3409  }
3410  }
3411 
3412  std::string col_stmt;
3413  col_stmt.append(col.col_name + " " + thrift_to_name(col.col_type));
3414 
3415  // As of 2016-06-27 the Immerse v1 frontend does not explicitly set the
3416  // `nullable` argument, leading this to default to false. Uncomment for v2.
3417  // if (!col.col_type.nullable) col_stmt.append(" NOT NULL");
3418 
3419  if (thrift_to_encoding(col.col_type.encoding) != kENCODING_NONE) {
3420  col_stmt.append(" ENCODING " + thrift_to_encoding_name(col.col_type));
3421  if (thrift_to_encoding(col.col_type.encoding) == kENCODING_DICT ||
3422  thrift_to_encoding(col.col_type.encoding) == kENCODING_FIXED ||
3423  thrift_to_encoding(col.col_type.encoding) == kENCODING_GEOINT) {
3424  col_stmt.append("(" + std::to_string(col.col_type.comp_param) + ")");
3425  }
3426  } else if (col.col_type.type == TDatumType::STR) {
3427  // non DICT encoded strings
3428  col_stmt.append(" ENCODING NONE");
3429  } else if (col.col_type.type == TDatumType::POINT ||
3430  col.col_type.type == TDatumType::LINESTRING ||
3431  col.col_type.type == TDatumType::POLYGON ||
3432  col.col_type.type == TDatumType::MULTIPOLYGON) {
3433  // non encoded compressable geo
3434  if (col.col_type.scale == 4326) {
3435  col_stmt.append(" ENCODING NONE");
3436  }
3437  }
3438  col_stmts.push_back(col_stmt);
3439  }
3440 
3441  stmt.append(" (" + boost::algorithm::join(col_stmts, ", ") + ")");
3442 
3443  if (create_params.is_replicated) {
3444  stmt.append(" WITH (PARTITIONS = 'REPLICATED')");
3445  }
3446 
3447  stmt.append(";");
3448 
3449  TQueryResult ret;
3450  sql_execute(ret, session, stmt, true, "", -1, -1);
3451 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
EncodingType thrift_to_encoding(const TEncodingType::type tEncodingType)
std::string join(T const &container, std::string const &delim)
std::string to_string(char const *&&v)
#define THROW_MAPD_EXCEPTION(errstr)
bool is_reserved_name(const std::string &name)
std::string sanitize_name(const std::string &name)
std::string thrift_to_encoding_name(const TTypeInfo &ti)
std::string thrift_to_name(const TTypeInfo &ti)
void check_read_only(const std::string &str)
void sql_execute(TQueryResult &_return, const TSessionId &session, const std::string &query, const bool column_format, const std::string &nonce, const int32_t first_n, const int32_t at_most_n) override
TSessionId session
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deallocate_df()

void MapDHandler::deallocate_df ( const TSessionId &  session,
const TDataFrame &  df,
const TDeviceType::type  device_type,
const int32_t  device_id 
)
override

Definition at line 913 of file MapDHandler.cpp.

References CPU, data_mgr_, ArrowResultSet::deallocateArrowResultBuffer(), logger::ERROR, get_session_copy(), GPU, handle_to_dev_ptr_mutex_, ipc_handle_to_dev_ptr_, LOG, LOG_SESSION, and run-benchmark-import::result.

916  {
918  const auto session_info = get_session_copy(session);
919  int8_t* dev_ptr{0};
920  if (device_type == TDeviceType::GPU) {
921  std::lock_guard<std::mutex> map_lock(handle_to_dev_ptr_mutex_);
922  if (ipc_handle_to_dev_ptr_.count(df.df_handle) != size_t(1)) {
923  TMapDException ex;
924  ex.error_msg = std::string(
925  "Exception: current data frame handle is not bookkept or been inserted twice");
926  LOG(ERROR) << ex.error_msg;
927  throw ex;
928  }
929  dev_ptr = ipc_handle_to_dev_ptr_[df.df_handle];
930  ipc_handle_to_dev_ptr_.erase(df.df_handle);
931  }
932  std::vector<char> sm_handle(df.sm_handle.begin(), df.sm_handle.end());
933  std::vector<char> df_handle(df.df_handle.begin(), df.df_handle.end());
934  ArrowResult result{sm_handle, df.sm_size, df_handle, df.df_size, dev_ptr};
936  result,
938  device_id,
939  data_mgr_);
940 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
#define LOG(tag)
Definition: Logger.h:182
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
static void deallocateArrowResultBuffer(const ArrowResult &result, const ExecutorDeviceType device_type, const size_t device_id, std::shared_ptr< Data_Namespace::DataMgr > &data_mgr)
std::shared_ptr< Data_Namespace::DataMgr > data_mgr_
Definition: MapDHandler.h:437
std::mutex handle_to_dev_ptr_mutex_
Definition: MapDHandler.h:685
TSessionId session
std::unordered_map< std::string, int8_t * > ipc_handle_to_dev_ptr_
Definition: MapDHandler.h:686
+ Here is the call graph for this function:

◆ delete_dashboard()

void MapDHandler::delete_dashboard ( const TSessionId &  session,
const int32_t  dashboard_id 
)
override

Definition at line 3129 of file MapDHandler.cpp.

References check_read_only(), AccessPrivileges::DELETE_DASHBOARD, get_session_copy(), is_allowed_on_dashboard(), LOG_SESSION, THROW_MAPD_EXCEPTION, and to_string().

3130  {
3132  check_read_only("delete_dashboard");
3133  const auto session_info = get_session_copy(session);
3134  auto& cat = session_info.getCatalog();
3135  auto dash = cat.getMetadataForDashboard(dashboard_id);
3136  if (!dash) {
3137  THROW_MAPD_EXCEPTION("Dashboard with id" + std::to_string(dashboard_id) +
3138  " doesn't exist, so cannot delete it");
3139  }
3141  session_info, dash->dashboardId, AccessPrivileges::DELETE_DASHBOARD)) {
3142  THROW_MAPD_EXCEPTION("Not enough privileges to delete a dashboard.");
3143  }
3144  try {
3145  cat.deleteMetadataForDashboard(dashboard_id);
3146  } catch (const std::exception& e) {
3147  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
3148  }
3149 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
std::string to_string(char const *&&v)
#define THROW_MAPD_EXCEPTION(errstr)
static bool is_allowed_on_dashboard(const Catalog_Namespace::SessionInfo &session_info, int32_t dashboard_id, AccessPrivileges requestedPermissions)
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
void check_read_only(const std::string &str)
static const AccessPrivileges DELETE_DASHBOARD
Definition: DBObject.h:166
TSessionId session
+ Here is the call graph for this function:

◆ detect_column_types()

void MapDHandler::detect_column_types ( TDetectResult &  _return,
const TSessionId &  session,
const std::string &  file_name,
const TCopyParams &  copy_params 
)
override

Definition at line 2749 of file MapDHandler.cpp.

References add_vsi_archive_prefix(), add_vsi_geo_prefix(), add_vsi_network_prefix(), Importer_NS::Detector::best_encodings, Importer_NS::Detector::best_sqltypes, check_geospatial_files(), check_read_only(), copyparams_to_thrift(), Importer_NS::DELIMITED, encoding_to_thrift(), Importer_NS::CopyParams::file_type, find_first_geo_file_in_archive(), Importer_NS::Importer::gdalFileExists(), Importer_NS::Importer::gdalFileOrDirectoryExists(), Importer_NS::Importer::gdalToColumnDescriptors(), Importer_NS::CopyParams::geo_coords_comp_param, Importer_NS::CopyParams::geo_coords_encoding, Importer_NS::CopyParams::geo_coords_srid, Importer_NS::CopyParams::geo_coords_type, Importer_NS::DataStreamSink::get_copy_params(), Importer_NS::Detector::get_headers(), Importer_NS::Detector::get_sample_rows(), get_session_copy(), import_path_, is_a_supported_archive_file(), is_a_supported_geo_file(), IS_GEO, ImportHelpers::is_reserved_name(), LOG_SESSION, OMNISCI_GEO_PREFIX, path_is_relative(), Importer_NS::POLYGON, populateThriftColumnType(), Importer_NS::Importer::readMetadataSampleGDAL(), Importer_NS::CopyParams::sanitize_column_names, ImportHelpers::sanitize_name(), SQLTypeInfoCore< TYPE_FACET_PACK >::set_compression(), thrift_to_copyparams(), THROW_MAPD_EXCEPTION, and type_to_thrift().

Referenced by import_geo_table().

2752  {
2754  check_read_only("detect_column_types");
2756 
2758 
2759  std::string file_name{file_name_in};
2760 
2761  if (path_is_relative(file_name)) {
2762  // assume relative paths are relative to data_path / mapd_import / <session>
2763  auto file_path = import_path_ / picosha2::hash256_hex_string(session) /
2764  boost::filesystem::path(file_name).filename();
2765  file_name = file_path.string();
2766  }
2767 
2768  // if it's a geo table, handle alternative paths (S3, HTTP, archive etc.)
2769  if (copy_params.file_type == Importer_NS::FileType::POLYGON) {
2770  if (is_a_supported_geo_file(file_name, true)) {
2771  // prepare to detect geo file directly
2772  add_vsi_network_prefix(file_name);
2773  add_vsi_geo_prefix(file_name);
2774  } else if (is_a_supported_archive_file(file_name)) {
2775  // find the archive file
2776  add_vsi_network_prefix(file_name);
2777  if (!Importer_NS::Importer::gdalFileExists(file_name, copy_params)) {
2778  THROW_MAPD_EXCEPTION("Archive does not exist: " + file_name_in);
2779  }
2780  // find geo file in archive
2781  add_vsi_archive_prefix(file_name);
2782  std::string geo_file = find_first_geo_file_in_archive(file_name, copy_params);
2783  // prepare to detect that geo file
2784  if (geo_file.size()) {
2785  file_name = file_name + std::string("/") + geo_file;
2786  }
2787  } else {
2788  THROW_MAPD_EXCEPTION("File is not a supported geo or geo archive format: " +
2789  file_name_in);
2790  }
2791  }
2792 
2793  auto file_path = boost::filesystem::path(file_name);
2794  // can be a s3 url
2795  if (!boost::istarts_with(file_name, "s3://")) {
2796  if (!boost::filesystem::path(file_name).is_absolute()) {
2797  file_path = import_path_ / picosha2::hash256_hex_string(session) /
2798  boost::filesystem::path(file_name).filename();
2799  file_name = file_path.string();
2800  }
2801 
2802  if (copy_params.file_type == Importer_NS::FileType::POLYGON) {
2803  // check for geo file
2804  if (!Importer_NS::Importer::gdalFileOrDirectoryExists(file_name, copy_params)) {
2805  THROW_MAPD_EXCEPTION("File does not exist: " + file_path.string());
2806  }
2807  } else {
2808  // check for regular file
2809  if (!boost::filesystem::exists(file_path)) {
2810  THROW_MAPD_EXCEPTION("File does not exist: " + file_path.string());
2811  }
2812  }
2813  }
2814  try {
2815  if (copy_params.file_type == Importer_NS::FileType::DELIMITED
2816 #ifdef ENABLE_IMPORT_PARQUET
2817  || (copy_params.file_type == Importer_NS::FileType::PARQUET)
2818 #endif
2819  ) {
2820  Importer_NS::Detector detector(file_path, copy_params);
2821  std::vector<SQLTypes> best_types = detector.best_sqltypes;
2822  std::vector<EncodingType> best_encodings = detector.best_encodings;
2823  std::vector<std::string> headers = detector.get_headers();
2824  copy_params = detector.get_copy_params();
2825 
2826  _return.copy_params = copyparams_to_thrift(copy_params);
2827  _return.row_set.row_desc.resize(best_types.size());
2828  for (size_t col_idx = 0; col_idx < best_types.size(); col_idx++) {
2829  TColumnType col;
2830  SQLTypes t = best_types[col_idx];
2831  EncodingType encodingType = best_encodings[col_idx];
2832  SQLTypeInfo ti(t, false, encodingType);
2833  if (IS_GEO(t)) {
2834  // set this so encoding_to_thrift does the right thing
2835  ti.set_compression(copy_params.geo_coords_encoding);
2836  // fill in these directly
2837  col.col_type.precision = static_cast<int>(copy_params.geo_coords_type);
2838  col.col_type.scale = copy_params.geo_coords_srid;
2839  col.col_type.comp_param = copy_params.geo_coords_comp_param;
2840  }
2841  col.col_type.type = type_to_thrift(ti);
2842  col.col_type.encoding = encoding_to_thrift(ti);
2843  if (copy_params.sanitize_column_names) {
2844  col.col_name = ImportHelpers::sanitize_name(headers[col_idx]);
2845  } else {
2846  col.col_name = headers[col_idx];
2847  }
2848  col.is_reserved_keyword = ImportHelpers::is_reserved_name(col.col_name);
2849  _return.row_set.row_desc[col_idx] = col;
2850  }
2851  size_t num_samples = 100;
2852  auto sample_data = detector.get_sample_rows(num_samples);
2853 
2854  TRow sample_row;
2855  for (auto row : sample_data) {
2856  sample_row.cols.clear();
2857  for (const auto& s : row) {
2858  TDatum td;
2859  td.val.str_val = s;
2860  td.is_null = s.empty();
2861  sample_row.cols.push_back(td);
2862  }
2863  _return.row_set.rows.push_back(sample_row);
2864  }
2865  } else if (copy_params.file_type == Importer_NS::FileType::POLYGON) {
2866  // @TODO simon.eves get this from somewhere!
2867  const std::string geoColumnName(OMNISCI_GEO_PREFIX);
2868 
2869  check_geospatial_files(file_path, copy_params);
2870  std::list<ColumnDescriptor> cds = Importer_NS::Importer::gdalToColumnDescriptors(
2871  file_path.string(), geoColumnName, copy_params);
2872  for (auto cd : cds) {
2873  if (copy_params.sanitize_column_names) {
2874  cd.columnName = ImportHelpers::sanitize_name(cd.columnName);
2875  }
2876  _return.row_set.row_desc.push_back(populateThriftColumnType(nullptr, &cd));
2877  }
2878  std::map<std::string, std::vector<std::string>> sample_data;
2880  file_path.string(), geoColumnName, sample_data, 100, copy_params);
2881  if (sample_data.size() > 0) {
2882  for (size_t i = 0; i < sample_data.begin()->second.size(); i++) {
2883  TRow sample_row;
2884  for (auto cd : cds) {
2885  TDatum td;
2886  td.val.str_val = sample_data[cd.sourceName].at(i);
2887  td.is_null = td.val.str_val.empty();
2888  sample_row.cols.push_back(td);
2889  }
2890  _return.row_set.rows.push_back(sample_row);
2891  }
2892  }
2893  _return.copy_params = copyparams_to_thrift(copy_params);
2894  }
2895  } catch (const std::exception& e) {
2896  THROW_MAPD_EXCEPTION("detect_column_types error: " + std::string(e.what()));
2897  }
2898 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
TColumnType populateThriftColumnType(const Catalog_Namespace::Catalog *cat, const ColumnDescriptor *cd)
void add_vsi_network_prefix(std::string &path)
TDatumType::type type_to_thrift(const SQLTypeInfo &type_info)
SQLTypes
Definition: sqltypes.h:40
EncodingType
Definition: encodetypes.h:22
boost::filesystem::path import_path_
Definition: MapDHandler.h:442
void add_vsi_archive_prefix(std::string &path)
SQLTypes geo_coords_type
Definition: Importer.h:128
void add_vsi_geo_prefix(std::string &path)
#define THROW_MAPD_EXCEPTION(errstr)
EncodingType geo_coords_encoding
Definition: Importer.h:126
static bool gdalFileOrDirectoryExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:4372
TCopyParams copyparams_to_thrift(const Importer_NS::CopyParams &cp)
static const std::list< ColumnDescriptor > gdalToColumnDescriptors(const std::string &fileName, const std::string &geoColumnName, const CopyParams &copy_params)
Definition: Importer.cpp:4265
bool is_reserved_name(const std::string &name)
bool is_a_supported_geo_file(const std::string &path, bool include_gz)
std::string sanitize_name(const std::string &name)
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
bool path_is_relative(const std::string &path)
static bool gdalFileExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:4367
static void readMetadataSampleGDAL(const std::string &fileName, const std::string &geoColumnName, std::map< std::string, std::vector< std::string >> &metadata, int rowLimit, const CopyParams &copy_params)
Definition: Importer.cpp:4144
void check_geospatial_files(const boost::filesystem::path file_path, const Importer_NS::CopyParams &copy_params)
std::string find_first_geo_file_in_archive(const std::string &archive_path, const Importer_NS::CopyParams &copy_params)
void check_read_only(const std::string &str)
Importer_NS::CopyParams thrift_to_copyparams(const TCopyParams &cp)
TSessionId session
#define IS_GEO(T)
Definition: sqltypes.h:164
bool is_a_supported_archive_file(const std::string &path)
int32_t geo_coords_comp_param
Definition: Importer.h:127
const std::string OMNISCI_GEO_PREFIX
Definition: geosupport.h:23
TEncodingType::type encoding_to_thrift(const SQLTypeInfo &type_info)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ disconnect()

void MapDHandler::disconnect ( const TSessionId &  session)
override

Definition at line 383 of file MapDHandler.cpp.

References disconnect_impl(), get_session_it_unsafe(), logger::INFO, LOG, LOG_SESSION, and sessions_mutex_.

383  {
385  mapd_lock_guard<mapd_shared_mutex> write_lock(sessions_mutex_);
386  auto session_it = get_session_it_unsafe(session);
387  const auto dbname = session_it->second->getCatalog().getCurrentDB().dbName;
388  LOG(INFO) << "User " << session_it->second->get_currentUser().userName
389  << " disconnected from database " << dbname << std::endl;
390  disconnect_impl(session_it);
391 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
SessionMap::iterator get_session_it_unsafe(const TSessionId &session)
#define LOG(tag)
Definition: Logger.h:182
mapd_shared_mutex sessions_mutex_
Definition: MapDHandler.h:452
void disconnect_impl(const SessionMap::iterator &session_it)
TSessionId session
+ Here is the call graph for this function:

◆ disconnect_impl()

void MapDHandler::disconnect_impl ( const SessionMap::iterator &  session_it)
private

Definition at line 393 of file MapDHandler.cpp.

References LeafAggregator::disconnect(), leaf_aggregator_, LeafAggregator::leafCount(), render_handler_, and sessions_.

Referenced by check_session_exp_unsafe(), and disconnect().

393  {
394  // session_it existence should already have been checked (i.e. called via
395  // get_session_it_unsafe(...))
396  const auto session_id = session_it->second->get_session_id();
397  if (leaf_aggregator_.leafCount() > 0) {
398  leaf_aggregator_.disconnect(session_id);
399  }
400  if (render_handler_) {
401  render_handler_->disconnect(session_id);
402  }
403  sessions_.erase(session_it);
404 }
SessionMap sessions_
Definition: MapDHandler.h:669
std::unique_ptr< MapDRenderHandler > render_handler_
Definition: MapDHandler.h:457
void disconnect(const TSessionId session)
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:439
size_t leafCount() const
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ emergency_shutdown()

void MapDHandler::emergency_shutdown ( )

Definition at line 5546 of file MapDHandler.cpp.

References calcite_, and LogSession::s_match.

Referenced by shutdown().

5546  {
5547  if (calcite_) {
5548  calcite_->close_calcite_server(false);
5549  }
5550 }
std::shared_ptr< Calcite > calcite_
Definition: MapDHandler.h:460
+ Here is the caller graph for this function:

◆ execute_distributed_copy_statement()

void MapDHandler::execute_distributed_copy_statement ( Parser::CopyTableStmt copy_stmt,
const Catalog_Namespace::SessionInfo session_info 
)
private

Definition at line 5156 of file MapDHandler.cpp.

References Parser::CopyTableStmt::execute(), and leaf_aggregator_.

Referenced by sql_execute_impl().

5158  {
5159  auto importer_factory = [&session_info, this](
5160  const Catalog& catalog,
5161  const TableDescriptor* td,
5162  const std::string& file_path,
5163  const Importer_NS::CopyParams& copy_params) {
5164  return boost::make_unique<Importer_NS::Importer>(
5165  new DistributedLoader(session_info, td, &leaf_aggregator_),
5166  file_path,
5167  copy_params);
5168  };
5169  copy_stmt->execute(session_info, importer_factory);
5170 }
class for a per-database catalog. also includes metadata for the current database and the current use...
Definition: Catalog.h:81
void execute(const Catalog_Namespace::SessionInfo &session) override
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:439
specifies the content in-memory of a row in the table metadata table
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ execute_first_step()

void MapDHandler::execute_first_step ( TStepResult &  _return,
const TPendingQuery &  pending_query 
)
override

Definition at line 5280 of file MapDHandler.cpp.

References measure< TimeT >::execution(), logger::INFO, leaf_handler_, LOG, and THROW_MAPD_EXCEPTION.

5281  {
5282  if (!leaf_handler_) {
5283  THROW_MAPD_EXCEPTION("Distributed support is disabled.");
5284  }
5285  LOG(INFO) << "execute_first_step : id:" << pending_query.id;
5286  auto time_ms = measure<>::execution([&]() {
5287  try {
5288  leaf_handler_->execute_first_step(_return, pending_query);
5289  } catch (std::exception& e) {
5290  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
5291  }
5292  });
5293  LOG(INFO) << "execute_first_step-COMPLETED " << time_ms << "ms";
5294 }
#define LOG(tag)
Definition: Logger.h:182
#define THROW_MAPD_EXCEPTION(errstr)
std::unique_ptr< MapDLeafHandler > leaf_handler_
Definition: MapDHandler.h:459
static TimeT::rep execution(F func, Args &&... args)
Definition: sample.cpp:29
+ Here is the call graph for this function:

◆ execute_next_render_step()

void MapDHandler::execute_next_render_step ( TRenderStepResult &  _return,
const TPendingRenderQuery &  pending_render,
const TRenderAggDataMap &  merged_data 
)
override

Definition at line 5425 of file MapDHandler.cpp.

References measure< TimeT >::execution(), logger::INFO, LOG, render_handler_, and THROW_MAPD_EXCEPTION.

5427  {
5428  if (!render_handler_) {
5429  THROW_MAPD_EXCEPTION("Backend rendering is disabled.");
5430  }
5431 
5432  LOG(INFO) << "execute_next_render_step: id:" << pending_render.id;
5433  auto time_ms = measure<>::execution([&]() {
5434  try {
5435  render_handler_->execute_next_render_step(_return, pending_render, merged_data);
5436  } catch (std::exception& e) {
5437  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
5438  }
5439  });
5440  LOG(INFO) << "execute_next_render_step-COMPLETED id: " << pending_render.id
5441  << ", time: " << time_ms << "ms ";
5442 }
std::unique_ptr< MapDRenderHandler > render_handler_
Definition: MapDHandler.h:457
#define LOG(tag)
Definition: Logger.h:182
#define THROW_MAPD_EXCEPTION(errstr)
static TimeT::rep execution(F func, Args &&... args)
Definition: sample.cpp:29
+ Here is the call graph for this function:

◆ execute_rel_alg()

std::vector< PushedDownFilterInfo > MapDHandler::execute_rel_alg ( TQueryResult &  _return,
const std::string &  query_ra,
const bool  column_format,
const Catalog_Namespace::SessionInfo session_info,
const ExecutorDeviceType  executor_device_type,
const int32_t  first_n,
const int32_t  at_most_n,
const bool  just_explain,
const bool  just_validate,
const bool  find_push_down_candidates,
const bool  just_calcite_explain,
const bool  explain_optimized_ir 
) const
private

Definition at line 4329 of file MapDHandler.cpp.

References allow_loop_joins_, allow_multifrag_, convert_explain(), convert_rows(), CPU, Default, measure< TimeT >::execution(), g_dynamic_watchdog_time_limit, g_enable_columnar_output, g_enable_dynamic_watchdog, g_enable_watchdog, Catalog_Namespace::SessionInfo::getCatalog(), Executor::getExecutor(), MapDParameters::gpu_input_mem_limit, INJECT_TIMER, intel_jit_profile_, jit_debug_, mapd_parameters_, Optimized, and run-benchmark-import::result.

Referenced by execute_rel_alg_with_filter_push_down(), get_table_details_impl(), get_tables_meta(), sql_execute_impl(), and validate_rel_alg().

4341  {
4343  const auto& cat = session_info.getCatalog();
4344  CompilationOptions co = {executor_device_type,
4345  true,
4348  explain_optimized_ir ? ExecutorExplainType::Optimized
4353  just_explain,
4354  allow_loop_joins_ || just_validate,
4356  jit_debug_,
4357  just_validate,
4360  find_push_down_candidates,
4361  just_calcite_explain,
4363  auto executor = Executor::getExecutor(cat.getCurrentDB().dbId,
4364  jit_debug_ ? "/tmp" : "",
4365  jit_debug_ ? "mapdquery" : "",
4367  nullptr);
4368  RelAlgExecutor ra_executor(executor.get(), cat);
4369  ExecutionResult result{std::make_shared<ResultSet>(std::vector<TargetInfo>{},
4372  nullptr,
4373  nullptr),
4374  {}};
4375  _return.execution_time_ms += measure<>::execution(
4376  [&]() { result = ra_executor.executeRelAlgQuery(query_ra, co, eo, nullptr); });
4377  // reduce execution time by the time spent during queue waiting
4378  _return.execution_time_ms -= result.getRows()->getQueueTime();
4379  const auto& filter_push_down_info = result.getPushedDownFilterInfo();
4380  if (!filter_push_down_info.empty()) {
4381  return filter_push_down_info;
4382  }
4383  if (just_explain) {
4384  convert_explain(_return, *result.getRows(), column_format);
4385  } else if (!just_calcite_explain) {
4386  convert_rows(_return,
4387  result.getTargetsMeta(),
4388  *result.getRows(),
4389  column_format,
4390  first_n,
4391  at_most_n);
4392  }
4393  return {};
4394 }
const bool allow_loop_joins_
Definition: MapDHandler.h:450
static std::shared_ptr< Executor > getExecutor(const int db_id, const std::string &debug_dir="", const std::string &debug_file="", const MapDParameters mapd_parameters=MapDParameters(), ::QueryRenderer::QueryRenderManager *render_manager=nullptr)
Definition: Execute.cpp:122
const bool intel_jit_profile_
Definition: MapDHandler.h:447
bool g_enable_dynamic_watchdog
Definition: Execute.cpp:70
std::vector< PushedDownFilterInfo > execute_rel_alg(TQueryResult &_return, const std::string &query_ra, const bool column_format, const Catalog_Namespace::SessionInfo &session_info, const ExecutorDeviceType executor_device_type, const int32_t first_n, const int32_t at_most_n, const bool just_explain, const bool just_validate, const bool find_push_down_candidates, const bool just_calcite_explain, const bool explain_optimized_ir) const
const MapDParameters & mapd_parameters_
Definition: MapDHandler.h:456
bool g_enable_columnar_output
Definition: Execute.cpp:84
bool allow_multifrag_
Definition: MapDHandler.h:448
#define INJECT_TIMER(DESC)
Definition: measure.h:91
Catalog & getCatalog() const
Definition: SessionInfo.h:90
void convert_explain(TQueryResult &_return, const ResultSet &results, const bool column_format) const
double gpu_input_mem_limit
bool g_enable_watchdog
Definition: Execute.cpp:69
static TimeT::rep execution(F func, Args &&... args)
Definition: sample.cpp:29
void convert_rows(TQueryResult &_return, const std::vector< TargetMetaInfo > &targets, const R &results, const bool column_format, const int32_t first_n, const int32_t at_most_n) const
unsigned g_dynamic_watchdog_time_limit
Definition: Execute.cpp:71
const bool jit_debug_
Definition: MapDHandler.h:446
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ execute_rel_alg_df()

void MapDHandler::execute_rel_alg_df ( TDataFrame &  _return,
const std::string &  query_ra,
const Catalog_Namespace::SessionInfo session_info,
const ExecutorDeviceType  device_type,
const size_t  device_id,
const int32_t  first_n 
) const
private

Definition at line 4396 of file MapDHandler.cpp.

References allow_loop_joins_, allow_multifrag_, CHECK, CPU, data_mgr_, Default, g_dynamic_watchdog_time_limit, g_enable_dynamic_watchdog, g_enable_watchdog, Catalog_Namespace::SessionInfo::get_executor_device_type(), Catalog_Namespace::SessionInfo::getCatalog(), Executor::getExecutor(), getTargetNames(), GPU, MapDParameters::gpu_input_mem_limit, handle_to_dev_ptr_mutex_, intel_jit_profile_, ipc_handle_to_dev_ptr_, jit_debug_, mapd_parameters_, and run-benchmark-import::result.

Referenced by sql_execute_df().

4401  {
4402  const auto& cat = session_info.getCatalog();
4403  CHECK(device_type == ExecutorDeviceType::CPU ||
4405  CompilationOptions co = {session_info.get_executor_device_type(),
4406  true,
4411  ExecutionOptions eo = {false,
4413  false,
4416  jit_debug_,
4417  false,
4420  false,
4421  false,
4423  auto executor = Executor::getExecutor(cat.getCurrentDB().dbId,
4424  jit_debug_ ? "/tmp" : "",
4425  jit_debug_ ? "mapdquery" : "",
4427  nullptr);
4428  RelAlgExecutor ra_executor(executor.get(), cat);
4429  const auto result = ra_executor.executeRelAlgQuery(query_ra, co, eo, nullptr);
4430  const auto rs = result.getRows();
4431  const auto converter =
4432  std::make_unique<ArrowResultSetConverter>(rs,
4433  data_mgr_,
4434  device_type,
4435  device_id,
4436  getTargetNames(result.getTargetsMeta()),
4437  first_n);
4438  const auto copy = converter->getArrowResult();
4439  _return.sm_handle = std::string(copy.sm_handle.begin(), copy.sm_handle.end());
4440  _return.sm_size = copy.sm_size;
4441  _return.df_handle = std::string(copy.df_handle.begin(), copy.df_handle.end());
4442  if (device_type == ExecutorDeviceType::GPU) {
4443  std::lock_guard<std::mutex> map_lock(handle_to_dev_ptr_mutex_);
4444  CHECK(!ipc_handle_to_dev_ptr_.count(_return.df_handle));
4445  ipc_handle_to_dev_ptr_.insert(std::make_pair(_return.df_handle, copy.df_dev_ptr));
4446  }
4447  _return.df_size = copy.df_size;
4448 }
const bool allow_loop_joins_
Definition: MapDHandler.h:450
static std::shared_ptr< Executor > getExecutor(const int db_id, const std::string &debug_dir="", const std::string &debug_file="", const MapDParameters mapd_parameters=MapDParameters(), ::QueryRenderer::QueryRenderManager *render_manager=nullptr)
Definition: Execute.cpp:122
const bool intel_jit_profile_
Definition: MapDHandler.h:447
bool g_enable_dynamic_watchdog
Definition: Execute.cpp:70
const MapDParameters & mapd_parameters_
Definition: MapDHandler.h:456
bool allow_multifrag_
Definition: MapDHandler.h:448
Catalog & getCatalog() const
Definition: SessionInfo.h:90
std::shared_ptr< Data_Namespace::DataMgr > data_mgr_
Definition: MapDHandler.h:437
std::vector< std::string > getTargetNames(const std::vector< TargetMetaInfo > &targets) const
double gpu_input_mem_limit
#define CHECK(condition)
Definition: Logger.h:187
bool g_enable_watchdog
Definition: Execute.cpp:69
std::mutex handle_to_dev_ptr_mutex_
Definition: MapDHandler.h:685
unsigned g_dynamic_watchdog_time_limit
Definition: Execute.cpp:71
const bool jit_debug_
Definition: MapDHandler.h:446
const ExecutorDeviceType get_executor_device_type() const
Definition: SessionInfo.h:94
std::unordered_map< std::string, int8_t * > ipc_handle_to_dev_ptr_
Definition: MapDHandler.h:686
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ execute_rel_alg_with_filter_push_down()

void MapDHandler::execute_rel_alg_with_filter_push_down ( TQueryResult &  _return,
std::string &  query_ra,
const bool  column_format,
const Catalog_Namespace::SessionInfo session_info,
const ExecutorDeviceType  executor_device_type,
const int32_t  first_n,
const int32_t  at_most_n,
const bool  just_explain,
const bool  just_calcite_explain,
const std::string &  query_str,
const std::vector< PushedDownFilterInfo filter_push_down_requests 
)
private

Definition at line 5108 of file MapDHandler.cpp.

References convert_explain(), execute_rel_alg(), measure< TimeT >::execution(), mapd_parameters_, and parse_to_ra().

Referenced by sql_execute_impl().

5119  {
5120  // collecting the selected filters' info to be sent to Calcite:
5121  std::vector<TFilterPushDownInfo> filter_push_down_info;
5122  for (const auto& req : filter_push_down_requests) {
5123  TFilterPushDownInfo filter_push_down_info_for_request;
5124  filter_push_down_info_for_request.input_prev = req.input_prev;
5125  filter_push_down_info_for_request.input_start = req.input_start;
5126  filter_push_down_info_for_request.input_next = req.input_next;
5127  filter_push_down_info.push_back(filter_push_down_info_for_request);
5128  }
5129  // deriving the new relational algebra plan with respect to the pushed down filters
5130  _return.execution_time_ms += measure<>::execution([&]() {
5131  query_ra = parse_to_ra(
5132  query_str, filter_push_down_info, session_info, boost::none, mapd_parameters_);
5133  });
5134 
5135  if (just_calcite_explain) {
5136  // return the new ra as the result
5137  convert_explain(_return, ResultSet(query_ra), true);
5138  return;
5139  }
5140 
5141  // execute the new relational algebra plan:
5142  execute_rel_alg(_return,
5143  query_ra,
5144  column_format,
5145  session_info,
5146  executor_device_type,
5147  first_n,
5148  at_most_n,
5149  just_explain,
5150  /*just_validate = */ false,
5151  /*find_push_down_candidates = */ false,
5152  /*just_calcite_explain = */ false,
5153  /*TODO: explain optimized*/ false);
5154 }
std::string parse_to_ra(const std::string &query_str, const std::vector< TFilterPushDownInfo > &filter_push_down_info, const Catalog_Namespace::SessionInfo &session_info, OptionalTableMap tableNames, const MapDParameters mapd_parameters, RenderInfo *render_info=nullptr)
std::vector< PushedDownFilterInfo > execute_rel_alg(TQueryResult &_return, const std::string &query_ra, const bool column_format, const Catalog_Namespace::SessionInfo &session_info, const ExecutorDeviceType executor_device_type, const int32_t first_n, const int32_t at_most_n, const bool just_explain, const bool just_validate, const bool find_push_down_candidates, const bool just_calcite_explain, const bool explain_optimized_ir) const
const MapDParameters & mapd_parameters_
Definition: MapDHandler.h:456
void convert_explain(TQueryResult &_return, const ResultSet &results, const bool column_format) const
static TimeT::rep execution(F func, Args &&... args)
Definition: sample.cpp:29
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ execute_root_plan()

void MapDHandler::execute_root_plan ( TQueryResult &  _return,
const Planner::RootPlan root_plan,
const bool  column_format,
const Catalog_Namespace::SessionInfo session_info,
const ExecutorDeviceType  executor_device_type,
const int32_t  first_n 
) const
private

Definition at line 4450 of file MapDHandler.cpp.

References allow_loop_joins_, allow_multifrag_, CHECK, convert_explain(), convert_rows(), Catalog_Namespace::DBMetadata::dbId, Default, measure< TimeT >::execution(), Planner::RootPlan::get_plan(), Planner::RootPlan::get_plan_dest(), Planner::RootPlan::getCatalog(), Catalog_Namespace::Catalog::getCurrentDB(), Executor::getExecutor(), getTargetMetaInfo(), jit_debug_, mapd_parameters_, and render_handler_.

Referenced by sql_execute_impl().

4455  {
4456  auto executor = Executor::getExecutor(
4457  root_plan->getCatalog().getCurrentDB().dbId,
4458  jit_debug_ ? "/tmp" : "",
4459  jit_debug_ ? "mapdquery" : "",
4461  render_handler_ ? render_handler_->get_render_manager() : nullptr);
4462  std::shared_ptr<ResultSet> results;
4463  _return.execution_time_ms += measure<>::execution([&]() {
4464  results = executor->execute(root_plan,
4465  session_info,
4466  true,
4467  executor_device_type,
4471  });
4472  // reduce execution time by the time spent during queue waiting
4473  _return.execution_time_ms -= results->getQueueTime();
4474  if (root_plan->get_plan_dest() == Planner::RootPlan::Dest::kEXPLAIN) {
4475  convert_explain(_return, *results, column_format);
4476  return;
4477  }
4478  const auto plan = root_plan->get_plan();
4479  CHECK(plan);
4480  const auto& targets = plan->get_targetlist();
4481  convert_rows(_return, getTargetMetaInfo(targets), *results, column_format, -1, -1);
4482 }
const bool allow_loop_joins_
Definition: MapDHandler.h:450
std::vector< TargetMetaInfo > getTargetMetaInfo(const std::vector< std::shared_ptr< Analyzer::TargetEntry >> &targets) const
std::unique_ptr< MapDRenderHandler > render_handler_
Definition: MapDHandler.h:457
static std::shared_ptr< Executor > getExecutor(const int db_id, const std::string &debug_dir="", const std::string &debug_file="", const MapDParameters mapd_parameters=MapDParameters(), ::QueryRenderer::QueryRenderManager *render_manager=nullptr)
Definition: Execute.cpp:122
const MapDParameters & mapd_parameters_
Definition: MapDHandler.h:456
bool allow_multifrag_
Definition: MapDHandler.h:448
const Catalog_Namespace::Catalog & getCatalog() const
Definition: Planner.h:293
const DBMetadata & getCurrentDB() const
Definition: Catalog.h:176
const Plan * get_plan() const
Definition: Planner.h:289
void convert_explain(TQueryResult &_return, const ResultSet &results, const bool column_format) const
#define CHECK(condition)
Definition: Logger.h:187
static TimeT::rep execution(F func, Args &&... args)
Definition: sample.cpp:29
void convert_rows(TQueryResult &_return, const std::vector< TargetMetaInfo > &targets, const R &results, const bool column_format, const int32_t first_n, const int32_t at_most_n) const
const bool jit_debug_
Definition: MapDHandler.h:446
Dest get_plan_dest() const
Definition: Planner.h:299
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fill_column_names_by_table()

std::unordered_map< std::string, std::unordered_set< std::string > > MapDHandler::fill_column_names_by_table ( const std::vector< std::string > &  table_names,
const TSessionId &  session 
)
private

Definition at line 1113 of file MapDHandler.cpp.

References get_table_details().

Referenced by get_token_based_completions().

1114  {
1115  std::unordered_map<std::string, std::unordered_set<std::string>> column_names_by_table;
1116  for (const auto& table_name : table_names) {
1117  TTableDetails table_details;
1118  get_table_details(table_details, session, table_name);
1119  for (const auto& column_type : table_details.row_desc) {
1120  column_names_by_table[table_name].emplace(column_type.col_name);
1121  }
1122  }
1123  return column_names_by_table;
1124 }
void get_table_details(TTableDetails &_return, const TSessionId &session, const std::string &table_name) override
TSessionId session
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fixup_row_descriptor()

TRowDescriptor MapDHandler::fixup_row_descriptor ( const TRowDescriptor &  row_desc,
const Catalog_Namespace::Catalog cat 
)
private

Definition at line 4609 of file MapDHandler.cpp.

References DictDescriptor::dictNBits, and Catalog_Namespace::Catalog::getMetadataForDict().

Referenced by get_table_details_impl(), and validate_rel_alg().

4610  {
4611  TRowDescriptor fixedup_row_desc;
4612  for (const TColumnType& col_desc : row_desc) {
4613  auto fixedup_col_desc = col_desc;
4614  if (col_desc.col_type.encoding == TEncodingType::DICT &&
4615  col_desc.col_type.comp_param > 0) {
4616  const auto dd = cat.getMetadataForDict(col_desc.col_type.comp_param, false);
4617  fixedup_col_desc.col_type.comp_param = dd->dictNBits;
4618  }
4619  fixedup_row_desc.push_back(fixedup_col_desc);
4620  }
4621  return fixedup_row_desc;
4622 }
const DictDescriptor * getMetadataForDict(int dict_ref, bool loadDict=true) const
Definition: Catalog.cpp:1348
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_all_files_in_archive()

void MapDHandler::get_all_files_in_archive ( std::vector< std::string > &  _return,
const TSessionId &  session,
const std::string &  archive_path,
const TCopyParams &  copy_params 
)
override

Definition at line 4055 of file MapDHandler.cpp.

References add_vsi_archive_prefix(), add_vsi_network_prefix(), Importer_NS::Importer::gdalFileExists(), Importer_NS::Importer::gdalGetAllFilesInArchive(), import_path_, is_a_supported_archive_file(), LOG_SESSION, path_is_relative(), thrift_to_copyparams(), and THROW_MAPD_EXCEPTION.

4058  {
4059  LOG_SESSION(session, "get_all_files_in_archive", archive_path_in);
4060  std::string archive_path(archive_path_in);
4061 
4062  if (path_is_relative(archive_path)) {
4063  // assume relative paths are relative to data_path / mapd_import / <session>
4064  auto file_path = import_path_ / picosha2::hash256_hex_string(session) /
4065  boost::filesystem::path(archive_path).filename();
4066  archive_path = file_path.string();
4067  }
4068 
4069  if (is_a_supported_archive_file(archive_path)) {
4070  // find the archive file
4071  add_vsi_network_prefix(archive_path);
4072  if (!Importer_NS::Importer::gdalFileExists(archive_path,
4073  thrift_to_copyparams(copy_params))) {
4074  THROW_MAPD_EXCEPTION("Archive does not exist: " + archive_path_in);
4075  }
4076  // find all files in archive
4077  add_vsi_archive_prefix(archive_path);
4079  archive_path, thrift_to_copyparams(copy_params));
4080  // prepend them all with original path
4081  for (auto& s : _return) {
4082  s = archive_path_in + std::string("/") + s;
4083  }
4084  }
4085 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
void add_vsi_network_prefix(std::string &path)
boost::filesystem::path import_path_
Definition: MapDHandler.h:442
void add_vsi_archive_prefix(std::string &path)
#define THROW_MAPD_EXCEPTION(errstr)
bool path_is_relative(const std::string &path)
static bool gdalFileExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:4367
Importer_NS::CopyParams thrift_to_copyparams(const TCopyParams &cp)
TSessionId session
bool is_a_supported_archive_file(const std::string &path)
static std::vector< std::string > gdalGetAllFilesInArchive(const std::string &archive_path, const CopyParams &copy_params)
Definition: Importer.cpp:4444
+ Here is the call graph for this function:

◆ get_all_roles_for_user()

void MapDHandler::get_all_roles_for_user ( std::vector< std::string > &  _return,
const TSessionId &  session,
const std::string &  granteeName 
)
override

Definition at line 1475 of file MapDHandler.cpp.

References CHECK, get_session_copy(), LOG_SESSION, session, and THROW_MAPD_EXCEPTION.

1477  {
1478  LOG_SESSION(sessionId);
1479  auto session = get_session_copy(sessionId);
1480  auto* grantee = SysCatalog::instance().getGrantee(granteeName);
1481  if (grantee) {
1482  if (session.get_currentUser().isSuper) {
1483  roles = grantee->getRoles();
1484  } else if (grantee->isUser()) {
1485  if (session.get_currentUser().userName == granteeName) {
1486  roles = grantee->getRoles();
1487  } else {
1489  "Only a superuser is authorized to request list of roles granted to another "
1490  "user.");
1491  }
1492  } else {
1493  CHECK(!grantee->isUser());
1494  // granteeName is actually a roleName here and we can check a role
1495  // only if it is granted to us
1496  if (SysCatalog::instance().isRoleGrantedToGrantee(
1497  session.get_currentUser().userName, granteeName, false)) {
1498  roles = grantee->getRoles();
1499  } else {
1500  THROW_MAPD_EXCEPTION("A user can check only roles granted to him.");
1501  }
1502  }
1503  } else {
1504  THROW_MAPD_EXCEPTION("Grantee " + granteeName + " does not exist.");
1505  }
1506 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
#define THROW_MAPD_EXCEPTION(errstr)
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
#define CHECK(condition)
Definition: Logger.h:187
TSessionId session
+ Here is the call graph for this function:

◆ get_completion_hints()

void MapDHandler::get_completion_hints ( std::vector< TCompletionHint > &  hints,
const TSessionId &  session,
const std::string &  sql,
const int  cursor 
)
override

Definition at line 1005 of file MapDHandler.cpp.

References anonymous_namespace{MapDHandler.cpp}::extract_projection_tokens_for_completion(), get_completion_hints_unsorted(), get_uc_compatible_table_names_by_column(), LOG_SESSION, and to_upper().

1008  {
1010  std::vector<std::string> visible_tables; // Tables allowed for the given session.
1011  get_completion_hints_unsorted(hints, visible_tables, session, sql, cursor);
1012  const auto proj_tokens = extract_projection_tokens_for_completion(sql);
1013  auto compatible_table_names = get_uc_compatible_table_names_by_column(
1014  proj_tokens.uc_column_names, visible_tables, session);
1015  // Add the table qualifiers explicitly specified by the user.
1016  compatible_table_names.insert(proj_tokens.uc_column_table_qualifiers.begin(),
1017  proj_tokens.uc_column_table_qualifiers.end());
1018  // Sort the hints by category, from COLUMN (most specific) to KEYWORD.
1019  std::sort(
1020  hints.begin(),
1021  hints.end(),
1022  [&compatible_table_names](const TCompletionHint& lhs, const TCompletionHint& rhs) {
1023  if (lhs.type == TCompletionHintType::TABLE &&
1024  rhs.type == TCompletionHintType::TABLE) {
1025  // Between two tables, one which is compatible with the specified projections
1026  // and one which isn't, pick the one which is compatible.
1027  if (compatible_table_names.find(to_upper(lhs.hints.back())) !=
1028  compatible_table_names.end() &&
1029  compatible_table_names.find(to_upper(rhs.hints.back())) ==
1030  compatible_table_names.end()) {
1031  return true;
1032  }
1033  }
1034  return lhs.type < rhs.type;
1035  });
1036 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
std::unordered_set< std::string > get_uc_compatible_table_names_by_column(const std::unordered_set< std::string > &uc_column_names, const std::vector< std::string > &table_names, const TSessionId &session)
auto sql(const std::string &sql_stmts)
std::string to_upper(const std::string &str)
void get_completion_hints_unsorted(std::vector< TCompletionHint > &hints, std::vector< std::string > &visible_tables, const TSessionId &session, const std::string &sql, const int cursor)
TSessionId session
ProjectionTokensForCompletion extract_projection_tokens_for_completion(const std::string &sql)
+ Here is the call graph for this function:

◆ get_completion_hints_unsorted()

void MapDHandler::get_completion_hints_unsorted ( std::vector< TCompletionHint > &  hints,
std::vector< std::string > &  visible_tables,
const TSessionId &  session,
const std::string &  sql,
const int  cursor 
)
private

Definition at line 1038 of file MapDHandler.cpp.

References calcite_, logger::ERROR, get_session_copy(), get_tables(), get_token_based_completions(), just_whitelisted_keyword_hints(), and LOG.

Referenced by get_completion_hints().

1042  {
1043  const auto session_info = get_session_copy(session);
1044  try {
1045  get_tables(visible_tables, session);
1046  // Filter out keywords suggested by Calcite which we don't support.
1048  calcite_->getCompletionHints(session_info, visible_tables, sql, cursor));
1049  } catch (const std::exception& e) {
1050  TMapDException ex;
1051  ex.error_msg = "Exception: " + std::string(e.what());
1052  LOG(ERROR) << ex.error_msg;
1053  throw ex;
1054  }
1055  boost::regex from_expr{R"(\s+from\s+)", boost::regex::extended | boost::regex::icase};
1056  const size_t length_to_cursor =
1057  cursor < 0 ? sql.size() : std::min(sql.size(), static_cast<size_t>(cursor));
1058  // Trust hints from Calcite after the FROM keyword.
1059  if (boost::regex_search(sql.cbegin(), sql.cbegin() + length_to_cursor, from_expr)) {
1060  return;
1061  }
1062  // Before FROM, the query is too incomplete for context-sensitive completions.
1063  get_token_based_completions(hints, session, visible_tables, sql, cursor);
1064 }
void get_token_based_completions(std::vector< TCompletionHint > &hints, const TSessionId &session, const std::vector< std::string > &visible_tables, const std::string &sql, const int cursor)
void get_tables(std::vector< std::string > &_return, const TSessionId &session) override
#define LOG(tag)
Definition: Logger.h:182
auto sql(const std::string &sql_stmts)
std::vector< TCompletionHint > just_whitelisted_keyword_hints(const std::vector< TCompletionHint > &hints)
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
std::shared_ptr< Calcite > calcite_
Definition: MapDHandler.h:460
TSessionId session
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_const_session_ptr()

std::shared_ptr< const Catalog_Namespace::SessionInfo > MapDHandler::get_const_session_ptr ( const TSessionId &  session)
private

Definition at line 4238 of file MapDHandler.cpp.

References get_session_it_unsafe(), and sessions_mutex_.

4239  {
4240  if (session.empty()) {
4241  return {};
4242  }
4243  mapd_shared_lock<mapd_shared_mutex> read_lock(sessions_mutex_);
4244  return get_session_it_unsafe(session)->second;
4245 }
SessionMap::iterator get_session_it_unsafe(const TSessionId &session)
mapd_shared_mutex sessions_mutex_
Definition: MapDHandler.h:452
TSessionId session
+ Here is the call graph for this function:

◆ get_dashboard()

void MapDHandler::get_dashboard ( TDashboard &  _return,
const TSessionId &  session,
int32_t  dashboard_id 
)
override

Definition at line 2976 of file MapDHandler.cpp.

References DashboardDBObjectType, get_session_copy(), is_allowed_on_dashboard(), LOG_SESSION, THROW_MAPD_EXCEPTION, to_string(), Catalog_Namespace::UserMetadata::userName, and AccessPrivileges::VIEW_DASHBOARD.

2978  {
2980  const auto session_info = get_session_copy(session);
2981  auto& cat = session_info.getCatalog();
2983  auto dash = cat.getMetadataForDashboard(dashboard_id);
2984  if (!dash) {
2985  THROW_MAPD_EXCEPTION("Dashboard with dashboard id " + std::to_string(dashboard_id) +
2986  " doesn't exist");
2987  }
2989  session_info, dash->dashboardId, AccessPrivileges::VIEW_DASHBOARD)) {
2990  THROW_MAPD_EXCEPTION("User has no view privileges for the dashboard with id " +
2991  std::to_string(dashboard_id));
2992  }
2993  user_meta.userName = "";
2994  SysCatalog::instance().getMetadataForUserById(dash->userId, user_meta);
2995  auto objects_list = SysCatalog::instance().getMetadataForObject(
2996  cat.getCurrentDB().dbId,
2997  static_cast<int>(DBObjectType::DashboardDBObjectType),
2998  dashboard_id);
2999  dashboard.dashboard_name = dash->dashboardName;
3000  dashboard.dashboard_state = dash->dashboardState;
3001  dashboard.image_hash = dash->imageHash;
3002  dashboard.update_time = dash->updateTime;
3003  dashboard.dashboard_metadata = dash->dashboardMetadata;
3004  dashboard.dashboard_owner = dash->user;
3005  dashboard.dashboard_id = dash->dashboardId;
3006  if (objects_list.empty() ||
3007  (objects_list.size() == 1 && objects_list[0]->roleName == user_meta.userName)) {
3008  dashboard.is_dash_shared = false;
3009  } else {
3010  dashboard.is_dash_shared = true;
3011  }
3012 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
static const AccessPrivileges VIEW_DASHBOARD
Definition: DBObject.h:164
std::string to_string(char const *&&v)
#define THROW_MAPD_EXCEPTION(errstr)
static bool is_allowed_on_dashboard(const Catalog_Namespace::SessionInfo &session_info, int32_t dashboard_id, AccessPrivileges requestedPermissions)
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
TSessionId session
+ Here is the call graph for this function:

◆ get_dashboard_grantees()

void MapDHandler::get_dashboard_grantees ( std::vector< TDashboardGrantees > &  _return,
const TSessionId &  session,
int32_t  dashboard_id 
)
override

Definition at line 3273 of file MapDHandler.cpp.

References DashboardPrivileges::CREATE_DASHBOARD, DashboardDBObjectType, DashboardPrivileges::DELETE_DASHBOARD, DashboardPrivileges::EDIT_DASHBOARD, get_session_copy(), LOG_SESSION, THROW_MAPD_EXCEPTION, to_string(), Catalog_Namespace::UserMetadata::userId, Catalog_Namespace::UserMetadata::userName, and DashboardPrivileges::VIEW_DASHBOARD.

3276  {
3278  const auto session_info = get_session_copy(session);
3279  auto& cat = session_info.getCatalog();
3281  auto dash = cat.getMetadataForDashboard(dashboard_id);
3282  if (!dash) {
3283  THROW_MAPD_EXCEPTION("Exception: Dashboard id " + std::to_string(dashboard_id) +
3284  " does not exist");
3285  } else if (session_info.get_currentUser().userId != dash->userId &&
3286  !session_info.get_currentUser().isSuper) {
3288  "User should be either owner of dashboard or super user to access grantees");
3289  }
3290  std::vector<ObjectRoleDescriptor*> objectsList;
3291  objectsList = SysCatalog::instance().getMetadataForObject(
3292  cat.getCurrentDB().dbId,
3293  static_cast<int>(DBObjectType::DashboardDBObjectType),
3294  dashboard_id); // By default objecttypecan be only dashabaords
3295  user_meta.userId = -1;
3296  user_meta.userName = "";
3297  SysCatalog::instance().getMetadataForUserById(dash->userId, user_meta);
3298  for (auto object : objectsList) {
3299  if (user_meta.userName == object->roleName) {
3300  // Mask owner
3301  continue;
3302  }
3303  TDashboardGrantees grantee;
3304  TDashboardPermissions perm;
3305  grantee.name = object->roleName;
3306  grantee.is_user = object->roleType;
3307  perm.create_ = object->privs.hasPermission(DashboardPrivileges::CREATE_DASHBOARD);
3308  perm.delete_ = object->privs.hasPermission(DashboardPrivileges::DELETE_DASHBOARD);
3309  perm.edit_ = object->privs.hasPermission(DashboardPrivileges::EDIT_DASHBOARD);
3310  perm.view_ = object->privs.hasPermission(DashboardPrivileges::VIEW_DASHBOARD);
3311  grantee.permissions = perm;
3312  dashboard_grantees.push_back(grantee);
3313  }
3314 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
std::string to_string(char const *&&v)
#define THROW_MAPD_EXCEPTION(errstr)
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
static const int32_t EDIT_DASHBOARD
Definition: DBObject.h:105
static const int32_t DELETE_DASHBOARD
Definition: DBObject.h:103
static const int32_t VIEW_DASHBOARD
Definition: DBObject.h:104
static const int32_t CREATE_DASHBOARD
Definition: DBObject.h:102
TSessionId session
+ Here is the call graph for this function:

◆ get_dashboards()

void MapDHandler::get_dashboards ( std::vector< TDashboard > &  _return,
const TSessionId &  session 
)
override

Definition at line 3014 of file MapDHandler.cpp.

References anonymous_namespace{ImportTest.cpp}::d(), DashboardDBObjectType, get_session_copy(), is_allowed_on_dashboard(), LOG_SESSION, Catalog_Namespace::UserMetadata::userName, and AccessPrivileges::VIEW_DASHBOARD.

3015  {
3017  const auto session_info = get_session_copy(session);
3018  auto& cat = session_info.getCatalog();
3020  const auto dashes = cat.getAllDashboardsMetadata();
3021  user_meta.userName = "";
3022  for (const auto d : dashes) {
3023  SysCatalog::instance().getMetadataForUserById(d->userId, user_meta);
3025  session_info, d->dashboardId, AccessPrivileges::VIEW_DASHBOARD)) {
3026  auto objects_list = SysCatalog::instance().getMetadataForObject(
3027  cat.getCurrentDB().dbId,
3028  static_cast<int>(DBObjectType::DashboardDBObjectType),
3029  d->dashboardId);
3030  TDashboard dash;
3031  dash.dashboard_name = d->dashboardName;
3032  dash.image_hash = d->imageHash;
3033  dash.update_time = d->updateTime;
3034  dash.dashboard_metadata = d->dashboardMetadata;
3035  dash.dashboard_id = d->dashboardId;
3036  dash.dashboard_owner = d->user;
3037  // dashboardState is intentionally not populated here
3038  // for payload reasons
3039  // use get_dashboard call to get state
3040  if (objects_list.empty() ||
3041  (objects_list.size() == 1 && objects_list[0]->roleName == user_meta.userName)) {
3042  dash.is_dash_shared = false;
3043  } else {
3044  dash.is_dash_shared = true;
3045  }
3046  dashboards.push_back(dash);
3047  }
3048  }
3049 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
static const AccessPrivileges VIEW_DASHBOARD
Definition: DBObject.h:164
void d(const SQLTypes expected_type, const std::string &str)
Definition: ImportTest.cpp:268
static bool is_allowed_on_dashboard(const Catalog_Namespace::SessionInfo &session_info, int32_t dashboard_id, AccessPrivileges requestedPermissions)
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
TSessionId session
+ Here is the call graph for this function:

◆ get_databases()

void MapDHandler::get_databases ( std::vector< TDBInfo > &  _return,
const TSessionId &  session 
)
override

Definition at line 1980 of file MapDHandler.cpp.

References get_session_copy(), LOG_SESSION, and anonymous_namespace{DBObjectPrivilegesTest.cpp}::user.

1981  {
1983  const auto session_info = get_session_copy(session);
1984  const auto& user = session_info.get_currentUser();
1986  SysCatalog::instance().getDatabaseListForUser(user);
1987  for (auto& db : dbs) {
1988  TDBInfo dbinfo;
1989  dbinfo.db_name = std::move(db.dbName);
1990  dbinfo.db_owner = std::move(db.dbOwnerName);
1991  dbinfos.push_back(std::move(dbinfo));
1992  }
1993 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
std::list< DBSummary > DBSummaryList
Definition: SysCatalog.h:106
TSessionId session
+ Here is the call graph for this function:

◆ get_db_object_privs()

void MapDHandler::get_db_object_privs ( std::vector< TDBObject > &  _return,
const TSessionId &  session,
const std::string &  objectName,
const TDBObjectType::type  type 
)
override

Definition at line 1398 of file MapDHandler.cpp.

References AccessPrivileges::ALL_TABLE, DashboardDBObjectType, DatabaseDBObjectType, get_session_copy(), DBObject::getObjectKey(), DBObject::loadKey(), LOG_SESSION, serialize_db_object(), session, TableDBObjectType, THROW_MAPD_EXCEPTION, to_string(), and ViewDBObjectType.

1401  {
1402  LOG_SESSION(sessionId);
1403  auto session = get_session_copy(sessionId);
1404  DBObjectType object_type;
1405  switch (type) {
1407  object_type = DBObjectType::DatabaseDBObjectType;
1408  break;
1410  object_type = DBObjectType::TableDBObjectType;
1411  break;
1414  break;
1416  object_type = DBObjectType::ViewDBObjectType;
1417  break;
1418  default:
1419  THROW_MAPD_EXCEPTION("Failed to get object privileges for " + objectName +
1420  ": unknown object type (" + std::to_string(type) + ").");
1421  }
1422  DBObject object_to_find(objectName, object_type);
1423 
1424  try {
1425  if (object_type == DashboardDBObjectType) {
1426  if (objectName == "") {
1427  object_to_find = DBObject(-1, object_type);
1428  } else {
1429  object_to_find = DBObject(std::stoi(objectName), object_type);
1430  }
1431  } else if ((object_type == TableDBObjectType || object_type == ViewDBObjectType) &&
1432  !objectName.empty()) {
1433  // special handling for view / table
1434  auto& cat = session.getCatalog();
1435  auto td = cat.getMetadataForTable(objectName, false);
1436  if (td) {
1437  object_type = td->isView ? ViewDBObjectType : TableDBObjectType;
1438  object_to_find = DBObject(objectName, object_type);
1439  }
1440  }
1441  object_to_find.loadKey(session.getCatalog());
1442  } catch (const std::exception&) {
1443  THROW_MAPD_EXCEPTION("Object with name " + objectName + " does not exist.");
1444  }
1445 
1446  // object type on database level
1447  DBObject object_to_find_dblevel("", object_type);
1448  object_to_find_dblevel.loadKey(session.getCatalog());
1449  // if user is superuser respond with a full priv
1450  if (session.get_currentUser().isSuper) {
1451  // using ALL_TABLE here to set max permissions
1452  DBObject dbObj{object_to_find.getObjectKey(),
1454  session.get_currentUser().userId};
1455  dbObj.setName("super");
1456  TDBObjects.push_back(serialize_db_object(session.get_currentUser().userName, dbObj));
1457  };
1458 
1459  std::vector<std::string> grantees = SysCatalog::instance().getRoles(
1460  true, session.get_currentUser().isSuper, session.get_currentUser().userName);
1461  for (const auto& grantee : grantees) {
1462  DBObject* object_found;
1463  auto* gr = SysCatalog::instance().getGrantee(grantee);
1464  if (gr && (object_found = gr->findDbObject(object_to_find.getObjectKey(), true))) {
1465  TDBObjects.push_back(serialize_db_object(grantee, *object_found));
1466  }
1467  // check object permissions on Database level
1468  if (gr &&
1469  (object_found = gr->findDbObject(object_to_find_dblevel.getObjectKey(), true))) {
1470  TDBObjects.push_back(serialize_db_object(grantee, *object_found));
1471  }
1472  }
1473 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
DBObjectType
Definition: DBObject.h:42
static TDBObject serialize_db_object(const std::string &roleName, const DBObject &inObject)
std::string to_string(char const *&&v)
#define THROW_MAPD_EXCEPTION(errstr)
DBObjectKey getObjectKey() const
Definition: DBObject.h:196
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
static const AccessPrivileges ALL_TABLE
Definition: DBObject.h:150
TSessionId session
+ Here is the call graph for this function:

◆ get_db_objects_for_grantee()

void MapDHandler::get_db_objects_for_grantee ( std::vector< TDBObject > &  _return,
const TSessionId &  session,
const std::string &  roleName 
)
override

Definition at line 1371 of file MapDHandler.cpp.

References get_session_copy(), Catalog_Namespace::UserMetadata::isSuper, LOG_SESSION, serialize_db_object(), session, THROW_MAPD_EXCEPTION, anonymous_namespace{DBObjectPrivilegesTest.cpp}::user, and Catalog_Namespace::UserMetadata::userName.

1373  {
1374  LOG_SESSION(sessionId);
1375  auto session = get_session_copy(sessionId);
1376  auto user = session.get_currentUser();
1377  if (!user.isSuper &&
1378  !SysCatalog::instance().isRoleGrantedToGrantee(user.userName, roleName, false)) {
1379  return;
1380  }
1381  auto* rl = SysCatalog::instance().getGrantee(roleName);
1382  if (rl) {
1383  auto dbId = session.getCatalog().getCurrentDB().dbId;
1384  for (auto& dbObject : *rl->getDbObjects(true)) {
1385  if (dbObject.first.dbId != dbId) {
1386  // TODO (max): it doesn't scale well in case we have many DBs (not a typical
1387  // usecase for now, though)
1388  continue;
1389  }
1390  TDBObject tdbObject = serialize_db_object(roleName, *dbObject.second);
1391  TDBObjectsForRole.push_back(tdbObject);
1392  }
1393  } else {
1394  THROW_MAPD_EXCEPTION("User or role " + roleName + " does not exist.");
1395  }
1396 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
static TDBObject serialize_db_object(const std::string &roleName, const DBObject &inObject)
#define THROW_MAPD_EXCEPTION(errstr)
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
TSessionId session
+ Here is the call graph for this function:

◆ get_device_parameters()

void MapDHandler::get_device_parameters ( std::map< std::string, std::string > &  _return)
override

Definition at line 5611 of file MapDHandler.cpp.

Referenced by LogSession::set_session().

5611  {
5612  auto params = ::get_device_parameters();
5613  for (auto item : params) {
5614  _return.insert(item);
5615  }
5616 }
void get_device_parameters(std::map< std::string, std::string > &_return) override
+ Here is the caller graph for this function:

◆ get_first_geo_file_in_archive()

void MapDHandler::get_first_geo_file_in_archive ( std::string &  _return,
const TSessionId &  session,
const std::string &  archive_path,
const TCopyParams &  copy_params 
)
override

Definition at line 4016 of file MapDHandler.cpp.

References add_vsi_archive_prefix(), add_vsi_network_prefix(), find_first_geo_file_in_archive(), Importer_NS::Importer::gdalFileExists(), import_path_, is_a_supported_archive_file(), LOG_SESSION, path_is_relative(), thrift_to_copyparams(), and THROW_MAPD_EXCEPTION.

4019  {
4020  LOG_SESSION(session, "get_first_geo_file_in_archive", archive_path_in);
4021  std::string archive_path(archive_path_in);
4022 
4023  if (path_is_relative(archive_path)) {
4024  // assume relative paths are relative to data_path / mapd_import / <session>
4025  auto file_path = import_path_ / picosha2::hash256_hex_string(session) /
4026  boost::filesystem::path(archive_path).filename();
4027  archive_path = file_path.string();
4028  }
4029 
4030  if (is_a_supported_archive_file(archive_path)) {
4031  // find the archive file
4032  add_vsi_network_prefix(archive_path);
4033  if (!Importer_NS::Importer::gdalFileExists(archive_path,
4034  thrift_to_copyparams(copy_params))) {
4035  THROW_MAPD_EXCEPTION("Archive does not exist: " + archive_path_in);
4036  }
4037  // find geo file in archive
4038  add_vsi_archive_prefix(archive_path);
4039  std::string geo_file =
4040  find_first_geo_file_in_archive(archive_path, thrift_to_copyparams(copy_params));
4041  // what did we get?
4042  if (geo_file.size()) {
4043  // prepend it with the original path
4044  _return = archive_path_in + std::string("/") + geo_file;
4045  } else {
4046  // just return the original path
4047  _return = archive_path_in;
4048  }
4049  } else {
4050  // just return the original path
4051  _return = archive_path_in;
4052  }
4053 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
void add_vsi_network_prefix(std::string &path)
boost::filesystem::path import_path_
Definition: MapDHandler.h:442
void add_vsi_archive_prefix(std::string &path)
#define THROW_MAPD_EXCEPTION(errstr)
bool path_is_relative(const std::string &path)
static bool gdalFileExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:4367
std::string find_first_geo_file_in_archive(const std::string &archive_path, const Importer_NS::CopyParams &copy_params)
Importer_NS::CopyParams thrift_to_copyparams(const TCopyParams &cp)
TSessionId session
bool is_a_supported_archive_file(const std::string &path)
+ Here is the call graph for this function:

◆ get_hardware_info()

void MapDHandler::get_hardware_info ( TClusterHardwareInfo &  _return,
const TSessionId &  session 
)
override

Definition at line 495 of file MapDHandler.cpp.

References data_mgr_, LeafAggregator::getHardwareInfo(), leaf_aggregator_, LeafAggregator::leafCount(), and LOG_SESSION.

496  {
498  THardwareInfo ret;
499  const auto cuda_mgr = data_mgr_->getCudaMgr();
500  if (cuda_mgr) {
501  ret.num_gpu_hw = cuda_mgr->getDeviceCount();
502  ret.start_gpu = cuda_mgr->getStartGpu();
503  if (ret.start_gpu >= 0) {
504  ret.num_gpu_allocated = cuda_mgr->getDeviceCount() - cuda_mgr->getStartGpu();
505  // ^ This will break as soon as we allow non contiguous GPU allocations to MapD
506  }
507  for (int16_t device_id = 0; device_id < ret.num_gpu_hw; device_id++) {
508  TGpuSpecification gpu_spec;
509  auto deviceProperties = cuda_mgr->getDeviceProperties(device_id);
510  gpu_spec.num_sm = deviceProperties->numMPs;
511  gpu_spec.clock_frequency_kHz = deviceProperties->clockKhz;
512  gpu_spec.memory = deviceProperties->globalMem;
513  gpu_spec.compute_capability_major = deviceProperties->computeMajor;
514  gpu_spec.compute_capability_minor = deviceProperties->computeMinor;
515  ret.gpu_info.push_back(gpu_spec);
516  }
517  }
518 
519  // start hardware/OS dependent code
520  ret.num_cpu_hw = std::thread::hardware_concurrency();
521  // ^ This might return diffrent results in case of hyper threading
522  // end hardware/OS dependent code
523 
524  _return.hardware_info.push_back(ret);
525  if (leaf_aggregator_.leafCount() > 0) {
526  ret.host_name = "aggregator";
527  TClusterHardwareInfo leaf_hardware = leaf_aggregator_.getHardwareInfo(session);
528  _return.hardware_info.insert(_return.hardware_info.end(),
529  leaf_hardware.hardware_info.begin(),
530  leaf_hardware.hardware_info.end());
531  }
532 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:439
TClusterHardwareInfo getHardwareInfo(TSessionId session)
std::shared_ptr< Data_Namespace::DataMgr > data_mgr_
Definition: MapDHandler.h:437
size_t leafCount() const
TSessionId session
+ Here is the call graph for this function:

◆ get_heap_profile()

void MapDHandler::get_heap_profile ( std::string &  _return,
const TSessionId &  session 
)
override

Definition at line 4186 of file MapDHandler.cpp.

References get_session_copy(), LOG_SESSION, and THROW_MAPD_EXCEPTION.

4186  {
4188  const auto session_info = get_session_copy(session);
4189 #ifdef HAVE_PROFILER
4190  if (!IsHeapProfilerRunning()) {
4191  THROW_MAPD_EXCEPTION("Profiler not running");
4192  }
4193  auto profile_buff = GetHeapProfile();
4194  profile = profile_buff;
4195  free(profile_buff);
4196 #else
4197  THROW_MAPD_EXCEPTION("Profiler not enabled");
4198 #endif // HAVE_PROFILER
4199 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
#define THROW_MAPD_EXCEPTION(errstr)
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
TSessionId session
+ Here is the call graph for this function:

◆ get_internal_table_details()

void MapDHandler::get_internal_table_details ( TTableDetails &  _return,
const TSessionId &  session,
const std::string &  table_name 
)
override

Definition at line 1606 of file MapDHandler.cpp.

References get_table_details_impl(), and LOG_SESSION.

1608  {
1609  LOG_SESSION(session, "table_name", table_name);
1610  get_table_details_impl(_return, session, table_name, true, false);
1611 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
void get_table_details_impl(TTableDetails &_return, const TSessionId &session, const std::string &table_name, const bool get_system, const bool get_physical)
TSessionId session
+ Here is the call graph for this function:

◆ get_layers_in_geo_file()

void MapDHandler::get_layers_in_geo_file ( std::vector< TGeoFileLayerInfo > &  _return,
const TSessionId &  session,
const std::string &  file_name,
const TCopyParams &  copy_params 
)
override

Definition at line 4087 of file MapDHandler.cpp.

References add_vsi_archive_prefix(), add_vsi_geo_prefix(), add_vsi_network_prefix(), CHECK, Importer_NS::Importer::EMPTY, find_first_geo_file_in_archive(), Importer_NS::Importer::gdalFileExists(), Importer_NS::Importer::gdalFileOrDirectoryExists(), Importer_NS::Importer::gdalGetLayersInGeoFile(), Importer_NS::Importer::GEO, import_path_, is_a_supported_archive_file(), is_a_supported_geo_file(), LOG_SESSION, Importer_NS::Importer::NON_GEO, path_is_relative(), thrift_to_copyparams(), THROW_MAPD_EXCEPTION, and Importer_NS::Importer::UNSUPPORTED_GEO.

4090  {
4091  LOG_SESSION(session, "get_layers_in_geo_file", file_name_in);
4092  std::string file_name(file_name_in);
4093 
4095 
4096  // handle relative paths
4097  if (path_is_relative(file_name)) {
4098  // assume relative paths are relative to data_path / mapd_import / <session>
4099  auto file_path = import_path_ / picosha2::hash256_hex_string(session) /
4100  boost::filesystem::path(file_name).filename();
4101  file_name = file_path.string();
4102  }
4103 
4104  // validate file_name
4105  if (is_a_supported_geo_file(file_name, true)) {
4106  // prepare to load geo file directly
4107  add_vsi_network_prefix(file_name);
4108  add_vsi_geo_prefix(file_name);
4109  } else if (is_a_supported_archive_file(file_name)) {
4110  // find the archive file
4111  add_vsi_network_prefix(file_name);
4112  if (!Importer_NS::Importer::gdalFileExists(file_name, copy_params)) {
4113  THROW_MAPD_EXCEPTION("Archive does not exist: " + file_name_in);
4114  }
4115  // find geo file in archive
4116  add_vsi_archive_prefix(file_name);
4117  std::string geo_file = find_first_geo_file_in_archive(file_name, copy_params);
4118  // prepare to load that geo file
4119  if (geo_file.size()) {
4120  file_name = file_name + std::string("/") + geo_file;
4121  }
4122  } else {
4123  THROW_MAPD_EXCEPTION("File is not a supported geo or geo archive file: " +
4124  file_name_in);
4125  }
4126 
4127  // check the file actually exists
4128  if (!Importer_NS::Importer::gdalFileOrDirectoryExists(file_name, copy_params)) {
4129  THROW_MAPD_EXCEPTION("Geo file/archive does not exist: " + file_name_in);
4130  }
4131 
4132  // find all layers
4133  auto internal_layer_info =
4134  Importer_NS::Importer::gdalGetLayersInGeoFile(file_name, copy_params);
4135 
4136  // convert to Thrift type
4137  for (const auto& internal_layer : internal_layer_info) {
4138  TGeoFileLayerInfo layer;
4139  layer.name = internal_layer.name;
4140  switch (internal_layer.contents) {
4142  layer.contents = TGeoFileLayerContents::EMPTY;
4143  break;
4145  layer.contents = TGeoFileLayerContents::GEO;
4146  break;
4148  layer.contents = TGeoFileLayerContents::NON_GEO;
4149  break;
4151  layer.contents = TGeoFileLayerContents::UNSUPPORTED_GEO;
4152  break;
4153  default:
4154  CHECK(false);
4155  }
4156  _return.emplace_back(layer); // no suitable constructor to just pass parameters
4157  }
4158 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
static std::vector< GeoFileLayerInfo > gdalGetLayersInGeoFile(const std::string &file_name, const CopyParams &copy_params)
Definition: Importer.cpp:4469
void add_vsi_network_prefix(std::string &path)
boost::filesystem::path import_path_
Definition: MapDHandler.h:442
void add_vsi_archive_prefix(std::string &path)
void add_vsi_geo_prefix(std::string &path)
#define THROW_MAPD_EXCEPTION(errstr)
static bool gdalFileOrDirectoryExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:4372
bool is_a_supported_geo_file(const std::string &path, bool include_gz)
bool path_is_relative(const std::string &path)
static bool gdalFileExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:4367
std::string find_first_geo_file_in_archive(const std::string &archive_path, const Importer_NS::CopyParams &copy_params)
#define CHECK(condition)
Definition: Logger.h:187
Importer_NS::CopyParams thrift_to_copyparams(const TCopyParams &cp)
TSessionId session
bool is_a_supported_archive_file(const std::string &path)
+ Here is the call graph for this function:

◆ get_license_claims()

void MapDHandler::get_license_claims ( TLicenseInfo &  _return,
const TSessionId &  session,
const std::string &  nonce 
)
override

Definition at line 5530 of file MapDHandler.cpp.

References get_session_copy(), and LOG_SESSION.

5532  {
5534  const auto session_info = get_session_copy(session);
5535  _return.claims.emplace_back("");
5536 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
TSessionId session
+ Here is the call graph for this function:

◆ get_link_view()

void MapDHandler::get_link_view ( TFrontendView &  _return,
const TSessionId &  session,
const std::string &  link 
)
override

Definition at line 1696 of file MapDHandler.cpp.

References get_session_copy(), LOG_SESSION, THROW_MAPD_EXCEPTION, and to_string().

1698  {
1700  const auto session_info = get_session_copy(session);
1701  auto& cat = session_info.getCatalog();
1702  auto ld = cat.getMetadataForLink(std::to_string(cat.getCurrentDB().dbId) + link);
1703  if (!ld) {
1704  THROW_MAPD_EXCEPTION("Link " + link + " is not valid.");
1705  }
1706  _return.view_state = ld->viewState;
1707  _return.view_name = ld->link;
1708  _return.update_time = ld->updateTime;
1709  _return.view_metadata = ld->viewMetadata;
1710 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
std::string to_string(char const *&&v)
#define THROW_MAPD_EXCEPTION(errstr)
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
TSessionId session
+ Here is the call graph for this function:

◆ get_memory()

void MapDHandler::get_memory ( std::vector< TNodeMemoryInfo > &  _return,
const TSessionId &  session,
const std::string &  memory_level 
)
override

Definition at line 1935 of file MapDHandler.cpp.

References Data_Namespace::CPU_LEVEL, Buffer_Namespace::FREE, get_hostname(), get_session_copy(), LeafAggregator::getLeafMemoryInfo(), Data_Namespace::GPU_LEVEL, leaf_aggregator_, LeafAggregator::leafCount(), and LOG_SESSION.

1937  {
1939  const auto session_info = get_session_copy(session);
1940  std::vector<Data_Namespace::MemoryInfo> internal_memory;
1941  Data_Namespace::MemoryLevel mem_level;
1942  if (!memory_level.compare("gpu")) {
1944  internal_memory =
1945  SysCatalog::instance().getDataMgr().getMemoryInfo(MemoryLevel::GPU_LEVEL);
1946  } else {
1948  internal_memory =
1949  SysCatalog::instance().getDataMgr().getMemoryInfo(MemoryLevel::CPU_LEVEL);
1950  }
1951 
1952  for (auto memInfo : internal_memory) {
1953  TNodeMemoryInfo nodeInfo;
1954  if (leaf_aggregator_.leafCount() > 0) {
1955  nodeInfo.host_name = get_hostname();
1956  }
1957  nodeInfo.page_size = memInfo.pageSize;
1958  nodeInfo.max_num_pages = memInfo.maxNumPages;
1959  nodeInfo.num_pages_allocated = memInfo.numPageAllocated;
1960  nodeInfo.is_allocation_capped = memInfo.isAllocationCapped;
1961  for (auto gpu : memInfo.nodeMemoryData) {
1962  TMemoryData md;
1963  md.slab = gpu.slabNum;
1964  md.start_page = gpu.startPage;
1965  md.num_pages = gpu.numPages;
1966  md.touch = gpu.touch;
1967  md.chunk_key.insert(md.chunk_key.end(), gpu.chunk_key.begin(), gpu.chunk_key.end());
1968  md.is_free = gpu.isFree == Buffer_Namespace::MemStatus::FREE;
1969  nodeInfo.node_memory_data.push_back(md);
1970  }
1971  _return.push_back(nodeInfo);
1972  }
1973  if (leaf_aggregator_.leafCount() > 0) {
1974  std::vector<TNodeMemoryInfo> leafSummary =
1976  _return.insert(_return.begin(), leafSummary.begin(), leafSummary.end());
1977  }
1978 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:439
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
std::vector< TNodeMemoryInfo > getLeafMemoryInfo(TSessionId session, Data_Namespace::MemoryLevel memory_level)
std::string get_hostname()
Definition: SysInfo.cpp:6
size_t leafCount() const
TSessionId session
+ Here is the call graph for this function:

◆ get_physical_tables()

void MapDHandler::get_physical_tables ( std::vector< std::string > &  _return,
const TSessionId &  session 
)
override

Definition at line 1770 of file MapDHandler.cpp.

References GET_PHYSICAL_TABLES, get_tables_impl(), and LOG_SESSION.

1771  {
1774 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
void get_tables_impl(std::vector< std::string > &table_names, const TSessionId &session, const GetTablesType get_tables_type)
TSessionId session
+ Here is the call graph for this function:

◆ get_result_row_for_pixel()

void MapDHandler::get_result_row_for_pixel ( TPixelTableRowResult &  _return,
const TSessionId &  session,
const int64_t  widget_id,
const TPixel &  pixel,
const std::map< std::string, std::vector< std::string >> &  table_col_names,
const bool  column_format,
const int32_t  pixel_radius,
const std::string &  nonce 
)
override

Definition at line 1508 of file MapDHandler.cpp.

References MapDRenderHandler::dump_table_col_names(), get_session_copy_ptr(), LOG_SESSION, render_handler_, and THROW_MAPD_EXCEPTION.

1516  {
1518  "widget_id",
1519  widget_id,
1520  "pixel.x",
1521  pixel.x,
1522  "pixel.y",
1523  pixel.y,
1524  "column_format",
1525  column_format,
1526  "pixel_radius",
1527  pixel_radius,
1528  "table_col_names",
1529  MapDRenderHandler::dump_table_col_names(table_col_names),
1530  "nonce",
1531  nonce);
1532  if (!render_handler_) {
1533  THROW_MAPD_EXCEPTION("Backend rendering is disabled.");
1534  }
1535 
1536  auto session_ptr = get_session_copy_ptr(session);
1537  try {
1538  render_handler_->get_result_row_for_pixel(_return,
1539  session_ptr,
1540  widget_id,
1541  pixel,
1542  table_col_names,
1543  column_format,
1544  pixel_radius,
1545  nonce);
1546  } catch (std::exception& e) {
1547  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
1548  }
1549 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
std::unique_ptr< MapDRenderHandler > render_handler_
Definition: MapDHandler.h:457
#define THROW_MAPD_EXCEPTION(errstr)
static std::string dump_table_col_names(const std::map< std::string, std::vector< std::string >> &table_col_names)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_copy_ptr(const TSessionId &session)
TSessionId session
+ Here is the call graph for this function:

◆ get_roles()

void MapDHandler::get_roles ( std::vector< std::string > &  _return,
const TSessionId &  session 
)
override

Definition at line 1174 of file MapDHandler.cpp.

References get_session_copy(), and LOG_SESSION.

1174  {
1176  auto session_info = get_session_copy(session);
1177  if (!session_info.get_currentUser().isSuper) {
1178  // WARNING: This appears to not include roles a user is a member of,
1179  // if the role has no permissions granted to it.
1180  roles =
1181  SysCatalog::instance().getRoles(session_info.get_currentUser().userName,
1182  session_info.getCatalog().getCurrentDB().dbId);
1183  } else {
1184  roles = SysCatalog::instance().getRoles(
1185  false, true, session_info.get_currentUser().userName);
1186  }
1187 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
TSessionId session
+ Here is the call graph for this function:

◆ get_server_status()

void MapDHandler::get_server_status ( TServerStatus &  _return,
const TSessionId &  session 
)
override

Definition at line 454 of file MapDHandler.cpp.

References get_hostname(), LOG_SESSION, MAPD_EDITION, MAPD_RELEASE, read_only_, render_handler_, and start_time_.

454  {
456  const auto rendering_enabled = bool(render_handler_);
457  _return.read_only = read_only_;
458  _return.version = MAPD_RELEASE;
459  _return.rendering_enabled = rendering_enabled;
460  _return.poly_rendering_enabled = rendering_enabled;
461  _return.start_time = start_time_;
462  _return.edition = MAPD_EDITION;
463  _return.host_name = get_hostname();
464 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
std::unique_ptr< MapDRenderHandler > render_handler_
Definition: MapDHandler.h:457
static const std::string MAPD_EDITION
Definition: release.h:41
int64_t start_time_
Definition: MapDHandler.h:454
const bool read_only_
Definition: MapDHandler.h:449
std::string get_hostname()
Definition: SysInfo.cpp:6
static const std::string MAPD_RELEASE
Definition: release.h:43
TSessionId session
+ Here is the call graph for this function:

◆ get_session_copy()

Catalog_Namespace::SessionInfo MapDHandler::get_session_copy ( const TSessionId &  session)

Definition at line 4247 of file MapDHandler.cpp.

References get_session_it_unsafe(), and sessions_mutex_.

Referenced by check_table_load_privileges(), checkpoint(), clear_cpu_memory(), clear_gpu_memory(), create_dashboard(), create_link(), deallocate_df(), delete_dashboard(), detect_column_types(), get_all_roles_for_user(), get_completion_hints_unsorted(), get_dashboard(), get_dashboard_grantees(), get_dashboards(), get_databases(), get_db_object_privs(), get_db_objects_for_grantee(), get_heap_profile(), get_license_claims(), get_link_view(), get_memory(), get_roles(), get_session_info(), get_table_details_impl(), get_table_epoch(), get_table_epoch_by_name(), get_tables_impl(), get_tables_meta(), get_users(), get_valid_groups(), has_object_privilege(), hasTableAccessPrivileges(), import_geo_table(), import_table(), insert_data(), load_table(), load_table_binary(), load_table_binary_arrow(), load_table_binary_columnar(), register_runtime_udf(), replace_dashboard(), set_license_key(), set_table_epoch(), set_table_epoch_by_name(), share_dashboard(), sql_execute(), sql_execute_df(), sql_validate(), start_heap_profile(), start_query(), start_render_query(), stop_heap_profile(), and unshare_dashboard().

4247  {
4248  mapd_shared_lock<mapd_shared_mutex> read_lock(sessions_mutex_);
4249  return *get_session_it_unsafe(session)->second;
4250 }
SessionMap::iterator get_session_it_unsafe(const TSessionId &session)
mapd_shared_mutex sessions_mutex_
Definition: MapDHandler.h:452
TSessionId session
+ Here is the call graph for this function:

◆ get_session_copy_ptr()

std::shared_ptr< Catalog_Namespace::SessionInfo > MapDHandler::get_session_copy_ptr ( const TSessionId &  session)

Definition at line 4252 of file MapDHandler.cpp.

References get_session_it_unsafe(), and sessions_mutex_.

Referenced by get_result_row_for_pixel(), and render_vega().

4253  {
4254  // Note(Wamsi): We have `get_const_session_ptr` which would return as const SessionInfo
4255  // stored in the map. You can use `get_const_session_ptr` instead of the copy of
4256  // SessionInfo but beware that it can be changed in teh map. So if you do not care about
4257  // the changes then use `get_const_session_ptr` if you do then use this function to get
4258  // a copy. We should eventually aim to merge both `get_const_session_ptr` and
4259  // `get_session_copy_ptr`.
4260  mapd_shared_lock<mapd_shared_mutex> read_lock(sessions_mutex_);
4261  auto& session_info_ref = *get_session_it_unsafe(session)->second;
4262  return std::make_shared<Catalog_Namespace::SessionInfo>(session_info_ref);
4263 }
SessionMap::iterator get_session_it_unsafe(const TSessionId &session)
mapd_shared_mutex sessions_mutex_
Definition: MapDHandler.h:452
TSessionId session
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_session_info()

void MapDHandler::get_session_info ( TSessionInfo &  _return,
const TSessionId &  session 
)
override

Definition at line 534 of file MapDHandler.cpp.

References get_session_copy(), and LOG_SESSION.

534  {
536  auto session_info = get_session_copy(session);
537  auto user_metadata = session_info.get_currentUser();
538 
539  _return.user = user_metadata.userName;
540  _return.database = session_info.getCatalog().getCurrentDB().dbName;
541  _return.start_time = session_info.get_start_time();
542  _return.is_super = user_metadata.isSuper;
543 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
TSessionId session
+ Here is the call graph for this function:

◆ get_session_it_unsafe()

SessionMap::iterator MapDHandler::get_session_it_unsafe ( const TSessionId &  session)
private

Definition at line 4222 of file MapDHandler.cpp.

References calcite_, check_session_exp_unsafe(), anonymous_namespace{MapDHandler.cpp}::get_session_from_map(), and sessions_.

Referenced by disconnect(), get_const_session_ptr(), get_session_copy(), get_session_copy_ptr(), get_session_ptr(), interrupt(), set_execution_mode(), and switch_database().

4222  {
4223  SessionMap::iterator session_it;
4224  const auto calcite_session_prefix = calcite_->get_session_prefix();
4225  const auto prefix_length = calcite_session_prefix.size();
4226  if (prefix_length && 0 == session.compare(0, prefix_length, calcite_session_prefix)) {
4227  session_it = get_session_from_map(session.substr(prefix_length + 1), sessions_);
4228  check_session_exp_unsafe(session_it);
4229  session_it->second->make_superuser();
4230  } else {
4231  session_it = get_session_from_map(session, sessions_);
4232  check_session_exp_unsafe(session_it);
4233  session_it->second->reset_superuser();
4234  }
4235  return session_it;
4236 }
SessionMap sessions_
Definition: MapDHandler.h:669
void check_session_exp_unsafe(const SessionMap::iterator &session_it)
std::shared_ptr< Calcite > calcite_
Definition: MapDHandler.h:460
TSessionId session
SessionMap::iterator get_session_from_map(const TSessionId &session, SessionMap &session_map)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_session_ptr()

std::shared_ptr< Catalog_Namespace::SessionInfo > MapDHandler::get_session_ptr ( const TSessionId &  session_id)
private

Definition at line 4265 of file MapDHandler.cpp.

References get_session_it_unsafe(), and sessions_mutex_.

Referenced by LogSession::LogSession().

4266  {
4267  // Note(Wamsi): This method will give you a shared_ptr to master SessionInfo itself.
4268  // Should be used only when you need to make updates to original SessionInfo object.
4269  // Currently used by `update_session_last_used_duration`
4270 
4271  // 1) `session_id` will be empty during intial connect. 2)`sessionmapd iterator` will be
4272  // invalid during disconnect. SessionInfo will be erased from map by the time it reaches
4273  // here. In both the above cases, we would return `nullptr` and can skip SessionInfo
4274  // updates.
4275  if (!session_id.empty()) {
4276  try {
4277  mapd_lock_guard<mapd_shared_mutex> write_lock(sessions_mutex_);
4278  return get_session_it_unsafe(session_id)->second;
4279  } catch (TMapDException&) {
4280  return nullptr;
4281  }
4282  }
4283  return nullptr;
4284 }
SessionMap::iterator get_session_it_unsafe(const TSessionId &session)
mapd_shared_mutex sessions_mutex_
Definition: MapDHandler.h:452
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_status()

void MapDHandler::get_status ( std::vector< TServerStatus > &  _return,
const TSessionId &  session 
)
override

Definition at line 466 of file MapDHandler.cpp.

References g_cluster, get_hostname(), LeafAggregator::getLeafStatus(), leaf_aggregator_, LeafAggregator::leafCount(), LOG_SESSION, MAPD_EDITION, MAPD_RELEASE, read_only_, render_handler_, and start_time_.

467  {
469  const auto rendering_enabled = bool(render_handler_);
470  TServerStatus ret;
471  ret.read_only = read_only_;
472  ret.version = MAPD_RELEASE;
473  ret.rendering_enabled = rendering_enabled;
474  ret.poly_rendering_enabled = rendering_enabled;
475  ret.start_time = start_time_;
476  ret.edition = MAPD_EDITION;
477  ret.host_name = get_hostname();
478 
479  // TSercivePort tcp_port{}
480 
481  if (g_cluster) {
482  ret.role =
483  (leaf_aggregator_.leafCount() > 0) ? TRole::type::AGGREGATOR : TRole::type::LEAF;
484  } else {
485  ret.role = TRole::type::SERVER;
486  }
487 
488  _return.push_back(ret);
489  if (leaf_aggregator_.leafCount() > 0) {
490  std::vector<TServerStatus> leaf_status = leaf_aggregator_.getLeafStatus(session);
491  _return.insert(_return.end(), leaf_status.begin(), leaf_status.end());
492  }
493 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
std::unique_ptr< MapDRenderHandler > render_handler_
Definition: MapDHandler.h:457
static const std::string MAPD_EDITION
Definition: release.h:41
int64_t start_time_
Definition: MapDHandler.h:454
const bool read_only_
Definition: MapDHandler.h:449
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:439
bool g_cluster
std::string get_hostname()
Definition: SysInfo.cpp:6
size_t leafCount() const
static const std::string MAPD_RELEASE
Definition: release.h:43
std::vector< TServerStatus > getLeafStatus(TSessionId session)
TSessionId session
+ Here is the call graph for this function:

◆ get_table_details()

void MapDHandler::get_table_details ( TTableDetails &  _return,
const TSessionId &  session,
const std::string &  table_name 
)
override

Definition at line 1613 of file MapDHandler.cpp.

References get_table_details_impl(), and LOG_SESSION.

Referenced by fill_column_names_by_table(), and get_uc_compatible_table_names_by_column().

1615  {
1616  LOG_SESSION(session, "table_name", table_name);
1617  get_table_details_impl(_return, session, table_name, false, false);
1618 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
void get_table_details_impl(TTableDetails &_return, const TSessionId &session, const std::string &table_name, const bool get_system, const bool get_physical)
TSessionId session
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_table_details_impl()

void MapDHandler::get_table_details_impl ( TTableDetails &  _return,
const TSessionId &  session,
const std::string &  table_name,
const bool  get_system,
const bool  get_physical 
)
private

Definition at line 1620 of file MapDHandler.cpp.

References CPU, Data_Namespace::CPU_LEVEL, execute_rel_alg(), fixup_row_descriptor(), get_session_copy(), hasTableAccessPrivileges(), mapd_parameters_, parse_to_ra(), populateThriftColumnType(), run-benchmark-import::result, table_is_replicated(), and THROW_MAPD_EXCEPTION.

Referenced by get_internal_table_details(), and get_table_details().

1624  {
1625  auto session_info = get_session_copy(session);
1626  auto& cat = session_info.getCatalog();
1627  auto td = cat.getMetadataForTable(
1628  table_name,
1629  false); // don't populate fragmenter on this call since we only want metadata
1630  if (!td) {
1631  THROW_MAPD_EXCEPTION("Table " + table_name + " doesn't exist");
1632  }
1633  if (td->isView) {
1634  try {
1635  if (hasTableAccessPrivileges(td, session)) {
1636  session_info.make_superuser();
1637  const auto query_ra =
1638  parse_to_ra(td->viewSQL, {}, session_info, boost::none, mapd_parameters_);
1640  execute_rel_alg(result,
1641  query_ra,
1642  true,
1643  session_info,
1645  -1,
1646  -1,
1647  false,
1648  true,
1649  false,
1650  false,
1651  false);
1652  _return.row_desc = fixup_row_descriptor(result.row_set.row_desc, cat);
1653  } else {
1654  THROW_MAPD_EXCEPTION("User has no access privileges to table " + table_name);
1655  }
1656  } catch (std::exception& e) {
1657  TColumnType tColumnType;
1658  tColumnType.col_name = "BROKEN_VIEW_PLEASE_FIX";
1659  _return.row_desc.push_back(tColumnType);
1660  }
1661  } else {
1662  try {
1663  if (hasTableAccessPrivileges(td, session)) {
1664  const auto col_descriptors =
1665  cat.getAllColumnMetadataForTable(td->tableId, get_system, true, get_physical);
1666  const auto deleted_cd = cat.getDeletedColumn(td);
1667  for (const auto cd : col_descriptors) {
1668  if (cd == deleted_cd) {
1669  continue;
1670  }
1671  _return.row_desc.push_back(populateThriftColumnType(&cat, cd));
1672  }
1673  } else {
1674  THROW_MAPD_EXCEPTION("User has no access privileges to table " + table_name);
1675  }
1676  } catch (const std::runtime_error& e) {
1677  THROW_MAPD_EXCEPTION(e.what());
1678  }
1679  }
1680  _return.fragment_size = td->maxFragRows;
1681  _return.page_size = td->fragPageSize;
1682  _return.max_rows = td->maxRows;
1683  _return.view_sql = td->viewSQL;
1684  _return.shard_count = td->nShards;
1685  _return.key_metainfo = td->keyMetainfo;
1686  _return.is_temporary = td->persistenceLevel == Data_Namespace::MemoryLevel::CPU_LEVEL;
1687  _return.partition_detail =
1688  td->partitions.empty()
1689  ? TPartitionDetail::DEFAULT
1690  : (table_is_replicated(td)
1691  ? TPartitionDetail::REPLICATED
1692  : (td->partitions == "SHARDED" ? TPartitionDetail::SHARDED
1693  : TPartitionDetail::OTHER));
1694 }
TColumnType populateThriftColumnType(const Catalog_Namespace::Catalog *cat, const ColumnDescriptor *cd)
std::string parse_to_ra(const std::string &query_str, const std::vector< TFilterPushDownInfo > &filter_push_down_info, const Catalog_Namespace::SessionInfo &session_info, OptionalTableMap tableNames, const MapDParameters mapd_parameters, RenderInfo *render_info=nullptr)
#define THROW_MAPD_EXCEPTION(errstr)
TRowDescriptor fixup_row_descriptor(const TRowDescriptor &row_desc, const Catalog_Namespace::Catalog &cat)
std::vector< PushedDownFilterInfo > execute_rel_alg(TQueryResult &_return, const std::string &query_ra, const bool column_format, const Catalog_Namespace::SessionInfo &session_info, const ExecutorDeviceType executor_device_type, const int32_t first_n, const int32_t at_most_n, const bool just_explain, const bool just_validate, const bool find_push_down_candidates, const bool just_calcite_explain, const bool explain_optimized_ir) const
const MapDParameters & mapd_parameters_
Definition: MapDHandler.h:456
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
bool table_is_replicated(const TableDescriptor *td)
TSessionId session
bool hasTableAccessPrivileges(const TableDescriptor *td, const TSessionId &session)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_table_epoch()

int32_t MapDHandler::get_table_epoch ( const TSessionId &  session,
const int32_t  db_id,
const int32_t  table_id 
)
override

Definition at line 5492 of file MapDHandler.cpp.

References get_session_copy(), LeafAggregator::get_table_epochLeaf(), leaf_aggregator_, LeafAggregator::leafCount(), and LOG_SESSION.

5494  {
5496  const auto session_info = get_session_copy(session);
5497  auto& cat = session_info.getCatalog();
5498 
5499  if (leaf_aggregator_.leafCount() > 0) {
5500  return leaf_aggregator_.get_table_epochLeaf(session_info, db_id, table_id);
5501  }
5502  return cat.getTableEpoch(db_id, table_id);
5503 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
int32_t get_table_epochLeaf(const Catalog_Namespace::SessionInfo &parent_session_info, const int32_t db_id, const int32_t table_id)
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:439
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
size_t leafCount() const
TSessionId session
+ Here is the call graph for this function:

◆ get_table_epoch_by_name()

int32_t MapDHandler::get_table_epoch_by_name ( const TSessionId &  session,
const std::string &  table_name 
)
override

Definition at line 5505 of file MapDHandler.cpp.

References get_session_copy(), LeafAggregator::get_table_epochLeaf(), leaf_aggregator_, LeafAggregator::leafCount(), and LOG_SESSION.

5506  {
5507  LOG_SESSION(session, "table_name", table_name);
5508  const auto session_info = get_session_copy(session);
5509  auto& cat = session_info.getCatalog();
5510  auto td = cat.getMetadataForTable(
5511  table_name,
5512  false); // don't populate fragmenter on this call since we only want metadata
5513  int32_t db_id = cat.getCurrentDB().dbId;
5514  if (leaf_aggregator_.leafCount() > 0) {
5515  return leaf_aggregator_.get_table_epochLeaf(session_info, db_id, td->tableId);
5516  }
5517  return cat.getTableEpoch(db_id, td->tableId);
5518 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
int32_t get_table_epochLeaf(const Catalog_Namespace::SessionInfo &parent_session_info, const int32_t db_id, const int32_t table_id)
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:439
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
size_t leafCount() const
TSessionId session
+ Here is the call graph for this function:

◆ get_tables()

void MapDHandler::get_tables ( std::vector< std::string > &  _return,
const TSessionId &  session 
)
override

Definition at line 1764 of file MapDHandler.cpp.

References GET_PHYSICAL_TABLES_AND_VIEWS, get_tables_impl(), and LOG_SESSION.

Referenced by get_completion_hints_unsorted().

1765  {
1768 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
void get_tables_impl(std::vector< std::string > &table_names, const TSessionId &session, const GetTablesType get_tables_type)
TSessionId session
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_tables_impl()

void MapDHandler::get_tables_impl ( std::vector< std::string > &  table_names,
const TSessionId &  session,
const GetTablesType  get_tables_type 
)
private

Definition at line 1729 of file MapDHandler.cpp.

References GET_PHYSICAL_TABLES, get_session_copy(), GET_VIEWS, hasTableAccessPrivileges(), and run-benchmark-import::tables.

Referenced by get_physical_tables(), get_tables(), and get_views().

1731  {
1732  const auto session_info = get_session_copy(session);
1733  auto& cat = session_info.getCatalog();
1734  const auto tables = cat.getAllTableMetadata();
1735  for (const auto td : tables) {
1736  if (td->shard >= 0) {
1737  // skip shards, they're not standalone tables
1738  continue;
1739  }
1740  switch (get_tables_type) {
1741  case GET_PHYSICAL_TABLES: {
1742  if (td->isView) {
1743  continue;
1744  }
1745  break;
1746  }
1747  case GET_VIEWS: {
1748  if (!td->isView) {
1749  continue;
1750  }
1751  }
1752  default: {
1753  break;
1754  }
1755  }
1756  if (!hasTableAccessPrivileges(td, session)) {
1757  // skip table, as there are no privileges to access it
1758  continue;
1759  }
1760  table_names.push_back(td->tableName);
1761  }
1762 }
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
TSessionId session
bool hasTableAccessPrivileges(const TableDescriptor *td, const TSessionId &session)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_tables_meta()

void MapDHandler::get_tables_meta ( std::vector< TTableMeta > &  _return,
const TSessionId &  session 
)
override

Definition at line 1782 of file MapDHandler.cpp.

References CPU, execute_rel_alg(), get_session_copy(), hasTableAccessPrivileges(), LOG, LOG_SESSION, mapd_parameters_, parse_to_ra(), run-benchmark-import::result, table_is_replicated(), run-benchmark-import::tables, THROW_MAPD_EXCEPTION, ThriftSerializers::type_info_to_thrift(), and logger::WARNING.

1783  {
1785  const auto session_info = get_session_copy(session);
1786  auto& cat = session_info.getCatalog();
1787  const auto tables = cat.getAllTableMetadata();
1788  _return.reserve(tables.size());
1789 
1790  for (const auto td : tables) {
1791  if (td->shard >= 0) {
1792  // skip shards, they're not standalone tables
1793  continue;
1794  }
1795  if (!hasTableAccessPrivileges(td, session)) {
1796  // skip table, as there are no privileges to access it
1797  continue;
1798  }
1799 
1800  TTableMeta ret;
1801  ret.table_name = td->tableName;
1802  ret.is_view = td->isView;
1803  ret.is_replicated = table_is_replicated(td);
1804  ret.shard_count = td->nShards;
1805  ret.max_rows = td->maxRows;
1806  ret.table_id = td->tableId;
1807 
1808  std::vector<TTypeInfo> col_types;
1809  std::vector<std::string> col_names;
1810  size_t num_cols = 0;
1811  if (td->isView) {
1812  try {
1813  const auto query_ra =
1814  parse_to_ra(td->viewSQL, {}, session_info, boost::none, mapd_parameters_);
1816  execute_rel_alg(result,
1817  query_ra,
1818  true,
1819  session_info,
1821  -1,
1822  -1,
1823  false,
1824  true,
1825  false,
1826  false,
1827  false);
1828  num_cols = result.row_set.row_desc.size();
1829  for (const auto col : result.row_set.row_desc) {
1830  if (col.is_physical) {
1831  num_cols--;
1832  continue;
1833  }
1834  col_types.push_back(col.col_type);
1835  col_names.push_back(col.col_name);
1836  }
1837  } catch (std::exception& e) {
1838  LOG(WARNING) << "get_tables_meta: Ignoring broken view: " << td->tableName;
1839  }
1840  } else {
1841  try {
1842  if (hasTableAccessPrivileges(td, session)) {
1843  const auto col_descriptors =
1844  cat.getAllColumnMetadataForTable(td->tableId, false, true, false);
1845  const auto deleted_cd = cat.getDeletedColumn(td);
1846  for (const auto cd : col_descriptors) {
1847  if (cd == deleted_cd) {
1848  continue;
1849  }
1850  col_types.push_back(ThriftSerializers::type_info_to_thrift(cd->columnType));
1851  col_names.push_back(cd->columnName);
1852  }
1853  num_cols = col_descriptors.size();
1854  } else {
1855  continue;
1856  }
1857  } catch (const std::runtime_error& e) {
1858  THROW_MAPD_EXCEPTION(e.what());
1859  }
1860  }
1861 
1862  ret.num_cols = num_cols;
1863  std::copy(col_types.begin(), col_types.end(), std::back_inserter(ret.col_types));
1864  std::copy(col_names.begin(), col_names.end(), std::back_inserter(ret.col_names));
1865 
1866  _return.push_back(ret);
1867  }
1868 }
#define LOG_SESSION(session,...)
Definition: MapDHandler.h:742
std::string parse_to_ra(const std::string &query_str, const std::vector< TFilterPushDownInfo > &filter_push_down_info, const Catalog_Namespace::SessionInfo &session_info, OptionalTableMap tableNames, const MapDParameters mapd_parameters, RenderInfo *render_info=nullptr)
#define LOG(tag)
Definition: Logger.h:182
#define THROW_MAPD_EXCEPTION(errstr)
std::vector< PushedDownFilterInfo > execute_rel_alg(TQueryResult &_return, const std::string &query_ra, const bool column_format, const Catalog_Namespace::SessionInfo &session_info, const ExecutorDeviceType executor_device_type, const int32_t first_n, const int32_t at_most_n, const bool just_explain, const bool just_validate, const bool find_push_down_candidates, const bool just_calcite_explain, const bool explain_optimized_ir) const
const MapDParameters & mapd_parameters_
Definition: MapDHandler.h:456
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
bool table_is_replicated(const TableDescriptor *td)
TTypeInfo type_info_to_thrift(const SQLTypeInfo &ti)
TSessionId session
bool hasTableAccessPrivileges(const TableDescriptor *td, const TSessionId &session)
+ Here is the call graph for this function:

◆ get_token_based_completions()

void MapDHandler::get_token_based_completions ( std::vector< TCompletionHint > &  hints,
const TSessionId &  session,
const std::vector< std::string > &  visible_tables,
const std::string &  sql,
const int  cursor 
)
private

Definition at line 1066 of file MapDHandler.cpp.

References fill_column_names_by_table(),