OmniSciDB  1dac507f6e
 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 int num_gpus, const int start_gpu, const size_t reserved_gpu_mem, const size_t num_reader_threads, const AuthMetadata &authMetadata, const MapDParameters &mapd_parameters, const bool legacy_syntax, const int idle_session_duration, const int max_session_duration, const bool enable_runtime_udf_registration, const std::string &udf_filename)
 
 ~MapDHandler () override
 
void krb5_connect (TKrb5Session &session, const std::string &token, const std::string &dbname) override
 
void connect (TSessionId &session, const std::string &username, const std::string &passwd, const std::string &dbname) override
 
void disconnect (const TSessionId &session) override
 
void switch_database (const TSessionId &session, const std::string &dbname) override
 
void get_server_status (TServerStatus &_return, const TSessionId &session) override
 
void get_status (std::vector< TServerStatus > &_return, const TSessionId &session) override
 
void get_hardware_info (TClusterHardwareInfo &_return, const TSessionId &session) override
 
bool hasTableAccessPrivileges (const TableDescriptor *td, const TSessionId &session)
 
void get_tables (std::vector< std::string > &_return, const TSessionId &session) override
 
void get_physical_tables (std::vector< std::string > &_return, const TSessionId &session) override
 
void get_views (std::vector< std::string > &_return, const TSessionId &session) override
 
void get_tables_meta (std::vector< TTableMeta > &_return, const TSessionId &session) override
 
void get_table_details (TTableDetails &_return, const TSessionId &session, const std::string &table_name) override
 
void get_internal_table_details (TTableDetails &_return, const TSessionId &session, const std::string &table_name) override
 
void get_users (std::vector< std::string > &_return, const TSessionId &session) override
 
void get_databases (std::vector< TDBInfo > &_return, const TSessionId &session) override
 
void get_version (std::string &_return) override
 
void start_heap_profile (const TSessionId &session) override
 
void stop_heap_profile (const TSessionId &session) override
 
void get_heap_profile (std::string &_return, const TSessionId &session) override
 
void get_memory (std::vector< TNodeMemoryInfo > &_return, const TSessionId &session, const std::string &memory_level) override
 
void clear_cpu_memory (const TSessionId &session) override
 
void clear_gpu_memory (const TSessionId &session) override
 
void set_table_epoch (const TSessionId &session, const int db_id, const int table_id, const int new_epoch) override
 
void set_table_epoch_by_name (const TSessionId &session, const std::string &table_name, const int new_epoch) override
 
int32_t get_table_epoch (const TSessionId &session, const int32_t db_id, const int32_t table_id) override
 
int32_t get_table_epoch_by_name (const TSessionId &session, const std::string &table_name) override
 
void get_session_info (TSessionInfo &_return, const TSessionId &session) override
 
void sql_execute (TQueryResult &_return, const TSessionId &session, const std::string &query, const bool column_format, const std::string &nonce, const int32_t first_n, const int32_t at_most_n) override
 
void get_completion_hints (std::vector< TCompletionHint > &hints, const TSessionId &session, const std::string &sql, const int cursor) override
 
void sql_execute_df (TDataFrame &_return, const TSessionId &session, const std::string &query, const TDeviceType::type device_type, const int32_t device_id, const int32_t first_n) override
 
void sql_execute_gdf (TDataFrame &_return, const TSessionId &session, const std::string &query, const int32_t device_id, const int32_t first_n) override
 
void deallocate_df (const TSessionId &session, const TDataFrame &df, const TDeviceType::type device_type, const int32_t device_id) override
 
void interrupt (const TSessionId &session) override
 
void sql_validate (TTableDescriptor &_return, const TSessionId &session, const std::string &query) override
 
void set_execution_mode (const TSessionId &session, const TExecuteMode::type mode) override
 
void render_vega (TRenderResult &_return, const TSessionId &session, const int64_t widget_id, const std::string &vega_json, const int32_t compression_level, const std::string &nonce) override
 
void get_result_row_for_pixel (TPixelTableRowResult &_return, const TSessionId &session, const int64_t widget_id, const TPixel &pixel, const std::map< std::string, std::vector< std::string >> &table_col_names, const bool column_format, const int32_t pixel_radius, const std::string &nonce) override
 
void get_dashboard (TDashboard &_return, const TSessionId &session, int32_t dashboard_id) override
 
void get_dashboards (std::vector< TDashboard > &_return, const TSessionId &session) override
 
int32_t create_dashboard (const TSessionId &session, const std::string &dashboard_name, const std::string &dashboard_state, const std::string &image_hash, const std::string &dashboard_metadata) override
 
void replace_dashboard (const TSessionId &session, const int32_t dashboard_id, const std::string &dashboard_name, const std::string &dashboard_owner, const std::string &dashboard_state, const std::string &image_hash, const std::string &dashboard_metadata) override
 
void delete_dashboard (const TSessionId &session, const int32_t dashboard_id) override
 
void share_dashboard (const TSessionId &session, const int32_t dashboard_id, const std::vector< std::string > &groups, const std::vector< std::string > &objects, const TDashboardPermissions &permissions, const bool grant_role) override
 
void unshare_dashboard (const TSessionId &session, const int32_t dashboard_id, const std::vector< std::string > &groups, const std::vector< std::string > &objects, const TDashboardPermissions &permissions) override
 
void get_dashboard_grantees (std::vector< TDashboardGrantees > &_return, const TSessionId &session, int32_t dashboard_id) override
 
void get_link_view (TFrontendView &_return, const TSessionId &session, const std::string &link) override
 
void create_link (std::string &_return, const TSessionId &session, const std::string &view_state, const std::string &view_metadata) override
 
void load_table_binary (const TSessionId &session, const std::string &table_name, const std::vector< TRow > &rows) override
 
void prepare_columnar_loader (const Catalog_Namespace::SessionInfo &session_info, const std::string &table_name, size_t num_cols, std::unique_ptr< Importer_NS::Loader > *loader, std::vector< std::unique_ptr< Importer_NS::TypedImportBuffer >> *import_buffers)
 
void load_table_binary_columnar (const TSessionId &session, const std::string &table_name, const std::vector< TColumn > &cols) override
 
void load_table_binary_arrow (const TSessionId &session, const std::string &table_name, const std::string &arrow_stream) override
 
void load_table (const TSessionId &session, const std::string &table_name, const std::vector< TStringRow > &rows) override
 
void detect_column_types (TDetectResult &_return, const TSessionId &session, const std::string &file_name, const TCopyParams &copy_params) override
 
void create_table (const TSessionId &session, const std::string &table_name, const TRowDescriptor &row_desc, const TFileType::type file_type, const TCreateParams &create_params) override
 
void import_table (const TSessionId &session, const std::string &table_name, const std::string &file_name, const TCopyParams &copy_params) override
 
void import_geo_table (const TSessionId &session, const std::string &table_name, const std::string &file_name, const TCopyParams &copy_params, const TRowDescriptor &row_desc, const TCreateParams &create_params) override
 
void import_table_status (TImportStatus &_return, const TSessionId &session, const std::string &import_id) override
 
void get_first_geo_file_in_archive (std::string &_return, const TSessionId &session, const std::string &archive_path, const TCopyParams &copy_params) override
 
void get_all_files_in_archive (std::vector< std::string > &_return, const TSessionId &session, const std::string &archive_path, const TCopyParams &copy_params) override
 
void get_layers_in_geo_file (std::vector< TGeoFileLayerInfo > &_return, const TSessionId &session, const std::string &file_name, const TCopyParams &copy_params) override
 
void check_table_consistency (TTableMeta &_return, const TSessionId &session, const int32_t table_id) override
 
void start_query (TPendingQuery &_return, const TSessionId &session, const std::string &query_ra, const bool just_explain) override
 
void execute_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_lock_guard< mapd_shared_mutex > &write_lock)
 

Static Public Member Functions

static size_t max_bytes_for_thrift ()
 

Public Attributes

std::shared_ptr
< Data_Namespace::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

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

Static Private Member Functions

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

Private Attributes

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

Friends

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

Detailed Description

Definition at line 115 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 int  num_gpus,
const int  start_gpu,
const size_t  reserved_gpu_mem,
const size_t  num_reader_threads,
const AuthMetadata authMetadata,
const MapDParameters mapd_parameters,
const bool  legacy_syntax,
const int  idle_session_duration,
const int  max_session_duration,
const bool  enable_runtime_udf_registration,
const std::string &  udf_filename 
)

Definition at line 167 of file MapDHandler.cpp.

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

Definition at line 343 of file MapDHandler.cpp.

343 {}

Member Function Documentation

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

Definition at line 1057 of file MapDHandler.cpp.

References apply_shim(), and run_benchmark_import::result.

Referenced by sql_execute_impl().

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

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

5448  {
5449  if (!leaf_handler_) {
5450  THROW_MAPD_EXCEPTION("Distributed support is disabled.");
5451  }
5452  LOG(INFO) << "BROADCAST-SERIALIZED-ROWS id:" << query_id;
5453  auto time_ms = measure<>::execution([&]() {
5454  try {
5455  leaf_handler_->broadcast_serialized_rows(serialized_rows, row_desc, query_id);
5456  } catch (std::exception& e) {
5457  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
5458  }
5459  });
5460  LOG(INFO) << "BROADCAST-SERIALIZED-ROWS COMPLETED " << time_ms << "ms";
5461 }
static TimeT::rep execution(F func, Args &&...args)
Definition: sample.cpp:29
#define LOG(tag)
Definition: Logger.h:185
#define THROW_MAPD_EXCEPTION(errstr)
std::unique_ptr< MapDLeafHandler > leaf_handler_
Definition: MapDHandler.h:463

+ Here is the call graph for this function:

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

Definition at line 4847 of file MapDHandler.cpp.

References invalidate_sessions().

Referenced by sql_execute_impl().

4847  {
4848  const auto drop_db_stmt = dynamic_cast<Parser::DropDBStmt*>(ddl);
4849  if (drop_db_stmt) {
4850  invalidate_sessions(*drop_db_stmt->getDatabaseName(), drop_db_stmt);
4851  return;
4852  }
4853  const auto rename_db_stmt = dynamic_cast<Parser::RenameDatabaseStmt*>(ddl);
4854  if (rename_db_stmt) {
4855  invalidate_sessions(*rename_db_stmt->getPreviousDatabaseName(), rename_db_stmt);
4856  return;
4857  }
4858  const auto drop_user_stmt = dynamic_cast<Parser::DropUserStmt*>(ddl);
4859  if (drop_user_stmt) {
4860  invalidate_sessions(*drop_user_stmt->getUserName(), drop_user_stmt);
4861  return;
4862  }
4863  const auto rename_user_stmt = dynamic_cast<Parser::RenameUserStmt*>(ddl);
4864  if (rename_user_stmt) {
4865  invalidate_sessions(*rename_user_stmt->getOldUserName(), rename_user_stmt);
4866  return;
4867  }
4868 }
void invalidate_sessions(std::string &name, STMT_TYPE *stmt)
Definition: MapDHandler.h:717

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 3511 of file MapDHandler.cpp.

References Importer_NS::Importer::gdalFileExists().

Referenced by detect_column_types(), and import_geo_table().

3512  {
3513  const std::list<std::string> shp_ext{".shp", ".shx", ".dbf"};
3514  if (std::find(shp_ext.begin(),
3515  shp_ext.end(),
3516  boost::algorithm::to_lower_copy(file_path.extension().string())) !=
3517  shp_ext.end()) {
3518  for (auto ext : shp_ext) {
3519  auto aux_file = file_path;
3521  aux_file.replace_extension(boost::algorithm::to_upper_copy(ext)).string(),
3522  copy_params) &&
3523  !Importer_NS::Importer::gdalFileExists(aux_file.replace_extension(ext).string(),
3524  copy_params)) {
3525  throw std::runtime_error("required file for shapefile does not exist: " +
3526  aux_file.filename().string());
3527  }
3528  }
3529  }
3530 }
static bool gdalFileExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:4457

+ 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 345 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().

345  {
347  THROW_MAPD_EXCEPTION(str + " disabled: server running in read-only mode.");
348  }
349 }
#define THROW_MAPD_EXCEPTION(errstr)
const bool read_only_
Definition: MapDHandler.h:453

+ Here is the caller graph for this function:

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

Definition at line 4364 of file MapDHandler.cpp.

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

