OmniSciDB  cecceef8da
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MapDHandler Class Reference

#include <MapDHandler.h>

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

Public Member Functions

 MapDHandler (const std::vector< LeafHostInfo > &db_leaves, const std::vector< LeafHostInfo > &string_leaves, const std::string &base_data_path, const bool cpu_only, const bool allow_multifrag, const bool jit_debug, const bool intel_jit_profile, const bool read_only, const bool allow_loop_joins, const bool enable_rendering, const bool enable_auto_clear_render_mem, const int render_oom_retry_threshold, const size_t render_mem_bytes, const size_t max_concurrent_render_sessions, const int num_gpus, const int start_gpu, const size_t reserved_gpu_mem, const size_t num_reader_threads, const AuthMetadata &authMetadata, const MapDParameters &mapd_parameters, const bool legacy_syntax, const int idle_session_duration, const int max_session_duration, const bool enable_runtime_udf_registration, const std::string &udf_filename, const std::string &clang_path, const std::vector< std::string > &clang_options)
 
 ~MapDHandler () override
 
void krb5_connect (TKrb5Session &session, const std::string &token, const std::string &dbname) override
 
void connect (TSessionId &session, const std::string &username, const std::string &passwd, const std::string &dbname) override
 
void disconnect (const TSessionId &session) override
 
void switch_database (const TSessionId &session, const std::string &dbname) override
 
void 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_session_info (TSessionInfo &_return, const TSessionId &session) override
 
void sql_execute (TQueryResult &_return, const TSessionId &session, const std::string &query, const bool column_format, const std::string &nonce, const int32_t first_n, const int32_t at_most_n) override
 
void get_completion_hints (std::vector< TCompletionHint > &hints, const TSessionId &session, const std::string &sql, const int cursor) override
 
void sql_execute_df (TDataFrame &_return, const TSessionId &session, const std::string &query, const TDeviceType::type device_type, const int32_t device_id, const int32_t first_n) override
 
void sql_execute_gdf (TDataFrame &_return, const TSessionId &session, const std::string &query, const int32_t device_id, const int32_t first_n) override
 
void deallocate_df (const TSessionId &session, const TDataFrame &df, const TDeviceType::type device_type, const int32_t device_id) override
 
void interrupt (const TSessionId &session) override
 
void sql_validate (TTableDescriptor &_return, const TSessionId &session, const std::string &query) override
 
void set_execution_mode (const TSessionId &session, const TExecuteMode::type mode) override
 
void render_vega (TRenderResult &_return, const TSessionId &session, const int64_t widget_id, const std::string &vega_json, const int32_t compression_level, const std::string &nonce) override
 
void get_result_row_for_pixel (TPixelTableRowResult &_return, const TSessionId &session, const int64_t widget_id, const TPixel &pixel, const std::map< std::string, std::vector< std::string >> &table_col_names, const bool column_format, const int32_t pixel_radius, const std::string &nonce) override
 
void get_dashboard (TDashboard &_return, const TSessionId &session, int32_t dashboard_id) override
 
void get_dashboards (std::vector< TDashboard > &_return, const TSessionId &session) override
 
int32_t create_dashboard (const TSessionId &session, const std::string &dashboard_name, const std::string &dashboard_state, const std::string &image_hash, const std::string &dashboard_metadata) override
 
void replace_dashboard (const TSessionId &session, const int32_t dashboard_id, const std::string &dashboard_name, const std::string &dashboard_owner, const std::string &dashboard_state, const std::string &image_hash, const std::string &dashboard_metadata) override
 
void delete_dashboard (const TSessionId &session, const int32_t dashboard_id) override
 
void share_dashboard (const TSessionId &session, const int32_t dashboard_id, const std::vector< std::string > &groups, const std::vector< std::string > &objects, const TDashboardPermissions &permissions, const bool grant_role) override
 
void unshare_dashboard (const TSessionId &session, const int32_t dashboard_id, const std::vector< std::string > &groups, const std::vector< std::string > &objects, const TDashboardPermissions &permissions) override
 
void get_dashboard_grantees (std::vector< TDashboardGrantees > &_return, const TSessionId &session, int32_t dashboard_id) override
 
void get_link_view (TFrontendView &_return, const TSessionId &session, const std::string &link) override
 
void create_link (std::string &_return, const TSessionId &session, const std::string &view_state, const std::string &view_metadata) override
 
void load_table_binary (const TSessionId &session, const std::string &table_name, const std::vector< TRow > &rows) override
 
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< Importer_NS::Loader > *loader, std::vector< std::unique_ptr< Importer_NS::TypedImportBuffer >> *import_buffers)
 
void load_table_binary_columnar (const TSessionId &session, const std::string &table_name, const std::vector< TColumn > &cols) override
 
void load_table_binary_arrow (const TSessionId &session, const std::string &table_name, const std::string &arrow_stream) override
 
void load_table (const TSessionId &session, const std::string &table_name, const std::vector< TStringRow > &rows) override
 
void detect_column_types (TDetectResult &_return, const TSessionId &session, const std::string &file_name, const TCopyParams &copy_params) override
 
void create_table (const TSessionId &session, const std::string &table_name, const TRowDescriptor &row_desc, const TFileType::type file_type, const TCreateParams &create_params) override
 
void import_table (const TSessionId &session, const std::string &table_name, const std::string &file_name, const TCopyParams &copy_params) override
 
void import_geo_table (const TSessionId &session, const std::string &table_name, const std::string &file_name, const TCopyParams &copy_params, const TRowDescriptor &row_desc, const TCreateParams &create_params) override
 
void import_table_status (TImportStatus &_return, const TSessionId &session, const std::string &import_id) override
 
void get_first_geo_file_in_archive (std::string &_return, const TSessionId &session, const std::string &archive_path, const TCopyParams &copy_params) override
 
void get_all_files_in_archive (std::vector< std::string > &_return, const TSessionId &session, const std::string &archive_path, const TCopyParams &copy_params) override
 
void get_layers_in_geo_file (std::vector< TGeoFileLayerInfo > &_return, const TSessionId &session, const std::string &file_name, const TCopyParams &copy_params) override
 
void check_table_consistency (TTableMeta &_return, const TSessionId &session, const int32_t table_id) override
 
void start_query (TPendingQuery &_return, const TSessionId &session, const std::string &query_ra, const bool just_explain) override
 
void execute_query_step (TStepResult &_return, const TPendingQuery &pending_query) override
 
void broadcast_serialized_rows (const TSerializedRows &serialized_rows, const TRowDescriptor &row_desc, const TQueryId query_id) override
 
void start_render_query (TPendingRenderQuery &_return, const TSessionId &session, const int64_t widget_id, const int16_t node_idx, const std::string &vega_json) override
 
void execute_next_render_step (TRenderStepResult &_return, const TPendingRenderQuery &pending_render, const TRenderAggDataMap &merged_data) override
 
void insert_data (const TSessionId &session, const TInsertData &insert_data) override
 
void checkpoint (const TSessionId &session, const int32_t db_id, const int32_t table_id) override
 
void get_roles (std::vector< std::string > &_return, const TSessionId &session) override
 
bool has_role (const TSessionId &sessionId, const std::string &granteeName, const std::string &roleName) override
 
bool has_object_privilege (const TSessionId &sessionId, const std::string &granteeName, const std::string &objectName, const TDBObjectType::type object_type, const TDBObjectPermissions &permissions) override
 
void get_db_objects_for_grantee (std::vector< TDBObject > &_return, const TSessionId &session, const std::string &roleName) override
 
void get_db_object_privs (std::vector< TDBObject > &_return, const TSessionId &session, const std::string &objectName, const TDBObjectType::type type) override
 
void get_all_roles_for_user (std::vector< std::string > &_return, const TSessionId &session, const std::string &granteeName) override
 
std::vector< std::string > get_valid_groups (const TSessionId &session, int32_t dashboard_id, std::vector< std::string > groups)
 
void set_license_key (TLicenseInfo &_return, const TSessionId &session, const std::string &key, const std::string &nonce) override
 
void get_license_claims (TLicenseInfo &_return, const TSessionId &session, const std::string &nonce) override
 
void get_device_parameters (std::map< std::string, std::string > &_return, const TSessionId &session) override
 
void register_runtime_extension_functions (const TSessionId &session, const std::vector< TUserDefinedFunction > &udfs, const std::vector< TUserDefinedTableFunction > &udtfs, const std::map< std::string, std::string > &device_ir_map) override
 
void shutdown ()
 
void emergency_shutdown ()
 
TSessionId getInvalidSessionId () const
 
void internal_connect (TSessionId &session, const std::string &username, const std::string &dbname)
 
template<typename... ARGS>
std::shared_ptr
< query_state::QueryState
create_query_state (ARGS &&...args)
 
Catalog_Namespace::SessionInfo get_session_copy (const TSessionId &session)
 
std::shared_ptr
< Catalog_Namespace::SessionInfo
get_session_copy_ptr (const TSessionId &session)
 
template<>
SessionMap::iterator get_session_it_unsafe (const TSessionId &session, mapd_shared_lock< mapd_shared_mutex > &read_lock)
 
template<>
SessionMap::iterator get_session_it_unsafe (const TSessionId &session, mapd_unique_lock< mapd_shared_mutex > &write_lock)
 

Static Public Member Functions

static size_t max_bytes_for_thrift ()
 

Public Attributes

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

Private Member Functions

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)
 
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)
 
std::shared_ptr< const
Catalog_Namespace::SessionInfo
get_const_session_ptr (const TSessionId &session)
 
std::shared_ptr
< Catalog_Namespace::SessionInfo
get_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::LockedTableDescriptors
parse_to_ra (QueryStateProxy, const std::string &query_str, const std::vector< TFilterPushDownInfo > &filter_push_down_info, const bool acquire_locks, const MapDParameters mapd_parameters, RenderInfo *render_info=nullptr, 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)
 
void validate_rel_alg (TTableDescriptor &_return, QueryStateProxy)
 
std::vector< PushedDownFilterInfoexecute_rel_alg (TQueryResult &_return, QueryStateProxy, const std::string &query_ra, const bool column_format, const ExecutorDeviceType executor_device_type, const int32_t first_n, const int32_t at_most_n, const bool just_validate, const bool find_push_down_candidates, const ExplainInfo &explain_info) const
 
void execute_rel_alg_with_filter_push_down (TQueryResult &_return, QueryStateProxy, std::string &query_ra, const bool column_format, const ExecutorDeviceType executor_device_type, const int32_t first_n, const int32_t at_most_n, const bool just_explain, const bool just_calcite_explain, const std::vector< PushedDownFilterInfo > filter_push_down_requests)
 
void execute_rel_alg_df (TDataFrame &_return, const std::string &query_ra, QueryStateProxy query_state_proxy, const Catalog_Namespace::SessionInfo &session_info, const ExecutorDeviceType device_type, const size_t device_id, const int32_t first_n) const
 
TColumnType populateThriftColumnType (const Catalog_Namespace::Catalog *cat, const ColumnDescriptor *cd)
 
TRowDescriptor fixup_row_descriptor (const TRowDescriptor &row_desc, const Catalog_Namespace::Catalog &cat)
 
void set_execution_mode_nolock (Catalog_Namespace::SessionInfo *session_ptr, const TExecuteMode::type mode)
 
char unescape_char (std::string str)
 
Importer_NS::CopyParams thrift_to_copyparams (const TCopyParams &cp)
 
TCopyParams copyparams_to_thrift (const Importer_NS::CopyParams &cp)
 
void check_geospatial_files (const boost::filesystem::path file_path, const Importer_NS::CopyParams &copy_params)
 
void render_rel_alg (TRenderResult &_return, const std::string &query_ra, const std::string &query_str, const Catalog_Namespace::SessionInfo &session_info, const std::string &render_type, const bool is_projection_query)
 
TColumnType create_geo_column (const TDatumType::type type, const std::string &name, const bool is_array)
 
void convert_explain (TQueryResult &_return, const ResultSet &results, const bool column_format) const
 
void convert_result (TQueryResult &_return, const ResultSet &results, const bool column_format) const
 
template<class R >
void convert_rows (TQueryResult &_return, QueryStateProxy query_state_proxy, const std::vector< TargetMetaInfo > &targets, const R &results, const bool column_format, const int32_t first_n, const int32_t at_most_n) const
 
void create_simple_result (TQueryResult &_return, const ResultSet &results, const bool column_format, const std::string label) const
 
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)
 

Static Private Member Functions

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

Private Attributes

query_state::QueryStates query_states_
 
SessionMap sessions_
 
bool super_user_rights_
 
const int idle_session_duration_
 
const int max_session_duration_
 
const bool runtime_udf_registration_enabled_
 
bool _was_geo_copy_from
 
std::string _geo_copy_from_table
 
std::string _geo_copy_from_file_name
 
Importer_NS::CopyParams _geo_copy_from_copy_params
 
std::string _geo_copy_from_partitions
 
std::mutex handle_to_dev_ptr_mutex_
 
std::unordered_map
< std::string, std::string > 
ipc_handle_to_dev_ptr_
 
std::map< const std::string,
const permissionFuncPtr
permissionFuncMap_
 

Friends

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

Detailed Description

Definition at line 162 of file MapDHandler.h.

Constructor & Destructor Documentation

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

Definition at line 171 of file MapDHandler.cpp.

