OmniSciDB  2e3a973ef4
DBHandler Class Reference

#include <DBHandler.h>

+ Inheritance diagram for DBHandler:
+ Collaboration diagram for DBHandler:

Classes

struct  GeoCopyFromSessions
 
struct  GeoCopyFromState
 

Public Member Functions

 DBHandler (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 renderer_use_vulkan_driver, const bool enable_auto_clear_render_mem, const int render_oom_retry_threshold, const size_t render_mem_bytes, const size_t max_concurrent_render_sessions, const int num_gpus, const int start_gpu, const size_t reserved_gpu_mem, const bool render_compositor_use_last_gpu, const size_t num_reader_threads, const AuthMetadata &authMetadata, const SystemParameters &system_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, const std::string &clang_path, const std::vector< std::string > &clang_options, const DiskCacheConfig &disk_cache_config)
 
 ~DBHandler () 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 clone_session (TSessionId &session2, const TSessionId &session1) 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_table_epochs (std::vector< TTableEpochInfo > &_return, const TSessionId &session, const int32_t db_id, const int32_t table_id) override
 
void set_table_epochs (const TSessionId &session, const int32_t db_id, const std::vector< TTableEpochInfo > &table_epochs) 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, const TArrowTransport::type transport_method) 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 &query_session, const TSessionId &interrupt_session) override
 
void sql_validate (TRowDescriptor &_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_dashboards (const TSessionId &session, const std::vector< int32_t > &dashboard_ids, const std::vector< std::string > &groups, const TDashboardPermissions &permissions) override
 
void delete_dashboards (const TSessionId &session, const std::vector< int32_t > &dashboard_ids) 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_dashboards (const TSessionId &session, const std::vector< int32_t > &dashboard_ids, const std::vector< std::string > &groups, const TDashboardPermissions &permissions) 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
 
std::unique_ptr< lockmgr::AbstractLockContainer< const TableDescriptor * > > prepare_columnar_loader (const Catalog_Namespace::SessionInfo &session_info, const std::string &table_name, size_t num_cols, std::unique_ptr< import_export::Loader > *loader, std::vector< std::unique_ptr< import_export::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
 
int64_t query_get_outer_fragment_count (const TSessionId &session, const std::string &select_query) override
 
void check_table_consistency (TTableMeta &_return, const TSessionId &session, const int32_t table_id) override
 
void start_query (TPendingQuery &_return, const TSessionId &leaf_session, const TSessionId &parent_session, const std::string &query_ra, const bool just_explain, const std::vector< int64_t > &outer_fragment_indices) 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)
 
void get_tables_meta_impl (std::vector< TTableMeta > &_return, QueryStateProxy query_state_proxy, const Catalog_Namespace::SessionInfo &session_info, const bool with_table_locks=true)
 
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_unique_lock< mapd_shared_mutex > &write_lock)
 

Static Public Member Functions

static size_t max_bytes_for_thrift ()
 
static void parser_with_error_handler (const std::string &query_str, std::list< std::unique_ptr< Parser::Stmt >> &parse_trees)
 

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 SystemParameterssystem_parameters_
 
std::unique_ptr< RenderHandlerrender_handler_
 
std::unique_ptr< MapDAggHandleragg_handler_
 
std::unique_ptr< MapDLeafHandlerleaf_handler_
 
std::shared_ptr< Calcitecalcite_
 
const bool legacy_syntax_
 
std::unique_ptr< QueryDispatchQueuedispatch_queue_
 

Private Member Functions

std::shared_ptr< Catalog_Namespace::SessionInfocreate_new_session (TSessionId &session, const std::string &dbname, const Catalog_Namespace::UserMetadata &user_meta, std::shared_ptr< Catalog_Namespace::Catalog > cat)
 
void connect_impl (TSessionId &session, const std::string &passwd, const std::string &dbname, const Catalog_Namespace::UserMetadata &user_meta, std::shared_ptr< Catalog_Namespace::Catalog > cat, query_state::StdLog &stdlog)
 
void disconnect_impl (const SessionMap::iterator &session_it, mapd_unique_lock< mapd_shared_mutex > &write_lock)
 
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)
 
void validateGroups (const std::vector< std::string > &groups)
 
void validateDashboardIdsForSharing (const Catalog_Namespace::SessionInfo &session_info, const std::vector< int32_t > &dashboard_ids)
 
void shareOrUnshareDashboards (const TSessionId &session, const std::vector< int32_t > &dashboard_ids, const std::vector< std::string > &groups, const TDashboardPermissions &permissions, const bool do_share)
 
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::pair< TPlanResult, lockmgr::LockedTableDescriptorsparse_to_ra (QueryStateProxy, const std::string &query_str, const std::vector< TFilterPushDownInfo > &filter_push_down_info, const bool acquire_locks, const SystemParameters system_parameters, bool check_privileges=true)
 
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)
 
TQueryResult validate_rel_alg (const std::string &query_ra, 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_validate, const bool find_push_down_candidates, const ExplainInfo &explain_info, const std::optional< size_t > executor_index=std::nullopt) 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 TArrowTransport::type transport_method) const
 
void executeDdl (TQueryResult &_return, const std::string &query_ra, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
 
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)
 
import_export::CopyParams thrift_to_copyparams (const TCopyParams &cp)
 
TCopyParams copyparams_to_thrift (const import_export::CopyParams &cp)
 
void check_geospatial_files (const boost::filesystem::path file_path, const import_export::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
 
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)
 
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)
 
ConnectionInfo getConnectionInfo () const
 
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)
 
void getUserSessions (const Catalog_Namespace::SessionInfo &session_info, TQueryResult &_return)
 
void getQueries (const Catalog_Namespace::SessionInfo &session_info, TQueryResult &_return)
 
void interruptQuery (const Catalog_Namespace::SessionInfo &session_info, const std::string &target_session)
 

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_
 
GeoCopyFromSessions geo_copy_from_sessions
 
std::mutex handle_to_dev_ptr_mutex_
 
std::unordered_map< std::string, std::string > ipc_handle_to_dev_ptr_
 
std::map< const std::string, const PermissionFuncPtrpermissionFuncMap_
 

Friends

class RenderHandler::Impl
 
class MapDAggHandler
 
class MapDLeafHandler
 
void run_warmup_queries (mapd::shared_ptr< DBHandler > handler, std::string base_path, std::string query_file_path)
 

Detailed Description

Definition at line 159 of file DBHandler.h.

Constructor & Destructor Documentation

◆ DBHandler()

DBHandler::DBHandler ( 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  renderer_use_vulkan_driver,
const bool  enable_auto_clear_render_mem,
const int  render_oom_retry_threshold,
const size_t  render_mem_bytes,
const size_t  max_concurrent_render_sessions,
const int  num_gpus,
const int  start_gpu,
const size_t  reserved_gpu_mem,
const bool  render_compositor_use_last_gpu,
const size_t  num_reader_threads,
const AuthMetadata authMetadata,
const SystemParameters system_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,
const std::string &  clang_path,
const std::vector< std::string > &  clang_options,
const DiskCacheConfig disk_cache_config 
)

Definition at line 176 of file DBHandler.cpp.

References ExtensionFunctionsWhitelist::add(), ExtensionFunctionsWhitelist::addUdfs(), agg_handler_, allow_loop_joins_, allow_multifrag_, authMetadata_, base_data_path_, calcite_, UdfCompiler::compileUdf(), CPU, cpu_mode_only_, data_mgr_, dispatch_queue_, 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_, CudaMgr_Namespace::Kepler, leaf_aggregator_, leaf_handler_, LeafAggregator::leafCount(), legacy_syntax_, LOG, MAPD_RELEASE, MapDAggHandler, MapDLeafHandler, max_session_duration_, read_only_, registerArrowCsvForeignStorage(), render_handler_, runtime_udf_registration_enabled_, session_id_dist_, start_time_, string_leaves_, super_user_rights_, and system_parameters_.

209  : leaf_aggregator_(db_leaves)
210  , string_leaves_(string_leaves)
211  , base_data_path_(base_data_path)
212  , random_gen_(std::random_device{}())
213  , session_id_dist_(0, INT32_MAX)
214  , jit_debug_(jit_debug)
215  , intel_jit_profile_(intel_jit_profile)
216  , allow_multifrag_(allow_multifrag)
217  , read_only_(read_only)
218  , allow_loop_joins_(allow_loop_joins)
219  , authMetadata_(authMetadata)
220  , system_parameters_(system_parameters)
221  , legacy_syntax_(legacy_syntax)
222  , dispatch_queue_(
223  std::make_unique<QueryDispatchQueue>(system_parameters.num_executors))
224  , super_user_rights_(false)
225  , idle_session_duration_(idle_session_duration * 60)
226  , max_session_duration_(max_session_duration * 60)
227  , runtime_udf_registration_enabled_(enable_runtime_udf_registration) {
228  LOG(INFO) << "OmniSci Server " << MAPD_RELEASE;
229  // Register foreign storage interfaces here
231  bool is_rendering_enabled = enable_rendering;
232 
233  try {
234  if (cpu_only) {
235  is_rendering_enabled = false;
237  cpu_mode_only_ = true;
238  } else {
239 #ifdef HAVE_CUDA
241  cpu_mode_only_ = false;
242 #else
244  LOG(ERROR) << "This build isn't CUDA enabled, will run on CPU";
245  cpu_mode_only_ = true;
246  is_rendering_enabled = false;
247 #endif
248  }
249  } catch (const std::exception& e) {
250  LOG(FATAL) << "Failed to executor device type: " << e.what();
251  }
252 
253  const auto data_path = boost::filesystem::path(base_data_path_) / "mapd_data";
254  // calculate the total amount of memory we need to reserve from each gpu that the Buffer
255  // manage cannot ask for
256  size_t total_reserved = reserved_gpu_mem;
257  if (is_rendering_enabled) {
258  total_reserved += render_mem_bytes;
259  }
260 
261  try {
262  data_mgr_.reset(new Data_Namespace::DataMgr(data_path.string(),
263  system_parameters,
265  num_gpus,
266  start_gpu,
267  total_reserved,
268  num_reader_threads,
269  disk_cache_config));
270  } catch (const std::exception& e) {
271  LOG(FATAL) << "Failed to initialize data manager: " << e.what();
272  }
273 
274  std::string udf_ast_filename("");
275 
276  try {
277  if (!udf_filename.empty()) {
278  const auto cuda_mgr = data_mgr_->getCudaMgr();
279  const CudaMgr_Namespace::NvidiaDeviceArch device_arch =
280  cuda_mgr ? cuda_mgr->getDeviceArch()
282  UdfCompiler compiler(udf_filename, device_arch, clang_path, clang_options);
283  int compile_result = compiler.compileUdf();
284 
285  if (compile_result == 0) {
286  udf_ast_filename = compiler.getAstFileName();
287  }
288  }
289  } catch (const std::exception& e) {
290  LOG(FATAL) << "Failed to initialize UDF compiler: " << e.what();
291  }
292 
293  try {
294  calcite_ =
295  std::make_shared<Calcite>(system_parameters, base_data_path_, udf_ast_filename);
296  } catch (const std::exception& e) {
297  LOG(FATAL) << "Failed to initialize Calcite server: " << e.what();
298  }
299 
300  try {
301  ExtensionFunctionsWhitelist::add(calcite_->getExtensionFunctionWhitelist());
302  if (!udf_filename.empty()) {
303  ExtensionFunctionsWhitelist::addUdfs(calcite_->getUserDefinedFunctionWhitelist());
304  }
305  } catch (const std::exception& e) {
306  LOG(FATAL) << "Failed to initialize extension functions: " << e.what();
307  }
308 
309  try {
311  } catch (const std::exception& e) {
312  LOG(FATAL) << "Failed to initialize table functions factory: " << e.what();
313  }
314 
315  if (!data_mgr_->gpusPresent() && !cpu_mode_only_) {
317  LOG(ERROR) << "No GPUs detected, falling back to CPU mode";
318  cpu_mode_only_ = true;
319  }
320 
321  switch (executor_device_type_) {
323  LOG(INFO) << "Started in GPU mode" << std::endl;
324  break;
326  LOG(INFO) << "Started in CPU mode" << std::endl;
327  break;
328  }
329 
330  try {
331  SysCatalog::instance().init(base_data_path_,
332  data_mgr_,
333  authMetadata,
334  calcite_,
335  false,
336  !db_leaves.empty(),
338  } catch (const std::exception& e) {
339  LOG(FATAL) << "Failed to initialize system catalog: " << e.what();
340  }
341 
342  import_path_ = boost::filesystem::path(base_data_path_) / "mapd_import";
343  start_time_ = std::time(nullptr);
344 
345  if (is_rendering_enabled) {
346  try {
347  render_handler_.reset(new RenderHandler(this,
348  render_mem_bytes,
349  max_concurrent_render_sessions,
350  render_compositor_use_last_gpu,
351  false,
352  0,
353  false,
355  } catch (const std::exception& e) {
356  LOG(ERROR) << "Backend rendering disabled: " << e.what();
357  }
358  }
359 
360  if (leaf_aggregator_.leafCount() > 0) {
361  try {
362  agg_handler_.reset(new MapDAggHandler(this));
363  } catch (const std::exception& e) {
364  LOG(ERROR) << "Distributed aggregator support disabled: " << e.what();
365  }
366  } else if (g_cluster) {
367  try {
368  leaf_handler_.reset(new MapDLeafHandler(this));
369  } catch (const std::exception& e) {
370  LOG(ERROR) << "Distributed leaf support disabled: " << e.what();
371  }
372  }
373 
374 #ifdef ENABLE_GEOS
375  if (!libgeos_so_filename.empty()) {
376  g_libgeos_so_filename.reset(new std::string(libgeos_so_filename));
377  LOG(INFO) << "Overriding default geos library with '" + *g_libgeos_so_filename + "'";
378  }
379 #endif
380 }
static void addUdfs(const std::string &json_func_sigs)
boost::filesystem::path import_path_
Definition: DBHandler.h:531
std::unique_ptr< QueryDispatchQueue > dispatch_queue_
Definition: DBHandler.h:552
const bool runtime_udf_registration_enabled_
Definition: DBHandler.h:790
friend class MapDLeafHandler
Definition: DBHandler.h:835
const std::vector< LeafHostInfo > string_leaves_
Definition: DBHandler.h:529
#define LOG(tag)
Definition: Logger.h:188
LeafAggregator leaf_aggregator_
Definition: DBHandler.h:528
static void add(const std::string &json_func_sigs)
const std::string base_data_path_
Definition: DBHandler.h:530
const bool jit_debug_
Definition: DBHandler.h:535
int64_t start_time_
Definition: DBHandler.h:543
const int max_session_duration_
Definition: DBHandler.h:788
ExecutorDeviceType executor_device_type_
Definition: DBHandler.h:532
void registerArrowCsvForeignStorage(void)
std::unique_ptr< RenderHandler > render_handler_
Definition: DBHandler.h:546
std::unique_ptr< MapDLeafHandler > leaf_handler_
Definition: DBHandler.h:548
friend class MapDAggHandler
Definition: DBHandler.h:834
const bool allow_loop_joins_
Definition: DBHandler.h:539
const bool intel_jit_profile_
Definition: DBHandler.h:536
bool super_user_rights_
Definition: DBHandler.h:784
std::shared_ptr< Calcite > calcite_
Definition: DBHandler.h:549
const SystemParameters & system_parameters_
Definition: DBHandler.h:545
std::shared_ptr< Data_Namespace::DataMgr > data_mgr_
Definition: DBHandler.h:526
const bool read_only_
Definition: DBHandler.h:538
const bool legacy_syntax_
Definition: DBHandler.h:550
const int idle_session_duration_
Definition: DBHandler.h:787
std::unique_ptr< MapDAggHandler > agg_handler_
Definition: DBHandler.h:547
bool g_cluster
size_t leafCount() const
bool allow_multifrag_
Definition: DBHandler.h:537
static const std::string MAPD_RELEASE
Definition: release.h:43
const AuthMetadata & authMetadata_
Definition: DBHandler.h:544
bool cpu_mode_only_
Definition: DBHandler.h:540
std::default_random_engine random_gen_
Definition: DBHandler.h:533
std::uniform_int_distribution< int64_t > session_id_dist_
Definition: DBHandler.h:534
+ Here is the call graph for this function:

◆ ~DBHandler()

DBHandler::~DBHandler ( )
override

Definition at line 382 of file DBHandler.cpp.

382 {}

Member Function Documentation

◆ apply_copy_to_shim()

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

Definition at line 1198 of file DBHandler.cpp.

References apply_shim(), and run_benchmark_import::result.

Referenced by sql_execute_impl().

1198  {
1199  auto result = query_str;
1200  {
1201  // boost::regex copy_to{R"(COPY\s\((.*)\)\sTO\s(.*))", boost::regex::extended |
1202  // boost::regex::icase};
1203  boost::regex copy_to{R"(COPY\s*\(([^#])(.+)\)\s+TO\s)",
1204  boost::regex::extended | boost::regex::icase};
1205  apply_shim(result, copy_to, [](std::string& result, const boost::smatch& what) {
1206  result.replace(
1207  what.position(), what.length(), "COPY (#~#" + what[1] + what[2] + "#~#) TO ");
1208  });
1209  }
1210  return result;
1211 }
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 DBHandler::broadcast_serialized_rows ( const TSerializedRows &  serialized_rows,
const TRowDescriptor &  row_desc,
const TQueryId  query_id 
)
override

Definition at line 5631 of file DBHandler.cpp.

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

5633  {
5634  if (!leaf_handler_) {
5635  THROW_MAPD_EXCEPTION("Distributed support is disabled.");
5636  }
5637  LOG(INFO) << "BROADCAST-SERIALIZED-ROWS id:" << query_id;
5638  auto time_ms = measure<>::execution([&]() {
5639  try {
5640  leaf_handler_->broadcast_serialized_rows(serialized_rows, row_desc, query_id);
5641  } catch (std::exception& e) {
5642  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
5643  }
5644  });
5645  LOG(INFO) << "BROADCAST-SERIALIZED-ROWS COMPLETED " << time_ms << "ms";
5646 }
#define LOG(tag)
Definition: Logger.h:188
#define THROW_MAPD_EXCEPTION(errstr)
Definition: DBHandler.cpp:113
std::unique_ptr< MapDLeafHandler > leaf_handler_
Definition: DBHandler.h:548
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 DBHandler::check_and_invalidate_sessions ( Parser::DDLStmt ddl)
private

Definition at line 5085 of file DBHandler.cpp.

References invalidate_sessions().

Referenced by sql_execute_impl().

5085  {
5086  const auto drop_db_stmt = dynamic_cast<Parser::DropDBStmt*>(ddl);
5087  if (drop_db_stmt) {
5088  invalidate_sessions(*drop_db_stmt->getDatabaseName(), drop_db_stmt);
5089  return;
5090  }
5091  const auto rename_db_stmt = dynamic_cast<Parser::RenameDatabaseStmt*>(ddl);
5092  if (rename_db_stmt) {
5093  invalidate_sessions(*rename_db_stmt->getPreviousDatabaseName(), rename_db_stmt);
5094  return;
5095  }
5096  const auto drop_user_stmt = dynamic_cast<Parser::DropUserStmt*>(ddl);
5097  if (drop_user_stmt) {
5098  invalidate_sessions(*drop_user_stmt->getUserName(), drop_user_stmt);
5099  return;
5100  }
5101  const auto rename_user_stmt = dynamic_cast<Parser::RenameUserStmt*>(ddl);
5102  if (rename_user_stmt) {
5103  invalidate_sessions(*rename_user_stmt->getOldUserName(), rename_user_stmt);
5104  return;
5105  }
5106 }
void invalidate_sessions(std::string &name, STMT_TYPE *stmt)
Definition: DBHandler.h:846
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ check_geospatial_files()

void DBHandler::check_geospatial_files ( const boost::filesystem::path  file_path,
const import_export::CopyParams copy_params 
)
private

Definition at line 3733 of file DBHandler.cpp.

References import_export::Importer::gdalFileExists().

Referenced by detect_column_types(), and import_geo_table().

3734  {
3735  const std::list<std::string> shp_ext{".shp", ".shx", ".dbf"};
3736  if (std::find(shp_ext.begin(),
3737  shp_ext.end(),
3738  boost::algorithm::to_lower_copy(file_path.extension().string())) !=
3739  shp_ext.end()) {
3740  for (auto ext : shp_ext) {
3741  auto aux_file = file_path;
3743  aux_file.replace_extension(boost::algorithm::to_upper_copy(ext)).string(),
3744  copy_params) &&
3746  aux_file.replace_extension(ext).string(), copy_params)) {
3747  throw std::runtime_error("required file for shapefile does not exist: " +
3748  aux_file.filename().string());
3749  }
3750  }
3751  }
3752 }
static bool gdalFileExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:4561
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ check_read_only()

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