4364  {
4365  if (session_it->second.use_count() > 2 ||
4366  isInMemoryCalciteSession(session_it->second->get_currentUser())) {
4367  // SessionInfo is being used in more than one active operation. Original copy + one
4368  // stored in StdLog. Skip the checks.
4369  return;
4370  }
4371  time_t last_used_time = session_it->second->get_last_used_time();
4372  time_t start_time = session_it->second->get_start_time();
4373  if ((time(0) - last_used_time) > idle_session_duration_) {
4374  throw ForceDisconnect("Idle Session Timeout. User should re-authenticate.");
4375  } else if ((time(0) - start_time) > max_session_duration_) {
4376  throw ForceDisconnect("Maximum active Session Timeout. User should re-authenticate.");
4377  }
4378 }
bool isInMemoryCalciteSession(const Catalog_Namespace::UserMetadata user_meta)
const int idle_session_duration_
Definition: MapDHandler.h:685
const int max_session_duration_
Definition: MapDHandler.h:686

+ Here is the call graph for this function:

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

Definition at line 5395 of file MapDHandler.cpp.

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

5397  {
5398  auto stdlog = STDLOG(get_session_ptr(session));
5399  if (!leaf_handler_) {
5400  THROW_MAPD_EXCEPTION("Distributed support is disabled.");
5401  }
5402  try {
5403  leaf_handler_->check_table_consistency(_return, session, table_id);
5404  } catch (std::exception& e) {
5405  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
5406  }
5407 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
#define THROW_MAPD_EXCEPTION(errstr)
std::unique_ptr< MapDLeafHandler > leaf_handler_
Definition: MapDHandler.h:463
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 4437 of file MapDHandler.cpp.

References get_session_copy().

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

4438  {
4439  const auto session_info = get_session_copy(session);
4440  check_table_load_privileges(session_info, table_name);
4441 }
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 4420 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.

4422  {
4423  auto user_metadata = session_info.get_currentUser();
4424  auto& cat = session_info.getCatalog();
4425  DBObject dbObject(table_name, TableDBObjectType);
4426  dbObject.loadKey(cat);
4427  dbObject.setPrivileges(AccessPrivileges::INSERT_INTO_TABLE);
4428  std::vector<DBObject> privObjects;
4429  privObjects.push_back(dbObject);
4430  if (!SysCatalog::instance().checkPrivileges(user_metadata, privObjects)) {
4431  THROW_MAPD_EXCEPTION("Violation of access privileges: user " +
4432  user_metadata.userName + " has no insert privileges for table " +
4433  table_name + ".");
4434  }
4435 }
static const AccessPrivileges INSERT_INTO_TABLE
Definition: DBObject.h:154
#define THROW_MAPD_EXCEPTION(errstr)
Catalog & getCatalog() const
Definition: SessionInfo.h:90
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:93

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

References get_session_ptr(), and STDLOG.

5596  {
5597  auto stdlog = STDLOG(get_session_ptr(session));
5598  auto session_ptr = stdlog.getConstSessionInfo();
5599  auto& cat = session_ptr->getCatalog();
5600  cat.getDataMgr().checkpoint(db_id, table_id);
5601 }
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 2068 of file MapDHandler.cpp.

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

2068  {
2069  auto stdlog = STDLOG(get_session_ptr(session));
2070  auto session_ptr = stdlog.getConstSessionInfo();
2071  if (!session_ptr->get_currentUser().isSuper) {
2072  THROW_MAPD_EXCEPTION("Superuser privilege is required to run clear_cpu_memory");
2073  }
2074  try {
2076  } catch (const std::exception& e) {
2077  THROW_MAPD_EXCEPTION(e.what());
2078  }
2079  if (render_handler_) {
2080  render_handler_->clear_cpu_memory();
2081  }
2082 
2083  if (leaf_aggregator_.leafCount() > 0) {
2085  }
2086 }
std::unique_ptr< MapDRenderHandler > render_handler_
Definition: MapDHandler.h:461
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
static void clearMemory(const Data_Namespace::MemoryLevel memory_level)
Definition: Execute.cpp:160
#define THROW_MAPD_EXCEPTION(errstr)
void clear_leaf_cpu_memory(const TSessionId session)
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:443
size_t leafCount() const
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 2048 of file MapDHandler.cpp.

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

2048  {
2049  auto stdlog = STDLOG(get_session_ptr(session));
2050  auto session_ptr = stdlog.getConstSessionInfo();
2051  if (!session_ptr->get_currentUser().isSuper) {
2052  THROW_MAPD_EXCEPTION("Superuser privilege is required to run clear_gpu_memory");
2053  }
2054  try {
2056  } catch (const std::exception& e) {
2057  THROW_MAPD_EXCEPTION(e.what());
2058  }
2059  if (render_handler_) {
2060  render_handler_->clear_gpu_memory();
2061  }
2062 
2063  if (leaf_aggregator_.leafCount() > 0) {
2065  }
2066 }
std::unique_ptr< MapDRenderHandler > render_handler_
Definition: MapDHandler.h:461
void clear_leaf_gpu_memory(const TSessionId session)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
static void clearMemory(const Data_Namespace::MemoryLevel memory_level)
Definition: Execute.cpp:160
#define THROW_MAPD_EXCEPTION(errstr)
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:443
size_t leafCount() const
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 425 of file MapDHandler.cpp.

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

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

+ Here is the call graph for this function:

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

Definition at line 454 of file MapDHandler.cpp.

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

Referenced by connect(), and internal_connect().

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

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

References create_simple_result().

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

4821  {
4822  create_simple_result(_return, results, column_format, "Explanation");
4823 }
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 4825 of file MapDHandler.cpp.

References create_simple_result().

Referenced by sql_execute_impl().

4827  {
4828  create_simple_result(_return, results, column_format, "Result");
4829 }
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 4712 of file MapDHandler.cpp.

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

Referenced by execute_rel_alg(), and execute_root_plan().

4718  {
4719  query_state::Timer timer = query_state_proxy.createTimer(__func__);
4720  _return.row_set.row_desc = convert_target_metainfo(targets);
4721  int32_t fetched{0};
4722  if (column_format) {
4723  _return.row_set.is_columnar = true;
4724  std::vector<TColumn> tcolumns(results.colCount());
4725  while (first_n == -1 || fetched < first_n) {
4726  const auto crt_row = results.getNextRow(true, true);
4727  if (crt_row.empty()) {
4728  break;
4729  }
4730  ++fetched;
4731  if (at_most_n >= 0 && fetched > at_most_n) {
4732  THROW_MAPD_EXCEPTION("The result contains more rows than the specified cap of " +
4733  std::to_string(at_most_n));
4734  }
4735  for (size_t i = 0; i < results.colCount(); ++i) {
4736  const auto agg_result = crt_row[i];
4737  value_to_thrift_column(agg_result, targets[i].get_type_info(), tcolumns[i]);
4738  }
4739  }
4740  for (size_t i = 0; i < results.colCount(); ++i) {
4741  _return.row_set.columns.push_back(tcolumns[i]);
4742  }
4743  } else {
4744  _return.row_set.is_columnar = false;
4745  while (first_n == -1 || fetched < first_n) {
4746  const auto crt_row = results.getNextRow(true, true);
4747  if (crt_row.empty()) {
4748  break;
4749  }
4750  ++fetched;
4751  if (at_most_n >= 0 && fetched > at_most_n) {
4752  THROW_MAPD_EXCEPTION("The result contains more rows than the specified cap of " +
4753  std::to_string(at_most_n));
4754  }
4755  TRow trow;
4756  trow.cols.reserve(results.colCount());
4757  for (size_t i = 0; i < results.colCount(); ++i) {
4758  const auto agg_result = crt_row[i];
4759  trow.cols.push_back(value_to_thrift(agg_result, targets[i].get_type_info()));
4760  }
4761  _return.row_set.rows.push_back(trow);
4762  }
4763  }
4764 }
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:111
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 4671 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().

4672  {
4673  TColumnType proj_info;
4674  proj_info.col_name = target.get_resname();
4675  if (proj_info.col_name.empty()) {
4676  proj_info.col_name = "result_" + std::to_string(idx + 1);
4677  }
4678  const auto& target_ti = target.get_type_info();
4679  proj_info.col_type.type = type_to_thrift(target_ti);
4680  proj_info.col_type.encoding = encoding_to_thrift(target_ti);
4681  proj_info.col_type.nullable = !target_ti.get_notnull();
4682  proj_info.col_type.is_array = target_ti.get_type() == kARRAY;
4683  if (IS_GEO(target_ti.get_type())) {
4685  proj_info, target_ti.get_subtype(), target_ti.get_output_srid());
4686  } else {
4687  proj_info.col_type.precision = target_ti.get_precision();
4688  proj_info.col_type.scale = target_ti.get_scale();
4689  }
4690  if (target_ti.get_type() == kDATE) {
4691  proj_info.col_type.size = target_ti.get_size();
4692  }
4693  proj_info.col_type.comp_param =
4694  (target_ti.is_date_in_days() && target_ti.get_comp_param() == 0)
4695  ? 32
4696  : target_ti.get_comp_param();
4697  return proj_info;
4698 }
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:56
const std::string & get_resname() const
SQLTypes type
Definition: sqltypes.h:669
#define IS_GEO(T)
Definition: sqltypes.h:167
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 4700 of file MapDHandler.cpp.

References convert_target_metainfo().

4701  {
4702  TRowDescriptor row_desc;
4703  size_t i = 0;
4704  for (const auto target : targets) {
4705  row_desc.push_back(convert_target_metainfo(target, i));
4706  ++i;
4707  }
4708  return row_desc;
4709 }
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 2698 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().

2698  {
2699  TCopyParams copy_params;
2700  copy_params.delimiter = cp.delimiter;
2701  copy_params.null_str = cp.null_str;
2702  switch (cp.has_header) {
2704  copy_params.has_header = TImportHeaderRow::AUTODETECT;
2705  break;
2707  copy_params.has_header = TImportHeaderRow::NO_HEADER;
2708  break;
2710  copy_params.has_header = TImportHeaderRow::HAS_HEADER;
2711  break;
2712  default:
2713  CHECK(false);
2714  break;
2715  }
2716  copy_params.quoted = cp.quoted;
2717  copy_params.quote = cp.quote;
2718  copy_params.escape = cp.escape;
2719  copy_params.line_delim = cp.line_delim;
2720  copy_params.array_delim = cp.array_delim;
2721  copy_params.array_begin = cp.array_begin;
2722  copy_params.array_end = cp.array_end;
2723  copy_params.threads = cp.threads;
2724  copy_params.s3_access_key = cp.s3_access_key;
2725  copy_params.s3_secret_key = cp.s3_secret_key;
2726  copy_params.s3_region = cp.s3_region;
2727  copy_params.s3_endpoint = cp.s3_endpoint;
2728  switch (cp.file_type) {
2730  copy_params.file_type = TFileType::POLYGON;
2731  break;
2732  default:
2733  copy_params.file_type = TFileType::DELIMITED;
2734  break;
2735  }
2736  switch (cp.geo_coords_encoding) {
2737  case kENCODING_GEOINT:
2738  copy_params.geo_coords_encoding = TEncodingType::GEOINT;
2739  break;
2740  default:
2741  copy_params.geo_coords_encoding = TEncodingType::NONE;
2742  break;
2743  }
2744  copy_params.geo_coords_comp_param = cp.geo_coords_comp_param;
2745  switch (cp.geo_coords_type) {
2746  case kGEOGRAPHY:
2747  copy_params.geo_coords_type = TDatumType::GEOGRAPHY;
2748  break;
2749  case kGEOMETRY:
2750  copy_params.geo_coords_type = TDatumType::GEOMETRY;
2751  break;
2752  default:
2753  CHECK(false);
2754  break;
2755  }
2756  copy_params.geo_coords_srid = cp.geo_coords_srid;
2757  copy_params.sanitize_column_names = cp.sanitize_column_names;
2758  copy_params.geo_layer_name = cp.geo_layer_name;
2759  copy_params.geo_assign_render_groups = cp.geo_assign_render_groups;
2760  copy_params.geo_explode_collections = cp.geo_explode_collections;
2761  return copy_params;
2762 }
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 3215 of file MapDHandler.cpp.

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