198  : leaf_aggregator_(db_leaves)
199  , string_leaves_(string_leaves)
200  , base_data_path_(base_data_path)
201  , random_gen_(std::random_device{}())
202  , session_id_dist_(0, INT32_MAX)
203  , jit_debug_(jit_debug)
204  , intel_jit_profile_(intel_jit_profile)
205  , allow_multifrag_(allow_multifrag)
206  , read_only_(read_only)
207  , allow_loop_joins_(allow_loop_joins)
208  , authMetadata_(authMetadata)
209  , mapd_parameters_(mapd_parameters)
210  , legacy_syntax_(legacy_syntax)
211  , super_user_rights_(false)
212  , idle_session_duration_(idle_session_duration * 60)
213  , max_session_duration_(max_session_duration * 60)
214  , runtime_udf_registration_enabled_(enable_runtime_udf_registration)
215  , _was_geo_copy_from(false) {
216  LOG(INFO) << "OmniSci Server " << MAPD_RELEASE;
217  // Register foreign storage interfaces here
219  bool is_rendering_enabled = enable_rendering;
220 
221  try {
222  if (cpu_only) {
223  is_rendering_enabled = false;
225  cpu_mode_only_ = true;
226  } else {
227 #ifdef HAVE_CUDA
229  cpu_mode_only_ = false;
230 #else
232  LOG(ERROR) << "This build isn't CUDA enabled, will run on CPU";
233  cpu_mode_only_ = true;
234  is_rendering_enabled = false;
235 #endif
236  }
237  } catch (const std::exception& e) {
238  LOG(FATAL) << "Failed to executor device type: " << e.what();
239  }
240 
241  const auto data_path = boost::filesystem::path(base_data_path_) / "mapd_data";
242  // calculate the total amount of memory we need to reserve from each gpu that the Buffer
243  // manage cannot ask for
244  size_t total_reserved = reserved_gpu_mem;
245  if (is_rendering_enabled) {
246  total_reserved += render_mem_bytes;
247  }
248 
249  try {
250  data_mgr_.reset(new Data_Namespace::DataMgr(data_path.string(),
251  mapd_parameters,
253  num_gpus,
254  start_gpu,
255  total_reserved,
256  num_reader_threads));
257  } catch (const std::exception& e) {
258  LOG(FATAL) << "Failed to initialize data manager: " << e.what();
259  }
260 
261  std::string udf_ast_filename("");
262 
263  try {
264  if (!udf_filename.empty()) {
265  UdfCompiler compiler(udf_filename, clang_path, clang_options);
266  int compile_result = compiler.compileUdf();
267 
268  if (compile_result == 0) {
269  udf_ast_filename = compiler.getAstFileName();
270  }
271  }
272  } catch (const std::exception& e) {
273  LOG(FATAL) << "Failed to initialize UDF compiler: " << e.what();
274  }
275 
276  try {
277  calcite_ =
278  std::make_shared<Calcite>(mapd_parameters, base_data_path_, udf_ast_filename);
279  } catch (const std::exception& e) {
280  LOG(FATAL) << "Failed to initialize Calcite server: " << e.what();
281  }
282 
283  try {
284  ExtensionFunctionsWhitelist::add(calcite_->getExtensionFunctionWhitelist());
285  if (!udf_filename.empty()) {
286  ExtensionFunctionsWhitelist::addUdfs(calcite_->getUserDefinedFunctionWhitelist());
287  }
288  } catch (const std::exception& e) {
289  LOG(FATAL) << "Failed to initialize extension functions: " << e.what();
290  }
291 
292  try {
294  } catch (const std::exception& e) {
295  LOG(FATAL) << "Failed to initialize table functions factory: " << e.what();
296  }
297 
298  if (!data_mgr_->gpusPresent() && !cpu_mode_only_) {
300  LOG(ERROR) << "No GPUs detected, falling back to CPU mode";
301  cpu_mode_only_ = true;
302  }
303 
304  switch (executor_device_type_) {
306  LOG(INFO) << "Started in GPU mode" << std::endl;
307  break;
309  LOG(INFO) << "Started in CPU mode" << std::endl;
310  break;
311  }
312 
313  try {
314  SysCatalog::instance().init(base_data_path_,
315  data_mgr_,
316  authMetadata,
317  calcite_,
318  false,
319  !db_leaves.empty(),
321  } catch (const std::exception& e) {
322  LOG(FATAL) << "Failed to initialize system catalog: " << e.what();
323  }
324 
325  import_path_ = boost::filesystem::path(base_data_path_) / "mapd_import";
326  start_time_ = std::time(nullptr);
327 
328  if (is_rendering_enabled) {
329  try {
330  render_handler_.reset(new MapDRenderHandler(this,
331  render_mem_bytes,
332  max_concurrent_render_sessions,
333  0u,
334  false,
335  0,
337  } catch (const std::exception& e) {
338  LOG(ERROR) << "Backend rendering disabled: " << e.what();
339  }
340  }
341 
342  if (leaf_aggregator_.leafCount() > 0) {
343  try {
344  agg_handler_.reset(new MapDAggHandler(this));
345  } catch (const std::exception& e) {
346  LOG(ERROR) << "Distributed aggregator support disabled: " << e.what();
347  }
348  } else if (g_cluster) {
349  try {
350  leaf_handler_.reset(new MapDLeafHandler(this));
351  } catch (const std::exception& e) {
352  LOG(ERROR) << "Distributed leaf support disabled: " << e.what();
353  }
354  }
355 }
const bool allow_loop_joins_
Definition: MapDHandler.h:507
static void addUdfs(const std::string &json_func_sigs)
std::unique_ptr< MapDRenderHandler > render_handler_
Definition: MapDHandler.h:514
boost::filesystem::path import_path_
Definition: MapDHandler.h:499
#define LOG(tag)
Definition: Logger.h:188
static void add(const std::string &json_func_sigs)
friend class MapDAggHandler
Definition: MapDHandler.h:754
std::unique_ptr< MapDAggHandler > agg_handler_
Definition: MapDHandler.h:515
bool cpu_mode_only_
Definition: MapDHandler.h:508
const bool runtime_udf_registration_enabled_
Definition: MapDHandler.h:737
const bool intel_jit_profile_
Definition: MapDHandler.h:504
int64_t start_time_
Definition: MapDHandler.h:511
const int idle_session_duration_
Definition: MapDHandler.h:734
const MapDParameters & mapd_parameters_
Definition: MapDHandler.h:513
bool allow_multifrag_
Definition: MapDHandler.h:505
const bool read_only_
Definition: MapDHandler.h:506
const std::vector< LeafHostInfo > string_leaves_
Definition: MapDHandler.h:497
void registerArrowCsvForeignStorage(void)
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:496
size_t leafCount() const
std::shared_ptr< Calcite > calcite_
Definition: MapDHandler.h:517
bool _was_geo_copy_from
Definition: MapDHandler.h:739
std::shared_ptr< Data_Namespace::DataMgr > data_mgr_
Definition: MapDHandler.h:494
ExecutorDeviceType executor_device_type_
Definition: MapDHandler.h:500
std::uniform_int_distribution< int64_t > session_id_dist_
Definition: MapDHandler.h:502
friend class MapDLeafHandler
Definition: MapDHandler.h:755
const AuthMetadata & authMetadata_
Definition: MapDHandler.h:512
bool g_cluster
std::unique_ptr< MapDLeafHandler > leaf_handler_
Definition: MapDHandler.h:516
static const std::string MAPD_RELEASE
Definition: release.h:43
const int max_session_duration_
Definition: MapDHandler.h:735
const bool jit_debug_
Definition: MapDHandler.h:503
bool super_user_rights_
Definition: MapDHandler.h:731
std::default_random_engine random_gen_
Definition: MapDHandler.h:501
const bool legacy_syntax_
Definition: MapDHandler.h:518
const std::string base_data_path_
Definition: MapDHandler.h:498
MapDHandler::~MapDHandler ( )
override

Definition at line 357 of file MapDHandler.cpp.

357 {}

Member Function Documentation

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

Definition at line 1119 of file MapDHandler.cpp.

References apply_shim(), and run_benchmark_import::result.

Referenced by sql_execute_impl().

1119  {
1120  auto result = query_str;
1121  {
1122  // boost::regex copy_to{R"(COPY\s\((.*)\)\sTO\s(.*))", boost::regex::extended |
1123  // boost::regex::icase};
1124  boost::regex copy_to{R"(COPY\s*\(([^#])(.+)\)\s+TO\s)",
1125  boost::regex::extended | boost::regex::icase};
1126  apply_shim(result, copy_to, [](std::string& result, const boost::smatch& what) {
1127  result.replace(
1128  what.position(), what.length(), "COPY (#~#" + what[1] + what[2] + "#~#) TO ");
1129  });
1130  }
1131  return result;
1132 }
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:

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

Definition at line 5498 of file MapDHandler.cpp.

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

5500  {
5501  if (!leaf_handler_) {
5502  THROW_MAPD_EXCEPTION("Distributed support is disabled.");
5503  }
5504  LOG(INFO) << "BROADCAST-SERIALIZED-ROWS id:" << query_id;
5505  auto time_ms = measure<>::execution([&]() {
5506  try {
5507  leaf_handler_->broadcast_serialized_rows(serialized_rows, row_desc, query_id);
5508  } catch (std::exception& e) {
5509  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
5510  }
5511  });
5512  LOG(INFO) << "BROADCAST-SERIALIZED-ROWS COMPLETED " << time_ms << "ms";
5513 }
static TimeT::rep execution(F func, Args &&...args)
Definition: sample.cpp:29
#define LOG(tag)
Definition: Logger.h:188
#define THROW_MAPD_EXCEPTION(errstr)
std::unique_ptr< MapDLeafHandler > leaf_handler_
Definition: MapDHandler.h:516

+ Here is the call graph for this function:

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

Definition at line 4956 of file MapDHandler.cpp.

References invalidate_sessions().

Referenced by sql_execute_impl().

4956  {
4957  const auto drop_db_stmt = dynamic_cast<Parser::DropDBStmt*>(ddl);
4958  if (drop_db_stmt) {
4959  invalidate_sessions(*drop_db_stmt->getDatabaseName(), drop_db_stmt);
4960  return;
4961  }
4962  const auto rename_db_stmt = dynamic_cast<Parser::RenameDatabaseStmt*>(ddl);
4963  if (rename_db_stmt) {
4964  invalidate_sessions(*rename_db_stmt->getPreviousDatabaseName(), rename_db_stmt);
4965  return;
4966  }
4967  const auto drop_user_stmt = dynamic_cast<Parser::DropUserStmt*>(ddl);
4968  if (drop_user_stmt) {
4969  invalidate_sessions(*drop_user_stmt->getUserName(), drop_user_stmt);
4970  return;
4971  }
4972  const auto rename_user_stmt = dynamic_cast<Parser::RenameUserStmt*>(ddl);
4973  if (rename_user_stmt) {
4974  invalidate_sessions(*rename_user_stmt->getOldUserName(), rename_user_stmt);
4975  return;
4976  }
4977 }
void invalidate_sessions(std::string &name, STMT_TYPE *stmt)
Definition: MapDHandler.h:766

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 3645 of file MapDHandler.cpp.

References Importer_NS::Importer::gdalFileExists().

Referenced by detect_column_types(), and import_geo_table().

3646  {
3647  const std::list<std::string> shp_ext{".shp", ".shx", ".dbf"};
3648  if (std::find(shp_ext.begin(),
3649  shp_ext.end(),
3650  boost::algorithm::to_lower_copy(file_path.extension().string())) !=
3651  shp_ext.end()) {
3652  for (auto ext : shp_ext) {
3653  auto aux_file = file_path;
3655  aux_file.replace_extension(boost::algorithm::to_upper_copy(ext)).string(),
3656  copy_params) &&
3657  !Importer_NS::Importer::gdalFileExists(aux_file.replace_extension(ext).string(),
3658  copy_params)) {
3659  throw std::runtime_error("required file for shapefile does not exist: " +
3660  aux_file.filename().string());
3661  }
3662  }
3663  }
3664 }
static bool gdalFileExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:4521

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 359 of file MapDHandler.cpp.

References read_only_, and THROW_MAPD_EXCEPTION.

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

359  {
361  THROW_MAPD_EXCEPTION(str + " disabled: server running in read-only mode.");
362  }
363 }
#define THROW_MAPD_EXCEPTION(errstr)
const bool read_only_
Definition: MapDHandler.h:506

+ Here is the caller graph for this function:

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

Definition at line 4507 of file MapDHandler.cpp.

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

Referenced by get_session_it_unsafe().

4507  {
4508  if (session_it->second.use_count() > 2 ||
4509  isInMemoryCalciteSession(session_it->second->get_currentUser())) {
4510  // SessionInfo is being used in more than one active operation. Original copy + one
4511  // stored in StdLog. Skip the checks.
4512  return;
4513  }
4514  time_t last_used_time = session_it->second->get_last_used_time();
4515  time_t start_time = session_it->second->get_start_time();
4516  if ((time(0) - last_used_time) > idle_session_duration_) {
4517  throw ForceDisconnect("Idle Session Timeout. User should re-authenticate.");
4518  } else if ((time(0) - start_time) > max_session_duration_) {
4519  throw ForceDisconnect("Maximum active Session Timeout. User should re-authenticate.");
4520  }
4521 }
bool isInMemoryCalciteSession(const Catalog_Namespace::UserMetadata user_meta)
const int idle_session_duration_
Definition: MapDHandler.h:734
const int max_session_duration_
Definition: MapDHandler.h:735

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 5447 of file MapDHandler.cpp.

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

5449  {
5450  auto stdlog = STDLOG(get_session_ptr(session));
5451  if (!leaf_handler_) {
5452  THROW_MAPD_EXCEPTION("Distributed support is disabled.");
5453  }
5454  try {
5455  leaf_handler_->check_table_consistency(_return, session, table_id);
5456  } catch (std::exception& e) {
5457  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
5458  }
5459 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
#define THROW_MAPD_EXCEPTION(errstr)
std::unique_ptr< MapDLeafHandler > leaf_handler_
Definition: MapDHandler.h:516
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 4580 of file MapDHandler.cpp.

References get_session_copy().

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

4581  {
4582  const auto session_info = get_session_copy(session);
4583  check_table_load_privileges(session_info, table_name);
4584 }
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
void check_table_load_privileges(const TSessionId &session, const std::string &table_name)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 4563 of file MapDHandler.cpp.

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

4565  {
4566  auto user_metadata = session_info.get_currentUser();
4567  auto& cat = session_info.getCatalog();
4568  DBObject dbObject(table_name, TableDBObjectType);
4569  dbObject.loadKey(cat);
4570  dbObject.setPrivileges(AccessPrivileges::INSERT_INTO_TABLE);
4571  std::vector<DBObject> privObjects;
4572  privObjects.push_back(dbObject);
4573  if (!SysCatalog::instance().checkPrivileges(user_metadata, privObjects)) {
4574  THROW_MAPD_EXCEPTION("Violation of access privileges: user " +
4575  user_metadata.userName + " has no insert privileges for table " +
4576  table_name + ".");
4577  }
4578 }
static const AccessPrivileges INSERT_INTO_TABLE
Definition: DBObject.h:161
#define THROW_MAPD_EXCEPTION(errstr)
Catalog & getCatalog() const
Definition: SessionInfo.h:76
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:79

+ Here is the call graph for this function:

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

Definition at line 5647 of file MapDHandler.cpp.

References get_session_ptr(), and STDLOG.

5649  {
5650  auto stdlog = STDLOG(get_session_ptr(session));
5651  auto session_ptr = stdlog.getConstSessionInfo();
5652  auto& cat = session_ptr->getCatalog();
5653  cat.getDataMgr().checkpoint(db_id, table_id);
5654 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 2198 of file MapDHandler.cpp.

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

2198  {
2199  auto stdlog = STDLOG(get_session_ptr(session));
2200  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
2201  auto session_ptr = stdlog.getConstSessionInfo();
2202  if (!session_ptr->get_currentUser().isSuper) {
2203  THROW_MAPD_EXCEPTION("Superuser privilege is required to run clear_cpu_memory");
2204  }
2205  try {
2207  } catch (const std::exception& e) {
2208  THROW_MAPD_EXCEPTION(e.what());
2209  }
2210  if (render_handler_) {
2211  render_handler_->clear_cpu_memory();
2212  }
2213 
2214  if (leaf_aggregator_.leafCount() > 0) {
2216  }
2217 }
std::unique_ptr< MapDRenderHandler > render_handler_
Definition: MapDHandler.h:514
ConnectionInfo getConnectionInfo() const
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
static void clearMemory(const Data_Namespace::MemoryLevel memory_level)
Definition: Execute.cpp:157
#define THROW_MAPD_EXCEPTION(errstr)
void clear_leaf_cpu_memory(const TSessionId session)
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:496
size_t leafCount() const
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 2177 of file MapDHandler.cpp.

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

2177  {
2178  auto stdlog = STDLOG(get_session_ptr(session));
2179  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
2180  auto session_ptr = stdlog.getConstSessionInfo();
2181  if (!session_ptr->get_currentUser().isSuper) {
2182  THROW_MAPD_EXCEPTION("Superuser privilege is required to run clear_gpu_memory");
2183  }
2184  try {
2186  } catch (const std::exception& e) {
2187  THROW_MAPD_EXCEPTION(e.what());
2188  }
2189  if (render_handler_) {
2190  render_handler_->clear_gpu_memory();
2191  }
2192 
2193  if (leaf_aggregator_.leafCount() > 0) {
2195  }
2196 }
std::unique_ptr< MapDRenderHandler > render_handler_
Definition: MapDHandler.h:514
ConnectionInfo getConnectionInfo() const
void clear_leaf_gpu_memory(const TSessionId session)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
static void clearMemory(const Data_Namespace::MemoryLevel memory_level)
Definition: Execute.cpp:157
#define THROW_MAPD_EXCEPTION(errstr)
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:496
size_t leafCount() const
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 566 of file MapDHandler.cpp.

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

566  {
567  auto stdlog = STDLOG(get_session_ptr(session1));
568  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
569  mapd_unique_lock<mapd_shared_mutex> write_lock(sessions_mutex_);
570  auto session_it = get_session_it_unsafe(session1, write_lock);
571 
572  try {
573  const Catalog_Namespace::UserMetadata& user_meta =
574  session_it->second->get_currentUser();
575  std::shared_ptr<Catalog> cat = session_it->second->get_catalog_ptr();
576  auto session2_ptr = create_new_session(session2, cat->name(), user_meta, cat);
577  if (leaf_aggregator_.leafCount() > 0) {
578  leaf_aggregator_.clone_session(session1, session2);
579  return;
580  }
581  } catch (std::exception& e) {
582  THROW_MAPD_EXCEPTION(e.what());
583  }
584 }
void clone_session(const TSessionId session1, const TSessionId session2)
ConnectionInfo getConnectionInfo() const
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
SessionMap::iterator get_session_it_unsafe(const TSessionId &session, SESSION_MAP_LOCK &lock)
mapd_shared_mutex sessions_mutex_
Definition: MapDHandler.h:509
#define THROW_MAPD_EXCEPTION(errstr)
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:496
size_t leafCount() const
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)
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 441 of file MapDHandler.cpp.

References AccessPrivileges::ACCESS, connect_impl(), DatabaseDBObjectType, getConnectionInfo(), DBObject::loadKey(), sessions_mutex_, DBObject::setPrivileges(), STDLOG, super_user_rights_, and THROW_MAPD_EXCEPTION.

444  {
445  auto stdlog = STDLOG(); // session_info set by connect_impl()
446  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
447  mapd_lock_guard<mapd_shared_mutex> write_lock(sessions_mutex_);
448  std::string username2 = username; // login() may reset username given as argument
449  std::string dbname2 = dbname; // login() may reset dbname given as argument
451  std::shared_ptr<Catalog> cat = nullptr;
452  try {
453  cat = SysCatalog::instance().login(
454  dbname2, username2, passwd, user_meta, !super_user_rights_);
455  } catch (std::exception& e) {
456  stdlog.appendNameValuePairs("user", username, "db", dbname, "exception", e.what());
457  THROW_MAPD_EXCEPTION(e.what());
458  }
459 
460  DBObject dbObject(dbname2, DatabaseDBObjectType);
461  dbObject.loadKey(*cat);
462  dbObject.setPrivileges(AccessPrivileges::ACCESS);
463  std::vector<DBObject> dbObjects;
464  dbObjects.push_back(dbObject);
465  if (!SysCatalog::instance().checkPrivileges(user_meta, dbObjects)) {
466  stdlog.appendNameValuePairs(
467  "user", username, "db", dbname, "exception", "Missing Privileges");
468  THROW_MAPD_EXCEPTION("Unauthorized Access: user " + username +
469  " is not allowed to access database " + dbname2 + ".");
470  }
471  connect_impl(session, passwd, dbname2, user_meta, cat, stdlog);
472  // if pki auth session will come back encrypted with user pubkey
473  SysCatalog::instance().check_for_session_encryption(passwd, session);
474 }
ConnectionInfo getConnectionInfo() const
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)
mapd_shared_mutex sessions_mutex_
Definition: MapDHandler.h:509
#define THROW_MAPD_EXCEPTION(errstr)
static const AccessPrivileges ACCESS
Definition: DBObject.h:153
#define STDLOG(...)
Definition: QueryState.h:225
bool super_user_rights_
Definition: MapDHandler.h:731

+ Here is the call graph for this function:

void MapDHandler::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 495 of file MapDHandler.cpp.

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

Referenced by connect(), and internal_connect().

500  {
501  // TODO(sy): Is there any reason to have dbname as a parameter
502  // here when the cat parameter already provides cat->name()?
503  // Should dbname and cat->name() ever differ?
504  auto session_ptr = create_new_session(session, dbname, user_meta, cat);
505  stdlog.setSessionInfo(session_ptr);
506  if (!super_user_rights_) { // no need to connect to leaf_aggregator_ at this time while
507  // doing warmup
508  if (leaf_aggregator_.leafCount() > 0) {
509  leaf_aggregator_.connect(*session_ptr, user_meta.userName, passwd, dbname);
510  return;
511  }
512  }
513  auto const roles = session_ptr->get_currentUser().isSuper
514  ? std::vector<std::string>{{"super"}}
515  : SysCatalog::instance().getRoles(
516  false, false, session_ptr->get_currentUser().userName);
517  stdlog.appendNameValuePairs("roles", boost::algorithm::join(roles, ","));
518 }
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:238
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:496
size_t leafCount() const
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)
void appendNameValuePairs(Pairs &&...pairs)
Definition: QueryState.h:303
bool super_user_rights_
Definition: MapDHandler.h:731

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 4928 of file MapDHandler.cpp.

References create_simple_result().

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

4930  {
4931  create_simple_result(_return, results, column_format, "Explanation");
4932 }
void create_simple_result(TQueryResult &_return, const ResultSet &results, const bool column_format, const std::string label) const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 4934 of file MapDHandler.cpp.

References create_simple_result().

Referenced by sql_execute_impl().

4936  {
4937  create_simple_result(_return, results, column_format, "Result");
4938 }
void create_simple_result(TQueryResult &_return, const ResultSet &results, const bool column_format, const std::string label) const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 4821 of file MapDHandler.cpp.

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

Referenced by execute_rel_alg().

