OmniSciDB  29e35f4d58
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_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 krb5_connect (TKrb5Session &session, const std::string &token, const std::string &dbname) 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 Catalog_Namespace::SessionInfo &session_info)
 
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_query_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_role (const TSessionId &sessionId, const std::string &granteeName, const std::string &roleName) 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, const TSessionId &session) override
 
void register_runtime_extension_functions (const TSessionId &session, const std::vector< TUserDefinedFunction > &udfs, const std::vector< TUserDefinedTableFunction > &udtfs, 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)
 
template<typename... ARGS>
std::shared_ptr< query_state::QueryStatecreate_query_state (ARGS &&... args)
 
Catalog_Namespace::SessionInfo get_session_copy (const TSessionId &session)
 
std::shared_ptr< Catalog_Namespace::SessionInfoget_session_copy_ptr (const TSessionId &session)
 
template<>
SessionMap::iterator get_session_it_unsafe (const TSessionId &session, mapd_shared_lock< mapd_shared_mutex > &read_lock)
 
template<>
SessionMap::iterator get_session_it_unsafe (const TSessionId &session, mapd_lock_guard< mapd_shared_mutex > &write_lock)
 

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, query_state::StdLog &stdlog)
 
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 Catalog_Namespace::SessionInfo &, const GetTablesType get_tables_type)
 
void get_table_details_impl (TTableDetails &_return, query_state::StdLog &stdlog, 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)
 
template<typename SESSION_MAP_LOCK >
SessionMap::iterator get_session_it_unsafe (const TSessionId &session, SESSION_MAP_LOCK &lock)
 
std::string parse_to_ra (QueryStateProxy, const std::string &query_str, const std::vector< TFilterPushDownInfo > &filter_push_down_info, OptionalTableMap tableNames, const MapDParameters mapd_parameters, RenderInfo *render_info=nullptr)
 
void sql_execute_impl (TQueryResult &_return, QueryStateProxy, 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, QueryStateProxy)
 
std::vector< PushedDownFilterInfoexecute_rel_alg (TQueryResult &_return, QueryStateProxy, const std::string &query_ra, const bool column_format, 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, QueryStateProxy, std::string &query_ra, const bool column_format, 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::vector< PushedDownFilterInfo > filter_push_down_requests)
 
void execute_rel_alg_df (TDataFrame &_return, const std::string &query_ra, QueryStateProxy query_state_proxy, 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, QueryStateProxy query_state_proxy, 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, QueryStateProxy query_state_proxy, 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, query_state::StdLog &stdlog, const std::string &sql, const int cursor)
 
void get_token_based_completions (std::vector< TCompletionHint > &hints, query_state::StdLog &stdlog, std::vector< std::string > &visible_tables, const std::string &sql, const int cursor)
 
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 (std::vector< std::string > &table_names, query_state::StdLog &stdlog)
 
std::unordered_set< std::string > get_uc_compatible_table_names_by_column (const std::unordered_set< std::string > &uc_column_names, std::vector< std::string > &table_names, query_state::StdLog &stdlog)
 
void check_and_invalidate_sessions (Parser::DDLStmt *ddl)
 
template<typename STMT_TYPE >
void invalidate_sessions (std::string &name, STMT_TYPE *stmt)
 
std::string const createInMemoryCalciteSession (const std::shared_ptr< Catalog_Namespace::Catalog > &catalog_ptr)
 
bool isInMemoryCalciteSession (const Catalog_Namespace::UserMetadata user_meta)
 
void removeInMemoryCalciteSession (const std::string &session_id)
 

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

query_state::QueryStates query_states_
 
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 MapDRenderHandler::Impl
 
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 114 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_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 166 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_, logger::FATAL, g_cluster, UdfCompiler::getAstFileName(), GPU, idle_session_duration_, import_path_, logger::INFO, table_functions::TableFunctionsFactory::init(), intel_jit_profile_, jit_debug_, leaf_aggregator_, leaf_handler_, LeafAggregator::leafCount(), legacy_syntax_, LOG, mapd_parameters_, MAPD_RELEASE, MapDAggHandler, MapDLeafHandler, max_session_duration_, read_only_, render_handler_, runtime_udf_registration_enabled_, session_id_dist_, start_time_, string_leaves_, and super_user_rights_.

190  : leaf_aggregator_(db_leaves)
191  , string_leaves_(string_leaves)
192  , base_data_path_(base_data_path)
193  , random_gen_(std::random_device{}())
194  , session_id_dist_(0, INT32_MAX)
195  , jit_debug_(jit_debug)
196  , intel_jit_profile_(intel_jit_profile)
197  , allow_multifrag_(allow_multifrag)
198  , read_only_(read_only)
199  , allow_loop_joins_(allow_loop_joins)
200  , authMetadata_(authMetadata)
201  , mapd_parameters_(mapd_parameters)
202  , legacy_syntax_(legacy_syntax)
203  , super_user_rights_(false)
204  , idle_session_duration_(idle_session_duration * 60)
205  , max_session_duration_(max_session_duration * 60)
206  , runtime_udf_registration_enabled_(enable_runtime_udf_registration)
207  , _was_geo_copy_from(false) {
208  LOG(INFO) << "OmniSci Server " << MAPD_RELEASE;
209  bool is_rendering_enabled = enable_rendering;
210 
211  try {
212  if (cpu_only) {
213  is_rendering_enabled = false;
215  cpu_mode_only_ = true;
216  } else {
217 #ifdef HAVE_CUDA
219  cpu_mode_only_ = false;
220 #else
222  LOG(ERROR) << "This build isn't CUDA enabled, will run on CPU";
223  cpu_mode_only_ = true;
224  is_rendering_enabled = false;
225 #endif
226  }
227  } catch (const std::exception& e) {
228  LOG(FATAL) << "Failed to executor device type: " << e.what();
229  }
230 
231  const auto data_path = boost::filesystem::path(base_data_path_) / "mapd_data";
232  // calculate the total amount of memory we need to reserve from each gpu that the Buffer
233  // manage cannot ask for
234  size_t total_reserved = reserved_gpu_mem;
235  if (is_rendering_enabled) {
236  total_reserved += render_mem_bytes;
237  }
238 
239  try {
240  data_mgr_.reset(new Data_Namespace::DataMgr(data_path.string(),
241  mapd_parameters,
243  num_gpus,
244  start_gpu,
245  total_reserved,
246  num_reader_threads));
247  } catch (const std::exception& e) {
248  LOG(FATAL) << "Failed to initialize data manager: " << e.what();
249  }
250 
251  std::string udf_ast_filename("");
252 
253  try {
254  if (!udf_filename.empty()) {
255  UdfCompiler compiler(udf_filename);
256  int compile_result = compiler.compileUdf();
257 
258  if (compile_result == 0) {
259  udf_ast_filename = compiler.getAstFileName();
260  }
261  }
262  } catch (const std::exception& e) {
263  LOG(FATAL) << "Failed to initialize UDF compiler: " << e.what();
264  }
265 
266  try {
267  calcite_ =
268  std::make_shared<Calcite>(mapd_parameters, base_data_path_, udf_ast_filename);
269  } catch (const std::exception& e) {
270  LOG(FATAL) << "Failed to initialize Calcite server: " << e.what();
271  }
272 
273  try {
274  ExtensionFunctionsWhitelist::add(calcite_->getExtensionFunctionWhitelist());
275  if (!udf_filename.empty()) {
276  ExtensionFunctionsWhitelist::addUdfs(calcite_->getUserDefinedFunctionWhitelist());
277  }
278  } catch (const std::exception& e) {
279  LOG(FATAL) << "Failed to initialize extension functions: " << e.what();
280  }
281 
282  try {
284  } catch (const std::exception& e) {
285  LOG(FATAL) << "Failed to initialize table functions factory: " << e.what();
286  }
287 
288  if (!data_mgr_->gpusPresent() && !cpu_mode_only_) {
290  LOG(ERROR) << "No GPUs detected, falling back to CPU mode";
291  cpu_mode_only_ = true;
292  }
293 
294  switch (executor_device_type_) {
296  LOG(INFO) << "Started in GPU mode" << std::endl;
297  break;
299  LOG(INFO) << "Started in CPU mode" << std::endl;
300  break;
301  }
302 
303  try {
304  SysCatalog::instance().init(base_data_path_,
305  data_mgr_,
306  authMetadata,
307  calcite_,
308  false,
309  !db_leaves.empty(),
311  } catch (const std::exception& e) {
312  LOG(FATAL) << "Failed to initialize system catalog: " << e.what();
313  }
314 
315  import_path_ = boost::filesystem::path(base_data_path_) / "mapd_import";
316  start_time_ = std::time(nullptr);
317 
318  if (is_rendering_enabled) {
319  try {
320  render_handler_.reset(
321  new MapDRenderHandler(this, render_mem_bytes, 0u, false, 0, mapd_parameters_));
322  } catch (const std::exception& e) {
323  LOG(ERROR) << "Backend rendering disabled: " << e.what();
324  }
325  }
326 
327  if (leaf_aggregator_.leafCount() > 0) {
328  try {
329  agg_handler_.reset(new MapDAggHandler(this));
330  } catch (const std::exception& e) {
331  LOG(ERROR) << "Distributed aggregator support disabled: " << e.what();
332  }
333  } else if (g_cluster) {
334  try {
335  leaf_handler_.reset(new MapDLeafHandler(this));
336  } catch (const std::exception& e) {
337  LOG(ERROR) << "Distributed leaf support disabled: " << e.what();
338  }
339  }
340 }
const bool allow_loop_joins_
Definition: MapDHandler.h:454
static void addUdfs(const std::string &json_func_sigs)
std::unique_ptr< MapDRenderHandler > render_handler_
Definition: MapDHandler.h:461
bool g_cluster
boost::filesystem::path import_path_
Definition: MapDHandler.h:446
#define LOG(tag)
Definition: Logger.h:188
static void add(const std::string &json_func_sigs)
friend class MapDAggHandler
Definition: MapDHandler.h:705
std::unique_ptr< MapDAggHandler > agg_handler_
Definition: MapDHandler.h:462
bool cpu_mode_only_
Definition: MapDHandler.h:455
const bool runtime_udf_registration_enabled_
Definition: MapDHandler.h:688
const bool intel_jit_profile_
Definition: MapDHandler.h:451
int64_t start_time_
Definition: MapDHandler.h:458
const int idle_session_duration_
Definition: MapDHandler.h:685
const MapDParameters & mapd_parameters_
Definition: MapDHandler.h:460
bool allow_multifrag_
Definition: MapDHandler.h:452
const bool read_only_
Definition: MapDHandler.h:453
const std::vector< LeafHostInfo > string_leaves_
Definition: MapDHandler.h:444
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:443
std::shared_ptr< Calcite > calcite_
Definition: MapDHandler.h:464
bool _was_geo_copy_from
Definition: MapDHandler.h:690
std::shared_ptr< Data_Namespace::DataMgr > data_mgr_
Definition: MapDHandler.h:441
ExecutorDeviceType executor_device_type_
Definition: MapDHandler.h:447
std::uniform_int_distribution< int64_t > session_id_dist_
Definition: MapDHandler.h:449
friend class MapDLeafHandler
Definition: MapDHandler.h:706
const AuthMetadata & authMetadata_
Definition: MapDHandler.h:459
std::unique_ptr< MapDLeafHandler > leaf_handler_
Definition: MapDHandler.h:463
size_t leafCount() const
static const std::string MAPD_RELEASE
Definition: release.h:43
const int max_session_duration_
Definition: MapDHandler.h:686
const bool jit_debug_
Definition: MapDHandler.h:450
bool super_user_rights_
Definition: MapDHandler.h:682
std::default_random_engine random_gen_
Definition: MapDHandler.h:448
const bool legacy_syntax_
Definition: MapDHandler.h:465
const std::string base_data_path_
Definition: MapDHandler.h:445
+ Here is the call graph for this function:

◆ ~MapDHandler()

MapDHandler::~MapDHandler ( )
override

Definition at line 342 of file MapDHandler.cpp.

342 {}

Member Function Documentation

◆ apply_copy_to_shim()

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

Definition at line 1059 of file MapDHandler.cpp.

References apply_shim(), and run_benchmark_import::result.

Referenced by sql_execute_impl().

1059  {
1060  auto result = query_str;
1061  {
1062  // boost::regex copy_to{R"(COPY\s\((.*)\)\sTO\s(.*))", boost::regex::extended |
1063  // boost::regex::icase};
1064  boost::regex copy_to{R"(COPY\s*\(([^#])(.+)\)\s+TO\s)",
1065  boost::regex::extended | boost::regex::icase};
1066  apply_shim(result, copy_to, [](std::string& result, const boost::smatch& what) {
1067  result.replace(
1068  what.position(), what.length(), "COPY (#~#" + what[1] + what[2] + "#~#) TO ");
1069  });
1070  }
1071  return result;
1072 }
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 5475 of file MapDHandler.cpp.

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

5477  {
5478  if (!leaf_handler_) {
5479  THROW_MAPD_EXCEPTION("Distributed support is disabled.");
5480  }
5481  LOG(INFO) << "BROADCAST-SERIALIZED-ROWS id:" << query_id;
5482  auto time_ms = measure<>::execution([&]() {
5483  try {
5484  leaf_handler_->broadcast_serialized_rows(serialized_rows, row_desc, query_id);
5485  } catch (std::exception& e) {
5486  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
5487  }
5488  });
5489  LOG(INFO) << "BROADCAST-SERIALIZED-ROWS COMPLETED " << time_ms << "ms";
5490 }
#define LOG(tag)
Definition: Logger.h:188
#define THROW_MAPD_EXCEPTION(errstr)
std::unique_ptr< MapDLeafHandler > leaf_handler_
Definition: MapDHandler.h:463
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 4876 of file MapDHandler.cpp.

References invalidate_sessions().

Referenced by sql_execute_impl().

4876  {
4877  const auto drop_db_stmt = dynamic_cast<Parser::DropDBStmt*>(ddl);
4878  if (drop_db_stmt) {
4879  invalidate_sessions(*drop_db_stmt->getDatabaseName(), drop_db_stmt);
4880  return;
4881  }
4882  const auto rename_db_stmt = dynamic_cast<Parser::RenameDatabaseStmt*>(ddl);
4883  if (rename_db_stmt) {
4884  invalidate_sessions(*rename_db_stmt->getPreviousDatabaseName(), rename_db_stmt);
4885  return;
4886  }
4887  const auto drop_user_stmt = dynamic_cast<Parser::DropUserStmt*>(ddl);
4888  if (drop_user_stmt) {
4889  invalidate_sessions(*drop_user_stmt->getUserName(), drop_user_stmt);
4890  return;
4891  }
4892  const auto rename_user_stmt = dynamic_cast<Parser::RenameUserStmt*>(ddl);
4893  if (rename_user_stmt) {
4894  invalidate_sessions(*rename_user_stmt->getOldUserName(), rename_user_stmt);
4895  return;
4896  }
4897 }
void invalidate_sessions(std::string &name, STMT_TYPE *stmt)
Definition: MapDHandler.h:717
+ 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 3537 of file MapDHandler.cpp.

References Importer_NS::Importer::gdalFileExists().

Referenced by detect_column_types(), and import_geo_table().

3538  {
3539  const std::list<std::string> shp_ext{".shp", ".shx", ".dbf"};
3540  if (std::find(shp_ext.begin(),
3541  shp_ext.end(),
3542  boost::algorithm::to_lower_copy(file_path.extension().string())) !=
3543  shp_ext.end()) {
3544  for (auto ext : shp_ext) {
3545  auto aux_file = file_path;
3547  aux_file.replace_extension(boost::algorithm::to_upper_copy(ext)).string(),
3548  copy_params) &&
3549  !Importer_NS::Importer::gdalFileExists(aux_file.replace_extension(ext).string(),
3550  copy_params)) {
3551  throw std::runtime_error("required file for shapefile does not exist: " +
3552  aux_file.filename().string());
3553  }
3554  }
3555  }
3556 }
static bool gdalFileExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:4461
+ 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 344 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().

344  {
346  THROW_MAPD_EXCEPTION(str + " disabled: server running in read-only mode.");
347  }
348 }
#define THROW_MAPD_EXCEPTION(errstr)
const bool read_only_
Definition: MapDHandler.h:453
+ 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 4390 of file MapDHandler.cpp.

References idle_session_duration_, isInMemoryCalciteSession(), max_session_duration_, and run_benchmark_import::start_time.

4390  {
4391  if (session_it->second.use_count() > 2 ||
4392  isInMemoryCalciteSession(session_it->second->get_currentUser())) {
4393  // SessionInfo is being used in more than one active operation. Original copy + one
4394  // stored in StdLog. Skip the checks.
4395  return;
4396  }
4397  time_t last_used_time = session_it->second->get_last_used_time();
4398  time_t start_time = session_it->second->get_start_time();
4399  if ((time(0) - last_used_time) > idle_session_duration_) {
4400  throw ForceDisconnect("Idle Session Timeout. User should re-authenticate.");
4401  } else if ((time(0) - start_time) > max_session_duration_) {
4402  throw ForceDisconnect("Maximum active Session Timeout. User should re-authenticate.");
4403  }
4404 }
bool isInMemoryCalciteSession(const Catalog_Namespace::UserMetadata user_meta)
const int idle_session_duration_
Definition: MapDHandler.h:685
const int max_session_duration_
Definition: MapDHandler.h:686
+ Here is the call 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 5424 of file MapDHandler.cpp.

References get_session_ptr(), leaf_handler_, STDLOG, and THROW_MAPD_EXCEPTION.