Definition at line 400 of file DBHandler.cpp.

References read_only_, and THROW_MAPD_EXCEPTION.

Referenced by create_dashboard(), create_table(), delete_dashboards(), 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(), shareOrUnshareDashboards(), and sql_execute_impl().

400  {
401  if (DBHandler::read_only_) {
402  THROW_MAPD_EXCEPTION(str + " disabled: server running in read-only mode.");
403  }
404 }
#define THROW_MAPD_EXCEPTION(errstr)
Definition: DBHandler.cpp:113
const bool read_only_
Definition: DBHandler.h:538
+ Here is the caller graph for this function:

◆ check_session_exp_unsafe()

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

Definition at line 4606 of file DBHandler.cpp.

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

4606  {
4607  if (session_it->second.use_count() > 2 ||
4608  isInMemoryCalciteSession(session_it->second->get_currentUser())) {
4609  // SessionInfo is being used in more than one active operation. Original copy + one
4610  // stored in StdLog. Skip the checks.
4611  return;
4612  }
4613  time_t last_used_time = session_it->second->get_last_used_time();
4614  time_t start_time = session_it->second->get_start_time();
4615  const auto current_session_duration = time(0) - last_used_time;
4616  if (current_session_duration > idle_session_duration_) {
4617  LOG(INFO) << "Session " << session_it->second->get_public_session_id()
4618  << " idle duration " << current_session_duration
4619  << " seconds exceeds maximum idle duration " << idle_session_duration_
4620  << " seconds. Invalidating session.";
4621  throw ForceDisconnect("Idle Session Timeout. User should re-authenticate.");
4622  }
4623  const auto total_session_duration = time(0) - start_time;
4624  if (total_session_duration > max_session_duration_) {
4625  LOG(INFO) << "Session " << session_it->second->get_public_session_id()
4626  << " total duration " << total_session_duration
4627  << " seconds exceeds maximum total session duration "
4628  << max_session_duration_ << " seconds. Invalidating session.";
4629  throw ForceDisconnect("Maximum active Session Timeout. User should re-authenticate.");
4630  }
4631 }
#define LOG(tag)
Definition: Logger.h:188
const int max_session_duration_
Definition: DBHandler.h:788
const int idle_session_duration_
Definition: DBHandler.h:787
bool isInMemoryCalciteSession(const Catalog_Namespace::UserMetadata user_meta)
Definition: DBHandler.cpp:432
+ Here is the call graph for this function:

◆ check_table_consistency()

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

Definition at line 5573 of file DBHandler.cpp.

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

5575  {
5576  auto stdlog = STDLOG(get_session_ptr(session));
5577  if (!leaf_handler_) {
5578  THROW_MAPD_EXCEPTION("Distributed support is disabled.");
5579  }
5580  try {
5581  leaf_handler_->check_table_consistency(_return, session, table_id);
5582  } catch (std::exception& e) {
5583  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
5584  }
5585 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:4656
#define THROW_MAPD_EXCEPTION(errstr)
Definition: DBHandler.cpp:113
std::unique_ptr< MapDLeafHandler > leaf_handler_
Definition: DBHandler.h:548
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ check_table_load_privileges() [1/2]

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

Definition at line 4690 of file DBHandler.cpp.

References get_session_copy().

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

4691  {
4692  const auto session_info = get_session_copy(session);
4693  check_table_load_privileges(session_info, table_name);
4694 }
void check_table_load_privileges(const TSessionId &session, const std::string &table_name)
Definition: DBHandler.cpp:4690
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
Definition: DBHandler.cpp:4638
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ check_table_load_privileges() [2/2]

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

Definition at line 4673 of file DBHandler.cpp.

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

4675  {
4676  auto user_metadata = session_info.get_currentUser();
4677  auto& cat = session_info.getCatalog();
4678  DBObject dbObject(table_name, TableDBObjectType);
4679  dbObject.loadKey(cat);
4680  dbObject.setPrivileges(AccessPrivileges::INSERT_INTO_TABLE);
4681  std::vector<DBObject> privObjects;
4682  privObjects.push_back(dbObject);
4683  if (!SysCatalog::instance().checkPrivileges(user_metadata, privObjects)) {
4684  THROW_MAPD_EXCEPTION("Violation of access privileges: user " +
4685  user_metadata.userName + " has no insert privileges for table " +
4686  table_name + ".");
4687  }
4688 }
static const AccessPrivileges INSERT_INTO_TABLE
Definition: DBObject.h:162
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:68
std::string cat(Ts &&... args)
Catalog & getCatalog() const
Definition: SessionInfo.h:65
#define THROW_MAPD_EXCEPTION(errstr)
Definition: DBHandler.cpp:113
+ Here is the call graph for this function:

◆ checkpoint()

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

Definition at line 5780 of file DBHandler.cpp.

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

5782  {
5783  auto stdlog = STDLOG(get_session_ptr(session));
5784  auto session_ptr = stdlog.getConstSessionInfo();
5785  auto& cat = session_ptr->getCatalog();
5786  cat.getDataMgr().checkpoint(db_id, table_id);
5787 }
std::string cat(Ts &&... args)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:4656
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ clear_cpu_memory()

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

Definition at line 2262 of file DBHandler.cpp.

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

2262  {
2263  auto stdlog = STDLOG(get_session_ptr(session));
2264  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
2265  auto session_ptr = stdlog.getConstSessionInfo();
2266  if (!session_ptr->get_currentUser().isSuper) {
2267  THROW_MAPD_EXCEPTION("Superuser privilege is required to run clear_cpu_memory");
2268  }
2269  try {
2271  } catch (const std::exception& e) {
2272  THROW_MAPD_EXCEPTION(e.what());
2273  }
2274  if (render_handler_) {
2275  render_handler_->clear_cpu_memory();
2276  }
2277 
2278  if (leaf_aggregator_.leafCount() > 0) {
2280  }
2281 }
std::string toString(const ExtArgumentType &sig_type)
LeafAggregator leaf_aggregator_
Definition: DBHandler.h:528
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1410
static void clearMemory(const Data_Namespace::MemoryLevel memory_level)
Definition: Execute.cpp:172
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:4656
void clear_leaf_cpu_memory(const TSessionId session)
std::unique_ptr< RenderHandler > render_handler_
Definition: DBHandler.h:546
#define THROW_MAPD_EXCEPTION(errstr)
Definition: DBHandler.cpp:113
size_t leafCount() const
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ clear_gpu_memory()

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

Definition at line 2241 of file DBHandler.cpp.

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

2241  {
2242  auto stdlog = STDLOG(get_session_ptr(session));
2243  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
2244  auto session_ptr = stdlog.getConstSessionInfo();
2245  if (!session_ptr->get_currentUser().isSuper) {
2246  THROW_MAPD_EXCEPTION("Superuser privilege is required to run clear_gpu_memory");
2247  }
2248  try {
2250  } catch (const std::exception& e) {
2251  THROW_MAPD_EXCEPTION(e.what());
2252  }
2253  if (render_handler_) {
2254  render_handler_->clear_gpu_memory();
2255  }
2256 
2257  if (leaf_aggregator_.leafCount() > 0) {
2259  }
2260 }
std::string toString(const ExtArgumentType &sig_type)
LeafAggregator leaf_aggregator_
Definition: DBHandler.h:528
void clear_leaf_gpu_memory(const TSessionId session)
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1410
static void clearMemory(const Data_Namespace::MemoryLevel memory_level)
Definition: Execute.cpp:172
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:4656
std::unique_ptr< RenderHandler > render_handler_
Definition: DBHandler.h:546
#define THROW_MAPD_EXCEPTION(errstr)
Definition: DBHandler.cpp:113
size_t leafCount() const
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ clone_session()

void DBHandler::clone_session ( TSessionId &  session2,
const TSessionId &  session1 
)
override

Definition at line 615 of file DBHandler.cpp.

References cat(), LeafAggregator::clone_session(), create_new_session(), get_session_it_unsafe(), get_session_ptr(), getConnectionInfo(), leaf_aggregator_, LeafAggregator::leafCount(), sessions_mutex_, STDLOG, THROW_MAPD_EXCEPTION, and toString().

615  {
616  auto stdlog = STDLOG(get_session_ptr(session1));
617  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
618  mapd_unique_lock<mapd_shared_mutex> write_lock(sessions_mutex_);
619  auto session_it = get_session_it_unsafe(session1, write_lock);
620 
621  try {
622  const Catalog_Namespace::UserMetadata& user_meta =
623  session_it->second->get_currentUser();
624  std::shared_ptr<Catalog> cat = session_it->second->get_catalog_ptr();
625  auto session2_ptr = create_new_session(session2, cat->name(), user_meta, cat);
626  if (leaf_aggregator_.leafCount() > 0) {
627  leaf_aggregator_.clone_session(session1, session2);
628  return;
629  }
630  } catch (std::exception& e) {
631  THROW_MAPD_EXCEPTION(e.what());
632  }
633 }
std::string toString(const ExtArgumentType &sig_type)
void clone_session(const TSessionId session1, const TSessionId session2)
LeafAggregator leaf_aggregator_
Definition: DBHandler.h:528
std::shared_ptr< Catalog_Namespace::SessionInfo > create_new_session(TSessionId &session, const std::string &dbname, const Catalog_Namespace::UserMetadata &user_meta, std::shared_ptr< Catalog_Namespace::Catalog > cat)
Definition: DBHandler.cpp:515
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1410
mapd_shared_mutex sessions_mutex_
Definition: DBHandler.h:541
std::string cat(Ts &&... args)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:4656
#define THROW_MAPD_EXCEPTION(errstr)
Definition: DBHandler.cpp:113
SessionMap::iterator get_session_it_unsafe(const TSessionId &session, SESSION_MAP_LOCK &lock)
size_t leafCount() const
mapd_unique_lock< mapd_shared_mutex > write_lock
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ connect()

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

Definition at line 481 of file DBHandler.cpp.

References AccessPrivileges::ACCESS, cat(), connect_impl(), DatabaseDBObjectType, getConnectionInfo(), STDLOG, super_user_rights_, THROW_MAPD_EXCEPTION, and toString().

484  {
485  auto stdlog = STDLOG(); // session_info set by connect_impl()
486  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
487  std::string username2 = username; // login() may reset username given as argument
488  std::string dbname2 = dbname; // login() may reset dbname given as argument
490  std::shared_ptr<Catalog> cat = nullptr;
491  try {
492  cat = SysCatalog::instance().login(
493  dbname2, username2, passwd, user_meta, !super_user_rights_);
494  } catch (std::exception& e) {
495  stdlog.appendNameValuePairs("user", username, "db", dbname, "exception", e.what());
496  THROW_MAPD_EXCEPTION(e.what());
497  }
498 
499  DBObject dbObject(dbname2, DatabaseDBObjectType);
500  dbObject.loadKey(*cat);
501  dbObject.setPrivileges(AccessPrivileges::ACCESS);
502  std::vector<DBObject> dbObjects;
503  dbObjects.push_back(dbObject);
504  if (!SysCatalog::instance().checkPrivileges(user_meta, dbObjects)) {
505  stdlog.appendNameValuePairs(
506  "user", username, "db", dbname, "exception", "Missing Privileges");
507  THROW_MAPD_EXCEPTION("Unauthorized Access: user " + username +
508  " is not allowed to access database " + dbname2 + ".");
509  }
510  connect_impl(session, passwd, dbname2, user_meta, cat, stdlog);
511  // if pki auth session will come back encrypted with user pubkey
512  SysCatalog::instance().check_for_session_encryption(passwd, session);
513 }
std::string toString(const ExtArgumentType &sig_type)
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1410
void connect_impl(TSessionId &session, const std::string &passwd, const std::string &dbname, const Catalog_Namespace::UserMetadata &user_meta, std::shared_ptr< Catalog_Namespace::Catalog > cat, query_state::StdLog &stdlog)
Definition: DBHandler.cpp:533
std::string cat(Ts &&... args)
#define THROW_MAPD_EXCEPTION(errstr)
Definition: DBHandler.cpp:113
bool super_user_rights_
Definition: DBHandler.h:784
static const AccessPrivileges ACCESS
Definition: DBObject.h:154
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ connect_impl()

void DBHandler::connect_impl ( TSessionId &  session,
const std::string &  passwd,
const std::string &  dbname,
const Catalog_Namespace::UserMetadata user_meta,
std::shared_ptr< Catalog_Namespace::Catalog cat,
query_state::StdLog stdlog 
)
private

Definition at line 533 of file DBHandler.cpp.

References query_state::StdLog::appendNameValuePairs(), LeafAggregator::connect(), create_new_session(), getConnectionInfo(), query_state::StdLog::getConstSessionInfo(), join(), leaf_aggregator_, LeafAggregator::leafCount(), sessions_mutex_, query_state::StdLog::setSessionInfo(), super_user_rights_, toString(), and Catalog_Namespace::UserMetadata::userName.

Referenced by connect(), and internal_connect().

538  {
539  // TODO(sy): Is there any reason to have dbname as a parameter
540  // here when the cat parameter already provides cat->name()?
541  // Should dbname and cat->name() ever differ?
542  {
543  mapd_lock_guard<mapd_shared_mutex> write_lock(sessions_mutex_);
544  auto session_ptr = create_new_session(session, dbname, user_meta, cat);
545  stdlog.setSessionInfo(session_ptr);
546  session_ptr->set_connection_info(getConnectionInfo().toString());
547  if (!super_user_rights_) { // no need to connect to leaf_aggregator_ at this time
548  // while doing warmup
549  if (leaf_aggregator_.leafCount() > 0) {
550  leaf_aggregator_.connect(*session_ptr, user_meta.userName, passwd, dbname);
551  return;
552  }
553  }
554  }
555  auto const roles =
556  stdlog.getConstSessionInfo()->get_currentUser().isSuper
557  ? std::vector<std::string>{{"super"}}
558  : SysCatalog::instance().getRoles(
559  false, false, stdlog.getConstSessionInfo()->get_currentUser().userName);
560  stdlog.appendNameValuePairs("roles", boost::algorithm::join(roles, ","));
561 }
std::string toString(const ExtArgumentType &sig_type)
LeafAggregator leaf_aggregator_
Definition: DBHandler.h:528
std::shared_ptr< Catalog_Namespace::SessionInfo > create_new_session(TSessionId &session, const std::string &dbname, const Catalog_Namespace::UserMetadata &user_meta, std::shared_ptr< Catalog_Namespace::Catalog > cat)
Definition: DBHandler.cpp:515
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:255
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1410
mapd_shared_mutex sessions_mutex_
Definition: DBHandler.h:541
void appendNameValuePairs(Pairs &&... pairs)
Definition: QueryState.h:303
std::string cat(Ts &&... args)
bool super_user_rights_
Definition: DBHandler.h:784
size_t leafCount() const
mapd_unique_lock< mapd_shared_mutex > write_lock
std::shared_ptr< Catalog_Namespace::SessionInfo const > getConstSessionInfo() const
Definition: QueryState.cpp:130
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ convert_explain()

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

Definition at line 5058 of file DBHandler.cpp.

References create_simple_result().

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

5060  {
5061  create_simple_result(_return, results, column_format, "Explanation");
5062 }
void create_simple_result(TQueryResult &_return, const ResultSet &results, const bool column_format, const std::string label) const
Definition: DBHandler.cpp:5021
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ convert_result()

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

Definition at line 5064 of file DBHandler.cpp.

References create_simple_result().

Referenced by sql_execute_impl().

5066  {
5067  create_simple_result(_return, results, column_format, "Result");
5068 }
void create_simple_result(TQueryResult &_return, const ResultSet &results, const bool column_format, const std::string label) const
Definition: DBHandler.cpp:5021
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ convert_rows()

template<class R >
void DBHandler::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 4950 of file DBHandler.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().

4956  {
4957  query_state::Timer timer = query_state_proxy.createTimer(__func__);
4958  _return.row_set.row_desc = convert_target_metainfo(targets);
4959  int32_t fetched{0};
4960  if (column_format) {
4961  _return.row_set.is_columnar = true;
4962  std::vector<TColumn> tcolumns(results.colCount());
4963  while (first_n == -1 || fetched < first_n) {
4964  const auto crt_row = results.getNextRow(true, true);
4965  if (crt_row.empty()) {
4966  break;
4967  }
4968  ++fetched;
4969  if (at_most_n >= 0 && fetched > at_most_n) {
4970  THROW_MAPD_EXCEPTION("The result contains more rows than the specified cap of " +
4971  std::to_string(at_most_n));
4972  }
4973  for (size_t i = 0; i < results.colCount(); ++i) {
4974  const auto agg_result = crt_row[i];
4975  value_to_thrift_column(agg_result, targets[i].get_type_info(), tcolumns[i]);
4976  }
4977  }
4978  for (size_t i = 0; i < results.colCount(); ++i) {
4979  _return.row_set.columns.push_back(tcolumns[i]);
4980  }
4981  } else {
4982  _return.row_set.is_columnar = false;
4983  while (first_n == -1 || fetched < first_n) {
4984  const auto crt_row = results.getNextRow(true, true);
4985  if (crt_row.empty()) {
4986  break;
4987  }
4988  ++fetched;
4989  if (at_most_n >= 0 && fetched > at_most_n) {
4990  THROW_MAPD_EXCEPTION("The result contains more rows than the specified cap of " +
4991  std::to_string(at_most_n));
4992  }
4993  TRow trow;
4994  trow.cols.reserve(results.colCount());
4995  for (size_t i = 0; i < results.colCount(); ++i) {
4996  const auto agg_result = crt_row[i];
4997  trow.cols.push_back(value_to_thrift(agg_result, targets[i].get_type_info()));
4998  }
4999  _return.row_set.rows.push_back(trow);
5000  }
5001  }
5002 }
static void value_to_thrift_column(const TargetValue &tv, const SQLTypeInfo &ti, TColumn &column)
Definition: DBHandler.cpp:767
Timer createTimer(char const *event_name)
Definition: QueryState.cpp:113
std::string to_string(char const *&&v)
TColumnType convert_target_metainfo(const TargetMetaInfo &target, const size_t idx) const
Definition: DBHandler.cpp:4909
#define THROW_MAPD_EXCEPTION(errstr)
Definition: DBHandler.cpp:113
static TDatum value_to_thrift(const TargetValue &tv, const SQLTypeInfo &ti)
Definition: DBHandler.cpp:891
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ convert_target_metainfo() [1/2]

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

Definition at line 4909 of file DBHandler.cpp.

References encoding_to_thrift(), anonymous_namespace{DBHandler.cpp}::fixup_geo_column_descriptor(), TargetMetaInfo::get_resname(), TargetMetaInfo::get_type_info(), IS_GEO, kARRAY, kDATE, to_string(), SQLTypeInfo::type, and type_to_thrift().

Referenced by convert_rows(), and convert_target_metainfo().

4910  {
4911  TColumnType proj_info;
4912  proj_info.col_name = target.get_resname();
4913  if (proj_info.col_name.empty()) {
4914  proj_info.col_name = "result_" + std::to_string(idx + 1);
4915  }
4916  const auto& target_ti = target.get_type_info();
4917  proj_info.col_type.type = type_to_thrift(target_ti);
4918  proj_info.col_type.encoding = encoding_to_thrift(target_ti);
4919  proj_info.col_type.nullable = !target_ti.get_notnull();
4920  proj_info.col_type.is_array = target_ti.get_type() == kARRAY;
4921  if (IS_GEO(target_ti.get_type())) {
4923  proj_info, target_ti.get_subtype(), target_ti.get_output_srid());
4924  } else {
4925  proj_info.col_type.precision = target_ti.get_precision();
4926  proj_info.col_type.scale = target_ti.get_scale();
4927  }
4928  if (target_ti.get_type() == kDATE) {
4929  proj_info.col_type.size = target_ti.get_size();
4930  }
4931  proj_info.col_type.comp_param =
4932  (target_ti.is_date_in_days() && target_ti.get_comp_param() == 0)
4933  ? 32
4934  : target_ti.get_comp_param();
4935  return proj_info;
4936 }
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: DBHandler.cpp:1886
Definition: sqltypes.h:55
const std::string & get_resname() const
SQLTypes type
Definition: sqltypes.h:657
#define IS_GEO(T)
Definition: sqltypes.h:174
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 DBHandler::convert_target_metainfo ( const std::vector< TargetMetaInfo > &  targets) const
private