3219  {
3220  auto stdlog = STDLOG(get_session_ptr(session));
3221  auto session_ptr = stdlog.getConstSessionInfo();
3222  check_read_only("create_dashboard");
3223  auto& cat = session_ptr->getCatalog();
3224 
3225  if (!session_ptr->checkDBAccessPrivileges(DBObjectType::DashboardDBObjectType,
3227  THROW_MAPD_EXCEPTION("Not enough privileges to create a dashboard.");
3228  }
3229 
3230  auto dash = cat.getMetadataForDashboard(
3231  std::to_string(session_ptr->get_currentUser().userId), dashboard_name);
3232  if (dash) {
3233  THROW_MAPD_EXCEPTION("Dashboard with name: " + dashboard_name + " already exists.");
3234  }
3235 
3237  dd.dashboardName = dashboard_name;
3238  dd.dashboardState = dashboard_state;
3239  dd.imageHash = image_hash;
3240  dd.dashboardMetadata = dashboard_metadata;
3241  dd.userId = session_ptr->get_currentUser().userId;
3242  dd.user = session_ptr->get_currentUser().userName;
3243 
3244  try {
3245  auto id = cat.createDashboard(dd);
3246  // TODO: transactionally unsafe
3247  SysCatalog::instance().createDBObject(
3248  session_ptr->get_currentUser(), dashboard_name, DashboardDBObjectType, cat, id);
3249  return id;
3250  } catch (const std::exception& e) {
3251  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
3252  }
3253 }
static const AccessPrivileges CREATE_DASHBOARD
Definition: DBObject.h:163
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
std::string to_string(char const *&&v)
#define THROW_MAPD_EXCEPTION(errstr)
void check_read_only(const std::string &str)
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 3501 of file MapDHandler.cpp.

References run_benchmark_import::type.

3503  {
3504  TColumnType ct;
3505  ct.col_name = name;
3506  ct.col_type.type = type;
3507  ct.col_type.is_array = is_array;
3508  return ct;
3509 }
void MapDHandler::create_link ( std::string &  _return,
const TSessionId &  session,
const std::string &  view_state,
const std::string &  view_metadata 
)
override

Definition at line 3480 of file MapDHandler.cpp.

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

3483  {
3484  auto stdlog = STDLOG(get_session_ptr(session));
3485  auto session_ptr = stdlog.getConstSessionInfo();
3486  // check_read_only("create_link");
3487  auto& cat = session_ptr->getCatalog();
3488 
3489  LinkDescriptor ld;
3490  ld.userId = session_ptr->get_currentUser().userId;
3491  ld.viewState = view_state;
3492  ld.viewMetadata = view_metadata;
3493 
3494  try {
3495  _return = cat.createLink(ld, 6);
3496  } catch (const std::exception& e) {
3497  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
3498  }
3499 }
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:

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

Definition at line 468 of file MapDHandler.h.

References run_benchmark_import::args.

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

468  {
469  return query_states_.create(std::forward<ARGS>(args)...);
470  }
CircleBuffer::value_type create(ARGS &&...args)
Definition: QueryState.h:185
query_state::QueryStates query_states_
Definition: MapDHandler.h:679

+ Here is the 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 4782 of file MapDHandler.cpp.

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

Referenced by convert_explain(), and convert_result().

4785  {
4786  CHECK_EQ(size_t(1), results.rowCount());
4787  TColumnType proj_info;
4788  proj_info.col_name = label;
4789  proj_info.col_type.type = TDatumType::STR;
4790  proj_info.col_type.nullable = false;
4791  proj_info.col_type.is_array = false;
4792  _return.row_set.row_desc.push_back(proj_info);
4793  const auto crt_row = results.getNextRow(true, true);
4794  const auto tv = crt_row[0];
4795  CHECK(results.getNextRow(true, true).empty());
4796  const auto scalar_tv = boost::get<ScalarTargetValue>(&tv);
4797  CHECK(scalar_tv);
4798  const auto s_n = boost::get<NullableString>(scalar_tv);
4799  CHECK(s_n);
4800  const auto s = boost::get<std::string>(s_n);
4801  CHECK(s);
4802  if (column_format) {
4803  TColumn tcol;
4804  tcol.data.str_col.push_back(*s);
4805  tcol.nulls.push_back(false);
4806  _return.row_set.is_columnar = true;
4807  _return.row_set.columns.push_back(tcol);
4808  } else {
4809  TDatum explanation;
4810  explanation.val.str_val = *s;
4811  explanation.is_null = false;
4812  TRow trow;
4813  trow.cols.push_back(explanation);
4814  _return.row_set.is_columnar = false;
4815  _return.row_set.rows.push_back(trow);
4816  }
4817 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
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 3532 of file MapDHandler.cpp.

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

Referenced by import_geo_table().

3536  {
3537  auto stdlog = STDLOG("table_name", table_name);
3538  check_read_only("create_table");
3539 
3540  if (ImportHelpers::is_reserved_name(table_name)) {
3541  THROW_MAPD_EXCEPTION("Invalid table name (reserved keyword): " + table_name);
3542  } else if (table_name != ImportHelpers::sanitize_name(table_name)) {
3543  THROW_MAPD_EXCEPTION("Invalid characters in table name: " + table_name);
3544  }
3545 
3546  auto rds = rd;
3547 
3548  // no longer need to manually add the poly column for a TFileType::POLYGON table
3549  // a column of the correct geo type has already been added
3550  // @TODO simon.eves rename TFileType::POLYGON to TFileType::GEO or something!
3551 
3552  std::string stmt{"CREATE TABLE " + table_name};
3553  std::vector<std::string> col_stmts;
3554 
3555  for (auto col : rds) {
3556  if (ImportHelpers::is_reserved_name(col.col_name)) {
3557  THROW_MAPD_EXCEPTION("Invalid column name (reserved keyword): " + col.col_name);
3558  } else if (col.col_name != ImportHelpers::sanitize_name(col.col_name)) {
3559  THROW_MAPD_EXCEPTION("Invalid characters in column name: " + col.col_name);
3560  }
3561  if (col.col_type.type == TDatumType::INTERVAL_DAY_TIME ||
3562  col.col_type.type == TDatumType::INTERVAL_YEAR_MONTH) {
3563  THROW_MAPD_EXCEPTION("Unsupported type: " + thrift_to_name(col.col_type) +
3564  " for column: " + col.col_name);
3565  }
3566 
3567  if (col.col_type.type == TDatumType::DECIMAL) {
3568  // if no precision or scale passed in set to default 14,7
3569  if (col.col_type.precision == 0 && col.col_type.scale == 0) {
3570  col.col_type.precision = 14;
3571  col.col_type.scale = 7;
3572  }
3573  }
3574 
3575  std::string col_stmt;
3576  col_stmt.append(col.col_name + " " + thrift_to_name(col.col_type));
3577 
3578  // As of 2016-06-27 the Immerse v1 frontend does not explicitly set the
3579  // `nullable` argument, leading this to default to false. Uncomment for v2.
3580  // if (!col.col_type.nullable) col_stmt.append(" NOT NULL");
3581 
3582  if (thrift_to_encoding(col.col_type.encoding) != kENCODING_NONE) {
3583  col_stmt.append(" ENCODING " + thrift_to_encoding_name(col.col_type));
3584  if (thrift_to_encoding(col.col_type.encoding) == kENCODING_DICT ||
3585  thrift_to_encoding(col.col_type.encoding) == kENCODING_FIXED ||
3586  thrift_to_encoding(col.col_type.encoding) == kENCODING_GEOINT) {
3587  col_stmt.append("(" + std::to_string(col.col_type.comp_param) + ")");
3588  }
3589  } else if (col.col_type.type == TDatumType::STR) {
3590  // non DICT encoded strings
3591  col_stmt.append(" ENCODING NONE");
3592  } else if (col.col_type.type == TDatumType::POINT ||
3593  col.col_type.type == TDatumType::LINESTRING ||
3594  col.col_type.type == TDatumType::POLYGON ||
3595  col.col_type.type == TDatumType::MULTIPOLYGON) {
3596  // non encoded compressable geo
3597  if (col.col_type.scale == 4326) {
3598  col_stmt.append(" ENCODING NONE");
3599  }
3600  }
3601  col_stmts.push_back(col_stmt);
3602  }
3603 
3604  stmt.append(" (" + boost::algorithm::join(col_stmts, ", ") + ")");
3605 
3606  if (create_params.is_replicated) {
3607  stmt.append(" WITH (PARTITIONS = 'REPLICATED')");
3608  }
3609 
3610  stmt.append(";");
3611 
3612  TQueryResult ret;
3613  sql_execute(ret, session, stmt, true, "", -1, -1);
3614 }
EncodingType thrift_to_encoding(const TEncodingType::type tEncodingType)
std::string join(T const &container, std::string const &delim)
std::string to_string(char const *&&v)
#define THROW_MAPD_EXCEPTION(errstr)
bool is_reserved_name(const std::string &name)
std::string sanitize_name(const std::string &name)
std::string thrift_to_encoding_name(const TTypeInfo &ti)
std::string thrift_to_name(const TTypeInfo &ti)
void check_read_only(const std::string &str)
void sql_execute(TQueryResult &_return, const TSessionId &session, const std::string &query, const bool column_format, const std::string &nonce, const int32_t first_n, const int32_t at_most_n) override
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 351 of file MapDHandler.cpp.

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

Referenced by parse_to_ra().

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

+ 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 1029 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.

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

+ Here is the call graph for this function:

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

Definition at line 3293 of file MapDHandler.cpp.

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

3294  {
3295  auto stdlog = STDLOG(get_session_ptr(session));
3296  auto session_ptr = stdlog.getConstSessionInfo();
3297  check_read_only("delete_dashboard");
3298  auto& cat = session_ptr->getCatalog();
3299  auto dash = cat.getMetadataForDashboard(dashboard_id);
3300  if (!dash) {
3301  THROW_MAPD_EXCEPTION("Dashboard with id" + std::to_string(dashboard_id) +
3302  " doesn't exist, so cannot delete it");
3303  }
3305  *session_ptr, dash->dashboardId, AccessPrivileges::DELETE_DASHBOARD)) {
3306  THROW_MAPD_EXCEPTION("Not enough privileges to delete a dashboard.");
3307  }
3308  try {
3309  cat.deleteMetadataForDashboard(dashboard_id);
3310  } catch (const std::exception& e) {
3311  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
3312  }
3313 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
std::string to_string(char const *&&v)
#define THROW_MAPD_EXCEPTION(errstr)
static bool is_allowed_on_dashboard(const Catalog_Namespace::SessionInfo &session_info, int32_t dashboard_id, AccessPrivileges requestedPermissions)
void check_read_only(const std::string &str)
static const AccessPrivileges DELETE_DASHBOARD
Definition: DBObject.h:166
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 2909 of file MapDHandler.cpp.

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

Referenced by import_geo_table().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 486 of file MapDHandler.cpp.

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

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

+ Here is the call graph for this function:

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

Definition at line 497 of file MapDHandler.cpp.

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

Referenced by disconnect().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void MapDHandler::emergency_shutdown ( )

Definition at line 5696 of file MapDHandler.cpp.

References calcite_.

Referenced by shutdown().

5696  {
5697  if (calcite_) {
5698  calcite_->close_calcite_server(false);
5699  }
5700 }
std::shared_ptr< Calcite > calcite_
Definition: MapDHandler.h:464

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

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

Referenced by sql_execute_impl().

5320  {
5321  auto importer_factory = [&session_info, this](
5322  const Catalog& catalog,
5323  const TableDescriptor* td,
5324  const std::string& file_path,
5325  const Importer_NS::CopyParams& copy_params) {
5326  return boost::make_unique<Importer_NS::Importer>(
5327  new DistributedLoader(session_info, td, &leaf_aggregator_),
5328  file_path,
5329  copy_params);
5330  };
5331  copy_stmt->execute(session_info, importer_factory);
5332 }
class for a per-database catalog. also includes metadata for the current database and the current use...
Definition: Catalog.h:81
void execute(const Catalog_Namespace::SessionInfo &session) override
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:443
specifies the content in-memory of a row in the table metadata table

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 5575 of file MapDHandler.cpp.

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

5577  {
5578  if (!render_handler_) {
5579  THROW_MAPD_EXCEPTION("Backend rendering is disabled.");
5580  }
5581 
5582  LOG(INFO) << "execute_next_render_step: id:" << pending_render.id;
5583  auto time_ms = measure<>::execution([&]() {
5584  try {
5585  render_handler_->execute_next_render_step(_return, pending_render, merged_data);
5586  } catch (std::exception& e) {
5587  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
5588  }
5589  });
5590  LOG(INFO) << "execute_next_render_step-COMPLETED id: " << pending_render.id
5591  << ", time: " << time_ms << "ms ";
5592 }
std::unique_ptr< MapDRenderHandler > render_handler_
Definition: MapDHandler.h:461
static TimeT::rep execution(F func, Args &&...args)
Definition: sample.cpp:29
#define LOG(tag)
Definition: Logger.h:185
#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 5430 of file MapDHandler.cpp.

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

5431  {
5432  if (!leaf_handler_) {
5433  THROW_MAPD_EXCEPTION("Distributed support is disabled.");
5434  }
5435  LOG(INFO) << "execute_query_step : id:" << pending_query.id;
5436  auto time_ms = measure<>::execution([&]() {
5437  try {
5438  leaf_handler_->execute_query_step(_return, pending_query);
5439  } catch (std::exception& e) {
5440  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
5441  }
5442  });
5443  LOG(INFO) << "execute_query_step-COMPLETED " << time_ms << "ms";
5444 }
static TimeT::rep execution(F func, Args &&...args)
Definition: sample.cpp:29
#define LOG(tag)
Definition: Logger.h:185
#define THROW_MAPD_EXCEPTION(errstr)
std::unique_ptr< MapDLeafHandler > leaf_handler_
Definition: MapDHandler.h:463

+ 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_explain,
const bool  just_validate,
const bool  find_push_down_candidates,
const bool  just_calcite_explain,
const bool  explain_optimized_ir 
) const
private