5426  {
5427  auto stdlog = STDLOG(get_session_ptr(session));
5428  if (!leaf_handler_) {
5429  THROW_MAPD_EXCEPTION("Distributed support is disabled.");
5430  }
5431  try {
5432  leaf_handler_->check_table_consistency(_return, session, table_id);
5433  } catch (std::exception& e) {
5434  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
5435  }
5436 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
#define THROW_MAPD_EXCEPTION(errstr)
std::unique_ptr< MapDLeafHandler > leaf_handler_
Definition: MapDHandler.h:463
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ check_table_load_privileges() [1/2]

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

Definition at line 4463 of file MapDHandler.cpp.

References get_session_copy().

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

4464  {
4465  const auto session_info = get_session_copy(session);
4466  check_table_load_privileges(session_info, table_name);
4467 }
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
void check_table_load_privileges(const TSessionId &session, const std::string &table_name)
+ 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 4446 of file MapDHandler.cpp.

References Catalog_Namespace::SessionInfo::get_currentUser(), Catalog_Namespace::SessionInfo::getCatalog(), AccessPrivileges::INSERT_INTO_TABLE, DBObject::loadKey(), DBObject::setPrivileges(), TableDBObjectType, and THROW_MAPD_EXCEPTION.

4448  {
4449  auto user_metadata = session_info.get_currentUser();
4450  auto& cat = session_info.getCatalog();
4451  DBObject dbObject(table_name, TableDBObjectType);
4452  dbObject.loadKey(cat);
4453  dbObject.setPrivileges(AccessPrivileges::INSERT_INTO_TABLE);
4454  std::vector<DBObject> privObjects;
4455  privObjects.push_back(dbObject);
4456  if (!SysCatalog::instance().checkPrivileges(user_metadata, privObjects)) {
4457  THROW_MAPD_EXCEPTION("Violation of access privileges: user " +
4458  user_metadata.userName + " has no insert privileges for table " +
4459  table_name + ".");
4460  }
4461 }
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 5623 of file MapDHandler.cpp.

References get_session_ptr(), and STDLOG.

5625  {
5626  auto stdlog = STDLOG(get_session_ptr(session));
5627  auto session_ptr = stdlog.getConstSessionInfo();
5628  auto& cat = session_ptr->getCatalog();
5629  cat.getDataMgr().checkpoint(db_id, table_id);
5630 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ clear_cpu_memory()

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

Definition at line 2094 of file MapDHandler.cpp.

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

2094  {
2095  auto stdlog = STDLOG(get_session_ptr(session));
2096  auto session_ptr = stdlog.getConstSessionInfo();
2097  if (!session_ptr->get_currentUser().isSuper) {
2098  THROW_MAPD_EXCEPTION("Superuser privilege is required to run clear_cpu_memory");
2099  }
2100  try {
2102  } catch (const std::exception& e) {
2103  THROW_MAPD_EXCEPTION(e.what());
2104  }
2105  if (render_handler_) {
2106  render_handler_->clear_cpu_memory();
2107  }
2108 
2109  if (leaf_aggregator_.leafCount() > 0) {
2111  }
2112 }
std::unique_ptr< MapDRenderHandler > render_handler_
Definition: MapDHandler.h:461
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
static void clearMemory(const Data_Namespace::MemoryLevel memory_level)
Definition: Execute.cpp:157
#define THROW_MAPD_EXCEPTION(errstr)
void clear_leaf_cpu_memory(const TSessionId session)
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:443
size_t leafCount() const
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ clear_gpu_memory()

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

Definition at line 2074 of file MapDHandler.cpp.

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

2074  {
2075  auto stdlog = STDLOG(get_session_ptr(session));
2076  auto session_ptr = stdlog.getConstSessionInfo();
2077  if (!session_ptr->get_currentUser().isSuper) {
2078  THROW_MAPD_EXCEPTION("Superuser privilege is required to run clear_gpu_memory");
2079  }
2080  try {
2082  } catch (const std::exception& e) {
2083  THROW_MAPD_EXCEPTION(e.what());
2084  }
2085  if (render_handler_) {
2086  render_handler_->clear_gpu_memory();
2087  }
2088 
2089  if (leaf_aggregator_.leafCount() > 0) {
2091  }
2092 }
std::unique_ptr< MapDRenderHandler > render_handler_
Definition: MapDHandler.h:461
void clear_leaf_gpu_memory(const TSessionId session)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
static void clearMemory(const Data_Namespace::MemoryLevel memory_level)
Definition: Execute.cpp:157
#define THROW_MAPD_EXCEPTION(errstr)
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:443
size_t leafCount() const
#define STDLOG(...)
Definition: QueryState.h:225
+ 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 425 of file MapDHandler.cpp.

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

428  {
429  auto stdlog = STDLOG(); // session_info set by connect_impl()
430  mapd_lock_guard<mapd_shared_mutex> write_lock(sessions_mutex_);
431  std::string username2 = username; // login() may reset username given as argument
432  std::string dbname2 = dbname; // login() may reset dbname given as argument
434  std::shared_ptr<Catalog> cat = nullptr;
435  try {
436  cat = SysCatalog::instance().login(
437  dbname2, username2, passwd, user_meta, !super_user_rights_);
438  } catch (std::exception& e) {
439  THROW_MAPD_EXCEPTION(e.what());
440  }
441 
442  DBObject dbObject(dbname2, DatabaseDBObjectType);
443  dbObject.loadKey(*cat);
444  dbObject.setPrivileges(AccessPrivileges::ACCESS);
445  std::vector<DBObject> dbObjects;
446  dbObjects.push_back(dbObject);
447  if (!SysCatalog::instance().checkPrivileges(user_meta, dbObjects)) {
448  THROW_MAPD_EXCEPTION("Unauthorized Access: user " + username +
449  " is not allowed to access database " + dbname2 + ".");
450  }
451  connect_impl(session, passwd, dbname2, user_meta, cat, stdlog);
452  // if pki auth session will come back encrypted with user pubkey
453  SysCatalog::instance().check_for_session_encryption(passwd, session);
454 }
mapd_shared_mutex sessions_mutex_
Definition: MapDHandler.h:456
#define THROW_MAPD_EXCEPTION(errstr)
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, query_state::StdLog &stdlog)
static const AccessPrivileges ACCESS
Definition: DBObject.h:146
#define STDLOG(...)
Definition: QueryState.h:225
bool super_user_rights_
Definition: MapDHandler.h:682
+ 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,
query_state::StdLog stdlog 
)
private

Definition at line 456 of file MapDHandler.cpp.

References query_state::StdLog::appendNameValuePairs(), CHECK, LeafAggregator::connect(), executor_device_type_, generate_random_string(), logger::INFO, join(), leaf_aggregator_, LeafAggregator::leafCount(), LOG, sessions_, query_state::StdLog::setSessionInfo(), super_user_rights_, and Catalog_Namespace::UserMetadata::userName.

Referenced by connect(), and internal_connect().

461  {
462  do {
463  session = generate_random_string(32);
464  } while (sessions_.find(session) != sessions_.end());
465  std::pair<SessionMap::iterator, bool> emplace_retval =
466  sessions_.emplace(session,
467  std::make_shared<Catalog_Namespace::SessionInfo>(
468  cat, user_meta, executor_device_type_, session));
469  CHECK(emplace_retval.second);
470  auto& session_ptr = emplace_retval.first->second;
471  stdlog.setSessionInfo(session_ptr);
472  if (!super_user_rights_) { // no need to connect to leaf_aggregator_ at this time while
473  // doing warmup
474  if (leaf_aggregator_.leafCount() > 0) {
475  leaf_aggregator_.connect(*session_ptr, user_meta.userName, passwd, dbname);
476  return;
477  }
478  }
479  auto const roles = session_ptr->get_currentUser().isSuper
480  ? std::vector<std::string>{{"super"}}
481  : SysCatalog::instance().getRoles(
482  false, false, session_ptr->get_currentUser().userName);
483  stdlog.appendNameValuePairs("roles", boost::algorithm::join(roles, ","));
484  LOG(INFO) << "User " << user_meta.userName << " connected to database " << dbname
485  << " with public_session_id " << session_ptr->get_public_session_id();
486 }
SessionMap sessions_
Definition: MapDHandler.h:680
#define LOG(tag)
Definition: Logger.h:188
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)
void setSessionInfo(std::shared_ptr< Catalog_Namespace::SessionInfo >)
Definition: QueryState.cpp:226
void appendNameValuePairs(Pairs &&... pairs)
Definition: QueryState.h:302
std::string generate_random_string(const size_t len)
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:443
ExecutorDeviceType executor_device_type_
Definition: MapDHandler.h:447
#define CHECK(condition)
Definition: Logger.h:193
size_t leafCount() const
bool super_user_rights_
Definition: MapDHandler.h:682
+ 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 4848 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().

4850  {
4851  create_simple_result(_return, results, column_format, "Explanation");
4852 }
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 4854 of file MapDHandler.cpp.

References create_simple_result().

Referenced by sql_execute_impl().

4856  {
4857  create_simple_result(_return, results, column_format, "Result");
4858 }
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,
QueryStateProxy  query_state_proxy,
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 4741 of file MapDHandler.cpp.

References convert_target_metainfo(), query_state::QueryStateProxy::createTimer(), THROW_MAPD_EXCEPTION, to_string(), value_to_thrift(), and value_to_thrift_column().

Referenced by execute_rel_alg(), and execute_root_plan().

4747  {
4748  query_state::Timer timer = query_state_proxy.createTimer(__func__);
4749  _return.row_set.row_desc = convert_target_metainfo(targets);
4750  int32_t fetched{0};
4751  if (column_format) {
4752  _return.row_set.is_columnar = true;
4753  std::vector<TColumn> tcolumns(results.colCount());
4754  while (first_n == -1 || fetched < first_n) {
4755  const auto crt_row = results.getNextRow(true, true);
4756  if (crt_row.empty()) {
4757  break;
4758  }
4759  ++fetched;
4760  if (at_most_n >= 0 && fetched > at_most_n) {
4761  THROW_MAPD_EXCEPTION("The result contains more rows than the specified cap of " +
4762  std::to_string(at_most_n));
4763  }
4764  for (size_t i = 0; i < results.colCount(); ++i) {
4765  const auto agg_result = crt_row[i];
4766  value_to_thrift_column(agg_result, targets[i].get_type_info(), tcolumns[i]);
4767  }
4768  }
4769  for (size_t i = 0; i < results.colCount(); ++i) {
4770  _return.row_set.columns.push_back(tcolumns[i]);
4771  }
4772  } else {
4773  _return.row_set.is_columnar = false;
4774  while (first_n == -1 || fetched < first_n) {
4775  const auto crt_row = results.getNextRow(true, true);
4776  if (crt_row.empty()) {
4777  break;
4778  }
4779  ++fetched;
4780  if (at_most_n >= 0 && fetched > at_most_n) {
4781  THROW_MAPD_EXCEPTION("The result contains more rows than the specified cap of " +
4782  std::to_string(at_most_n));
4783  }
4784  TRow trow;
4785  trow.cols.reserve(results.colCount());
4786  for (size_t i = 0; i < results.colCount(); ++i) {
4787  const auto agg_result = crt_row[i];
4788  trow.cols.push_back(value_to_thrift(agg_result, targets[i].get_type_info()));
4789  }
4790  _return.row_set.rows.push_back(trow);
4791  }
4792  }
4793 }
static TDatum value_to_thrift(const TargetValue &tv, const SQLTypeInfo &ti)
Timer createTimer(char const *event_name)
Definition: QueryState.cpp:111
TColumnType convert_target_metainfo(const TargetMetaInfo &target, const size_t idx) const
std::string to_string(char const *&&v)
#define THROW_MAPD_EXCEPTION(errstr)
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 4700 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().

4701  {
4702  TColumnType proj_info;
4703  proj_info.col_name = target.get_resname();
4704  if (proj_info.col_name.empty()) {
4705  proj_info.col_name = "result_" + std::to_string(idx + 1);
4706  }
4707  const auto& target_ti = target.get_type_info();
4708  proj_info.col_type.type = type_to_thrift(target_ti);
4709  proj_info.col_type.encoding = encoding_to_thrift(target_ti);
4710  proj_info.col_type.nullable = !target_ti.get_notnull();
4711  proj_info.col_type.is_array = target_ti.get_type() == kARRAY;
4712  if (IS_GEO(target_ti.get_type())) {
4714  proj_info, target_ti.get_subtype(), target_ti.get_output_srid());
4715  } else {
4716  proj_info.col_type.precision = target_ti.get_precision();
4717  proj_info.col_type.scale = target_ti.get_scale();
4718  }
4719  if (target_ti.get_type() == kDATE) {
4720  proj_info.col_type.size = target_ti.get_size();
4721  }
4722  proj_info.col_type.comp_param =
4723  (target_ti.is_date_in_days() && target_ti.get_comp_param() == 0)
4724  ? 32
4725  : target_ti.get_comp_param();
4726  return proj_info;
4727 }
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:56
const std::string & get_resname() const
SQLTypes type
Definition: sqltypes.h:669
#define IS_GEO(T)
Definition: sqltypes.h:167
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 4729 of file MapDHandler.cpp.

References convert_target_metainfo().

4730  {
4731  TRowDescriptor row_desc;
4732  size_t i = 0;
4733  for (const auto target : targets) {
4734  row_desc.push_back(convert_target_metainfo(target, i));
4735  ++i;
4736  }
4737  return row_desc;
4738 }
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 2724 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_assign_render_groups, 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_explode_collections, 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().

2724  {
2725  TCopyParams copy_params;
2726  copy_params.delimiter = cp.delimiter;
2727  copy_params.null_str = cp.null_str;
2728  switch (cp.has_header) {
2730  copy_params.has_header = TImportHeaderRow::AUTODETECT;
2731  break;
2733  copy_params.has_header = TImportHeaderRow::NO_HEADER;
2734  break;
2736  copy_params.has_header = TImportHeaderRow::HAS_HEADER;
2737  break;
2738  default:
2739  CHECK(false);
2740  break;
2741  }
2742  copy_params.quoted = cp.quoted;
2743  copy_params.quote = cp.quote;
2744  copy_params.escape = cp.escape;
2745  copy_params.line_delim = cp.line_delim;
2746  copy_params.array_delim = cp.array_delim;
2747  copy_params.array_begin = cp.array_begin;
2748  copy_params.array_end = cp.array_end;
2749  copy_params.threads = cp.threads;
2750  copy_params.s3_access_key = cp.s3_access_key;
2751  copy_params.s3_secret_key = cp.s3_secret_key;
2752  copy_params.s3_region = cp.s3_region;
2753  copy_params.s3_endpoint = cp.s3_endpoint;
2754  switch (cp.file_type) {
2756  copy_params.file_type = TFileType::POLYGON;
2757  break;
2758  default:
2759  copy_params.file_type = TFileType::DELIMITED;
2760  break;
2761  }
2762  switch (cp.geo_coords_encoding) {
2763  case kENCODING_GEOINT:
2764  copy_params.geo_coords_encoding = TEncodingType::GEOINT;
2765  break;
2766  default:
2767  copy_params.geo_coords_encoding = TEncodingType::NONE;
2768  break;
2769  }
2770  copy_params.geo_coords_comp_param = cp.geo_coords_comp_param;
2771  switch (cp.geo_coords_type) {
2772  case kGEOGRAPHY:
2773  copy_params.geo_coords_type = TDatumType::GEOGRAPHY;
2774  break;
2775  case kGEOMETRY:
2776  copy_params.geo_coords_type = TDatumType::GEOMETRY;
2777  break;
2778  default:
2779  CHECK(false);
2780  break;
2781  }
2782  copy_params.geo_coords_srid = cp.geo_coords_srid;
2783  copy_params.sanitize_column_names = cp.sanitize_column_names;
2784  copy_params.geo_layer_name = cp.geo_layer_name;
2785  copy_params.geo_assign_render_groups = cp.geo_assign_render_groups;
2786  copy_params.geo_explode_collections = cp.geo_explode_collections;
2787  return copy_params;
2788 }
std::string null_str
Definition: CopyParams.h:47
EncodingType geo_coords_encoding
Definition: CopyParams.h:73
std::string s3_access_key
Definition: CopyParams.h:62
ImportHeaderRow has_header
Definition: CopyParams.h:48
std::string s3_endpoint
Definition: CopyParams.h:65
std::string s3_region
Definition: CopyParams.h:64
std::string geo_layer_name
Definition: CopyParams.h:78
#define CHECK(condition)
Definition: Logger.h:193
std::string s3_secret_key
Definition: CopyParams.h:63
int32_t geo_coords_comp_param
Definition: CopyParams.h:74
+ 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 3241 of file MapDHandler.cpp.

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