Definition at line 4938 of file DBHandler.cpp.

References convert_target_metainfo().

4939  {
4940  TRowDescriptor row_desc;
4941  size_t i = 0;
4942  for (const auto& target : targets) {
4943  row_desc.push_back(convert_target_metainfo(target, i));
4944  ++i;
4945  }
4946  return row_desc;
4947 }
TColumnType convert_target_metainfo(const TargetMetaInfo &target, const size_t idx) const
Definition: DBHandler.cpp:4909
+ Here is the call graph for this function:

◆ copyparams_to_thrift()

TCopyParams DBHandler::copyparams_to_thrift ( const import_export::CopyParams cp)
private

Definition at line 2918 of file DBHandler.cpp.

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

Referenced by detect_column_types(), and sql_execute().

2918  {
2919  TCopyParams copy_params;
2920  copy_params.delimiter = cp.delimiter;
2921  copy_params.null_str = cp.null_str;
2922  switch (cp.has_header) {
2924  copy_params.has_header = TImportHeaderRow::AUTODETECT;
2925  break;
2927  copy_params.has_header = TImportHeaderRow::NO_HEADER;
2928  break;
2930  copy_params.has_header = TImportHeaderRow::HAS_HEADER;
2931  break;
2932  default:
2933  CHECK(false);
2934  break;
2935  }
2936  copy_params.quoted = cp.quoted;
2937  copy_params.quote = cp.quote;
2938  copy_params.escape = cp.escape;
2939  copy_params.line_delim = cp.line_delim;
2940  copy_params.array_delim = cp.array_delim;
2941  copy_params.array_begin = cp.array_begin;
2942  copy_params.array_end = cp.array_end;
2943  copy_params.threads = cp.threads;
2944  copy_params.s3_access_key = cp.s3_access_key;
2945  copy_params.s3_secret_key = cp.s3_secret_key;
2946  copy_params.s3_region = cp.s3_region;
2947  copy_params.s3_endpoint = cp.s3_endpoint;
2948  switch (cp.file_type) {
2950  copy_params.file_type = TFileType::POLYGON;
2951  break;
2952  default:
2953  copy_params.file_type = TFileType::DELIMITED;
2954  break;
2955  }
2956  switch (cp.geo_coords_encoding) {
2957  case kENCODING_GEOINT:
2958  copy_params.geo_coords_encoding = TEncodingType::GEOINT;
2959  break;
2960  default:
2961  copy_params.geo_coords_encoding = TEncodingType::NONE;
2962  break;
2963  }
2964  copy_params.geo_coords_comp_param = cp.geo_coords_comp_param;
2965  switch (cp.geo_coords_type) {
2966  case kGEOGRAPHY:
2967  copy_params.geo_coords_type = TDatumType::GEOGRAPHY;
2968  break;
2969  case kGEOMETRY:
2970  copy_params.geo_coords_type = TDatumType::GEOMETRY;
2971  break;
2972  default:
2973  CHECK(false);
2974  break;
2975  }
2976  copy_params.geo_coords_srid = cp.geo_coords_srid;
2977  copy_params.sanitize_column_names = cp.sanitize_column_names;
2978  copy_params.geo_layer_name = cp.geo_layer_name;
2979  copy_params.geo_assign_render_groups = cp.geo_assign_render_groups;
2980  copy_params.geo_explode_collections = cp.geo_explode_collections;
2981  return copy_params;
2982 }
std::string s3_secret_key
Definition: CopyParams.h:63
ImportHeaderRow has_header
Definition: CopyParams.h:48
std::string geo_layer_name
Definition: CopyParams.h:78
#define CHECK(condition)
Definition: Logger.h:197
std::string s3_access_key
Definition: CopyParams.h:62
EncodingType geo_coords_encoding
Definition: CopyParams.h:73
+ Here is the caller graph for this function:

◆ create_dashboard()

int32_t DBHandler::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 3422 of file DBHandler.cpp.

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

3426  {
3427  auto stdlog = STDLOG(get_session_ptr(session));
3428  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
3429  auto session_ptr = stdlog.getConstSessionInfo();
3430  check_read_only("create_dashboard");
3431  auto& cat = session_ptr->getCatalog();
3432 
3433  if (!session_ptr->checkDBAccessPrivileges(DBObjectType::DashboardDBObjectType,
3435  THROW_MAPD_EXCEPTION("Not enough privileges to create a dashboard.");
3436  }
3437 
3438  auto dash = cat.getMetadataForDashboard(
3439  std::to_string(session_ptr->get_currentUser().userId), dashboard_name);
3440  if (dash) {
3441  THROW_MAPD_EXCEPTION("Dashboard with name: " + dashboard_name + " already exists.");
3442  }
3443 
3445  dd.dashboardName = dashboard_name;
3446  dd.dashboardState = dashboard_state;
3447  dd.imageHash = image_hash;
3448  dd.dashboardMetadata = dashboard_metadata;
3449  dd.userId = session_ptr->get_currentUser().userId;
3450  dd.user = session_ptr->get_currentUser().userName;
3451 
3452  try {
3453  auto id = cat.createDashboard(dd);
3454  // TODO: transactionally unsafe
3455  SysCatalog::instance().createDBObject(
3456  session_ptr->get_currentUser(), dashboard_name, DashboardDBObjectType, cat, id);
3457  return id;
3458  } catch (const std::exception& e) {
3459  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
3460  }
3461 }
std::string toString(const ExtArgumentType &sig_type)
static const AccessPrivileges CREATE_DASHBOARD
Definition: DBObject.h:171
std::string to_string(char const *&&v)
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1410
std::string cat(Ts &&... args)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:4656
#define THROW_MAPD_EXCEPTION(errstr)
Definition: DBHandler.cpp:113
void check_read_only(const std::string &str)
Definition: DBHandler.cpp:400
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ create_geo_column()

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

Definition at line 3723 of file DBHandler.cpp.

References run_benchmark_import::type.

3725  {
3726  TColumnType ct;
3727  ct.col_name = name;
3728  ct.col_type.type = type;
3729  ct.col_type.is_array = is_array;
3730  return ct;
3731 }

◆ create_link()

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

Definition at line 3701 of file DBHandler.cpp.

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

3704  {
3705  auto stdlog = STDLOG(get_session_ptr(session));
3706  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
3707  auto session_ptr = stdlog.getConstSessionInfo();
3708  // check_read_only("create_link");
3709  auto& cat = session_ptr->getCatalog();
3710 
3711  LinkDescriptor ld;
3712  ld.userId = session_ptr->get_currentUser().userId;
3713  ld.viewState = view_state;
3714  ld.viewMetadata = view_metadata;
3715 
3716  try {
3717  _return = cat.createLink(ld, 6);
3718  } catch (const std::exception& e) {
3719  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
3720  }
3721 }
std::string toString(const ExtArgumentType &sig_type)
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1410
std::string cat(Ts &&... args)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:4656
#define THROW_MAPD_EXCEPTION(errstr)
Definition: DBHandler.cpp:113
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ create_new_session()

std::shared_ptr< Catalog_Namespace::SessionInfo > DBHandler::create_new_session ( TSessionId &  session,
const std::string &  dbname,
const Catalog_Namespace::UserMetadata user_meta,
std::shared_ptr< Catalog_Namespace::Catalog cat 
)
private

Definition at line 515 of file DBHandler.cpp.

References CHECK, executor_device_type_, generate_random_string(), logger::INFO, LOG, sessions_, and Catalog_Namespace::UserMetadata::userName.

Referenced by clone_session(), and connect_impl().

519  {
520  do {
521  session = generate_random_string(32);
522  } while (sessions_.find(session) != sessions_.end());
523  std::pair<SessionMap::iterator, bool> emplace_retval =
524  sessions_.emplace(session,
525  std::make_shared<Catalog_Namespace::SessionInfo>(
526  cat, user_meta, executor_device_type_, session));
527  CHECK(emplace_retval.second);
528  auto& session_ptr = emplace_retval.first->second;
529  LOG(INFO) << "User " << user_meta.userName << " connected to database " << dbname;
530  return session_ptr;
531 }
#define LOG(tag)
Definition: Logger.h:188
std::string cat(Ts &&... args)
std::string generate_random_string(const size_t len)
ExecutorDeviceType executor_device_type_
Definition: DBHandler.h:532
#define CHECK(condition)
Definition: Logger.h:197
SessionMap sessions_
Definition: DBHandler.h:782
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ create_query_state()

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

Definition at line 555 of file DBHandler.h.

References QueryRunner::apply_copy_to_shim(), run_benchmark_import::args, cat(), run_benchmark_import::label, and run_benchmark_import::type.

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

555  {
556  return query_states_.create(std::forward<ARGS>(args)...);
557  }
CircleBuffer::value_type create(ARGS &&... args)
Definition: QueryState.h:185
query_state::QueryStates query_states_
Definition: DBHandler.h:781
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ create_simple_result()

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

Definition at line 5021 of file DBHandler.cpp.

References CHECK, CHECK_EQ, and run_benchmark_import::label.

Referenced by convert_explain(), and convert_result().

5024  {
5025  CHECK_EQ(size_t(1), results.rowCount());
5026  TColumnType proj_info;
5027  proj_info.col_name = label;
5028  proj_info.col_type.type = TDatumType::STR;
5029  proj_info.col_type.nullable = false;
5030  proj_info.col_type.is_array = false;
5031  _return.row_set.row_desc.push_back(proj_info);
5032  const auto crt_row = results.getNextRow(true, true);
5033  const auto tv = crt_row[0];
5034  CHECK(results.getNextRow(true, true).empty());
5035  const auto scalar_tv = boost::get<ScalarTargetValue>(&tv);
5036  CHECK(scalar_tv);
5037  const auto s_n = boost::get<NullableString>(scalar_tv);
5038  CHECK(s_n);
5039  const auto s = boost::get<std::string>(s_n);
5040  CHECK(s);
5041  if (column_format) {
5042  TColumn tcol;
5043  tcol.data.str_col.push_back(*s);
5044  tcol.nulls.push_back(false);
5045  _return.row_set.is_columnar = true;
5046  _return.row_set.columns.push_back(tcol);
5047  } else {
5048  TDatum explanation;
5049  explanation.val.str_val = *s;
5050  explanation.is_null = false;
5051  TRow trow;
5052  trow.cols.push_back(explanation);
5053  _return.row_set.is_columnar = false;
5054  _return.row_set.rows.push_back(trow);
5055  }
5056 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
#define CHECK(condition)
Definition: Logger.h:197
+ Here is the caller graph for this function:

◆ create_table()

void DBHandler::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 3754 of file DBHandler.cpp.

References check_read_only(), getConnectionInfo(), 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, to_string(), and toString().

Referenced by import_geo_table().

3758  {
3759  auto stdlog = STDLOG("table_name", table_name);
3760  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
3761  check_read_only("create_table");
3762 
3763  if (ImportHelpers::is_reserved_name(table_name)) {
3764  THROW_MAPD_EXCEPTION("Invalid table name (reserved keyword): " + table_name);
3765  } else if (table_name != ImportHelpers::sanitize_name(table_name)) {
3766  THROW_MAPD_EXCEPTION("Invalid characters in table name: " + table_name);
3767  }
3768 
3769  auto rds = rd;
3770 
3771  // no longer need to manually add the poly column for a TFileType::POLYGON table
3772  // a column of the correct geo type has already been added
3773  // @TODO simon.eves rename TFileType::POLYGON to TFileType::GEO or something!
3774 
3775  std::string stmt{"CREATE TABLE " + table_name};
3776  std::vector<std::string> col_stmts;
3777 
3778  for (auto col : rds) {
3779  if (ImportHelpers::is_reserved_name(col.col_name)) {
3780  THROW_MAPD_EXCEPTION("Invalid column name (reserved keyword): " + col.col_name);
3781  } else if (col.col_name != ImportHelpers::sanitize_name(col.col_name)) {
3782  THROW_MAPD_EXCEPTION("Invalid characters in column name: " + col.col_name);
3783  }
3784  if (col.col_type.type == TDatumType::INTERVAL_DAY_TIME ||
3785  col.col_type.type == TDatumType::INTERVAL_YEAR_MONTH) {
3786  THROW_MAPD_EXCEPTION("Unsupported type: " + thrift_to_name(col.col_type) +
3787  " for column: " + col.col_name);
3788  }
3789 
3790  if (col.col_type.type == TDatumType::DECIMAL) {
3791  // if no precision or scale passed in set to default 14,7
3792  if (col.col_type.precision == 0 && col.col_type.scale == 0) {
3793  col.col_type.precision = 14;
3794  col.col_type.scale = 7;
3795  }
3796  }
3797 
3798  std::string col_stmt;
3799  col_stmt.append(col.col_name + " " + thrift_to_name(col.col_type));
3800 
3801  // As of 2016-06-27 the Immerse v1 frontend does not explicitly set the
3802  // `nullable` argument, leading this to default to false. Uncomment for v2.
3803  // if (!col.col_type.nullable) col_stmt.append(" NOT NULL");
3804 
3805  if (thrift_to_encoding(col.col_type.encoding) != kENCODING_NONE) {
3806  col_stmt.append(" ENCODING " + thrift_to_encoding_name(col.col_type));
3807  if (thrift_to_encoding(col.col_type.encoding) == kENCODING_DICT ||
3808  thrift_to_encoding(col.col_type.encoding) == kENCODING_FIXED ||
3809  thrift_to_encoding(col.col_type.encoding) == kENCODING_GEOINT) {
3810  col_stmt.append("(" + std::to_string(col.col_type.comp_param) + ")");
3811  }
3812  } else if (col.col_type.type == TDatumType::STR) {
3813  // non DICT encoded strings
3814  col_stmt.append(" ENCODING NONE");
3815  } else if (col.col_type.type == TDatumType::POINT ||
3816  col.col_type.type == TDatumType::LINESTRING ||
3817  col.col_type.type == TDatumType::POLYGON ||
3818  col.col_type.type == TDatumType::MULTIPOLYGON) {
3819  // non encoded compressable geo
3820  if (col.col_type.scale == 4326) {
3821  col_stmt.append(" ENCODING NONE");
3822  }
3823  }
3824  col_stmts.push_back(col_stmt);
3825  }
3826 
3827  stmt.append(" (" + boost::algorithm::join(col_stmts, ", ") + ")");
3828 
3829  if (create_params.is_replicated) {
3830  stmt.append(" WITH (PARTITIONS = 'REPLICATED')");
3831  }
3832 
3833  stmt.append(";");
3834 
3835  TQueryResult ret;
3836  sql_execute(ret, session, stmt, true, "", -1, -1);
3837 }
std::string toString(const ExtArgumentType &sig_type)
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)
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1410
bool is_reserved_name(const std::string &name)
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
Definition: DBHandler.cpp:979
std::string sanitize_name(const std::string &name)
#define THROW_MAPD_EXCEPTION(errstr)
Definition: DBHandler.cpp:113
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)
Definition: DBHandler.cpp:400
#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 DBHandler::createInMemoryCalciteSession ( const std::shared_ptr< Catalog_Namespace::Catalog > &  catalog_ptr)
private