Definition at line 4463 of file MapDHandler.cpp.

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

4475  {
4476  query_state::Timer timer = query_state_proxy.createTimer(__func__);
4477  const auto& cat = query_state_proxy.getQueryState().getConstSessionInfo()->getCatalog();
4478  CompilationOptions co = {executor_device_type,
4479  true,
4482  explain_optimized_ir ? ExecutorExplainType::Optimized
4487  just_explain,
4488  allow_loop_joins_ || just_validate,
4490  jit_debug_,
4491  just_validate,
4494  find_push_down_candidates,
4495  just_calcite_explain,
4497  auto executor = Executor::getExecutor(cat.getCurrentDB().dbId,
4498  jit_debug_ ? "/tmp" : "",
4499  jit_debug_ ? "mapdquery" : "",
4501  nullptr);
4502  RelAlgExecutor ra_executor(executor.get(), cat);
4503  ExecutionResult result{std::make_shared<ResultSet>(std::vector<TargetInfo>{},
4506  nullptr,
4507  nullptr),
4508  {}};
4509  _return.execution_time_ms += measure<>::execution(
4510  [&]() { result = ra_executor.executeRelAlgQuery(query_ra, co, eo, nullptr); });
4511  // reduce execution time by the time spent during queue waiting
4512  _return.execution_time_ms -= result.getRows()->getQueueTime();
4513  const auto& filter_push_down_info = result.getPushedDownFilterInfo();
4514  if (!filter_push_down_info.empty()) {
4515  return filter_push_down_info;
4516  }
4517  if (just_explain) {
4518  convert_explain(_return, *result.getRows(), column_format);
4519  } else if (!just_calcite_explain) {
4520  convert_rows(_return,
4521  timer.createQueryStateProxy(),
4522  result.getTargetsMeta(),
4523  *result.getRows(),
4524  column_format,
4525  first_n,
4526  at_most_n);
4527  }
4528  return {};
4529 }
const bool allow_loop_joins_
Definition: MapDHandler.h:454
static std::shared_ptr< Executor > getExecutor(const int db_id, const std::string &debug_dir="", const std::string &debug_file="", const MapDParameters mapd_parameters=MapDParameters(),::QueryRenderer::QueryRenderManager *render_manager=nullptr)
Definition: Execute.cpp:127
static TimeT::rep execution(F func, Args &&...args)
Definition: sample.cpp:29
void convert_rows(TQueryResult &_return, QueryStateProxy query_state_proxy, const std::vector< TargetMetaInfo > &targets, const R &results, const bool column_format, const int32_t first_n, const int32_t at_most_n) const
const bool intel_jit_profile_
Definition: MapDHandler.h:451
bool g_enable_dynamic_watchdog
Definition: Execute.cpp:72
Timer createTimer(char const *event_name)
Definition: QueryState.cpp:111
bool g_enable_watchdog
const MapDParameters & mapd_parameters_
Definition: MapDHandler.h:460
bool g_enable_columnar_output
Definition: Execute.cpp:86
bool allow_multifrag_
Definition: MapDHandler.h:452
QueryState & getQueryState()
Definition: QueryState.h:172
QueryStateProxy createQueryStateProxy()
Definition: QueryState.cpp:118
double gpu_input_mem_limit
void convert_explain(TQueryResult &_return, const ResultSet &results, const bool column_format) const
unsigned g_dynamic_watchdog_time_limit
Definition: Execute.cpp:73
const bool jit_debug_
Definition: MapDHandler.h:450
std::shared_ptr< Catalog_Namespace::SessionInfo const > getConstSessionInfo() const
Definition: QueryState.cpp:75

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

References allow_loop_joins_, allow_multifrag_, CHECK(), CPU, data_mgr_, Default, ArrowResult::df_dev_ptr, ArrowResult::df_handle, ArrowResult::df_size, measure< TimeT >::execution(), g_dynamic_watchdog_time_limit, g_enable_dynamic_watchdog, g_enable_watchdog, Catalog_Namespace::SessionInfo::get_executor_device_type(), Catalog_Namespace::SessionInfo::getCatalog(), Executor::getExecutor(), 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::sm_handle, and ArrowResult::sm_size.

Referenced by sql_execute_df().

4536  {
4537  const auto& cat = session_info.getCatalog();
4538  CHECK(device_type == ExecutorDeviceType::CPU ||
4540  CompilationOptions co = {session_info.get_executor_device_type(),
4541  true,
4546  ExecutionOptions eo = {false,
4548  false,
4551  jit_debug_,
4552  false,
4555  false,
4556  false,
4558  auto executor = Executor::getExecutor(cat.getCurrentDB().dbId,
4559  jit_debug_ ? "/tmp" : "",
4560  jit_debug_ ? "mapdquery" : "",
4562  nullptr);
4563  RelAlgExecutor ra_executor(executor.get(), cat);
4564  ExecutionResult result{std::make_shared<ResultSet>(std::vector<TargetInfo>{},
4567  nullptr,
4568  nullptr),
4569  {}};
4570  _return.execution_time_ms += measure<>::execution(
4571  [&]() { result = ra_executor.executeRelAlgQuery(query_ra, co, eo, nullptr); });
4572  _return.execution_time_ms -= result.getRows()->getQueueTime();
4573  const auto rs = result.getRows();
4574  const auto converter =
4575  std::make_unique<ArrowResultSetConverter>(rs,
4576  data_mgr_,
4577  device_type,
4578  device_id,
4579  getTargetNames(result.getTargetsMeta()),
4580  first_n);
4581  ArrowResult arrow_result;
4582 
4583  _return.arrow_conversion_time_ms +=
4584  measure<>::execution([&] { arrow_result = converter->getArrowResult(); });
4585  _return.sm_handle =
4586  std::string(arrow_result.sm_handle.begin(), arrow_result.sm_handle.end());
4587  _return.sm_size = arrow_result.sm_size;
4588  _return.df_handle =
4589  std::string(arrow_result.df_handle.begin(), arrow_result.df_handle.end());
4590  if (device_type == ExecutorDeviceType::GPU) {
4591  std::lock_guard<std::mutex> map_lock(handle_to_dev_ptr_mutex_);
4592  CHECK(!ipc_handle_to_dev_ptr_.count(_return.df_handle));
4593  ipc_handle_to_dev_ptr_.insert(
4594  std::make_pair(_return.df_handle, arrow_result.df_dev_ptr));
4595  }
4596  _return.df_size = arrow_result.df_size;
4597 }
const bool allow_loop_joins_
Definition: MapDHandler.h:454
static std::shared_ptr< Executor > getExecutor(const int db_id, const std::string &debug_dir="", const std::string &debug_file="", const MapDParameters mapd_parameters=MapDParameters(),::QueryRenderer::QueryRenderManager *render_manager=nullptr)
Definition: Execute.cpp:127
static TimeT::rep execution(F func, Args &&...args)
Definition: sample.cpp:29
std::vector< char > sm_handle
const bool intel_jit_profile_
Definition: MapDHandler.h:451
bool g_enable_dynamic_watchdog
Definition: Execute.cpp:72
bool g_enable_watchdog
const MapDParameters & mapd_parameters_
Definition: MapDHandler.h:460
bool allow_multifrag_
Definition: MapDHandler.h:452
CHECK(cgen_state)
int8_t * df_dev_ptr
std::vector< char > df_handle
int64_t sm_size
std::shared_ptr< Data_Namespace::DataMgr > data_mgr_
Definition: MapDHandler.h:441
Catalog & getCatalog() const
Definition: SessionInfo.h:90
double gpu_input_mem_limit
int64_t df_size
std::vector< std::string > getTargetNames(const std::vector< TargetMetaInfo > &targets) const
std::mutex handle_to_dev_ptr_mutex_
Definition: MapDHandler.h:697
unsigned g_dynamic_watchdog_time_limit
Definition: Execute.cpp:73
const bool jit_debug_
Definition: MapDHandler.h:450
const ExecutorDeviceType get_executor_device_type() const
Definition: SessionInfo.h:94
std::unordered_map< std::string, int8_t * > ipc_handle_to_dev_ptr_
Definition: MapDHandler.h:698

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

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

Referenced by sql_execute_impl().

5278  {
5279  // collecting the selected filters' info to be sent to Calcite:
5280  std::vector<TFilterPushDownInfo> filter_push_down_info;
5281  for (const auto& req : filter_push_down_requests) {
5282  TFilterPushDownInfo filter_push_down_info_for_request;
5283  filter_push_down_info_for_request.input_prev = req.input_prev;
5284  filter_push_down_info_for_request.input_start = req.input_start;
5285  filter_push_down_info_for_request.input_next = req.input_next;
5286  filter_push_down_info.push_back(filter_push_down_info_for_request);
5287  }
5288  // deriving the new relational algebra plan with respect to the pushed down filters
5289  _return.execution_time_ms += measure<>::execution([&]() {
5290  query_ra = parse_to_ra(query_state_proxy,
5291  query_state_proxy.getQueryState().getQueryStr(),
5292  filter_push_down_info,
5293  boost::none,
5295  });
5296 
5297  if (just_calcite_explain) {
5298  // return the new ra as the result
5299  convert_explain(_return, ResultSet(query_ra), true);
5300  return;
5301  }
5302 
5303  // execute the new relational algebra plan:
5304  execute_rel_alg(_return,
5305  query_state_proxy,
5306  query_ra,
5307  column_format,
5308  executor_device_type,
5309  first_n,
5310  at_most_n,
5311  just_explain,
5312  /*just_validate = */ false,
5313  /*find_push_down_candidates = */ false,
5314  /*just_calcite_explain = */ false,
5315  /*TODO: explain optimized*/ false);
5316 }
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:460
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_explain, const bool just_validate, const bool find_push_down_candidates, const bool just_calcite_explain, const bool explain_optimized_ir) const
std::string parse_to_ra(QueryStateProxy, const std::string &query_str, const std::vector< TFilterPushDownInfo > &filter_push_down_info, OptionalTableMap tableNames, const MapDParameters mapd_parameters, RenderInfo *render_info=nullptr)
void convert_explain(TQueryResult &_return, const ResultSet &results, const bool column_format) const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 4599 of file MapDHandler.cpp.

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

Referenced by sql_execute_impl().

4605  {
4606  auto executor = Executor::getExecutor(
4607  root_plan->getCatalog().getCurrentDB().dbId,
4608  jit_debug_ ? "/tmp" : "",
4609  jit_debug_ ? "mapdquery" : "",
4611  render_handler_ ? render_handler_->get_render_manager() : nullptr);
4612  std::shared_ptr<ResultSet> results;
4613  _return.execution_time_ms += measure<>::execution([&]() {
4614  results = executor->execute(root_plan,
4615  session_info,
4616  true,
4617  executor_device_type,
4621  });
4622  // reduce execution time by the time spent during queue waiting
4623  _return.execution_time_ms -= results->getQueueTime();
4624  if (root_plan->get_plan_dest() == Planner::RootPlan::Dest::kEXPLAIN) {
4625  convert_explain(_return, *results, column_format);
4626  return;
4627  }
4628  const auto plan = root_plan->get_plan();
4629  CHECK(plan);
4630  const auto& targets = plan->get_targetlist();
4631  convert_rows(_return,
4632  query_state_proxy,
4633  getTargetMetaInfo(targets),
4634  *results,
4635  column_format,
4636  -1,
4637  -1);
4638 }
const bool allow_loop_joins_
Definition: MapDHandler.h:454
const Plan * get_plan() const
Definition: Planner.h:289
std::unique_ptr< MapDRenderHandler > render_handler_
Definition: MapDHandler.h:461
static std::shared_ptr< Executor > getExecutor(const int db_id, const std::string &debug_dir="", const std::string &debug_file="", const MapDParameters mapd_parameters=MapDParameters(),::QueryRenderer::QueryRenderManager *render_manager=nullptr)
Definition: Execute.cpp:127
static TimeT::rep execution(F func, Args &&...args)
Definition: sample.cpp:29
void convert_rows(TQueryResult &_return, QueryStateProxy query_state_proxy, const std::vector< TargetMetaInfo > &targets, const R &results, const bool column_format, const int32_t first_n, const int32_t at_most_n) const
const Catalog_Namespace::Catalog & getCatalog() const
Definition: Planner.h:293
const MapDParameters & mapd_parameters_
Definition: MapDHandler.h:460
bool allow_multifrag_
Definition: MapDHandler.h:452
CHECK(cgen_state)
const DBMetadata & getCurrentDB() const
Definition: Catalog.h:176
std::vector< TargetMetaInfo > getTargetMetaInfo(const std::vector< std::shared_ptr< Analyzer::TargetEntry >> &targets) const
void convert_explain(TQueryResult &_return, const ResultSet &results, const bool column_format) const
Dest get_plan_dest() const
Definition: Planner.h:299
const bool jit_debug_
Definition: MapDHandler.h:450

+ 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 ( const std::vector< std::string > &  table_names,
const TSessionId &  session 
)
private

Definition at line 1229 of file MapDHandler.cpp.

References get_table_details().

Referenced by get_token_based_completions().

1230  {
1231  std::unordered_map<std::string, std::unordered_set<std::string>> column_names_by_table;
1232  for (const auto& table_name : table_names) {
1233  TTableDetails table_details;
1234  get_table_details(table_details, session, table_name);
1235  for (const auto& column_type : table_details.row_desc) {
1236  column_names_by_table[table_name].emplace(column_type.col_name);
1237  }
1238  }
1239  return column_names_by_table;
1240 }
void get_table_details(TTableDetails &_return, const TSessionId &session, const std::string &table_name) override

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

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

Referenced by get_table_details_impl(), and validate_rel_alg().

4767  {
4768  TRowDescriptor fixedup_row_desc;
4769  for (const TColumnType& col_desc : row_desc) {
4770  auto fixedup_col_desc = col_desc;
4771  if (col_desc.col_type.encoding == TEncodingType::DICT &&
4772  col_desc.col_type.comp_param > 0) {
4773  const auto dd = cat.getMetadataForDict(col_desc.col_type.comp_param, false);
4774  fixedup_col_desc.col_type.comp_param = dd->dictNBits;
4775  }
4776  fixedup_row_desc.push_back(fixedup_col_desc);
4777  }
4778  return fixedup_row_desc;
4779 }
const DictDescriptor * getMetadataForDict(int dict_ref, bool loadDict=true) const
Definition: Catalog.cpp:1350

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

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

4222  {
4223  auto stdlog =
4224  STDLOG(get_session_ptr(session), "get_all_files_in_archive", archive_path_in);
4225 
4226  std::string archive_path(archive_path_in);
4227  if (path_is_relative(archive_path)) {
4228  // assume relative paths are relative to data_path / mapd_import / <session>
4229  auto file_path = import_path_ / picosha2::hash256_hex_string(session) /
4230  boost::filesystem::path(archive_path).filename();
4231  archive_path = file_path.string();
4232  }
4233 
4234  if (is_a_supported_archive_file(archive_path)) {
4235  // find the archive file
4236  add_vsi_network_prefix(archive_path);
4237  if (!Importer_NS::Importer::gdalFileExists(archive_path,
4238  thrift_to_copyparams(copy_params))) {
4239  THROW_MAPD_EXCEPTION("Archive does not exist: " + archive_path_in);
4240  }
4241  // find all files in archive
4242  add_vsi_archive_prefix(archive_path);
4244  archive_path, thrift_to_copyparams(copy_params));
4245  // prepend them all with original path
4246  for (auto& s : _return) {
4247  s = archive_path_in + '/' + s;
4248  }
4249  }
4250 }
void add_vsi_network_prefix(std::string &path)
boost::filesystem::path import_path_
Definition: MapDHandler.h:446
void add_vsi_archive_prefix(std::string &path)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
#define THROW_MAPD_EXCEPTION(errstr)
bool path_is_relative(const std::string &path)
static bool gdalFileExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:4457
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:4534

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

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

1621  {
1622  auto stdlog = STDLOG(get_session_ptr(sessionId));
1623  auto session_ptr = stdlog.getConstSessionInfo();
1624  auto* grantee = SysCatalog::instance().getGrantee(granteeName);
1625  if (grantee) {
1626  if (session_ptr->get_currentUser().isSuper) {
1627  roles = grantee->getRoles();
1628  } else if (grantee->isUser()) {
1629  if (session_ptr->get_currentUser().userName == granteeName) {
1630  roles = grantee->getRoles();
1631  } else {
1633  "Only a superuser is authorized to request list of roles granted to another "
1634  "user.");
1635  }
1636  } else {
1637  CHECK(!grantee->isUser());
1638  // granteeName is actually a roleName here and we can check a role
1639  // only if it is granted to us
1640  if (SysCatalog::instance().isRoleGrantedToGrantee(
1641  session_ptr->get_currentUser().userName, granteeName, false)) {
1642  roles = grantee->getRoles();
1643  } else {
1644  THROW_MAPD_EXCEPTION("A user can check only roles granted to him.");
1645  }
1646  }
1647  } else {
1648  THROW_MAPD_EXCEPTION("Grantee " + granteeName + " does not exist.");
1649  }
1650 }
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 1121 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().

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

Definition at line 1154 of file MapDHandler.cpp.

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

Referenced by get_completion_hints().

1158  {
1159  const auto session_info = get_session_copy(session);
1160  try {
1161  get_tables(visible_tables, session);
1162  // Filter out keywords suggested by Calcite which we don't support.
1164  calcite_->getCompletionHints(session_info, visible_tables, sql, cursor));
1165  } catch (const std::exception& e) {
1166  TMapDException ex;
1167  ex.error_msg = "Exception: " + std::string(e.what());
1168  LOG(ERROR) << ex.error_msg;
1169  throw ex;
1170  }
1171  boost::regex from_expr{R"(\s+from\s+)", boost::regex::extended | boost::regex::icase};
1172  const size_t length_to_cursor =
1173  cursor < 0 ? sql.size() : std::min(sql.size(), static_cast<size_t>(cursor));
1174  // Trust hints from Calcite after the FROM keyword.
1175  if (boost::regex_search(sql.cbegin(), sql.cbegin() + length_to_cursor, from_expr)) {
1176  return;
1177  }
1178  // Before FROM, the query is too incomplete for context-sensitive completions.
1179  get_token_based_completions(hints, session, visible_tables, sql, cursor);
1180 }
void get_token_based_completions(std::vector< TCompletionHint > &hints, const TSessionId &session, const std::vector< std::string > &visible_tables, const std::string &sql, const int cursor)
void get_tables(std::vector< std::string > &_return, const TSessionId &session) override
#define LOG(tag)
Definition: Logger.h:185
std::vector< TCompletionHint > just_whitelisted_keyword_hints(const std::vector< TCompletionHint > &hints)
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
std::shared_ptr< Calcite > calcite_
Definition: MapDHandler.h:464

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

References get_session_ptr().

4381  {
4382  return get_session_ptr(session);
4383 }
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 3140 of file MapDHandler.cpp.

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

3142  {
3143  auto stdlog = STDLOG(get_session_ptr(session));
3144  auto session_ptr = stdlog.getConstSessionInfo();
3145  auto const& cat = session_ptr->getCatalog();
3147  auto dash = cat.getMetadataForDashboard(dashboard_id);
3148  if (!dash) {
3149  THROW_MAPD_EXCEPTION("Dashboard with dashboard id " + std::to_string(dashboard_id) +
3150  " doesn't exist");
3151  }
3153  *session_ptr, dash->dashboardId, AccessPrivileges::VIEW_DASHBOARD)) {
3154  THROW_MAPD_EXCEPTION("User has no view privileges for the dashboard with id " +
3155  std::to_string(dashboard_id));
3156  }
3157  user_meta.userName = "";
3158  SysCatalog::instance().getMetadataForUserById(dash->userId, user_meta);
3159  auto objects_list = SysCatalog::instance().getMetadataForObject(
3160  cat.getCurrentDB().dbId,
3161  static_cast<int>(DBObjectType::DashboardDBObjectType),
3162  dashboard_id);
3163  dashboard.dashboard_name = dash->dashboardName;
3164  dashboard.dashboard_state = dash->dashboardState;
3165  dashboard.image_hash = dash->imageHash;
3166  dashboard.update_time = dash->updateTime;
3167  dashboard.dashboard_metadata = dash->dashboardMetadata;
3168  dashboard.dashboard_owner = dash->user;
3169  dashboard.dashboard_id = dash->dashboardId;
3170  if (objects_list.empty() ||
3171  (objects_list.size() == 1 && objects_list[0]->roleName == user_meta.userName)) {
3172  dashboard.is_dash_shared = false;
3173  } else {
3174  dashboard.is_dash_shared = true;
3175  }
3176 }
static const AccessPrivileges VIEW_DASHBOARD
Definition: DBObject.h:164
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
std::string to_string(char const *&&v)
#define THROW_MAPD_EXCEPTION(errstr)
static bool is_allowed_on_dashboard(const Catalog_Namespace::SessionInfo &session_info, int32_t dashboard_id, AccessPrivileges requestedPermissions)
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 3437 of file MapDHandler.cpp.

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