3245  {
3246  auto stdlog = STDLOG(get_session_ptr(session));
3247  auto session_ptr = stdlog.getConstSessionInfo();
3248  check_read_only("create_dashboard");
3249  auto& cat = session_ptr->getCatalog();
3250 
3251  if (!session_ptr->checkDBAccessPrivileges(DBObjectType::DashboardDBObjectType,
3253  THROW_MAPD_EXCEPTION("Not enough privileges to create a dashboard.");
3254  }
3255 
3256  auto dash = cat.getMetadataForDashboard(
3257  std::to_string(session_ptr->get_currentUser().userId), dashboard_name);
3258  if (dash) {
3259  THROW_MAPD_EXCEPTION("Dashboard with name: " + dashboard_name + " already exists.");
3260  }
3261 
3263  dd.dashboardName = dashboard_name;
3264  dd.dashboardState = dashboard_state;
3265  dd.imageHash = image_hash;
3266  dd.dashboardMetadata = dashboard_metadata;
3267  dd.userId = session_ptr->get_currentUser().userId;
3268  dd.user = session_ptr->get_currentUser().userName;
3269 
3270  try {
3271  auto id = cat.createDashboard(dd);
3272  // TODO: transactionally unsafe
3273  SysCatalog::instance().createDBObject(
3274  session_ptr->get_currentUser(), dashboard_name, DashboardDBObjectType, cat, id);
3275  return id;
3276  } catch (const std::exception& e) {
3277  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
3278  }
3279 }
static const AccessPrivileges CREATE_DASHBOARD
Definition: DBObject.h:163
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
std::string to_string(char const *&&v)
#define THROW_MAPD_EXCEPTION(errstr)
void check_read_only(const std::string &str)
#define STDLOG(...)
Definition: QueryState.h:225
+ 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 3527 of file MapDHandler.cpp.

References run_benchmark_import::type.

3529  {
3530  TColumnType ct;
3531  ct.col_name = name;
3532  ct.col_type.type = type;
3533  ct.col_type.is_array = is_array;
3534  return ct;
3535 }

◆ 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 3506 of file MapDHandler.cpp.

References get_session_ptr(), STDLOG, THROW_MAPD_EXCEPTION, LinkDescriptor::userId, LinkDescriptor::viewMetadata, and LinkDescriptor::viewState.

3509  {
3510  auto stdlog = STDLOG(get_session_ptr(session));
3511  auto session_ptr = stdlog.getConstSessionInfo();
3512  // check_read_only("create_link");
3513  auto& cat = session_ptr->getCatalog();
3514 
3515  LinkDescriptor ld;
3516  ld.userId = session_ptr->get_currentUser().userId;
3517  ld.viewState = view_state;
3518  ld.viewMetadata = view_metadata;
3519 
3520  try {
3521  _return = cat.createLink(ld, 6);
3522  } catch (const std::exception& e) {
3523  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
3524  }
3525 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
#define THROW_MAPD_EXCEPTION(errstr)
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ create_query_state()

template<typename... ARGS>
std::shared_ptr<query_state::QueryState> MapDHandler::create_query_state ( ARGS &&...  args)
inline

Definition at line 468 of file MapDHandler.h.

References run_benchmark_import::action, run_benchmark_import::args, run_benchmark_import::label, Lock_Namespace::parse_to_ra(), and run_benchmark_import::type.

Referenced by get_table_details_impl(), get_tables_meta(), sql_execute(), sql_execute_df(), and sql_validate().

468  {
469  return query_states_.create(std::forward<ARGS>(args)...);
470  }
CircleBuffer::value_type create(ARGS &&... args)
Definition: QueryState.h:185
query_state::QueryStates query_states_
Definition: MapDHandler.h:679
+ Here is the call graph for this function:
+ Here is the caller 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 4811 of file MapDHandler.cpp.

References CHECK, CHECK_EQ, and run_benchmark_import::label.

Referenced by convert_explain(), and convert_result().

4814  {
4815  CHECK_EQ(size_t(1), results.rowCount());
4816  TColumnType proj_info;
4817  proj_info.col_name = label;
4818  proj_info.col_type.type = TDatumType::STR;
4819  proj_info.col_type.nullable = false;
4820  proj_info.col_type.is_array = false;
4821  _return.row_set.row_desc.push_back(proj_info);
4822  const auto crt_row = results.getNextRow(true, true);
4823  const auto tv = crt_row[0];
4824  CHECK(results.getNextRow(true, true).empty());
4825  const auto scalar_tv = boost::get<ScalarTargetValue>(&tv);
4826  CHECK(scalar_tv);
4827  const auto s_n = boost::get<NullableString>(scalar_tv);
4828  CHECK(s_n);
4829  const auto s = boost::get<std::string>(s_n);
4830  CHECK(s);
4831  if (column_format) {
4832  TColumn tcol;
4833  tcol.data.str_col.push_back(*s);
4834  tcol.nulls.push_back(false);
4835  _return.row_set.is_columnar = true;
4836  _return.row_set.columns.push_back(tcol);
4837  } else {
4838  TDatum explanation;
4839  explanation.val.str_val = *s;
4840  explanation.is_null = false;
4841  TRow trow;
4842  trow.cols.push_back(explanation);
4843  _return.row_set.is_columnar = false;
4844  _return.row_set.rows.push_back(trow);
4845  }
4846 }
#define CHECK_EQ(x, y)
Definition: Logger.h:201
#define CHECK(condition)
Definition: Logger.h:193
+ 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 3558 of file MapDHandler.cpp.

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

Referenced by import_geo_table().

3562  {
3563  auto stdlog = STDLOG("table_name", table_name);
3564  check_read_only("create_table");
3565 
3566  if (ImportHelpers::is_reserved_name(table_name)) {
3567  THROW_MAPD_EXCEPTION("Invalid table name (reserved keyword): " + table_name);
3568  } else if (table_name != ImportHelpers::sanitize_name(table_name)) {
3569  THROW_MAPD_EXCEPTION("Invalid characters in table name: " + table_name);
3570  }
3571 
3572  auto rds = rd;
3573 
3574  // no longer need to manually add the poly column for a TFileType::POLYGON table
3575  // a column of the correct geo type has already been added
3576  // @TODO simon.eves rename TFileType::POLYGON to TFileType::GEO or something!
3577 
3578  std::string stmt{"CREATE TABLE " + table_name};
3579  std::vector<std::string> col_stmts;
3580 
3581  for (auto col : rds) {
3582  if (ImportHelpers::is_reserved_name(col.col_name)) {
3583  THROW_MAPD_EXCEPTION("Invalid column name (reserved keyword): " + col.col_name);
3584  } else if (col.col_name != ImportHelpers::sanitize_name(col.col_name)) {
3585  THROW_MAPD_EXCEPTION("Invalid characters in column name: " + col.col_name);
3586  }
3587  if (col.col_type.type == TDatumType::INTERVAL_DAY_TIME ||
3588  col.col_type.type == TDatumType::INTERVAL_YEAR_MONTH) {
3589  THROW_MAPD_EXCEPTION("Unsupported type: " + thrift_to_name(col.col_type) +
3590  " for column: " + col.col_name);
3591  }
3592 
3593  if (col.col_type.type == TDatumType::DECIMAL) {
3594  // if no precision or scale passed in set to default 14,7
3595  if (col.col_type.precision == 0 && col.col_type.scale == 0) {
3596  col.col_type.precision = 14;
3597  col.col_type.scale = 7;
3598  }
3599  }
3600 
3601  std::string col_stmt;
3602  col_stmt.append(col.col_name + " " + thrift_to_name(col.col_type));
3603 
3604  // As of 2016-06-27 the Immerse v1 frontend does not explicitly set the
3605  // `nullable` argument, leading this to default to false. Uncomment for v2.
3606  // if (!col.col_type.nullable) col_stmt.append(" NOT NULL");
3607 
3608  if (thrift_to_encoding(col.col_type.encoding) != kENCODING_NONE) {
3609  col_stmt.append(" ENCODING " + thrift_to_encoding_name(col.col_type));
3610  if (thrift_to_encoding(col.col_type.encoding) == kENCODING_DICT ||
3611  thrift_to_encoding(col.col_type.encoding) == kENCODING_FIXED ||
3612  thrift_to_encoding(col.col_type.encoding) == kENCODING_GEOINT) {
3613  col_stmt.append("(" + std::to_string(col.col_type.comp_param) + ")");
3614  }
3615  } else if (col.col_type.type == TDatumType::STR) {
3616  // non DICT encoded strings
3617  col_stmt.append(" ENCODING NONE");
3618  } else if (col.col_type.type == TDatumType::POINT ||
3619  col.col_type.type == TDatumType::LINESTRING ||
3620  col.col_type.type == TDatumType::POLYGON ||
3621  col.col_type.type == TDatumType::MULTIPOLYGON) {
3622  // non encoded compressable geo
3623  if (col.col_type.scale == 4326) {
3624  col_stmt.append(" ENCODING NONE");
3625  }
3626  }
3627  col_stmts.push_back(col_stmt);
3628  }
3629 
3630  stmt.append(" (" + boost::algorithm::join(col_stmts, ", ") + ")");
3631 
3632  if (create_params.is_replicated) {
3633  stmt.append(" WITH (PARTITIONS = 'REPLICATED')");
3634  }
3635 
3636  stmt.append(";");
3637 
3638  TQueryResult ret;
3639  sql_execute(ret, session, stmt, true, "", -1, -1);
3640 }
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
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createInMemoryCalciteSession()

std::string const MapDHandler::createInMemoryCalciteSession ( const std::shared_ptr< Catalog_Namespace::Catalog > &  catalog_ptr)
private

Definition at line 350 of file MapDHandler.cpp.

References calcite_, CHECK, executor_device_type_, generate_random_string(), sessions_, and sessions_mutex_.

Referenced by parse_to_ra().

351  {
352  // We would create an in memory session for calcite with super user privileges which
353  // would be used for getting all tables metadata when a user runs the query. The
354  // session would be under the name of a proxy user/password which would only persist
355  // till server's lifetime or execution of calcite query(in memory) whichever is the
356  // earliest.
357  mapd_lock_guard<mapd_shared_mutex> write_lock(sessions_mutex_);
358  std::string session_id;
359  do {
360  session_id = generate_random_string(64);
361  } while (sessions_.find(session_id) != sessions_.end());
362  Catalog_Namespace::UserMetadata user_meta(-1,
363  calcite_->getInternalSessionProxyUserName(),
364  calcite_->getInternalSessionProxyPassword(),
365  true,
366  -1,
367  true);
368  const auto emplace_ret =
369  sessions_.emplace(session_id,
370  std::make_shared<Catalog_Namespace::SessionInfo>(
371  catalog_ptr, user_meta, executor_device_type_, session_id));
372  CHECK(emplace_ret.second);
373  return session_id;
374 }
SessionMap sessions_
Definition: MapDHandler.h:680
mapd_shared_mutex sessions_mutex_
Definition: MapDHandler.h:456
std::string generate_random_string(const size_t len)
std::shared_ptr< Calcite > calcite_
Definition: MapDHandler.h:464
ExecutorDeviceType executor_device_type_
Definition: MapDHandler.h:447
#define CHECK(condition)
Definition: Logger.h:193
+ 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 1031 of file MapDHandler.cpp.

References CPU, data_mgr_, ArrowResultSet::deallocateArrowResultBuffer(), logger::ERROR, get_session_ptr(), GPU, handle_to_dev_ptr_mutex_, ipc_handle_to_dev_ptr_, LOG, run_benchmark_import::result, and STDLOG.

1034  {
1035  auto stdlog = STDLOG(get_session_ptr(session));
1036  int8_t* dev_ptr{0};
1037  if (device_type == TDeviceType::GPU) {
1038  std::lock_guard<std::mutex> map_lock(handle_to_dev_ptr_mutex_);
1039  if (ipc_handle_to_dev_ptr_.count(df.df_handle) != size_t(1)) {
1040  TMapDException ex;
1041  ex.error_msg = std::string(
1042  "Exception: current data frame handle is not bookkept or been inserted twice");
1043  LOG(ERROR) << ex.error_msg;
1044  throw ex;
1045  }
1046  dev_ptr = ipc_handle_to_dev_ptr_[df.df_handle];
1047  ipc_handle_to_dev_ptr_.erase(df.df_handle);
1048  }
1049  std::vector<char> sm_handle(df.sm_handle.begin(), df.sm_handle.end());
1050  std::vector<char> df_handle(df.df_handle.begin(), df.df_handle.end());
1051  ArrowResult result{sm_handle, df.sm_size, df_handle, df.df_size, dev_ptr};
1053  result,
1054  device_type == TDeviceType::CPU ? ExecutorDeviceType::CPU : ExecutorDeviceType::GPU,
1055  device_id,
1056  data_mgr_);
1057 }
#define LOG(tag)
Definition: Logger.h:188
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
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:441
std::mutex handle_to_dev_ptr_mutex_
Definition: MapDHandler.h:697
#define STDLOG(...)
Definition: QueryState.h:225
std::unordered_map< std::string, int8_t * > ipc_handle_to_dev_ptr_
Definition: MapDHandler.h:698
+ 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 3319 of file MapDHandler.cpp.

References check_read_only(), AccessPrivileges::DELETE_DASHBOARD, get_session_ptr(), is_allowed_on_dashboard(), STDLOG, THROW_MAPD_EXCEPTION, and to_string().

3320  {
3321  auto stdlog = STDLOG(get_session_ptr(session));
3322  auto session_ptr = stdlog.getConstSessionInfo();
3323  check_read_only("delete_dashboard");
3324  auto& cat = session_ptr->getCatalog();
3325  auto dash = cat.getMetadataForDashboard(dashboard_id);
3326  if (!dash) {
3327  THROW_MAPD_EXCEPTION("Dashboard with id" + std::to_string(dashboard_id) +
3328  " doesn't exist, so cannot delete it");
3329  }
3331  *session_ptr, dash->dashboardId, AccessPrivileges::DELETE_DASHBOARD)) {
3332  THROW_MAPD_EXCEPTION("Not enough privileges to delete a dashboard.");
3333  }
3334  try {
3335  cat.deleteMetadataForDashboard(dashboard_id);
3336  } catch (const std::exception& e) {
3337  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
3338  }
3339 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
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)
void check_read_only(const std::string &str)
static const AccessPrivileges DELETE_DASHBOARD
Definition: DBObject.h:166
#define STDLOG(...)
Definition: QueryState.h:225
+ 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 2935 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_ptr(), import_path_, is_a_supported_archive_file(), is_a_supported_geo_file(), IS_GEO, ImportHelpers::is_reserved_name(), 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(), STDLOG, thrift_to_copyparams(), THROW_MAPD_EXCEPTION, and type_to_thrift().

Referenced by import_geo_table().

2938  {
2939  auto stdlog = STDLOG(get_session_ptr(session));
2940  check_read_only("detect_column_types");
2941 
2943 
2944  std::string file_name{file_name_in};
2945 
2946  if (path_is_relative(file_name)) {
2947  // assume relative paths are relative to data_path / mapd_import / <session>
2948  auto file_path = import_path_ / picosha2::hash256_hex_string(session) /
2949  boost::filesystem::path(file_name).filename();
2950  file_name = file_path.string();
2951  }
2952 
2953  // if it's a geo table, handle alternative paths (S3, HTTP, archive etc.)
2954  if (copy_params.file_type == Importer_NS::FileType::POLYGON) {
2955  if (is_a_supported_geo_file(file_name, true)) {
2956  // prepare to detect geo file directly
2957  add_vsi_network_prefix(file_name);
2958  add_vsi_geo_prefix(file_name);
2959  } else if (is_a_supported_archive_file(file_name)) {
2960  // find the archive file
2961  add_vsi_network_prefix(file_name);
2962  if (!Importer_NS::Importer::gdalFileExists(file_name, copy_params)) {
2963  THROW_MAPD_EXCEPTION("Archive does not exist: " + file_name_in);
2964  }
2965  // find geo file in archive
2966  add_vsi_archive_prefix(file_name);
2967  std::string geo_file = find_first_geo_file_in_archive(file_name, copy_params);
2968  // prepare to detect that geo file
2969  if (geo_file.size()) {
2970  file_name = file_name + std::string("/") + geo_file;
2971  }
2972  } else {
2973  THROW_MAPD_EXCEPTION("File is not a supported geo or geo archive format: " +
2974  file_name_in);
2975  }
2976  }
2977 
2978  auto file_path = boost::filesystem::path(file_name);
2979  // can be a s3 url
2980  if (!boost::istarts_with(file_name, "s3://")) {
2981  if (!boost::filesystem::path(file_name).is_absolute()) {
2982  file_path = import_path_ / picosha2::hash256_hex_string(session) /
2983  boost::filesystem::path(file_name).filename();
2984  file_name = file_path.string();
2985  }
2986 
2987  if (copy_params.file_type == Importer_NS::FileType::POLYGON) {
2988  // check for geo file
2989  if (!Importer_NS::Importer::gdalFileOrDirectoryExists(file_name, copy_params)) {
2990  THROW_MAPD_EXCEPTION("File does not exist: " + file_path.string());
2991  }
2992  } else {
2993  // check for regular file
2994  if (!boost::filesystem::exists(file_path)) {
2995  THROW_MAPD_EXCEPTION("File does not exist: " + file_path.string());
2996  }
2997  }
2998  }
2999  try {
3000  if (copy_params.file_type == Importer_NS::FileType::DELIMITED
3001 #ifdef ENABLE_IMPORT_PARQUET
3002  || (copy_params.file_type == Importer_NS::FileType::PARQUET)
3003 #endif
3004  ) {
3005  Importer_NS::Detector detector(file_path, copy_params);
3006  std::vector<SQLTypes> best_types = detector.best_sqltypes;
3007  std::vector<EncodingType> best_encodings = detector.best_encodings;
3008  std::vector<std::string> headers = detector.get_headers();
3009  copy_params = detector.get_copy_params();
3010 
3011  _return.copy_params = copyparams_to_thrift(copy_params);
3012  _return.row_set.row_desc.resize(best_types.size());
3013  for (size_t col_idx = 0; col_idx < best_types.size(); col_idx++) {
3014  TColumnType col;
3015  SQLTypes t = best_types[col_idx];
3016  EncodingType encodingType = best_encodings[col_idx];
3017  SQLTypeInfo ti(t, false, encodingType);
3018  if (IS_GEO(t)) {
3019  // set this so encoding_to_thrift does the right thing
3020  ti.set_compression(copy_params.geo_coords_encoding);
3021  // fill in these directly
3022  col.col_type.precision = static_cast<int>(copy_params.geo_coords_type);
3023  col.col_type.scale = copy_params.geo_coords_srid;
3024  col.col_type.comp_param = copy_params.geo_coords_comp_param;
3025  }
3026  col.col_type.type = type_to_thrift(ti);
3027  col.col_type.encoding = encoding_to_thrift(ti);
3028  if (copy_params.sanitize_column_names) {
3029  col.col_name = ImportHelpers::sanitize_name(headers[col_idx]);
3030  } else {
3031  col.col_name = headers[col_idx];
3032  }
3033  col.is_reserved_keyword = ImportHelpers::is_reserved_name(col.col_name);
3034  _return.row_set.row_desc[col_idx] = col;
3035  }
3036  size_t num_samples = 100;
3037  auto sample_data = detector.get_sample_rows(num_samples);
3038 
3039  TRow sample_row;
3040  for (auto row : sample_data) {
3041  sample_row.cols.clear();
3042  for (const auto& s : row) {
3043  TDatum td;
3044  td.val.str_val = s;
3045  td.is_null = s.empty();
3046  sample_row.cols.push_back(td);
3047  }
3048  _return.row_set.rows.push_back(sample_row);
3049  }
3050  } else if (copy_params.file_type == Importer_NS::FileType::POLYGON) {
3051  // @TODO simon.eves get this from somewhere!
3052  const std::string geoColumnName(OMNISCI_GEO_PREFIX);
3053 
3054  check_geospatial_files(file_path, copy_params);
3055  std::list<ColumnDescriptor> cds = Importer_NS::Importer::gdalToColumnDescriptors(
3056  file_path.string(), geoColumnName, copy_params);
3057  for (auto cd : cds) {
3058  if (copy_params.sanitize_column_names) {
3059  cd.columnName = ImportHelpers::sanitize_name(cd.columnName);
3060  }
3061  _return.row_set.row_desc.push_back(populateThriftColumnType(nullptr, &cd));
3062  }
3063  std::map<std::string, std::vector<std::string>> sample_data;
3065  file_path.string(), geoColumnName, sample_data, 100, copy_params);
3066  if (sample_data.size() > 0) {
3067  for (size_t i = 0; i < sample_data.begin()->second.size(); i++) {
3068  TRow sample_row;
3069  for (auto cd : cds) {
3070  TDatum td;
3071  td.val.str_val = sample_data[cd.sourceName].at(i);
3072  td.is_null = td.val.str_val.empty();
3073  sample_row.cols.push_back(td);
3074  }
3075  _return.row_set.rows.push_back(sample_row);
3076  }
3077  }
3078  _return.copy_params = copyparams_to_thrift(copy_params);
3079  }
3080  } catch (const std::exception& e) {
3081  THROW_MAPD_EXCEPTION("detect_column_types error: " + std::string(e.what()));
3082  }
3083 }
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:41
EncodingType
Definition: encodetypes.h:22
boost::filesystem::path import_path_
Definition: MapDHandler.h:446
void add_vsi_archive_prefix(std::string &path)
void add_vsi_geo_prefix(std::string &path)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
#define THROW_MAPD_EXCEPTION(errstr)
EncodingType geo_coords_encoding
Definition: CopyParams.h:73
static bool gdalFileOrDirectoryExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:4466
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:4338
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)
bool path_is_relative(const std::string &path)
static bool gdalFileExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:4461
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:4217
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)
#define IS_GEO(T)
Definition: sqltypes.h:167
#define STDLOG(...)
Definition: QueryState.h:225
bool is_a_supported_archive_file(const std::string &path)
int32_t geo_coords_comp_param
Definition: CopyParams.h:74
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 488 of file MapDHandler.cpp.

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