Definition at line 406 of file DBHandler.cpp.

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

Referenced by parse_to_ra().

407  {
408  // We would create an in memory session for calcite with super user privileges which
409  // would be used for getting all tables metadata when a user runs the query. The
410  // session would be under the name of a proxy user/password which would only persist
411  // till server's lifetime or execution of calcite query(in memory) whichever is the
412  // earliest.
413  mapd_lock_guard<mapd_shared_mutex> write_lock(sessions_mutex_);
414  std::string session_id;
415  do {
416  session_id = generate_random_string(64);
417  } while (sessions_.find(session_id) != sessions_.end());
418  Catalog_Namespace::UserMetadata user_meta(-1,
419  calcite_->getInternalSessionProxyUserName(),
420  calcite_->getInternalSessionProxyPassword(),
421  true,
422  -1,
423  true);
424  const auto emplace_ret =
425  sessions_.emplace(session_id,
426  std::make_shared<Catalog_Namespace::SessionInfo>(
427  catalog_ptr, user_meta, executor_device_type_, session_id));
428  CHECK(emplace_ret.second);
429  return session_id;
430 }
mapd_shared_mutex sessions_mutex_
Definition: DBHandler.h:541
std::string generate_random_string(const size_t len)
ExecutorDeviceType executor_device_type_
Definition: DBHandler.h:532
std::shared_ptr< Calcite > calcite_
Definition: DBHandler.h:549
#define CHECK(condition)
Definition: Logger.h:197
mapd_unique_lock< mapd_shared_mutex > write_lock
SessionMap sessions_
Definition: DBHandler.h:782
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deallocate_df()

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

Definition at line 1168 of file DBHandler.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.

1171  {
1172  auto stdlog = STDLOG(get_session_ptr(session));
1173  std::string serialized_cuda_handle = "";
1174  if (device_type == TDeviceType::GPU) {
1175  std::lock_guard<std::mutex> map_lock(handle_to_dev_ptr_mutex_);
1176  if (ipc_handle_to_dev_ptr_.count(df.df_handle) != size_t(1)) {
1177  TOmniSciException ex;
1178  ex.error_msg = std::string(
1179  "Exception: current data frame handle is not bookkept or been inserted "
1180  "twice");
1181  LOG(ERROR) << ex.error_msg;
1182  throw ex;
1183  }
1184  serialized_cuda_handle = ipc_handle_to_dev_ptr_[df.df_handle];
1185  ipc_handle_to_dev_ptr_.erase(df.df_handle);
1186  }
1187  std::vector<char> sm_handle(df.sm_handle.begin(), df.sm_handle.end());
1188  std::vector<char> df_handle(df.df_handle.begin(), df.df_handle.end());
1190  sm_handle, df.sm_size, df_handle, df.df_size, serialized_cuda_handle};
1192  result,
1193  device_type == TDeviceType::CPU ? ExecutorDeviceType::CPU : ExecutorDeviceType::GPU,
1194  device_id,
1195  data_mgr_);
1196 }
std::mutex handle_to_dev_ptr_mutex_
Definition: DBHandler.h:826
#define LOG(tag)
Definition: Logger.h:188
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:4656
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: DBHandler.h:526
std::unordered_map< std::string, std::string > ipc_handle_to_dev_ptr_
Definition: DBHandler.h:827
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ delete_dashboard()

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

Definition at line 3502 of file DBHandler.cpp.

References delete_dashboards().

3502  {
3503  delete_dashboards(session, {dashboard_id});
3504 }
void delete_dashboards(const TSessionId &session, const std::vector< int32_t > &dashboard_ids) override
Definition: DBHandler.cpp:3506
+ Here is the call graph for this function:

◆ delete_dashboards()

void DBHandler::delete_dashboards ( const TSessionId &  session,
const std::vector< int32_t > &  dashboard_ids 
)
override

Definition at line 3506 of file DBHandler.cpp.

References cat(), check_read_only(), get_session_ptr(), getConnectionInfo(), STDLOG, THROW_MAPD_EXCEPTION, and toString().

Referenced by delete_dashboard().

3507  {
3508  auto stdlog = STDLOG(get_session_ptr(session));
3509  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
3510  auto session_ptr = stdlog.getConstSessionInfo();
3511  check_read_only("delete_dashboards");
3512  auto& cat = session_ptr->getCatalog();
3513  // Checks will be performed in catalog
3514  try {
3515  cat.deleteMetadataForDashboards(dashboard_ids, session_ptr->get_currentUser());
3516  } catch (const std::exception& e) {
3517  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
3518  }
3519 }
std::string toString(const ExtArgumentType &sig_type)
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1410
std::string cat(Ts &&... args)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:4656
#define THROW_MAPD_EXCEPTION(errstr)
Definition: DBHandler.cpp:113
void check_read_only(const std::string &str)
Definition: DBHandler.cpp:400
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ detect_column_types()

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

Definition at line 3143 of file DBHandler.cpp.

References anonymous_namespace{DBHandler.cpp}::add_vsi_archive_prefix(), anonymous_namespace{DBHandler.cpp}::add_vsi_geo_prefix(), anonymous_namespace{DBHandler.cpp}::add_vsi_network_prefix(), import_export::Detector::best_encodings, import_export::Detector::best_sqltypes, check_geospatial_files(), check_read_only(), copyparams_to_thrift(), import_export::DELIMITED, encoding_to_thrift(), import_export::CopyParams::file_type, anonymous_namespace{DBHandler.cpp}::find_first_geo_file_in_archive(), import_export::Importer::gdalFileExists(), import_export::Importer::gdalFileOrDirectoryExists(), import_export::Importer::gdalToColumnDescriptors(), import_export::CopyParams::geo_coords_comp_param, import_export::CopyParams::geo_coords_encoding, import_export::CopyParams::geo_coords_srid, import_export::CopyParams::geo_coords_type, import_export::DataStreamSink::get_copy_params(), import_export::Detector::get_headers(), import_export::Detector::get_sample_rows(), get_session_ptr(), getConnectionInfo(), import_path_, anonymous_namespace{DBHandler.cpp}::is_a_supported_archive_file(), anonymous_namespace{DBHandler.cpp}::is_a_supported_geo_file(), IS_GEO, ImportHelpers::is_reserved_name(), OMNISCI_GEO_PREFIX, anonymous_namespace{DBHandler.cpp}::path_is_relative(), import_export::POLYGON, populateThriftColumnType(), import_export::Importer::readMetadataSampleGDAL(), import_export::CopyParams::sanitize_column_names, ImportHelpers::sanitize_name(), SQLTypeInfo::set_compression(), STDLOG, thrift_to_copyparams(), THROW_MAPD_EXCEPTION, toString(), type_to_thrift(), and anonymous_namespace{DBHandler.cpp}::validate_import_file_path_if_local().

Referenced by import_geo_table().

3146  {
3147  auto stdlog = STDLOG(get_session_ptr(session));
3148  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
3149  check_read_only("detect_column_types");
3150 
3152 
3153  std::string file_name{file_name_in};
3154  if (path_is_relative(file_name)) {
3155  // assume relative paths are relative to data_path / mapd_import / <session>
3156  auto file_path = import_path_ / picosha2::hash256_hex_string(session) /
3157  boost::filesystem::path(file_name).filename();
3158  file_name = file_path.string();
3159  }
3161 
3162  // if it's a geo table, handle alternative paths (S3, HTTP, archive etc.)
3163  if (copy_params.file_type == import_export::FileType::POLYGON) {
3164  if (is_a_supported_geo_file(file_name, true)) {
3165  // prepare to detect geo file directly
3166  add_vsi_network_prefix(file_name);
3167  add_vsi_geo_prefix(file_name);
3168  } else if (is_a_supported_archive_file(file_name)) {
3169  // find the archive file
3170  add_vsi_network_prefix(file_name);
3171  if (!import_export::Importer::gdalFileExists(file_name, copy_params)) {
3172  THROW_MAPD_EXCEPTION("Archive does not exist: " + file_name_in);
3173  }
3174  // find geo file in archive
3175  add_vsi_archive_prefix(file_name);
3176  std::string geo_file = find_first_geo_file_in_archive(file_name, copy_params);
3177  // prepare to detect that geo file
3178  if (geo_file.size()) {
3179  file_name = file_name + std::string("/") + geo_file;
3180  }
3181  } else {
3182  THROW_MAPD_EXCEPTION("File is not a supported geo or geo archive format: " +
3183  file_name_in);
3184  }
3185  }
3186 
3187  auto file_path = boost::filesystem::path(file_name);
3188  // can be a s3 url
3189  if (!boost::istarts_with(file_name, "s3://")) {
3190  if (!boost::filesystem::path(file_name).is_absolute()) {
3191  file_path = import_path_ / picosha2::hash256_hex_string(session) /
3192  boost::filesystem::path(file_name).filename();
3193  file_name = file_path.string();
3194  }
3195 
3196  if (copy_params.file_type == import_export::FileType::POLYGON) {
3197  // check for geo file
3198  if (!import_export::Importer::gdalFileOrDirectoryExists(file_name, copy_params)) {
3199  THROW_MAPD_EXCEPTION("File does not exist: " + file_path.string());
3200  }
3201  } else {
3202  // check for regular file
3203  if (!boost::filesystem::exists(file_path)) {
3204  THROW_MAPD_EXCEPTION("File does not exist: " + file_path.string());
3205  }
3206  }
3207  }
3208 
3209  try {
3211 #ifdef ENABLE_IMPORT_PARQUET
3212  || (copy_params.file_type == import_export::FileType::PARQUET)
3213 #endif
3214  ) {
3215  import_export::Detector detector(file_path, copy_params);
3216  std::vector<SQLTypes> best_types = detector.best_sqltypes;
3217  std::vector<EncodingType> best_encodings = detector.best_encodings;
3218  std::vector<std::string> headers = detector.get_headers();
3219  copy_params = detector.get_copy_params();
3220 
3221  _return.copy_params = copyparams_to_thrift(copy_params);
3222  _return.row_set.row_desc.resize(best_types.size());
3223  for (size_t col_idx = 0; col_idx < best_types.size(); col_idx++) {
3224  TColumnType col;
3225  SQLTypes t = best_types[col_idx];
3226  EncodingType encodingType = best_encodings[col_idx];
3227  SQLTypeInfo ti(t, false, encodingType);
3228  if (IS_GEO(t)) {
3229  // set this so encoding_to_thrift does the right thing
3230  ti.set_compression(copy_params.geo_coords_encoding);
3231  // fill in these directly
3232  col.col_type.precision = static_cast<int>(copy_params.geo_coords_type);
3233  col.col_type.scale = copy_params.geo_coords_srid;
3234  col.col_type.comp_param = copy_params.geo_coords_comp_param;
3235  }
3236  col.col_type.type = type_to_thrift(ti);
3237  col.col_type.encoding = encoding_to_thrift(ti);
3238  if (copy_params.sanitize_column_names) {
3239  col.col_name = ImportHelpers::sanitize_name(headers[col_idx]);
3240  } else {
3241  col.col_name = headers[col_idx];
3242  }
3243  col.is_reserved_keyword = ImportHelpers::is_reserved_name(col.col_name);
3244  _return.row_set.row_desc[col_idx] = col;
3245  }
3246  size_t num_samples = 100;
3247  auto sample_data = detector.get_sample_rows(num_samples);
3248 
3249  TRow sample_row;
3250  for (auto row : sample_data) {
3251  sample_row.cols.clear();
3252  for (const auto& s : row) {
3253  TDatum td;
3254  td.val.str_val = s;
3255  td.is_null = s.empty();
3256  sample_row.cols.push_back(td);
3257  }
3258  _return.row_set.rows.push_back(sample_row);
3259  }
3260  } else if (copy_params.file_type == import_export::FileType::POLYGON) {
3261  // @TODO simon.eves get this from somewhere!
3262  const std::string geoColumnName(OMNISCI_GEO_PREFIX);
3263 
3264  check_geospatial_files(file_path, copy_params);
3265  std::list<ColumnDescriptor> cds = import_export::Importer::gdalToColumnDescriptors(
3266  file_path.string(), geoColumnName, copy_params);
3267  for (auto cd : cds) {
3268  if (copy_params.sanitize_column_names) {
3269  cd.columnName = ImportHelpers::sanitize_name(cd.columnName);
3270  }
3271  _return.row_set.row_desc.push_back(populateThriftColumnType(nullptr, &cd));
3272  }
3273  std::map<std::string, std::vector<std::string>> sample_data;
3275  file_path.string(), geoColumnName, sample_data, 100, copy_params);
3276  if (sample_data.size() > 0) {
3277  for (size_t i = 0; i < sample_data.begin()->second.size(); i++) {
3278  TRow sample_row;
3279  for (auto cd : cds) {
3280  TDatum td;
3281  td.val.str_val = sample_data[cd.sourceName].at(i);
3282  td.is_null = td.val.str_val.empty();
3283  sample_row.cols.push_back(td);
3284  }
3285  _return.row_set.rows.push_back(sample_row);
3286  }
3287  }
3288  _return.copy_params = copyparams_to_thrift(copy_params);
3289  }
3290  } catch (const std::exception& e) {
3291  THROW_MAPD_EXCEPTION("detect_column_types error: " + std::string(e.what()));
3292  }
3293 }
boost::filesystem::path import_path_
Definition: DBHandler.h:531
void add_vsi_archive_prefix(std::string &path)
Definition: DBHandler.cpp:3014
bool is_a_supported_archive_file(const std::string &path)
Definition: DBHandler.cpp:3082
std::string toString(const ExtArgumentType &sig_type)
TDatumType::type type_to_thrift(const SQLTypeInfo &type_info)
SQLTypes
Definition: sqltypes.h:40
bool path_is_relative(const std::string &path)
Definition: DBHandler.cpp:3048
TCopyParams copyparams_to_thrift(const import_export::CopyParams &cp)
Definition: DBHandler.cpp:2918
static bool gdalFileExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:4561
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1410
EncodingType
Definition: sqltypes.h:156
bool is_reserved_name(const std::string &name)
TColumnType populateThriftColumnType(const Catalog_Namespace::Catalog *cat, const ColumnDescriptor *cd)
Definition: DBHandler.cpp:1895
void check_geospatial_files(const boost::filesystem::path file_path, const import_export::CopyParams &copy_params)
Definition: DBHandler.cpp:3733
static const std::list< ColumnDescriptor > gdalToColumnDescriptors(const std::string &fileName, const std::string &geoColumnName, const CopyParams &copy_params)
Definition: Importer.cpp:4438
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:4304
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:4656
void validate_import_file_path_if_local(const std::string &file_path)
Definition: DBHandler.cpp:3136
std::string sanitize_name(const std::string &name)
#define THROW_MAPD_EXCEPTION(errstr)
Definition: DBHandler.cpp:113
const std::string OMNISCI_GEO_PREFIX
Definition: Transforms.h:22
static bool gdalFileOrDirectoryExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:4566
void check_read_only(const std::string &str)
Definition: DBHandler.cpp:400
std::string find_first_geo_file_in_archive(const std::string &archive_path, const import_export::CopyParams &copy_params)
Definition: DBHandler.cpp:3095
void add_vsi_network_prefix(std::string &path)
Definition: DBHandler.cpp:2985
import_export::CopyParams thrift_to_copyparams(const TCopyParams &cp)
Definition: DBHandler.cpp:2799
#define IS_GEO(T)
Definition: sqltypes.h:174
void add_vsi_geo_prefix(std::string &path)
Definition: DBHandler.cpp:3007
#define STDLOG(...)
Definition: QueryState.h:225
TEncodingType::type encoding_to_thrift(const SQLTypeInfo &type_info)
EncodingType geo_coords_encoding
Definition: CopyParams.h:73
bool is_a_supported_geo_file(const std::string &path, bool include_gz)
Definition: DBHandler.cpp:3064
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ disconnect()

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

Definition at line 563 of file DBHandler.cpp.

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

563  {
564  auto stdlog = STDLOG();
565  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
566 
567  mapd_unique_lock<mapd_shared_mutex> write_lock(sessions_mutex_);
568  auto session_it = get_session_it_unsafe(session, write_lock);
569  stdlog.setSessionInfo(session_it->second);
570  const auto dbname = session_it->second->getCatalog().getCurrentDB().dbName;
571 
572  LOG(INFO) << "User " << session_it->second->get_currentUser().userName
573  << " disconnected from database " << dbname
574  << " with public_session_id: " << session_it->second->get_public_session_id();
575  disconnect_impl(session_it, write_lock);
576 }
std::string toString(const ExtArgumentType &sig_type)
#define LOG(tag)
Definition: Logger.h:188
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1410
mapd_shared_mutex sessions_mutex_
Definition: DBHandler.h:541
SessionMap::iterator get_session_it_unsafe(const TSessionId &session, SESSION_MAP_LOCK &lock)
void disconnect_impl(const SessionMap::iterator &session_it, mapd_unique_lock< mapd_shared_mutex > &write_lock)
Definition: DBHandler.cpp:578
mapd_unique_lock< mapd_shared_mutex > write_lock
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ disconnect_impl()

void DBHandler::disconnect_impl ( const SessionMap::iterator &  session_it,
mapd_unique_lock< mapd_shared_mutex > &  write_lock 
)
private

Definition at line 578 of file DBHandler.cpp.

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

Referenced by disconnect().

579  {
580  // session_it existence should already have been checked (i.e. called via
581  // get_session_it_unsafe(...))
582  const auto session_id = session_it->second->get_session_id();
583  if (leaf_aggregator_.leafCount() > 0) {
584  leaf_aggregator_.disconnect(session_id);
585  }
586  sessions_.erase(session_it);
587  write_lock.unlock();
588 
589  if (render_handler_) {
590  render_handler_->disconnect(session_id);
591  }
592 }
LeafAggregator leaf_aggregator_
Definition: DBHandler.h:528
void disconnect(const TSessionId session)
std::unique_ptr< RenderHandler > render_handler_
Definition: DBHandler.h:546
size_t leafCount() const
mapd_unique_lock< mapd_shared_mutex > write_lock
SessionMap sessions_
Definition: DBHandler.h:782
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ emergency_shutdown()

void DBHandler::emergency_shutdown ( )

Definition at line 5939 of file DBHandler.cpp.

References calcite_, and get_device_parameters().

Referenced by shutdown().