3440  {
3441  auto stdlog = STDLOG(get_session_ptr(session));
3442  auto session_ptr = stdlog.getConstSessionInfo();
3443  auto const& cat = session_ptr->getCatalog();
3445  auto dash = cat.getMetadataForDashboard(dashboard_id);
3446  if (!dash) {
3447  THROW_MAPD_EXCEPTION("Exception: Dashboard id " + std::to_string(dashboard_id) +
3448  " does not exist");
3449  } else if (session_ptr->get_currentUser().userId != dash->userId &&
3450  !session_ptr->get_currentUser().isSuper) {
3452  "User should be either owner of dashboard or super user to access grantees");
3453  }
3454  std::vector<ObjectRoleDescriptor*> objectsList;
3455  objectsList = SysCatalog::instance().getMetadataForObject(
3456  cat.getCurrentDB().dbId,
3457  static_cast<int>(DBObjectType::DashboardDBObjectType),
3458  dashboard_id); // By default objecttypecan be only dashabaords
3459  user_meta.userId = -1;
3460  user_meta.userName = "";
3461  SysCatalog::instance().getMetadataForUserById(dash->userId, user_meta);
3462  for (auto object : objectsList) {
3463  if (user_meta.userName == object->roleName) {
3464  // Mask owner
3465  continue;
3466  }
3467  TDashboardGrantees grantee;
3468  TDashboardPermissions perm;
3469  grantee.name = object->roleName;
3470  grantee.is_user = object->roleType;
3471  perm.create_ = object->privs.hasPermission(DashboardPrivileges::CREATE_DASHBOARD);
3472  perm.delete_ = object->privs.hasPermission(DashboardPrivileges::DELETE_DASHBOARD);
3473  perm.edit_ = object->privs.hasPermission(DashboardPrivileges::EDIT_DASHBOARD);
3474  perm.view_ = object->privs.hasPermission(DashboardPrivileges::VIEW_DASHBOARD);
3475  grantee.permissions = perm;
3476  dashboard_grantees.push_back(grantee);
3477  }
3478 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
std::string to_string(char const *&&v)
#define THROW_MAPD_EXCEPTION(errstr)
static const int32_t EDIT_DASHBOARD
Definition: DBObject.h:105
static const int32_t DELETE_DASHBOARD
Definition: DBObject.h:103
static const int32_t VIEW_DASHBOARD
Definition: DBObject.h:104
static const int32_t CREATE_DASHBOARD
Definition: DBObject.h:102
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 3178 of file MapDHandler.cpp.

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