488  {
489  auto stdlog = STDLOG();
490  mapd_lock_guard<mapd_shared_mutex> write_lock(sessions_mutex_);
491  auto session_it = get_session_it_unsafe(session, write_lock);
492  stdlog.setSessionInfo(session_it->second);
493  const auto dbname = session_it->second->getCatalog().getCurrentDB().dbName;
494  LOG(INFO) << "User " << session_it->second->get_currentUser().userName
495  << " disconnected from database " << dbname << std::endl;
496  disconnect_impl(session_it);
497 }
#define LOG(tag)
Definition: Logger.h:188
SessionMap::iterator get_session_it_unsafe(const TSessionId &session, SESSION_MAP_LOCK &lock)
mapd_shared_mutex sessions_mutex_
Definition: MapDHandler.h:456
void disconnect_impl(const SessionMap::iterator &session_it)
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ disconnect_impl()

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

Definition at line 499 of file MapDHandler.cpp.

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

Referenced by disconnect().

499  {
500  // session_it existence should already have been checked (i.e. called via
501  // get_session_it_unsafe(...))
502  const auto session_id = session_it->second->get_session_id();
503  if (leaf_aggregator_.leafCount() > 0) {
504  leaf_aggregator_.disconnect(session_id);
505  }
506  if (render_handler_) {
507  render_handler_->disconnect(session_id);
508  }
509  sessions_.erase(session_it);
510 }
SessionMap sessions_
Definition: MapDHandler.h:680
std::unique_ptr< MapDRenderHandler > render_handler_
Definition: MapDHandler.h:461
void disconnect(const TSessionId session)
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:443
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 5725 of file MapDHandler.cpp.

References calcite_, and get_device_parameters().

Referenced by shutdown().

5725  {
5726  if (calcite_) {
5727  calcite_->close_calcite_server(false);
5728  }
5729 }
std::shared_ptr< Calcite > calcite_
Definition: MapDHandler.h:464
+ Here is the call graph for this function:
+ 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 5347 of file MapDHandler.cpp.

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

Referenced by sql_execute_impl().

5349  {
5350  auto importer_factory = [&session_info, this](
5351  const Catalog& catalog,
5352  const TableDescriptor* td,
5353  const std::string& file_path,
5354  const Importer_NS::CopyParams& copy_params) {
5355  return boost::make_unique<Importer_NS::Importer>(
5356  new DistributedLoader(session_info, td, &leaf_aggregator_),
5357  file_path,
5358  copy_params);
5359  };
5360  copy_stmt->execute(session_info, importer_factory);
5361 }
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:443
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_next_render_step()

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

Definition at line 5604 of file MapDHandler.cpp.

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

5606  {
5607  if (!render_handler_) {
5608  THROW_MAPD_EXCEPTION("Backend rendering is disabled.");
5609  }
5610 
5611  LOG(INFO) << "execute_next_render_step: id:" << pending_render.id;
5612  auto time_ms = measure<>::execution([&]() {
5613  try {
5614  render_handler_->execute_next_render_step(_return, pending_render, merged_data);
5615  } catch (std::exception& e) {
5616  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
5617  }
5618  });
5619  LOG(INFO) << "execute_next_render_step-COMPLETED id: " << pending_render.id
5620  << ", time: " << time_ms << "ms ";
5621 }
std::unique_ptr< MapDRenderHandler > render_handler_
Definition: MapDHandler.h:461
#define LOG(tag)
Definition: Logger.h:188
#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_query_step()

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

Definition at line 5459 of file MapDHandler.cpp.

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

5460  {
5461  if (!leaf_handler_) {
5462  THROW_MAPD_EXCEPTION("Distributed support is disabled.");
5463  }
5464  LOG(INFO) << "execute_query_step : id:" << pending_query.id;
5465  auto time_ms = measure<>::execution([&]() {
5466  try {
5467  leaf_handler_->execute_query_step(_return, pending_query);
5468  } catch (std::exception& e) {
5469  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
5470  }
5471  });
5472  LOG(INFO) << "execute_query_step-COMPLETED " << time_ms << "ms";
5473 }
#define LOG(tag)
Definition: Logger.h:188
#define THROW_MAPD_EXCEPTION(errstr)
std::unique_ptr< MapDLeafHandler > leaf_handler_
Definition: MapDHandler.h:463
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,
QueryStateProxy  query_state_proxy,
const std::string &  query_ra,
const bool  column_format,
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 4489 of file MapDHandler.cpp.

References allow_loop_joins_, allow_multifrag_, convert_explain(), convert_rows(), CPU, query_state::Timer::createQueryStateProxy(), query_state::QueryStateProxy::createTimer(), Default, measure< TimeT >::execution(), g_dynamic_watchdog_time_limit, g_enable_columnar_output, g_enable_dynamic_watchdog, g_enable_watchdog, query_state::QueryState::getConstSessionInfo(), Executor::getExecutor(), query_state::QueryStateProxy::getQueryState(), MapDParameters::gpu_input_mem_limit, 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().