5939  {
5940  if (calcite_) {
5941  calcite_->close_calcite_server(false);
5942  }
5943 }
std::shared_ptr< Calcite > calcite_
Definition: DBHandler.h:549
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ execute_distributed_copy_statement()

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

Definition at line 5462 of file DBHandler.cpp.

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

Referenced by sql_execute_impl().

5464  {
5465  auto importer_factory = [&session_info, this](
5466  const Catalog& catalog,
5467  const TableDescriptor* td,
5468  const std::string& file_path,
5469  const import_export::CopyParams& copy_params) {
5470  return std::make_unique<import_export::Importer>(
5471  new DistributedLoader(session_info, td, &leaf_aggregator_),
5472  file_path,
5473  copy_params);
5474  };
5475  copy_stmt->execute(session_info, importer_factory);
5476 }
class for a per-database catalog. also includes metadata for the current database and the current use...
Definition: Catalog.h:97
LeafAggregator leaf_aggregator_
Definition: DBHandler.h:528
void execute(const Catalog_Namespace::SessionInfo &session) override
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 DBHandler::execute_next_render_step ( TRenderStepResult &  _return,
const TPendingRenderQuery &  pending_render,
const TRenderAggDataMap &  merged_data 
)
override

Definition at line 5761 of file DBHandler.cpp.

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

5763  {
5764  if (!render_handler_) {
5765  THROW_MAPD_EXCEPTION("Backend rendering is disabled.");
5766  }
5767 
5768  LOG(INFO) << "execute_next_render_step: id:" << pending_render.id;
5769  auto time_ms = measure<>::execution([&]() {
5770  try {
5771  render_handler_->execute_next_render_step(_return, pending_render, merged_data);
5772  } catch (std::exception& e) {
5773  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
5774  }
5775  });
5776  LOG(INFO) << "execute_next_render_step-COMPLETED id: " << pending_render.id
5777  << ", time: " << time_ms << "ms ";
5778 }
#define LOG(tag)
Definition: Logger.h:188
std::unique_ptr< RenderHandler > render_handler_
Definition: DBHandler.h:546
#define THROW_MAPD_EXCEPTION(errstr)
Definition: DBHandler.cpp:113
static TimeT::rep execution(F func, Args &&... args)
Definition: sample.cpp:29
+ Here is the call graph for this function:

◆ execute_query_step()

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

Definition at line 5615 of file DBHandler.cpp.

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

5616  {
5617  if (!leaf_handler_) {
5618  THROW_MAPD_EXCEPTION("Distributed support is disabled.");
5619  }
5620  LOG(INFO) << "execute_query_step : id:" << pending_query.id;
5621  auto time_ms = measure<>::execution([&]() {
5622  try {
5623  leaf_handler_->execute_query_step(_return, pending_query);
5624  } catch (std::exception& e) {
5625  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
5626  }
5627  });
5628  LOG(INFO) << "execute_query_step-COMPLETED " << time_ms << "ms";
5629 }
#define LOG(tag)
Definition: Logger.h:188
#define THROW_MAPD_EXCEPTION(errstr)
Definition: DBHandler.cpp:113
std::unique_ptr< MapDLeafHandler > leaf_handler_
Definition: DBHandler.h:548
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 > DBHandler::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_validate,
const bool  find_push_down_candidates,
const ExplainInfo explain_info,
const std::optional< size_t >  executor_index = std::nullopt 
) const
private

Definition at line 4716 of file DBHandler.cpp.

References allow_loop_joins_, allow_multifrag_, cat(), convert_explain(), convert_rows(), CPU, query_state::Timer::createQueryStateProxy(), query_state::QueryStateProxy::createTimer(), Default, measure< TimeT >::execution(), ExplainInfo::explain_optimized, ExplainInfo::explain_plan, g_dynamic_watchdog_time_limit, g_enable_columnar_output, g_enable_dynamic_watchdog, g_enable_runtime_query_interrupt, g_enable_watchdog, g_runtime_query_interrupt_frequency, query_state::QueryState::getConstSessionInfo(), Executor::getExecutor(), RelAlgExecutor::getParsedQueryHints(), query_state::QueryStateProxy::getQueryState(), SystemParameters::gpu_input_mem_limit, lockmgr::TableSchemaLockMgr::instance(), lockmgr::TableDataLockMgr::instance(), intel_jit_profile_, jit_debug_, ExplainInfo::justCalciteExplain(), ExplainInfo::justExplain(), Optimized, run_benchmark_import::result, system_parameters_, Executor::UNITARY_EXECUTOR_ID, and VLOG.

Referenced by execute_rel_alg_with_filter_push_down(), get_tables_meta_impl(), sql_execute_impl(), and validate_rel_alg().

4727  {
4728  query_state::Timer timer = query_state_proxy.createTimer(__func__);
4729 
4730  VLOG(1) << "Table Schema Locks:\n" << lockmgr::TableSchemaLockMgr::instance();
4731  VLOG(1) << "Table Data Locks:\n" << lockmgr::TableDataLockMgr::instance();
4732 
4733  const auto& cat = query_state_proxy.getQueryState().getConstSessionInfo()->getCatalog();
4734  auto executor = Executor::getExecutor(
4735  executor_index ? *executor_index : Executor::UNITARY_EXECUTOR_ID,
4736  jit_debug_ ? "/tmp" : "",
4737  jit_debug_ ? "mapdquery" : "",
4739  RelAlgExecutor ra_executor(executor.get(),
4740  cat,
4741  query_ra,
4742  query_state_proxy.getQueryState().shared_from_this());
4743  // handle hints
4744  const auto& query_hints = ra_executor.getParsedQueryHints();
4745  CompilationOptions co = {
4746  query_hints.cpu_mode ? ExecutorDeviceType::CPU : executor_device_type,
4747  /*hoist_literals=*/true,
4750  /*allow_lazy_fetch=*/true,
4751  /*filter_on_deleted_column=*/true,
4757  explain_info.justExplain(),
4758  allow_loop_joins_ || just_validate,
4760  jit_debug_,
4761  just_validate,
4764  find_push_down_candidates,
4765  explain_info.justCalciteExplain(),
4769  ExecutionResult result{std::make_shared<ResultSet>(std::vector<TargetInfo>{},
4772  nullptr,
4773  nullptr),
4774  {}};
4775  _return.execution_time_ms += measure<>::execution([&]() {
4776  result = ra_executor.executeRelAlgQuery(co, eo, explain_info.explain_plan, nullptr);
4777  });
4778  // reduce execution time by the time spent during queue waiting
4779  _return.execution_time_ms -= result.getRows()->getQueueTime();
4780  VLOG(1) << cat.getDataMgr().getSystemMemoryUsage();
4781  const auto& filter_push_down_info = result.getPushedDownFilterInfo();
4782  if (!filter_push_down_info.empty()) {
4783  return filter_push_down_info;
4784  }
4785  if (explain_info.justExplain()) {
4786  convert_explain(_return, *result.getRows(), column_format);
4787  } else if (!explain_info.justCalciteExplain()) {
4788  convert_rows(_return,
4789  timer.createQueryStateProxy(),
4790  result.getTargetsMeta(),
4791  *result.getRows(),
4792  column_format,
4793  first_n,
4794  at_most_n);
4795  }
4796  return {};
4797 }
static TableSchemaLockMgr & instance()
Definition: LockMgr.h:40
const bool jit_debug_
Definition: DBHandler.h:535
static std::shared_ptr< Executor > getExecutor(const ExecutorId id, const std::string &debug_dir="", const std::string &debug_file="", const SystemParameters system_parameters=SystemParameters())
Definition: Execute.cpp:150
bool g_enable_dynamic_watchdog
Definition: Execute.cpp:75
Timer createTimer(char const *event_name)
Definition: QueryState.cpp:113
static TableDataLockMgr & instance()
Definition: LockMgr.h:76
bool g_enable_columnar_output
Definition: Execute.cpp:91
std::string cat(Ts &&... args)
bool explain_plan
Definition: ParserWrapper.h:34
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
Definition: DBHandler.cpp:4950
QueryState & getQueryState()
Definition: QueryState.h:172
const QueryHint getParsedQueryHints() const
QueryStateProxy createQueryStateProxy()
Definition: QueryState.cpp:120
bool justCalciteExplain() const
Definition: ParserWrapper.h:41
const bool allow_loop_joins_
Definition: DBHandler.h:539
unsigned g_runtime_query_interrupt_frequency
Definition: Execute.cpp:110
const bool intel_jit_profile_
Definition: DBHandler.h:536
std::shared_ptr< Catalog_Namespace::SessionInfo const > getConstSessionInfo() const
Definition: QueryState.cpp:77
const SystemParameters & system_parameters_
Definition: DBHandler.h:545
bool explain_optimized
Definition: ParserWrapper.h:33
void convert_explain(TQueryResult &_return, const ResultSet &results, const bool column_format) const
Definition: DBHandler.cpp:5058
bool g_enable_watchdog
Definition: Execute.cpp:74
static TimeT::rep execution(F func, Args &&... args)
Definition: sample.cpp:29
bool allow_multifrag_
Definition: DBHandler.h:537
bool justExplain() const
Definition: ParserWrapper.h:39
unsigned g_dynamic_watchdog_time_limit
Definition: Execute.cpp:78
bool g_enable_runtime_query_interrupt
Definition: Execute.cpp:108
#define VLOG(n)
Definition: Logger.h:291
static const ExecutorId UNITARY_EXECUTOR_ID
Definition: Execute.h:337
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ execute_rel_alg_df()

void DBHandler::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 TArrowTransport::type  transport_method 
) const
private

Definition at line 4799 of file DBHandler.cpp.

References allow_loop_joins_, allow_multifrag_, cat(), CHECK, CPU, data_mgr_, Default, measure< TimeT >::execution(), g_dynamic_watchdog_time_limit, g_enable_columnar_output, g_enable_dynamic_watchdog, g_enable_runtime_query_interrupt, g_enable_watchdog, g_runtime_query_interrupt_frequency, Catalog_Namespace::SessionInfo::get_executor_device_type(), Catalog_Namespace::SessionInfo::getCatalog(), Executor::getExecutor(), RelAlgExecutor::getParsedQueryHints(), query_state::QueryStateProxy::getQueryState(), getTargetNames(), GPU, SystemParameters::gpu_input_mem_limit, handle_to_dev_ptr_mutex_, intel_jit_profile_, ipc_handle_to_dev_ptr_, jit_debug_, run_benchmark_import::result, system_parameters_, and Executor::UNITARY_EXECUTOR_ID.

Referenced by sql_execute_df().

4806  {
4807  const auto& cat = session_info.getCatalog();
4808  CHECK(device_type == ExecutorDeviceType::CPU ||
4811  jit_debug_ ? "/tmp" : "",
4812  jit_debug_ ? "mapdquery" : "",
4814  RelAlgExecutor ra_executor(executor.get(),
4815  cat,
4816  query_ra,
4817  query_state_proxy.getQueryState().shared_from_this());
4818  const auto& query_hints = ra_executor.getParsedQueryHints();
4819  CompilationOptions co = {query_hints.cpu_mode ? ExecutorDeviceType::CPU : device_type,
4820  /*hoist_literals=*/true,
4823  /*allow_lazy_fetch=*/true,
4824  /*filter_on_deleted_column=*/true,
4829  false,
4832  jit_debug_,
4833  false,
4836  false,
4837  false,
4841  ExecutionResult result{std::make_shared<ResultSet>(std::vector<TargetInfo>{},
4844  nullptr,
4845  nullptr),
4846  {}};
4847  _return.execution_time_ms += measure<>::execution(
4848  [&]() { result = ra_executor.executeRelAlgQuery(co, eo, false, nullptr); });
4849  _return.execution_time_ms -= result.getRows()->getQueueTime();
4850  const auto rs = result.getRows();
4851  const auto converter =
4852  std::make_unique<ArrowResultSetConverter>(rs,
4853  data_mgr_,
4854  device_type,
4855  device_id,
4856  getTargetNames(result.getTargetsMeta()),
4857  first_n,
4858  ArrowTransport(transport_method));
4859  ArrowResult arrow_result;
4860  _return.arrow_conversion_time_ms +=
4861  measure<>::execution([&] { arrow_result = converter->getArrowResult(); });
4862  _return.sm_handle =
4863  std::string(arrow_result.sm_handle.begin(), arrow_result.sm_handle.end());
4864  _return.sm_size = arrow_result.sm_size;
4865  _return.df_handle =
4866  std::string(arrow_result.df_handle.begin(), arrow_result.df_handle.end());
4867  _return.df_buffer =
4868  std::string(arrow_result.df_buffer.begin(), arrow_result.df_buffer.end());
4869  if (device_type == ExecutorDeviceType::GPU) {
4870  std::lock_guard<std::mutex> map_lock(handle_to_dev_ptr_mutex_);
4871  CHECK(!ipc_handle_to_dev_ptr_.count(_return.df_handle));
4872  ipc_handle_to_dev_ptr_.insert(
4873  std::make_pair(_return.df_handle, arrow_result.serialized_cuda_handle));
4874  }
4875  _return.df_size = arrow_result.df_size;
4876 }
std::mutex handle_to_dev_ptr_mutex_
Definition: DBHandler.h:826
ArrowTransport
const bool jit_debug_
Definition: DBHandler.h:535
static std::shared_ptr< Executor > getExecutor(const ExecutorId id, const std::string &debug_dir="", const std::string &debug_file="", const SystemParameters system_parameters=SystemParameters())
Definition: Execute.cpp:150
bool g_enable_dynamic_watchdog
Definition: Execute.cpp:75
std::vector< std::string > getTargetNames(const std::vector< TargetMetaInfo > &targets) const
Definition: DBHandler.cpp:4900
bool g_enable_columnar_output
Definition: Execute.cpp:91
std::string cat(Ts &&... args)
QueryState & getQueryState()
Definition: QueryState.h:172
const QueryHint getParsedQueryHints() const
Catalog & getCatalog() const
Definition: SessionInfo.h:65
const bool allow_loop_joins_
Definition: DBHandler.h:539
unsigned g_runtime_query_interrupt_frequency
Definition: Execute.cpp:110
const bool intel_jit_profile_
Definition: DBHandler.h:536
const SystemParameters & system_parameters_
Definition: DBHandler.h:545
std::shared_ptr< Data_Namespace::DataMgr > data_mgr_
Definition: DBHandler.h:526
#define CHECK(condition)
Definition: Logger.h:197
bool g_enable_watchdog
Definition: Execute.cpp:74
std::unordered_map< std::string, std::string > ipc_handle_to_dev_ptr_
Definition: DBHandler.h:827
static TimeT::rep execution(F func, Args &&... args)
Definition: sample.cpp:29
bool allow_multifrag_
Definition: DBHandler.h:537
unsigned g_dynamic_watchdog_time_limit
Definition: Execute.cpp:78
const ExecutorDeviceType get_executor_device_type() const
Definition: SessionInfo.h:69
bool g_enable_runtime_query_interrupt
Definition: Execute.cpp:108
static const ExecutorId UNITARY_EXECUTOR_ID
Definition: Execute.h:337
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ execute_rel_alg_with_filter_push_down()

void DBHandler::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 5411 of file DBHandler.cpp.

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

Referenced by sql_execute_impl().

5421  {
5422  // collecting the selected filters' info to be sent to Calcite:
5423  std::vector<TFilterPushDownInfo> filter_push_down_info;
5424  for (const auto& req : filter_push_down_requests) {
5425  TFilterPushDownInfo filter_push_down_info_for_request;
5426  filter_push_down_info_for_request.input_prev = req.input_prev;
5427  filter_push_down_info_for_request.input_start = req.input_start;
5428  filter_push_down_info_for_request.input_next = req.input_next;
5429  filter_push_down_info.push_back(filter_push_down_info_for_request);
5430  }
5431  // deriving the new relational algebra plan with respect to the pushed down filters
5432  _return.execution_time_ms += measure<>::execution([&]() {
5433  query_ra = parse_to_ra(query_state_proxy,
5434  query_state_proxy.getQueryState().getQueryStr(),
5435  filter_push_down_info,
5436  false,
5438  .first.plan_result;
5439  });
5440 
5441  if (just_calcite_explain) {
5442  // return the new ra as the result
5443  convert_explain(_return, ResultSet(query_ra), true);
5444  return;
5445  }
5446 
5447  // execute the new relational algebra plan:
5448  auto explain_info = ExplainInfo::defaults();
5449  explain_info.explain = just_explain;
5450  execute_rel_alg(_return,
5451  query_state_proxy,
5452  query_ra,
5453  column_format,
5454  executor_device_type,
5455  first_n,
5456  at_most_n,
5457  /*just_validate=*/false,
5458  /*find_push_down_candidates=*/false,
5459  explain_info);
5460 }
static ExplainInfo defaults()
Definition: ParserWrapper.h:37
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_validate, const bool find_push_down_candidates, const ExplainInfo &explain_info, const std::optional< size_t > executor_index=std::nullopt) const
Definition: DBHandler.cpp:4716
QueryState & getQueryState()
Definition: QueryState.h:172
std::string const & getQueryStr() const
Definition: QueryState.h:152
const SystemParameters & system_parameters_
Definition: DBHandler.h:545
void convert_explain(TQueryResult &_return, const ResultSet &results, const bool column_format) const
Definition: DBHandler.cpp:5058
std::pair< TPlanResult, lockmgr::LockedTableDescriptors > parse_to_ra(QueryStateProxy, const std::string &query_str, const std::vector< TFilterPushDownInfo > &filter_push_down_info, const bool acquire_locks, const SystemParameters system_parameters, bool check_privileges=true)
Definition: DBHandler.cpp:5478
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:

◆ executeDdl()

void DBHandler::executeDdl ( TQueryResult &  _return,
const std::string &  query_ra,
std::shared_ptr< Catalog_Namespace::SessionInfo const >  session_ptr 
)
private

Definition at line 6282 of file DBHandler.cpp.

References DdlCommandExecutor::execute(), getQueries(), DdlCommandExecutor::getTargetQuerySessionToKill(), getUserSessions(), interruptQuery(), DdlCommandExecutor::isKillQuery(), DdlCommandExecutor::isShowQueries(), and DdlCommandExecutor::isShowUserSessions().

Referenced by sql_execute_impl().

6285  {
6286  DdlCommandExecutor executor = DdlCommandExecutor(query_ra, session_ptr);
6287  if (executor.isShowUserSessions()) {
6288  getUserSessions(*session_ptr, _return);
6289  } else if (executor.isShowQueries()) {
6290  getQueries(*session_ptr, _return);
6291  } else if (executor.isKillQuery()) {
6292  interruptQuery(*session_ptr, executor.getTargetQuerySessionToKill());
6293  } else {
6294  executor.execute(_return);
6295  }
6296 }
void getQueries(const Catalog_Namespace::SessionInfo &session_info, TQueryResult &_return)
Definition: DBHandler.cpp:6173
void getUserSessions(const Catalog_Namespace::SessionInfo &session_info, TQueryResult &_return)
Definition: DBHandler.cpp:6129
const std::string getTargetQuerySessionToKill()
void execute(TQueryResult &_return)
void interruptQuery(const Catalog_Namespace::SessionInfo &session_info, const std::string &target_session)
Definition: DBHandler.cpp:6253
+ 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 > > DBHandler::fill_column_names_by_table ( std::vector< std::string > &  table_names,
query_state::StdLog stdlog 
)
private

Definition at line 1390 of file DBHandler.cpp.

References get_table_details_impl().

Referenced by get_token_based_completions().

1391  {
1392  std::unordered_map<std::string, std::unordered_set<std::string>> column_names_by_table;
1393  for (auto it = table_names.begin(); it != table_names.end();) {
1394  TTableDetails table_details;
1395  try {
1396  get_table_details_impl(table_details, stdlog, *it, false, false);
1397  } catch (const TOmniSciException& e) {
1398  // Remove the corrupted Table/View name from the list for further processing.
1399  it = table_names.erase(it);
1400  continue;
1401  }
1402  for (const auto& column_type : table_details.row_desc) {
1403  column_names_by_table[*it].emplace(column_type.col_name);
1404  }
1405  ++it;
1406  }
1407  return column_names_by_table;
1408 }
void get_table_details_impl(TTableDetails &_return, query_state::StdLog &stdlog, const std::string &table_name, const bool get_system, const bool get_physical)
Definition: DBHandler.cpp:1955
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fixup_row_descriptor()

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

Definition at line 5004 of file DBHandler.cpp.

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

Referenced by get_table_details_impl(), and sql_validate().

5005  {
5006  TRowDescriptor fixedup_row_desc;
5007  for (const TColumnType& col_desc : row_desc) {
5008  auto fixedup_col_desc = col_desc;
5009  if (col_desc.col_type.encoding == TEncodingType::DICT &&
5010  col_desc.col_type.comp_param > 0) {
5011  const auto dd = cat.getMetadataForDict(col_desc.col_type.comp_param, false);
5012  fixedup_col_desc.col_type.comp_param = dd->dictNBits;
5013  }
5014  fixedup_row_desc.push_back(fixedup_col_desc);
5015  }
5016 
5017  return fixedup_row_desc;
5018 }
const DictDescriptor * getMetadataForDict(int dict_ref, bool loadDict=true) const
Definition: Catalog.cpp:1451
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_all_files_in_archive()

void DBHandler::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 4456 of file DBHandler.cpp.

References anonymous_namespace{DBHandler.cpp}::add_vsi_archive_prefix(), anonymous_namespace{DBHandler.cpp}::add_vsi_network_prefix(), import_export::Importer::gdalFileExists(), import_export::Importer::gdalGetAllFilesInArchive(), get_session_ptr(), getConnectionInfo(), import_path_, anonymous_namespace{DBHandler.cpp}::is_a_supported_archive_file(), anonymous_namespace{DBHandler.cpp}::path_is_relative(), STDLOG, thrift_to_copyparams(), THROW_MAPD_EXCEPTION, toString(), and anonymous_namespace{DBHandler.cpp}::validate_import_file_path_if_local().

4459  {
4460  auto stdlog =
4461  STDLOG(get_session_ptr(session), "get_all_files_in_archive", archive_path_in);
4462  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
4463 
4464  std::string archive_path(archive_path_in);
4465  if (path_is_relative(archive_path)) {
4466  // assume relative paths are relative to data_path / mapd_import / <session>
4467  auto file_path = import_path_ / picosha2::hash256_hex_string(session) /
4468  boost::filesystem::path(archive_path).filename();
4469  archive_path = file_path.string();
4470  }
4471  validate_import_file_path_if_local(archive_path);
4472 
4473  if (is_a_supported_archive_file(archive_path)) {
4474  // find the archive file
4475  add_vsi_network_prefix(archive_path);
4476  if (!import_export::Importer::gdalFileExists(archive_path,
4477  thrift_to_copyparams(copy_params))) {
4478  THROW_MAPD_EXCEPTION("Archive does not exist: " + archive_path_in);
4479  }
4480  // find all files in archive
4481  add_vsi_archive_prefix(archive_path);
4483  archive_path, thrift_to_copyparams(copy_params));
4484  // prepend them all with original path
4485  for (auto& s : _return) {
4486  s = archive_path_in + '/' + s;
4487  }
4488  }
4489 }
boost::filesystem::path import_path_
Definition: DBHandler.h:531
void add_vsi_archive_prefix(std::string &path)
Definition: DBHandler.cpp:3014
bool is_a_supported_archive_file(const std::string &path)
Definition: DBHandler.cpp:3082
std::string toString(const ExtArgumentType &sig_type)
bool path_is_relative(const std::string &path)
Definition: DBHandler.cpp:3048
static bool gdalFileExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:4561
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1410
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:4656
void validate_import_file_path_if_local(const std::string &file_path)
Definition: DBHandler.cpp:3136
#define THROW_MAPD_EXCEPTION(errstr)
Definition: DBHandler.cpp:113
void add_vsi_network_prefix(std::string &path)
Definition: DBHandler.cpp:2985
static std::vector< std::string > gdalGetAllFilesInArchive(const std::string &archive_path, const CopyParams &copy_params)
Definition: Importer.cpp:4638
import_export::CopyParams thrift_to_copyparams(const TCopyParams &cp)
Definition: DBHandler.cpp:2799
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ get_all_roles_for_user()

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

Definition at line 1792 of file DBHandler.cpp.

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

1794  {
1795  auto stdlog = STDLOG(get_session_ptr(sessionId));
1796  auto session_ptr = stdlog.getConstSessionInfo();
1797  auto* grantee = SysCatalog::instance().getGrantee(granteeName);
1798  if (grantee) {
1799  if (session_ptr->get_currentUser().isSuper) {
1800  roles = grantee->getRoles();
1801  } else if (grantee->isUser()) {
1802  if (session_ptr->get_currentUser().userName == granteeName) {
1803  roles = grantee->getRoles();
1804  } else {
1806  "Only a superuser is authorized to request list of roles granted to "
1807  "another "
1808  "user.");
1809  }
1810  } else {
1811  CHECK(!grantee->isUser());
1812  // granteeName is actually a roleName here and we can check a role
1813  // only if it is granted to us
1814  if (SysCatalog::instance().isRoleGrantedToGrantee(
1815  session_ptr->get_currentUser().userName, granteeName, false)) {
1816  roles = grantee->getRoles();
1817  } else {
1818  THROW_MAPD_EXCEPTION("A user can check only roles granted to him.");
1819  }
1820  }
1821  } else {
1822  THROW_MAPD_EXCEPTION("Grantee " + granteeName + " does not exist.");
1823  }
1824 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:4656
#define THROW_MAPD_EXCEPTION(errstr)
Definition: DBHandler.cpp:113
#define CHECK(condition)
Definition: Logger.h:197
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ get_completion_hints()

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

Definition at line 1284 of file DBHandler.cpp.

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

1287  {
1288  auto stdlog = STDLOG(get_session_ptr(session));
1289  std::vector<std::string> visible_tables; // Tables allowed for the given session.
1290  get_completion_hints_unsorted(hints, visible_tables, stdlog, sql, cursor);
1291  const auto proj_tokens = extract_projection_tokens_for_completion(sql);
1292  auto compatible_table_names = get_uc_compatible_table_names_by_column(
1293  proj_tokens.uc_column_names, visible_tables, stdlog);
1294  // Add the table qualifiers explicitly specified by the user.
1295  compatible_table_names.insert(proj_tokens.uc_column_table_qualifiers.begin(),
1296  proj_tokens.uc_column_table_qualifiers.end());
1297  // Sort the hints by category, from COLUMN (most specific) to KEYWORD.
1298  std::sort(
1299  hints.begin(),
1300  hints.end(),
1301  [&compatible_table_names](const TCompletionHint& lhs, const TCompletionHint& rhs) {
1302  if (lhs.type == TCompletionHintType::TABLE &&
1303  rhs.type == TCompletionHintType::TABLE) {
1304  // Between two tables, one which is compatible with the specified
1305  // projections and one which isn't, pick the one which is compatible.
1306  if (compatible_table_names.find(to_upper(lhs.hints.back())) !=
1307  compatible_table_names.end() &&
1308  compatible_table_names.find(to_upper(rhs.hints.back())) ==
1309  compatible_table_names.end()) {
1310  return true;
1311  }
1312  }
1313  return lhs.type < rhs.type;
1314  });
1315 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:4656
ProjectionTokensForCompletion extract_projection_tokens_for_completion(const std::string &sql)
Definition: DBHandler.cpp:1260
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)
Definition: DBHandler.cpp:1317
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)
Definition: DBHandler.cpp:1415
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ get_completion_hints_unsorted()

void DBHandler::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 1317 of file DBHandler.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().

1321  {
1322  const auto& session_info = *stdlog.getConstSessionInfo();
1323  try {
1324  get_tables_impl(visible_tables, session_info, GET_PHYSICAL_TABLES_AND_VIEWS);
1325  // Filter out keywords suggested by Calcite which we don't support.
1327  calcite_->getCompletionHints(session_info, visible_tables, sql, cursor));
1328  } catch (const std::exception& e) {
1329  TOmniSciException ex;
1330  ex.error_msg = "Exception: " + std::string(e.what());
1331  LOG(ERROR) << ex.error_msg;
1332  throw ex;
1333  }
1334  boost::regex from_expr{R"(\s+from\s+)", boost::regex::extended | boost::regex::icase};
1335  const size_t length_to_cursor =
1336  cursor < 0 ? sql.size() : std::min(sql.size(), static_cast<size_t>(cursor));
1337  // Trust hints from Calcite after the FROM keyword.
1338  if (boost::regex_search(sql.cbegin(), sql.cbegin() + length_to_cursor, from_expr)) {
1339  return;
1340  }
1341  // Before FROM, the query is too incomplete for context-sensitive completions.
1342  get_token_based_completions(hints, stdlog, visible_tables, sql, cursor);
1343 }
#define LOG(tag)
Definition: Logger.h:188
std::vector< TCompletionHint > just_whitelisted_keyword_hints(const std::vector< TCompletionHint > &hints)
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)
Definition: DBHandler.cpp:1345
std::shared_ptr< Calcite > calcite_
Definition: DBHandler.h:549
void get_tables_impl(std::vector< std::string > &table_names, const Catalog_Namespace::SessionInfo &, const GetTablesType get_tables_type)
Definition: DBHandler.cpp:2081
std::shared_ptr< Catalog_Namespace::SessionInfo const > getConstSessionInfo() const
Definition: QueryState.cpp:130
+ 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 > DBHandler::get_const_session_ptr ( const TSessionId &  session)
private