3179  {
3180  auto stdlog = STDLOG(get_session_ptr(session));
3181  auto session_ptr = stdlog.getConstSessionInfo();
3182  auto const& cat = session_ptr->getCatalog();
3184  const auto dashes = cat.getAllDashboardsMetadata();
3185  user_meta.userName = "";
3186  for (const auto d : dashes) {
3187  SysCatalog::instance().getMetadataForUserById(d->userId, user_meta);
3189  *session_ptr, d->dashboardId, AccessPrivileges::VIEW_DASHBOARD)) {
3190  auto objects_list = SysCatalog::instance().getMetadataForObject(
3191  cat.getCurrentDB().dbId,
3192  static_cast<int>(DBObjectType::DashboardDBObjectType),
3193  d->dashboardId);
3194  TDashboard dash;
3195  dash.dashboard_name = d->dashboardName;
3196  dash.image_hash = d->imageHash;
3197  dash.update_time = d->updateTime;
3198  dash.dashboard_metadata = d->dashboardMetadata;
3199  dash.dashboard_id = d->dashboardId;
3200  dash.dashboard_owner = d->user;
3201  // dashboardState is intentionally not populated here
3202  // for payload reasons
3203  // use get_dashboard call to get state
3204  if (objects_list.empty() ||
3205  (objects_list.size() == 1 && objects_list[0]->roleName == user_meta.userName)) {
3206  dash.is_dash_shared = false;
3207  } else {
3208  dash.is_dash_shared = true;
3209  }
3210  dashboards.push_back(dash);
3211  }
3212  }
3213 }
static const AccessPrivileges VIEW_DASHBOARD
Definition: DBObject.h:164
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
static bool is_allowed_on_dashboard(const Catalog_Namespace::SessionInfo &session_info, int32_t dashboard_id, AccessPrivileges requestedPermissions)
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 2136 of file MapDHandler.cpp.

References get_session_ptr(), and STDLOG.