4827  {
4828  query_state::Timer timer = query_state_proxy.createTimer(__func__);
4829  _return.row_set.row_desc = convert_target_metainfo(targets);
4830  int32_t fetched{0};
4831  if (column_format) {
4832  _return.row_set.is_columnar = true;
4833  std::vector<TColumn> tcolumns(results.colCount());
4834  while (first_n == -1 || fetched < first_n) {
4835  const auto crt_row = results.getNextRow(true, true);
4836  if (crt_row.empty()) {
4837  break;
4838  }
4839  ++fetched;
4840  if (at_most_n >= 0 && fetched > at_most_n) {
4841  THROW_MAPD_EXCEPTION("The result contains more rows than the specified cap of " +
4842  std::to_string(at_most_n));
4843  }
4844  for (size_t i = 0; i < results.colCount(); ++i) {
4845  const auto agg_result = crt_row[i];
4846  value_to_thrift_column(agg_result, targets[i].get_type_info(), tcolumns[i]);
4847  }
4848  }
4849  for (size_t i = 0; i < results.colCount(); ++i) {
4850  _return.row_set.columns.push_back(tcolumns[i]);
4851  }
4852  } else {
4853  _return.row_set.is_columnar = false;
4854  while (first_n == -1 || fetched < first_n) {
4855  const auto crt_row = results.getNextRow(true, true);
4856  if (crt_row.empty()) {
4857  break;
4858  }
4859  ++fetched;
4860  if (at_most_n >= 0 && fetched > at_most_n) {
4861  THROW_MAPD_EXCEPTION("The result contains more rows than the specified cap of " +
4862  std::to_string(at_most_n));
4863  }
4864  TRow trow;
4865  trow.cols.reserve(results.colCount());
4866  for (size_t i = 0; i < results.colCount(); ++i) {
4867  const auto agg_result = crt_row[i];
4868  trow.cols.push_back(value_to_thrift(agg_result, targets[i].get_type_info()));
4869  }
4870  _return.row_set.rows.push_back(trow);
4871  }
4872  }
4873 }
static TDatum value_to_thrift(const TargetValue &tv, const SQLTypeInfo &ti)
TColumnType convert_target_metainfo(const TargetMetaInfo &target, const size_t idx) const
Timer createTimer(char const *event_name)
Definition: QueryState.cpp:113
std::string to_string(char const *&&v)
#define THROW_MAPD_EXCEPTION(errstr)
static void value_to_thrift_column(const TargetValue &tv, const SQLTypeInfo &ti, TColumn &column)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 4780 of file MapDHandler.cpp.

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

Referenced by convert_rows(), and convert_target_metainfo().

4781  {
4782  TColumnType proj_info;
4783  proj_info.col_name = target.get_resname();
4784  if (proj_info.col_name.empty()) {
4785  proj_info.col_name = "result_" + std::to_string(idx + 1);
4786  }
4787  const auto& target_ti = target.get_type_info();
4788  proj_info.col_type.type = type_to_thrift(target_ti);
4789  proj_info.col_type.encoding = encoding_to_thrift(target_ti);
4790  proj_info.col_type.nullable = !target_ti.get_notnull();
4791  proj_info.col_type.is_array = target_ti.get_type() == kARRAY;
4792  if (IS_GEO(target_ti.get_type())) {
4794  proj_info, target_ti.get_subtype(), target_ti.get_output_srid());
4795  } else {
4796  proj_info.col_type.precision = target_ti.get_precision();
4797  proj_info.col_type.scale = target_ti.get_scale();
4798  }
4799  if (target_ti.get_type() == kDATE) {
4800  proj_info.col_type.size = target_ti.get_size();
4801  }
4802  proj_info.col_type.comp_param =
4803  (target_ti.is_date_in_days() && target_ti.get_comp_param() == 0)
4804  ? 32
4805  : target_ti.get_comp_param();
4806  return proj_info;
4807 }
TDatumType::type type_to_thrift(const SQLTypeInfo &type_info)
const SQLTypeInfo & get_type_info() const
std::string to_string(char const *&&v)
void fixup_geo_column_descriptor(TColumnType &col_type, const SQLTypes subtype, const int output_srid)
Definition: sqltypes.h:54
const std::string & get_resname() const
SQLTypes type
Definition: sqltypes.h:682
#define IS_GEO(T)
Definition: sqltypes.h:165
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:

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

Definition at line 4809 of file MapDHandler.cpp.

References convert_target_metainfo().

4810  {
4811  TRowDescriptor row_desc;
4812  size_t i = 0;
4813  for (const auto target : targets) {
4814  row_desc.push_back(convert_target_metainfo(target, i));
4815  ++i;
4816  }
4817  return row_desc;
4818 }
TColumnType convert_target_metainfo(const TargetMetaInfo &target, const size_t idx) const

+ Here is the call graph for this function:

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

Definition at line 2854 of file MapDHandler.cpp.

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

Referenced by detect_column_types(), and sql_execute().

2854  {
2855  TCopyParams copy_params;
2856  copy_params.delimiter = cp.delimiter;
2857  copy_params.null_str = cp.null_str;
2858  switch (cp.has_header) {
2860  copy_params.has_header = TImportHeaderRow::AUTODETECT;
2861  break;
2863  copy_params.has_header = TImportHeaderRow::NO_HEADER;
2864  break;
2866  copy_params.has_header = TImportHeaderRow::HAS_HEADER;
2867  break;
2868  default:
2869  CHECK(false);
2870  break;
2871  }
2872  copy_params.quoted = cp.quoted;
2873  copy_params.quote = cp.quote;
2874  copy_params.escape = cp.escape;
2875  copy_params.line_delim = cp.line_delim;
2876  copy_params.array_delim = cp.array_delim;
2877  copy_params.array_begin = cp.array_begin;
2878  copy_params.array_end = cp.array_end;
2879  copy_params.threads = cp.threads;
2880  copy_params.s3_access_key = cp.s3_access_key;
2881  copy_params.s3_secret_key = cp.s3_secret_key;
2882  copy_params.s3_region = cp.s3_region;
2883  copy_params.s3_endpoint = cp.s3_endpoint;
2884  switch (cp.file_type) {
2886  copy_params.file_type = TFileType::POLYGON;
2887  break;
2888  default:
2889  copy_params.file_type = TFileType::DELIMITED;
2890  break;
2891  }
2892  switch (cp.geo_coords_encoding) {
2893  case kENCODING_GEOINT:
2894  copy_params.geo_coords_encoding = TEncodingType::GEOINT;
2895  break;
2896  default:
2897  copy_params.geo_coords_encoding = TEncodingType::NONE;
2898  break;
2899  }
2900  copy_params.geo_coords_comp_param = cp.geo_coords_comp_param;
2901  switch (cp.geo_coords_type) {
2902  case kGEOGRAPHY:
2903  copy_params.geo_coords_type = TDatumType::GEOGRAPHY;
2904  break;
2905  case kGEOMETRY:
2906  copy_params.geo_coords_type = TDatumType::GEOMETRY;
2907  break;
2908  default:
2909  CHECK(false);
2910  break;
2911  }
2912  copy_params.geo_coords_srid = cp.geo_coords_srid;
2913  copy_params.sanitize_column_names = cp.sanitize_column_names;
2914  copy_params.geo_layer_name = cp.geo_layer_name;
2915  copy_params.geo_assign_render_groups = cp.geo_assign_render_groups;
2916  copy_params.geo_explode_collections = cp.geo_explode_collections;
2917  return copy_params;
2918 }
std::string null_str
Definition: CopyParams.h:47
EncodingType geo_coords_encoding
Definition: CopyParams.h:73
CHECK(cgen_state)
std::string s3_access_key
Definition: CopyParams.h:62
ImportHeaderRow has_header
Definition: CopyParams.h:48
std::string s3_endpoint
Definition: CopyParams.h:65
std::string s3_region
Definition: CopyParams.h:64
std::string geo_layer_name
Definition: CopyParams.h:78
std::string s3_secret_key
Definition: CopyParams.h:63
int32_t geo_coords_comp_param
Definition: CopyParams.h:74

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 3342 of file MapDHandler.cpp.

References 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(), DashboardDescriptor::user, and DashboardDescriptor::userId.

3346  {
3347  auto stdlog = STDLOG(get_session_ptr(session));
3348  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
3349  auto session_ptr = stdlog.getConstSessionInfo();
3350  check_read_only("create_dashboard");
3351  auto& cat = session_ptr->getCatalog();
3352 
3353  if (!session_ptr->checkDBAccessPrivileges(DBObjectType::DashboardDBObjectType,
3355  THROW_MAPD_EXCEPTION("Not enough privileges to create a dashboard.");
3356  }
3357 
3358  auto dash = cat.getMetadataForDashboard(
3359  std::to_string(session_ptr->get_currentUser().userId), dashboard_name);
3360  if (dash) {
3361  THROW_MAPD_EXCEPTION("Dashboard with name: " + dashboard_name + " already exists.");
3362  }
3363 
3365  dd.dashboardName = dashboard_name;
3366  dd.dashboardState = dashboard_state;
3367  dd.imageHash = image_hash;
3368  dd.dashboardMetadata = dashboard_metadata;
3369  dd.userId = session_ptr->get_currentUser().userId;
3370  dd.user = session_ptr->get_currentUser().userName;
3371 
3372  try {
3373  auto id = cat.createDashboard(dd);
3374  // TODO: transactionally unsafe
3375  SysCatalog::instance().createDBObject(
3376  session_ptr->get_currentUser(), dashboard_name, DashboardDBObjectType, cat, id);
3377  return id;
3378  } catch (const std::exception& e) {
3379  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
3380  }
3381 }
ConnectionInfo getConnectionInfo() const
static const AccessPrivileges CREATE_DASHBOARD
Definition: DBObject.h:170
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
std::string to_string(char const *&&v)
#define THROW_MAPD_EXCEPTION(errstr)
void check_read_only(const std::string &str)
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 3635 of file MapDHandler.cpp.

References run_benchmark_import::type.

3637  {
3638  TColumnType ct;
3639  ct.col_name = name;
3640  ct.col_type.type = type;
3641  ct.col_type.is_array = is_array;
3642  return ct;
3643 }
void MapDHandler::create_link ( std::string &  _return,
const TSessionId &  session,
const std::string &  view_state,
const std::string &  view_metadata 
)
override

Definition at line 3613 of file MapDHandler.cpp.

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

3616  {
3617  auto stdlog = STDLOG(get_session_ptr(session));
3618  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
3619  auto session_ptr = stdlog.getConstSessionInfo();
3620  // check_read_only("create_link");
3621  auto& cat = session_ptr->getCatalog();
3622 
3623  LinkDescriptor ld;
3624  ld.userId = session_ptr->get_currentUser().userId;
3625  ld.viewState = view_state;
3626  ld.viewMetadata = view_metadata;
3627 
3628  try {
3629  _return = cat.createLink(ld, 6);
3630  } catch (const std::exception& e) {
3631  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
3632  }
3633 }
ConnectionInfo getConnectionInfo() const
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
#define THROW_MAPD_EXCEPTION(errstr)
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

std::shared_ptr< Catalog_Namespace::SessionInfo > MapDHandler::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 476 of file MapDHandler.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().

480  {
481  do {
482  session = generate_random_string(32);
483  } while (sessions_.find(session) != sessions_.end());
484  std::pair<SessionMap::iterator, bool> emplace_retval =
485  sessions_.emplace(session,
486  std::make_shared<Catalog_Namespace::SessionInfo>(
487  cat, user_meta, executor_device_type_, session));
488  CHECK(emplace_retval.second);
489  auto& session_ptr = emplace_retval.first->second;
490  LOG(INFO) << "User " << user_meta.userName << " connected to database " << dbname
491  << " with public_session_id " << session_ptr->get_public_session_id();
492  return session_ptr;
493 }
SessionMap sessions_
Definition: MapDHandler.h:729
#define LOG(tag)
Definition: Logger.h:188
CHECK(cgen_state)
std::string generate_random_string(const size_t len)
ExecutorDeviceType executor_device_type_
Definition: MapDHandler.h:500

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 521 of file MapDHandler.h.

References run_benchmark_import::args.

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

521  {
522  return query_states_.create(std::forward<ARGS>(args)...);
523  }
CircleBuffer::value_type create(ARGS &&...args)
Definition: QueryState.h:185
query_state::QueryStates query_states_
Definition: MapDHandler.h:728

+ Here is the caller graph for this function:

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

Definition at line 4891 of file MapDHandler.cpp.

References CHECK(), CHECK_EQ, and run_benchmark_import::label.

Referenced by convert_explain(), and convert_result().

4894  {
4895  CHECK_EQ(size_t(1), results.rowCount());
4896  TColumnType proj_info;
4897  proj_info.col_name = label;
4898  proj_info.col_type.type = TDatumType::STR;
4899  proj_info.col_type.nullable = false;
4900  proj_info.col_type.is_array = false;
4901  _return.row_set.row_desc.push_back(proj_info);
4902  const auto crt_row = results.getNextRow(true, true);
4903  const auto tv = crt_row[0];
4904  CHECK(results.getNextRow(true, true).empty());
4905  const auto scalar_tv = boost::get<ScalarTargetValue>(&tv);
4906  CHECK(scalar_tv);
4907  const auto s_n = boost::get<NullableString>(scalar_tv);
4908  CHECK(s_n);
4909  const auto s = boost::get<std::string>(s_n);
4910  CHECK(s);
4911  if (column_format) {
4912  TColumn tcol;
4913  tcol.data.str_col.push_back(*s);
4914  tcol.nulls.push_back(false);
4915  _return.row_set.is_columnar = true;
4916  _return.row_set.columns.push_back(tcol);
4917  } else {
4918  TDatum explanation;
4919  explanation.val.str_val = *s;
4920  explanation.is_null = false;
4921  TRow trow;
4922  trow.cols.push_back(explanation);
4923  _return.row_set.is_columnar = false;
4924  _return.row_set.rows.push_back(trow);
4925  }
4926 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
CHECK(cgen_state)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 3666 of file MapDHandler.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, and to_string().

Referenced by import_geo_table().

3670  {
3671  auto stdlog = STDLOG("table_name", table_name);
3672  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
3673  check_read_only("create_table");
3674 
3675  if (ImportHelpers::is_reserved_name(table_name)) {
3676  THROW_MAPD_EXCEPTION("Invalid table name (reserved keyword): " + table_name);
3677  } else if (table_name != ImportHelpers::sanitize_name(table_name)) {
3678  THROW_MAPD_EXCEPTION("Invalid characters in table name: " + table_name);
3679  }
3680 
3681  auto rds = rd;
3682 
3683  // no longer need to manually add the poly column for a TFileType::POLYGON table
3684  // a column of the correct geo type has already been added
3685  // @TODO simon.eves rename TFileType::POLYGON to TFileType::GEO or something!
3686 
3687  std::string stmt{"CREATE TABLE " + table_name};
3688  std::vector<std::string> col_stmts;
3689 
3690  for (auto col : rds) {
3691  if (ImportHelpers::is_reserved_name(col.col_name)) {
3692  THROW_MAPD_EXCEPTION("Invalid column name (reserved keyword): " + col.col_name);
3693  } else if (col.col_name != ImportHelpers::sanitize_name(col.col_name)) {
3694  THROW_MAPD_EXCEPTION("Invalid characters in column name: " + col.col_name);
3695  }
3696  if (col.col_type.type == TDatumType::INTERVAL_DAY_TIME ||
3697  col.col_type.type == TDatumType::INTERVAL_YEAR_MONTH) {
3698  THROW_MAPD_EXCEPTION("Unsupported type: " + thrift_to_name(col.col_type) +
3699  " for column: " + col.col_name);
3700  }
3701 
3702  if (col.col_type.type == TDatumType::DECIMAL) {
3703  // if no precision or scale passed in set to default 14,7
3704  if (col.col_type.precision == 0 && col.col_type.scale == 0) {
3705  col.col_type.precision = 14;
3706  col.col_type.scale = 7;
3707  }
3708  }
3709 
3710  std::string col_stmt;
3711  col_stmt.append(col.col_name + " " + thrift_to_name(col.col_type));
3712 
3713  // As of 2016-06-27 the Immerse v1 frontend does not explicitly set the
3714  // `nullable` argument, leading this to default to false. Uncomment for v2.
3715  // if (!col.col_type.nullable) col_stmt.append(" NOT NULL");
3716 
3717  if (thrift_to_encoding(col.col_type.encoding) != kENCODING_NONE) {
3718  col_stmt.append(" ENCODING " + thrift_to_encoding_name(col.col_type));
3719  if (thrift_to_encoding(col.col_type.encoding) == kENCODING_DICT ||
3720  thrift_to_encoding(col.col_type.encoding) == kENCODING_FIXED ||
3721  thrift_to_encoding(col.col_type.encoding) == kENCODING_GEOINT) {
3722  col_stmt.append("(" + std::to_string(col.col_type.comp_param) + ")");
3723  }
3724  } else if (col.col_type.type == TDatumType::STR) {
3725  // non DICT encoded strings
3726  col_stmt.append(" ENCODING NONE");
3727  } else if (col.col_type.type == TDatumType::POINT ||
3728  col.col_type.type == TDatumType::LINESTRING ||
3729  col.col_type.type == TDatumType::POLYGON ||
3730  col.col_type.type == TDatumType::MULTIPOLYGON) {
3731  // non encoded compressable geo
3732  if (col.col_type.scale == 4326) {
3733  col_stmt.append(" ENCODING NONE");
3734  }
3735  }
3736  col_stmts.push_back(col_stmt);
3737  }
3738 
3739  stmt.append(" (" + boost::algorithm::join(col_stmts, ", ") + ")");
3740 
3741  if (create_params.is_replicated) {
3742  stmt.append(" WITH (PARTITIONS = 'REPLICATED')");
3743  }
3744 
3745  stmt.append(";");
3746 
3747  TQueryResult ret;
3748  sql_execute(ret, session, stmt, true, "", -1, -1);
3749 }
EncodingType thrift_to_encoding(const TEncodingType::type tEncodingType)
ConnectionInfo getConnectionInfo() const
std::string join(T const &container, std::string const &delim)
std::string to_string(char const *&&v)
#define THROW_MAPD_EXCEPTION(errstr)
bool is_reserved_name(const std::string &name)
std::string sanitize_name(const std::string &name)
std::string thrift_to_encoding_name(const TTypeInfo &ti)
std::string thrift_to_name(const TTypeInfo &ti)
void check_read_only(const std::string &str)
void sql_execute(TQueryResult &_return, const TSessionId &session, const std::string &query, const bool column_format, const std::string &nonce, const int32_t first_n, const int32_t at_most_n) override
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 365 of file MapDHandler.cpp.

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

Referenced by parse_to_ra().

366  {
367  // We would create an in memory session for calcite with super user privileges which
368  // would be used for getting all tables metadata when a user runs the query. The
369  // session would be under the name of a proxy user/password which would only persist
370  // till server's lifetime or execution of calcite query(in memory) whichever is the
371  // earliest.
372  mapd_lock_guard<mapd_shared_mutex> write_lock(sessions_mutex_);
373  std::string session_id;
374  do {
375  session_id = generate_random_string(64);
376  } while (sessions_.find(session_id) != sessions_.end());
377  Catalog_Namespace::UserMetadata user_meta(-1,
378  calcite_->getInternalSessionProxyUserName(),
379  calcite_->getInternalSessionProxyPassword(),
380  true,
381  -1,
382  true);
383  const auto emplace_ret =
384  sessions_.emplace(session_id,
385  std::make_shared<Catalog_Namespace::SessionInfo>(
386  catalog_ptr, user_meta, executor_device_type_, session_id));
387  CHECK(emplace_ret.second);
388  return session_id;
389 }
SessionMap sessions_
Definition: MapDHandler.h:729
mapd_shared_mutex sessions_mutex_
Definition: MapDHandler.h:509
CHECK(cgen_state)
std::string generate_random_string(const size_t len)
std::shared_ptr< Calcite > calcite_
Definition: MapDHandler.h:517
ExecutorDeviceType executor_device_type_
Definition: MapDHandler.h:500

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 1090 of file MapDHandler.cpp.

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

1093  {
1094  auto stdlog = STDLOG(get_session_ptr(session));
1095  std::string serialized_cuda_handle = "";
1096  if (device_type == TDeviceType::GPU) {
1097  std::lock_guard<std::mutex> map_lock(handle_to_dev_ptr_mutex_);
1098  if (ipc_handle_to_dev_ptr_.count(df.df_handle) != size_t(1)) {
1099  TMapDException ex;
1100  ex.error_msg = std::string(
1101  "Exception: current data frame handle is not bookkept or been inserted twice");
1102  LOG(ERROR) << ex.error_msg;
1103  throw ex;
1104  }
1105  serialized_cuda_handle = ipc_handle_to_dev_ptr_[df.df_handle];
1106  ipc_handle_to_dev_ptr_.erase(df.df_handle);
1107  }
1108  std::vector<char> sm_handle(df.sm_handle.begin(), df.sm_handle.end());
1109  std::vector<char> df_handle(df.df_handle.begin(), df.df_handle.end());
1111  sm_handle, df.sm_size, df_handle, df.df_size, serialized_cuda_handle};
1113  result,
1114  device_type == TDeviceType::CPU ? ExecutorDeviceType::CPU : ExecutorDeviceType::GPU,
1115  device_id,
1116  data_mgr_);
1117 }
#define LOG(tag)
Definition: Logger.h:188
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
static void deallocateArrowResultBuffer(const ArrowResult &result, const ExecutorDeviceType device_type, const size_t device_id, std::shared_ptr< Data_Namespace::DataMgr > &data_mgr)
std::shared_ptr< Data_Namespace::DataMgr > data_mgr_
Definition: MapDHandler.h:494
std::unordered_map< std::string, std::string > ipc_handle_to_dev_ptr_
Definition: MapDHandler.h:747
std::mutex handle_to_dev_ptr_mutex_
Definition: MapDHandler.h:746
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 3422 of file MapDHandler.cpp.

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