Definition at line 4633 of file DBHandler.cpp.

References get_session_ptr().

4634  {
4635  return get_session_ptr(session);
4636 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:4656
+ Here is the call graph for this function:

◆ get_dashboard()

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

Definition at line 3345 of file DBHandler.cpp.

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

3347  {
3348  auto stdlog = STDLOG(get_session_ptr(session));
3349  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
3350  auto session_ptr = stdlog.getConstSessionInfo();
3351  auto const& cat = session_ptr->getCatalog();
3353  auto dash = cat.getMetadataForDashboard(dashboard_id);
3354  if (!dash) {
3355  THROW_MAPD_EXCEPTION("Dashboard with dashboard id " + std::to_string(dashboard_id) +
3356  " doesn't exist");
3357  }
3359  *session_ptr, dash->dashboardId, AccessPrivileges::VIEW_DASHBOARD)) {
3360  THROW_MAPD_EXCEPTION("User has no view privileges for the dashboard with id " +
3361  std::to_string(dashboard_id));
3362  }
3363  user_meta.userName = "";
3364  SysCatalog::instance().getMetadataForUserById(dash->userId, user_meta);
3365  auto objects_list = SysCatalog::instance().getMetadataForObject(
3366  cat.getCurrentDB().dbId,
3367  static_cast<int>(DBObjectType::DashboardDBObjectType),
3368  dashboard_id);
3369  dashboard.dashboard_name = dash->dashboardName;
3370  dashboard.dashboard_state = dash->dashboardState;
3371  dashboard.image_hash = dash->imageHash;
3372  dashboard.update_time = dash->updateTime;
3373  dashboard.dashboard_metadata = dash->dashboardMetadata;
3374  dashboard.dashboard_owner = dash->user;
3375  dashboard.dashboard_id = dash->dashboardId;
3376  if (objects_list.empty() ||
3377  (objects_list.size() == 1 && objects_list[0]->roleName == user_meta.userName)) {
3378  dashboard.is_dash_shared = false;
3379  } else {
3380  dashboard.is_dash_shared = true;
3381  }
3382 }
static const AccessPrivileges VIEW_DASHBOARD
Definition: DBObject.h:172
std::string toString(const ExtArgumentType &sig_type)
std::string to_string(char const *&&v)
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1410
std::string cat(Ts &&... args)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:4656
#define THROW_MAPD_EXCEPTION(errstr)
Definition: DBHandler.cpp:113
static bool is_allowed_on_dashboard(const Catalog_Namespace::SessionInfo &session_info, int32_t dashboard_id, AccessPrivileges requestedPermissions)
Definition: DBHandler.cpp:3332
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ get_dashboard_grantees()

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

Definition at line 3657 of file DBHandler.cpp.

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

3660  {
3661  auto stdlog = STDLOG(get_session_ptr(session));
3662  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
3663  auto session_ptr = stdlog.getConstSessionInfo();
3664  auto const& cat = session_ptr->getCatalog();
3666  auto dash = cat.getMetadataForDashboard(dashboard_id);
3667  if (!dash) {
3668  THROW_MAPD_EXCEPTION("Exception: Dashboard id " + std::to_string(dashboard_id) +
3669  " does not exist");
3670  } else if (session_ptr->get_currentUser().userId != dash->userId &&
3671  !session_ptr->get_currentUser().isSuper) {
3673  "User should be either owner of dashboard or super user to access grantees");
3674  }
3675  std::vector<ObjectRoleDescriptor*> objectsList;
3676  objectsList = SysCatalog::instance().getMetadataForObject(
3677  cat.getCurrentDB().dbId,
3678  static_cast<int>(DBObjectType::DashboardDBObjectType),
3679  dashboard_id); // By default objecttypecan be only dashabaords
3680  user_meta.userId = -1;
3681  user_meta.userName = "";
3682  SysCatalog::instance().getMetadataForUserById(dash->userId, user_meta);
3683  for (auto object : objectsList) {
3684  if (user_meta.userName == object->roleName) {
3685  // Mask owner
3686  continue;
3687  }
3688  TDashboardGrantees grantee;
3689  TDashboardPermissions perm;
3690  grantee.name = object->roleName;
3691  grantee.is_user = object->roleType;
3692  perm.create_ = object->privs.hasPermission(DashboardPrivileges::CREATE_DASHBOARD);
3693  perm.delete_ = object->privs.hasPermission(DashboardPrivileges::DELETE_DASHBOARD);
3694  perm.edit_ = object->privs.hasPermission(DashboardPrivileges::EDIT_DASHBOARD);
3695  perm.view_ = object->privs.hasPermission(DashboardPrivileges::VIEW_DASHBOARD);
3696  grantee.permissions = perm;
3697  dashboard_grantees.push_back(grantee);
3698  }
3699 }
std::string toString(const ExtArgumentType &sig_type)
std::string to_string(char const *&&v)
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1410
std::string cat(Ts &&... args)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:4656
static const int32_t EDIT_DASHBOARD
Definition: DBObject.h:106
static const int32_t DELETE_DASHBOARD
Definition: DBObject.h:104
#define THROW_MAPD_EXCEPTION(errstr)
Definition: DBHandler.cpp:113
static const int32_t VIEW_DASHBOARD
Definition: DBObject.h:105
static const int32_t CREATE_DASHBOARD
Definition: DBObject.h:103
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ get_dashboards()

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

Definition at line 3384 of file DBHandler.cpp.

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

3385  {
3386  auto stdlog = STDLOG(get_session_ptr(session));
3387  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
3388  auto session_ptr = stdlog.getConstSessionInfo();
3389  auto const& cat = session_ptr->getCatalog();
3391  const auto dashes = cat.getAllDashboardsMetadata();
3392  user_meta.userName = "";
3393  for (const auto d : dashes) {
3394  SysCatalog::instance().getMetadataForUserById(d->userId, user_meta);
3396  *session_ptr, d->dashboardId, AccessPrivileges::VIEW_DASHBOARD)) {
3397  auto objects_list = SysCatalog::instance().getMetadataForObject(
3398  cat.getCurrentDB().dbId,
3399  static_cast<int>(DBObjectType::DashboardDBObjectType),
3400  d->dashboardId);
3401  TDashboard dash;
3402  dash.dashboard_name = d->dashboardName;
3403  dash.image_hash = d->imageHash;
3404  dash.update_time = d->updateTime;
3405  dash.dashboard_metadata = d->dashboardMetadata;
3406  dash.dashboard_id = d->dashboardId;
3407  dash.dashboard_owner = d->user;
3408  // dashboardState is intentionally not populated here
3409  // for payload reasons
3410  // use get_dashboard call to get state
3411  if (objects_list.empty() ||
3412  (objects_list.size() == 1 && objects_list[0]->roleName == user_meta.userName)) {
3413  dash.is_dash_shared = false;
3414  } else {
3415  dash.is_dash_shared = true;
3416  }
3417  dashboards.push_back(dash);
3418  }
3419  }
3420 }
static const AccessPrivileges VIEW_DASHBOARD
Definition: DBObject.h:172
std::string toString(const ExtArgumentType &sig_type)
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1410
std::string cat(Ts &&... args)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:4656
static bool is_allowed_on_dashboard(const Catalog_Namespace::SessionInfo &session_info, int32_t dashboard_id, AccessPrivileges requestedPermissions)
Definition: DBHandler.cpp:3332
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ get_databases()

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

Definition at line 2332 of file DBHandler.cpp.

References get_session_ptr(), getConnectionInfo(), STDLOG, and toString().

2332  {
2333  auto stdlog = STDLOG(get_session_ptr(session));
2334  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
2335  auto session_ptr = stdlog.getConstSessionInfo();
2336  const auto& user = session_ptr->get_currentUser();
2338  SysCatalog::instance().getDatabaseListForUser(user);
2339  for (auto& db : dbs) {
2340  TDBInfo dbinfo;
2341  dbinfo.db_name = std::move(db.dbName);
2342  dbinfo.db_owner = std::move(db.dbOwnerName);
2343  dbinfos.push_back(std::move(dbinfo));
2344  }
2345 }
std::string toString(const ExtArgumentType &sig_type)
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1410
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:4656
std::list< DBSummary > DBSummaryList
Definition: SysCatalog.h:118
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ get_db_object_privs()

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