2137  {
2138  auto stdlog = STDLOG(get_session_ptr(session));
2139  auto session_ptr = stdlog.getConstSessionInfo();
2140  const auto& user = session_ptr->get_currentUser();
2142  SysCatalog::instance().getDatabaseListForUser(user);
2143  for (auto& db : dbs) {
2144  TDBInfo dbinfo;
2145  dbinfo.db_name = std::move(db.dbName);
2146  dbinfo.db_owner = std::move(db.dbOwnerName);
2147  dbinfos.push_back(std::move(dbinfo));
2148  }
2149 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
std::list< DBSummary > DBSummaryList
Definition: SysCatalog.h:108
#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 1539 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.

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

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

1514  {
1515  auto stdlog = STDLOG(get_session_ptr(sessionId));
1516  auto session_ptr = stdlog.getConstSessionInfo();
1517  auto const& user = session_ptr->get_currentUser();
1518  if (!user.isSuper &&
1519  !SysCatalog::instance().isRoleGrantedToGrantee(user.userName, roleName, false)) {
1520  return;
1521  }
1522  auto* rl = SysCatalog::instance().getGrantee(roleName);
1523  if (rl) {
1524  auto dbId = session_ptr->getCatalog().getCurrentDB().dbId;
1525  for (auto& dbObject : *rl->getDbObjects(true)) {
1526  if (dbObject.first.dbId != dbId) {
1527  // TODO (max): it doesn't scale well in case we have many DBs (not a typical
1528  // usecase for now, though)
1529  continue;
1530  }
1531  TDBObject tdbObject = serialize_db_object(roleName, *dbObject.second);
1532  TDBObjectsForRole.push_back(tdbObject);
1533  }
1534  } else {
1535  THROW_MAPD_EXCEPTION("User or role " + roleName + " does not exist.");
1536  }
1537 }
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 5704 of file MapDHandler.cpp.

References get_session_copy().

5705  {
5706  const auto session_info = get_session_copy(session);
5707  auto params = ::get_device_parameters();
5708  for (auto item : params) {
5709  _return.insert(item);
5710  }
5711 }
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 4179 of file MapDHandler.cpp.

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

4182  {
4183  auto stdlog =
4184  STDLOG(get_session_ptr(session), "get_first_geo_file_in_archive", archive_path_in);
4185  std::string archive_path(archive_path_in);
4186 
4187  if (path_is_relative(archive_path)) {
4188  // assume relative paths are relative to data_path / mapd_import / <session>
4189  auto file_path = import_path_ / picosha2::hash256_hex_string(session) /
4190  boost::filesystem::path(archive_path).filename();
4191  archive_path = file_path.string();
4192  }
4193 
4194  if (is_a_supported_archive_file(archive_path)) {
4195  // find the archive file
4196  add_vsi_network_prefix(archive_path);
4197  if (!Importer_NS::Importer::gdalFileExists(archive_path,
4198  thrift_to_copyparams(copy_params))) {
4199  THROW_MAPD_EXCEPTION("Archive does not exist: " + archive_path_in);
4200  }
4201  // find geo file in archive
4202  add_vsi_archive_prefix(archive_path);
4203  std::string geo_file =
4204  find_first_geo_file_in_archive(archive_path, thrift_to_copyparams(copy_params));
4205  // what did we get?
4206  if (geo_file.size()) {
4207  // prepend it with the original path
4208  _return = archive_path_in + std::string("/") + geo_file;
4209  } else {
4210  // just return the original path
4211  _return = archive_path_in;
4212  }
4213  } else {
4214  // just return the original path
4215  _return = archive_path_in;
4216  }
4217 }
void add_vsi_network_prefix(std::string &path)
boost::filesystem::path import_path_
Definition: MapDHandler.h:446
void add_vsi_archive_prefix(std::string &path)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
#define THROW_MAPD_EXCEPTION(errstr)
bool path_is_relative(const std::string &path)
static bool gdalFileExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:4457
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 599 of file MapDHandler.cpp.

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

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

References get_session_ptr(), STDLOG, and THROW_MAPD_EXCEPTION.

4349  {
4350  auto stdlog = STDLOG(get_session_ptr(session));
4351 #ifdef HAVE_PROFILER
4352  if (!IsHeapProfilerRunning()) {
4353  THROW_MAPD_EXCEPTION("Profiler not running");
4354  }
4355  auto profile_buff = GetHeapProfile();
4356  profile = profile_buff;
4357  free(profile_buff);
4358 #else
4359  THROW_MAPD_EXCEPTION("Profiler not enabled");
4360 #endif // HAVE_PROFILER
4361 }
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 1750 of file MapDHandler.cpp.

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

1752  {
1753  auto stdlog = STDLOG(get_session_ptr(session), "table_name", table_name);
1754  get_table_details_impl(_return, stdlog, session, table_name, true, false);
1755 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
void get_table_details_impl(TTableDetails &_return, query_state::StdLog &, const TSessionId &session, 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 4252 of file MapDHandler.cpp.

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

4255  {
4256  auto stdlog = STDLOG(get_session_ptr(session), "get_layers_in_geo_file", file_name_in);
4257  std::string file_name(file_name_in);
4258 
4260 
4261  // handle relative paths
4262  if (path_is_relative(file_name)) {
4263  // assume relative paths are relative to data_path / mapd_import / <session>
4264  auto file_path = import_path_ / picosha2::hash256_hex_string(session) /
4265  boost::filesystem::path(file_name).filename();
4266  file_name = file_path.string();
4267  }
4268 
4269  // validate file_name
4270  if (is_a_supported_geo_file(file_name, true)) {
4271  // prepare to load geo file directly
4272  add_vsi_network_prefix(file_name);
4273  add_vsi_geo_prefix(file_name);
4274  } else if (is_a_supported_archive_file(file_name)) {
4275  // find the archive file
4276  add_vsi_network_prefix(file_name);
4277  if (!Importer_NS::Importer::gdalFileExists(file_name, copy_params)) {
4278  THROW_MAPD_EXCEPTION("Archive does not exist: " + file_name_in);
4279  }
4280  // find geo file in archive
4281  add_vsi_archive_prefix(file_name);
4282  std::string geo_file = find_first_geo_file_in_archive(file_name, copy_params);
4283  // prepare to load that geo file
4284  if (geo_file.size()) {
4285  file_name = file_name + std::string("/") + geo_file;
4286  }
4287  } else {
4288  THROW_MAPD_EXCEPTION("File is not a supported geo or geo archive file: " +
4289  file_name_in);
4290  }
4291 
4292  // check the file actually exists
4293  if (!Importer_NS::Importer::gdalFileOrDirectoryExists(file_name, copy_params)) {
4294  THROW_MAPD_EXCEPTION("Geo file/archive does not exist: " + file_name_in);
4295  }
4296 
4297  // find all layers
4298  auto internal_layer_info =
4299  Importer_NS::Importer::gdalGetLayersInGeoFile(file_name, copy_params);
4300 
4301  // convert to Thrift type
4302  for (const auto& internal_layer : internal_layer_info) {
4303  TGeoFileLayerInfo layer;
4304  layer.name = internal_layer.name;
4305  switch (internal_layer.contents) {
4307  layer.contents = TGeoFileLayerContents::EMPTY;
4308  break;
4310  layer.contents = TGeoFileLayerContents::GEO;
4311  break;
4313  layer.contents = TGeoFileLayerContents::NON_GEO;
4314  break;
4316  layer.contents = TGeoFileLayerContents::UNSUPPORTED_GEO;
4317  break;
4318  default:
4319  CHECK(false);
4320  }
4321  _return.emplace_back(layer); // no suitable constructor to just pass parameters
4322  }
4323 }
static std::vector< GeoFileLayerInfo > gdalGetLayersInGeoFile(const std::string &file_name, const CopyParams &copy_params)
Definition: Importer.cpp:4559
void add_vsi_network_prefix(std::string &path)
boost::filesystem::path import_path_
Definition: MapDHandler.h:446
void add_vsi_archive_prefix(std::string &path)
void add_vsi_geo_prefix(std::string &path)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
#define THROW_MAPD_EXCEPTION(errstr)
static bool gdalFileOrDirectoryExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:4462
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:4457
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 5680 of file MapDHandler.cpp.

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

5682  {
5683  auto stdlog = STDLOG(get_session_ptr(session));
5684  const auto session_info = get_session_copy(session);
5685  _return.claims.emplace_back("");
5686 }
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 1848 of file MapDHandler.cpp.

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

1850  {
1851  auto stdlog = STDLOG(get_session_ptr(session));
1852  auto session_ptr = stdlog.getConstSessionInfo();
1853  auto const& cat = session_ptr->getCatalog();
1854  auto ld = cat.getMetadataForLink(std::to_string(cat.getCurrentDB().dbId) + link);
1855  if (!ld) {
1856  THROW_MAPD_EXCEPTION("Link " + link + " is not valid.");
1857  }
1858  _return.view_state = ld->viewState;
1859  _return.view_name = ld->link;
1860  _return.update_time = ld->updateTime;
1861  _return.view_metadata = ld->viewMetadata;
1862 }
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 2092 of file MapDHandler.cpp.

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

2094  {
2095  auto stdlog = STDLOG(get_session_ptr(session));
2096  std::vector<Data_Namespace::MemoryInfo> internal_memory;
2097  Data_Namespace::MemoryLevel mem_level;
2098  if (!memory_level.compare("gpu")) {
2100  internal_memory =
2101  SysCatalog::instance().getDataMgr().getMemoryInfo(MemoryLevel::GPU_LEVEL);
2102  } else {
2104  internal_memory =
2105  SysCatalog::instance().getDataMgr().getMemoryInfo(MemoryLevel::CPU_LEVEL);
2106  }
2107 
2108  for (auto memInfo : internal_memory) {
2109  TNodeMemoryInfo nodeInfo;
2110  if (leaf_aggregator_.leafCount() > 0) {
2111  nodeInfo.host_name = get_hostname();
2112  }
2113  nodeInfo.page_size = memInfo.pageSize;
2114  nodeInfo.max_num_pages = memInfo.maxNumPages;
2115  nodeInfo.num_pages_allocated = memInfo.numPageAllocated;
2116  nodeInfo.is_allocation_capped = memInfo.isAllocationCapped;
2117  for (auto gpu : memInfo.nodeMemoryData) {
2118  TMemoryData md;
2119  md.slab = gpu.slabNum;
2120  md.start_page = gpu.startPage;
2121  md.num_pages = gpu.numPages;
2122  md.touch = gpu.touch;
2123  md.chunk_key.insert(md.chunk_key.end(), gpu.chunk_key.begin(), gpu.chunk_key.end());
2124  md.is_free = gpu.isFree == Buffer_Namespace::MemStatus::FREE;
2125  nodeInfo.node_memory_data.push_back(md);
2126  }
2127  _return.push_back(nodeInfo);
2128  }
2129  if (leaf_aggregator_.leafCount() > 0) {
2130  std::vector<TNodeMemoryInfo> leafSummary =
2131  leaf_aggregator_.getLeafMemoryInfo(session, mem_level);
2132  _return.insert(_return.begin(), leafSummary.begin(), leafSummary.end());
2133  }
2134 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:443
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 1921 of file MapDHandler.cpp.

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

1922  {
1923  auto stdlog = STDLOG(get_session_ptr(session));
1924  get_tables_impl(table_names, stdlog, GET_PHYSICAL_TABLES);
1925 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
void get_tables_impl(std::vector< std::string > &table_names, query_state::StdLog &stdlog, const GetTablesType get_tables_type)
#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 1652 of file MapDHandler.cpp.

References MapDRenderHandler::dump_table_col_names(), get_session_ptr(), render_handler_, STDLOG, and THROW_MAPD_EXCEPTION.

1660  {
1661  auto stdlog = STDLOG(get_session_ptr(session),
1662  "widget_id",
1663  widget_id,
1664  "pixel.x",
1665  pixel.x,
1666  "pixel.y",
1667  pixel.y,
1668  "column_format",
1669  column_format,
1670  "pixel_radius",
1671  pixel_radius,
1672  "table_col_names",
1673  MapDRenderHandler::dump_table_col_names(table_col_names),
1674  "nonce",
1675  nonce);
1676  auto session_ptr = stdlog.getSessionInfo();
1677  if (!render_handler_) {
1678  THROW_MAPD_EXCEPTION("Backend rendering is disabled.");
1679  }
1680 
1681  try {
1682  render_handler_->get_result_row_for_pixel(_return,
1683  session_ptr,
1684  widget_id,
1685  pixel,
1686  table_col_names,
1687  column_format,
1688  pixel_radius,
1689  nonce);
1690  } catch (std::exception& e) {
1691  THROW_MAPD_EXCEPTION(std::string("Exception: ") + e.what());
1692  }
1693 }
std::unique_ptr< MapDRenderHandler > render_handler_
Definition: MapDHandler.h:461
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
#define THROW_MAPD_EXCEPTION(errstr)
static 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 1293 of file MapDHandler.cpp.

References get_session_ptr(), and STDLOG.

1293  {
1294  auto stdlog = STDLOG(get_session_ptr(session));
1295  auto session_ptr = stdlog.getConstSessionInfo();
1296  if (!session_ptr->get_currentUser().isSuper) {
1297  // WARNING: This appears to not include roles a user is a member of,
1298  // if the role has no permissions granted to it.
1299  roles =
1300  SysCatalog::instance().getRoles(session_ptr->get_currentUser().userName,
1301  session_ptr->getCatalog().getCurrentDB().dbId);
1302  } else {
1303  roles = SysCatalog::instance().getRoles(
1304  false, true, session_ptr->get_currentUser().userName);
1305  }
1306 }
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 558 of file MapDHandler.cpp.

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

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

+ Here is the call graph for this function:

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

Definition at line 4385 of file MapDHandler.cpp.

References get_session_it_unsafe(), and sessions_mutex_.

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

4385  {
4386  mapd_shared_lock<mapd_shared_mutex> read_lock(sessions_mutex_);
4387  return *get_session_it_unsafe(session, read_lock)->second;
4388 }
SessionMap::iterator get_session_it_unsafe(const TSessionId &session, SESSION_MAP_LOCK &lock)
mapd_shared_mutex sessions_mutex_
Definition: MapDHandler.h:456

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 4390 of file MapDHandler.cpp.

References get_session_it_unsafe(), and sessions_mutex_.

4391  {
4392  // Note(Wamsi): We have `get_const_session_ptr` which would return as const SessionInfo
4393  // stored in the map. You can use `get_const_session_ptr` instead of the copy of
4394  // SessionInfo but beware that it can be changed in teh map. So if you do not care about
4395  // the changes then use `get_const_session_ptr` if you do then use this function to get
4396  // a copy. We should eventually aim to merge both `get_const_session_ptr` and
4397  // `get_session_copy_ptr`.
4398  mapd_shared_lock<mapd_shared_mutex> read_lock(sessions_mutex_);
4399  auto& session_info_ref = *get_session_it_unsafe(session, read_lock)->second;
4400  return std::make_shared<Catalog_Namespace::SessionInfo>(session_info_ref);
4401 }
SessionMap::iterator get_session_it_unsafe(const TSessionId &session, SESSION_MAP_LOCK &lock)
mapd_shared_mutex sessions_mutex_
Definition: MapDHandler.h:456

+ Here is the call graph for this function:

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

Definition at line 638 of file MapDHandler.cpp.

References get_session_ptr(), and STDLOG.

638  {
639  auto session_ptr = get_session_ptr(session);
640  auto stdlog = STDLOG(session_ptr);
641  auto user_metadata = session_ptr->get_currentUser();
642 
643  _return.user = user_metadata.userName;
644  _return.database = session_ptr->getCatalog().getCurrentDB().dbName;
645  _return.start_time = session_ptr->get_start_time();
646  _return.is_super = user_metadata.isSuper;
647 }
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 137 of file MapDHandler.cpp.

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

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

+ Here is the call graph for this function:

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

Definition at line 154 of file MapDHandler.cpp.

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

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

+ Here is the call graph for this function:

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

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

+ Here is the caller graph for this function:

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

Definition at line 4403 of file MapDHandler.cpp.

References get_session_it_unsafe(), and sessions_mutex_.

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

4404  {
4405  // Note(Wamsi): This method will give you a shared_ptr to master SessionInfo itself.
4406  // Should be used only when you need to make updates to original SessionInfo object.
4407  // Currently used by `update_session_last_used_duration`
4408 
4409  // 1) `session_id` will be empty during intial connect. 2)`sessionmapd iterator` will be
4410  // invalid during disconnect. SessionInfo will be erased from map by the time it reaches
4411  // here. In both the above cases, we would return `nullptr` and can skip SessionInfo
4412  // updates.
4413  if (session_id.empty()) {
4414  return {};
4415  }
4416  mapd_shared_lock<mapd_shared_mutex> read_lock(sessions_mutex_);
4417  return get_session_it_unsafe(session_id, read_lock)->second;
4418 }
SessionMap::iterator get_session_it_unsafe(const TSessionId &session, SESSION_MAP_LOCK &lock)
mapd_shared_mutex sessions_mutex_
Definition: MapDHandler.h:456

+ Here is the call graph for this function:

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

Definition at line 570 of file MapDHandler.cpp.

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

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

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

Referenced by fill_column_names_by_table(), and get_uc_compatible_table_names_by_column().

1759  {
1760  auto stdlog = STDLOG(get_session_ptr(session), "table_name", table_name);
1761  get_table_details_impl(_return, stdlog, session, table_name, false, false);
1762 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
void get_table_details_impl(TTableDetails &_return, query_state::StdLog &, const TSessionId &session, 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:

+ Here is the caller graph for this function:

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

Definition at line 1764 of file MapDHandler.cpp.

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

Referenced by get_internal_table_details(), and get_table_details().

1769  {
1770  auto session_copy =
1771  std::make_shared<Catalog_Namespace::SessionInfo>(*stdlog.getSessionInfo());
1772  auto& cat = session_copy->getCatalog();
1773  auto td = cat.getMetadataForTable(
1774  table_name,
1775  false); // don't populate fragmenter on this call since we only want metadata
1776  if (!td) {
1777  THROW_MAPD_EXCEPTION("Table " + table_name + " doesn't exist");
1778  }
1779  if (td->isView) {
1780  auto query_state = create_query_state(session_copy, td->viewSQL);
1781  stdlog.setQueryState(query_state);
1782  try {
1783  if (hasTableAccessPrivileges(td, session)) {
1784  const auto query_ra = parse_to_ra(query_state->createQueryStateProxy(),
1785  query_state->getQueryStr(),
1786  {},
1787  boost::none,
1789  TQueryResult result;
1790  execute_rel_alg(result,
1791  query_state->createQueryStateProxy(),
1792  query_ra,
1793  true,
1795  -1,
1796  -1,
1797  false,
1798  true,
1799  false,
1800  false,
1801  false);
1802  _return.row_desc = fixup_row_descriptor(result.row_set.row_desc, cat);
1803  } else {
1804  THROW_MAPD_EXCEPTION("User has no access privileges to table " + table_name);
1805  }
1806  } catch (const std::exception& e) {
1807  THROW_MAPD_EXCEPTION("View query has failed with an error: '" +
1808  std::string(e.what()) +
1809  "'.\nThe view must be dropped and re-created to "
1810  "resolve the error. \nQuery:\n" +
1811  query_state->getQueryStr());
1812  }
1813  } else {
1814  try {
1815  if (hasTableAccessPrivileges(td, session)) {
1816  const auto col_descriptors =
1817  cat.getAllColumnMetadataForTable(td->tableId, get_system, true, get_physical);
1818  const auto deleted_cd = cat.getDeletedColumn(td);
1819  for (const auto cd : col_descriptors) {
1820  if (cd == deleted_cd) {
1821  continue;
1822  }
1823  _return.row_desc.push_back(populateThriftColumnType(&cat, cd));
1824  }
1825  } else {
1826  THROW_MAPD_EXCEPTION("User has no access privileges to table " + table_name);
1827  }
1828  } catch (const std::runtime_error& e) {
1829  THROW_MAPD_EXCEPTION(e.what());
1830  }
1831  }
1832  _return.fragment_size = td->maxFragRows;
1833  _return.page_size = td->fragPageSize;
1834  _return.max_rows = td->maxRows;
1835  _return.view_sql = td->viewSQL;
1836  _return.shard_count = td->nShards;
1837  _return.key_metainfo = td->keyMetainfo;
1838  _return.is_temporary = td->persistenceLevel == Data_Namespace::MemoryLevel::CPU_LEVEL;
1839  _return.partition_detail =
1840  td->partitions.empty()
1841  ? TPartitionDetail::DEFAULT
1842  : (table_is_replicated(td)
1843  ? TPartitionDetail::REPLICATED
1844  : (td->partitions == "SHARDED" ? TPartitionDetail::SHARDED
1845  : TPartitionDetail::OTHER));
1846 }
TColumnType populateThriftColumnType(const Catalog_Namespace::Catalog *cat, const ColumnDescriptor *cd)
#define THROW_MAPD_EXCEPTION(errstr)
TRowDescriptor fixup_row_descriptor(const TRowDescriptor &row_desc, const Catalog_Namespace::Catalog &cat)
const MapDParameters & mapd_parameters_
Definition: MapDHandler.h:460
void setQueryState(std::shared_ptr< QueryState >)
Definition: QueryState.cpp:222
std::shared_ptr< Catalog_Namespace::SessionInfo > getSessionInfo() const
Definition: QueryState.cpp:133
std::shared_ptr< query_state::QueryState > create_query_state(ARGS &&...args)
Definition: MapDHandler.h:468
std::vector< PushedDownFilterInfo > execute_rel_alg(TQueryResult &_return, QueryStateProxy, const std::string &query_ra, const bool column_format, const ExecutorDeviceType executor_device_type, const int32_t first_n, const int32_t at_most_n, const bool just_explain, const bool just_validate, const bool find_push_down_candidates, const bool just_calcite_explain, const bool explain_optimized_ir) const
std::string parse_to_ra(QueryStateProxy, const std::string &query_str, const std::vector< TFilterPushDownInfo > &filter_push_down_info, OptionalTableMap tableNames, const MapDParameters mapd_parameters, RenderInfo *render_info=nullptr)
bool table_is_replicated(const TableDescriptor *td)
bool hasTableAccessPrivileges(const TableDescriptor *td, const TSessionId &session)

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

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

5644  {
5645  auto stdlog = STDLOG(get_session_ptr(session));
5646  auto session_ptr = stdlog.getConstSessionInfo();
5647  auto const& cat = session_ptr->getCatalog();
5648 
5649  if (leaf_aggregator_.leafCount() > 0) {
5650  return leaf_aggregator_.get_table_epochLeaf(*session_ptr, db_id, table_id);
5651  }
5652  return cat.getTableEpoch(db_id, table_id);
5653 }
int32_t get_table_epochLeaf(const Catalog_Namespace::SessionInfo &parent_session_info, const int32_t db_id, const int32_t table_id)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:443
size_t leafCount() const
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 5655 of file MapDHandler.cpp.

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

5656  {
5657  auto stdlog = STDLOG(get_session_ptr(session), "table_name", table_name);
5658  auto session_ptr = stdlog.getConstSessionInfo();
5659  auto const& cat = session_ptr->getCatalog();
5660  auto td = cat.getMetadataForTable(
5661  table_name,
5662  false); // don't populate fragmenter on this call since we only want metadata
5663  int32_t db_id = cat.getCurrentDB().dbId;
5664  if (leaf_aggregator_.leafCount() > 0) {
5665  return leaf_aggregator_.get_table_epochLeaf(*session_ptr, db_id, td->tableId);
5666  }
5667  return cat.getTableEpoch(db_id, td->tableId);
5668 }
int32_t get_table_epochLeaf(const Catalog_Namespace::SessionInfo &parent_session_info, const int32_t db_id, const int32_t table_id)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
LeafAggregator leaf_aggregator_
Definition: MapDHandler.h:443
size_t leafCount() const
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 1915 of file MapDHandler.cpp.

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

Referenced by get_completion_hints_unsorted().

1916  {
1917  auto stdlog = STDLOG(get_session_ptr(session));
1918  get_tables_impl(table_names, stdlog, GET_PHYSICAL_TABLES_AND_VIEWS);
1919 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
void get_tables_impl(std::vector< std::string > &table_names, query_state::StdLog &stdlog, const GetTablesType get_tables_type)
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void MapDHandler::get_tables_impl ( std::vector< std::string > &  table_names,
query_state::StdLog stdlog,
const GetTablesType  get_tables_type 
)
private

Definition at line 1881 of file MapDHandler.cpp.

References GET_PHYSICAL_TABLES, GET_VIEWS, query_state::StdLog::getConstSessionInfo(), hasTableAccessPrivileges(), and run_benchmark_import::tables.

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

1883  {
1884  auto const session_ptr = stdlog.getConstSessionInfo();
1885  auto const& cat = session_ptr->getCatalog();
1886  const auto tables = cat.getAllTableMetadata();
1887  for (const auto td : tables) {
1888  if (td->shard >= 0) {
1889  // skip shards, they're not standalone tables
1890  continue;
1891  }
1892  switch (get_tables_type) {
1893  case GET_PHYSICAL_TABLES: {
1894  if (td->isView) {
1895  continue;
1896  }
1897  break;
1898  }
1899  case GET_VIEWS: {
1900  if (!td->isView) {
1901  continue;
1902  }
1903  }
1904  default:
1905  break;
1906  }
1907  if (!hasTableAccessPrivileges(td, session_ptr->get_session_id())) {
1908  // skip table, as there are no privileges to access it
1909  continue;
1910  }
1911  table_names.push_back(td->tableName);
1912  }
1913 }
std::shared_ptr< Catalog_Namespace::SessionInfo const > getConstSessionInfo() const
Definition: QueryState.cpp:128
bool hasTableAccessPrivileges(const TableDescriptor *td, const TSessionId &session)

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

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

1934  {
1935  auto stdlog = STDLOG(get_session_ptr(session));
1936  auto session_ptr = stdlog.getConstSessionInfo();
1937  auto query_state = create_query_state(session_ptr, "");
1938  stdlog.setQueryState(query_state);
1939 
1940  const auto& cat = session_ptr->getCatalog();
1941  const auto tables = cat.getAllTableMetadata();
1942  _return.reserve(tables.size());
1943 
1944  for (const auto td : tables) {
1945  if (td->shard >= 0) {
1946  // skip shards, they're not standalone tables
1947  continue;
1948  }
1949  if (!hasTableAccessPrivileges(td, session)) {
1950  // skip table, as there are no privileges to access it
1951  continue;
1952  }
1953 
1954  TTableMeta ret;
1955  ret.table_name = td->tableName;
1956  ret.is_view = td->isView;
1957  ret.is_replicated = table_is_replicated(td);
1958  ret.shard_count = td->nShards;
1959  ret.max_rows = td->maxRows;
1960  ret.table_id = td->tableId;
1961 
1962  std::vector<TTypeInfo> col_types;
1963  std::vector<std::string> col_names;
1964  size_t num_cols = 0;
1965  if (td->isView) {
1966  try {
1967  const auto query_ra = parse_to_ra(query_state->createQueryStateProxy(),
1968  td->viewSQL,
1969  {},
1970  boost::none,
1972  TQueryResult result;
1973  execute_rel_alg(result,
1974  query_state->createQueryStateProxy(),
1975  query_ra,
1976  true,
1978  -1,
1979  -1,
1980  false,
1981  true,
1982  false,
1983  false,
1984  false);
1985  num_cols = result.row_set.row_desc.size();
1986  for (const auto col : result.row_set.row_desc) {
1987  if (col.is_physical) {
1988  num_cols--;
1989  continue;
1990  }
1991  col_types.push_back(col.col_type);
1992  col_names.push_back(col.col_name);
1993  }
1994  } catch (std::exception& e) {
1995  LOG(WARNING) << "get_tables_meta: Ignoring broken view: " << td->tableName;
1996  }
1997  } else {
1998  try {
1999  if (hasTableAccessPrivileges(td, session)) {
2000  const auto col_descriptors =
2001  cat.getAllColumnMetadataForTable(td->tableId, false, true, false);
2002  const auto deleted_cd = cat.getDeletedColumn(td);
2003  for (const auto cd : col_descriptors) {
2004  if (cd == deleted_cd) {
2005  continue;
2006  }
2007  col_types.push_back(ThriftSerializers::type_info_to_thrift(cd->columnType));
2008  col_names.push_back(cd->columnName);
2009  }
2010  num_cols = col_descriptors.size();
2011  } else {
2012  continue;
2013  }
2014  } catch (const std::runtime_error& e) {
2015  THROW_MAPD_EXCEPTION(e.what());
2016  }
2017  }
2018 
2019  ret.num_cols = num_cols;
2020  std::copy(col_types.begin(), col_types.end(), std::back_inserter(ret.col_types));
2021  std::copy(col_names.begin(), col_names.end(), std::back_inserter(ret.col_names));
2022 
2023  _return.push_back(ret);
2024  }
2025 }
#define LOG(tag)
Definition: Logger.h:185
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:460
std::shared_ptr< query_state::QueryState > create_query_state(ARGS &&...args)
Definition: MapDHandler.h:468
std::vector< PushedDownFilterInfo > execute_rel_alg(TQueryResult &_return, QueryStateProxy, const std::string &query_ra, const bool column_format, const ExecutorDeviceType executor_device_type, const int32_t first_n, const int32_t at_most_n, const bool just_explain, const bool just_validate, const bool find_push_down_candidates, const bool just_calcite_explain, const bool explain_optimized_ir) const
std::string parse_to_ra(QueryStateProxy, const std::string &query_str, const std::vector< TFilterPushDownInfo > &filter_push_down_info, OptionalTableMap tableNames, const MapDParameters mapd_parameters, RenderInfo *render_info=nullptr)
bool table_is_replicated(const TableDescriptor *td)
TTypeInfo type_info_to_thrift(const SQLTypeInfo &ti)
bool hasTableAccessPrivileges(const TableDescriptor *td, const TSessionId &session)
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

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

Definition at line 1182 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().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 1242 of file MapDHandler.cpp.

References get_table_details(), and to_upper().

Referenced by get_completion_hints().

1245  {
1246  std::unordered_set<std::string> compatible_table_names_by_column;
1247  for (const auto& table_name : table_names) {
1248  TTableDetails table_details;
1249  get_table_details(table_details, session, table_name);
1250  for (const auto& column_type : table_details.row_desc) {
1251  if (uc_column_names.find(to_upper(column_type.col_name)) != uc_column_names.end()) {
1252  compatible_table_names_by_column.emplace(to_upper(table_name));
1253  break;
1254  }
1255  }
1256  }
1257  return compatible_table_names_by_column;
1258 }
std::string to_upper(const std::string &str)
void get_table_details(TTableDetails &_return, const TSessionId &session, const std::string &table_name) override

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 2027 of file MapDHandler.cpp.

References get_session_ptr(), and STDLOG.

2028  {
2029  auto stdlog = STDLOG(get_session_ptr(session));
2030  auto session_ptr = stdlog.getConstSessionInfo();
2031  std::list<Catalog_Namespace::UserMetadata> user_list;
2032 
2033  if (!session_ptr->get_currentUser().isSuper) {
2034  user_list = SysCatalog::instance().getAllUserMetadata(
2035  session_ptr->getCatalog().getCurrentDB().dbId);
2036  } else {
2037  user_list = SysCatalog::instance().getAllUserMetadata();
2038  }
2039  for (auto u : user_list) {
2040  user_names.push_back(u.userName);
2041  }
2042 }
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:

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

Definition at line 3315 of file MapDHandler.cpp.

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

Referenced by share_dashboard(), and unshare_dashboard().

3317  {
3318  const auto session_info = get_session_copy(session);
3319  auto& cat = session_info.getCatalog();
3320  auto dash = cat.getMetadataForDashboard(dashboard_id);
3321  if (!dash) {
3322  THROW_MAPD_EXCEPTION("Exception: Dashboard id " + std::to_string(dashboard_id) +
3323  " does not exist");
3324  } else if (session_info.get_currentUser().userId != dash->userId &&
3325  !session_info.get_currentUser().isSuper) {
3326  throw std::runtime_error(
3327  "User should be either owner of dashboard or super user to share/unshare it");
3328  }
3329  std::vector<std::string> valid_groups;
3331  for (auto& group : groups) {
3332  user_meta.isSuper = false; // initialize default flag
3333  if (!SysCatalog::instance().getGrantee(group)) {
3334  THROW_MAPD_EXCEPTION("Exception: User/Role " + group + " does not exist");
3335  } else if (!user_meta.isSuper) {
3336  valid_groups.push_back(group);
3337  }
3338  }
3339  return valid_groups;
3340 }
std::string to_string(char const *&&v)
#define THROW_MAPD_EXCEPTION(errstr)
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
std::atomic< bool > isSuper
Definition: SysCatalog.h:85

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void MapDHandler::get_version ( std::string &  _return)
override

Definition at line 2044 of file MapDHandler.cpp.

References MAPD_RELEASE.

2044  {
2045  version = MAPD_RELEASE;
2046 }
static const std::string MAPD_RELEASE
Definition: release.h:43
void MapDHandler::get_views ( std::vector< std::string > &  _return,
const TSessionId &  session 
)
override

Definition at line 1927 of file MapDHandler.cpp.

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

1928  {
1929  auto stdlog = STDLOG(get_session_ptr(session));
1930  get_tables_impl(table_names, stdlog, GET_VIEWS);
1931 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
void get_tables_impl(std::vector< std::string > &table_names, query_state::StdLog &stdlog, const GetTablesType get_tables_type)
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

TSessionId MapDHandler::getInvalidSessionId ( ) const

Definition at line 2088 of file MapDHandler.cpp.

References INVALID_SESSION_ID.

2088  {
2089  return INVALID_SESSION_ID;
2090 }
#define INVALID_SESSION_ID
std::vector< TargetMetaInfo > MapDHandler::getTargetMetaInfo ( const std::vector< std::shared_ptr< Analyzer::TargetEntry >> &  targets) const
private

Definition at line 4640 of file MapDHandler.cpp.

References CHECK(), and run_benchmark_import::result.

Referenced by execute_root_plan().

4641  {
4642  std::vector<TargetMetaInfo> result;
4643  for (const auto target : targets) {
4644  CHECK(target);
4645  CHECK(target->get_expr());
4646  result.emplace_back(target->get_resname(), target->get_expr()->get_type_info());
4647  }
4648  return result;
4649 }
CHECK(cgen_state)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector< std::string > MapDHandler::getTargetNames ( const std::vector< TargetMetaInfo > &a