3423  {
3424  auto stdlog = STDLOG(get_session_ptr(session));
3425  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
3426  auto session_ptr = stdlog.getConstSessionInfo();
3427  check_read_only("delete_dashboard");
3428  auto& cat = session_ptr->getCatalog();
3429  auto dash = cat.getMetadataForDashboard(dashboard_id);
3430  if (!dash) {
3431  THROW_MAPD_EXCEPTION("Dashboard with id" + std::to_string(dashboard_id) +
3432  " doesn't exist, so cannot delete it");
3433  }
3435  *session_ptr, dash->dashboardId, AccessPrivileges::DELETE_DASHBOARD)) {
3436  THROW_MAPD_EXCEPTION("Not enough privileges to delete a dashboard.");
3437  }
3438  try {
3439  cat.deleteMetadataForDashboard(dashboard_id);
3440  } catch (const std::exception& e) {
3441  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
3442  }
3443 }
ConnectionInfo getConnectionInfo() const
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
std::string to_string(char const *&&v)
#define THROW_MAPD_EXCEPTION(errstr)
static bool is_allowed_on_dashboard(const Catalog_Namespace::SessionInfo &session_info, int32_t dashboard_id, AccessPrivileges requestedPermissions)
void check_read_only(const std::string &str)
static const AccessPrivileges DELETE_DASHBOARD
Definition: DBObject.h:173
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 3065 of file MapDHandler.cpp.

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

Referenced by import_geo_table().

3068  {
3069  auto stdlog = STDLOG(get_session_ptr(session));
3070  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
3071  check_read_only("detect_column_types");
3072 
3074 
3075  std::string file_name{file_name_in};
3076 
3077  if (path_is_relative(file_name)) {
3078  // assume relative paths are relative to data_path / mapd_import / <session>
3079  auto file_path = import_path_ / picosha2::hash256_hex_string(session) /
3080  boost::filesystem::path(file_name).filename();
3081  file_name = file_path.string();
3082  }
3083 
3084  // if it's a geo table, handle alternative paths (S3, HTTP, archive etc.)
3085  if (copy_params.file_type == Importer_NS::FileType::POLYGON) {
3086  if (is_a_supported_geo_file(file_name, true)) {
3087  // prepare to detect geo file directly
3088  add_vsi_network_prefix(file_name);
3089  add_vsi_geo_prefix(file_name);
3090  } else if (is_a_supported_archive_file(file_name)) {
3091  // find the archive file
3092  add_vsi_network_prefix(file_name);
3093  if (!Importer_NS::Importer::gdalFileExists(file_name, copy_params)) {
3094  THROW_MAPD_EXCEPTION("Archive does not exist: " + file_name_in);
3095  }
3096  // find geo file in archive
3097  add_vsi_archive_prefix(file_name);
3098  std::string geo_file = find_first_geo_file_in_archive(file_name, copy_params);
3099  // prepare to detect that geo file
3100  if (geo_file.size()) {
3101  file_name = file_name + std::string("/") + geo_file;
3102  }
3103  } else {
3104  THROW_MAPD_EXCEPTION("File is not a supported geo or geo archive format: " +
3105  file_name_in);
3106  }
3107  }
3108 
3109  auto file_path = boost::filesystem::path(file_name);
3110  // can be a s3 url
3111  if (!boost::istarts_with(file_name, "s3://")) {
3112  if (!boost::filesystem::path(file_name).is_absolute()) {
3113  file_path = import_path_ / picosha2::hash256_hex_string(session) /
3114  boost::filesystem::path(file_name).filename();
3115  file_name = file_path.string();
3116  }
3117 
3118  if (copy_params.file_type == Importer_NS::FileType::POLYGON) {
3119  // check for geo file
3120  if (!Importer_NS::Importer::gdalFileOrDirectoryExists(file_name, copy_params)) {
3121  THROW_MAPD_EXCEPTION("File does not exist: " + file_path.string());
3122  }
3123  } else {
3124  // check for regular file
3125  if (!boost::filesystem::exists(file_path)) {
3126  THROW_MAPD_EXCEPTION("File does not exist: " + file_path.string());
3127  }
3128  }
3129  }
3130  try {
3131  if (copy_params.file_type == Importer_NS::FileType::DELIMITED
3132 #ifdef ENABLE_IMPORT_PARQUET
3133  || (copy_params.file_type == Importer_NS::FileType::PARQUET)
3134 #endif
3135  ) {
3136  Importer_NS::Detector detector(file_path, copy_params);
3137  std::vector<SQLTypes> best_types = detector.best_sqltypes;
3138  std::vector<EncodingType> best_encodings = detector.best_encodings;
3139  std::vector<std::string> headers = detector.get_headers();
3140  copy_params = detector.get_copy_params();
3141 
3142  _return.copy_params = copyparams_to_thrift(copy_params);
3143  _return.row_set.row_desc.resize(best_types.size());
3144  for (size_t col_idx = 0; col_idx < best_types.size(); col_idx++) {
3145  TColumnType col;
3146  SQLTypes t = best_types[col_idx];
3147  EncodingType encodingType = best_encodings[col_idx];
3148  SQLTypeInfo ti(t, false, encodingType);
3149  if (IS_GEO(t)) {
3150  // set this so encoding_to_thrift does the right thing
3151  ti.set_compression(copy_params.geo_coords_encoding);
3152  // fill in these directly
3153  col.col_type.precision = static_cast<int>(copy_params.geo_coords_type);
3154  col.col_type.scale = copy_params.geo_coords_srid;
3155  col.col_type.comp_param = copy_params.geo_coords_comp_param;
3156  }
3157  col.col_type.type = type_to_thrift(ti);
3158  col.col_type.encoding = encoding_to_thrift(ti);
3159  if (copy_params.sanitize_column_names) {
3160  col.col_name = ImportHelpers::sanitize_name(headers[col_idx]);
3161  } else {
3162  col.col_name = headers[col_idx];
3163  }
3164  col.is_reserved_keyword = ImportHelpers::is_reserved_name(col.col_name);
3165  _return.row_set.row_desc[col_idx] = col;
3166  }
3167  size_t num_samples = 100;
3168  auto sample_data = detector.get_sample_rows(num_samples);
3169 
3170  TRow sample_row;
3171  for (auto row : sample_data) {
3172  sample_row.cols.clear();
3173  for (const auto& s : row) {
3174  TDatum td;
3175  td.val.str_val = s;
3176  td.is_null = s.empty();
3177  sample_row.cols.push_back(td);
3178  }
3179  _return.row_set.rows.push_back(sample_row);
3180  }
3181  } else if (copy_params.file_type == Importer_NS::FileType::POLYGON) {
3182  // @TODO simon.eves get this from somewhere!
3183  const std::string geoColumnName(OMNISCI_GEO_PREFIX);
3184 
3185  check_geospatial_files(file_path, copy_params);
3186  std::list<ColumnDescriptor> cds = Importer_NS::Importer::gdalToColumnDescriptors(
3187  file_path.string(), geoColumnName, copy_params);
3188  for (auto cd : cds) {
3189  if (copy_params.sanitize_column_names) {
3190  cd.columnName = ImportHelpers::sanitize_name(cd.columnName);
3191  }
3192  _return.row_set.row_desc.push_back(populateThriftColumnType(nullptr, &cd));
3193  }
3194  std::map<std::string, std::vector<std::string>> sample_data;
3196  file_path.string(), geoColumnName, sample_data, 100, copy_params);
3197  if (sample_data.size() > 0) {
3198  for (size_t i = 0; i < sample_data.begin()->second.size(); i++) {
3199  TRow sample_row;
3200  for (auto cd : cds) {
3201  TDatum td;
3202  td.val.str_val = sample_data[cd.sourceName].at(i);
3203  td.is_null = td.val.str_val.empty();
3204  sample_row.cols.push_back(td);
3205  }
3206  _return.row_set.rows.push_back(sample_row);
3207  }
3208  }
3209  _return.copy_params = copyparams_to_thrift(copy_params);
3210  }
3211  } catch (const std::exception& e) {
3212  THROW_MAPD_EXCEPTION("detect_column_types error: " + std::string(e.what()));
3213  }
3214 }
TColumnType populateThriftColumnType(const Catalog_Namespace::Catalog *cat, const ColumnDescriptor *cd)
void add_vsi_network_prefix(std::string &path)
TDatumType::type type_to_thrift(const SQLTypeInfo &type_info)
SQLTypes
Definition: sqltypes.h:39
EncodingType
Definition: encodetypes.h:22
boost::filesystem::path import_path_
Definition: MapDHandler.h:499
ConnectionInfo getConnectionInfo() const
void add_vsi_archive_prefix(std::string &path)
void add_vsi_geo_prefix(std::string &path)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
#define THROW_MAPD_EXCEPTION(errstr)
EncodingType geo_coords_encoding
Definition: CopyParams.h:73
static bool gdalFileOrDirectoryExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:4526
TCopyParams copyparams_to_thrift(const Importer_NS::CopyParams &cp)
static const std::list< ColumnDescriptor > gdalToColumnDescriptors(const std::string &fileName, const std::string &geoColumnName, const CopyParams &copy_params)
Definition: Importer.cpp:4398
bool is_reserved_name(const std::string &name)
bool is_a_supported_geo_file(const std::string &path, bool include_gz)
std::string sanitize_name(const std::string &name)
bool path_is_relative(const std::string &path)
static bool gdalFileExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:4521
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:4272
void check_geospatial_files(const boost::filesystem::path file_path, const Importer_NS::CopyParams &copy_params)
std::string find_first_geo_file_in_archive(const std::string &archive_path, const Importer_NS::CopyParams &copy_params)
void check_read_only(const std::string &str)
Importer_NS::CopyParams thrift_to_copyparams(const TCopyParams &cp)
#define IS_GEO(T)
Definition: sqltypes.h:165
#define STDLOG(...)
Definition: QueryState.h:225
bool is_a_supported_archive_file(const std::string &path)
int32_t geo_coords_comp_param
Definition: CopyParams.h:74
const std::string OMNISCI_GEO_PREFIX
Definition: geosupport.h:23
TEncodingType::type encoding_to_thrift(const SQLTypeInfo &type_info)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 520 of file MapDHandler.cpp.

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

520  {
521  auto stdlog = STDLOG();
522  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
523 
524  mapd_unique_lock<mapd_shared_mutex> write_lock(sessions_mutex_);
525  auto session_it = get_session_it_unsafe(session, write_lock);
526  stdlog.setSessionInfo(session_it->second);
527  const auto dbname = session_it->second->getCatalog().getCurrentDB().dbName;
528  LOG(INFO) << "User " << session_it->second->get_currentUser().userName
529  << " disconnected from database " << dbname << std::endl;
530  disconnect_impl(session_it, write_lock);
531 }
void disconnect_impl(const SessionMap::iterator &session_it, mapd_unique_lock< mapd_shared_mutex > &write_lock)
#define LOG(tag)
Definition: Logger.h:188
ConnectionInfo getConnectionInfo() const
SessionMap::iterator get_session_it_unsafe(const TSessionId &session, SESSION_MAP_LOCK &lock)
mapd_shared_mutex sessions_mutex_
Definition: MapDHandler.h:509
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 533 of file MapDHandler.cpp.

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

Referenced by disconnect(), and get_session_it_unsafe().

534  {
535  // session_it existence should already have been checked (i.e. called via
536  // get_session_it_unsafe(...))
537  const auto session_id = session_it->second->get_session_id();
538  if (leaf_aggregator_.leafCount() > 0) {
539  leaf_aggregator_.disconnect(session_id);
540  }
541  sessions_.erase(session_it);
542  write_lock.unlock();
543 
544  if (render_handler_) {
545  render_handler_->disconnect(session_id);
546  }
547 }
SessionMap sessions_
Definition: MapDHandler.h:729
std::unique_ptr< MapDRenderHandler > render_handler_
Definition: MapDHandler.h:514
void disconnect(const TSessionId session)
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:496
size_t leafCount() const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void MapDHandler::emergency_shutdown ( )

Definition at line 5753 of file MapDHandler.cpp.

References calcite_.

Referenced by shutdown().

5753  {
5754  if (calcite_) {
5755  calcite_->close_calcite_server(false);
5756  }
5757 }
std::shared_ptr< Calcite > calcite_
Definition: MapDHandler.h:517

+ Here is the caller graph for this function:

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

Definition at line 5335 of file MapDHandler.cpp.

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

Referenced by sql_execute_impl().

5337  {
5338  auto importer_factory = [&session_info, this](
5339  const Catalog& catalog,
5340  const TableDescriptor* td,
5341  const std::string& file_path,
5342  const Importer_NS::CopyParams& copy_params) {
5343  return std::make_unique<Importer_NS::Importer>(
5344  new DistributedLoader(session_info, td, &leaf_aggregator_),
5345  file_path,
5346  copy_params);
5347  };
5348  copy_stmt->execute(session_info, importer_factory);
5349 }
class for a per-database catalog. also includes metadata for the current database and the current use...
Definition: Catalog.h:84
void execute(const Catalog_Namespace::SessionInfo &session) override
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:496
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:

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

Definition at line 5628 of file MapDHandler.cpp.

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

5630  {
5631  if (!render_handler_) {
5632  THROW_MAPD_EXCEPTION("Backend rendering is disabled.");
5633  }
5634 
5635  LOG(INFO) << "execute_next_render_step: id:" << pending_render.id;
5636  auto time_ms = measure<>::execution([&]() {
5637  try {
5638  render_handler_->execute_next_render_step(_return, pending_render, merged_data);
5639  } catch (std::exception& e) {
5640  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
5641  }
5642  });
5643  LOG(INFO) << "execute_next_render_step-COMPLETED id: " << pending_render.id
5644  << ", time: " << time_ms << "ms ";
5645 }
std::unique_ptr< MapDRenderHandler > render_handler_
Definition: MapDHandler.h:514
static TimeT::rep execution(F func, Args &&...args)
Definition: sample.cpp:29
#define LOG(tag)
Definition: Logger.h:188
#define THROW_MAPD_EXCEPTION(errstr)

+ Here is the call graph for this function:

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

Definition at line 5482 of file MapDHandler.cpp.

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

5483  {
5484  if (!leaf_handler_) {
5485  THROW_MAPD_EXCEPTION("Distributed support is disabled.");
5486  }
5487  LOG(INFO) << "execute_query_step : id:" << pending_query.id;
5488  auto time_ms = measure<>::execution([&]() {
5489  try {
5490  leaf_handler_->execute_query_step(_return, pending_query);
5491  } catch (std::exception& e) {
5492  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
5493  }
5494  });
5495  LOG(INFO) << "execute_query_step-COMPLETED " << time_ms << "ms";
5496 }
static TimeT::rep execution(F func, Args &&...args)
Definition: sample.cpp:29
#define LOG(tag)
Definition: Logger.h:188
#define THROW_MAPD_EXCEPTION(errstr)
std::unique_ptr< MapDLeafHandler > leaf_handler_
Definition: MapDHandler.h:516