Definition at line 1711 of file DBHandler.cpp.

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

1714  {
1715  auto stdlog = STDLOG(get_session_ptr(sessionId));
1716  auto session_ptr = stdlog.getConstSessionInfo();
1717  DBObjectType object_type;
1718  switch (type) {
1720  object_type = DBObjectType::DatabaseDBObjectType;
1721  break;
1723  object_type = DBObjectType::TableDBObjectType;
1724  break;
1727  break;
1729  object_type = DBObjectType::ViewDBObjectType;
1730  break;
1731  default:
1732  THROW_MAPD_EXCEPTION("Failed to get object privileges for " + objectName +
1733  ": unknown object type (" + std::to_string(type) + ").");
1734  }
1735  DBObject object_to_find(objectName, object_type);
1736 
1737  // TODO(adb): Use DatabaseLock to protect method
1738  try {
1739  if (object_type == DashboardDBObjectType) {
1740  if (objectName == "") {
1741  object_to_find = DBObject(-1, object_type);
1742  } else {
1743  object_to_find = DBObject(std::stoi(objectName), object_type);
1744  }
1745  } else if ((object_type == TableDBObjectType || object_type == ViewDBObjectType) &&
1746  !objectName.empty()) {
1747  // special handling for view / table
1748  auto const& cat = session_ptr->getCatalog();
1749  auto td = cat.getMetadataForTable(objectName, false);
1750  if (td) {
1751  object_type = td->isView ? ViewDBObjectType : TableDBObjectType;
1752  object_to_find = DBObject(objectName, object_type);
1753  }
1754  }
1755  object_to_find.loadKey(session_ptr->getCatalog());
1756  } catch (const std::exception&) {
1757  THROW_MAPD_EXCEPTION("Object with name " + objectName + " does not exist.");
1758  }
1759 
1760  // object type on database level
1761  DBObject object_to_find_dblevel("", object_type);
1762  object_to_find_dblevel.loadKey(session_ptr->getCatalog());
1763  // if user is superuser respond with a full priv
1764  if (session_ptr->get_currentUser().isSuper) {
1765  // using ALL_TABLE here to set max permissions
1766  DBObject dbObj{object_to_find.getObjectKey(),
1768  session_ptr->get_currentUser().userId};
1769  dbObj.setName("super");
1770  TDBObjects.push_back(
1771  serialize_db_object(session_ptr->get_currentUser().userName, dbObj));
1772  };
1773 
1774  std::vector<std::string> grantees =
1775  SysCatalog::instance().getRoles(true,
1776  session_ptr->get_currentUser().isSuper,
1777  session_ptr->get_currentUser().userName);
1778  for (const auto& grantee : grantees) {
1779  DBObject* object_found;
1780  auto* gr = SysCatalog::instance().getGrantee(grantee);
1781  if (gr && (object_found = gr->findDbObject(object_to_find.getObjectKey(), true))) {
1782  TDBObjects.push_back(serialize_db_object(grantee, *object_found));
1783  }
1784  // check object permissions on Database level
1785  if (gr &&
1786  (object_found = gr->findDbObject(object_to_find_dblevel.getObjectKey(), true))) {
1787  TDBObjects.push_back(serialize_db_object(grantee, *object_found));
1788  }
1789  }
1790 }
DBObjectType
Definition: DBObject.h:42
std::string to_string(char const *&&v)
DBObjectKey getObjectKey() const
Definition: DBObject.h:211
std::string cat(Ts &&... args)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:4656
#define THROW_MAPD_EXCEPTION(errstr)
Definition: DBHandler.cpp:113
static TDBObject serialize_db_object(const std::string &roleName, const DBObject &inObject)
Definition: DBHandler.cpp:1499
static const AccessPrivileges ALL_TABLE
Definition: DBObject.h:158
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ get_db_objects_for_grantee()

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

Definition at line 1684 of file DBHandler.cpp.

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