4501  {
4502  query_state::Timer timer = query_state_proxy.createTimer(__func__);
4503  const auto& cat = query_state_proxy.getQueryState().getConstSessionInfo()->getCatalog();
4504  CompilationOptions co = {executor_device_type,
4505  true,
4508  explain_optimized_ir ? ExecutorExplainType::Optimized
4513  just_explain,
4514  allow_loop_joins_ || just_validate,
4516  jit_debug_,
4517  just_validate,
4520  find_push_down_candidates,
4521  just_calcite_explain,
4523  auto executor = Executor::getExecutor(cat.getCurrentDB().dbId,
4524  jit_debug_ ? "/tmp" : "",
4525  jit_debug_ ? "mapdquery" : "",
4527  RelAlgExecutor ra_executor(executor.get(),
4528  cat,
4529  query_ra,
4530  query_state_proxy.getQueryState().shared_from_this());
4531  ExecutionResult result{std::make_shared<ResultSet>(std::vector<TargetInfo>{},
4534  nullptr,
4535  nullptr),
4536  {}};
4537  _return.execution_time_ms += measure<>::execution(
4538  [&]() { result = ra_executor.executeRelAlgQuery(co, eo, nullptr); });
4539  // reduce execution time by the time spent during queue waiting
4540  _return.execution_time_ms -= result.getRows()->getQueueTime();
4541  const auto& filter_push_down_info = result.getPushedDownFilterInfo();
4542  if (!filter_push_down_info.empty()) {
4543  return filter_push_down_info;
4544  }
4545  if (just_explain) {
4546  convert_explain(_return, *result.getRows(), column_format);
4547  } else if (!just_calcite_explain) {
4548  convert_rows(_return,
4549  timer.createQueryStateProxy(),
4550  result.getTargetsMeta(),
4551  *result.getRows(),
4552  column_format,
4553  first_n,
4554  at_most_n);
4555  }
4556  return {};
4557 }
const bool allow_loop_joins_
Definition: MapDHandler.h:454
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())
Definition: Execute.cpp:127
const bool intel_jit_profile_
Definition: MapDHandler.h:451
bool g_enable_dynamic_watchdog
Definition: Execute.cpp:72
Timer createTimer(char const *event_name)
Definition: QueryState.cpp:111
const MapDParameters & mapd_parameters_
Definition: MapDHandler.h:460
bool g_enable_columnar_output
Definition: Execute.cpp:86
bool allow_multifrag_
Definition: MapDHandler.h:452
QueryState & getQueryState()
Definition: QueryState.h:172
QueryStateProxy createQueryStateProxy()
Definition: QueryState.cpp:118
std::shared_ptr< Catalog_Namespace::SessionInfo const > getConstSessionInfo() const
Definition: QueryState.cpp:75
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:71
static TimeT::rep execution(F func, Args &&... args)
Definition: sample.cpp:29
void convert_rows(TQueryResult &_return, QueryStateProxy query_state_proxy, 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:73
const bool jit_debug_
Definition: MapDHandler.h:450
+ 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,
QueryStateProxy  query_state_proxy,
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 4559 of file MapDHandler.cpp.

References allow_loop_joins_, allow_multifrag_, CHECK, CPU, data_mgr_, Default, ArrowResult::df_dev_ptr, ArrowResult::df_handle, ArrowResult::df_size, measure< TimeT >::execution(), 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(), query_state::QueryStateProxy::getQueryState(), getTargetNames(), GPU, MapDParameters::gpu_input_mem_limit, handle_to_dev_ptr_mutex_, intel_jit_profile_, ipc_handle_to_dev_ptr_, jit_debug_, mapd_parameters_, run_benchmark_import::result, ArrowResult::sm_handle, and ArrowResult::sm_size.

Referenced by sql_execute_df().

4565  {
4566  const auto& cat = session_info.getCatalog();
4567  CHECK(device_type == ExecutorDeviceType::CPU ||
4569  CompilationOptions co = {session_info.get_executor_device_type(),
4570  true,
4575  ExecutionOptions eo = {false,
4577  false,
4580  jit_debug_,
4581  false,
4584  false,
4585  false,
4587  auto executor = Executor::getExecutor(cat.getCurrentDB().dbId,
4588  jit_debug_ ? "/tmp" : "",
4589  jit_debug_ ? "mapdquery" : "",
4591  RelAlgExecutor ra_executor(executor.get(),
4592  cat,
4593  query_ra,
4594  query_state_proxy.getQueryState().shared_from_this());
4595  ExecutionResult result{std::make_shared<ResultSet>(std::vector<TargetInfo>{},
4598  nullptr,
4599  nullptr),
4600  {}};
4601  _return.execution_time_ms += measure<>::execution(
4602  [&]() { result = ra_executor.executeRelAlgQuery(co, eo, nullptr); });
4603  _return.execution_time_ms -= result.getRows()->getQueueTime();
4604  const auto rs = result.getRows();
4605  const auto converter =
4606  std::make_unique<ArrowResultSetConverter>(rs,
4607  data_mgr_,
4608  device_type,
4609  device_id,
4610  getTargetNames(result.getTargetsMeta()),
4611  first_n);
4612  ArrowResult arrow_result;
4613 
4614  _return.arrow_conversion_time_ms +=
4615  measure<>::execution([&] { arrow_result = converter->getArrowResult(); });
4616  _return.sm_handle =
4617  std::string(arrow_result.sm_handle.begin(), arrow_result.sm_handle.end());
4618  _return.sm_size = arrow_result.sm_size;
4619  _return.df_handle =
4620  std::string(arrow_result.df_handle.begin(), arrow_result.df_handle.end());
4621  if (device_type == ExecutorDeviceType::GPU) {
4622  std::lock_guard<std::mutex> map_lock(handle_to_dev_ptr_mutex_);
4623  CHECK(!ipc_handle_to_dev_ptr_.count(_return.df_handle));
4624  ipc_handle_to_dev_ptr_.insert(
4625  std::make_pair(_return.df_handle, arrow_result.df_dev_ptr));
4626  }
4627  _return.df_size = arrow_result.df_size;
4628 }
const bool allow_loop_joins_
Definition: MapDHandler.h:454
std::vector< char > sm_handle
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())
Definition: Execute.cpp:127
const bool intel_jit_profile_
Definition: MapDHandler.h:451
bool g_enable_dynamic_watchdog
Definition: Execute.cpp:72
const MapDParameters & mapd_parameters_
Definition: MapDHandler.h:460
bool allow_multifrag_
Definition: MapDHandler.h:452
int8_t * df_dev_ptr
QueryState & getQueryState()
Definition: QueryState.h:172
Catalog & getCatalog() const
Definition: SessionInfo.h:90
std::vector< char > df_handle
int64_t sm_size
std::shared_ptr< Data_Namespace::DataMgr > data_mgr_
Definition: MapDHandler.h:441
std::vector< std::string > getTargetNames(const std::vector< TargetMetaInfo > &targets) const
double gpu_input_mem_limit
int64_t df_size
#define CHECK(condition)
Definition: Logger.h:193
bool g_enable_watchdog
Definition: Execute.cpp:71
static TimeT::rep execution(F func, Args &&... args)
Definition: sample.cpp:29
std::mutex handle_to_dev_ptr_mutex_
Definition: MapDHandler.h:697
unsigned g_dynamic_watchdog_time_limit
Definition: Execute.cpp:73
const bool jit_debug_
Definition: MapDHandler.h:450
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:698
+ 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,
QueryStateProxy  query_state_proxy,
std::string &  query_ra,
const bool  column_format,
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::vector< PushedDownFilterInfo filter_push_down_requests 
)
private

Definition at line 5297 of file MapDHandler.cpp.

References convert_explain(), execute_rel_alg(), measure< TimeT >::execution(), query_state::QueryStateProxy::getQueryState(), query_state::QueryState::getQueryStr(), mapd_parameters_, and parse_to_ra().

Referenced by sql_execute_impl().

5307  {
5308  // collecting the selected filters' info to be sent to Calcite:
5309  std::vector<TFilterPushDownInfo> filter_push_down_info;
5310  for (const auto& req : filter_push_down_requests) {
5311  TFilterPushDownInfo filter_push_down_info_for_request;
5312  filter_push_down_info_for_request.input_prev = req.input_prev;
5313  filter_push_down_info_for_request.input_start = req.input_start;
5314  filter_push_down_info_for_request.input_next = req.input_next;
5315  filter_push_down_info.push_back(filter_push_down_info_for_request);
5316  }
5317  // deriving the new relational algebra plan with respect to the pushed down filters
5318  _return.execution_time_ms += measure<>::execution([&]() {
5319  query_ra = parse_to_ra(query_state_proxy,
5320  query_state_proxy.getQueryState().getQueryStr(),
5321  filter_push_down_info,
5322  boost::none,
5324  });
5325 
5326  if (just_calcite_explain) {
5327  // return the new ra as the result
5328  convert_explain(_return, ResultSet(query_ra), true);
5329  return;
5330  }
5331 
5332  // execute the new relational algebra plan:
5333  execute_rel_alg(_return,
5334  query_state_proxy,
5335  query_ra,
5336  column_format,
5337  executor_device_type,
5338  first_n,
5339  at_most_n,
5340  just_explain,
5341  /*just_validate = */ false,
5342  /*find_push_down_candidates = */ false,
5343  /*just_calcite_explain = */ false,
5344  /*TODO: explain optimized*/ false);
5345 }
std::vector< PushedDownFilterInfo > execute_rel_alg(TQueryResult &_return, QueryStateProxy, const std::string &query_ra, const bool column_format, 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:460
QueryState & getQueryState()
Definition: QueryState.h:172
std::string const & getQueryStr() const
Definition: QueryState.h:152
std::string parse_to_ra(QueryStateProxy, const std::string &query_str, const std::vector< TFilterPushDownInfo > &filter_push_down_info, OptionalTableMap tableNames, const MapDParameters mapd_parameters, RenderInfo *render_info=nullptr)
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,
QueryStateProxy  query_state_proxy,
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 4630 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_, and mapd_parameters_.

Referenced by sql_execute_impl().

4636  {
4637  auto executor = Executor::getExecutor(root_plan->getCatalog().getCurrentDB().dbId,
4638  jit_debug_ ? "/tmp" : "",
4639  jit_debug_ ? "mapdquery" : "",
4641  std::shared_ptr<ResultSet> results;
4642  _return.execution_time_ms += measure<>::execution([&]() {
4643  results = executor->execute(root_plan,
4644  session_info,
4645  true,
4646  executor_device_type,
4650  });
4651  // reduce execution time by the time spent during queue waiting
4652  _return.execution_time_ms -= results->getQueueTime();
4653  if (root_plan->get_plan_dest() == Planner::RootPlan::Dest::kEXPLAIN) {
4654  convert_explain(_return, *results, column_format);
4655  return;
4656  }
4657  const auto plan = root_plan->get_plan();
4658  CHECK(plan);
4659  const auto& targets = plan->get_targetlist();
4660  convert_rows(_return,
4661  query_state_proxy,
4662  getTargetMetaInfo(targets),
4663  *results,
4664  column_format,
4665  -1,
4666  -1);
4667 }
const bool allow_loop_joins_
Definition: MapDHandler.h:454
std::vector< TargetMetaInfo > getTargetMetaInfo(const std::vector< std::shared_ptr< Analyzer::TargetEntry >> &targets) const
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())
Definition: Execute.cpp:127
const MapDParameters & mapd_parameters_
Definition: MapDHandler.h:460
bool allow_multifrag_
Definition: MapDHandler.h:452
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:193
static TimeT::rep execution(F func, Args &&... args)
Definition: sample.cpp:29
void convert_rows(TQueryResult &_return, QueryStateProxy query_state_proxy, 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:450
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 ( std::vector< std::string > &  table_names,
query_state::StdLog stdlog 
)
private

Definition at line 1229 of file MapDHandler.cpp.

References get_table_details_impl().

Referenced by get_token_based_completions().

1230  {
1231  std::unordered_map<std::string, std::unordered_set<std::string>> column_names_by_table;
1232  for (auto it = table_names.begin(); it != table_names.end();) {
1233  TTableDetails table_details;
1234  try {
1235  get_table_details_impl(table_details, stdlog, *it, false, false);
1236  } catch (const TMapDException& e) {
1237  // Remove the corrupted Table/View name from the list for further processing.
1238  it = table_names.erase(it);
1239  continue;
1240  }
1241  for (const auto& column_type : table_details.row_desc) {
1242  column_names_by_table[*it].emplace(column_type.col_name);
1243  }
1244  ++it;
1245  }
1246  return column_names_by_table;
1247 }
void get_table_details_impl(TTableDetails &_return, query_state::StdLog &stdlog, const std::string &table_name, const bool get_system, const bool get_physical)
+ 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 4795 of file MapDHandler.cpp.

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

Referenced by get_table_details_impl(), and validate_rel_alg().

4796  {
4797  TRowDescriptor fixedup_row_desc;
4798  for (const TColumnType& col_desc : row_desc) {
4799  auto fixedup_col_desc = col_desc;
4800  if (col_desc.col_type.encoding == TEncodingType::DICT &&
4801  col_desc.col_type.comp_param > 0) {
4802  const auto dd = cat.getMetadataForDict(col_desc.col_type.comp_param, false);
4803  fixedup_col_desc.col_type.comp_param = dd->dictNBits;
4804  }
4805  fixedup_row_desc.push_back(fixedup_col_desc);
4806  }
4807  return fixedup_row_desc;
4808 }
const DictDescriptor * getMetadataForDict(int dict_ref, bool loadDict=true) const
Definition: Catalog.cpp:1377
+ 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 4245 of file MapDHandler.cpp.

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

4248  {
4249  auto stdlog =
4250  STDLOG(get_session_ptr(session), "get_all_files_in_archive", archive_path_in);
4251 
4252  std::string archive_path(archive_path_in);
4253  if (path_is_relative(archive_path)) {
4254  // assume relative paths are relative to data_path / mapd_import / <session>
4255  auto file_path = import_path_ / picosha2::hash256_hex_string(session) /
4256  boost::filesystem::path(archive_path).filename();
4257  archive_path = file_path.string();
4258  }
4259 
4260  if (is_a_supported_archive_file(archive_path)) {
4261  // find the archive file
4262  add_vsi_network_prefix(archive_path);
4263  if (!Importer_NS::Importer::gdalFileExists(archive_path,
4264  thrift_to_copyparams(copy_params))) {
4265  THROW_MAPD_EXCEPTION("Archive does not exist: " + archive_path_in);
4266  }
4267  // find all files in archive
4268  add_vsi_archive_prefix(archive_path);
4270  archive_path, thrift_to_copyparams(copy_params));
4271  // prepend them all with original path
4272  for (auto& s : _return) {
4273  s = archive_path_in + '/' + s;
4274  }
4275  }
4276 }
void add_vsi_network_prefix(std::string &path)
boost::filesystem::path import_path_
Definition: MapDHandler.h:446
void add_vsi_archive_prefix(std::string &path)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
#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:4461
Importer_NS::CopyParams thrift_to_copyparams(const TCopyParams &cp)
#define STDLOG(...)
Definition: QueryState.h:225
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:4538
+ 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 1633 of file MapDHandler.cpp.

References CHECK, get_session_ptr(), STDLOG, and THROW_MAPD_EXCEPTION.

1635  {
1636  auto stdlog = STDLOG(get_session_ptr(sessionId));
1637  auto session_ptr = stdlog.getConstSessionInfo();
1638  auto* grantee = SysCatalog::instance().getGrantee(granteeName);
1639  if (grantee) {
1640  if (session_ptr->get_currentUser().isSuper) {
1641  roles = grantee->getRoles();
1642  } else if (grantee->isUser()) {
1643  if (session_ptr->get_currentUser().userName == granteeName) {
1644  roles = grantee->getRoles();
1645  } else {
1647  "Only a superuser is authorized to request list of roles granted to another "
1648  "user.");
1649  }
1650  } else {
1651  CHECK(!grantee->isUser());
1652  // granteeName is actually a roleName here and we can check a role
1653  // only if it is granted to us
1654  if (SysCatalog::instance().isRoleGrantedToGrantee(
1655  session_ptr->get_currentUser().userName, granteeName, false)) {
1656  roles = grantee->getRoles();
1657  } else {
1658  THROW_MAPD_EXCEPTION("A user can check only roles granted to him.");
1659  }
1660  }
1661  } else {
1662  THROW_MAPD_EXCEPTION("Grantee " + granteeName + " does not exist.");
1663  }
1664 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
#define THROW_MAPD_EXCEPTION(errstr)
#define CHECK(condition)
Definition: Logger.h:193
#define STDLOG(...)
Definition: QueryState.h:225
+ 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 1123 of file MapDHandler.cpp.

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

1126  {
1127  auto stdlog = STDLOG(get_session_ptr(session));
1128  std::vector<std::string> visible_tables; // Tables allowed for the given session.
1129  get_completion_hints_unsorted(hints, visible_tables, stdlog, sql, cursor);
1130  const auto proj_tokens = extract_projection_tokens_for_completion(sql);
1131  auto compatible_table_names = get_uc_compatible_table_names_by_column(
1132  proj_tokens.uc_column_names, visible_tables, stdlog);
1133  // Add the table qualifiers explicitly specified by the user.
1134  compatible_table_names.insert(proj_tokens.uc_column_table_qualifiers.begin(),
1135  proj_tokens.uc_column_table_qualifiers.end());
1136  // Sort the hints by category, from COLUMN (most specific) to KEYWORD.
1137  std::sort(
1138  hints.begin(),
1139  hints.end(),
1140  [&compatible_table_names](const TCompletionHint& lhs, const TCompletionHint& rhs) {
1141  if (lhs.type == TCompletionHintType::TABLE &&
1142  rhs.type == TCompletionHintType::TABLE) {
1143  // Between two tables, one which is compatible with the specified projections
1144  // and one which isn't, pick the one which is compatible.
1145  if (compatible_table_names.find(to_upper(lhs.hints.back())) !=
1146  compatible_table_names.end() &&
1147  compatible_table_names.find(to_upper(rhs.hints.back())) ==
1148  compatible_table_names.end()) {
1149  return true;
1150  }
1151  }
1152  return lhs.type < rhs.type;
1153  });
1154 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
void get_completion_hints_unsorted(std::vector< TCompletionHint > &hints, std::vector< std::string > &visible_tables, query_state::StdLog &stdlog, const std::string &sql, const int cursor)
std::string to_upper(const std::string &str)
std::unordered_set< std::string > get_uc_compatible_table_names_by_column(const std::unordered_set< std::string > &uc_column_names, std::vector< std::string > &table_names, query_state::StdLog &stdlog)
#define STDLOG(...)
Definition: QueryState.h:225
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,
query_state::StdLog stdlog,
const std::string &  sql,
const int  cursor 
)
private

Definition at line 1156 of file MapDHandler.cpp.

References calcite_, logger::ERROR, GET_PHYSICAL_TABLES_AND_VIEWS, get_tables_impl(), get_token_based_completions(), query_state::StdLog::getConstSessionInfo(), just_whitelisted_keyword_hints(), and LOG.

Referenced by get_completion_hints().

1160  {
1161  const auto& session_info = *stdlog.getConstSessionInfo();
1162  try {
1163  get_tables_impl(visible_tables, session_info, GET_PHYSICAL_TABLES_AND_VIEWS);
1164  // Filter out keywords suggested by Calcite which we don't support.
1166  calcite_->getCompletionHints(session_info, visible_tables, sql, cursor));
1167  } catch (const std::exception& e) {
1168  TMapDException ex;
1169  ex.error_msg = "Exception: " + std::string(e.what());
1170  LOG(ERROR) << ex.error_msg;
1171  throw ex;
1172  }
1173  boost::regex from_expr{R"(\s+from\s+)", boost::regex::extended | boost::regex::icase};
1174  const size_t length_to_cursor =
1175  cursor < 0 ? sql.size() : std::min(sql.size(), static_cast<size_t>(cursor));
1176  // Trust hints from Calcite after the FROM keyword.
1177  if (boost::regex_search(sql.cbegin(), sql.cbegin() + length_to_cursor, from_expr)) {
1178  return;
1179  }
1180  // Before FROM, the query is too incomplete for context-sensitive completions.
1181  get_token_based_completions(hints, stdlog, visible_tables, sql, cursor);
1182 }
void get_tables_impl(std::vector< std::string > &table_names, const Catalog_Namespace::SessionInfo &, const GetTablesType get_tables_type)
void get_token_based_completions(std::vector< TCompletionHint > &hints, query_state::StdLog &stdlog, std::vector< std::string > &visible_tables, const std::string &sql, const int cursor)
#define LOG(tag)
Definition: Logger.h:188
std::vector< TCompletionHint > just_whitelisted_keyword_hints(const std::vector< TCompletionHint > &hints)
std::shared_ptr< Calcite > calcite_
Definition: MapDHandler.h:464
std::shared_ptr< Catalog_Namespace::SessionInfo const > getConstSessionInfo() const
Definition: QueryState.cpp:128
+ 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 4406 of file MapDHandler.cpp.

References get_session_ptr().

4407  {
4408  return get_session_ptr(session);
4409 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
+ 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 3166 of file MapDHandler.cpp.

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

3168  {
3169  auto stdlog = STDLOG(get_session_ptr(session));
3170  auto session_ptr = stdlog.getConstSessionInfo();
3171  auto const& cat = session_ptr->getCatalog();
3173  auto dash = cat.getMetadataForDashboard(dashboard_id);
3174  if (!dash) {
3175  THROW_MAPD_EXCEPTION("Dashboard with dashboard id " + std::to_string(dashboard_id) +
3176  " doesn't exist");
3177  }
3179  *session_ptr, dash->dashboardId, AccessPrivileges::VIEW_DASHBOARD)) {
3180  THROW_MAPD_EXCEPTION("User has no view privileges for the dashboard with id " +
3181  std::to_string(dashboard_id));
3182  }
3183  user_meta.userName = "";
3184  SysCatalog::instance().getMetadataForUserById(dash->userId, user_meta);
3185  auto objects_list = SysCatalog::instance().getMetadataForObject(
3186  cat.getCurrentDB().dbId,
3187  static_cast<int>(DBObjectType::DashboardDBObjectType),
3188  dashboard_id);
3189  dashboard.dashboard_name = dash->dashboardName;
3190  dashboard.dashboard_state = dash->dashboardState;
3191  dashboard.image_hash = dash->imageHash;
3192  dashboard.update_time = dash->updateTime;
3193  dashboard.dashboard_metadata = dash->dashboardMetadata;
3194  dashboard.dashboard_owner = dash->user;
3195  dashboard.dashboard_id = dash->dashboardId;
3196  if (objects_list.empty() ||
3197  (objects_list.size() == 1 && objects_list[0]->roleName == user_meta.userName)) {
3198  dashboard.is_dash_shared = false;
3199  } else {
3200  dashboard.is_dash_shared = true;
3201  }
3202 }
static const AccessPrivileges VIEW_DASHBOARD
Definition: DBObject.h:164
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
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)
#define STDLOG(...)
Definition: QueryState.h:225
+ 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 3463 of file MapDHandler.cpp.

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

3466  {
3467  auto stdlog = STDLOG(get_session_ptr(session));
3468  auto session_ptr = stdlog.getConstSessionInfo();
3469  auto const& cat = session_ptr->getCatalog();
3471  auto dash = cat.getMetadataForDashboard(dashboard_id);
3472  if (!dash) {
3473  THROW_MAPD_EXCEPTION("Exception: Dashboard id " + std::to_string(dashboard_id) +
3474  " does not exist");
3475  } else if (session_ptr->get_currentUser().userId != dash->userId &&
3476  !session_ptr->get_currentUser().isSuper) {
3478  "User should be either owner of dashboard or super user to access grantees");
3479  }
3480  std::vector<ObjectRoleDescriptor*> objectsList;
3481  objectsList = SysCatalog::instance().getMetadataForObject(
3482  cat.getCurrentDB().dbId,
3483  static_cast<int>(DBObjectType::DashboardDBObjectType),
3484  dashboard_id); // By default objecttypecan be only dashabaords
3485  user_meta.userId = -1;
3486  user_meta.userName = "";
3487  SysCatalog::instance().getMetadataForUserById(dash->userId, user_meta);
3488  for (auto object : objectsList) {
3489  if (user_meta.userName == object->roleName) {
3490  // Mask owner
3491  continue;
3492  }
3493  TDashboardGrantees grantee;
3494  TDashboardPermissions perm;
3495  grantee.name = object->roleName;
3496  grantee.is_user = object->roleType;
3497  perm.create_ = object->privs.hasPermission(DashboardPrivileges::CREATE_DASHBOARD);
3498  perm.delete_ = object->privs.hasPermission(DashboardPrivileges::DELETE_DASHBOARD);
3499  perm.edit_ = object->privs.hasPermission(DashboardPrivileges::EDIT_DASHBOARD);
3500  perm.view_ = object->privs.hasPermission(DashboardPrivileges::VIEW_DASHBOARD);
3501  grantee.permissions = perm;
3502  dashboard_grantees.push_back(grantee);
3503  }
3504 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
std::string to_string(char const *&&v)
#define THROW_MAPD_EXCEPTION(errstr)
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
#define STDLOG(...)
Definition: QueryState.h:225
+ 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 3204 of file MapDHandler.cpp.

References DashboardDBObjectType, get_session_ptr(), is_allowed_on_dashboard(), STDLOG, Catalog_Namespace::UserMetadata::userName, and AccessPrivileges::VIEW_DASHBOARD.

3205  {
3206  auto stdlog = STDLOG(get_session_ptr(session));
3207  auto session_ptr = stdlog.getConstSessionInfo();
3208  auto const& cat = session_ptr->getCatalog();
3210  const auto dashes = cat.getAllDashboardsMetadata();
3211  user_meta.userName = "";
3212  for (const auto d : dashes) {
3213  SysCatalog::instance().getMetadataForUserById(d->userId, user_meta);
3215  *session_ptr, d->dashboardId, AccessPrivileges::VIEW_DASHBOARD)) {
3216  auto objects_list = SysCatalog::instance().getMetadataForObject(
3217  cat.getCurrentDB().dbId,
3218  static_cast<int>(DBObjectType::DashboardDBObjectType),
3219  d->dashboardId);
3220  TDashboard dash;
3221  dash.dashboard_name = d->dashboardName;
3222  dash.image_hash = d->imageHash;
3223  dash.update_time = d->updateTime;
3224  dash.dashboard_metadata = d->dashboardMetadata;
3225  dash.dashboard_id = d->dashboardId;
3226  dash.dashboard_owner = d->user;
3227  // dashboardState is intentionally not populated here
3228  // for payload reasons
3229  // use get_dashboard call to get state
3230  if (objects_list.empty() ||
3231  (objects_list.size() == 1 && objects_list[0]->roleName == user_meta.userName)) {
3232  dash.is_dash_shared = false;
3233  } else {
3234  dash.is_dash_shared = true;
3235  }
3236  dashboards.push_back(dash);
3237  }
3238  }
3239 }
static const AccessPrivileges VIEW_DASHBOARD
Definition: DBObject.h:164
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
static bool is_allowed_on_dashboard(const Catalog_Namespace::SessionInfo &session_info, int32_t dashboard_id, AccessPrivileges requestedPermissions)
#define STDLOG(...)
Definition: QueryState.h:225
+ 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 2162 of file MapDHandler.cpp.

References get_session_ptr(), and STDLOG.

2163  {
2164  auto stdlog = STDLOG(get_session_ptr(session));
2165  auto session_ptr = stdlog.getConstSessionInfo();
2166  const auto& user = session_ptr->get_currentUser();
2168  SysCatalog::instance().getDatabaseListForUser(user);
2169  for (auto& db : dbs) {
2170  TDBInfo dbinfo;
2171  dbinfo.db_name = std::move(db.dbName);
2172  dbinfo.db_owner = std::move(db.dbOwnerName);
2173  dbinfos.push_back(std::move(dbinfo));
2174  }
2175 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
std::list< DBSummary > DBSummaryList
Definition: SysCatalog.h:121
#define STDLOG(...)
Definition: QueryState.h:225
+ 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 1553 of file MapDHandler.cpp.

References AccessPrivileges::ALL_TABLE, DashboardDBObjectType, DatabaseDBObjectType, get_session_ptr(), DBObject::getObjectKey(), DBObject::loadKey(), serialize_db_object(), STDLOG, TableDBObjectType, THROW_MAPD_EXCEPTION, to_string(), and ViewDBObjectType.

1556  {
1557  auto stdlog = STDLOG(get_session_ptr(sessionId));
1558  auto session_ptr = stdlog.getConstSessionInfo();
1559  DBObjectType object_type;
1560  switch (type) {
1562  object_type = DBObjectType::DatabaseDBObjectType;
1563  break;
1565  object_type = DBObjectType::TableDBObjectType;
1566  break;
1569  break;
1571  object_type = DBObjectType::ViewDBObjectType;
1572  break;
1573  default:
1574  THROW_MAPD_EXCEPTION("Failed to get object privileges for " + objectName +
1575  ": unknown object type (" + std::to_string(type) + ").");
1576  }
1577  DBObject object_to_find(objectName, object_type);
1578 
1579  try {
1580  if (object_type == DashboardDBObjectType) {
1581  if (objectName == "") {
1582  object_to_find = DBObject(-1, object_type);
1583  } else {
1584  object_to_find = DBObject(std::stoi(objectName), object_type);
1585  }
1586  } else if ((object_type == TableDBObjectType || object_type == ViewDBObjectType) &&
1587  !objectName.empty()) {
1588  // special handling for view / table
1589  auto const& cat = session_ptr->getCatalog();
1590  auto td = cat.getMetadataForTable(objectName, false);
1591  if (td) {
1592  object_type = td->isView ? ViewDBObjectType : TableDBObjectType;
1593  object_to_find = DBObject(objectName, object_type);
1594  }
1595  }
1596  object_to_find.loadKey(session_ptr->getCatalog());
1597  } catch (const std::exception&) {
1598  THROW_MAPD_EXCEPTION("Object with name " + objectName + " does not exist.");
1599  }
1600 
1601  // object type on database level
1602  DBObject object_to_find_dblevel("", object_type);
1603  object_to_find_dblevel.loadKey(session_ptr->getCatalog());
1604  // if user is superuser respond with a full priv
1605  if (session_ptr->get_currentUser().isSuper) {
1606  // using ALL_TABLE here to set max permissions
1607  DBObject dbObj{object_to_find.getObjectKey(),
1609  session_ptr->get_currentUser().userId};
1610  dbObj.setName("super");
1611  TDBObjects.push_back(
1612  serialize_db_object(session_ptr->get_currentUser().userName, dbObj));
1613  };
1614 
1615  std::vector<std::string> grantees =
1616  SysCatalog::instance().getRoles(true,
1617  session_ptr->get_currentUser().isSuper,
1618  session_ptr->get_currentUser().userName);
1619  for (const auto& grantee : grantees) {
1620  DBObject* object_found;
1621  auto* gr = SysCatalog::instance().getGrantee(grantee);
1622  if (gr && (object_found = gr->findDbObject(object_to_find.getObjectKey(), true))) {
1623  TDBObjects.push_back(serialize_db_object(grantee, *object_found));
1624  }
1625  // check object permissions on Database level
1626  if (gr &&
1627  (object_found = gr->findDbObject(object_to_find_dblevel.getObjectKey(), true))) {
1628  TDBObjects.push_back(serialize_db_object(grantee, *object_found));
1629  }
1630  }
1631 }
DBObjectType
Definition: DBObject.h:42
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
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:197
static const AccessPrivileges ALL_TABLE
Definition: DBObject.h:150
#define STDLOG(...)
Definition: QueryState.h:225
+ 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 1526 of file MapDHandler.cpp.

References get_session_ptr(), serialize_db_object(), STDLOG, and THROW_MAPD_EXCEPTION.

1528  {
1529  auto stdlog = STDLOG(get_session_ptr(sessionId));
1530  auto session_ptr = stdlog.getConstSessionInfo();
1531  auto const& user = session_ptr->get_currentUser();
1532  if (!user.isSuper &&
1533  !SysCatalog::instance().isRoleGrantedToGrantee(user.userName, roleName, false)) {
1534  return;
1535  }
1536  auto* rl = SysCatalog::instance().getGrantee(roleName);
1537  if (rl) {
1538  auto dbId = session_ptr->getCatalog().getCurrentDB().dbId;
1539  for (auto& dbObject : *rl->getDbObjects(true)) {
1540  if (dbObject.first.dbId != dbId) {
1541  // TODO (max): it doesn't scale well in case we have many DBs (not a typical
1542  // usecase for now, though)
1543  continue;
1544  }
1545  TDBObject tdbObject = serialize_db_object(roleName, *dbObject.second);
1546  TDBObjectsForRole.push_back(tdbObject);
1547  }
1548  } else {
1549  THROW_MAPD_EXCEPTION("User or role " + roleName + " does not exist.");
1550  }
1551 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
static TDBObject serialize_db_object(const std::string &roleName, const DBObject &inObject)
#define THROW_MAPD_EXCEPTION(errstr)
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ get_device_parameters()

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

Definition at line 5733 of file MapDHandler.cpp.

References get_session_copy().

Referenced by emergency_shutdown().

5734  {
5735  const auto session_info = get_session_copy(session);
5736  auto params = ::get_device_parameters();
5737  for (auto item : params) {
5738  _return.insert(item);
5739  }
5740 }
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
void get_device_parameters(std::map< std::string, std::string > &_return, const TSessionId &session) override
+ Here is the call graph for this function:
+ 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 4205 of file MapDHandler.cpp.

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

4208  {
4209  auto stdlog =
4210  STDLOG(get_session_ptr(session), "get_first_geo_file_in_archive", archive_path_in);
4211  std::string archive_path(archive_path_in);
4212 
4213  if (path_is_relative(archive_path)) {
4214  // assume relative paths are relative to data_path / mapd_import / <session>
4215  auto file_path = import_path_ / picosha2::hash256_hex_string(session) /
4216  boost::filesystem::path(archive_path).filename();
4217  archive_path = file_path.string();
4218  }
4219 
4220  if (is_a_supported_archive_file(archive_path)) {
4221  // find the archive file
4222  add_vsi_network_prefix(archive_path);
4223  if (!Importer_NS::Importer::gdalFileExists(archive_path,
4224  thrift_to_copyparams(copy_params))) {
4225  THROW_MAPD_EXCEPTION("Archive does not exist: " + archive_path_in);
4226  }
4227  // find geo file in archive
4228  add_vsi_archive_prefix(archive_path);
4229  std::string geo_file =
4230  find_first_geo_file_in_archive(archive_path, thrift_to_copyparams(copy_params));
4231  // what did we get?
4232  if (geo_file.size()) {
4233  // prepend it with the original path
4234  _return = archive_path_in + std::string("/") + geo_file;
4235  } else {
4236  // just return the original path
4237  _return = archive_path_in;
4238  }
4239  } else {
4240  // just return the original path
4241  _return = archive_path_in;
4242  }
4243 }
void add_vsi_network_prefix(std::string &path)
boost::filesystem::path import_path_
Definition: MapDHandler.h:446
void add_vsi_archive_prefix(std::string &path)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
#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:4461
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)
#define STDLOG(...)
Definition: QueryState.h:225
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 600 of file MapDHandler.cpp.

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

601  {
602  auto stdlog = STDLOG(get_session_ptr(session));
603  THardwareInfo ret;
604  const auto cuda_mgr = data_mgr_->getCudaMgr();
605  if (cuda_mgr) {
606  ret.num_gpu_hw = cuda_mgr->getDeviceCount();
607  ret.start_gpu = cuda_mgr->getStartGpu();
608  if (ret.start_gpu >= 0) {
609  ret.num_gpu_allocated = cuda_mgr->getDeviceCount() - cuda_mgr->getStartGpu();
610  // ^ This will break as soon as we allow non contiguous GPU allocations to MapD
611  }
612  for (int16_t device_id = 0; device_id < ret.num_gpu_hw; device_id++) {
613  TGpuSpecification gpu_spec;
614  auto deviceProperties = cuda_mgr->getDeviceProperties(device_id);
615  gpu_spec.num_sm = deviceProperties->numMPs;
616  gpu_spec.clock_frequency_kHz = deviceProperties->clockKhz;
617  gpu_spec.memory = deviceProperties->globalMem;
618  gpu_spec.compute_capability_major = deviceProperties->computeMajor;
619  gpu_spec.compute_capability_minor = deviceProperties->computeMinor;
620  ret.gpu_info.push_back(gpu_spec);
621  }
622  }
623 
624  // start hardware/OS dependent code
625  ret.num_cpu_hw = std::thread::hardware_concurrency();
626  // ^ This might return diffrent results in case of hyper threading
627  // end hardware/OS dependent code
628 
629  _return.hardware_info.push_back(ret);
630  if (leaf_aggregator_.leafCount() > 0) {
631  ret.host_name = "aggregator";
632  TClusterHardwareInfo leaf_hardware = leaf_aggregator_.getHardwareInfo(session);
633  _return.hardware_info.insert(_return.hardware_info.end(),
634  leaf_hardware.hardware_info.begin(),
635  leaf_hardware.hardware_info.end());
636  }
637 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:443
TClusterHardwareInfo getHardwareInfo(TSessionId session)
std::shared_ptr< Data_Namespace::DataMgr > data_mgr_
Definition: MapDHandler.h:441
size_t leafCount() const
#define STDLOG(...)
Definition: QueryState.h:225
+ 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 4375 of file MapDHandler.cpp.

References get_session_ptr(), STDLOG, and THROW_MAPD_EXCEPTION.

4375  {
4376  auto stdlog = STDLOG(get_session_ptr(session));
4377 #ifdef HAVE_PROFILER
4378  if (!IsHeapProfilerRunning()) {
4379  THROW_MAPD_EXCEPTION("Profiler not running");
4380  }
4381  auto profile_buff = GetHeapProfile();
4382  profile = profile_buff;
4383  free(profile_buff);
4384 #else
4385  THROW_MAPD_EXCEPTION("Profiler not enabled");
4386 #endif // HAVE_PROFILER
4387 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
#define THROW_MAPD_EXCEPTION(errstr)
#define STDLOG(...)
Definition: QueryState.h:225
+ 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 1778 of file MapDHandler.cpp.

References get_session_ptr(), get_table_details_impl(), and STDLOG.

1780  {
1781  auto stdlog = STDLOG(get_session_ptr(session), "table_name", table_name);
1782  get_table_details_impl(_return, stdlog, table_name, true, false);
1783 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
void get_table_details_impl(TTableDetails &_return, query_state::StdLog &stdlog, const std::string &table_name, const bool get_system, const bool get_physical)
#define STDLOG(...)
Definition: QueryState.h:225
+ 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 4278 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, get_session_ptr(), import_path_, is_a_supported_archive_file(), is_a_supported_geo_file(), Importer_NS::Importer::NON_GEO, path_is_relative(), STDLOG, thrift_to_copyparams(), THROW_MAPD_EXCEPTION, and Importer_NS::Importer::UNSUPPORTED_GEO.

4281  {
4282  auto stdlog = STDLOG(get_session_ptr(session), "get_layers_in_geo_file", file_name_in);
4283  std::string file_name(file_name_in);
4284 
4286 
4287  // handle relative paths
4288  if (path_is_relative(file_name)) {
4289  // assume relative paths are relative to data_path / mapd_import / <session>
4290  auto file_path = import_path_ / picosha2::hash256_hex_string(session) /
4291  boost::filesystem::path(file_name).filename();
4292  file_name = file_path.string();
4293  }
4294 
4295  // validate file_name
4296  if (is_a_supported_geo_file(file_name, true)) {
4297  // prepare to load geo file directly
4298  add_vsi_network_prefix(file_name);
4299  add_vsi_geo_prefix(file_name);
4300  } else if (is_a_supported_archive_file(file_name)) {
4301  // find the archive file
4302  add_vsi_network_prefix(file_name);
4303  if (!Importer_NS::Importer::gdalFileExists(file_name, copy_params)) {
4304  THROW_MAPD_EXCEPTION("Archive does not exist: " + file_name_in);
4305  }
4306  // find geo file in archive
4307  add_vsi_archive_prefix(file_name);
4308  std::string geo_file = find_first_geo_file_in_archive(file_name, copy_params);
4309  // prepare to load that geo file
4310  if (geo_file.size()) {
4311  file_name = file_name + std::string("/") + geo_file;
4312  }
4313  } else {
4314  THROW_MAPD_EXCEPTION("File is not a supported geo or geo archive file: " +
4315  file_name_in);
4316  }
4317 
4318  // check the file actually exists
4319  if (!Importer_NS::Importer::gdalFileOrDirectoryExists(file_name, copy_params)) {
4320  THROW_MAPD_EXCEPTION("Geo file/archive does not exist: " + file_name_in);
4321  }
4322 
4323  // find all layers
4324  auto internal_layer_info =
4325  Importer_NS::Importer::gdalGetLayersInGeoFile(file_name, copy_params);
4326 
4327  // convert to Thrift type
4328  for (const auto& internal_layer : internal_layer_info) {
4329  TGeoFileLayerInfo layer;
4330  layer.name = internal_layer.name;
4331  switch (internal_layer.contents) {
4333  layer.contents = TGeoFileLayerContents::EMPTY;
4334  break;
4336  layer.contents = TGeoFileLayerContents::GEO;
4337  break;
4339  layer.contents = TGeoFileLayerContents::NON_GEO;
4340  break;
4342  layer.contents = TGeoFileLayerContents::UNSUPPORTED_GEO;
4343  break;
4344  default:
4345  CHECK(false);
4346  }
4347  _return.emplace_back(layer); // no suitable constructor to just pass parameters
4348  }
4349 }
static std::vector< GeoFileLayerInfo > gdalGetLayersInGeoFile(const std::string &file_name, const CopyParams &copy_params)
Definition: Importer.cpp:4563
void add_vsi_network_prefix(std::string &path)
boost::filesystem::path import_path_
Definition: MapDHandler.h:446
void add_vsi_archive_prefix(std::string &path)
void add_vsi_geo_prefix(std::string &path)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
#define THROW_MAPD_EXCEPTION(errstr)
static bool gdalFileOrDirectoryExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:4466
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:4461
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:193
Importer_NS::CopyParams thrift_to_copyparams(const TCopyParams &cp)
#define STDLOG(...)
Definition: QueryState.h:225
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 5709 of file MapDHandler.cpp.

References get_session_copy(), get_session_ptr(), and STDLOG.

5711  {
5712  auto stdlog = STDLOG(get_session_ptr(session));
5713  const auto session_info = get_session_copy(session);
5714  _return.claims.emplace_back("");
5715 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
#define STDLOG(...)
Definition: QueryState.h:225
+ 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 1874 of file MapDHandler.cpp.

References get_session_ptr(), STDLOG, THROW_MAPD_EXCEPTION, and to_string().

1876  {
1877  auto stdlog = STDLOG(get_session_ptr(session));
1878  auto session_ptr = stdlog.getConstSessionInfo();
1879  auto const& cat = session_ptr->getCatalog();
1880  auto ld = cat.getMetadataForLink(std::to_string(cat.getCurrentDB().dbId) + link);
1881  if (!ld) {
1882  THROW_MAPD_EXCEPTION("Link " + link + " is not valid.");
1883  }
1884  _return.view_state = ld->viewState;
1885  _return.view_name = ld->link;
1886  _return.update_time = ld->updateTime;
1887  _return.view_metadata = ld->viewMetadata;
1888 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
std::string to_string(char const *&&v)
#define THROW_MAPD_EXCEPTION(errstr)
#define STDLOG(...)
Definition: QueryState.h:225
+ 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 2118 of file MapDHandler.cpp.

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

2120  {
2121  auto stdlog = STDLOG(get_session_ptr(session));
2122  std::vector<Data_Namespace::MemoryInfo> internal_memory;
2123  Data_Namespace::MemoryLevel mem_level;
2124  if (!memory_level.compare("gpu")) {
2126  internal_memory =
2127  SysCatalog::instance().getDataMgr().getMemoryInfo(MemoryLevel::GPU_LEVEL);
2128  } else {
2130  internal_memory =
2131  SysCatalog::instance().getDataMgr().getMemoryInfo(MemoryLevel::CPU_LEVEL);
2132  }
2133 
2134  for (auto memInfo : internal_memory) {
2135  TNodeMemoryInfo nodeInfo;
2136  if (leaf_aggregator_.leafCount() > 0) {
2137  nodeInfo.host_name = get_hostname();
2138  }
2139  nodeInfo.page_size = memInfo.pageSize;
2140  nodeInfo.max_num_pages = memInfo.maxNumPages;
2141  nodeInfo.num_pages_allocated = memInfo.numPageAllocated;
2142  nodeInfo.is_allocation_capped = memInfo.isAllocationCapped;
2143  for (auto gpu : memInfo.nodeMemoryData) {
2144  TMemoryData md;
2145  md.slab = gpu.slabNum;
2146  md.start_page = gpu.startPage;
2147  md.num_pages = gpu.numPages;
2148  md.touch = gpu.touch;
2149  md.chunk_key.insert(md.chunk_key.end(), gpu.chunk_key.begin(), gpu.chunk_key.end());
2150  md.is_free = gpu.memStatus == Buffer_Namespace::MemStatus::FREE;
2151  nodeInfo.node_memory_data.push_back(md);
2152  }
2153  _return.push_back(nodeInfo);
2154  }
2155  if (leaf_aggregator_.leafCount() > 0) {
2156  std::vector<TNodeMemoryInfo> leafSummary =
2157  leaf_aggregator_.getLeafMemoryInfo(session, mem_level);
2158  _return.insert(_return.begin(), leafSummary.begin(), leafSummary.end());
2159  }
2160 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:443
std::vector< TNodeMemoryInfo > getLeafMemoryInfo(TSessionId session, Data_Namespace::MemoryLevel memory_level)
std::string get_hostname()
Definition: SysInfo.cpp:6
size_t leafCount() const
#define STDLOG(...)
Definition: QueryState.h:225
+ 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 1947 of file MapDHandler.cpp.

References GET_PHYSICAL_TABLES, get_session_ptr(), get_tables_impl(), and STDLOG.

1948  {
1949  auto stdlog = STDLOG(get_session_ptr(session));
1950  get_tables_impl(table_names, *stdlog.getConstSessionInfo(), GET_PHYSICAL_TABLES);
1951 }
void get_tables_impl(std::vector< std::string > &table_names, const Catalog_Namespace::SessionInfo &, const GetTablesType get_tables_type)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
#define STDLOG(...)
Definition: QueryState.h:225
+ 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 1680 of file MapDHandler.cpp.

References anonymous_namespace{MapDHandler.cpp}::dump_table_col_names(), get_session_ptr(), render_handler_, STDLOG, and THROW_MAPD_EXCEPTION.

1688  {
1689  auto stdlog = STDLOG(get_session_ptr(session),
1690  "widget_id",
1691  widget_id,
1692  "pixel.x",
1693  pixel.x,
1694  "pixel.y",
1695  pixel.y,
1696  "column_format",
1697  column_format,
1698  "pixel_radius",
1699  pixel_radius,
1700  "table_col_names",
1701  dump_table_col_names(table_col_names),
1702  "nonce",
1703  nonce);
1704  auto session_ptr = stdlog.getSessionInfo();
1705  if (!render_handler_) {
1706  THROW_MAPD_EXCEPTION("Backend rendering is disabled.");
1707  }
1708 
1709  try {
1710  render_handler_->get_result_row_for_pixel(_return,
1711  session_ptr,
1712  widget_id,
1713  pixel,
1714  table_col_names,
1715  column_format,
1716  pixel_radius,
1717  nonce);
1718  } catch (std::exception& e) {
1719  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
1720  }
1721 }
std::unique_ptr< MapDRenderHandler > render_handler_
Definition: MapDHandler.h:461
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
#define THROW_MAPD_EXCEPTION(errstr)
std::string dump_table_col_names(const std::map< std::string, std::vector< std::string >> &table_col_names)
#define STDLOG(...)
Definition: QueryState.h:225
+ 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 1307 of file MapDHandler.cpp.

References get_session_ptr(), and STDLOG.

1307  {
1308  auto stdlog = STDLOG(get_session_ptr(session));
1309  auto session_ptr = stdlog.getConstSessionInfo();
1310  if (!session_ptr->get_currentUser().isSuper) {
1311  // WARNING: This appears to not include roles a user is a member of,
1312  // if the role has no permissions granted to it.
1313  roles =
1314  SysCatalog::instance().getRoles(session_ptr->get_currentUser().userName,
1315  session_ptr->getCatalog().getCurrentDB().dbId);
1316  } else {
1317  roles = SysCatalog::instance().getRoles(
1318  false, true, session_ptr->get_currentUser().userName);
1319  }
1320 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
#define STDLOG(...)
Definition: QueryState.h:225
+ 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 559 of file MapDHandler.cpp.

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

559  {
560  auto stdlog = STDLOG(get_session_ptr(session));
561  const auto rendering_enabled = bool(render_handler_);
562  _return.read_only = read_only_;
563  _return.version = MAPD_RELEASE;
564  _return.rendering_enabled = rendering_enabled;
565  _return.poly_rendering_enabled = rendering_enabled;
566  _return.start_time = start_time_;
567  _return.edition = MAPD_EDITION;
568  _return.host_name = get_hostname();
569 }
std::unique_ptr< MapDRenderHandler > render_handler_
Definition: MapDHandler.h:461
static const std::string MAPD_EDITION
Definition: release.h:41
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
int64_t start_time_
Definition: MapDHandler.h:458
const bool read_only_
Definition: MapDHandler.h:453
std::string get_hostname()
Definition: SysInfo.cpp:6
static const std::string MAPD_RELEASE
Definition: release.h:43
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ get_session_copy()

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

Definition at line 4411 of file MapDHandler.cpp.

References get_session_it_unsafe(), and sessions_mutex_.

Referenced by check_table_load_privileges(), get_device_parameters(), get_license_claims(), get_valid_groups(), and register_runtime_extension_functions().

4411  {
4412  mapd_shared_lock<mapd_shared_mutex> read_lock(sessions_mutex_);
4413  return *get_session_it_unsafe(session, read_lock)->second;
4414 }
SessionMap::iterator get_session_it_unsafe(const TSessionId &session, SESSION_MAP_LOCK &lock)
mapd_shared_mutex sessions_mutex_
Definition: MapDHandler.h:456
+ Here is the call graph for this function:
+ Here is the caller 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 4416 of file MapDHandler.cpp.

References get_session_it_unsafe(), and sessions_mutex_.

4417  {
4418  // Note(Wamsi): We have `get_const_session_ptr` which would return as const SessionInfo
4419  // stored in the map. You can use `get_const_session_ptr` instead of the copy of
4420  // SessionInfo but beware that it can be changed in teh map. So if you do not care about
4421  // the changes then use `get_const_session_ptr` if you do then use this function to get
4422  // a copy. We should eventually aim to merge both `get_const_session_ptr` and
4423  // `get_session_copy_ptr`.
4424  mapd_shared_lock<mapd_shared_mutex> read_lock(sessions_mutex_);
4425  auto& session_info_ref = *get_session_it_unsafe(session, read_lock)->second;
4426  return std::make_shared<Catalog_Namespace::SessionInfo>(session_info_ref);
4427 }
SessionMap::iterator get_session_it_unsafe(const TSessionId &session, SESSION_MAP_LOCK &lock)
mapd_shared_mutex sessions_mutex_
Definition: MapDHandler.h:456
+ Here is the call graph for this function:

◆ get_session_info()

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

Definition at line 639 of file MapDHandler.cpp.

References get_session_ptr(), and STDLOG.

639  {
640  auto session_ptr = get_session_ptr(session);
641  auto stdlog = STDLOG(session_ptr);
642  auto user_metadata = session_ptr->get_currentUser();
643 
644  _return.user = user_metadata.userName;
645  _return.database = session_ptr->getCatalog().getCurrentDB().dbName;
646  _return.start_time = session_ptr->get_start_time();
647  _return.is_super = user_metadata.isSuper;
648 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ get_session_it_unsafe() [1/3]

template<>
SessionMap::iterator MapDHandler::get_session_it_unsafe ( const TSessionId &  session,
mapd_shared_lock< mapd_shared_mutex > &  read_lock 
)

Definition at line 136 of file MapDHandler.cpp.

References anonymous_namespace{MapDHandler.cpp}::get_session_from_map(), and THROW_MAPD_EXCEPTION.

138  {
139  auto session_it = get_session_from_map(session, sessions_);
140  try {
141  check_session_exp_unsafe(session_it);
142  } catch (const ForceDisconnect& e) {
143  read_lock.unlock();
144  mapd_lock_guard<mapd_shared_mutex> write_lock(sessions_mutex_);
145  auto session_it2 = get_session_from_map(session, sessions_);
146  disconnect_impl(session_it2);
147  THROW_MAPD_EXCEPTION(e.what());
148  }
149  return session_it;
150 }
SessionMap sessions_
Definition: MapDHandler.h:680
mapd_shared_mutex sessions_mutex_
Definition: MapDHandler.h:456
#define THROW_MAPD_EXCEPTION(errstr)
void check_session_exp_unsafe(const SessionMap::iterator &session_it)
void disconnect_impl(const SessionMap::iterator &session_it)
SessionMap::iterator get_session_from_map(const TSessionId &session, SessionMap &session_map)
+ Here is the call graph for this function:

◆ get_session_it_unsafe() [2/3]

template<>
SessionMap::iterator MapDHandler::get_session_it_unsafe ( const TSessionId &  session,
mapd_lock_guard< mapd_shared_mutex > &  write_lock 
)

Definition at line 153 of file MapDHandler.cpp.

References anonymous_namespace{MapDHandler.cpp}::get_session_from_map(), and THROW_MAPD_EXCEPTION.

155  {
156  auto session_it = get_session_from_map(session, sessions_);
157  try {
158  check_session_exp_unsafe(session_it);
159  } catch (const ForceDisconnect& e) {
160  disconnect_impl(session_it);
161  THROW_MAPD_EXCEPTION(e.what());
162  }
163  return session_it;
164 }
SessionMap sessions_
Definition: MapDHandler.h:680
#define THROW_MAPD_EXCEPTION(errstr)
void check_session_exp_unsafe(const SessionMap::iterator &session_it)
void disconnect_impl(const SessionMap::iterator &session_it)
SessionMap::iterator get_session_from_map(const TSessionId &session, SessionMap &session_map)
+ Here is the call graph for this function:

◆ get_session_it_unsafe() [3/3]

template<typename SESSION_MAP_LOCK >
SessionMap::iterator MapDHandler::get_session_it_unsafe ( const TSessionId &  session,
SESSION_MAP_LOCK &  lock 
)
private

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

+ 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 4429 of file MapDHandler.cpp.

References get_session_it_unsafe(), and sessions_mutex_.

Referenced by check_table_consistency(), checkpoint(), clear_cpu_memory(), clear_gpu_memory(), create_dashboard(), create_link(), deallocate_df(), delete_dashboard(), detect_column_types(), get_all_files_in_archive(), get_all_roles_for_user(), get_completion_hints(), get_const_session_ptr(), get_dashboard(), get_dashboard_grantees(), get_dashboards(), get_databases(), get_db_object_privs(), get_db_objects_for_grantee(), get_first_geo_file_in_archive(), get_hardware_info(), get_heap_profile(), get_internal_table_details(), get_layers_in_geo_file(), get_license_claims(), get_link_view(), get_memory(), get_physical_tables(), get_result_row_for_pixel(), get_roles(), get_server_status(), get_session_info(), get_status(), get_table_details(), get_table_epoch(), get_table_epoch_by_name(), get_tables(), get_tables_meta(), get_users(), get_views(), has_object_privilege(), has_role(), import_geo_table(), import_table(), import_table_status(), insert_data(), interrupt(), load_table(), load_table_binary(), load_table_binary_arrow(), load_table_binary_columnar(), render_vega(), replace_dashboard(), set_execution_mode(), set_license_key(), set_table_epoch(), set_table_epoch_by_name(), share_dashboard(), sql_execute(), sql_execute_df(), sql_execute_gdf(), sql_validate(), start_heap_profile(), start_query(), start_render_query(), stop_heap_profile(), switch_database(), and unshare_dashboard().

4430  {
4431  // Note(Wamsi): This method will give you a shared_ptr to master SessionInfo itself.
4432  // Should be used only when you need to make updates to original SessionInfo object.
4433  // Currently used by `update_session_last_used_duration`
4434 
4435  // 1) `session_id` will be empty during intial connect. 2)`sessionmapd iterator` will be
4436  // invalid during disconnect. SessionInfo will be erased from map by the time it reaches
4437  // here. In both the above cases, we would return `nullptr` and can skip SessionInfo
4438  // updates.
4439  if (session_id.empty()) {
4440  return {};
4441  }
4442  mapd_shared_lock<mapd_shared_mutex> read_lock(sessions_mutex_);
4443  return get_session_it_unsafe(session_id, read_lock)->second;
4444 }
SessionMap::iterator get_session_it_unsafe(const TSessionId &session, SESSION_MAP_LOCK &lock)
mapd_shared_mutex sessions_mutex_
Definition: MapDHandler.h:456
+ Here is the call graph for this function:

◆ get_status()

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

Definition at line 571 of file MapDHandler.cpp.

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

572  {
573  auto stdlog = STDLOG(get_session_ptr(session));
574  const auto rendering_enabled = bool(render_handler_);
575  TServerStatus ret;
576  ret.read_only = read_only_;
577  ret.version = MAPD_RELEASE;
578  ret.rendering_enabled = rendering_enabled;
579  ret.poly_rendering_enabled = rendering_enabled;
580  ret.start_time = start_time_;
581  ret.edition = MAPD_EDITION;
582  ret.host_name = get_hostname();
583 
584  // TSercivePort tcp_port{}
585 
586  if (g_cluster) {
587  ret.role =
588  (leaf_aggregator_.leafCount() > 0) ? TRole::type::AGGREGATOR : TRole::type::LEAF;
589  } else {
590  ret.role = TRole::type::SERVER;
591  }
592 
593  _return.push_back(ret);
594  if (leaf_aggregator_.leafCount() > 0) {
595  std::vector<TServerStatus> leaf_status = leaf_aggregator_.getLeafStatus(session);
596  _return.insert(_return.end(), leaf_status.begin(), leaf_status.end());
597  }
598 }
std::unique_ptr< MapDRenderHandler > render_handler_
Definition: MapDHandler.h:461
bool g_cluster
static const std::string MAPD_EDITION
Definition: release.h:41
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
int64_t start_time_
Definition: MapDHandler.h:458
const bool read_only_
Definition: MapDHandler.h:453
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:443
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)
#define STDLOG(...)
Definition: QueryState.h:225
+ 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 1785 of file MapDHandler.cpp.

References get_session_ptr(), get_table_details_impl(), and STDLOG.

1787  {
1788  auto stdlog = STDLOG(get_session_ptr(session), "table_name", table_name);
1789  get_table_details_impl(_return, stdlog, table_name, false, false);
1790 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
void get_table_details_impl(TTableDetails &_return, query_state::StdLog &stdlog, const std::string &table_name, const bool get_system, const bool get_physical)
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ get_table_details_impl()

void MapDHandler::get_table_details_impl ( TTableDetails &  _return,
query_state::StdLog stdlog,
const std::string &  table_name,
const bool  get_system,
const bool  get_physical 
)
private

Definition at line 1792 of file MapDHandler.cpp.

References CPU, Data_Namespace::CPU_LEVEL, create_query_state(), execute_rel_alg(), fixup_row_descriptor(), query_state::StdLog::getSessionInfo(), hasTableAccessPrivileges(), mapd_parameters_, parse_to_ra(), populateThriftColumnType(), run_benchmark_import::result, query_state::StdLog::setQueryState(), table_is_replicated(), and THROW_MAPD_EXCEPTION.

Referenced by fill_column_names_by_table(), get_internal_table_details(), get_table_details(), and get_uc_compatible_table_names_by_column().

1796  {
1797  auto session_info = stdlog.getSessionInfo();
1798  auto& cat = session_info->getCatalog();
1799  auto td = cat.getMetadataForTable(
1800  table_name,
1801  false); // don't populate fragmenter on this call since we only want metadata
1802  if (!td) {
1803  THROW_MAPD_EXCEPTION("Table " + table_name + " doesn't exist");
1804  }
1805  if (td->isView) {
1806  auto query_state = create_query_state(session_info, td->viewSQL);
1807  stdlog.setQueryState(query_state);
1808  try {
1809  if (hasTableAccessPrivileges(td, *session_info)) {
1810  const auto query_ra = parse_to_ra(query_state->createQueryStateProxy(),
1811  query_state->getQueryStr(),
1812  {},
1813  boost::none,
1815  TQueryResult result;
1816  execute_rel_alg(result,
1817  query_state->createQueryStateProxy(),
1818  query_ra,
1819  true,
1821  -1,
1822  -1,
1823  false,
1824  true,
1825  false,
1826  false,
1827  false);
1828  _return.row_desc = fixup_row_descriptor(result.row_set.row_desc, cat);
1829  } else {
1830  THROW_MAPD_EXCEPTION("User has no access privileges to table " + table_name);
1831  }
1832  } catch (const std::exception& e) {
1833  THROW_MAPD_EXCEPTION("View '" + table_name + "' query has failed with an error: '" +
1834  std::string(e.what()) +
1835  "'.\nThe view must be dropped and re-created to "
1836  "resolve the error. \nQuery:\n" +
1837  query_state->getQueryStr());
1838  }
1839  } else {
1840  try {
1841  if (hasTableAccessPrivileges(td, *session_info)) {
1842  const auto col_descriptors =
1843  cat.getAllColumnMetadataForTable(td->tableId, get_system, true, get_physical);
1844  const auto deleted_cd = cat.getDeletedColumn(td);
1845  for (const auto cd : col_descriptors) {
1846  if (cd == deleted_cd) {
1847  continue;
1848  }
1849  _return.row_desc.push_back(populateThriftColumnType(&cat, cd));
1850  }
1851  } else {
1852  THROW_MAPD_EXCEPTION("User has no access privileges to table " + table_name);
1853  }
1854  } catch (const std::runtime_error& e) {
1855  THROW_MAPD_EXCEPTION(e.what());
1856  }
1857  }
1858  _return.fragment_size = td->maxFragRows;
1859  _return.page_size = td->fragPageSize;
1860  _return.max_rows = td->maxRows;
1861  _return.view_sql = td->viewSQL;
1862  _return.shard_count = td->nShards;
1863  _return.key_metainfo = td->keyMetainfo;
1864  _return.is_temporary = td->persistenceLevel == Data_Namespace::MemoryLevel::CPU_LEVEL;
1865  _return.partition_detail =
1866  td->partitions.empty()
1867  ? TPartitionDetail::DEFAULT
1868  : (table_is_replicated(td)
1869  ? TPartitionDetail::REPLICATED
1870  : (td->partitions == "SHARDED" ? TPartitionDetail::SHARDED
1871  : TPartitionDetail::OTHER));
1872 }
TColumnType populateThriftColumnType(const Catalog_Namespace::Catalog *cat, const ColumnDescriptor *cd)
bool hasTableAccessPrivileges(const TableDescriptor *td, const Catalog_Namespace::SessionInfo &session_info)
std::shared_ptr< Catalog_Namespace::SessionInfo > getSessionInfo() const
Definition: QueryState.cpp:133
std::vector< PushedDownFilterInfo > execute_rel_alg(TQueryResult &_return, QueryStateProxy, const std::string &query_ra, const bool column_format, 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
#define THROW_MAPD_EXCEPTION(errstr)
TRowDescriptor fixup_row_descriptor(const TRowDescriptor &row_desc, const Catalog_Namespace::Catalog &cat)
const MapDParameters & mapd_parameters_
Definition: MapDHandler.h:460
void setQueryState(std::shared_ptr< QueryState >)
Definition: QueryState.cpp:222
std::string parse_to_ra(QueryStateProxy, const std::string &query_str, const std::vector< TFilterPushDownInfo > &filter_push_down_info, OptionalTableMap tableNames, const MapDParameters mapd_parameters, RenderInfo *render_info=nullptr)
bool table_is_replicated(const TableDescriptor *td)
std::shared_ptr< query_state::QueryState > create_query_state(ARGS &&... args)
Definition: MapDHandler.h:468
+ 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 5671 of file MapDHandler.cpp.

References get_session_ptr(), LeafAggregator::get_table_epochLeaf(), leaf_aggregator_, LeafAggregator::leafCount(), and STDLOG.

5673  {
5674  auto stdlog = STDLOG(get_session_ptr(session));
5675  auto session_ptr = stdlog.getConstSessionInfo();
5676  auto const& cat = session_ptr->getCatalog();
5677 
5678  if (leaf_aggregator_.leafCount() > 0) {
5679  return leaf_aggregator_.get_table_epochLeaf(*session_ptr, db_id, table_id);
5680  }
5681  return cat.getTableEpoch(db_id, table_id);
5682 }
int32_t get_table_epochLeaf(const Catalog_Namespace::SessionInfo &parent_session_info, const int32_t db_id, const int32_t table_id)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:443
size_t leafCount() const
#define STDLOG(...)
Definition: QueryState.h:225
+ 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 5684 of file MapDHandler.cpp.

References get_session_ptr(), LeafAggregator::get_table_epochLeaf(), leaf_aggregator_, LeafAggregator::leafCount(), and STDLOG.

5685  {
5686  auto stdlog = STDLOG(get_session_ptr(session), "table_name", table_name);
5687  auto session_ptr = stdlog.getConstSessionInfo();
5688  auto const& cat = session_ptr->getCatalog();
5689  auto td = cat.getMetadataForTable(
5690  table_name,
5691  false); // don't populate fragmenter on this call since we only want metadata
5692  int32_t db_id = cat.getCurrentDB().dbId;
5693  if (leaf_aggregator_.leafCount() > 0) {
5694  return leaf_aggregator_.get_table_epochLeaf(*session_ptr, db_id, td->tableId);
5695  }
5696  return cat.getTableEpoch(db_id, td->tableId);
5697 }
int32_t get_table_epochLeaf(const Catalog_Namespace::SessionInfo &parent_session_info, const int32_t db_id, const int32_t table_id)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:443
size_t leafCount() const
#define STDLOG(...)
Definition: QueryState.h:225
+ 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 1940 of file MapDHandler.cpp.

References GET_PHYSICAL_TABLES_AND_VIEWS, get_session_ptr(), get_tables_impl(), and STDLOG.

1941  {
1942  auto stdlog = STDLOG(get_session_ptr(session));
1944  table_names, *stdlog.getConstSessionInfo(), GET_PHYSICAL_TABLES_AND_VIEWS);
1945 }
void get_tables_impl(std::vector< std::string > &table_names, const Catalog_Namespace::SessionInfo &, const GetTablesType get_tables_type)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ get_tables_impl()

void MapDHandler::get_tables_impl ( std::vector< std::string > &  table_names,
const Catalog_Namespace::SessionInfo session_info,
const GetTablesType  get_tables_type 
)
private

Definition at line 1907 of file MapDHandler.cpp.

References GET_PHYSICAL_TABLES, GET_VIEWS, Catalog_Namespace::SessionInfo::getCatalog(), hasTableAccessPrivileges(), and run_benchmark_import::tables.

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

1909  {
1910  auto const& cat = session_info.getCatalog();
1911  const auto tables = cat.getAllTableMetadata();
1912  for (const auto td : tables) {
1913  if (td->shard >= 0) {
1914  // skip shards, they're not standalone tables
1915  continue;
1916  }
1917  switch (get_tables_type) {
1918  case GET_PHYSICAL_TABLES: {
1919  if (td->isView) {
1920  continue;
1921  }
1922  break;
1923  }
1924  case GET_VIEWS: {
1925  if (!td->isView) {
1926  continue;
1927  }
1928  }
1929  default:
1930  break;
1931  }
1932  if (!hasTableAccessPrivileges(td, session_info)) {
1933  // skip table, as there are no privileges to access it
1934  continue;
1935  }
1936  table_names.push_back(td->tableName);
1937  }
1938 }
bool hasTableAccessPrivileges(const TableDescriptor *td, const Catalog_Namespace::SessionInfo &session_info)
Catalog & getCatalog() const
Definition: SessionInfo.h:90
+ 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 1959 of file MapDHandler.cpp.

References CPU, create_query_state(), execute_rel_alg(), get_session_ptr(), hasTableAccessPrivileges(), LOG, mapd_parameters_, parse_to_ra(), run_benchmark_import::result, STDLOG, table_is_replicated(), run_benchmark_import::tables, THROW_MAPD_EXCEPTION, ThriftSerializers::type_info_to_thrift(), and logger::WARNING.

1960  {
1961  auto stdlog = STDLOG(get_session_ptr(session));
1962  auto session_ptr = stdlog.getConstSessionInfo();
1963  auto query_state = create_query_state(session_ptr, "");
1964  stdlog.setQueryState(query_state);
1965 
1966  const auto& cat = session_ptr->getCatalog();
1967  const auto tables = cat.getAllTableMetadata();
1968  _return.reserve(tables.size());
1969 
1970  for (const auto td : tables) {
1971  if (td->shard >= 0) {
1972  // skip shards, they're not standalone tables
1973  continue;
1974  }
1975  if (!hasTableAccessPrivileges(td, *session_ptr)) {
1976  // skip table, as there are no privileges to access it
1977  continue;
1978  }
1979 
1980  TTableMeta ret;
1981  ret.table_name = td->tableName;
1982  ret.is_view = td->isView;
1983  ret.is_replicated = table_is_replicated(td);
1984  ret.shard_count = td->nShards;
1985  ret.max_rows = td->maxRows;
1986  ret.table_id = td->tableId;
1987 
1988  std::vector<TTypeInfo> col_types;
1989  std::vector<std::string> col_names;
1990  size_t num_cols = 0;
1991  if (td->isView) {
1992  try {
1993  const auto query_ra = parse_to_ra(query_state->createQueryStateProxy(),
1994  td->viewSQL,
1995  {},
1996  boost::none,
1998  TQueryResult result;
1999  execute_rel_alg(result,
2000  query_state->createQueryStateProxy(),
2001  query_ra,
2002  true,
2004  -1,
2005  -1,
2006  false,
2007  true,
2008  false,
2009  false,
2010  false);
2011  num_cols = result.row_set.row_desc.size();
2012  for (const auto col : result.row_set.row_desc) {
2013  if (col.is_physical) {
2014  num_cols--;
2015  continue;
2016  }
2017  col_types.push_back(col.col_type);
2018  col_names.push_back(col.col_name);
2019  }
2020  } catch (std::exception& e) {
2021  LOG(WARNING) << "get_tables_meta: Ignoring broken view: " << td->tableName;
2022  }
2023  } else {
2024  try {
2025  if (hasTableAccessPrivileges(td, *session_ptr)) {
2026  const auto col_descriptors =
2027  cat.getAllColumnMetadataForTable(td->tableId, false, true, false);
2028  const auto deleted_cd = cat.getDeletedColumn(td);
2029  for (const auto cd : col_descriptors) {
2030  if (cd == deleted_cd) {
2031  continue;
2032  }
2033  col_types.push_back(ThriftSerializers::type_info_to_thrift(cd->columnType));
2034  col_names.push_back(cd->columnName);
2035  }
2036  num_cols = col_descriptors.size();
2037  } else {
2038  continue;
2039  }
2040  } catch (const std::runtime_error& e) {
2041  THROW_MAPD_EXCEPTION(e.what());
2042  }
2043  }
2044 
2045  ret.num_cols = num_cols;
2046  std::copy(col_types.begin(), col_types.end(), std::back_inserter(ret.col_types));
2047  std::copy(col_names.begin(), col_names.end(), std::back_inserter(ret.col_names));
2048 
2049  _return.push_back(ret);
2050  }
2051 }
bool hasTableAccessPrivileges(const TableDescriptor *td, const Catalog_Namespace::SessionInfo &session_info)
#define LOG(tag)
Definition: Logger.h:188
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
std::vector< PushedDownFilterInfo > execute_rel_alg(TQueryResult &_return, QueryStateProxy, const std::string &query_ra, const bool column_format, 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
#define THROW_MAPD_EXCEPTION(errstr)
const MapDParameters & mapd_parameters_
Definition: MapDHandler.h:460
std::string parse_to_ra(QueryStateProxy, const std::string &query_str, const std::vector< TFilterPushDownInfo > &filter_push_down_info, OptionalTableMap tableNames, const MapDParameters mapd_parameters, RenderInfo *render_info=nullptr)
bool table_is_replicated(const TableDescriptor *td)
std::shared_ptr< query_state::QueryState > create_query_state(ARGS &&... args)
Definition: MapDHandler.h:468
TTypeInfo type_info_to_thrift(const SQLTypeInfo &ti)
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ get_token_based_completions()

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

Definition at line 1184 of file MapDHandler.cpp.

References fill_column_names_by_table(), find_last_word_from_cursor(), get_column_hints(), get_qualified_column_hints(), and should_suggest_column_hints().

Referenced by get_completion_hints_unsorted().

1188  {
1189  const auto last_word =
1190  find_last_word_from_cursor(sql, cursor < 0 ? sql.size() : cursor);
1191  boost::regex select_expr{R"(\s*select\s+)",
1192  boost::regex::extended | boost::regex::icase};
1193  const size_t length_to_cursor =
1194  cursor < 0 ? sql.size() : std::min(sql.size(), static_cast<size_t>(cursor));
1195  // After SELECT but before FROM, look for all columns in all tables which match the
1196  // prefix.
1197  if (boost::regex_search(sql.cbegin(), sql.cbegin() + length_to_cursor, select_expr)) {
1198  const auto column_names_by_table = fill_column_names_by_table(visible_tables, stdlog);
1199  // Trust the fully qualified columns the most.
1200  if (get_qualified_column_hints(hints, last_word, column_names_by_table)) {
1201  return;
1202  }
1203  // Not much information to use, just retrieve column names which match the prefix.
1204  if (should_suggest_column_hints(sql)) {
1205  get_column_hints(hints, last_word, column_names_by_table);
1206  return;
1207  }
1208  const std::string kFromKeyword{"FROM"};
1209  if (boost::istarts_with(kFromKeyword, last_word)) {
1210  TCompletionHint keyword_hint;
1211  keyword_hint.type = TCompletionHintType::KEYWORD;
1212  keyword_hint.replaced = last_word;
1213  keyword_hint.hints.emplace_back(kFromKeyword);
1214  hints.push_back(keyword_hint);
1215  }
1216  } else {
1217  const std::string kSelectKeyword{"SELECT"};
1218  if (boost::istarts_with(kSelectKeyword, last_word)) {
1219  TCompletionHint keyword_hint;
1220  keyword_hint.type = TCompletionHintType::KEYWORD;
1221  keyword_hint.replaced = last_word;
1222  keyword_hint.hints.emplace_back(kSelectKeyword);
1223  hints.push_back(keyword_hint);
1224  }
1225  }
1226 }
std::unordered_map< std::string, std::unordered_set< std::string > > fill_column_names_by_table(std::vector< std::string > &table_names, query_state::StdLog &stdlog)
void get_column_hints(std::vector< TCompletionHint > &hints, const std::string &last_word, const std::unordered_map< std::string, std::unordered_set< std::string >> &column_names_by_table)
bool get_qualified_column_hints(std::vector< TCompletionHint > &hints, const std::string &last_word, const std::unordered_map< std::string, std::unordered_set< std::string >> &column_names_by_table)
bool should_suggest_column_hints(const std::string &partial_query)
std::string find_last_word_from_cursor(const std::string &sql, const ssize_t cursor)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_uc_compatible_table_names_by_column()

std::unordered_set< std::string > MapDHandler::get_uc_compatible_table_names_by_column ( const std::unordered_set< std::string > &  uc_column_names,
std::vector< std::string > &  table_names,
query_state::StdLog stdlog 
)
private

Definition at line 1249 of file MapDHandler.cpp.

References get_table_details_impl(), and to_upper().

Referenced by get_completion_hints().

1252  {
1253  std::unordered_set<std::string> compatible_table_names_by_column;
1254  for (auto it = table_names.begin(); it != table_names.end();) {
1255  TTableDetails table_details;
1256  try {
1257  get_table_details_impl(table_details, stdlog, *it, false, false);
1258  } catch (const TMapDException& e) {
1259  // Remove the corrupted Table/View name from the list for further processing.
1260  it = table_names.erase(it);
1261  continue;
1262  }
1263  for (const auto& column_type : table_details.row_desc) {
1264  if (uc_column_names.find(to_upper(column_type.col_name)) != uc_column_names.end()) {
1265  compatible_table_names_by_column.emplace(to_upper(*it));
1266  break;
1267  }
1268  }
1269  ++it;
1270  }
1271  return compatible_table_names_by_column;
1272 }
void get_table_details_impl(TTableDetails &_return, query_state::StdLog &stdlog, const std::string &table_name, const bool get_system, const bool get_physical)
std::string to_upper(const std::string &str)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_users()

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

Definition at line 2053 of file MapDHandler.cpp.

References get_session_ptr(), and STDLOG.

2054  {
2055  auto stdlog = STDLOG(get_session_ptr(session));
2056  auto session_ptr = stdlog.getConstSessionInfo();
2057  std::list<Catalog_Namespace::UserMetadata> user_list;
2058 
2059  if (!session_ptr->get_currentUser().isSuper) {
2060  user_list = SysCatalog::instance().getAllUserMetadata(
2061  session_ptr->getCatalog().getCurrentDB().dbId);
2062  } else {
2063  user_list = SysCatalog::instance().getAllUserMetadata();
2064  }
2065  for (auto u : user_list) {
2066  user_names.push_back(u.userName);
2067  }
2068 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ get_valid_groups()

std::vector< std::string > MapDHandler::get_valid_groups ( const TSessionId &  session,
int32_t  dashboard_id,
std::vector< std::string >  groups 
)

Definition at line 3341 of file MapDHandler.cpp.

References get_session_copy(), Catalog_Namespace::UserMetadata::isSuper, THROW_MAPD_EXCEPTION, and to_string().

Referenced by share_dashboard(), and unshare_dashboard().

3343  {
3344  const auto session_info = get_session_copy(session);
3345  auto& cat = session_info.getCatalog();
3346  auto dash = cat.getMetadataForDashboard(dashboard_id);
3347  if (!dash) {
3348  THROW_MAPD_EXCEPTION("Exception: Dashboard id " + std::to_string(dashboard_id) +
3349  " does not exist");
3350  } else if (session_info.get_currentUser().userId != dash->userId &&
3351  !session_info.get_currentUser().isSuper) {
3352  throw std::runtime_error(
3353  "User should be either owner of dashboard or super user to share/unshare it");
3354  }
3355  std::vector<std::string> valid_groups;
3357  for (auto& group : groups) {
3358  user_meta.isSuper = false; // initialize default flag
3359  if (!SysCatalog::instance().getGrantee(group)) {
3360  THROW_MAPD_EXCEPTION("Exception: User/Role " + group + " does not exist");
3361  } else if (!user_meta.isSuper) {
3362  valid_group