+ Here is the call graph for this function:

std::vector< PushedDownFilterInfo > MapDHandler::execute_rel_alg ( TQueryResult &  _return,
QueryStateProxy  query_state_proxy,
const std::string &  query_ra,
const bool  column_format,
const ExecutorDeviceType  executor_device_type,
const int32_t  first_n,
const int32_t  at_most_n,
const bool  just_validate,
const bool  find_push_down_candidates,
const ExplainInfo explain_info 
) const
private

Definition at line 4606 of file MapDHandler.cpp.

References allow_loop_joins_, allow_multifrag_, convert_explain(), convert_rows(), CPU, query_state::Timer::createQueryStateProxy(), query_state::QueryStateProxy::createTimer(), Default, measure< TimeT >::execution(), ExplainInfo::explain_optimized, ExplainInfo::explain_plan, g_dynamic_watchdog_time_limit, g_enable_columnar_output, g_enable_dynamic_watchdog, g_enable_watchdog, query_state::QueryState::getConstSessionInfo(), Executor::getExecutor(), query_state::QueryStateProxy::getQueryState(), MapDParameters::gpu_input_mem_limit, intel_jit_profile_, jit_debug_, ExplainInfo::justCalciteExplain(), ExplainInfo::justExplain(), mapd_parameters_, and Optimized.

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

4616  {
4617  query_state::Timer timer = query_state_proxy.createTimer(__func__);
4618  const auto& cat = query_state_proxy.getQueryState().getConstSessionInfo()->getCatalog();
4619  CompilationOptions co = {executor_device_type,
4620  /*hoist_literals=*/true,
4623  /*allow_lazy_fetch=*/true,
4624  /*add_delete_column=*/true,
4630  explain_info.justExplain(),
4631  allow_loop_joins_ || just_validate,
4633  jit_debug_,
4634  just_validate,
4637  find_push_down_candidates,
4638  explain_info.justCalciteExplain(),
4640  auto executor = Executor::getExecutor(cat.getCurrentDB().dbId,
4641  jit_debug_ ? "/tmp" : "",
4642  jit_debug_ ? "mapdquery" : "",
4644  RelAlgExecutor ra_executor(executor.get(),
4645  cat,
4646  query_ra,
4647  query_state_proxy.getQueryState().shared_from_this());
4648  ExecutionResult result{std::make_shared<ResultSet>(std::vector<TargetInfo>{},
4651  nullptr,
4652  nullptr),
4653  {}};
4654  _return.execution_time_ms += measure<>::execution([&]() {
4655  result = ra_executor.executeRelAlgQuery(co, eo, explain_info.explain_plan, nullptr);
4656  });
4657  // reduce execution time by the time spent during queue waiting
4658  _return.execution_time_ms -= result.getRows()->getQueueTime();
4659  const auto& filter_push_down_info = result.getPushedDownFilterInfo();
4660  if (!filter_push_down_info.empty()) {
4661  return filter_push_down_info;
4662  }
4663  if (explain_info.justExplain()) {
4664  convert_explain(_return, *result.getRows(), column_format);
4665  } else if (!explain_info.justCalciteExplain()) {
4666  convert_rows(_return,
4667  timer.createQueryStateProxy(),
4668  result.getTargetsMeta(),
4669  *result.getRows(),
4670  column_format,
4671  first_n,
4672  at_most_n);
4673  }
4674  return {};
4675 }
const bool allow_loop_joins_
Definition: MapDHandler.h:507
static TimeT::rep execution(F func, Args &&...args)
Definition: sample.cpp:29
void convert_rows(TQueryResult &_return, QueryStateProxy query_state_proxy, const std::vector< TargetMetaInfo > &targets, const R &results, const bool column_format, const int32_t first_n, const int32_t at_most_n) const
static std::shared_ptr< Executor > getExecutor(const int db_id, const std::string &debug_dir="", const std::string &debug_file="", const MapDParameters mapd_parameters=MapDParameters())
Definition: Execute.cpp:127
const bool intel_jit_profile_
Definition: MapDHandler.h:504
bool g_enable_dynamic_watchdog
Definition: Execute.cpp:72
Timer createTimer(char const *event_name)
Definition: QueryState.cpp:113
bool g_enable_watchdog
const MapDParameters & mapd_parameters_
Definition: MapDHandler.h:513
bool g_enable_columnar_output
Definition: Execute.cpp:86
bool allow_multifrag_
Definition: MapDHandler.h:505
bool justExplain() const
Definition: ParserWrapper.h:59
bool explain_plan
Definition: ParserWrapper.h:54
QueryState & getQueryState()
Definition: QueryState.h:172
QueryStateProxy createQueryStateProxy()
Definition: QueryState.cpp:120
double gpu_input_mem_limit
void convert_explain(TQueryResult &_return, const ResultSet &results, const bool column_format) const
bool explain_optimized
Definition: ParserWrapper.h:53
unsigned g_dynamic_watchdog_time_limit
Definition: Execute.cpp:73
const bool jit_debug_
Definition: MapDHandler.h:503
bool justCalciteExplain() const
Definition: ParserWrapper.h:61
std::shared_ptr< Catalog_Namespace::SessionInfo const > getConstSessionInfo() const
Definition: QueryState.cpp:77

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 4677 of file MapDHandler.cpp.

References allow_loop_joins_, allow_multifrag_, CHECK(), CPU, data_mgr_, Default, ArrowResult::df_handle, ArrowResult::df_size, measure< TimeT >::execution(), g_dynamic_watchdog_time_limit, g_enable_columnar_output, g_enable_dynamic_watchdog, g_enable_watchdog, Catalog_Namespace::SessionInfo::get_executor_device_type(), Catalog_Namespace::SessionInfo::getCatalog(), Executor::getExecutor(), query_state::QueryStateProxy::getQueryState(), getTargetNames(), GPU, MapDParameters::gpu_input_mem_limit, handle_to_dev_ptr_mutex_, intel_jit_profile_, ipc_handle_to_dev_ptr_, jit_debug_, mapd_parameters_, ArrowResult::serialized_cuda_handle, ArrowResult::sm_handle, and ArrowResult::sm_size.

Referenced by sql_execute_df().

4683  {
4684  const auto& cat = session_info.getCatalog();
4685  CHECK(device_type == ExecutorDeviceType::CPU ||
4687  CompilationOptions co = {session_info.get_executor_device_type(),
4688  /*hoist_literals=*/true,
4691  /*allow_lazy_fetch=*/true,
4692  /*add_delete_column=*/true,
4697  false,
4700  jit_debug_,
4701  false,
4704  false,
4705  false,
4707  auto executor = Executor::getExecutor(cat.getCurrentDB().dbId,
4708  jit_debug_ ? "/tmp" : "",
4709  jit_debug_ ? "mapdquery" : "",
4711  RelAlgExecutor ra_executor(executor.get(),
4712  cat,
4713  query_ra,
4714  query_state_proxy.getQueryState().shared_from_this());
4715  ExecutionResult result{std::make_shared<ResultSet>(std::vector<TargetInfo>{},
4718  nullptr,
4719  nullptr),
4720  {}};
4721  _return.execution_time_ms += measure<>::execution(
4722  [&]() { result = ra_executor.executeRelAlgQuery(co, eo, false, nullptr); });
4723  _return.execution_time_ms -= result.getRows()->getQueueTime();
4724  const auto rs = result.getRows();
4725  const auto converter =
4726  std::make_unique<ArrowResultSetConverter>(rs,
4727  data_mgr_,
4728  device_type,
4729  device_id,
4730  getTargetNames(result.getTargetsMeta()),
4731  first_n);
4732  ArrowResult arrow_result;
4733  _return.arrow_conversion_time_ms +=
4734  measure<>::execution([&] { arrow_result = converter->getArrowResult(); });
4735  _return.sm_handle =
4736  std::string(arrow_result.sm_handle.begin(), arrow_result.sm_handle.end());
4737  _return.sm_size = arrow_result.sm_size;
4738  _return.df_handle =
4739  std::string(arrow_result.df_handle.begin(), arrow_result.df_handle.end());
4740  if (device_type == ExecutorDeviceType::GPU) {
4741  std::lock_guard<std::mutex> map_lock(handle_to_dev_ptr_mutex_);
4742  CHECK(!ipc_handle_to_dev_ptr_.count(_return.df_handle));
4743  ipc_handle_to_dev_ptr_.insert(
4744  std::make_pair(_return.df_handle, arrow_result.serialized_cuda_handle));
4745  }
4746  _return.df_size = arrow_result.df_size;
4747 }
const bool allow_loop_joins_
Definition: MapDHandler.h:507
static TimeT::rep execution(F func, Args &&...args)
Definition: sample.cpp:29
std::vector< char > sm_handle
static std::shared_ptr< Executor > getExecutor(const int db_id, const std::string &debug_dir="", const std::string &debug_file="", const MapDParameters mapd_parameters=MapDParameters())
Definition: Execute.cpp:127
const bool intel_jit_profile_
Definition: MapDHandler.h:504
bool g_enable_dynamic_watchdog
Definition: Execute.cpp:72
bool g_enable_watchdog
const MapDParameters & mapd_parameters_
Definition: MapDHandler.h:513
bool g_enable_columnar_output
Definition: Execute.cpp:86
bool allow_multifrag_
Definition: MapDHandler.h:505
CHECK(cgen_state)
QueryState & getQueryState()
Definition: QueryState.h:172
std::vector< char > df_handle
int64_t sm_size
std::shared_ptr< Data_Namespace::DataMgr > data_mgr_
Definition: MapDHandler.h:494
Catalog & getCatalog() const
Definition: SessionInfo.h:76
double gpu_input_mem_limit
std::string serialized_cuda_handle
int64_t df_size
std::unordered_map< std::string, std::string > ipc_handle_to_dev_ptr_
Definition: MapDHandler.h:747
std::vector< std::string > getTargetNames(const std::vector< TargetMetaInfo > &targets) const
std::mutex handle_to_dev_ptr_mutex_
Definition: MapDHandler.h:746
unsigned g_dynamic_watchdog_time_limit
Definition: Execute.cpp:73
const bool jit_debug_
Definition: MapDHandler.h:503
const ExecutorDeviceType get_executor_device_type() const
Definition: SessionInfo.h:80

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 5284 of file MapDHandler.cpp.

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

Referenced by sql_execute_impl().

5294  {
5295  // collecting the selected filters' info to be sent to Calcite:
5296  std::vector<TFilterPushDownInfo> filter_push_down_info;
5297  for (const auto& req : filter_push_down_requests) {
5298  TFilterPushDownInfo filter_push_down_info_for_request;
5299  filter_push_down_info_for_request.input_prev = req.input_prev;
5300  filter_push_down_info_for_request.input_start = req.input_start;
5301  filter_push_down_info_for_request.input_next = req.input_next;
5302  filter_push_down_info.push_back(filter_push_down_info_for_request);
5303  }
5304  // deriving the new relational algebra plan with respect to the pushed down filters
5305  _return.execution_time_ms += measure<>::execution([&]() {
5306  query_ra = parse_to_ra(query_state_proxy,
5307  query_state_proxy.getQueryState().getQueryStr(),
5308  filter_push_down_info,
5309  false,
5311  .first.plan_result;
5312  });
5313 
5314  if (just_calcite_explain) {
5315  // return the new ra as the result
5316  convert_explain(_return, ResultSet(query_ra), true);
5317  return;
5318  }
5319 
5320  // execute the new relational algebra plan:
5321  auto explain_info = ExplainInfo::defaults();
5322  explain_info.explain = just_explain;
5323  execute_rel_alg(_return,
5324  query_state_proxy,
5325  query_ra,
5326  column_format,
5327  executor_device_type,
5328  first_n,
5329  at_most_n,
5330  /*just_validate=*/false,
5331  /*find_push_down_candidates=*/false,
5332  explain_info);
5333 }
static ExplainInfo defaults()
Definition: ParserWrapper.h:57
static TimeT::rep execution(F func, Args &&...args)
Definition: sample.cpp:29
std::string const & getQueryStr() const
Definition: QueryState.h:152
const MapDParameters & mapd_parameters_
Definition: MapDHandler.h:513
QueryState & getQueryState()
Definition: QueryState.h:172
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
void convert_explain(TQueryResult &_return, const ResultSet &results, const bool column_format) const
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 MapDParameters mapd_parameters, RenderInfo *render_info=nullptr, bool check_privileges=true)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::unordered_map< std::string, std::unordered_set< std::string > > MapDHandler::fill_column_names_by_table ( std::vector< std::string > &  table_names,
query_state::StdLog stdlog 
)
private

Definition at line 1290 of file MapDHandler.cpp.

References get_table_details_impl().

Referenced by get_token_based_completions().

1291  {
1292  std::unordered_map<std::string, std::unordered_set<std::string>> column_names_by_table;
1293  for (auto it = table_names.begin(); it != table_names.end();) {
1294  TTableDetails table_details;
1295  try {
1296  get_table_details_impl(table_details, stdlog, *it, false, false);
1297  } catch (const TMapDException& e) {
1298  // Remove the corrupted Table/View name from the list for further processing.
1299  it = table_names.erase(it);
1300  continue;
1301  }
1302  for (const auto& column_type : table_details.row_desc) {
1303  column_names_by_table[*it].emplace(column_type.col_name);
1304  }
1305  ++it;
1306  }
1307  return column_names_by_table;
1308 }
void get_table_details_impl(TTableDetails &_return, query_state::StdLog &stdlog, const std::string &table_name, const bool get_system, const bool get_physical)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 4875 of file MapDHandler.cpp.

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

Referenced by get_table_details_impl(), and validate_rel_alg().

4876  {
4877  TRowDescriptor fixedup_row_desc;
4878  for (const TColumnType& col_desc : row_desc) {
4879  auto fixedup_col_desc = col_desc;
4880  if (col_desc.col_type.encoding == TEncodingType::DICT &&
4881  col_desc.col_type.comp_param > 0) {
4882  const auto dd = cat.getMetadataForDict(col_desc.col_type.comp_param, false);
4883  fixedup_col_desc.col_type.comp_param = dd->dictNBits;
4884  }
4885  fixedup_row_desc.push_back(fixedup_col_desc);
4886  }
4887  return fixedup_row_desc;
4888 }
const DictDescriptor * getMetadataForDict(int dict_ref, bool loadDict=true) const
Definition: Catalog.cpp:1444

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 4360 of file MapDHandler.cpp.

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

4363  {
4364  auto stdlog =
4365  STDLOG(get_session_ptr(session), "get_all_files_in_archive", archive_path_in);
4366  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
4367 
4368  std::string archive_path(archive_path_in);
4369  if (path_is_relative(archive_path)) {
4370  // assume relative paths are relative to data_path / mapd_import / <session>
4371  auto file_path = import_path_ / picosha2::hash256_hex_string(session) /
4372  boost::filesystem::path(archive_path).filename();
4373  archive_path = file_path.string();
4374  }
4375 
4376  if (is_a_supported_archive_file(archive_path)) {
4377  // find the archive file
4378  add_vsi_network_prefix(archive_path);
4379  if (!Importer_NS::Importer::gdalFileExists(archive_path,
4380  thrift_to_copyparams(copy_params))) {
4381  THROW_MAPD_EXCEPTION("Archive does not exist: " + archive_path_in);
4382  }
4383  // find all files in archive
4384  add_vsi_archive_prefix(archive_path);
4386  archive_path, thrift_to_copyparams(copy_params));
4387  // prepend them all with original path
4388  for (auto& s : _return) {
4389  s = archive_path_in + '/' + s;
4390  }
4391  }
4392 }
void add_vsi_network_prefix(std::string &path)
boost::filesystem::path import_path_
Definition: MapDHandler.h:499
ConnectionInfo getConnectionInfo() const
void add_vsi_archive_prefix(std::string &path)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
#define THROW_MAPD_EXCEPTION(errstr)
bool path_is_relative(const std::string &path)
static bool gdalFileExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:4521
Importer_NS::CopyParams thrift_to_copyparams(const TCopyParams &cp)
#define STDLOG(...)
Definition: QueryState.h:225
bool is_a_supported_archive_file(const std::string &path)
static std::vector< std::string > gdalGetAllFilesInArchive(const std::string &archive_path, const CopyParams &copy_params)
Definition: Importer.cpp:4598

+ Here is the call graph for this function:

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

Definition at line 1709 of file MapDHandler.cpp.

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

1711  {
1712  auto stdlog = STDLOG(get_session_ptr(sessionId));
1713  auto session_ptr = stdlog.getConstSessionInfo();
1714  auto* grantee = SysCatalog::instance().getGrantee(granteeName);
1715  if (grantee) {
1716  if (session_ptr->get_currentUser().isSuper) {
1717  roles = grantee->getRoles();
1718  } else if (grantee->isUser()) {
1719  if (session_ptr->get_currentUser().userName == granteeName) {
1720  roles = grantee->getRoles();
1721  } else {
1723  "Only a superuser is authorized to request list of roles granted to another "
1724  "user.");
1725  }
1726  } else {
1727  CHECK(!grantee->isUser());
1728  // granteeName is actually a roleName here and we can check a role
1729  // only if it is granted to us
1730  if (SysCatalog::instance().isRoleGrantedToGrantee(
1731  session_ptr->get_currentUser().userName, granteeName, false)) {
1732  roles = grantee->getRoles();
1733  } else {
1734  THROW_MAPD_EXCEPTION("A user can check only roles granted to him.");
1735  }
1736  }
1737  } else {
1738  THROW_MAPD_EXCEPTION("Grantee " + granteeName + " does not exist.");
1739  }
1740 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
#define THROW_MAPD_EXCEPTION(errstr)
CHECK(cgen_state)
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 1184 of file MapDHandler.cpp.

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

1187  {
1188  auto stdlog = STDLOG(get_session_ptr(session));
1189  std::vector<std::string> visible_tables; // Tables allowed for the given session.
1190  get_completion_hints_unsorted(hints, visible_tables, stdlog, sql, cursor);
1191  const auto proj_tokens = extract_projection_tokens_for_completion(sql);
1192  auto compatible_table_names = get_uc_compatible_table_names_by_column(
1193  proj_tokens.uc_column_names, visible_tables, stdlog);
1194  // Add the table qualifiers explicitly specified by the user.
1195  compatible_table_names.insert(proj_tokens.uc_column_table_qualifiers.begin(),
1196  proj_tokens.uc_column_table_qualifiers.end());
1197  // Sort the hints by category, from COLUMN (most specific) to KEYWORD.
1198  std::sort(
1199  hints.begin(),
1200  hints.end(),
1201  [&compatible_table_names](const TCompletionHint& lhs, const TCompletionHint& rhs) {
1202  if (lhs.type == TCompletionHintType::TABLE &&
1203  rhs.type == TCompletionHintType::TABLE) {
1204  // Between two tables, one which is compatible with the specified projections
1205  // and one which isn't, pick the one which is compatible.
1206  if (compatible_table_names.find(to_upper(lhs.hints.back())) !=
1207  compatible_table_names.end() &&
1208  compatible_table_names.find(to_upper(rhs.hints.back())) ==
1209  compatible_table_names.end()) {
1210  return true;
1211  }
1212  }
1213  return lhs.type < rhs.type;
1214  });
1215 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
void get_completion_hints_unsorted(std::vector< TCompletionHint > &hints, std::vector< std::string > &visible_tables, query_state::StdLog &stdlog, const std::string &sql, const int cursor)
std::string to_upper(const std::string &str)
std::unordered_set< std::string > get_uc_compatible_table_names_by_column(const std::unordered_set< std::string > &uc_column_names, std::vector< std::string > &table_names, query_state::StdLog &stdlog)
#define STDLOG(...)
Definition: QueryState.h:225
ProjectionTokensForCompletion extract_projection_tokens_for_completion(const std::string &sql)

+ Here is the call graph for this function:

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

Definition at line 1217 of file MapDHandler.cpp.

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

Referenced by get_completion_hints().

1221  {
1222  const auto& session_info = *stdlog.getConstSessionInfo();
1223  try {
1224  get_tables_impl(visible_tables, session_info, GET_PHYSICAL_TABLES_AND_VIEWS);
1225  // Filter out keywords suggested by Calcite which we don't support.
1227  calcite_->getCompletionHints(session_info, visible_tables, sql, cursor));
1228  } catch (const std::exception& e) {
1229  TMapDException ex;
1230  ex.error_msg = "Exception: " + std::string(e.what());
1231  LOG(ERROR) << ex.error_msg;
1232  throw ex;
1233  }
1234  boost::regex from_expr{R"(\s+from\s+)", boost::regex::extended | boost::regex::icase};
1235  const size_t length_to_cursor =
1236  cursor < 0 ? sql.size() : std::min(sql.size(), static_cast<size_t>(cursor));
1237  // Trust hints from Calcite after the FROM keyword.
1238  if (boost::regex_search(sql.cbegin(), sql.cbegin() + length_to_cursor, from_expr)) {
1239  return;
1240  }
1241  // Before FROM, the query is too incomplete for context-sensitive completions.
1242  get_token_based_completions(hints, stdlog, visible_tables, sql, cursor);
1243 }
void get_tables_impl(std::vector< std::string > &table_names, const Catalog_Namespace::SessionInfo &, const GetTablesType get_tables_type)
void get_token_based_completions(std::vector< TCompletionHint > &hints, query_state::StdLog &stdlog, std::vector< std::string > &visible_tables, const std::string &sql, const int cursor)
#define LOG(tag)
Definition: Logger.h:188
std::vector< TCompletionHint > just_whitelisted_keyword_hints(const std::vector< TCompletionHint > &hints)
std::shared_ptr< Calcite > calcite_
Definition: MapDHandler.h:517
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:

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

Definition at line 4523 of file MapDHandler.cpp.

References get_session_ptr().

4524  {
4525  return get_session_ptr(session);
4526 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)

+ Here is the call graph for this function:

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

Definition at line 3265 of file MapDHandler.cpp.

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

3267  {
3268  auto stdlog = STDLOG(get_session_ptr(session));
3269  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
3270  auto session_ptr = stdlog.getConstSessionInfo();
3271  auto const& cat = session_ptr->getCatalog();
3273  auto dash = cat.getMetadataForDashboard(dashboard_id);
3274  if (!dash) {
3275  THROW_MAPD_EXCEPTION("Dashboard with dashboard id " + std::to_string(dashboard_id) +
3276  " doesn't exist");
3277  }
3279  *session_ptr, dash->dashboardId, AccessPrivileges::VIEW_DASHBOARD)) {
3280  THROW_MAPD_EXCEPTION("User has no view privileges for the dashboard with id " +
3281  std::to_string(dashboard_id));
3282  }
3283  user_meta.userName = "";
3284  SysCatalog::instance().getMetadataForUserById(dash->userId, user_meta);
3285  auto objects_list = SysCatalog::instance().getMetadataForObject(
3286  cat.getCurrentDB().dbId,
3287  static_cast<int>(DBObjectType::DashboardDBObjectType),
3288  dashboard_id);
3289  dashboard.dashboard_name = dash->dashboardName;
3290  dashboard.dashboard_state = dash->dashboardState;
3291  dashboard.image_hash = dash->imageHash;
3292  dashboard.update_time = dash->updateTime;
3293  dashboard.dashboard_metadata = dash->dashboardMetadata;
3294  dashboard.dashboard_owner = dash->user;
3295  dashboard.dashboard_id = dash->dashboardId;
3296  if (objects_list.empty() ||
3297  (objects_list.size() == 1 && objects_list[0]->roleName == user_meta.userName)) {
3298  dashboard.is_dash_shared = false;
3299  } else {
3300  dashboard.is_dash_shared = true;
3301  }
3302 }
static const AccessPrivileges VIEW_DASHBOARD
Definition: DBObject.h:171
ConnectionInfo getConnectionInfo() const
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
std::string to_string(char const *&&v)
#define THROW_MAPD_EXCEPTION(errstr)
static bool is_allowed_on_dashboard(const Catalog_Namespace::SessionInfo &session_info, int32_t dashboard_id, AccessPrivileges requestedPermissions)
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 3569 of file MapDHandler.cpp.

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

3572  {
3573  auto stdlog = STDLOG(get_session_ptr(session));
3574  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
3575  auto session_ptr = stdlog.getConstSessionInfo();
3576  auto const& cat = session_ptr->getCatalog();
3578  auto dash = cat.getMetadataForDashboard(dashboard_id);
3579  if (!dash) {
3580  THROW_MAPD_EXCEPTION("Exception: Dashboard id " + std::to_string(dashboard_id) +
3581  " does not exist");
3582  } else if (session_ptr->get_currentUser().userId != dash->userId &&
3583  !session_ptr->get_currentUser().isSuper) {
3585  "User should be either owner of dashboard or super user to access grantees");
3586  }
3587  std::vector<ObjectRoleDescriptor*> objectsList;
3588  objectsList = SysCatalog::instance().getMetadataForObject(
3589  cat.getCurrentDB().dbId,
3590  static_cast<int>(DBObjectType::DashboardDBObjectType),
3591  dashboard_id); // By default objecttypecan be only dashabaords
3592  user_meta.userId = -1;
3593  user_meta.userName = "";
3594  SysCatalog::instance().getMetadataForUserById(dash->userId, user_meta);
3595  for (auto object : objectsList) {
3596  if (user_meta.userName == object->roleName) {
3597  // Mask owner
3598  continue;
3599  }
3600  TDashboardGrantees grantee;
3601  TDashboardPermissions perm;
3602  grantee.name = object->roleName;
3603  grantee.is_user = object->roleType;
3604  perm.create_ = object->privs.hasPermission(DashboardPrivileges::CREATE_DASHBOARD);
3605  perm.delete_ = object->privs.hasPermission(DashboardPrivileges::DELETE_DASHBOARD);
3606  perm.edit_ = object->privs.hasPermission(DashboardPrivileges::EDIT_DASHBOARD);
3607  perm.view_ = object->privs.hasPermission(DashboardPrivileges::VIEW_DASHBOARD);
3608  grantee.permissions = perm;
3609  dashboard_grantees.push_back(grantee);
3610  }
3611 }
ConnectionInfo getConnectionInfo() const
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
std::string to_string(char const *&&v)
#define THROW_MAPD_EXCEPTION(errstr)
static const int32_t EDIT_DASHBOARD
Definition: DBObject.h:106
static const int32_t DELETE_DASHBOARD
Definition: DBObject.h:104
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:

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

Definition at line 3304 of file MapDHandler.cpp.

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

3305  {
3306  auto stdlog = STDLOG(get_session_ptr(session));
3307  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
3308  auto session_ptr = stdlog.getConstSessionInfo();
3309  auto const& cat = session_ptr->getCatalog();
3311  const auto dashes = cat.getAllDashboardsMetadata();
3312  user_meta.userName = "";
3313  for (const auto d : dashes) {
3314  SysCatalog::instance().getMetadataForUserById(d->userId, user_meta);
3316  *session_ptr, d->dashboardId, AccessPrivileges::VIEW_DASHBOARD)) {
3317  auto objects_list = SysCatalog::instance().getMetadataForObject(
3318  cat.getCurrentDB().dbId,
3319  static_cast<int>(DBObjectType::DashboardDBObjectType),
3320  d->dashboardId);
3321  TDashboard dash;
3322  dash.dashboard_name = d->dashboardName;
3323  dash.image_hash = d->imageHash;
3324  dash.update_time = d->updateTime;
3325  dash.dashboard_metadata = d->dashboardMetadata;
3326  dash.dashboard_id = d->dashboardId;
3327  dash.dashboard_owner = d->user;
3328  // dashboardState is intentionally not populated here
3329  // for payload reasons
3330  // use get_dashboard call to get state
3331  if (objects_list.empty() ||
3332  (objects_list.size() == 1 && objects_list[0]->roleName == user_meta.userName)) {
3333  dash.is_dash_shared = false;
3334  } else {
3335  dash.is_dash_shared = true;
3336  }
3337  dashboards.push_back(dash);
3338  }
3339  }
3340 }
static const AccessPrivileges VIEW_DASHBOARD
Definition: DBObject.h:171
ConnectionInfo getConnectionInfo() const
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
static bool is_allowed_on_dashboard(const Catalog_Namespace::SessionInfo &session_info, int32_t dashboard_id, AccessPrivileges requestedPermissions)
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 2268 of file MapDHandler.cpp.

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