1686  {
1687  auto stdlog = STDLOG(get_session_ptr(sessionId));
1688  auto session_ptr = stdlog.getConstSessionInfo();
1689  auto const& user = session_ptr->get_currentUser();
1690  if (!user.isSuper &&
1691  !SysCatalog::instance().isRoleGrantedToGrantee(user.userName, roleName, false)) {
1692  return;
1693  }
1694  auto* rl = SysCatalog::instance().getGrantee(roleName);
1695  if (rl) {
1696  auto dbId = session_ptr->getCatalog().getCurrentDB().dbId;
1697  for (auto& dbObject : *rl->getDbObjects(true)) {
1698  if (dbObject.first.dbId != dbId) {
1699  // TODO (max): it doesn't scale well in case we have many DBs (not a typical
1700  // usecase for now, though)
1701  continue;
1702  }
1703  TDBObject tdbObject = serialize_db_object(roleName, *dbObject.second);
1704  TDBObjectsForRole.push_back(tdbObject);
1705  }
1706  } else {
1707  THROW_MAPD_EXCEPTION("User or role " + roleName + " does not exist.");
1708  }
1709 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:4656
#define THROW_MAPD_EXCEPTION(errstr)
Definition: DBHandler.cpp:113
static TDBObject serialize_db_object(const std::string &roleName, const DBObject &inObject)
Definition: DBHandler.cpp:1499
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ get_device_parameters()

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

Definition at line 5958 of file DBHandler.cpp.

References cpu_mode_only_, EXPOSE_THRIFT_MAP, and get_session_copy().

Referenced by emergency_shutdown().

5959  {
5960  const auto session_info = get_session_copy(session);
5961  auto params = ::get_device_parameters(cpu_mode_only_);
5962  for (auto item : params) {
5963  _return.insert(item);
5964  }
5965  EXPOSE_THRIFT_MAP(TDeviceType);
5966  EXPOSE_THRIFT_MAP(TDatumType);
5967  EXPOSE_THRIFT_MAP(TEncodingType);
5968  EXPOSE_THRIFT_MAP(TExtArgumentType);
5969  EXPOSE_THRIFT_MAP(TOutputBufferSizeType);
5970 }
#define EXPOSE_THRIFT_MAP(TYPENAME)
Definition: DBHandler.cpp:5947
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
Definition: DBHandler.cpp:4638
void get_device_parameters(std::map< std::string, std::string > &_return, const TSessionId &session) override
Definition: DBHandler.cpp:5958
bool cpu_mode_only_
Definition: DBHandler.h:540
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_first_geo_file_in_archive()

void DBHandler::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 4413 of file DBHandler.cpp.

References anonymous_namespace{DBHandler.cpp}::add_vsi_archive_prefix(), anonymous_namespace{DBHandler.cpp}::add_vsi_network_prefix(), anonymous_namespace{DBHandler.cpp}::find_first_geo_file_in_archive(), import_export::Importer::gdalFileExists(), get_session_ptr(), getConnectionInfo(), import_path_, anonymous_namespace{DBHandler.cpp}::is_a_supported_archive_file(), anonymous_namespace{DBHandler.cpp}::path_is_relative(), STDLOG, thrift_to_copyparams(), THROW_MAPD_EXCEPTION, toString(), and anonymous_namespace{DBHandler.cpp}::validate_import_file_path_if_local().

4416  {
4417  auto stdlog =
4418  STDLOG(get_session_ptr(session), "get_first_geo_file_in_archive", archive_path_in);
4419  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
4420 
4421  std::string archive_path(archive_path_in);
4422 
4423  if (path_is_relative(archive_path)) {
4424  // assume relative paths are relative to data_path / mapd_import / <session>
4425  auto file_path = import_path_ / picosha2::hash256_hex_string(session) /
4426  boost::filesystem::path(archive_path).filename();
4427  archive_path = file_path.string();
4428  }
4429  validate_import_file_path_if_local(archive_path);
4430 
4431  if (is_a_supported_archive_file(archive_path)) {
4432  // find the archive file
4433  add_vsi_network_prefix(archive_path);
4434  if (!import_export::Importer::gdalFileExists(archive_path,
4435  thrift_to_copyparams(copy_params))) {
4436  THROW_MAPD_EXCEPTION("Archive does not exist: " + archive_path_in);
4437  }
4438  // find geo file in archive
4439  add_vsi_archive_prefix(archive_path);
4440  std::string geo_file =
4441  find_first_geo_file_in_archive(archive_path, thrift_to_copyparams(copy_params));
4442  // what did we get?
4443  if (geo_file.size()) {
4444  // prepend it with the original path
4445  _return = archive_path_in + std::string("/") + geo_file;
4446  } else {
4447  // just return the original path
4448  _return = archive_path_in;
4449  }
4450  } else {
4451  // just return the original path
4452  _return = archive_path_in;
4453  }
4454 }
boost::filesystem::path import_path_
Definition: DBHandler.h:531
void add_vsi_archive_prefix(std::string &path)
Definition: DBHandler.cpp:3014
bool is_a_supported_archive_file(const std::string &path)
Definition: DBHandler.cpp:3082
std::string toString(const ExtArgumentType &sig_type)
bool path_is_relative(const std::string &path)
Definition: DBHandler.cpp:3048
static bool gdalFileExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:4561
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1410
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:4656
void validate_import_file_path_if_local(const std::string &file_path)
Definition: DBHandler.cpp:3136
#define THROW_MAPD_EXCEPTION(errstr)
Definition: DBHandler.cpp:113
std::string find_first_geo_file_in_archive(const std::string &archive_path, const import_export::CopyParams &copy_params)
Definition: DBHandler.cpp:3095
void add_vsi_network_prefix(std::string &path)
Definition: DBHandler.cpp:2985
import_export::CopyParams thrift_to_copyparams(const TCopyParams &cp)
Definition: DBHandler.cpp:2799
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ get_hardware_info()

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

Definition at line 715 of file DBHandler.cpp.

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

716  {
717  auto stdlog = STDLOG(get_session_ptr(session));
718  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
719  THardwareInfo ret;
720  const auto cuda_mgr = data_mgr_->getCudaMgr();
721  if (cuda_mgr) {
722  ret.num_gpu_hw = cuda_mgr->getDeviceCount();
723  ret.start_gpu = cuda_mgr->getStartGpu();
724  if (ret.start_gpu >= 0) {
725  ret.num_gpu_allocated = cuda_mgr->getDeviceCount() - cuda_mgr->getStartGpu();
726  // ^ This will break as soon as we allow non contiguous GPU allocations to MapD
727  }
728  for (int16_t device_id = 0; device_id < ret.num_gpu_hw; device_id++) {
729  TGpuSpecification gpu_spec;
730  auto deviceProperties = cuda_mgr->getDeviceProperties(device_id);
731  gpu_spec.num_sm = deviceProperties->numMPs;
732  gpu_spec.clock_frequency_kHz = deviceProperties->clockKhz;
733  gpu_spec.memory = deviceProperties->globalMem;
734  gpu_spec.compute_capability_major = deviceProperties->computeMajor;
735  gpu_spec.compute_capability_minor = deviceProperties->computeMinor;
736  ret.gpu_info.push_back(gpu_spec);
737  }
738  }
739 
740  // start hardware/OS dependent code
741  ret.num_cpu_hw = std::thread::hardware_concurrency();
742  // ^ This might return diffrent results in case of hyper threading
743  // end hardware/OS dependent code
744 
745  _return.hardware_info.push_back(ret);
746  if (leaf_aggregator_.leafCount() > 0) {
747  ret.host_name = "aggregator";
748  TClusterHardwareInfo leaf_hardware = leaf_aggregator_.getHardwareInfo(session);
749  _return.hardware_info.insert(_return.hardware_info.end(),
750  leaf_hardware.hardware_info.begin(),
751  leaf_hardware.hardware_info.end());
752  }
753 }
std::string toString(const ExtArgumentType &sig_type)
LeafAggregator leaf_aggregator_
Definition: DBHandler.h:528
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1410
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:4656
TClusterHardwareInfo getHardwareInfo(TSessionId session)
std::shared_ptr< Data_Namespace::DataMgr > data_mgr_
Definition: DBHandler.h:526
size_t leafCount() const
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ get_heap_profile()

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

Definition at line 4591 of file DBHandler.cpp.

References get_session_ptr(), STDLOG, and THROW_MAPD_EXCEPTION.

4591  {
4592  auto stdlog = STDLOG(get_session_ptr(session));
4593 #ifdef HAVE_PROFILER
4594  if (!IsHeapProfilerRunning()) {
4595  THROW_MAPD_EXCEPTION("Profiler not running");
4596  }
4597  auto profile_buff = GetHeapProfile();
4598  profile = profile_buff;
4599  free(profile_buff);
4600 #else
4601  THROW_MAPD_EXCEPTION("Profiler not enabled");
4602 #endif // HAVE_PROFILER
4603 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:4656
#define THROW_MAPD_EXCEPTION(errstr)
Definition: DBHandler.cpp:113
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ get_internal_table_details()

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

Definition at line 1939 of file DBHandler.cpp.

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

1941  {
1942  auto stdlog = STDLOG(get_session_ptr(session), "table_name", table_name);
1943  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
1944  get_table_details_impl(_return, stdlog, table_name, true, false);
1945 }
std::string toString(const ExtArgumentType &sig_type)
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1410
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:4656
#define STDLOG(...)
Definition: QueryState.h:225
void get_table_details_impl(TTableDetails &_return, query_state::StdLog &stdlog, const std::string &table_name, const bool get_system, const bool get_physical)
Definition: DBHandler.cpp:1955
+ Here is the call graph for this function:

◆ get_layers_in_geo_file()

void DBHandler::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 4491 of file DBHandler.cpp.

References anonymous_namespace{DBHandler.cpp}::add_vsi_archive_prefix(), anonymous_namespace{DBHandler.cpp}::add_vsi_geo_prefix(), anonymous_namespace{DBHandler.cpp}::add_vsi_network_prefix(), CHECK, import_export::Importer::EMPTY, anonymous_namespace{DBHandler.cpp}::find_first_geo_file_in_archive(), import_export::Importer::gdalFileExists(), import_export::Importer::gdalFileOrDirectoryExists(), import_export::Importer::gdalGetLayersInGeoFile(), import_export::Importer::GEO, get_session_ptr(), getConnectionInfo(), import_path_, anonymous_namespace{DBHandler.cpp}::is_a_supported_archive_file(), anonymous_namespace{DBHandler.cpp}::is_a_supported_geo_file(), import_export::Importer::NON_GEO, anonymous_namespace{DBHandler.cpp}::path_is_relative(), STDLOG, thrift_to_copyparams(), THROW_MAPD_EXCEPTION, toString(), import_export::Importer::UNSUPPORTED_GEO, and anonymous_namespace{DBHandler.cpp}::validate_import_file_path_if_local().

4494  {
4495  auto stdlog = STDLOG(get_session_ptr(session), "get_layers_in_geo_file", file_name_in);
4496  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
4497 
4498  std::string file_name(file_name_in);
4499 
4501 
4502  // handle relative paths
4503  if (path_is_relative(file_name)) {
4504  // assume relative paths are relative to data_path / mapd_import / <session>
4505  auto file_path = import_path_ / picosha2::hash256_hex_string(session) /
4506  boost::filesystem::path(file_name).filename();
4507  file_name = file_path.string();
4508  }
4510 
4511  // validate file_name
4512  if (is_a_supported_geo_file(file_name, true)) {
4513  // prepare to load geo file directly
4514  add_vsi_network_prefix(file_name);
4515  add_vsi_geo_prefix(file_name);
4516  } else if (is_a_supported_archive_file(file_name)) {
4517  // find the archive file
4518  add_vsi_network_prefix(file_name);
4519  if (!import_export::Importer::gdalFileExists(file_name, copy_params)) {
4520  THROW_MAPD_EXCEPTION("Archive does not exist: " + file_name_in);
4521  }
4522  // find geo file in archive
4523  add_vsi_archive_prefix(file_name);
4524  std::string geo_file = find_first_geo_file_in_archive(file_name, copy_params);
4525  // prepare to load that geo file
4526  if (geo_file.size()) {
4527  file_name = file_name + std::string("/") + geo_file;
4528  }
4529  } else {
4530  THROW_MAPD_EXCEPTION("File is not a supported geo or geo archive file: " +
4531  file_name_in);
4532  }
4533 
4534  // check the file actually exists
4535  if (!import_export::Importer::gdalFileOrDirectoryExists(file_name, copy_params)) {
4536  THROW_MAPD_EXCEPTION("Geo file/archive does not exist: " + file_name_in);
4537  }
4538 
4539  // find all layers
4540  auto internal_layer_info =
4541  import_export::Importer::gdalGetLayersInGeoFile(file_name, copy_params);
4542 
4543  // convert to Thrift type
4544  for (const auto& internal_layer : internal_layer_info) {
4545  TGeoFileLayerInfo layer;
4546  layer.name = internal_layer.name;
4547  switch (internal_layer.contents) {
4549  layer.contents = TGeoFileLayerContents::EMPTY;
4550  break;
4552  layer.contents = TGeoFileLayerContents::GEO;
4553  break;
4555  layer.contents = TGeoFileLayerContents::NON_GEO;
4556  break;
4558  layer.contents = TGeoFileLayerContents::UNSUPPORTED_GEO;
4559  break;
4560  default:
4561  CHECK(false);
4562  }
4563  _return.emplace_back(layer); // no suitable constructor to just pass parameters
4564  }
4565 }
boost::filesystem::path import_path_
Definition: DBHandler.h:531
void add_vsi_archive_prefix(std::string &path)
Definition: DBHandler.cpp:3014
bool is_a_supported_archive_file(const std::string &path)
Definition: DBHandler.cpp:3082
std::string toString(const ExtArgumentType &sig_type)
bool path_is_relative(const std::string &path)
Definition: DBHandler.cpp:3048
static std::vector< GeoFileLayerInfo > gdalGetLayersInGeoFile(const std::string &file_name, const CopyParams &copy_params)
Definition: Importer.cpp:4663
static bool gdalFileExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:4561
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1410
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:4656
void validate_import_file_path_if_local(const std::string &file_path)
Definition: DBHandler.cpp:3136
#define THROW_MAPD_EXCEPTION(errstr)
Definition: DBHandler.cpp:113
static bool gdalFileOrDirectoryExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:4566
std::string find_first_geo_file_in_archive(const std::string &archive_path, const import_export::CopyParams &copy_params)
Definition: DBHandler.cpp:3095
void add_vsi_network_prefix(std::string &path)
Definition: DBHandler.cpp:2985
#define CHECK(condition)
Definition: Logger.h:197
import_export::CopyParams thrift_to_copyparams(const TCopyParams &cp)
Definition: DBHandler.cpp:2799
void add_vsi_geo_prefix(std::string &path)
Definition: DBHandler.cpp:3007
#define STDLOG(...)
Definition: QueryState.h:225
bool is_a_supported_geo_file(const std::string &path, bool include_gz)
Definition: DBHandler.cpp:3064
+ Here is the call graph for this function:

◆ get_license_claims()

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

Definition at line 5923 of file DBHandler.cpp.

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

5925  {
5926  auto stdlog = STDLOG(get_session_ptr(session));
5927  const auto session_info = get_session_copy(session);
5928  _return.claims.emplace_back("");
5929 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:4656
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
Definition: DBHandler.cpp:4638
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ get_link_view()

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

Definition at line 2047 of file DBHandler.cpp.

References cat(), get_session_ptr(), getConnectionInfo(), STDLOG, THROW_MAPD_EXCEPTION, to_string(), and toString().

2049  {
2050  auto stdlog = STDLOG(get_session_ptr(session));
2051  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
2052  auto session_ptr = stdlog.getConstSessionInfo();
2053  auto const& cat = session_ptr->getCatalog();
2054  auto ld = cat.getMetadataForLink(std::to_string(cat.getCurrentDB().dbId) + link);
2055  if (!ld) {
2056  THROW_MAPD_EXCEPTION("Link " + link + " is not valid.");
2057  }
2058  _return.view_state = ld->viewState;
2059  _return.view_name = ld->link;
2060  _return.update_time = ld->updateTime;
2061  _return.view_metadata = ld->viewMetadata;
2062 }
std::string toString(const ExtArgumentType &sig_type)
std::string to_string(char const *&&v)
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1410
std::string cat(Ts &&... args)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:4656
#define THROW_MAPD_EXCEPTION(errstr)
Definition: DBHandler.cpp:113
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ get_memory()

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

Definition at line 2287 of file DBHandler.cpp.

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

2289  {
2290  auto stdlog = STDLOG(get_session_ptr(session));
2291  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
2292  std::vector<Data_Namespace::MemoryInfo> internal_memory;
2293  Data_Namespace::MemoryLevel mem_level;
2294  if (!memory_level.compare("gpu")) {
2296  internal_memory =
2297  SysCatalog::instance().getDataMgr().getMemoryInfo(MemoryLevel::GPU_LEVEL);
2298  } else {
2300  internal_memory =
2301  SysCatalog::instance().getDataMgr().getMemoryInfo(MemoryLevel::CPU_LEVEL);
2302  }
2303 
2304  for (auto memInfo : internal_memory) {
2305  TNodeMemoryInfo nodeInfo;
2306  if (leaf_aggregator_.leafCount() > 0) {
2307  nodeInfo.host_name = omnisci::get_hostname();
2308  }
2309  nodeInfo.page_size = memInfo.pageSize;
2310  nodeInfo.max_num_pages = memInfo.maxNumPages;
2311  nodeInfo.num_pages_allocated = memInfo.numPageAllocated;
2312  nodeInfo.is_allocation_capped = memInfo.isAllocationCapped;
2313  for (auto gpu : memInfo.nodeMemoryData) {
2314  TMemoryData md;
2315  md.slab = gpu.slabNum;
2316  md.start_page = gpu.startPage;
2317  md.num_pages = gpu.numPages;
2318  md.touch = gpu.touch;
2319  md.chunk_key.insert(md.chunk_key.end(), gpu.chunk_key.begin(), gpu.chunk_key.end());
2320  md.is_free = gpu.memStatus == Buffer_Namespace::MemStatus::FREE;
2321  nodeInfo.node_memory_data.push_back(md);
2322  }
2323  _return.push_back(nodeInfo);
2324  }
2325  if (leaf_aggregator_.leafCount() > 0) {
2326  std::vector<TNodeMemoryInfo> leafSummary =
2327  leaf_aggregator_.getLeafMemoryInfo(session, mem_level);
2328  _return.insert(_return.begin(), leafSummary.begin(), leafSummary.end());
2329  }
2330 }
std::string toString(const ExtArgumentType &sig_type)
LeafAggregator leaf_aggregator_
Definition: DBHandler.h:528
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1410
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:4656
std::vector< TNodeMemoryInfo > getLeafMemoryInfo(TSessionId session, Data_Namespace::MemoryLevel memory_level)
size_t leafCount() const
std::string get_hostname()
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ get_physical_tables()

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

Definition at line 2096 of file DBHandler.cpp.

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

2097  {
2098  auto stdlog = STDLOG(get_session_ptr(session));
2099  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
2100  get_tables_impl(table_names, *stdlog.getConstSessionInfo(), GET_PHYSICAL_TABLES);
2101 }
std::string toString(const ExtArgumentType &sig_type)
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1410
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:4656
void get_tables_impl(std::vector< std::string > &table_names, const Catalog_Namespace::SessionInfo &, const GetTablesType get_tables_type)
Definition: DBHandler.cpp:2081
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ get_result_row_for_pixel()

void DBHandler::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 1840 of file DBHandler.cpp.

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

1848  {
1849  auto stdlog = STDLOG(get_session_ptr(session),
1850  "widget_id",
1851  widget_id,
1852  "pixel.x",
1853  pixel.x,
1854  "pixel.y",
1855  pixel.y,
1856  "column_format",
1857  column_format,
1858  "pixel_radius",
1859  pixel_radius,
1860  "table_col_names",
1861  dump_table_col_names(table_col_names),
1862  "nonce",
1863  nonce);
1864  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
1865  auto session_ptr = stdlog.getSessionInfo();
1866  if (!render_handler_) {
1867  THROW_MAPD_EXCEPTION("Backend rendering is disabled.");
1868  }
1869 
1870  try {
1871  render_handler_->get_result_row_for_pixel(_return,
1872  session_ptr,
1873  widget_id,
1874  pixel,
1875  table_col_names,
1876  column_format,
1877  pixel_radius,
1878  nonce);
1879  } catch (std::exception& e) {
1880  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
1881  }
1882 }
std::string toString(const ExtArgumentType &sig_type)
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1410
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:4656
std::unique_ptr< RenderHandler > render_handler_
Definition: DBHandler.h:546
#define THROW_MAPD_EXCEPTION(errstr)
Definition: DBHandler.cpp:113
std::string dump_table_col_names(const std::map< std::string, std::vector< std::string >> &table_col_names)
Definition: DBHandler.cpp:1827
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ get_roles()

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

Definition at line 1464 of file DBHandler.cpp.

References get_session_ptr(), and STDLOG.

1464  {
1465  auto stdlog = STDLOG(get_session_ptr(session));
1466  auto session_ptr = stdlog.getConstSessionInfo();
1467  if (!session_ptr->get_currentUser().isSuper) {
1468  // WARNING: This appears to not include roles a user is a member of,
1469  // if the role has no permissions granted to it.
1470  roles =
1471  SysCatalog::instance().getRoles(session_ptr->get_currentUser().userName,
1472  session_ptr->getCatalog().getCurrentDB().dbId);
1473  } else {
1474  roles = SysCatalog::instance().getRoles(
1475  false, true, session_ptr->get_currentUser().userName);
1476  }
1477 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:4656
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ get_server_status()

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

Definition at line 672 of file DBHandler.cpp.

References omnisci::get_hostname(), get_session_ptr(), getConnectionInfo(), MAPD_EDITION, MAPD_RELEASE, read_only_, render_handler_, start_time_, STDLOG, and toString().

672  {
673  auto stdlog = STDLOG(get_session_ptr(session));
674  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
675  const auto rendering_enabled = bool(render_handler_);
676  _return.read_only = read_only_;
677  _return.version = MAPD_RELEASE;
678  _return.rendering_enabled = rendering_enabled;
679  _return.poly_rendering_enabled = rendering_enabled;
680  _return.start_time = start_time_;
681  _return.edition = MAPD_EDITION;
682  _return.host_name = omnisci::get_hostname();
683 }
std::string toString(const ExtArgumentType &sig_type)
static const std::string MAPD_EDITION
Definition: release.h:41
int64_t start_time_
Definition: DBHandler.h:543
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1410
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:4656
std::unique_ptr< RenderHandler > render_handler_
Definition: DBHandler.h:546
const bool read_only_
Definition: DBHandler.h:538
std::string get_hostname()
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 DBHandler::get_session_copy ( const TSessionId &  session)

Definition at line 4638 of file DBHandler.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().

4638  {
4639  mapd_shared_lock<mapd_shared_mutex> read_lock(sessions_mutex_);
4640  return *get_session_it_unsafe(session, read_lock)->second;
4641 }
mapd_shared_mutex sessions_mutex_
Definition: DBHandler.h:541
SessionMap::iterator get_session_it_unsafe(const TSessionId &session, SESSION_MAP_LOCK &lock)
mapd_shared_lock< mapd_shared_mutex > read_lock
+ 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 > DBHandler::get_session_copy_ptr ( const TSessionId &  session)

Definition at line 4643 of file DBHandler.cpp.

References get_session_it_unsafe(), and sessions_mutex_.

4644  {
4645  // Note(Wamsi): We have `get_const_session_ptr` which would return as const
4646  // SessionInfo stored in the map. You can use `get_const_session_ptr` instead of the
4647  // copy of SessionInfo but beware that it can be changed in teh map. So if you do not
4648  // care about the changes then use `get_const_session_ptr` if you do then use this
4649  // function to get a copy. We should eventually aim to merge both
4650  // `get_const_session_ptr` and `get_session_copy_ptr`.
4651  mapd_shared_lock<mapd_shared_mutex> read_lock(sessions_mutex_);
4652  auto& session_info_ref = *get_session_it_unsafe(session, read_lock)->second;
4653  return std::make_shared<Catalog_Namespace::SessionInfo>(session_info_ref);
4654 }
mapd_shared_mutex sessions_mutex_
Definition: DBHandler.h:541
SessionMap::iterator get_session_it_unsafe(const TSessionId &session, SESSION_MAP_LOCK &lock)
mapd_shared_lock< mapd_shared_mutex > read_lock
+ Here is the call graph for this function:

◆ get_session_info()

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

Definition at line 755 of file DBHandler.cpp.

References get_session_ptr(), getConnectionInfo(), STDLOG, and toString().

755  {
756  auto session_ptr = get_session_ptr(session);
757  auto stdlog = STDLOG(session_ptr);
758  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
759  auto user_metadata = session_ptr->get_currentUser();
760 
761  _return.user = user_metadata.userName;
762  _return.database = session_ptr->getCatalog().getCurrentDB().dbName;
763  _return.start_time = session_ptr->get_start_time();
764  _return.is_super = user_metadata.isSuper;
765 }
std::string toString(const ExtArgumentType &sig_type)
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1410
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:4656
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ get_session_it_unsafe() [1/3]

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

Definition at line 142 of file DBHandler.cpp.

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

144  {
145  auto session_it = get_session_from_map(session, sessions_);
146  try {
147  check_session_exp_unsafe(session_it);
148  } catch (const ForceDisconnect& e) {
149  read_lock.unlock();
150  mapd_unique_lock<mapd_shared_mutex> write_lock(sessions_mutex_);
151  auto session_it2 = get_session_from_map(session, sessions_);
152  disconnect_impl(session_it2, write_lock);
153  THROW_MAPD_EXCEPTION(e.what());
154  }
155  return session_it;
156 }
SessionMap::iterator get_session_from_map(const TSessionId &session, SessionMap &session_map)
Definition: DBHandler.cpp:126
mapd_shared_mutex sessions_mutex_
Definition: DBHandler.h:541
#define THROW_MAPD_EXCEPTION(errstr)
Definition: DBHandler.cpp:113
void check_session_exp_unsafe(const SessionMap::iterator &session_it)
Definition: DBHandler.cpp:4606
void disconnect_impl(const SessionMap::iterator &session_it, mapd_unique_lock< mapd_shared_mutex > &write_lock)
Definition: DBHandler.cpp:578
mapd_shared_lock< mapd_shared_mutex > read_lock
mapd_unique_lock< mapd_shared_mutex > write_lock
SessionMap sessions_
Definition: DBHandler.h:782
+ Here is the call graph for this function:

◆ get_session_it_unsafe() [2/3]

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

Definition at line 159 of file DBHandler.cpp.

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

161  {
162  auto session_it = get_session_from_map(session, sessions_);
163  try {
164  check_session_exp_unsafe(session_it);
165  } catch (const ForceDisconnect& e) {
166  disconnect_impl(session_it, write_lock);
167  THROW_MAPD_EXCEPTION(e.what());
168  }
169  return session_it;
170 }
SessionMap::iterator get_session_from_map(const TSessionId &session, SessionMap &session_map)
Definition: DBHandler.cpp:126
#define THROW_MAPD_EXCEPTION(errstr)
Definition: DBHandler.cpp:113
void check_session_exp_unsafe(const SessionMap::iterator &session_it)
Definition: DBHandler.cpp:4606
void disconnect_impl(const SessionMap::iterator &session_it, mapd_unique_lock< mapd_shared_mutex > &write_lock)
Definition: DBHandler.cpp:578
mapd_unique_lock< mapd_shared_mutex > write_lock
SessionMap sessions_
Definition: DBHandler.h:782
+ Here is the call graph for this function:

◆ get_session_it_unsafe() [3/3]

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

Referenced by clone_session(), 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 > DBHandler::get_session_ptr ( const TSessionId &  session_id)
private

Definition at line 4656 of file DBHandler.cpp.

References get_session_it_unsafe(), and sessions_mutex_.

Referenced by check_table_consistency(), checkpoint(), clear_cpu_memory(), clear_gpu_memory(), clone_session(), create_dashboard(), create_link(), deallocate_df(), delete_dashboards(), 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_table_epochs(), 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(), query_get_outer_fragment_count(), render_vega(), replace_dashboard(), set_execution_mode(), set_license_key(), set_table_epoch(), set_table_epoch_by_name(), set_table_epochs(), shareOrUnshareDashboards(), sql_execute(), sql_execute_df(), sql_execute_gdf(), sql_validate(), start_heap_profile(), start_query(), start_render_query(), stop_heap_profile(), and switch_database().

4657  {
4658  // Note(Wamsi): This method will give you a shared_ptr to master SessionInfo itself.
4659  // Should be used only when you need to make updates to original SessionInfo object.
4660  // Currently used by `update_session_last_used_duration`
4661 
4662  // 1) `session_id` will be empty during intial connect. 2)`sessionmapd iterator` will
4663  // be invalid during disconnect. SessionInfo will be erased from map by the time it
4664  // reaches here. In both the above cases, we would return `nullptr` and can skip
4665  // SessionInfo updates.
4666  if (session_id.empty()) {
4667  return {};
4668  }
4669  mapd_shared_lock<mapd_shared_mutex> read_lock(sessions_mutex_);
4670  return get_session_it_unsafe(session_id, read_lock)->second;
4671 }
mapd_shared_mutex sessions_mutex_
Definition: DBHandler.h:541
SessionMap::iterator get_session_it_unsafe(const TSessionId &session, SESSION_MAP_LOCK &lock)
mapd_shared_lock< mapd_shared_mutex > read_lock
+ Here is the call graph for this function:

◆ get_status()

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

Definition at line 685 of file DBHandler.cpp.

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

686  {
687  auto stdlog = STDLOG(get_session_ptr(session));
688  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
689  const auto rendering_enabled = bool(render_handler_);
690  TServerStatus ret;
691  ret.read_only = read_only_;
692  ret.version = MAPD_RELEASE;
693  ret.rendering_enabled = rendering_enabled;
694  ret.poly_rendering_enabled = rendering_enabled;
695  ret.start_time = start_time_;
696  ret.edition = MAPD_EDITION;
697  ret.host_name = omnisci::get_hostname();
698 
699  // TSercivePort tcp_port{}
700 
701  if (g_cluster) {
702  ret.role =
703  (leaf_aggregator_.leafCount() > 0) ? TRole::type::AGGREGATOR : TRole::type::LEAF;
704  } else {
705  ret.role = TRole::type::SERVER;
706  }
707 
708  _return.push_back(ret);
709  if (leaf_aggregator_.leafCount() > 0) {
710  std::vector<TServerStatus> leaf_status = leaf_aggregator_.getLeafStatus(session);
711  _return.insert(_return.end(), leaf_status.begin(), leaf_status.end());
712  }
713 }
std::string toString(const ExtArgumentType &sig_type)
static const std::string MAPD_EDITION
Definition: release.h:41
LeafAggregator leaf_aggregator_
Definition: DBHandler.h:528
int64_t start_time_
Definition: DBHandler.h:543
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1410
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:4656
std::unique_ptr< RenderHandler > render_handler_
Definition: DBHandler.h:546
const bool read_only_
Definition: DBHandler.h:538
bool g_cluster
size_t leafCount() const
std::string get_hostname()
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 DBHandler::get_table_details ( TTableDetails &  _return,
const TSessionId &  session,
const std::string &  table_name 
)
override

Definition at line 1947 of file DBHandler.cpp.

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

1949  {
1950  auto stdlog = STDLOG(get_session_ptr(session), "table_name", table_name);
1951  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
1952  get_table_details_impl(_return, stdlog, table_name, false, false);
1953 }
std::string toString(const ExtArgumentType &sig_type)
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1410
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:4656
#define STDLOG(...)
Definition: QueryState.h:225
void get_table_details_impl(TTableDetails &_return, query_state::StdLog &stdlog, const std::string &table_name, const bool get_system, const bool get_physical)
Definition: DBHandler.cpp:1955
+ Here is the call graph for this function:

◆ get_table_details_impl()

void DBHandler::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 1955 of file DBHandler.cpp.

References calcite_, cat(), CHECK, Data_Namespace::CPU_LEVEL, create_query_state(), fixup_row_descriptor(), query_state::StdLog::getSessionInfo(), hasTableAccessPrivileges(), parse_to_ra(), populateThriftColumnType(), run_benchmark_import::result, query_state::StdLog::setQueryState(), system_parameters_, table_is_replicated(), THROW_MAPD_EXCEPTION, and validate_rel_alg().

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

1959  {
1960  try {
1961  auto session_info = stdlog.getSessionInfo();
1962  auto& cat = session_info->getCatalog();
1963  const auto td_with_lock =
1965  cat, table_name, false);
1966  const auto td = td_with_lock();
1967  CHECK(td);
1968 
1969  bool have_privileges_on_view_sources = true;
1970  if (td->isView) {
1971  auto query_state = create_query_state(session_info, td->viewSQL);
1972  stdlog.setQueryState(query_state);