2269  {
2270  auto stdlog = STDLOG(get_session_ptr(session));
2271  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
2272  auto session_ptr = stdlog.getConstSessionInfo();
2273  const auto& user = session_ptr->get_currentUser();
2275  SysCatalog::instance().getDatabaseListForUser(user);
2276  for (auto& db : dbs) {
2277  TDBInfo dbinfo;
2278  dbinfo.db_name = std::move(db.dbName);
2279  dbinfo.db_owner = std::move(db.dbOwnerName);
2280  dbinfos.push_back(std::move(dbinfo));
2281  }
2282 }
ConnectionInfo getConnectionInfo() const
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
std::list< DBSummary > DBSummaryList
Definition: SysCatalog.h:120
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 1628 of file MapDHandler.cpp.

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

1631  {
1632  auto stdlog = STDLOG(get_session_ptr(sessionId));
1633  auto session_ptr = stdlog.getConstSessionInfo();
1634  DBObjectType object_type;
1635  switch (type) {
1637  object_type = DBObjectType::DatabaseDBObjectType;
1638  break;
1640  object_type = DBObjectType::TableDBObjectType;
1641  break;
1644  break;
1646  object_type = DBObjectType::ViewDBObjectType;
1647  break;
1648  default:
1649  THROW_MAPD_EXCEPTION("Failed to get object privileges for " + objectName +
1650  ": unknown object type (" + std::to_string(type) + ").");
1651  }
1652  DBObject object_to_find(objectName, object_type);
1653 
1654  // TODO(adb): Use DatabaseLock to protect method
1655  try {
1656  if (object_type == DashboardDBObjectType) {
1657  if (objectName == "") {
1658  object_to_find = DBObject(-1, object_type);
1659  } else {
1660  object_to_find = DBObject(std::stoi(objectName), object_type);
1661  }
1662  } else if ((object_type == TableDBObjectType || object_type == ViewDBObjectType) &&
1663  !objectName.empty()) {
1664  // special handling for view / table
1665  auto const& cat = session_ptr->getCatalog();
1666  auto td = cat.getMetadataForTable(objectName, false);
1667  if (td) {
1668  object_type = td->isView ? ViewDBObjectType : TableDBObjectType;
1669  object_to_find = DBObject(objectName, object_type);
1670  }
1671  }
1672  object_to_find.loadKey(session_ptr->getCatalog());
1673  } catch (const std::exception&) {
1674  THROW_MAPD_EXCEPTION("Object with name " + objectName + " does not exist.");
1675  }
1676 
1677  // object type on database level
1678  DBObject object_to_find_dblevel("", object_type);
1679  object_to_find_dblevel.loadKey(session_ptr->getCatalog());
1680  // if user is superuser respond with a full priv
1681  if (session_ptr->get_currentUser().isSuper) {
1682  // using ALL_TABLE here to set max permissions
1683  DBObject dbObj{object_to_find.getObjectKey(),
1685  session_ptr->get_currentUser().userId};
1686  dbObj.setName("super");
1687  TDBObjects.push_back(
1688  serialize_db_object(session_ptr->get_currentUser().userName, dbObj));
1689  };
1690 
1691  std::vector<std::string> grantees =
1692  SysCatalog::instance().getRoles(true,
1693  session_ptr->get_currentUser().isSuper,
1694  session_ptr->get_currentUser().userName);
1695  for (const auto& grantee : grantees) {
1696  DBObject* object_found;
1697  auto* gr = SysCatalog::instance().getGrantee(grantee);
1698  if (gr && (object_found = gr->findDbObject(object_to_find.getObjectKey(), true))) {
1699  TDBObjects.push_back(serialize_db_object(grantee, *object_found));
1700  }
1701  // check object permissions on Database level
1702  if (gr &&
1703  (object_found = gr->findDbObject(object_to_find_dblevel.getObjectKey(), true))) {
1704  TDBObjects.push_back(serialize_db_object(grantee, *object_found));
1705  }
1706  }
1707 }
DBObjectKey getObjectKey() const
Definition: DBObject.h:209
DBObjectType
Definition: DBObject.h:42
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
static TDBObject serialize_db_object(const std::string &roleName, const DBObject &inObject)
std::string to_string(char const *&&v)
#define THROW_MAPD_EXCEPTION(errstr)
static const AccessPrivileges ALL_TABLE
Definition: DBObject.h:157
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 1601 of file MapDHandler.cpp.

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

1603  {
1604  auto stdlog = STDLOG(get_session_ptr(sessionId));
1605  auto session_ptr = stdlog.getConstSessionInfo();
1606  auto const& user = session_ptr->get_currentUser();
1607  if (!user.isSuper &&
1608  !SysCatalog::instance().isRoleGrantedToGrantee(user.userName, roleName, false)) {
1609  return;
1610  }
1611  auto* rl = SysCatalog::instance().getGrantee(roleName);
1612  if (rl) {
1613  auto dbId = session_ptr->getCatalog().getCurrentDB().dbId;
1614  for (auto& dbObject : *rl->getDbObjects(true)) {
1615  if (dbObject.first.dbId != dbId) {
1616  // TODO (max): it doesn't scale well in case we have many DBs (not a typical
1617  // usecase for now, though)
1618  continue;
1619  }
1620  TDBObject tdbObject = serialize_db_object(roleName, *dbObject.second);
1621  TDBObjectsForRole.push_back(tdbObject);
1622  }
1623  } else {
1624  THROW_MAPD_EXCEPTION("User or role " + roleName + " does not exist.");
1625  }
1626 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
static TDBObject serialize_db_object(const std::string &roleName, const DBObject &inObject)
#define THROW_MAPD_EXCEPTION(errstr)
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 5761 of file MapDHandler.cpp.

References get_session_copy().

5762  {
5763  const auto session_info = get_session_copy(session);
5764  auto params = ::get_device_parameters();
5765  for (auto item : params) {
5766  _return.insert(item);
5767  }
5768 }
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
void get_device_parameters(std::map< std::string, std::string > &_return, const TSessionId &session) override

+ Here is the call graph for this function:

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

Definition at line 4319 of file MapDHandler.cpp.

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

4322  {
4323  auto stdlog =
4324  STDLOG(get_session_ptr(session), "get_first_geo_file_in_archive", archive_path_in);
4325  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
4326  std::string archive_path(archive_path_in);
4327 
4328  if (path_is_relative(archive_path)) {
4329  // assume relative paths are relative to data_path / mapd_import / <session>
4330  auto file_path = import_path_ / picosha2::hash256_hex_string(session) /
4331  boost::filesystem::path(archive_path).filename();
4332  archive_path = file_path.string();
4333  }
4334 
4335  if (is_a_supported_archive_file(archive_path)) {
4336  // find the archive file
4337  add_vsi_network_prefix(archive_path);
4338  if (!Importer_NS::Importer::gdalFileExists(archive_path,
4339  thrift_to_copyparams(copy_params))) {
4340  THROW_MAPD_EXCEPTION("Archive does not exist: " + archive_path_in);
4341  }
4342  // find geo file in archive
4343  add_vsi_archive_prefix(archive_path);
4344  std::string geo_file =
4345  find_first_geo_file_in_archive(archive_path, thrift_to_copyparams(copy_params));
4346  // what did we get?
4347  if (geo_file.size()) {
4348  // prepend it with the original path
4349  _return = archive_path_in + std::string("/") + geo_file;
4350  } else {
4351  // just return the original path
4352  _return = archive_path_in;
4353  }
4354  } else {
4355  // just return the original path
4356  _return = archive_path_in;
4357  }
4358 }
void add_vsi_network_prefix(std::string &path)
boost::filesystem::path import_path_
Definition: MapDHandler.h:499
ConnectionInfo getConnectionInfo() const
void add_vsi_archive_prefix(std::string &path)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
#define THROW_MAPD_EXCEPTION(errstr)
bool path_is_relative(const std::string &path)
static bool gdalFileExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:4521
std::string find_first_geo_file_in_archive(const std::string &archive_path, const Importer_NS::CopyParams &copy_params)
Importer_NS::CopyParams thrift_to_copyparams(const TCopyParams &cp)
#define STDLOG(...)
Definition: QueryState.h:225
bool is_a_supported_archive_file(const std::string &path)

+ Here is the call graph for this function:

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

Definition at line 661 of file MapDHandler.cpp.

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

662  {
663  auto stdlog = STDLOG(get_session_ptr(session));
664  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
665  THardwareInfo ret;
666  const auto cuda_mgr = data_mgr_->getCudaMgr();
667  if (cuda_mgr) {
668  ret.num_gpu_hw = cuda_mgr->getDeviceCount();
669  ret.start_gpu = cuda_mgr->getStartGpu();
670  if (ret.start_gpu >= 0) {
671  ret.num_gpu_allocated = cuda_mgr->getDeviceCount() - cuda_mgr->getStartGpu();
672  // ^ This will break as soon as we allow non contiguous GPU allocations to MapD
673  }
674  for (int16_t device_id = 0; device_id < ret.num_gpu_hw; device_id++) {
675  TGpuSpecification gpu_spec;
676  auto deviceProperties = cuda_mgr->getDeviceProperties(device_id);
677  gpu_spec.num_sm = deviceProperties->numMPs;
678  gpu_spec.clock_frequency_kHz = deviceProperties->clockKhz;
679  gpu_spec.memory = deviceProperties->globalMem;
680  gpu_spec.compute_capability_major = deviceProperties->computeMajor;
681  gpu_spec.compute_capability_minor = deviceProperties->computeMinor;
682  ret.gpu_info.push_back(gpu_spec);
683  }
684  }
685 
686  // start hardware/OS dependent code
687  ret.num_cpu_hw = std::thread::hardware_concurrency();
688  // ^ This might return diffrent results in case of hyper threading
689  // end hardware/OS dependent code
690 
691  _return.hardware_info.push_back(ret);
692  if (leaf_aggregator_.leafCount() > 0) {
693  ret.host_name = "aggregator";
694  TClusterHardwareInfo leaf_hardware = leaf_aggregator_.getHardwareInfo(session);
695  _return.hardware_info.insert(_return.hardware_info.end(),
696  leaf_hardware.hardware_info.begin(),
697  leaf_hardware.hardware_info.end());
698  }
699 }
ConnectionInfo getConnectionInfo() const
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:496
size_t leafCount() const
TClusterHardwareInfo getHardwareInfo(TSessionId session)
std::shared_ptr< Data_Namespace::DataMgr > data_mgr_
Definition: MapDHandler.h:494
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 4492 of file MapDHandler.cpp.

References get_session_ptr(), STDLOG, and THROW_MAPD_EXCEPTION.

4492  {
4493  auto stdlog = STDLOG(get_session_ptr(session));
4494 #ifdef HAVE_PROFILER
4495  if (!IsHeapProfilerRunning()) {
4496  THROW_MAPD_EXCEPTION("Profiler not running");
4497  }
4498  auto profile_buff = GetHeapProfile();
4499  profile = profile_buff;
4500  free(profile_buff);
4501 #else
4502  THROW_MAPD_EXCEPTION("Profiler not enabled");
4503 #endif // HAVE_PROFILER
4504 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
#define THROW_MAPD_EXCEPTION(errstr)
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 1855 of file MapDHandler.cpp.

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

1857  {
1858  auto stdlog = STDLOG(get_session_ptr(session), "table_name", table_name);
1859  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
1860  get_table_details_impl(_return, stdlog, table_name, true, false);
1861 }
ConnectionInfo getConnectionInfo() const
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
void get_table_details_impl(TTableDetails &_return, query_state::StdLog &stdlog, const std::string &table_name, const bool get_system, const bool get_physical)
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 4394 of file MapDHandler.cpp.

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

4397  {
4398  auto stdlog = STDLOG(get_session_ptr(session), "get_layers_in_geo_file", file_name_in);
4399  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
4400  std::string file_name(file_name_in);
4401 
4403 
4404  // handle relative paths
4405  if (path_is_relative(file_name)) {
4406  // assume relative paths are relative to data_path / mapd_import / <session>
4407  auto file_path = import_path_ / picosha2::hash256_hex_string(session) /
4408  boost::filesystem::path(file_name).filename();
4409  file_name = file_path.string();
4410  }
4411 
4412  // validate file_name
4413  if (is_a_supported_geo_file(file_name, true)) {
4414  // prepare to load geo file directly
4415  add_vsi_network_prefix(file_name);
4416  add_vsi_geo_prefix(file_name);
4417  } else if (is_a_supported_archive_file(file_name)) {
4418  // find the archive file
4419  add_vsi_network_prefix(file_name);
4420  if (!Importer_NS::Importer::gdalFileExists(file_name, copy_params)) {
4421  THROW_MAPD_EXCEPTION("Archive does not exist: " + file_name_in);
4422  }
4423  // find geo file in archive
4424  add_vsi_archive_prefix(file_name);
4425  std::string geo_file = find_first_geo_file_in_archive(file_name, copy_params);
4426  // prepare to load that geo file
4427  if (geo_file.size()) {
4428  file_name = file_name + std::string("/") + geo_file;
4429  }
4430  } else {
4431  THROW_MAPD_EXCEPTION("File is not a supported geo or geo archive file: " +
4432  file_name_in);
4433  }
4434 
4435  // check the file actually exists
4436  if (!Importer_NS::Importer::gdalFileOrDirectoryExists(file_name, copy_params)) {
4437  THROW_MAPD_EXCEPTION("Geo file/archive does not exist: " + file_name_in);
4438  }
4439 
4440  // find all layers
4441  auto internal_layer_info =
4442  Importer_NS::Importer::gdalGetLayersInGeoFile(file_name, copy_params);
4443 
4444  // convert to Thrift type
4445  for (const auto& internal_layer : internal_layer_info) {
4446  TGeoFileLayerInfo layer;
4447  layer.name = internal_layer.name;
4448  switch (internal_layer.contents) {
4450  layer.contents = TGeoFileLayerContents::EMPTY;
4451  break;
4453  layer.contents = TGeoFileLayerContents::GEO;
4454  break;
4456  layer.contents = TGeoFileLayerContents::NON_GEO;
4457  break;
4459  layer.contents = TGeoFileLayerContents::UNSUPPORTED_GEO;
4460  break;
4461  default:
4462  CHECK(false);
4463  }
4464  _return.emplace_back(layer); // no suitable constructor to just pass parameters
4465  }
4466 }
static std::vector< GeoFileLayerInfo > gdalGetLayersInGeoFile(const std::string &file_name, const CopyParams &copy_params)
Definition: Importer.cpp:4623
void add_vsi_network_prefix(std::string &path)
boost::filesystem::path import_path_
Definition: MapDHandler.h:499
ConnectionInfo getConnectionInfo() const
void add_vsi_archive_prefix(std::string &path)
void add_vsi_geo_prefix(std::string &path)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
#define THROW_MAPD_EXCEPTION(errstr)
static bool gdalFileOrDirectoryExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:4526
CHECK(cgen_state)
bool is_a_supported_geo_file(const std::string &path, bool include_gz)
bool path_is_relative(const std::string &path)
static bool gdalFileExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:4521
std::string find_first_geo_file_in_archive(const std::string &archive_path, const Importer_NS::CopyParams &copy_params)
Importer_NS::CopyParams thrift_to_copyparams(const TCopyParams &cp)
#define STDLOG(...)
Definition: QueryState.h:225
bool is_a_supported_archive_file(const std::string &path)

+ Here is the call graph for this function:

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

Definition at line 5737 of file MapDHandler.cpp.

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

5739  {
5740  auto stdlog = STDLOG(get_session_ptr(session));
5741  const auto session_info = get_session_copy(session);
5742  _return.claims.emplace_back("");
5743 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 1972 of file MapDHandler.cpp.

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

1974  {
1975  auto stdlog = STDLOG(get_session_ptr(session));
1976  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
1977  auto session_ptr = stdlog.getConstSessionInfo();
1978  auto const& cat = session_ptr->getCatalog();
1979  auto ld = cat.getMetadataForLink(std::to_string(cat.getCurrentDB().dbId) + link);
1980  if (!ld) {
1981  THROW_MAPD_EXCEPTION("Link " + link + " is not valid.");
1982  }
1983  _return.view_state = ld->viewState;
1984  _return.view_name = ld->link;
1985  _return.update_time = ld->updateTime;
1986  _return.view_metadata = ld->viewMetadata;
1987 }
ConnectionInfo getConnectionInfo() const
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
std::string to_string(char const *&&v)
#define THROW_MAPD_EXCEPTION(errstr)
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 2223 of file MapDHandler.cpp.

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

2225  {
2226  auto stdlog = STDLOG(get_session_ptr(session));
2227  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
2228  std::vector<Data_Namespace::MemoryInfo> internal_memory;
2229  Data_Namespace::MemoryLevel mem_level;
2230  if (!memory_level.compare("gpu")) {
2232  internal_memory =
2233  SysCatalog::instance().getDataMgr().getMemoryInfo(MemoryLevel::GPU_LEVEL);
2234  } else {
2236  internal_memory =
2237  SysCatalog::instance().getDataMgr().getMemoryInfo(MemoryLevel::CPU_LEVEL);
2238  }
2239 
2240  for (auto memInfo : internal_memory) {
2241  TNodeMemoryInfo nodeInfo;
2242  if (leaf_aggregator_.leafCount() > 0) {
2243  nodeInfo.host_name = get_hostname();
2244  }
2245  nodeInfo.page_size = memInfo.pageSize;
2246  nodeInfo.max_num_pages = memInfo.maxNumPages;
2247  nodeInfo.num_pages_allocated = memInfo.numPageAllocated;
2248  nodeInfo.is_allocation_capped = memInfo.isAllocationCapped;
2249  for (auto gpu : memInfo.nodeMemoryData) {
2250  TMemoryData md;
2251  md.slab = gpu.slabNum;
2252  md.start_page = gpu.startPage;
2253  md.num_pages = gpu.numPages;
2254  md.touch = gpu.touch;
2255  md.chunk_key.insert(md.chunk_key.end(), gpu.chunk_key.begin(), gpu.chunk_key.end());
2256  md.is_free = gpu.memStatus == Buffer_Namespace::MemStatus::FREE;
2257  nodeInfo.node_memory_data.push_back(md);
2258  }
2259  _return.push_back(nodeInfo);
2260  }
2261  if (leaf_aggregator_.leafCount() > 0) {
2262  std::vector<TNodeMemoryInfo> leafSummary =
2263  leaf_aggregator_.getLeafMemoryInfo(session, mem_level);
2264  _return.insert(_return.begin(), leafSummary.begin(), leafSummary.end());
2265  }
2266 }
ConnectionInfo getConnectionInfo() const
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:496
size_t leafCount() const
std::vector< TNodeMemoryInfo > getLeafMemoryInfo(TSessionId session, Data_Namespace::MemoryLevel memory_level)
std::string get_hostname()
Definition: SysInfo.cpp:6
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 2047 of file MapDHandler.cpp.

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

2048  {
2049  auto stdlog = STDLOG(get_session_ptr(session));
2050  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
2051  get_tables_impl(table_names, *stdlog.getConstSessionInfo(), GET_PHYSICAL_TABLES);
2052 }
void get_tables_impl(std::vector< std::string > &table_names, const Catalog_Namespace::SessionInfo &, const GetTablesType get_tables_type)
ConnectionInfo getConnectionInfo() const
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 1756 of file MapDHandler.cpp.

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

1764  {
1765  auto stdlog = STDLOG(get_session_ptr(session),
1766  "widget_id",
1767  widget_id,
1768  "pixel.x",
1769  pixel.x,
1770  "pixel.y",
1771  pixel.y,
1772  "column_format",
1773  column_format,
1774  "pixel_radius",
1775  pixel_radius,
1776  "table_col_names",
1777  dump_table_col_names(table_col_names),
1778  "nonce",
1779  nonce);
1780  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
1781  auto session_ptr = stdlog.getSessionInfo();
1782  if (!render_handler_) {
1783  THROW_MAPD_EXCEPTION("Backend rendering is disabled.");
1784  }
1785 
1786  try {
1787  render_handler_->get_result_row_for_pixel(_return,
1788  session_ptr,
1789  widget_id,
1790  pixel,
1791  table_col_names,
1792  column_format,
1793  pixel_radius,
1794  nonce);
1795  } catch (std::exception& e) {
1796  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
1797  }
1798 }
std::unique_ptr< MapDRenderHandler > render_handler_
Definition: MapDHandler.h:514
ConnectionInfo getConnectionInfo() const
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
#define THROW_MAPD_EXCEPTION(errstr)
std::string dump_table_col_names(const std::map< std::string, std::vector< std::string >> &table_col_names)
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 1382 of file MapDHandler.cpp.

References get_session_ptr(), and STDLOG.

1382  {
1383  auto stdlog = STDLOG(get_session_ptr(session));
1384  auto session_ptr = stdlog.getConstSessionInfo();
1385  if (!session_ptr->get_currentUser().isSuper) {
1386  // WARNING: This appears to not include roles a user is a member of,
1387  // if the role has no permissions granted to it.
1388  roles =
1389  SysCatalog::instance().getRoles(session_ptr->get_currentUser().userName,
1390  session_ptr->getCatalog().getCurrentDB().dbId);
1391  } else {
1392  roles = SysCatalog::instance().getRoles(
1393  false, true, session_ptr->get_currentUser().userName);
1394  }
1395 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 618 of file MapDHandler.cpp.

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

618  {
619  auto stdlog = STDLOG(get_session_ptr(session));
620  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
621  const auto rendering_enabled = bool(render_handler_);
622  _return.read_only = read_only_;
623  _return.version = MAPD_RELEASE;
624  _return.rendering_enabled = rendering_enabled;
625  _return.poly_rendering_enabled = rendering_enabled;
626  _return.start_time = start_time_;
627  _return.edition = MAPD_EDITION;
628  _return.host_name = get_hostname();
629 }
std::unique_ptr< MapDRenderHandler > render_handler_
Definition: MapDHandler.h:514
ConnectionInfo getConnectionInfo() const
static const std::string MAPD_EDITION
Definition: release.h:41
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
int64_t start_time_
Definition: MapDHandler.h:511
const bool read_only_
Definition: MapDHandler.h:506
std::string get_hostname()
Definition: SysInfo.cpp:6
static const std::string MAPD_RELEASE
Definition: release.h:43
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 4528 of file MapDHandler.cpp.

References get_session_it_unsafe(), and sessions_mutex_.

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

4528  {
4529  mapd_shared_lock<mapd_shared_mutex> read_lock(sessions_mutex_);
4530  return *get_session_it_unsafe(session, read_lock)->second;
4531 }
SessionMap::iterator get_session_it_unsafe(const TSessionId &session, SESSION_MAP_LOCK &lock)
mapd_shared_mutex sessions_mutex_
Definition: MapDHandler.h:509

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 4533 of file MapDHandler.cpp.

References get_session_it_unsafe(), and sessions_mutex_.

4534  {
4535  // Note(Wamsi): We have `get_const_session_ptr` which would return as const SessionInfo
4536  // stored in the map. You can use `get_const_session_ptr` instead of the copy of
4537  // SessionInfo but beware that it can be changed in teh map. So if you do not care about
4538  // the changes then use `get_const_session_ptr` if you do then use this function to get
4539  // a copy. We should eventually aim to merge both `get_const_session_ptr` and
4540  // `get_session_copy_ptr`.
4541  mapd_shared_lock<mapd_shared_mutex> read_lock(sessions_mutex_);
4542  auto& session_info_ref = *get_session_it_unsafe(session, read_lock)->second;
4543  return std::make_shared<Catalog_Namespace::SessionInfo>(session_info_ref);
4544 }
SessionMap::iterator get_session_it_unsafe(const TSessionId &session, SESSION_MAP_LOCK &lock)
mapd_shared_mutex sessions_mutex_
Definition: MapDHandler.h:509

+ Here is the call graph for this function:

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

Definition at line 701 of file MapDHandler.cpp.

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

701  {
702  auto session_ptr = get_session_ptr(session);
703  auto stdlog = STDLOG(session_ptr);
704  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
705  auto user_metadata = session_ptr->get_currentUser();
706 
707  _return.user = user_metadata.userName;
708  _return.database = session_ptr->getCatalog().getCurrentDB().dbName;
709  _return.start_time = session_ptr->get_start_time();
710  _return.is_super = user_metadata.isSuper;
711 }
ConnectionInfo getConnectionInfo() const
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 141 of file MapDHandler.cpp.

References check_session_exp_unsafe(), disconnect_impl(), anonymous_namespace{MapDHandler.cpp}::get_session_from_map(), sessions_, sessions_mutex_, and THROW_MAPD_EXCEPTION.

143  {
144  auto session_it = get_session_from_map(session, sessions_);
145  try {
146  check_session_exp_unsafe(session_it);
147  } catch (const ForceDisconnect& e) {
148  read_lock.unlock();
149  mapd_unique_lock<mapd_shared_mutex> write_lock(sessions_mutex_);
150  auto session_it2 = get_session_from_map(session, sessions_);
151  disconnect_impl(session_it2, write_lock);
152  THROW_MAPD_EXCEPTION(e.what());
153  }
154  return session_it;
155 }
SessionMap sessions_
Definition: MapDHandler.h:729
void disconnect_impl(const SessionMap::iterator &session_it, mapd_unique_lock< mapd_shared_mutex > &write_lock)
mapd_shared_mutex sessions_mutex_
Definition: MapDHandler.h:509
#define THROW_MAPD_EXCEPTION(errstr)
void check_session_exp_unsafe(const SessionMap::iterator &session_it)
SessionMap::iterator get_session_from_map(const TSessionId &session, SessionMap &session_map)

+ Here is the call graph for this function:

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

Definition at line 158 of file MapDHandler.cpp.

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

160  {
161  auto session_it = get_session_from_map(session, sessions_);
162  try {
163  check_session_exp_unsafe(session_it);
164  } catch (const ForceDisconnect& e) {
165  disconnect_impl(session_it, write_lock);
166  THROW_MAPD_EXCEPTION(e.what());
167  }
168  return session_it;
169 }
SessionMap sessions_
Definition: MapDHandler.h:729
void disconnect_impl(const SessionMap::iterator &session_it, mapd_unique_lock< mapd_shared_mutex > &write_lock)
#define THROW_MAPD_EXCEPTION(errstr)
void check_session_exp_unsafe(const SessionMap::iterator &session_it)
SessionMap::iterator get_session_from_map(const TSessionId &session, SessionMap &session_map)

+ Here is the call graph for this function:

template<typename SESSION_MAP_LOCK >
SessionMap::iterator MapDHandler::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:

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

Definition at line 4546 of file MapDHandler.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_dashboard(), detect_column_types(), get_all_files_in_archive(), get_all_roles_for_user(), get_completion_hints(), get_const_session_ptr(), get_dashboard(), get_dashboard_grantees(), get_dashboards(), get_databases(), get_db_object_privs(), get_db_objects_for_grantee(), get_first_geo_file_in_archive(), get_hardware_info(), get_heap_profile(), get_internal_table_details(), get_layers_in_geo_file(), get_license_claims(), get_link_view(), get_memory(), get_physical_tables(), get_result_row_for_pixel(), get_roles(), get_server_status(), get_session_info(), get_status(), get_table_details(), get_table_epoch(), get_table_epoch_by_name(), get_tables(), get_tables_meta(), get_users(), get_views(), has_object_privilege(), has_role(), import_geo_table(), import_table(), import_table_status(), insert_data(), interrupt(), load_table(), load_table_binary(), load_table_binary_arrow(), load_table_binary_columnar(), render_vega(), replace_dashboard(), set_execution_mode(), set_license_key(), set_table_epoch(), set_table_epoch_by_name(), share_dashboard(), sql_execute(), sql_execute_df(), sql_execute_gdf(), sql_validate(), start_heap_profile(), start_query(), start_render_query(), stop_heap_profile(), switch_database(), and unshare_dashboard().

4547  {
4548  // Note(Wamsi): This method will give you a shared_ptr to master SessionInfo itself.
4549  // Should be used only when you need to make updates to original SessionInfo object.
4550  // Currently used by `update_session_last_used_duration`
4551 
4552  // 1) `session_id` will be empty during intial connect. 2)`sessionmapd iterator` will be
4553  // invalid during disconnect. SessionInfo will be erased from map by the time it reaches
4554  // here. In both the above cases, we would return `nullptr` and can skip SessionInfo
4555  // updates.
4556  if (session_id.empty()) {
4557  return {};
4558  }
4559  mapd_shared_lock<mapd_shared_mutex> read_lock(sessions_mutex_);
4560  return get_session_it_unsafe(session_id, read_lock)->second;
4561 }
SessionMap::iterator get_session_it_unsafe(const TSessionId &session, SESSION_MAP_LOCK &lock)
mapd_shared_mutex sessions_mutex_
Definition: MapDHandler.h:509

+ Here is the call graph for this function:

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

Definition at line 631 of file MapDHandler.cpp.

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

632  {
633  auto stdlog = STDLOG(get_session_ptr(session));
634  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
635  const auto rendering_enabled = bool(render_handler_);
636  TServerStatus ret;
637  ret.read_only = read_only_;
638  ret.version = MAPD_RELEASE;
639  ret.rendering_enabled = rendering_enabled;
640  ret.poly_rendering_enabled = rendering_enabled;
641  ret.start_time = start_time_;
642  ret.edition = MAPD_EDITION;
643  ret.host_name = get_hostname();
644 
645  // TSercivePort tcp_port{}
646 
647  if (g_cluster) {
648  ret.role =
649  (leaf_aggregator_.leafCount() > 0) ? TRole::type::AGGREGATOR : TRole::type::LEAF;
650  } else {
651  ret.role = TRole::type::SERVER;
652  }
653 
654  _return.push_back(ret);
655  if (leaf_aggregator_.leafCount() > 0) {
656  std::vector<TServerStatus> leaf_status = leaf_aggregator_.getLeafStatus(session);
657  _return.insert(_return.end(), leaf_status.begin(), leaf_status.end());
658  }
659 }
std::unique_ptr< MapDRenderHandler > render_handler_
Definition: MapDHandler.h:514
ConnectionInfo getConnectionInfo() const
static const std::string MAPD_EDITION
Definition: release.h:41
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
int64_t start_time_
Definition: MapDHandler.h:511
const bool read_only_
Definition: MapDHandler.h:506
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:496
size_t leafCount() const
bool g_cluster
std::string get_hostname()
Definition: SysInfo.cpp:6
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:

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

Definition at line 1863 of file MapDHandler.cpp.

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

1865  {
1866  auto stdlog = STDLOG(get_session_ptr(session), "table_name", table_name);
1867  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
1868  get_table_details_impl(_return, stdlog, table_name, false, false);
1869 }
ConnectionInfo getConnectionInfo() const
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
void get_table_details_impl(TTableDetails &_return, query_state::StdLog &stdlog, const std::string &table_name, const bool get_system, const bool get_physical)
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 1871 of file MapDHandler.cpp.

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

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

1875  {
1876  try {
1877  auto session_info = stdlog.getSessionInfo();
1878  auto& cat = session_info->getCatalog();
1879  const auto td_with_lock =
1881  cat, table_name, false);
1882  const auto td = td_with_lock();
1883  CHECK(td);
1884 
1885  bool have_privileges_on_view_sources = true;
1886  if (td->isView) {
1887  auto query_state = create_query_state(session_info, td->viewSQL);
1888  stdlog.setQueryState(query_state);
1889  try {
1890  if (hasTableAccessPrivileges(td, *session_info)) {
1891  // TODO(adb): we should take schema read locks on all tables making up the view,
1892  // at minimum
1893  const auto query_ra = parse_to_ra(query_state->createQueryStateProxy(),
1894  query_state->getQueryStr(),
1895  {},
1896  false,
1898  nullptr,
1899  false);
1900  try {
1901  calcite_->checkAccessedObjectsPrivileges(query_state->createQueryStateProxy(),
1902  query_ra.first);
1903  } catch (const std::runtime_error&) {
1904  have_privileges_on_view_sources = false;
1905  }
1906 
1907  TQueryResult result;
1908  execute_rel_alg(result,
1909  query_state->createQueryStateProxy(),
1910  query_ra.first.plan_result,
1911  true,
1913  -1,
1914  -1,
1915  /*just_validate=*/true,
1916  /*find_filter_push_down_candidates=*/false,
1918  _return.row_desc = fixup_row_descriptor(result.row_set.row_desc, cat);
1919  } else {
1920  throw std::runtime_error(
1921  "Unable to access view " + table_name +
1922  ". The view may not exist, or the logged in user may not "
1923  "have permission to access the view.");
1924  }
1925  } catch (const std::exception& e) {
1926  throw std::runtime_error("View '" + table_name +
1927  "' query has failed with an error: '" +
1928  std::string(e.what()) +
1929  "'.\nThe view must be dropped and re-created to "
1930  "resolve the error. \nQuery:\n" +
1931  query_state->getQueryStr());
1932  }
1933  } else {
1934  if (hasTableAccessPrivileges(td, *session_info)) {
1935  const auto col_descriptors =
1936  cat.getAllColumnMetadataForTable(td->tableId, get_system, true, get_physical);
1937  const auto deleted_cd = cat.getDeletedColumn(td);
1938  for (const auto cd : col_descriptors) {
1939  if (cd == deleted_cd) {
1940  continue;
1941  }
1942  _return.row_desc.push_back(populateThriftColumnType(&cat, cd));
1943  }
1944  } else {
1945  throw std::runtime_error(
1946  "Unable to access table " + table_name +
1947  ". The table may not exist, or the logged in user may not "
1948  "have permission to access the table.");
1949  }
1950  }
1951  _return.fragment_size = td->maxFragRows;
1952  _return.page_size = td->fragPageSize;
1953  _return.max_rows = td->maxRows;
1954  _return.view_sql =
1955  (have_privileges_on_view_sources ? td->viewSQL
1956  : "[Not enough privileges to see the view SQL]");
1957  _return.shard_count = td->nShards;
1958  _return.key_metainfo = td->keyMetainfo;
1959  _return.is_temporary = td->persistenceLevel == Data_Namespace::MemoryLevel::CPU_LEVEL;
1960  _return.partition_detail =
1961  td->partitions.empty()
1962  ? TPartitionDetail::DEFAULT
1963  : (table_is_replicated(td)
1964  ? TPartitionDetail::REPLICATED
1965  : (td->partitions == "SHARDED" ? TPartitionDetail::SHARDED
1966  : TPartitionDetail::OTHER));
1967  } catch (const std::runtime_error& e) {
1968  THROW_MAPD_EXCEPTION("Exception: " + std::string(e.what()));
1969  }
1970 }
TColumnType populateThriftColumnType(const Catalog_Namespace::Catalog *cat, const ColumnDescriptor *cd)
static ExplainInfo defaults()
Definition: ParserWrapper.h:57
bool hasTableAccessPrivileges(const TableDescriptor *td, const Catalog_Namespace::SessionInfo &session_info)
#define THROW_MAPD_EXCEPTION(errstr)
TRowDescriptor fixup_row_descriptor(const TRowDescriptor &row_desc, const Catalog_Namespace::Catalog &cat)
const MapDParameters & mapd_parameters_
Definition: MapDHandler.h:513
CHECK(cgen_state)
void setQueryState(std::shared_ptr< QueryState >)
Definition: QueryState.cpp:234
std::shared_ptr< Catalog_Namespace::SessionInfo > getSessionInfo() const
Definition: QueryState.cpp:135
std::shared_ptr< query_state::QueryState > create_query_state(ARGS &&...args)
Definition: MapDHandler.h:521
std::shared_ptr< Calcite > calcite_
Definition: MapDHandler.h:517
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
bool table_is_replicated(const TableDescriptor *td)
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 MapDParameters mapd_parameters, RenderInfo *render_info=nullptr, bool check_privileges=true)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 5697 of file MapDHandler.cpp.

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

5699  {
5700  auto stdlog = STDLOG(get_session_ptr(session));
5701  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
5702  auto session_ptr = stdlog.getConstSessionInfo();
5703  auto const& cat = session_ptr->getCatalog();
5704 
5705  if (leaf_aggregator_.leafCount() > 0) {
5706  return leaf_aggregator_.get_table_epochLeaf(*session_ptr, db_id, table_id);
5707  }
5708  return cat.getTableEpoch(db_id, table_id);
5709 }
int32_t get_table_epochLeaf(const Catalog_Namespace::SessionInfo &parent_session_info, const int32_t db_id, const int32_t table_id)
ConnectionInfo getConnectionInfo() const
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:496
size_t leafCount() const
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 5711 of file MapDHandler.cpp.

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

5712  {
5713  auto stdlog = STDLOG(get_session_ptr(session), "table_name", table_name);
5714  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
5715  auto session_ptr = stdlog.getConstSessionInfo();
5716  auto const& cat = session_ptr->getCatalog();
5717  auto td = cat.getMetadataForTable(
5718  table_name,
5719  false); // don't populate fragmenter on this call since we only want metadata
5720  int32_t db_id = cat.getCurrentDB().dbId;
5721  if (leaf_aggregator_.leafCount() > 0) {
5722  return leaf_aggregator_.get_table_epochLeaf(*session_ptr, db_id, td->tableId);
5723  }
5724  return cat.getTableEpoch(db_id, td->tableId);
5725 }
int32_t get_table_epochLeaf(const Catalog_Namespace::SessionInfo &parent_session_info, const int32_t db_id, const int32_t table_id)
ConnectionInfo getConnectionInfo() const
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:496
size_t leafCount() const
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 2039 of file MapDHandler.cpp.

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

2040  {
2041  auto stdlog = STDLOG(get_session_ptr(session));
2042  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
2044  table_names, *stdlog.getConstSessionInfo(), GET_PHYSICAL_TABLES_AND_VIEWS);
2045 }
void get_tables_impl(std::vector< std::string > &table_names, const Catalog_Namespace::SessionInfo &, const GetTablesType get_tables_type)
ConnectionInfo getConnectionInfo() const
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 2006 of file MapDHandler.cpp.

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

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

2008  {
2009  auto const& cat = session_info.getCatalog();
2010  const auto tables = cat.getAllTableMetadata();
2011  for (const auto td : tables) {
2012  if (td->shard >= 0) {
2013  // skip shards, they're not standalone tables
2014  continue;
2015  }
2016  switch (get_tables_type) {
2017  case GET_PHYSICAL_TABLES: {
2018  if (td->isView) {
2019  continue;
2020  }
2021  break;
2022  }
2023  case GET_VIEWS: {
2024  if (!td->isView) {
2025  continue;
2026  }
2027  }
2028  default:
2029  break;
2030  }
2031  if (!hasTableAccessPrivileges(td, session_info)) {
2032  // skip table, as there are no privileges to access it
2033  continue;
2034  }
2035  table_names.push_back(td->tableName);
2036  }
2037 }
bool hasTableAccessPrivileges(const TableDescriptor *td, const Catalog_Namespace::SessionInfo &session_info)
Catalog & getCatalog() const
Definition: SessionInfo.h:76

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 2061 of file MapDHandler.cpp.

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

2062  {
2063  auto stdlog = STDLOG(get_session_ptr(session));
2064  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
2065  auto session_ptr = stdlog.getConstSessionInfo();
2066  auto query_state = create_query_state(session_ptr, "");
2067  stdlog.setQueryState(query_state);
2068 
2069  const auto& cat = session_ptr->getCatalog();
2070  const auto tables = cat.getAllTableMetadata();
2071  _return.reserve(tables.size());
2072 
2073  for (const auto td : tables) {
2074  if (td->shard >= 0) {
2075  // skip shards, they're not standalone tables
2076  continue;
2077  }
2078  if (!hasTableAccessPrivileges(td, *session_ptr)) {
2079  // skip table, as there are no privileges to access it
2080  continue;
2081  }
2082 
2083  TTableMeta ret;
2084  ret.table_name = td->tableName;
2085  ret.is_view = td->isView;
2086  ret.is_replicated = table_is_replicated(td);
2087  ret.shard_count = td->nShards;
2088  ret.max_rows = td->maxRows;
2089  ret.table_id = td->tableId;
2090 
2091  std::vector<TTypeInfo> col_types;
2092  std::vector<std::string> col_names;
2093  size_t num_cols = 0;
2094  if (td->isView) {
2095  try {
2096  const auto query_ra = parse_to_ra(query_state->createQueryStateProxy(),
2097  td->viewSQL,
2098  {},
2099  false,
2101  .first.plan_result;
2102  TQueryResult result;
2104  query_state->createQueryStateProxy(),
2105  query_ra,
2106  true,
2108  -1,
2109  -1,
2110  /*just_validate=*/true,
2111  /*find_push_down_candidates=*/false,
2113  num_cols = result.row_set.row_desc.size();
2114  for (const auto col : result.row_set.row_desc) {
2115  if (col.is_physical) {
2116  num_cols--;
2117  continue;
2118  }
2119  col_types.push_back(col.col_type);
2120  col_names.push_back(col.col_name);
2121  }
2122  } catch (std::exception& e) {
2123  LOG(WARNING) << "get_tables_meta: Ignoring broken view: " << td->tableName;
2124  }
2125  } else {
2126  try {
2127  if (hasTableAccessPrivileges(td, *session_ptr)) {
2128  const auto col_descriptors =
2129  cat.getAllColumnMetadataForTable(td->tableId, false, true, false);
2130  const auto deleted_cd = cat.getDeletedColumn(td);
2131  for (const auto cd : col_descriptors) {
2132  if (cd == deleted_cd) {
2133  continue;
2134  }
2135  col_types.push_back(ThriftSerializers::type_info_to_thrift(cd->columnType));
2136  col_names.push_back(cd->columnName);
2137  }
2138  num_cols = col_descriptors.size();
2139  } else {
2140  continue;
2141  }
2142  } catch (const std::runtime_error& e) {
2143  THROW_MAPD_EXCEPTION(e.what());
2144  }
2145  }
2146 
2147  ret.num_cols = num_cols;
2148  std::copy(col_types.begin(), col_types.end(), std::back_inserter(ret.col_types));
2149  std::copy(col_names.begin(), col_names.end(), std::back_inserter(ret.col_names));
2150 
2151  _return.push_back(ret);
2152  }
2153 }
static ExplainInfo defaults()
Definition: ParserWrapper.h:57
bool hasTableAccessPrivileges(const TableDescriptor *td, const Catalog_Namespace::SessionInfo &session_info)
#define LOG(tag)
Definition: Logger.h:188
ConnectionInfo getConnectionInfo() const
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
#define THROW_MAPD_EXCEPTION(errstr)
const MapDParameters & mapd_parameters_
Definition: MapDHandler.h:513
std::shared_ptr< query_state::QueryState > create_query_state(ARGS &&...args)
Definition: MapDHandler.h:521
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
bool table_is_replicated(const TableDescriptor *td)
TTypeInfo type_info_to_thrift(const SQLTypeInfo &ti)
#define STDLOG(...)
Definition: QueryState.h:225
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 MapDParameters mapd_parameters, RenderInfo *render_info=nullptr, bool check_privileges=true)

+ Here is the call graph for this function:

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

Definition at line 1245 of file MapDHandler.cpp.

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

Referenced by get_completion_hints_unsorted().

1249  {
1250  const auto last_word =
1251  find_last_word_from_cursor(sql, cursor < 0 ? sql.size() : cursor);
1252  boost::regex select_expr{R"(\s*select\s+)",
1253  boost::regex::extended | boost::regex::icase};
1254  const size_t length_to_cursor =
1255  cursor < 0 ? sql.size() : std::min(sql.size(), static_cast<size_t>(cursor));
1256  // After SELECT but before FROM, look for all columns in all tables which match the
1257  // prefix.
1258  if (boost::regex_search(sql.cbegin(), sql.cbegin() + length_to_cursor, select_expr)) {
1259  const auto column_names_by_table = fill_column_names_by_table(visible_tables, stdlog);
1260  // Trust the fully qualified columns the most.
1261  if (get_qualified_column_hints(hints, last_word, column_names_by_table)) {
1262  return;
1263  }
1264  // Not much information to use, just retrieve column names which match the prefix.
1265  if (should_suggest_column_hints(sql)) {
1266  get_column_hints(hints, last_word, column_names_by_table);
1267  return;
1268  }
1269  const std::string kFromKeyword{"FROM"};
1270  if (boost::istarts_with(kFromKeyword, last_word)) {
1271  TCompletionHint keyword_hint;
1272  k