OmniSciDB  c1a53651b2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DBHandler Class Reference

#include <DBHandler.h>

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

Classes

struct  DeferredCopyFromSessions
 
struct  DeferredCopyFromState
 

Public Member Functions

 DBHandler (const std::vector< LeafHostInfo > &db_leaves, const std::vector< LeafHostInfo > &string_leaves, const std::string &base_data_path, const bool allow_multifrag, const bool jit_debug, const bool intel_jit_profile, const bool read_only, const bool allow_loop_joins, const bool enable_rendering, const bool renderer_use_ppll_polys, const bool renderer_prefer_igpu, const unsigned renderer_vulkan_timeout_ms, const bool renderer_use_parallel_executors, const bool enable_auto_clear_render_mem, const int render_oom_retry_threshold, const size_t render_mem_bytes, const size_t max_concurrent_render_sessions, const size_t reserved_gpu_mem, const bool render_compositor_use_last_gpu, const size_t num_reader_threads, const AuthMetadata &authMetadata, SystemParameters &system_parameters, const bool legacy_syntax, const int idle_session_duration, const int max_session_duration, const std::string &udf_filename, const std::string &clang_path, const std::vector< std::string > &clang_options, const File_Namespace::DiskCacheConfig &disk_cache_config, const bool is_new_db)
 
void initialize (const bool is_new_db)
 
 ~DBHandler () override
 
void krb5_connect (TKrb5Session &session, const std::string &token, const std::string &dbname) override
 
void connect (TSessionId &session, const std::string &username, const std::string &passwd, const std::string &dbname) override
 
void disconnect (const TSessionId &session) override
 
void switch_database (const TSessionId &session, const std::string &dbname) override
 
void clone_session (TSessionId &session2, const TSessionId &session1) override
 
void get_server_status (TServerStatus &_return, const TSessionId &session) override
 
void get_status (std::vector< TServerStatus > &_return, const TSessionId &session) override
 
void get_hardware_info (TClusterHardwareInfo &_return, const TSessionId &session) override
 
bool hasTableAccessPrivileges (const TableDescriptor *td, const Catalog_Namespace::SessionInfo &session_info)
 
void get_tables (std::vector< std::string > &_return, const TSessionId &session) override
 
void get_tables_for_database (std::vector< std::string > &_return, const TSessionId &session, const std::string &database_name) 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_table_details_for_database (TTableDetails &_return, const TSessionId &session, const std::string &table_name, const std::string &database_name) override
 
void get_internal_table_details (TTableDetails &_return, const TSessionId &session, const std::string &table_name, const bool include_system_columns) override
 
void get_internal_table_details_for_database (TTableDetails &_return, const TSessionId &session, const std::string &table_name, const std::string &database_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 clearRenderMemory (const TSessionId &session)
 
void set_cur_session (const TSessionId &parent_session, const TSessionId &leaf_session, const std::string &start_time_str, const std::string &label, bool for_running_query_kernel) override
 
void invalidate_cur_session (const TSessionId &parent_session, const TSessionId &leaf_session, const std::string &start_time_str, const std::string &label, bool for_running_query_kernel) override
 
void set_table_epoch (const TSessionId &session, const int db_id, const int table_id, const int new_epoch) override
 
void set_table_epoch_by_name (const TSessionId &session, const std::string &table_name, const int new_epoch) override
 
int32_t get_table_epoch (const TSessionId &session, const int32_t db_id, const int32_t table_id) override
 
int32_t get_table_epoch_by_name (const TSessionId &session, const std::string &table_name) override
 
void get_table_epochs (std::vector< TTableEpochInfo > &_return, const TSessionId &session, const int32_t db_id, const int32_t table_id) override
 
void set_table_epochs (const TSessionId &session, const int32_t db_id, const std::vector< TTableEpochInfo > &table_epochs) override
 
void get_session_info (TSessionInfo &_return, const TSessionId &session) override
 
void set_leaf_info (const TSessionId &session, const TLeafInfo &info) override
 
void sql_execute (ExecutionResult &_return, const TSessionId &session, const std::string &query, const bool column_format, const int32_t first_n, const int32_t at_most_n, lockmgr::LockedTableDescriptors &locks)
 
void sql_execute (TQueryResult &_return, const TSessionId &session, const std::string &query, const bool column_format, const std::string &nonce, const int32_t first_n, const int32_t at_most_n) override
 
void get_completion_hints (std::vector< TCompletionHint > &hints, const TSessionId &session, const std::string &sql, const int cursor) override
 
void sql_execute_df (TDataFrame &_return, const TSessionId &session, const std::string &query, const TDeviceType::type device_type, const int32_t device_id, const int32_t first_n, const TArrowTransport::type transport_method) override
 
void sql_execute_gdf (TDataFrame &_return, const TSessionId &session, const std::string &query, const int32_t device_id, const int32_t first_n) override
 
void deallocate_df (const TSessionId &session, const TDataFrame &df, const TDeviceType::type device_type, const int32_t device_id) override
 
void interrupt (const TSessionId &query_session, const TSessionId &interrupt_session) override
 
void sql_validate (TRowDescriptor &_return, const TSessionId &session, const std::string &query) override
 
TExecuteMode::type getExecutionMode (const TSessionId &session)
 
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
 
int32_t create_custom_expression (const TSessionId &session, const TCustomExpression &custom_expression) override
 
void get_custom_expressions (std::vector< TCustomExpression > &_return, const TSessionId &session) override
 
void update_custom_expression (const TSessionId &session, const int32_t id, const std::string &expression_json) override
 
void delete_custom_expressions (const TSessionId &session, const std::vector< int32_t > &custom_expression_ids, const bool do_soft_delete) override
 
void get_dashboard (TDashboard &_return, const TSessionId &session, const int32_t dashboard_id) override
 
void get_dashboards (std::vector< TDashboard > &_return, const TSessionId &session) override
 
int32_t create_dashboard (const TSessionId &session, const std::string &dashboard_name, const std::string &dashboard_state, const std::string &image_hash, const std::string &dashboard_metadata) override
 
void replace_dashboard (const TSessionId &session, const int32_t dashboard_id, const std::string &dashboard_name, const std::string &dashboard_owner, const std::string &dashboard_state, const std::string &image_hash, const std::string &dashboard_metadata) override
 
void delete_dashboard (const TSessionId &session, const int32_t dashboard_id) override
 
void share_dashboards (const TSessionId &session, const std::vector< int32_t > &dashboard_ids, const std::vector< std::string > &groups, const TDashboardPermissions &permissions) override
 
void delete_dashboards (const TSessionId &session, const std::vector< int32_t > &dashboard_ids) override
 
void share_dashboard (const TSessionId &session, const int32_t dashboard_id, const std::vector< std::string > &groups, const std::vector< std::string > &objects, const TDashboardPermissions &permissions, const bool grant_role) override
 
void unshare_dashboards (const TSessionId &session, const std::vector< int32_t > &dashboard_ids, const std::vector< std::string > &groups, const TDashboardPermissions &permissions) override
 
void unshare_dashboard (const TSessionId &session, const int32_t dashboard_id, const std::vector< std::string > &groups, const std::vector< std::string > &objects, const TDashboardPermissions &permissions) override
 
void get_dashboard_grantees (std::vector< TDashboardGrantees > &_return, const TSessionId &session, const 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, const std::vector< std::string > &column_names) override
 
void load_table_binary_columnar (const TSessionId &session, const std::string &table_name, const std::vector< TColumn > &cols, const std::vector< std::string > &column_names) override
 
void load_table_binary_columnar_polys (const TSessionId &session, const std::string &table_name, const std::vector< TColumn > &cols, const std::vector< std::string > &column_names, const bool assign_render_groups) override
 
void load_table_binary_arrow (const TSessionId &session, const std::string &table_name, const std::string &arrow_stream, const bool use_column_names) override
 
void load_table (const TSessionId &session, const std::string &table_name, const std::vector< TStringRow > &rows, const std::vector< std::string > &column_names) 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 TCreateParams &create_params) override
 
void import_table (const TSessionId &session, const std::string &table_name, const std::string &file_name, const TCopyParams &copy_params) override
 
void import_geo_table (const TSessionId &session, const std::string &table_name, const std::string &file_name, const TCopyParams &copy_params, const TRowDescriptor &row_desc, const TCreateParams &create_params) override
 
void import_table_status (TImportStatus &_return, const TSessionId &session, const std::string &import_id) override
 
void get_first_geo_file_in_archive (std::string &_return, const TSessionId &session, const std::string &archive_path, const TCopyParams &copy_params) override
 
void get_all_files_in_archive (std::vector< std::string > &_return, const TSessionId &session, const std::string &archive_path, const TCopyParams &copy_params) override
 
void get_layers_in_geo_file (std::vector< TGeoFileLayerInfo > &_return, const TSessionId &session, const std::string &file_name, const TCopyParams &copy_params) override
 
int64_t query_get_outer_fragment_count (const TSessionId &session, const std::string &select_query) override
 
void check_table_consistency (TTableMeta &_return, const TSessionId &session, const int32_t table_id) override
 
void start_query (TPendingQuery &_return, const TSessionId &leaf_session, const TSessionId &parent_session, const std::string &serialized_rel_alg_dag, const std::string &start_time_str, const bool just_explain, const std::vector< int64_t > &outer_fragment_indices) override
 
void execute_query_step (TStepResult &_return, const TPendingQuery &pending_query, const TSubqueryId subquery_id, const std::string &start_time_str) override
 
void broadcast_serialized_rows (const TSerializedRows &serialized_rows, const TRowDescriptor &row_desc, const TQueryId query_id, const TSubqueryId subquery_id, const bool is_final_subquery_result) 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 insert_chunks (const TSessionId &session, const TInsertChunks &insert_chunks) override
 
void checkpoint (const TSessionId &session, 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
 
void get_all_effective_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 get_function_names (std::vector< std::string > &_return, const TSessionId &session) override
 
void get_runtime_function_names (std::vector< std::string > &_return, const TSessionId &session) override
 
void get_function_details (std::vector< TUserDefinedFunction > &_return, const TSessionId &session, const std::vector< std::string > &udf_names) override
 
void get_table_function_names (std::vector< std::string > &_return, const TSessionId &session) override
 
void get_runtime_table_function_names (std::vector< std::string > &_return, const TSessionId &session) override
 
void get_table_function_details (std::vector< TUserDefinedTableFunction > &_return, const TSessionId &session, const std::vector< std::string > &udtf_names) override
 
void shutdown ()
 
void emergency_shutdown ()
 
TSessionId getInvalidSessionId () const
 
void internal_connect (TSessionId &session, const std::string &username, const std::string &dbname)
 
bool isAggregator () const
 
bool checkInMemorySystemTableQuery (const std::unordered_set< shared::TableKey > &tables_selected_from) const
 
template<typename... ARGS>
std::shared_ptr
< query_state::QueryState
create_query_state (ARGS &&...args)
 
Catalog_Namespace::SessionInfo get_session_copy (const TSessionId &session_id)
 
void get_tables_meta_impl (std::vector< TTableMeta > &_return, QueryStateProxy query_state_proxy, const Catalog_Namespace::SessionInfo &session_info, const bool with_table_locks=true)
 
void resizeDispatchQueue (size_t queue_size)
 

Static Public Member Functions

static size_t max_bytes_for_thrift ()
 

Public Attributes

std::shared_ptr
< Data_Namespace::DataMgr
data_mgr_
 
LeafAggregator leaf_aggregator_
 
std::vector< LeafHostInfodb_leaves_
 
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_
 
heavyai::shared_mutex sessions_mutex_
 
std::mutex render_mutex_
 
int64_t start_time_
 
const AuthMetadataauthMetadata_
 
SystemParameterssystem_parameters_
 
std::shared_ptr< QueryEnginequery_engine_
 
std::unique_ptr< RenderHandlerrender_handler_
 
std::unique_ptr
< HeavyDBAggHandler
agg_handler_
 
std::unique_ptr
< HeavyDBLeafHandler
leaf_handler_
 
std::shared_ptr< Calcitecalcite_
 
const bool legacy_syntax_
 
std::unique_ptr
< QueryDispatchQueue
dispatch_queue_
 

Protected Member Functions

std::shared_ptr
< Catalog_Namespace::SessionInfo
get_session_ptr (const TSessionId &session_id)
 
ConnectionInfo getConnectionInfo () const
 

Private Types

enum  AssignRenderGroupsMode { AssignRenderGroupsMode::kNone, AssignRenderGroupsMode::kAssign, AssignRenderGroupsMode::kCleanUp }
 
using RenderGroupAssignmentColumnMap = std::unordered_map< std::string, std::unique_ptr< import_export::RenderGroupAnalyzer >>
 
using RenderGroupAssignmentTableMap = std::unordered_map< std::string, RenderGroupAssignmentColumnMap >
 
using RenderGroupAnalyzerSessionMap = std::unordered_map< TSessionId, RenderGroupAssignmentTableMap >
 

Private Member Functions

std::shared_ptr
< Catalog_Namespace::SessionInfo
create_new_session (TSessionId &session, const std::string &dbname, const Catalog_Namespace::UserMetadata &user_meta, std::shared_ptr< Catalog_Namespace::Catalog > cat)
 
void connect_impl (TSessionId &session, const std::string &passwd, const std::string &dbname, const Catalog_Namespace::UserMetadata &user_meta, std::shared_ptr< Catalog_Namespace::Catalog > cat, query_state::StdLog &stdlog)
 
void disconnect_impl (Catalog_Namespace::SessionInfoPtr &session_ptr)
 
void check_table_load_privileges (const Catalog_Namespace::SessionInfo &session_info, const std::string &table_name)
 
void get_tables_impl (std::vector< std::string > &table_names, const Catalog_Namespace::SessionInfo &, const GetTablesType get_tables_type, const std::string &database_name={})
 
void get_table_details_impl (TTableDetails &_return, query_state::StdLog &stdlog, const std::string &table_name, const bool get_system, const bool get_physical, const std::string &database_name={})
 
void getAllRolesForUserImpl (std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr, std::vector< std::string > &roles, const std::string &granteeName, bool effective)
 
void check_read_only (const std::string &str)
 
void validateGroups (const std::vector< std::string > &groups)
 
void validateDashboardIdsForSharing (const Catalog_Namespace::SessionInfo &session_info, const std::vector< int32_t > &dashboard_ids)
 
void shareOrUnshareDashboards (const TSessionId &session, const std::vector< int32_t > &dashboard_ids, const std::vector< std::string > &groups, const TDashboardPermissions &permissions, const bool do_share)
 
std::pair< TPlanResult,
lockmgr::LockedTableDescriptors
parse_to_ra (QueryStateProxy, const std::string &query_str, const std::vector< TFilterPushDownInfo > &filter_push_down_info, const bool acquire_locks, const SystemParameters &system_parameters, bool check_privileges=true)
 
void sql_execute_local (TQueryResult &_return, const QueryStateProxy &query_state_proxy, const std::shared_ptr< Catalog_Namespace::SessionInfo > session_ptr, const std::string &query_str, const bool column_format, const std::string &nonce, const int32_t first_n, const int32_t at_most_n, const bool use_calcite)
 
int64_t process_deferred_copy_from (const TSessionId &session_id)
 
void sql_execute_impl (ExecutionResult &_return, QueryStateProxy, const bool column_format, const ExecutorDeviceType executor_device_type, const int32_t first_n, const int32_t at_most_n, const bool use_calcite, lockmgr::LockedTableDescriptors &locks)
 
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)
 
TPlanResult processCalciteRequest (QueryStateProxy, const std::shared_ptr< Catalog_Namespace::Catalog > &cat, const std::string &query_str, const std::vector< TFilterPushDownInfo > &filter_push_down_info, const SystemParameters &system_parameters, const bool check_privileges)
 
TQueryResult validate_rel_alg (const std::string &query_ra, QueryStateProxy)
 
void dispatch_query_task (std::shared_ptr< QueryDispatchQueue::Task > query_task, const bool is_update_delete)
 
std::vector< PushedDownFilterInfoexecute_rel_alg (ExecutionResult &_return, QueryStateProxy, const std::string &query_ra, const bool column_format, const ExecutorDeviceType executor_device_type, const int32_t first_n, const int32_t at_most_n, const bool just_validate, const bool find_push_down_candidates, const ExplainInfo &explain_info, const std::optional< size_t > executor_index=std::nullopt) const
 
void execute_rel_alg_with_filter_push_down (ExecutionResult &_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 executeDdl (TQueryResult &_return, const std::string &query_ra, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
 
void executeDdl (ExecutionResult &_return, const std::string &query_ra, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
 
TColumnType populateThriftColumnType (const Catalog_Namespace::Catalog *cat, const ColumnDescriptor *cd)
 
TRowDescriptor fixup_row_descriptor (const TRowDescriptor &row_desc, const Catalog_Namespace::Catalog &cat)
 
void set_execution_mode_nolock (Catalog_Namespace::SessionInfo *session_ptr, const TExecuteMode::type mode)
 
char unescape_char (std::string str)
 
import_export::CopyParams thrift_to_copyparams (const TCopyParams &cp)
 
TCopyParams copyparams_to_thrift (const import_export::CopyParams &cp)
 
void check_geospatial_files (const boost::filesystem::path file_path, const import_export::CopyParams &copy_params)
 
void render_rel_alg (TRenderResult &_return, const std::string &query_ra, const std::string &query_str, const Catalog_Namespace::SessionInfo &session_info, const std::string &render_type, const bool is_projection_query)
 
TColumnType create_geo_column (const TDatumType::type type, const std::string &name, const bool is_array)
 
void convertResultSet (ExecutionResult &result, const Catalog_Namespace::SessionInfo &session_info, const std::string &query_state_str, TQueryResult &_return)
 
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
 
void get_completion_hints_unsorted (std::vector< TCompletionHint > &hints, std::vector< std::string > &visible_tables, query_state::StdLog &stdlog, const std::string &sql, const int cursor)
 
void get_token_based_completions (std::vector< TCompletionHint > &hints, query_state::StdLog &stdlog, std::vector< std::string > &visible_tables, const std::string &sql, const int cursor)
 
std::unordered_map
< std::string,
std::unordered_set
< std::string > > 
fill_column_names_by_table (std::vector< std::string > &table_names, query_state::StdLog &stdlog)
 
TDashboard get_dashboard_impl (const std::shared_ptr< Catalog_Namespace::SessionInfo const > &session_ptr, Catalog_Namespace::UserMetadata &user_meta, const DashboardDescriptor *dash, const bool populate_state=true)
 
std::unordered_set< std::string > get_uc_compatible_table_names_by_column (const std::unordered_set< std::string > &uc_column_names, std::vector< std::string > &table_names, query_state::StdLog &stdlog)
 
std::unique_ptr
< lockmgr::AbstractLockContainer
< const TableDescriptor * > > 
prepare_loader_generic (const Catalog_Namespace::SessionInfo &session_info, const std::string &table_name, size_t num_cols, std::unique_ptr< import_export::Loader > *loader, std::vector< std::unique_ptr< import_export::TypedImportBuffer >> *import_buffers, const std::vector< std::string > &column_names, std::string load_type)
 
void fillGeoColumns (const TSessionId &session, const Catalog_Namespace::Catalog &catalog, std::vector< std::unique_ptr< import_export::TypedImportBuffer >> &import_buffers, const ColumnDescriptor *cd, size_t &col_idx, size_t num_rows, const std::string &table_name, bool assign_render_groups)
 
void fillMissingBuffers (const TSessionId &session, const Catalog_Namespace::Catalog &catalog, std::vector< std::unique_ptr< import_export::TypedImportBuffer >> &import_buffers, const std::list< const ColumnDescriptor * > &cds, const std::vector< int > &desc_id_to_column_id, size_t num_rows, const std::string &table_name, bool assign_render_groups)
 
Catalog_Namespace::SessionInfoPtr findCalciteSession (TSessionId const &) const
 
void check_and_invalidate_sessions (Parser::DDLStmt *ddl)
 
std::string const createInMemoryCalciteSession (const std::shared_ptr< Catalog_Namespace::Catalog > &catalog_ptr)
 
void removeInMemoryCalciteSession (const std::string &session_id)
 
ExecutionResult getUserSessions (std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
 
ExecutionResult getQueries (std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
 
void get_queries_info (std::vector< TQueryInfo > &_return, const TSessionId &session) override
 
void interruptQuery (const Catalog_Namespace::SessionInfo &session_info, const std::string &target_session)
 
void alterSystemClear (const std::string &sesson_id, ExecutionResult &result, const std::string &cache_type, int64_t &execution_time_ms)
 
void alterSession (const std::string &sesson_id, ExecutionResult &result, const std::pair< std::string, std::string > &session_parameter, int64_t &execution_time_ms)
 
void loadTableBinaryColumnarInternal (const TSessionId &session, const std::string &table_name, const std::vector< TColumn > &cols, const std::vector< std::string > &column_names, const AssignRenderGroupsMode assign_render_groups_mode)
 
TRole::type getServerRole () const
 
void importGeoTableGlobFilterSort (const TSessionId &session, const std::string &table_name, const std::string &file_name, const import_export::CopyParams &copy_params, const TRowDescriptor &row_desc, const TCreateParams &create_params)
 
void importGeoTableSingle (const TSessionId &session, const std::string &table_name, const std::string &file_name, const import_export::CopyParams &copy_params, const TRowDescriptor &row_desc, const TCreateParams &create_params)
 
void resetSessionsStore ()
 

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 void convertData (TQueryResult &_return, ExecutionResult &result, const QueryStateProxy &query_state_proxy, const bool column_format, const int32_t first_n, const int32_t at_most_n)
 
static void convertExplain (TQueryResult &_return, const ResultSet &results, const bool column_format)
 
static void convertResult (TQueryResult &_return, const ResultSet &results, const bool column_format)
 
static void convertRows (TQueryResult &_return, QueryStateProxy query_state_proxy, const std::vector< TargetMetaInfo > &targets, const ResultSet &results, const bool column_format, const int32_t first_n, const int32_t at_most_n)
 
static void createSimpleResult (TQueryResult &_return, const ResultSet &results, const bool column_format, const std::string label)
 
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)
 
static bool has_server_permission (const AccessPrivileges &privs, const TDBObjectPermissions &permissions)
 

Private Attributes

std::atomic< bool > initialized_ {false}
 
query_state::QueryStates query_states_
 
std::unordered_map
< std::string,
Catalog_Namespace::SessionInfoPtr
calcite_sessions_
 
heavyai::shared_mutex calcite_sessions_mtx_
 
bool super_user_rights_
 
const int idle_session_duration_
 
const int max_session_duration_
 
const bool enable_rendering_
 
const bool renderer_use_ppll_polys_
 
const bool renderer_prefer_igpu_
 
const unsigned renderer_vulkan_timeout_
 
const bool renderer_use_parallel_executors_
 
const bool enable_auto_clear_render_mem_
 
const int render_oom_retry_threshold_
 
const size_t max_concurrent_render_sessions_
 
const size_t reserved_gpu_mem_
 
const bool render_compositor_use_last_gpu_
 
const size_t render_mem_bytes_
 
const size_t num_reader_threads_
 
const
File_Namespace::DiskCacheConfig
disk_cache_config_
 
const std::string & udf_filename_
 
const std::string & clang_path_
 
const std::vector< std::string > & clang_options_
 
int32_t max_num_sessions_ {-1}
 
std::unique_ptr
< Catalog_Namespace::SessionsStore
sessions_store_
 
DeferredCopyFromSessions deferred_copy_from_sessions
 
std::mutex handle_to_dev_ptr_mutex_
 
std::unordered_map
< std::string, std::string > 
ipc_handle_to_dev_ptr_
 
std::map< const std::string,
const PermissionFuncPtr
permissionFuncMap_
 
RenderGroupAnalyzerSessionMap render_group_assignment_map_
 
std::mutex render_group_assignment_mutex_
 
heavyai::shared_mutex custom_expressions_mutex_
 

Friends

class RenderHandler::Impl
 
class HeavyDBAggHandler
 
class HeavyDBLeafHandler
 
void run_warmup_queries (std::shared_ptr< DBHandler > handler, std::string base_path, std::string query_file_path)
 

Detailed Description

Definition at line 166 of file DBHandler.h.

Member Typedef Documentation

using DBHandler::RenderGroupAnalyzerSessionMap = std::unordered_map<TSessionId, RenderGroupAssignmentTableMap>
private

Definition at line 1082 of file DBHandler.h.

using DBHandler::RenderGroupAssignmentColumnMap = std::unordered_map<std::string, std::unique_ptr<import_export::RenderGroupAnalyzer>>
private

Definition at line 1078 of file DBHandler.h.

using DBHandler::RenderGroupAssignmentTableMap = std::unordered_map<std::string, RenderGroupAssignmentColumnMap>
private

Definition at line 1080 of file DBHandler.h.

Member Enumeration Documentation

Enumerator
kNone 
kAssign 
kCleanUp 

Definition at line 1065 of file DBHandler.h.

1065 { kNone, kAssign, kCleanUp };

Constructor & Destructor Documentation

DBHandler::DBHandler ( const std::vector< LeafHostInfo > &  db_leaves,
const std::vector< LeafHostInfo > &  string_leaves,
const std::string &  base_data_path,
const bool  allow_multifrag,
const bool  jit_debug,
const bool  intel_jit_profile,
const bool  read_only,
const bool  allow_loop_joins,
const bool  enable_rendering,
const bool  renderer_use_ppll_polys,
const bool  renderer_prefer_igpu,
const unsigned  renderer_vulkan_timeout_ms,
const bool  renderer_use_parallel_executors,
const bool  enable_auto_clear_render_mem,
const int  render_oom_retry_threshold,
const size_t  render_mem_bytes,
const size_t  max_concurrent_render_sessions,
const size_t  reserved_gpu_mem,
const bool  render_compositor_use_last_gpu,
const size_t  num_reader_threads,
const AuthMetadata authMetadata,
SystemParameters system_parameters,
const bool  legacy_syntax,
const int  idle_session_duration,
const int  max_session_duration,
const std::string &  udf_filename,
const std::string &  clang_path,
const std::vector< std::string > &  clang_options,
const File_Namespace::DiskCacheConfig disk_cache_config,
const bool  is_new_db 
)

Definition at line 165 of file DBHandler.cpp.

198  : leaf_aggregator_(db_leaves)
199  , db_leaves_(db_leaves)
200  , string_leaves_(string_leaves)
201  , base_data_path_(base_data_path)
202  , random_gen_(std::random_device{}())
203  , session_id_dist_(0, INT32_MAX)
204  , jit_debug_(jit_debug)
205  , intel_jit_profile_(intel_jit_profile)
206  , allow_multifrag_(allow_multifrag)
207  , read_only_(read_only)
208  , allow_loop_joins_(allow_loop_joins)
209  , authMetadata_(authMetadata)
210  , system_parameters_(system_parameters)
211  , legacy_syntax_(legacy_syntax)
212  , dispatch_queue_(
213  std::make_unique<QueryDispatchQueue>(system_parameters.num_executors))
214  , super_user_rights_(false)
215  , idle_session_duration_(idle_session_duration * 60)
216  , max_session_duration_(max_session_duration * 60)
217  , enable_rendering_(enable_rendering)
218  , renderer_use_ppll_polys_(renderer_use_ppll_polys)
219  , renderer_prefer_igpu_(renderer_prefer_igpu)
220  , renderer_vulkan_timeout_(renderer_vulkan_timeout_ms)
221  , renderer_use_parallel_executors_(renderer_use_parallel_executors)
222  , enable_auto_clear_render_mem_(enable_auto_clear_render_mem)
223  , render_oom_retry_threshold_(render_oom_retry_threshold)
224  , max_concurrent_render_sessions_(max_concurrent_render_sessions)
225  , reserved_gpu_mem_(reserved_gpu_mem)
226  , render_compositor_use_last_gpu_(render_compositor_use_last_gpu)
227  , render_mem_bytes_(render_mem_bytes)
228  , num_reader_threads_(num_reader_threads)
229 #ifdef ENABLE_GEOS
230  , libgeos_so_filename_(libgeos_so_filename)
231 #endif
232  , disk_cache_config_(disk_cache_config)
233  , udf_filename_(udf_filename)
234  , clang_path_(clang_path)
235  , clang_options_(clang_options)
236  , max_num_sessions_(-1) {
237  LOG(INFO) << "HeavyDB Server " << MAPD_RELEASE;
238  initialize(is_new_db);
240 }
std::vector< LeafHostInfo > string_leaves_
Definition: DBHandler.h:631
const std::vector< std::string > & clang_options_
Definition: DBHandler.h:975
std::unique_ptr< QueryDispatchQueue > dispatch_queue_
Definition: DBHandler.h:655
void resetSessionsStore()
Definition: DBHandler.cpp:242
const bool renderer_use_parallel_executors_
Definition: DBHandler.h:961
const std::string & udf_filename_
Definition: DBHandler.h:973
const int render_oom_retry_threshold_
Definition: DBHandler.h:963
#define LOG(tag)
Definition: Logger.h:285
LeafAggregator leaf_aggregator_
Definition: DBHandler.h:629
const unsigned renderer_vulkan_timeout_
Definition: DBHandler.h:960
const std::string base_data_path_
Definition: DBHandler.h:632
void initialize(const bool is_new_db)
Definition: DBHandler.cpp:259
const bool jit_debug_
Definition: DBHandler.h:637
const size_t render_mem_bytes_
Definition: DBHandler.h:967
const bool renderer_use_ppll_polys_
Definition: DBHandler.h:958
const size_t reserved_gpu_mem_
Definition: DBHandler.h:965
const bool render_compositor_use_last_gpu_
Definition: DBHandler.h:966
const int max_session_duration_
Definition: DBHandler.h:955
std::vector< LeafHostInfo > db_leaves_
Definition: DBHandler.h:630
const File_Namespace::DiskCacheConfig & disk_cache_config_
Definition: DBHandler.h:972
const std::string & clang_path_
Definition: DBHandler.h:974
SystemParameters & system_parameters_
Definition: DBHandler.h:647
const size_t num_reader_threads_
Definition: DBHandler.h:968
int32_t max_num_sessions_
Definition: DBHandler.h:976
const bool enable_auto_clear_render_mem_
Definition: DBHandler.h:962
const bool renderer_prefer_igpu_
Definition: DBHandler.h:959
const bool allow_loop_joins_
Definition: DBHandler.h:641
const bool enable_rendering_
Definition: DBHandler.h:957
const bool intel_jit_profile_
Definition: DBHandler.h:638
bool super_user_rights_
Definition: DBHandler.h:951
const bool read_only_
Definition: DBHandler.h:640
const bool legacy_syntax_
Definition: DBHandler.h:653
const int idle_session_duration_
Definition: DBHandler.h:954
const size_t max_concurrent_render_sessions_
Definition: DBHandler.h:964
bool allow_multifrag_
Definition: DBHandler.h:639
static const std::string MAPD_RELEASE
Definition: release.h:42
const AuthMetadata & authMetadata_
Definition: DBHandler.h:646
std::default_random_engine random_gen_
Definition: DBHandler.h:635
std::uniform_int_distribution< int64_t > session_id_dist_
Definition: DBHandler.h:636
DBHandler::~DBHandler ( )
override

Definition at line 429 of file DBHandler.cpp.

References shutdown().

429  {
430  shutdown();
431 }
void shutdown()
Definition: DBHandler.cpp:7361

+ Here is the call graph for this function:

Member Function Documentation

void DBHandler::alterSession ( const std::string &  sesson_id,
ExecutionResult result,
const std::pair< std::string, std::string > &  session_parameter,
int64_t &  execution_time_ms 
)
private

Definition at line 7853 of file DBHandler.cpp.

References measure< TimeT >::execution(), set_execution_mode(), switch_database(), to_upper(), and run_benchmark_import::type.

Referenced by executeDdl().

7856  {
7857  result = ExecutionResult();
7858  if (session_parameter.first == "EXECUTOR_DEVICE") {
7859  std::string parameter_value = to_upper(session_parameter.second);
7860  TExecuteMode::type executorType;
7861  if (parameter_value == "GPU") {
7862  executorType = TExecuteMode::type::GPU;
7863  } else if (parameter_value == "CPU") {
7864  executorType = TExecuteMode::type::CPU;
7865  } else {
7866  throw std::runtime_error("Cannot set the " + session_parameter.first + " to " +
7867  session_parameter.second +
7868  ". Valid options are CPU and GPU");
7869  }
7870  execution_time_ms =
7871  measure<>::execution([&]() { set_execution_mode(session_id, executorType); });
7872  } else if (session_parameter.first == "CURRENT_DATABASE") {
7873  execution_time_ms = measure<>::execution(
7874  [&]() { switch_database(session_id, session_parameter.second); });
7875  }
7876 }
static TimeT::rep execution(F func, Args &&...args)
Definition: sample.cpp:29
void set_execution_mode(const TSessionId &session, const TExecuteMode::type mode) override
Definition: DBHandler.cpp:2875
std::string to_upper(const std::string &str)
void switch_database(const TSessionId &session, const std::string &dbname) override
Definition: DBHandler.cpp:605

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void DBHandler::alterSystemClear ( const std::string &  sesson_id,
ExecutionResult result,
const std::string &  cache_type,
int64_t &  execution_time_ms 
)
private

Definition at line 7837 of file DBHandler.cpp.

References clear_cpu_memory(), clear_gpu_memory(), clearRenderMemory(), measure< TimeT >::execution(), and to_upper().

Referenced by executeDdl().

7840  {
7841  result = ExecutionResult();
7842  if (to_upper(cache_type) == "CPU") {
7843  execution_time_ms = measure<>::execution([&]() { clear_cpu_memory(session_id); });
7844  } else if (to_upper(cache_type) == "GPU") {
7845  execution_time_ms = measure<>::execution([&]() { clear_gpu_memory(session_id); });
7846  } else if (to_upper(cache_type) == "RENDER") {
7847  execution_time_ms = measure<>::execution([&]() { clearRenderMemory(session_id); });
7848  } else {
7849  throw std::runtime_error("Invalid cache type. Valid values are CPU,GPU or RENDER");
7850  }
7851 }
void clearRenderMemory(const TSessionId &session)
Definition: DBHandler.cpp:2751
static TimeT::rep execution(F func, Args &&...args)
Definition: sample.cpp:29
std::string to_upper(const std::string &str)
void clear_gpu_memory(const TSessionId &session) override
Definition: DBHandler.cpp:2714
void clear_cpu_memory(const TSessionId &session) override
Definition: DBHandler.cpp:2733

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void DBHandler::broadcast_serialized_rows ( const TSerializedRows &  serialized_rows,
const TRowDescriptor &  row_desc,
const TQueryId  query_id,
const TSubqueryId  subquery_id,
const bool  is_final_subquery_result 
)
override

Definition at line 6899 of file DBHandler.cpp.

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

6903  {
6904  if (!leaf_handler_) {
6905  THROW_DB_EXCEPTION("Distributed support is disabled.");
6906  }
6907  LOG(INFO) << "BROADCAST-SERIALIZED-ROWS id:" << query_id;
6908  auto time_ms = measure<>::execution([&]() {
6909  try {
6910  leaf_handler_->broadcast_serialized_rows(
6911  serialized_rows, row_desc, query_id, subquery_id, is_final_subquery_result);
6912  } catch (std::exception& e) {
6913  THROW_DB_EXCEPTION(e.what());
6914  }
6915  });
6916  LOG(INFO) << "BROADCAST-SERIALIZED-ROWS COMPLETED " << time_ms << "ms";
6917 }
static TimeT::rep execution(F func, Args &&...args)
Definition: sample.cpp:29
#define LOG(tag)
Definition: Logger.h:285
std::unique_ptr< HeavyDBLeafHandler > leaf_handler_
Definition: DBHandler.h:651
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:136

+ Here is the call graph for this function:

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

Definition at line 6240 of file DBHandler.cpp.

References sessions_store_.

6240  {
6241  if (const auto drop_db_stmt = dynamic_cast<Parser::DropDBStmt*>(ddl)) {
6242  sessions_store_->eraseByDB(*drop_db_stmt->getDatabaseName());
6243  } else if (const auto rename_db_stmt = dynamic_cast<Parser::RenameDBStmt*>(ddl)) {
6244  sessions_store_->eraseByDB(*rename_db_stmt->getPreviousDatabaseName());
6245  } else if (const auto drop_user_stmt = dynamic_cast<Parser::DropUserStmt*>(ddl)) {
6246  sessions_store_->eraseByUser(*drop_user_stmt->getUserName());
6247  } else if (const auto rename_user_stmt = dynamic_cast<Parser::RenameUserStmt*>(ddl)) {
6248  sessions_store_->eraseByUser(*rename_user_stmt->getOldUserName());
6249  }
6250 }
std::unique_ptr< Catalog_Namespace::SessionsStore > sessions_store_
Definition: DBHandler.h:977
void DBHandler::check_geospatial_files ( const boost::filesystem::path  file_path,
const import_export::CopyParams copy_params 
)
private

Definition at line 4961 of file DBHandler.cpp.

References import_export::Importer::gdalFileExists().

Referenced by detect_column_types(), and importGeoTableSingle().

4962  {
4963  const std::list<std::string> shp_ext{".shp", ".shx", ".dbf"};
4964  if (std::find(shp_ext.begin(),
4965  shp_ext.end(),
4966  boost::algorithm::to_lower_copy(file_path.extension().string())) !=
4967  shp_ext.end()) {
4968  for (auto ext : shp_ext) {
4969  auto aux_file = file_path;
4971  aux_file.replace_extension(boost::algorithm::to_upper_copy(ext)).string(),
4972  copy_params) &&
4974  aux_file.replace_extension(ext).string(), copy_params)) {
4975  throw std::runtime_error("required file for shapefile does not exist: " +
4976  aux_file.filename().string());
4977  }
4978  }
4979  }
4980 }
static bool gdalFileExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:5153

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 433 of file DBHandler.cpp.

References read_only_, and THROW_DB_EXCEPTION.

Referenced by create_custom_expression(), create_dashboard(), create_table(), delete_custom_expressions(), delete_dashboards(), detect_column_types(), import_table(), importGeoTableSingle(), prepare_loader_generic(), replace_dashboard(), set_license_key(), shareOrUnshareDashboards(), sql_execute_impl(), and update_custom_expression().

433  {
434  if (DBHandler::read_only_) {
435  THROW_DB_EXCEPTION(str + " disabled: server running in read-only mode.");
436  }
437 }
const bool read_only_
Definition: DBHandler.h:640
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:136

+ Here is the caller graph for this function:

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

Definition at line 6830 of file DBHandler.cpp.

References get_session_ptr(), leaf_handler_, heavyai::RequestInfo::requestId(), heavyai::RequestInfo::sessionId(), SET_REQUEST_ID, STDLOG, and THROW_DB_EXCEPTION.

6832  {
6833  heavyai::RequestInfo const request_info(session_id_or_json);
6834  SET_REQUEST_ID(request_info.requestId());
6835  auto stdlog = STDLOG(get_session_ptr(request_info.sessionId()));
6836  if (!leaf_handler_) {
6837  THROW_DB_EXCEPTION("Distributed support is disabled.");
6838  }
6839  try {
6840  leaf_handler_->check_table_consistency(_return, request_info.sessionId(), table_id);
6841  } catch (std::exception& e) {
6842  THROW_DB_EXCEPTION(e.what());
6843  }
6844 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5935
#define SET_REQUEST_ID(parent_request_id)
Definition: DBHandler.cpp:130
std::unique_ptr< HeavyDBLeafHandler > leaf_handler_
Definition: DBHandler.h:651
#define STDLOG(...)
Definition: QueryState.h:234
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:136

+ Here is the call graph for this function:

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

Definition at line 5957 of file DBHandler.cpp.

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

Referenced by import_table(), importGeoTableSingle(), and prepare_loader_generic().

5959  {
5960  auto user_metadata = session_info.get_currentUser();
5961  auto& cat = session_info.getCatalog();
5962  DBObject dbObject(table_name, TableDBObjectType);
5963  dbObject.loadKey(cat);
5964  dbObject.setPrivileges(AccessPrivileges::INSERT_INTO_TABLE);
5965  std::vector<DBObject> privObjects;
5966  privObjects.push_back(dbObject);
5967  if (!SysCatalog::instance().checkPrivileges(user_metadata, privObjects)) {
5968  THROW_DB_EXCEPTION("Violation of access privileges: user " +
5969  user_metadata.userLoggable() +
5970  " has no insert privileges for table " + table_name + ".");
5971  }
5972 }
std::string cat(Ts &&...args)
static const AccessPrivileges INSERT_INTO_TABLE
Definition: DBObject.h:161
Catalog & getCatalog() const
Definition: SessionInfo.h:75
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:88
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:136

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool DBHandler::checkInMemorySystemTableQuery ( const std::unordered_set< shared::TableKey > &  tables_selected_from) const

Definition at line 7970 of file DBHandler.cpp.

References CHECK, anonymous_namespace{DBHandler.cpp}::check_and_reset_in_memory_system_table(), Catalog_Namespace::SysCatalog::getCatalog(), Catalog_Namespace::SysCatalog::instance(), and shared::kInfoSchemaDbName.

7971  {
7972  bool is_in_memory_system_table_query{false};
7973  const auto info_schema_catalog =
7975  if (info_schema_catalog) {
7976  for (const auto& table_key : selected_table_keys) {
7977  if (table_key.db_id == info_schema_catalog->getDatabaseId()) {
7978  auto td = info_schema_catalog->getMetadataForTable(table_key.table_id, false);
7979  CHECK(td);
7980  if (check_and_reset_in_memory_system_table(*info_schema_catalog, *td)) {
7981  is_in_memory_system_table_query = true;
7982  }
7983  }
7984  }
7985  }
7986  return is_in_memory_system_table_query;
7987 }
const std::string kInfoSchemaDbName
static SysCatalog & instance()
Definition: SysCatalog.h:343
std::shared_ptr< Catalog > getCatalog(const std::string &dbName)
#define CHECK(condition)
Definition: Logger.h:291
bool check_and_reset_in_memory_system_table(const Catalog &catalog, const TableDescriptor &td)
Definition: DBHandler.cpp:6639

+ Here is the call graph for this function:

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

Definition at line 7145 of file DBHandler.cpp.

References cat(), get_session_ptr(), heavyai::RequestInfo::requestId(), heavyai::RequestInfo::sessionId(), SET_REQUEST_ID, and STDLOG.

7145  {
7146  heavyai::RequestInfo const request_info(session_id_or_json);
7147  SET_REQUEST_ID(request_info.requestId());
7148  auto stdlog = STDLOG(get_session_ptr(request_info.sessionId()));
7149  auto session_ptr = stdlog.getConstSessionInfo();
7150  auto& cat = session_ptr->getCatalog();
7151  cat.checkpoint(table_id);
7152 }
std::string cat(Ts &&...args)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5935
#define SET_REQUEST_ID(parent_request_id)
Definition: DBHandler.cpp:130
#define STDLOG(...)
Definition: QueryState.h:234

+ Here is the call graph for this function:

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

Definition at line 2733 of file DBHandler.cpp.

References Executor::clearMemory(), Data_Namespace::CPU_LEVEL, get_session_ptr(), render_handler_, heavyai::RequestInfo::requestId(), heavyai::RequestInfo::sessionId(), SET_REQUEST_ID, STDLOG, and THROW_DB_EXCEPTION.

Referenced by alterSystemClear().

2733  {
2734  heavyai::RequestInfo const request_info(session_id_or_json);
2735  SET_REQUEST_ID(request_info.requestId());
2736  auto stdlog = STDLOG(get_session_ptr(request_info.sessionId()));
2737  auto session_ptr = stdlog.getConstSessionInfo();
2738  if (!session_ptr->get_currentUser().isSuper) {
2739  THROW_DB_EXCEPTION("Superuser privilege is required to run clear_cpu_memory");
2740  }
2741  try {
2743  } catch (const std::exception& e) {
2744  THROW_DB_EXCEPTION(e.what());
2745  }
2746  if (render_handler_) {
2747  render_handler_->clear_cpu_memory();
2748  }
2749 }
static void clearMemory(const Data_Namespace::MemoryLevel memory_level)
Definition: Execute.cpp:497
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5935
std::unique_ptr< RenderHandler > render_handler_
Definition: DBHandler.h:649
#define SET_REQUEST_ID(parent_request_id)
Definition: DBHandler.cpp:130
#define STDLOG(...)
Definition: QueryState.h:234
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:136

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 2714 of file DBHandler.cpp.

References Executor::clearMemory(), get_session_ptr(), getConnectionInfo(), Data_Namespace::GPU_LEVEL, render_handler_, heavyai::RequestInfo::requestId(), heavyai::RequestInfo::sessionId(), SET_REQUEST_ID, STDLOG, THROW_DB_EXCEPTION, and toString().

Referenced by alterSystemClear().

2714  {
2715  heavyai::RequestInfo const request_info(session_id_or_json);
2716  SET_REQUEST_ID(request_info.requestId());
2717  auto stdlog = STDLOG(get_session_ptr(request_info.sessionId()));
2718  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
2719  auto session_ptr = stdlog.getConstSessionInfo();
2720  if (!session_ptr->get_currentUser().isSuper) {
2721  THROW_DB_EXCEPTION("Superuser privilege is required to run clear_gpu_memory");
2722  }
2723  try {
2725  } catch (const std::exception& e) {
2726  THROW_DB_EXCEPTION(e.what());
2727  }
2728  if (render_handler_) {
2729  render_handler_->clear_gpu_memory();
2730  }
2731 }
static void clearMemory(const Data_Namespace::MemoryLevel memory_level)
Definition: Execute.cpp:497
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5935
std::unique_ptr< RenderHandler > render_handler_
Definition: DBHandler.h:649
#define SET_REQUEST_ID(parent_request_id)
Definition: DBHandler.cpp:130
std::string toString(const ExecutorDeviceType &device_type)
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1649
#define STDLOG(...)
Definition: QueryState.h:234
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:136

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void DBHandler::clearRenderMemory ( const TSessionId &  session)

Definition at line 2751 of file DBHandler.cpp.

References get_session_ptr(), getConnectionInfo(), render_handler_, heavyai::RequestInfo::requestId(), heavyai::RequestInfo::sessionId(), SET_REQUEST_ID, STDLOG, THROW_DB_EXCEPTION, and toString().

Referenced by alterSystemClear().

2751  {
2752  heavyai::RequestInfo const request_info(session_id_or_json);
2753  SET_REQUEST_ID(request_info.requestId());
2754  auto stdlog = STDLOG(get_session_ptr(request_info.sessionId()));
2755  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
2756  auto session_ptr = stdlog.getConstSessionInfo();
2757  if (!session_ptr->get_currentUser().isSuper) {
2758  THROW_DB_EXCEPTION("Superuser privilege is required to run clear_render_memory");
2759  }
2760  if (render_handler_) {
2761  render_handler_->clear_cpu_memory();
2762  render_handler_->clear_gpu_memory();
2763  }
2764 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5935
std::unique_ptr< RenderHandler > render_handler_
Definition: DBHandler.h:649
#define SET_REQUEST_ID(parent_request_id)
Definition: DBHandler.cpp:130
std::string toString(const ExecutorDeviceType &device_type)
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1649
#define STDLOG(...)
Definition: QueryState.h:234
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:136

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 626 of file DBHandler.cpp.

References cat(), LeafAggregator::clone_session(), executor_device_type_, get_session_ptr(), getConnectionInfo(), logger::INFO, leaf_aggregator_, LeafAggregator::leafCount(), LOG, heavyai::RequestInfo::requestId(), heavyai::RequestInfo::sessionId(), sessions_store_, SET_REQUEST_ID, STDLOG, THROW_DB_EXCEPTION, toString(), and Catalog_Namespace::UserMetadata::userLoggable().

627  {
628  heavyai::RequestInfo const request_info(session1_id_or_json);
629  SET_REQUEST_ID(request_info.requestId());
630  auto session1_ptr = get_session_ptr(request_info.sessionId());
631  auto stdlog = STDLOG(session1_ptr);
632  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
633 
634  try {
635  const Catalog_Namespace::UserMetadata& user_meta = session1_ptr->get_currentUser();
636  std::shared_ptr<Catalog> cat = session1_ptr->get_catalog_ptr();
637  auto session2_ptr = sessions_store_->add(user_meta, cat, executor_device_type_);
638  session2_id = session2_ptr->get_session_id();
639  LOG(INFO) << "User " << user_meta.userLoggable() << " connected to database "
640  << cat->name();
641  if (leaf_aggregator_.leafCount() > 0) {
642  leaf_aggregator_.clone_session(request_info.sessionId(), session2_id);
643  return;
644  }
645  } catch (std::exception& e) {
646  THROW_DB_EXCEPTION(e.what());
647  }
648 }
std::string cat(Ts &&...args)
void clone_session(const TSessionId session1, const TSessionId session2)
#define LOG(tag)
Definition: Logger.h:285
LeafAggregator leaf_aggregator_
Definition: DBHandler.h:629
ExecutorDeviceType executor_device_type_
Definition: DBHandler.h:634
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5935
#define SET_REQUEST_ID(parent_request_id)
Definition: DBHandler.cpp:130
std::string toString(const ExecutorDeviceType &device_type)
size_t leafCount() const
std::unique_ptr< Catalog_Namespace::SessionsStore > sessions_store_
Definition: DBHandler.h:977
std::string userLoggable() const
Definition: SysCatalog.cpp:158
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1649
#define STDLOG(...)
Definition: QueryState.h:234
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:136

+ Here is the call graph for this function:

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

Definition at line 511 of file DBHandler.cpp.

References AccessPrivileges::ACCESS, cat(), connect_impl(), DatabaseDBObjectType, getConnectionInfo(), DBObject::loadKey(), logger::set_new_request_id(), DBObject::setPrivileges(), STDLOG, super_user_rights_, THROW_DB_EXCEPTION, toString(), and Catalog_Namespace::UserMetadata::userLoggable().

514  {
516  auto stdlog = STDLOG(); // session_info set by connect_impl()
517  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
518  std::string username2 = username; // login() may reset username given as argument
519  std::string dbname2 = dbname; // login() may reset dbname given as argument
521  std::shared_ptr<Catalog> cat = nullptr;
522  try {
523  cat = SysCatalog::instance().login(
524  dbname2, username2, passwd, user_meta, !super_user_rights_);
525  } catch (std::exception& e) {
526  stdlog.appendNameValuePairs("user", username, "db", dbname, "exception", e.what());
527  THROW_DB_EXCEPTION(e.what());
528  }
529 
530  DBObject dbObject(dbname2, DatabaseDBObjectType);
531  dbObject.loadKey(*cat);
532  dbObject.setPrivileges(AccessPrivileges::ACCESS);
533  std::vector<DBObject> dbObjects;
534  dbObjects.push_back(dbObject);
535  if (!SysCatalog::instance().checkPrivileges(user_meta, dbObjects)) {
536  stdlog.appendNameValuePairs(
537  "user", username, "db", dbname, "exception", "Missing Privileges");
538  THROW_DB_EXCEPTION("Unauthorized Access: user " + user_meta.userLoggable() +
539  " is not allowed to access database " + dbname2 + ".");
540  }
541  connect_impl(session_id, passwd, dbname2, user_meta, cat, stdlog);
542 
543  // if pki auth session_id will come back encrypted with user pubkey
544  SysCatalog::instance().check_for_session_encryption(passwd, session_id);
545 }
std::string cat(Ts &&...args)
void connect_impl(TSessionId &session, const std::string &passwd, const std::string &dbname, const Catalog_Namespace::UserMetadata &user_meta, std::shared_ptr< Catalog_Namespace::Catalog > cat, query_state::StdLog &stdlog)
Definition: DBHandler.cpp:547
RequestId set_new_request_id()
Definition: Logger.cpp:883
std::string toString(const ExecutorDeviceType &device_type)
bool super_user_rights_
Definition: DBHandler.h:951
static const AccessPrivileges ACCESS
Definition: DBObject.h:153
std::string userLoggable() const
Definition: SysCatalog.cpp:158
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1649
#define STDLOG(...)
Definition: QueryState.h:234
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:136

+ Here is the call graph for this function:

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

Definition at line 547 of file DBHandler.cpp.

References query_state::StdLog::appendNameValuePairs(), executor_device_type_, getConnectionInfo(), query_state::StdLog::getConstSessionInfo(), logger::INFO, join(), LOG, sessions_store_, query_state::StdLog::setSessionInfo(), super_user_rights_, toString(), and Catalog_Namespace::UserMetadata::userLoggable().

Referenced by connect(), and internal_connect().

552  {
553  // TODO(sy): Is there any reason to have dbname as a parameter
554  // here when the cat parameter already provides cat->name()?
555  // Should dbname and cat->name() ever differ?
556  auto session_ptr = sessions_store_->add(user_meta, cat, executor_device_type_);
557  session_id = session_ptr->get_session_id();
558  LOG(INFO) << "User " << user_meta.userLoggable() << " connected to database " << dbname;
559  stdlog.setSessionInfo(session_ptr);
560  session_ptr->set_connection_info(getConnectionInfo().toString());
561  if (!super_user_rights_) { // no need to connect to leaf_aggregator_ at this time
562  // while doing warmup
563  }
564  auto const roles =
565  stdlog.getConstSessionInfo()->get_currentUser().isSuper
566  ? std::vector<std::string>{{"super"}}
567  : SysCatalog::instance().getRoles(
568  false, false, stdlog.getConstSessionInfo()->get_currentUser().userName);
569  stdlog.appendNameValuePairs("roles", boost::algorithm::join(roles, ","));
570 }
std::string cat(Ts &&...args)
#define LOG(tag)
Definition: Logger.h:285
std::string join(T const &container, std::string const &delim)
void setSessionInfo(std::shared_ptr< Catalog_Namespace::SessionInfo >)
Definition: QueryState.cpp:280
ExecutorDeviceType executor_device_type_
Definition: DBHandler.h:634
std::string toString(const ExecutorDeviceType &device_type)
void appendNameValuePairs(Pairs &&...pairs)
Definition: QueryState.h:312
bool super_user_rights_
Definition: DBHandler.h:951
std::unique_ptr< Catalog_Namespace::SessionsStore > sessions_store_
Definition: DBHandler.h:977
std::shared_ptr< Catalog_Namespace::SessionInfo const > getConstSessionInfo() const
Definition: QueryState.cpp:150
std::string userLoggable() const
Definition: SysCatalog.cpp:158
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1649

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void DBHandler::convertData ( TQueryResult &  _return,
ExecutionResult result,
const QueryStateProxy query_state_proxy,
const bool  column_format,
const int32_t  first_n,
const int32_t  at_most_n 
)
staticprivate

Definition at line 1103 of file DBHandler.cpp.

References ExecutionResult::CalciteDdl, convertExplain(), convertResult(), convertRows(), ExecutionResult::empty(), ExecutionResult::Explanation, ExecutionResult::getExecutionTime(), ExecutionResult::getResultType(), ExecutionResult::getRows(), ExecutionResult::getTargetsMeta(), ExecutionResult::QueryResult, and ExecutionResult::SimpleResult.

Referenced by convertResultSet(), get_tables_meta_impl(), sql_execute_local(), and validate_rel_alg().

1108  {
1109  _return.execution_time_ms += result.getExecutionTime();
1110  if (result.empty()) {
1111  return;
1112  }
1113 
1114  switch (result.getResultType()) {
1116  convertRows(_return,
1117  query_state_proxy,
1118  result.getTargetsMeta(),
1119  *result.getRows(),
1120  column_format,
1121  first_n,
1122  at_most_n);
1123  break;
1125  convertResult(_return, *result.getRows(), true);
1126  break;
1128  convertExplain(_return, *result.getRows(), true);
1129  break;
1131  convertRows(_return,
1132  query_state_proxy,
1133  result.getTargetsMeta(),
1134  *result.getRows(),
1135  column_format,
1136  -1,
1137  -1);
1138  break;
1139  }
1140 }
RType getResultType() const
static void convertExplain(TQueryResult &_return, const ResultSet &results, const bool column_format)
Definition: DBHandler.cpp:6212
static void convertResult(TQueryResult &_return, const ResultSet &results, const bool column_format)
Definition: DBHandler.cpp:6218
const std::vector< TargetMetaInfo > & getTargetsMeta() const
const std::shared_ptr< ResultSet > & getRows() const
static void convertRows(TQueryResult &_return, QueryStateProxy query_state_proxy, const std::vector< TargetMetaInfo > &targets, const ResultSet &results, const bool column_format, const int32_t first_n, const int32_t at_most_n)
Definition: DBHandler.cpp:6104
int64_t getExecutionTime() const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void DBHandler::convertExplain ( TQueryResult &  _return,
const ResultSet results,
const bool  column_format 
)
staticprivate

Definition at line 6212 of file DBHandler.cpp.

References createSimpleResult().

Referenced by convertData().

6214  {
6215  createSimpleResult(_return, results, column_format, "Explanation");
6216 }
static void createSimpleResult(TQueryResult &_return, const ResultSet &results, const bool column_format, const std::string label)
Definition: DBHandler.cpp:6175

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void DBHandler::convertResult ( TQueryResult &  _return,
const ResultSet results,
const bool  column_format 
)
staticprivate

Definition at line 6218 of file DBHandler.cpp.

References createSimpleResult().

Referenced by convertData().

6220  {
6221  createSimpleResult(_return, results, column_format, "Result");
6222 }
static void createSimpleResult(TQueryResult &_return, const ResultSet &results, const bool column_format, const std::string label)
Definition: DBHandler.cpp:6175

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void DBHandler::convertResultSet ( ExecutionResult result,
const Catalog_Namespace::SessionInfo session_info,
const std::string &  query_state_str,
TQueryResult &  _return 
)
private

Definition at line 7554 of file DBHandler.cpp.

References CHECK, convertData(), create_query_state(), query_state::QueryState::createQueryStateProxy(), Catalog_Namespace::SessionInfo::get_session_id(), get_session_ptr(), and ExecutionResult::getDataPtr().

Referenced by executeDdl().

7557  {
7558  // Stuff ResultSet into _return (which is a TQueryResult)
7559  // calls convertRows, but after some setup using session_info
7560 
7561  auto session_ptr = get_session_ptr(session_info.get_session_id());
7562  CHECK(session_ptr);
7563  auto qs = create_query_state(session_ptr, query_state_str);
7565 
7566  // heavysql only accepts column format as being 'VALID",
7567  // assume that heavydb should only return column format
7568  int32_t nRows = result.getDataPtr()->rowCount();
7569 
7570  convertData(_return,
7571  result,
7572  qsp,
7573  /*column_format=*/true,
7574  /*first_n=*/nRows,
7575  /*at_most_n=*/nRows);
7576 }
static void convertData(TQueryResult &_return, ExecutionResult &result, const QueryStateProxy &query_state_proxy, const bool column_format, const int32_t first_n, const int32_t at_most_n)
Definition: DBHandler.cpp:1103
QueryStateProxy createQueryStateProxy()
Definition: QueryState.cpp:71
std::shared_ptr< query_state::QueryState > create_query_state(ARGS &&...args)
Definition: DBHandler.h:658
const ResultSetPtr & getDataPtr() const
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5935
std::string get_session_id() const
Definition: SessionInfo.h:93
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void DBHandler::convertRows ( TQueryResult &  _return,
QueryStateProxy  query_state_proxy,
const std::vector< TargetMetaInfo > &  targets,
const ResultSet results,
const bool  column_format,
const int32_t  first_n,
const int32_t  at_most_n 
)
staticprivate

Definition at line 6104 of file DBHandler.cpp.

References query_state::QueryStateProxy::createTimer(), ThriftSerializers::target_meta_infos_to_thrift(), THROW_DB_EXCEPTION, to_string(), value_to_thrift(), and value_to_thrift_column().

Referenced by convertData().

6110  {
6111  query_state::Timer timer = query_state_proxy.createTimer(__func__);
6112  _return.row_set.row_desc = ThriftSerializers::target_meta_infos_to_thrift(targets);
6113  int32_t fetched{0};
6114  if (column_format) {
6115  _return.row_set.is_columnar = true;
6116  std::vector<TColumn> tcolumns(results.colCount());
6117  while (first_n == -1 || fetched < first_n) {
6118  const auto crt_row = results.getNextRow(true, true);
6119  if (crt_row.empty()) {
6120  break;
6121  }
6122  ++fetched;
6123  if (at_most_n >= 0 && fetched > at_most_n) {
6124  THROW_DB_EXCEPTION("The result contains more rows than the specified cap of " +
6125  std::to_string(at_most_n));
6126  }
6127  for (size_t i = 0; i < results.colCount(); ++i) {
6128  const auto agg_result = crt_row[i];
6129  value_to_thrift_column(agg_result, targets[i].get_type_info(), tcolumns[i]);
6130  }
6131  }
6132  for (size_t i = 0; i < results.colCount(); ++i) {
6133  _return.row_set.columns.push_back(tcolumns[i]);
6134  }
6135  } else {
6136  _return.row_set.is_columnar = false;
6137  while (first_n == -1 || fetched < first_n) {
6138  const auto crt_row = results.getNextRow(true, true);
6139  if (crt_row.empty()) {
6140  break;
6141  }
6142  ++fetched;
6143  if (at_most_n >= 0 && fetched > at_most_n) {
6144  THROW_DB_EXCEPTION("The result contains more rows than the specified cap of " +
6145  std::to_string(at_most_n));
6146  }
6147  TRow trow;
6148  trow.cols.reserve(results.colCount());
6149  for (size_t i = 0; i < results.colCount(); ++i) {
6150  const auto agg_result = crt_row[i];
6151  trow.cols.push_back(value_to_thrift(agg_result, targets[i].get_type_info()));
6152  }
6153  _return.row_set.rows.push_back(trow);
6154  }
6155  }
6156 }
TRowDescriptor target_meta_infos_to_thrift(const std::vector< TargetMetaInfo > &targets)
static void value_to_thrift_column(const TargetValue &tv, const SQLTypeInfo &ti, TColumn &column)
Definition: DBHandler.cpp:835
Timer createTimer(char const *event_name)
Definition: QueryState.cpp:129
std::string to_string(char const *&&v)
static TDatum value_to_thrift(const TargetValue &tv, const SQLTypeInfo &ti)
Definition: DBHandler.cpp:958
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:136

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 3840 of file DBHandler.cpp.

References import_export::CopyParams::add_metadata_columns, import_export::CopyParams::array_begin, import_export::CopyParams::array_delim, import_export::CopyParams::array_end, CHECK, import_export::CopyParams::connection_string, import_export::CopyParams::credential_string, import_export::CopyParams::delimiter, import_export::CopyParams::dsn, import_export::CopyParams::escape, import_export::CopyParams::geo_assign_render_groups, import_export::CopyParams::geo_coords_comp_param, import_export::CopyParams::geo_coords_encoding, import_export::CopyParams::geo_coords_srid, import_export::CopyParams::geo_coords_type, import_export::CopyParams::geo_explode_collections, import_export::CopyParams::geo_layer_name, import_export::CopyParams::has_header, import_export::kAuto, import_export::kAutoDetect, import_export::kDelimitedFile, import_export::kDouble, kENCODING_GEOINT, import_export::kFile, import_export::kFloat, import_export::kGeoFile, kGEOGRAPHY, kGEOMETRY, import_export::kHasHeader, import_export::kInt, import_export::kNoHeader, import_export::kNone, import_export::kOdbc, import_export::kParquetFile, import_export::kPoint, import_export::kRasterFile, import_export::kSmallInt, import_export::kWorld, import_export::CopyParams::line_delim, import_export::CopyParams::null_str, import_export::CopyParams::password, import_export::CopyParams::quote, import_export::CopyParams::quoted, import_export::CopyParams::raster_import_bands, import_export::CopyParams::raster_import_dimensions, import_export::CopyParams::raster_point_compute_angle, import_export::CopyParams::raster_point_transform, import_export::CopyParams::raster_point_type, import_export::CopyParams::raster_scanlines_per_thread, import_export::CopyParams::s3_access_key, import_export::CopyParams::s3_endpoint, import_export::CopyParams::s3_region, import_export::CopyParams::s3_secret_key, import_export::CopyParams::s3_session_token, import_export::CopyParams::sanitize_column_names, import_export::CopyParams::source_srid, import_export::CopyParams::source_type, import_export::CopyParams::sql_order_by, import_export::CopyParams::sql_select, import_export::CopyParams::threads, import_export::CopyParams::trim_spaces, and import_export::CopyParams::username.

Referenced by detect_column_types(), and importGeoTableSingle().

3840  {
3841  TCopyParams copy_params;
3842  copy_params.delimiter = cp.delimiter;
3843  copy_params.null_str = cp.null_str;
3844  switch (cp.has_header) {
3846  copy_params.has_header = TImportHeaderRow::AUTODETECT;
3847  break;
3849  copy_params.has_header = TImportHeaderRow::NO_HEADER;
3850  break;
3852  copy_params.has_header = TImportHeaderRow::HAS_HEADER;
3853  break;
3854  default:
3855  CHECK(false);
3856  }
3857  copy_params.quoted = cp.quoted;
3858  copy_params.quote = cp.quote;
3859  copy_params.escape = cp.escape;
3860  copy_params.line_delim = cp.line_delim;
3861  copy_params.array_delim = cp.array_delim;
3862  copy_params.array_begin = cp.array_begin;
3863  copy_params.array_end = cp.array_end;
3864  copy_params.threads = cp.threads;
3865  copy_params.s3_access_key = cp.s3_access_key;
3866  copy_params.s3_secret_key = cp.s3_secret_key;
3867  copy_params.s3_session_token = cp.s3_session_token;
3868  copy_params.s3_region = cp.s3_region;
3869  copy_params.s3_endpoint = cp.s3_endpoint;
3870  switch (cp.source_type) {
3872  copy_params.source_type = TSourceType::DELIMITED_FILE;
3873  break;
3875  copy_params.source_type = TSourceType::GEO_FILE;
3876  break;
3878  copy_params.source_type = TSourceType::PARQUET_FILE;
3879  break;
3881  copy_params.source_type = TSourceType::RASTER_FILE;
3882  break;
3884  copy_params.source_type = TSourceType::ODBC;
3885  break;
3886  default:
3887  CHECK(false);
3888  }
3889  switch (cp.geo_coords_encoding) {
3890  case kENCODING_GEOINT:
3891  copy_params.geo_coords_encoding = TEncodingType::GEOINT;
3892  break;
3893  default:
3894  copy_params.geo_coords_encoding = TEncodingType::NONE;
3895  break;
3896  }
3897  copy_params.geo_coords_comp_param = cp.geo_coords_comp_param;
3898  switch (cp.geo_coords_type) {
3899  case kGEOGRAPHY:
3900  copy_params.geo_coords_type = TDatumType::GEOGRAPHY;
3901  break;
3902  case kGEOMETRY:
3903  copy_params.geo_coords_type = TDatumType::GEOMETRY;
3904  break;
3905  default:
3906  CHECK(false);
3907  }
3908  copy_params.geo_coords_srid = cp.geo_coords_srid;
3909  copy_params.sanitize_column_names = cp.sanitize_column_names;
3910  copy_params.geo_layer_name = cp.geo_layer_name;
3911  copy_params.geo_assign_render_groups = cp.geo_assign_render_groups;
3912  copy_params.geo_explode_collections = cp.geo_explode_collections;
3913  copy_params.source_srid = cp.source_srid;
3914  switch (cp.raster_point_type) {
3916  copy_params.raster_point_type = TRasterPointType::NONE;
3917  break;
3919  copy_params.raster_point_type = TRasterPointType::AUTO;
3920  break;
3922  copy_params.raster_point_type = TRasterPointType::SMALLINT;
3923  break;
3925  copy_params.raster_point_type = TRasterPointType::INT;
3926  break;
3928  copy_params.raster_point_type = TRasterPointType::FLOAT;
3929  break;
3931  copy_params.raster_point_type = TRasterPointType::DOUBLE;
3932  break;
3934  copy_params.raster_point_type = TRasterPointType::POINT;
3935  break;
3936  default:
3937  CHECK(false);
3938  }
3939  copy_params.raster_import_bands = cp.raster_import_bands;
3940  copy_params.raster_scanlines_per_thread = cp.raster_scanlines_per_thread;
3941  switch (cp.raster_point_transform) {
3943  copy_params.raster_point_transform = TRasterPointTransform::NONE;
3944  break;
3946  copy_params.raster_point_transform = TRasterPointTransform::AUTO;
3947  break;
3949  copy_params.raster_point_transform = TRasterPointTransform::FILE;
3950  break;
3952  copy_params.raster_point_transform = TRasterPointTransform::WORLD;
3953  break;
3954  default:
3955  CHECK(false);
3956  }
3957  copy_params.raster_point_compute_angle = cp.raster_point_compute_angle;
3958  copy_params.raster_import_dimensions = cp.raster_import_dimensions;
3959  copy_params.odbc_dsn = cp.dsn;
3960  copy_params.odbc_connection_string = cp.connection_string;
3961  copy_params.odbc_sql_select = cp.sql_select;
3962  copy_params.odbc_sql_order_by = cp.sql_order_by;
3963  copy_params.odbc_username = cp.username;
3964  copy_params.odbc_password = cp.password;
3965  copy_params.odbc_credential_string = cp.credential_string;
3966  copy_params.add_metadata_columns = cp.add_metadata_columns;
3967  copy_params.trim_spaces = cp.trim_spaces;
3968  return copy_params;
3969 }
std::string s3_secret_key
Definition: CopyParams.h:62
int32_t raster_scanlines_per_thread
Definition: CopyParams.h:90
std::string connection_string
Definition: CopyParams.h:104
std::string raster_import_dimensions
Definition: CopyParams.h:93
std::string add_metadata_columns
Definition: CopyParams.h:94
ImportHeaderRow has_header
Definition: CopyParams.h:46
RasterPointType raster_point_type
Definition: CopyParams.h:88
std::string sql_order_by
Definition: CopyParams.h:97
import_export::SourceType source_type
Definition: CopyParams.h:57
std::string geo_layer_name
Definition: CopyParams.h:81
std::string s3_session_token
Definition: CopyParams.h:63
std::string raster_import_bands
Definition: CopyParams.h:89
#define CHECK(condition)
Definition: Logger.h:291
std::string s3_access_key
Definition: CopyParams.h:61
RasterPointTransform raster_point_transform
Definition: CopyParams.h:91
std::string credential_string
Definition: CopyParams.h:101
EncodingType geo_coords_encoding
Definition: CopyParams.h:76

+ Here is the caller graph for this function:

int32_t DBHandler::create_custom_expression ( const TSessionId &  session,
const TCustomExpression &  custom_expression 
)
override

Definition at line 4416 of file DBHandler.cpp.

References check_read_only(), anonymous_namespace{DBHandler.cpp}::create_custom_expr_from_thrift_obj(), custom_expressions_mutex_, get_session_ptr(), getConnectionInfo(), heavyai::RequestInfo::requestId(), heavyai::RequestInfo::sessionId(), SET_REQUEST_ID, STDLOG, THROW_DB_EXCEPTION, and toString().

4417  {
4418  heavyai::RequestInfo const request_info(session_id_or_json);
4419  SET_REQUEST_ID(request_info.requestId());
4420  auto stdlog = STDLOG(get_session_ptr(request_info.sessionId()));
4421  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
4422  check_read_only("create_custom_expression");
4423 
4424  auto session_ptr = stdlog.getConstSessionInfo();
4425  if (!session_ptr->get_currentUser().isSuper) {
4426  THROW_DB_EXCEPTION("Custom expressions can only be created by super users.")
4427  }
4428  auto& catalog = session_ptr->getCatalog();
4430  return catalog.createCustomExpression(
4431  create_custom_expr_from_thrift_obj(t_custom_expr, catalog));
4432 }
heavyai::unique_lock< heavyai::shared_mutex > write_lock
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5935
std::unique_lock< T > unique_lock
#define SET_REQUEST_ID(parent_request_id)
Definition: DBHandler.cpp:130
std::string toString(const ExecutorDeviceType &device_type)
heavyai::shared_mutex custom_expressions_mutex_
Definition: DBHandler.h:1085
void check_read_only(const std::string &str)
Definition: DBHandler.cpp:433
std::unique_ptr< Catalog_Namespace::CustomExpression > create_custom_expr_from_thrift_obj(const TCustomExpression &t_custom_expr, const Catalog &catalog)
Definition: DBHandler.cpp:4373
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1649
#define STDLOG(...)
Definition: QueryState.h:234
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:136

+ Here is the call graph for this function:

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

Definition at line 4615 of file DBHandler.cpp.

References cat(), CHECK, dbhandler::check_not_info_schema_db(), check_read_only(), AccessPrivileges::CREATE_DASHBOARD, anonymous_namespace{DBHandler.cpp}::dashboard_exists(), DashboardDBObjectType, DashboardDescriptor::dashboardMetadata, DashboardDescriptor::dashboardName, DashboardDescriptor::dashboardState, g_allow_system_dashboard_update, get_session_ptr(), getConnectionInfo(), DashboardDescriptor::imageHash, heavyai::RequestInfo::requestId(), heavyai::RequestInfo::sessionId(), SET_REQUEST_ID, STDLOG, THROW_DB_EXCEPTION, toString(), DashboardDescriptor::user, and DashboardDescriptor::userId.

4619  {
4620  heavyai::RequestInfo const request_info(session_id_or_json);
4621  SET_REQUEST_ID(request_info.requestId());
4622  auto stdlog = STDLOG(get_session_ptr(request_info.sessionId()));
4623  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
4624  auto session_ptr = stdlog.getConstSessionInfo();
4625  CHECK(session_ptr);
4626  check_read_only("create_dashboard");
4627  auto& cat = session_ptr->getCatalog();
4630  }
4631 
4632  if (!session_ptr->checkDBAccessPrivileges(DBObjectType::DashboardDBObjectType,
4634  THROW_DB_EXCEPTION("Not enough privileges to create a dashboard.");
4635  }
4636 
4637  if (dashboard_exists(cat, session_ptr->get_currentUser().userId, dashboard_name)) {
4638  THROW_DB_EXCEPTION("Dashboard with name: " + dashboard_name + " already exists.");
4639  }
4640 
4642  dd.dashboardName = dashboard_name;
4643  dd.dashboardState = dashboard_state;
4644  dd.imageHash = image_hash;
4645  dd.dashboardMetadata = dashboard_metadata;
4646  dd.userId = session_ptr->get_currentUser().userId;
4647  dd.user = session_ptr->get_currentUser().userName;
4648 
4649  try {
4650  auto id = cat.createDashboard(dd);
4651  // TODO: transactionally unsafe
4652  SysCatalog::instance().createDBObject(
4653  session_ptr->get_currentUser(), dashboard_name, DashboardDBObjectType, cat, id);
4654  return id;
4655  } catch (const std::exception& e) {
4656  THROW_DB_EXCEPTION(e.what());
4657  }
4658 }
std::string cat(Ts &&...args)
static const AccessPrivileges CREATE_DASHBOARD
Definition: DBObject.h:170
void check_not_info_schema_db(const std::string &db_name, bool throw_db_exception)
Definition: DBHandler.cpp:4602
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5935
#define SET_REQUEST_ID(parent_request_id)
Definition: DBHandler.cpp:130
std::string toString(const ExecutorDeviceType &device_type)
void check_read_only(const std::string &str)
Definition: DBHandler.cpp:433
bool g_allow_system_dashboard_update
Definition: DBHandler.cpp:122
bool dashboard_exists(const Catalog_Namespace::Catalog &cat, const int32_t user_id, const std::string &dashboard_name)
Definition: DBHandler.cpp:149
#define CHECK(condition)
Definition: Logger.h:291
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1649
#define STDLOG(...)
Definition: QueryState.h:234
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:136

+ Here is the call graph for this function:

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

Definition at line 4951 of file DBHandler.cpp.

References setup::name, and run_benchmark_import::type.

4953  {
4954  TColumnType ct;
4955  ct.col_name = name;
4956  ct.col_type.type = type;
4957  ct.col_type.is_array = is_array;
4958  return ct;
4959 }
string name
Definition: setup.in.py:72
void DBHandler::create_link ( std::string &  _return,
const TSessionId &  session,
const std::string &  view_state,
const std::string &  view_metadata 
)
override

Definition at line 4927 of file DBHandler.cpp.

References cat(), get_session_ptr(), getConnectionInfo(), heavyai::RequestInfo::requestId(), heavyai::RequestInfo::sessionId(), SET_REQUEST_ID, STDLOG, THROW_DB_EXCEPTION, toString(), LinkDescriptor::userId, LinkDescriptor::viewMetadata, and LinkDescriptor::viewState.

4930  {
4931  heavyai::RequestInfo const request_info(session_id_or_json);
4932  SET_REQUEST_ID(request_info.requestId());
4933  auto stdlog = STDLOG(get_session_ptr(request_info.sessionId()));
4934  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
4935  auto session_ptr = stdlog.getConstSessionInfo();
4936  // check_read_only("create_link");
4937  auto& cat = session_ptr->getCatalog();
4938 
4939  LinkDescriptor ld;
4940  ld.userId = session_ptr->get_currentUser().userId;
4941  ld.viewState = view_state;
4942  ld.viewMetadata = view_metadata;
4943 
4944  try {
4945  _return = cat.createLink(ld, 6);
4946  } catch (const std::exception& e) {
4947  THROW_DB_EXCEPTION(e.what());
4948  }
4949 }
std::string cat(Ts &&...args)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5935
#define SET_REQUEST_ID(parent_request_id)
Definition: DBHandler.cpp:130
std::string toString(const ExecutorDeviceType &device_type)
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1649
#define STDLOG(...)
Definition: QueryState.h:234
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:136

+ Here is the call graph for this function:

std::shared_ptr<Catalog_Namespace::SessionInfo> DBHandler::create_new_session ( TSessionId &  session,
const std::string &  dbname,
const Catalog_Namespace::UserMetadata user_meta,
std::shared_ptr< Catalog_Namespace::Catalog cat 
)
private
template<typename... ARGS>
std::shared_ptr<query_state::QueryState> DBHandler::create_query_state ( ARGS &&...  args)
inline

Definition at line 658 of file DBHandler.h.

References run_benchmark_import::args.

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

658  {
659  return query_states_.create(std::forward<ARGS>(args)...);
660  }
CircleBuffer::value_type create(ARGS &&...args)
Definition: QueryState.h:194
query_state::QueryStates query_states_
Definition: DBHandler.h:945

+ Here is the caller graph for this function:

void DBHandler::create_table ( const TSessionId &  session,
const std::string &  table_name,
const TRowDescriptor &  row_desc,
const TCreateParams &  create_params 
)
override

Definition at line 4982 of file DBHandler.cpp.

References check_read_only(), getConnectionInfo(), ImportHelpers::is_reserved_name(), join(), heavyai::RequestInfo::json(), kENCODING_DATE_IN_DAYS, kENCODING_DICT, kENCODING_FIXED, kENCODING_GEOINT, kENCODING_NONE, logger::request_id(), heavyai::RequestInfo::requestId(), ImportHelpers::sanitize_name(), SET_REQUEST_ID, heavyai::RequestInfo::setRequestId(), sql_execute(), STDLOG, thrift_to_encoding(), thrift_to_encoding_name(), thrift_to_name(), THROW_DB_EXCEPTION, to_string(), and toString().

Referenced by importGeoTableSingle().

4985  {
4986  heavyai::RequestInfo request_info(session_id_or_json);
4987  SET_REQUEST_ID(request_info.requestId());
4988  auto stdlog = STDLOG("table_name", table_name);
4989  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
4990  check_read_only("create_table");
4991 
4992  if (ImportHelpers::is_reserved_name(table_name)) {
4993  THROW_DB_EXCEPTION("Invalid table name (reserved keyword): " + table_name);
4994  } else if (table_name != ImportHelpers::sanitize_name(table_name)) {
4995  THROW_DB_EXCEPTION("Invalid characters in table name: " + table_name);
4996  }
4997 
4998  auto rds = rd;
4999 
5000  std::string stmt{"CREATE TABLE " + table_name};
5001  std::vector<std::string> col_stmts;
5002 
5003  for (auto col : rds) {
5004  if (ImportHelpers::is_reserved_name(col.col_name)) {
5005  THROW_DB_EXCEPTION("Invalid column name (reserved keyword): " + col.col_name);
5006  } else if (col.col_name != ImportHelpers::sanitize_name(col.col_name)) {
5007  THROW_DB_EXCEPTION("Invalid characters in column name: " + col.col_name);
5008  }
5009  if (col.col_type.type == TDatumType::INTERVAL_DAY_TIME ||
5010  col.col_type.type == TDatumType::INTERVAL_YEAR_MONTH) {
5011  THROW_DB_EXCEPTION("Unsupported type: " + thrift_to_name(col.col_type) +
5012  " for column: " + col.col_name);
5013  }
5014 
5015  if (col.col_type.type == TDatumType::DECIMAL) {
5016  // if no precision or scale passed in set to default 14,7
5017  if (col.col_type.precision == 0 && col.col_type.scale == 0) {
5018  col.col_type.precision = 14;
5019  col.col_type.scale = 7;
5020  }
5021  }
5022 
5023  std::string col_stmt;
5024  col_stmt.append(col.col_name + " " + thrift_to_name(col.col_type));
5025  if (col.__isset.default_value) {
5026  col_stmt.append(" DEFAULT " + col.default_value);
5027  }
5028 
5029  // As of 2016-06-27 the Immerse v1 frontend does not explicitly set the
5030  // `nullable` argument, leading this to default to false. Uncomment for v2.
5031  // if (!col.col_type.nullable) col_stmt.append(" NOT NULL");
5032 
5033  if (thrift_to_encoding(col.col_type.encoding) != kENCODING_NONE) {
5034  col_stmt.append(" ENCODING " + thrift_to_encoding_name(col.col_type));
5035  if (thrift_to_encoding(col.col_type.encoding) == kENCODING_DICT ||
5036  thrift_to_encoding(col.col_type.encoding) == kENCODING_FIXED ||
5037  thrift_to_encoding(col.col_type.encoding) == kENCODING_GEOINT ||
5038  thrift_to_encoding(col.col_type.encoding) == kENCODING_DATE_IN_DAYS) {
5039  col_stmt.append("(" + std::to_string(col.col_type.comp_param) + ")");
5040  }
5041  } else if (col.col_type.type == TDatumType::STR) {
5042  // non DICT encoded strings
5043  col_stmt.append(" ENCODING NONE");
5044  } else if (col.col_type.type == TDatumType::POINT ||
5045  col.col_type.type == TDatumType::MULTIPOINT ||
5046  col.col_type.type == TDatumType::LINESTRING ||
5047  col.col_type.type == TDatumType::MULTILINESTRING ||
5048  col.col_type.type == TDatumType::POLYGON ||
5049  col.col_type.type == TDatumType::MULTIPOLYGON) {
5050  // non encoded compressable geo
5051  if (col.col_type.scale == 4326) {
5052  col_stmt.append(" ENCODING NONE");
5053  }
5054  }
5055  col_stmts.push_back(col_stmt);
5056  }
5057 
5058  stmt.append(" (" + boost::algorithm::join(col_stmts, ", ") + ")");
5059 
5060  if (create_params.is_replicated) {
5061  stmt.append(" WITH (PARTITIONS = 'REPLICATED')");
5062  }
5063 
5064  stmt.append(";");
5065 
5066  TQueryResult ret;
5067  request_info.setRequestId(logger::request_id());
5068  sql_execute(ret, request_info.json(), stmt, true, "", -1, -1);
5069 }
EncodingType thrift_to_encoding(const TEncodingType::type tEncodingType)
void sql_execute(ExecutionResult &_return, const TSessionId &session, const std::string &query, const bool column_format, const int32_t first_n, const int32_t at_most_n, lockmgr::LockedTableDescriptors &locks)
Definition: DBHandler.cpp:1221
std::string join(T const &container, std::string const &delim)
std::string to_string(char const *&&v)
bool is_reserved_name(const std::string &name)
#define SET_REQUEST_ID(parent_request_id)
Definition: DBHandler.cpp:130
std::string toString(const ExecutorDeviceType &device_type)
std::string thrift_to_encoding_name(const TTypeInfo &ti)
std::string thrift_to_name(const TTypeInfo &ti)
std::string sanitize_name(const std::string &name, const bool underscore=false)
void check_read_only(const std::string &str)
Definition: DBHandler.cpp:433
RequestId request_id()
Definition: Logger.cpp:868
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1649
#define STDLOG(...)
Definition: QueryState.h:234
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:136

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 439 of file DBHandler.cpp.

References calcite_, Catalog_Namespace::CALCITE_SESSION_ID_LENGTH, calcite_sessions_, calcite_sessions_mtx_, CHECK, executor_device_type_, and generate_random_string().

Referenced by processCalciteRequest().

440  {
441  // We would create an in memory session for calcite with super user privileges which
442  // would be used for getting all tables metadata when a user runs the query. The
443  // session would be under the name of a proxy user/password which would only persist
444  // till server's lifetime or execution of calcite query(in memory) whichever is the
445  // earliest.
447  std::string session_id;
448  do {
450  } while (calcite_sessions_.find(session_id) != calcite_sessions_.end());
451  Catalog_Namespace::UserMetadata user_meta(-1,
452  calcite_->getInternalSessionProxyUserName(),
453  calcite_->getInternalSessionProxyPassword(),
454  true,
455  -1,
456  true,
457  false);
458  const auto emplace_ret = calcite_sessions_.emplace(
459  session_id,
460  std::make_shared<Catalog_Namespace::SessionInfo>(
461  catalog_ptr, user_meta, executor_device_type_, session_id));
462  CHECK(emplace_ret.second);
463  return session_id;
464 }
std::lock_guard< T > lock_guard
std::unordered_map< std::string, Catalog_Namespace::SessionInfoPtr > calcite_sessions_
Definition: DBHandler.h:946
const size_t CALCITE_SESSION_ID_LENGTH
Definition: SessionInfo.h:126
std::string generate_random_string(const size_t len)
ExecutorDeviceType executor_device_type_
Definition: DBHandler.h:634
heavyai::shared_mutex calcite_sessions_mtx_
Definition: DBHandler.h:947
std::shared_ptr< Calcite > calcite_
Definition: DBHandler.h:652
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 6175 of file DBHandler.cpp.

References CHECK, CHECK_EQ, and run_benchmark_import::label.

Referenced by convertExplain(), and convertResult().

6178  {
6179  CHECK_EQ(size_t(1), results.rowCount());
6180  TColumnType proj_info;
6181  proj_info.col_name = label;
6182  proj_info.col_type.type = TDatumType::STR;
6183  proj_info.col_type.nullable = false;
6184  proj_info.col_type.is_array = false;
6185  _return.row_set.row_desc.push_back(proj_info);
6186  const auto crt_row = results.getNextRow(true, true);
6187  const auto tv = crt_row[0];
6188  CHECK(results.getNextRow(true, true).empty());
6189  const auto scalar_tv = boost::get<ScalarTargetValue>(&tv);
6190  CHECK(scalar_tv);
6191  const auto s_n = boost::get<NullableString>(scalar_tv);
6192  CHECK(s_n);
6193  const auto s = boost::get<std::string>(s_n);
6194  CHECK(s);
6195  if (column_format) {
6196  TColumn tcol;
6197  tcol.data.str_col.push_back(*s);
6198  tcol.nulls.push_back(false);
6199  _return.row_set.is_columnar = true;
6200  _return.row_set.columns.push_back(tcol);
6201  } else {
6202  TDatum explanation;
6203  explanation.val.str_val = *s;
6204  explanation.is_null = false;
6205  TRow trow;
6206  trow.cols.push_back(explanation);
6207  _return.row_set.is_columnar = false;
6208  _return.row_set.rows.push_back(trow);
6209  }
6210 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the caller graph for this function:

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

Definition at line 1415 of file DBHandler.cpp.

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

1418  {
1419  heavyai::RequestInfo const request_info(session_id_or_json);
1420  SET_REQUEST_ID(request_info.requestId());
1421  auto stdlog = STDLOG(get_session_ptr(request_info.sessionId()));
1422  std::string serialized_cuda_handle = "";
1423  if (device_type == TDeviceType::GPU) {
1424  std::lock_guard<std::mutex> map_lock(handle_to_dev_ptr_mutex_);
1425  if (ipc_handle_to_dev_ptr_.count(df.df_handle) != size_t(1)) {
1426  TDBException ex;
1427  ex.error_msg = std::string(
1428  "Current data frame handle is not bookkept or been inserted "
1429  "twice");
1430  LOG(ERROR) << ex.error_msg;
1431  throw ex;
1432  }
1433  serialized_cuda_handle = ipc_handle_to_dev_ptr_[df.df_handle];
1434  ipc_handle_to_dev_ptr_.erase(df.df_handle);
1435  }
1436  std::vector<char> sm_handle(df.sm_handle.begin(), df.sm_handle.end());
1437  std::vector<char> df_handle(df.df_handle.begin(), df.df_handle.end());
1439  sm_handle, df.sm_size, df_handle, df.df_size, serialized_cuda_handle};
1441  result,
1442  device_type == TDeviceType::CPU ? ExecutorDeviceType::CPU : ExecutorDeviceType::GPU,
1443  device_id,
1444  data_mgr_);
1445 }
std::mutex handle_to_dev_ptr_mutex_
Definition: DBHandler.h:1013
#define LOG(tag)
Definition: Logger.h:285
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5935
#define SET_REQUEST_ID(parent_request_id)
Definition: DBHandler.cpp:130
static void deallocateArrowResultBuffer(const ArrowResult &result, const ExecutorDeviceType device_type, const size_t device_id, std::shared_ptr< Data_Namespace::DataMgr > &data_mgr)
std::shared_ptr< Data_Namespace::DataMgr > data_mgr_
Definition: DBHandler.h:627
std::unordered_map< std::string, std::string > ipc_handle_to_dev_ptr_
Definition: DBHandler.h:1014
#define STDLOG(...)
Definition: QueryState.h:234

+ Here is the call graph for this function:

void DBHandler::delete_custom_expressions ( const TSessionId &  session,
const std::vector< int32_t > &  custom_expression_ids,
const bool  do_soft_delete 
)
override

Definition at line 4469 of file DBHandler.cpp.

References check_read_only(), custom_expressions_mutex_, get_session_ptr(), getConnectionInfo(), heavyai::RequestInfo::requestId(), heavyai::RequestInfo::sessionId(), SET_REQUEST_ID, STDLOG, THROW_DB_EXCEPTION, and toString().

4472  {
4473  heavyai::RequestInfo const request_info(session_id_or_json);
4474  SET_REQUEST_ID(request_info.requestId());
4475  auto stdlog = STDLOG(get_session_ptr(request_info.sessionId()));
4476  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
4477  check_read_only("delete_custom_expressions");
4478 
4479  auto session_ptr = stdlog.getConstSessionInfo();
4480  if (!session_ptr->get_currentUser().isSuper) {
4481  THROW_DB_EXCEPTION("Custom expressions can only be deleted by super users.")
4482  }
4483  auto& catalog = session_ptr->getCatalog();
4485  catalog.deleteCustomExpressions(custom_expression_ids, do_soft_delete);
4486 }
heavyai::unique_lock< heavyai::shared_mutex > write_lock
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5935
std::unique_lock< T > unique_lock
#define SET_REQUEST_ID(parent_request_id)
Definition: DBHandler.cpp:130
std::string toString(const ExecutorDeviceType &device_type)
heavyai::shared_mutex custom_expressions_mutex_
Definition: DBHandler.h:1085
void check_read_only(const std::string &str)
Definition: DBHandler.cpp:433
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1649
#define STDLOG(...)
Definition: QueryState.h:234
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:136

+ Here is the call graph for this function:

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

Definition at line 4712 of file DBHandler.cpp.

References delete_dashboards().

4713  {
4714  delete_dashboards(session_id_or_json, {dashboard_id});
4715 }
void delete_dashboards(const TSessionId &session, const std::vector< int32_t > &dashboard_ids) override
Definition: DBHandler.cpp:4717

+ Here is the call graph for this function:

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

Definition at line 4717 of file DBHandler.cpp.

References cat(), dbhandler::check_not_info_schema_db(), check_read_only(), g_allow_system_dashboard_update, get_session_ptr(), getConnectionInfo(), heavyai::RequestInfo::requestId(), heavyai::RequestInfo::sessionId(), SET_REQUEST_ID, STDLOG, THROW_DB_EXCEPTION, and toString().

Referenced by delete_dashboard().

4718  {
4719  heavyai::RequestInfo const request_info(session_id_or_json);
4720  SET_REQUEST_ID(request_info.requestId());
4721  auto stdlog = STDLOG(get_session_ptr(request_info.sessionId()));
4722  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
4723  auto session_ptr = stdlog.getConstSessionInfo();
4724  check_read_only("delete_dashboards");
4725  auto& cat = session_ptr->getCatalog();
4728  }
4729  // Checks will be performed in catalog
4730  try {
4731  cat.deleteMetadataForDashboards(dashboard_ids, session_ptr->get_currentUser());
4732  } catch (const std::exception& e) {
4733  THROW_DB_EXCEPTION(e.what());
4734  }
4735 }
std::string cat(Ts &&...args)
void check_not_info_schema_db(const std::string &db_name, bool throw_db_exception)
Definition: DBHandler.cpp:4602
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5935
#define SET_REQUEST_ID(parent_request_id)
Definition: DBHandler.cpp:130
std::string toString(const ExecutorDeviceType &device_type)
void check_read_only(const std::string &str)
Definition: DBHandler.cpp:433
bool g_allow_system_dashboard_update
Definition: DBHandler.cpp:122
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1649
#define STDLOG(...)
Definition: QueryState.h:234
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:136

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 4129 of file DBHandler.cpp.

References anonymous_namespace{DBHandler.cpp}::add_vsi_archive_prefix(), anonymous_namespace{DBHandler.cpp}::add_vsi_geo_prefix(), anonymous_namespace{DBHandler.cpp}::add_vsi_network_prefix(), CHECK, check_geospatial_files(), check_read_only(), copyparams_to_thrift(), encoding_to_thrift(), shared::file_or_glob_path_exists(), import_export::CopyParams::file_sort_order_by, import_export::CopyParams::file_sort_regex, anonymous_namespace{DBHandler.cpp}::find_first_geo_file_in_archive(), import_export::Importer::gdalFileExists(), import_export::Importer::gdalFileOrDirectoryExists(), import_export::Importer::gdalToColumnDescriptors(), import_export::CopyParams::geo_coords_comp_param, import_export::CopyParams::geo_coords_encoding, import_export::CopyParams::geo_coords_srid, import_export::CopyParams::geo_coords_type, import_export::DataStreamSink::get_copy_params(), import_export::Detector::get_headers(), import_export::Detector::get_sample_rows(), get_session_ptr(), import_export::Detector::getBestColumnTypes(), getConnectionInfo(), import_path_, anonymous_namespace{DBHandler.cpp}::is_a_supported_archive_file(), anonymous_namespace{DBHandler.cpp}::is_local_file(), ImportHelpers::is_reserved_name(), import_export::Detector::kDefaultSampleRowsCount, import_export::kDelimitedFile, Geospatial::kGeoColumnName, import_export::kGeoFile, import_export::kOdbc, import_export::kParquetFile, import_export::kRasterFile, shared::local_glob_filter_sort_files(), anonymous_namespace{DBHandler.cpp}::path_is_relative(), populateThriftColumnType(), import_export::Importer::readMetadataSampleGDAL(), import_export::CopyParams::regex_path_filter, heavyai::RequestInfo::requestId(), import_export::CopyParams::sanitize_column_names, ImportHelpers::sanitize_name(), heavyai::RequestInfo::sessionId(), SET_REQUEST_ID, import_export::CopyParams::source_type, STDLOG, thrift_to_copyparams(), THROW_DB_EXCEPTION, toString(), type_to_thrift(), and anonymous_namespace{DBHandler.cpp}::validate_import_file_path_if_local().

Referenced by importGeoTableSingle().

4132  {
4133  heavyai::RequestInfo const request_info(session_id_or_json);
4134  SET_REQUEST_ID(request_info.requestId());
4135  auto stdlog = STDLOG(get_session_ptr(request_info.sessionId()));
4136  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
4137  check_read_only("detect_column_types");
4138 
4139  bool is_raster = false;
4140  boost::filesystem::path file_path;
4142  if (copy_params.source_type != import_export::SourceType::kOdbc) {
4143  std::string file_name{file_name_in};
4144  if (path_is_relative(file_name)) {
4145  // assume relative paths are relative to data_path / import / <session>
4146  auto temp_file_path = import_path_ /
4147  picosha2::hash256_hex_string(request_info.sessionId()) /
4148  boost::filesystem::path(file_name).filename();
4149  file_name = temp_file_path.string();
4150  }
4152 
4153  if ((copy_params.source_type == import_export::SourceType::kGeoFile ||
4155  is_local_file(file_name)) {
4156  const shared::FilePathOptions options{copy_params.regex_path_filter,
4157  copy_params.file_sort_order_by,
4158  copy_params.file_sort_regex};
4159  auto file_paths = shared::local_glob_filter_sort_files(file_name, options, false);
4160  // For geo and raster detect, pick the first file, if multiple files are provided
4161  // (e.g. through file globbing).
4162  CHECK(!file_paths.empty());
4163  file_name = file_paths[0];
4164  }
4165 
4166  // if it's a geo or raster import, handle alternative paths (S3, HTTP, archive etc.)
4167  if (copy_params.source_type == import_export::SourceType::kGeoFile) {
4168  if (is_a_supported_archive_file(file_name)) {
4169  // find the archive file
4170  add_vsi_network_prefix(file_name);
4171  if (!import_export::Importer::gdalFileExists(file_name, copy_params)) {
4172  THROW_DB_EXCEPTION("Archive does not exist: " + file_name_in);
4173  }
4174  // find geo file in archive
4175  add_vsi_archive_prefix(file_name);
4176  std::string geo_file = find_first_geo_file_in_archive(file_name, copy_params);
4177  // prepare to detect that geo file
4178  if (geo_file.size()) {
4179  file_name = file_name + std::string("/") + geo_file;
4180  }
4181  } else {
4182  // prepare to detect geo file directly
4183  add_vsi_network_prefix(file_name);
4184  add_vsi_geo_prefix(file_name);
4185  }
4186  } else if (copy_params.source_type == import_export::SourceType::kRasterFile) {
4187  // prepare to detect raster file directly
4188  add_vsi_network_prefix(file_name);
4189  add_vsi_geo_prefix(file_name);
4190  is_raster = true;
4191  }
4192 
4193  file_path = boost::filesystem::path(file_name);
4194  // can be a s3 url
4195  if (!boost::istarts_with(file_name, "s3://")) {
4196  if (!boost::filesystem::path(file_name).is_absolute()) {
4197  file_path = import_path_ /
4198  picosha2::hash256_hex_string(request_info.sessionId()) /
4199  boost::filesystem::path(file_name).filename();
4200  file_name = file_path.string();
4201  }
4202 
4203  if (copy_params.source_type == import_export::SourceType::kGeoFile ||
4205  // check for geo or raster file
4206  if (!import_export::Importer::gdalFileOrDirectoryExists(file_name, copy_params)) {
4207  THROW_DB_EXCEPTION("File or directory \"" + file_path.string() +
4208  "\" does not exist.")
4209  }
4210  } else {
4211  // check for regular file
4212  if (!shared::file_or_glob_path_exists(file_path.string())) {
4213  THROW_DB_EXCEPTION("File or directory \"" + file_path.string() +
4214  "\" does not exist.");
4215  }
4216  }
4217  }
4218  }
4219 
4220  try {
4222 #ifdef ENABLE_IMPORT_PARQUET
4224 #endif
4225  ) {
4226  import_export::Detector detector(file_path, copy_params);
4227  auto best_types = detector.getBestColumnTypes();
4228  std::vector<std::string> headers = detector.get_headers();
4229  copy_params = detector.get_copy_params();
4230 
4231  _return.copy_params = copyparams_to_thrift(copy_params);
4232  _return.row_set.row_desc.resize(best_types.size());
4233  for (size_t col_idx = 0; col_idx < best_types.size(); col_idx++) {
4234  TColumnType col;
4235  auto& ti = best_types[col_idx];
4236  col.col_type.precision = ti.get_precision();
4237  col.col_type.scale = ti.get_scale();
4238  col.col_type.comp_param = ti.get_comp_param();
4239  if (ti.is_geometry()) {
4240  // set this so encoding_to_thrift does the right thing
4241  ti.set_compression(copy_params.geo_coords_encoding);
4242  // fill in these directly
4243  col.col_type.precision = static_cast<int>(copy_params.geo_coords_type);
4244  col.col_type.scale = copy_params.geo_coords_srid;
4245  col.col_type.comp_param = copy_params.geo_coords_comp_param;
4246  }
4247  col.col_type.type = type_to_thrift(ti);
4248  col.col_type.encoding = encoding_to_thrift(ti);
4249  if (ti.is_array()) {
4250  col.col_type.is_array = true;
4251  }
4252  if (copy_params.sanitize_column_names) {
4253  col.col_name = ImportHelpers::sanitize_name(headers[col_idx]);
4254  } else {
4255  col.col_name = headers[col_idx];
4256  }
4257  col.is_reserved_keyword = ImportHelpers::is_reserved_name(col.col_name);
4258  _return.row_set.row_desc[col_idx] = col;
4259  }
4260  auto sample_data =
4261  detector.get_sample_rows(import_export::Detector::kDefaultSampleRowsCount);
4262 
4263  TRow sample_row;
4264  for (auto row : sample_data) {
4265  sample_row.cols.clear();
4266  for (const auto& s : row) {
4267  TDatum td;
4268  td.val.str_val = s;
4269  td.is_null = s.empty();
4270  sample_row.cols.push_back(td);
4271  }
4272  _return.row_set.rows.push_back(sample_row);
4273  }
4274  } else if (copy_params.source_type == import_export::SourceType::kGeoFile ||
4276  check_geospatial_files(file_path, copy_params);
4277  std::list<ColumnDescriptor> cds = import_export::Importer::gdalToColumnDescriptors(
4278  file_path.string(), is_raster, Geospatial::kGeoColumnName, copy_params);
4279  for (auto cd : cds) {
4280  if (copy_params.sanitize_column_names) {
4281  cd.columnName = ImportHelpers::sanitize_name(cd.columnName);
4282  }
4283  _return.row_set.row_desc.push_back(populateThriftColumnType(nullptr, &cd));
4284  }
4285  if (!is_raster) {
4286  // @TODO(se) support for raster?
4287  std::map<std::string, std::vector<std::string>> sample_data;
4289  file_path.string(),
4291  sample_data,
4293  copy_params);
4294  if (sample_data.size() > 0) {
4295  for (size_t i = 0; i < sample_data.begin()->second.size(); i++) {
4296  TRow sample_row;
4297  for (auto cd : cds) {
4298  TDatum td;
4299  td.val.str_val = sample_data[cd.sourceName].at(i);
4300  td.is_null = td.val.str_val.empty();
4301  sample_row.cols.push_back(td);
4302  }
4303  _return.row_set.rows.push_back(sample_row);
4304  }
4305  }
4306  }
4307  _return.copy_params = copyparams_to_thrift(copy_params);
4308  }
4309  } catch (const std::exception& e) {
4310  THROW_DB_EXCEPTION("detect_column_types error: " + std::string(e.what()));
4311  }
4312 }
boost::filesystem::path import_path_
Definition: DBHandler.h:633
void add_vsi_archive_prefix(std::string &path)
Definition: DBHandler.cpp:4001
bool is_a_supported_archive_file(const std::string &path)
Definition: DBHandler.cpp:4067
TDatumType::type type_to_thrift(const SQLTypeInfo &type_info)
bool path_is_relative(const std::string &path)
Definition: DBHandler.cpp:4035
TCopyParams copyparams_to_thrift(const import_export::CopyParams &cp)
Definition: DBHandler.cpp:3840
static bool gdalFileExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:5153
const std::string kGeoColumnName
Definition: ColumnNames.h:23
bool is_reserved_name(const std::string &name)
std::optional< std::string > regex_path_filter
Definition: CopyParams.h:85
TColumnType populateThriftColumnType(const Catalog_Namespace::Catalog *cat, const ColumnDescriptor *cd)
Definition: DBHandler.cpp:2200
void check_geospatial_files(const boost::filesystem::path file_path, const import_export::CopyParams &copy_params)
Definition: DBHandler.cpp:4961
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:4727
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5935
void validate_import_file_path_if_local(const std::string &file_path)
Definition: DBHandler.cpp:4121
import_export::SourceType source_type
Definition: CopyParams.h:57
#define SET_REQUEST_ID(parent_request_id)
Definition: DBHandler.cpp:130
std::string toString(const ExecutorDeviceType &device_type)
static constexpr size_t kDefaultSampleRowsCount
Definition: Importer.h:737
static bool gdalFileOrDirectoryExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:5158
bool file_or_glob_path_exists(const std::string &path)
std::string sanitize_name(const std::string &name, const bool underscore=false)
void check_read_only(const std::string &str)
Definition: DBHandler.cpp:433
std::string find_first_geo_file_in_archive(const std::string &archive_path, const import_export::CopyParams &copy_params)
Definition: DBHandler.cpp:4080
void add_vsi_network_prefix(std::string &path)
Definition: DBHandler.cpp:3972
#define CHECK(condition)
Definition: Logger.h:291
static const std::list< ColumnDescriptor > gdalToColumnDescriptors(const std::string &fileName, const bool is_raster, const std::string &geoColumnName, const CopyParams &copy_params)
Definition: Importer.cpp:4922
std::vector< std::string > local_glob_filter_sort_files(const std::string &file_path, const FilePathOptions &options, const bool recurse)
import_export::CopyParams thrift_to_copyparams(const TCopyParams &cp)
Definition: DBHandler.cpp:3645
std::optional< std::string > file_sort_order_by
Definition: CopyParams.h:86
void add_vsi_geo_prefix(std::string &path)
Definition: DBHandler.cpp:3994
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1649
#define STDLOG(...)
Definition: QueryState.h:234
std::optional< std::string > file_sort_regex
Definition: CopyParams.h:87
TEncodingType::type encoding_to_thrift(const SQLTypeInfo &type_info)
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:136
EncodingType geo_coords_encoding
Definition: CopyParams.h:76
bool is_local_file(const std::string &file_path)
Definition: DBHandler.cpp:4115

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 572 of file DBHandler.cpp.

References get_session_ptr(), getConnectionInfo(), heavyai::RequestInfo::requestId(), heavyai::RequestInfo::sessionId(), sessions_store_, SET_REQUEST_ID, STDLOG, and toString().

572  {
573  heavyai::RequestInfo const request_info(session_id_or_json);
574  SET_REQUEST_ID(request_info.requestId());
575  auto session_ptr = get_session_ptr(request_info.sessionId());
576  auto stdlog = STDLOG(session_ptr, "client", getConnectionInfo().toString());
577  sessions_store_->disconnect(request_info.sessionId());
578 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5935
#define SET_REQUEST_ID(parent_request_id)
Definition: DBHandler.cpp:130
std::string toString(const ExecutorDeviceType &device_type)
std::unique_ptr< Catalog_Namespace::SessionsStore > sessions_store_
Definition: DBHandler.h:977
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1649
#define STDLOG(...)
Definition: QueryState.h:234

+ Here is the call graph for this function:

void DBHandler::disconnect_impl ( Catalog_Namespace::SessionInfoPtr session_ptr)
private

Definition at line 580 of file DBHandler.cpp.

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

Referenced by resetSessionsStore().

580  {
581  const auto session_id = session_ptr->get_session_id();
582  std::exception_ptr leaf_exception = nullptr;
583  try {
584  if (leaf_aggregator_.leafCount() > 0) {
585  leaf_aggregator_.disconnect(session_id);
586  }
587  } catch (...) {
588  leaf_exception = std::current_exception();
589  }
590 
591  {
592  std::lock_guard<std::mutex> lock(render_group_assignment_mutex_);
593  render_group_assignment_map_.erase(session_id);
594  }
595 
596  if (render_handler_) {
597  render_handler_->disconnect(session_id);
598  }
599 
600  if (leaf_exception) {
601  std::rethrow_exception(leaf_exception);
602  }
603 }
std::mutex render_group_assignment_mutex_
Definition: DBHandler.h:1084
LeafAggregator leaf_aggregator_
Definition: DBHandler.h:629
void disconnect(const TSessionId session)
std::unique_ptr< RenderHandler > render_handler_
Definition: DBHandler.h:649
size_t leafCount() const
RenderGroupAnalyzerSessionMap render_group_assignment_map_
Definition: DBHandler.h:1083

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void DBHandler::dispatch_query_task ( std::shared_ptr< QueryDispatchQueue::Task query_task,
const bool  is_update_delete 
)
private

Definition at line 1679 of file DBHandler.cpp.

References CHECK, and dispatch_queue_.

Referenced by validate_rel_alg().

1680  {
1682  dispatch_queue_->submit(std::move(query_task), is_update_delete);
1683 }
std::unique_ptr< QueryDispatchQueue > dispatch_queue_
Definition: DBHandler.h:655
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the caller graph for this function:

void DBHandler::emergency_shutdown ( )

Definition at line 7373 of file DBHandler.cpp.

References calcite_.

Referenced by shutdown().

7373  {
7374  if (calcite_) {
7375  calcite_->close_calcite_server(false);
7376  }
7377 }
std::shared_ptr< Calcite > calcite_
Definition: DBHandler.h:652

+ Here is the caller graph for this function:

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

Definition at line 6634 of file DBHandler.cpp.

Referenced by sql_execute_impl().

6636  {}

+ Here is the caller graph for this function:

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

Definition at line 7123 of file DBHandler.cpp.

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

7125  {
7126  // No SessionID is available
7127  SET_REQUEST_ID(0);
7128 
7129  if (!render_handler_) {
7130  THROW_DB_EXCEPTION("Backend rendering is disabled.");
7131  }
7132 
7133  LOG(INFO) << "execute_next_render_step: id:" << pending_render.id;
7134  auto time_ms = measure<>::execution([&]() {
7135  try {
7136  render_handler_->execute_next_render_step(_return, pending_render, merged_data);
7137  } catch (std::exception& e) {
7138  THROW_DB_EXCEPTION(e.what());
7139  }
7140  });
7141  LOG(INFO) << "execute_next_render_step-COMPLETED id: " << pending_render.id
7142  << ", time: " << time_ms << "ms ";
7143 }
static TimeT::rep execution(F func, Args &&...args)
Definition: sample.cpp:29
#define LOG(tag)
Definition: Logger.h:285
std::unique_ptr< RenderHandler > render_handler_
Definition: DBHandler.h:649
#define SET_REQUEST_ID(parent_request_id)
Definition: DBHandler.cpp:130
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:136

+ Here is the call graph for this function:

void DBHandler::execute_query_step ( TStepResult &  _return,
const TPendingQuery &  pending_query,
const TSubqueryId  subquery_id,
const std::string &  start_time_str 
)
override

Definition at line 6879 of file DBHandler.cpp.

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

6882  {
6883  SET_REQUEST_ID(0); // No SessionID is available
6884  if (!leaf_handler_) {
6885  THROW_DB_EXCEPTION("Distributed support is disabled.");
6886  }
6887  LOG(INFO) << "execute_query_step : id:" << pending_query.id;
6888  auto time_ms = measure<>::execution([&]() {
6889  try {
6890  leaf_handler_->execute_query_step(
6891  _return, pending_query, subquery_id, start_time_str);
6892  } catch (std::exception& e) {
6893  THROW_DB_EXCEPTION(e.what());
6894  }
6895  });
6896  LOG(INFO) << "execute_query_step-COMPLETED " << time_ms << "ms";
6897 }
static TimeT::rep execution(F func, Args &&...args)
Definition: sample.cpp:29
#define LOG(tag)
Definition: Logger.h:285
#define SET_REQUEST_ID(parent_request_id)
Definition: DBHandler.cpp:130
std::unique_ptr< HeavyDBLeafHandler > leaf_handler_
Definition: DBHandler.h:651
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:136

+ Here is the call graph for this function:

std::vector< PushedDownFilterInfo > DBHandler::execute_rel_alg ( ExecutionResult _return,
QueryStateProxy  query_state_proxy,
const std::string &  query_ra,
const bool  column_format,
const ExecutorDeviceType  executor_device_type,
const int32_t  first_n,
const int32_t  at_most_n,
const bool  just_validate,
const bool  find_push_down_candidates,
const ExplainInfo explain_info,
const std::optional< size_t >  executor_index = std::nullopt 
) const
private

Definition at line 5994 of file DBHandler.cpp.

References allow_loop_joins_, allow_multifrag_, cat(), query_state::QueryStateProxy::createTimer(), Default, measure< TimeT >::execution(), ExecutionResult::Explanation, g_dynamic_watchdog_time_limit, g_enable_columnar_output, g_enable_dynamic_watchdog, g_enable_runtime_query_interrupt, g_enable_watchdog, g_optimize_cuda_block_and_grid_sizes, g_pending_query_interrupt_freq, g_running_query_interrupt_freq, query_state::QueryState::getConstSessionInfo(), ExecutionResult::getExecutionTime(), Executor::getExecutor(), ExecutionResult::getPushedDownFilterInfo(), ExecutionResult::getRows(), SystemParameters::gpu_input_mem_limit, lockmgr::TableSchemaLockMgr::instance(), lockmgr::TableDataLockMgr::instance(), intel_jit_profile_, ExplainInfo::isCalciteExplain(), ExplainInfo::isJustExplain(), ExplainInfo::isOptimizedExplain(), ExplainInfo::isPlanExplain(), jit_debug_, Optimized, ExecutionResult::QueryResult, ExecutionResult::setExecutionTime(), ExecutionResult::setResultType(), system_parameters_, Executor::UNITARY_EXECUTOR_ID, and VLOG.

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

6005  {
6006  query_state::Timer timer = query_state_proxy.createTimer(__func__);
6007 
6008  VLOG(1) << "Table Schema Locks:\n" << lockmgr::TableSchemaLockMgr::instance();
6009  VLOG(1) << "Table Data Locks:\n" << lockmgr::TableDataLockMgr::instance();
6010 
6011  auto& cat = query_state_proxy->getConstSessionInfo()->getCatalog();
6012  auto executor = Executor::getExecutor(
6013  executor_index ? *executor_index : Executor::UNITARY_EXECUTOR_ID,
6014  jit_debug_ ? "/tmp" : "",
6015  jit_debug_ ? "mapdquery" : "",
6017  RelAlgExecutor ra_executor(
6018  executor.get(), query_ra, query_state_proxy->shared_from_this());
6019  CompilationOptions co = {executor_device_type,
6020  /*hoist_literals=*/true,
6023  /*allow_lazy_fetch=*/true,
6024  /*filter_on_deleted_column=*/true,
6025  explain_info.isOptimizedExplain()
6029  auto validate_or_explain_query =
6030  explain_info.isJustExplain() || explain_info.isCalciteExplain() || just_validate;
6031  ExecutionOptions eo = {
6033  false,
6035  explain_info.isJustExplain(),
6036  allow_loop_joins_ || just_validate,
6038  jit_debug_,
6039  just_validate,
6042  find_push_down_candidates,
6043  explain_info.isCalciteExplain(),
6045  g_enable_runtime_query_interrupt && !validate_or_explain_query &&
6046  !query_state_proxy->getConstSessionInfo()->get_session_id().empty(),
6050  auto execution_time_ms = _return.getExecutionTime() + measure<>::execution([&]() {
6051  _return = ra_executor.executeRelAlgQuery(
6052  co, eo, explain_info.isPlanExplain(), nullptr);
6053  });
6054  // reduce execution time by the time spent during queue waiting
6055  const auto rs = _return.getRows();
6056  if (rs) {
6057  execution_time_ms -= rs->getQueueTime();
6058  }
6059  _return.setExecutionTime(execution_time_ms);
6060  VLOG(1) << cat.getDataMgr().getSystemMemoryUsage();
6061  const auto& filter_push_down_info = _return.getPushedDownFilterInfo();
6062  if (!filter_push_down_info.empty()) {
6063  return filter_push_down_info;
6064  }
6065  if (explain_info.isJustExplain()) {
6067  } else if (!explain_info.isCalciteExplain()) {
6069  }
6070  return {};
6071 }
double g_running_query_interrupt_freq
Definition: Execute.cpp:129
static TableSchemaLockMgr & instance()
Definition: LockMgr.h:40
std::string cat(Ts &&...args)
static TimeT::rep execution(F func, Args &&...args)
Definition: sample.cpp:29
unsigned g_pending_query_interrupt_freq
Definition: Execute.cpp:128
const bool jit_debug_
Definition: DBHandler.h:637
bool g_enable_dynamic_watchdog
Definition: Execute.cpp:80
Timer createTimer(char const *event_name)
Definition: QueryState.cpp:129
static TableDataLockMgr & instance()
Definition: LockMgr.h:78
static std::shared_ptr< Executor > getExecutor(const ExecutorId id, const std::string &debug_dir="", const std::string &debug_file="", const SystemParameters &system_parameters=SystemParameters())
Definition: Execute.cpp:475
bool g_enable_columnar_output
Definition: Execute.cpp:99
const std::shared_ptr< ResultSet > & getRows() const
bool g_enable_watchdog
SystemParameters & system_parameters_
Definition: DBHandler.h:647
bool isOptimizedExplain() const
Definition: ParserWrapper.h:57
bool g_optimize_cuda_block_and_grid_sizes
Definition: Execute.cpp:157
void setResultType(RType type)
bool isJustExplain() const
Definition: ParserWrapper.h:40
const bool allow_loop_joins_
Definition: DBHandler.h:641
const bool intel_jit_profile_
Definition: DBHandler.h:638
const std::vector< PushedDownFilterInfo > & getPushedDownFilterInfo() const
void setExecutionTime(int64_t execution_time_ms)
bool isCalciteExplain() const
Definition: ParserWrapper.h:58
bool allow_multifrag_
Definition: DBHandler.h:639
unsigned g_dynamic_watchdog_time_limit
Definition: Execute.cpp:85
std::shared_ptr< Catalog_Namespace::SessionInfo const > getConstSessionInfo() const
Definition: QueryState.cpp:84
int64_t getExecutionTime() const
bool g_enable_runtime_query_interrupt
Definition: Execute.cpp:125
#define VLOG(n)
Definition: Logger.h:387
bool isPlanExplain() const
Definition: ParserWrapper.h:59
static const ExecutorId UNITARY_EXECUTOR_ID
Definition: Execute.h:373

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void DBHandler::execute_rel_alg_with_filter_push_down ( ExecutionResult _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 6584 of file DBHandler.cpp.

References ExecutionResult::addExecutionTime(), execute_rel_alg(), ExecutionResult::Explanation, query_state::QueryState::getQueryStr(), ExplainInfo::IR, parse_to_ra(), system_parameters_, and ExecutionResult::updateResultSet().

Referenced by sql_execute_impl().

6594  {
6595  // collecting the selected filters' info to be sent to Calcite:
6596  std::vector<TFilterPushDownInfo> filter_push_down_info;
6597  for (const auto& req : filter_push_down_requests) {
6598  TFilterPushDownInfo filter_push_down_info_for_request;
6599  filter_push_down_info_for_request.input_prev = req.input_prev;
6600  filter_push_down_info_for_request.input_start = req.input_start;
6601  filter_push_down_info_for_request.input_next = req.input_next;
6602  filter_push_down_info.push_back(filter_push_down_info_for_request);
6603  }
6604  // deriving the new relational algebra plan with respect to the pushed down filters
6605  _return.addExecutionTime(measure<>::execution([&]() {
6606  query_ra = parse_to_ra(query_state_proxy,
6607  query_state_proxy->getQueryStr(),
6608  filter_push_down_info,
6609  false,
6611  .first.plan_result;
6612  }));
6613 
6614  if (is_calcite_explain) {
6615  // return the new ra as the result
6616  _return.updateResultSet(query_ra, ExecutionResult::Explanation);
6617  return;
6618  }
6619 
6620  // execute the new relational algebra plan:
6621  auto explain_info = ExplainInfo(ExplainInfo::ExplainType::IR);
6622  execute_rel_alg(_return,
6623  query_state_proxy,
6624  query_ra,
6625  column_format,
6626  executor_device_type,
6627  first_n,
6628  at_most_n,
6629  /*just_validate=*/false,
6630  /*find_push_down_candidates=*/false,
6631  explain_info);
6632 }
std::vector< PushedDownFilterInfo > execute_rel_alg(ExecutionResult &_return, QueryStateProxy, const std::string &query_ra, const bool column_format, const ExecutorDeviceType executor_device_type, const int32_t first_n, const int32_t at_most_n, const bool just_validate, const bool find_push_down_candidates, const ExplainInfo &explain_info, const std::optional< size_t > executor_index=std::nullopt) const
Definition: DBHandler.cpp:5994
std::string const & getQueryStr() const
Definition: QueryState.h:159
void addExecutionTime(int64_t execution_time_ms)
void updateResultSet(const std::string &query_ra, RType type, bool success=true)
SystemParameters & system_parameters_
Definition: DBHandler.h:647
std::pair< TPlanResult, lockmgr::LockedTableDescriptors > parse_to_ra(QueryStateProxy, const std::string &query_str, const std::vector< TFilterPushDownInfo > &filter_push_down_info, const bool acquire_locks, const SystemParameters &system_parameters, bool check_privileges=true)
Definition: DBHandler.cpp:6706

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 7878 of file DBHandler.cpp.

References alterSession(), alterSystemClear(), DdlCommandExecutor::commandStr(), convertResultSet(), ExecutionResult::empty(), DdlCommandExecutor::execute(), measure< TimeT >::execution(), getQueries(), ExecutionResult::getRows(), DdlCommandExecutor::getSessionParameter(), DdlCommandExecutor::getTargetQuerySessionToKill(), getUserSessions(), interruptQuery(), DdlCommandExecutor::isAlterSessionSet(), DdlCommandExecutor::isAlterSystemClear(), DdlCommandExecutor::isKillQuery(), DdlCommandExecutor::isShowQueries(), DdlCommandExecutor::isShowUserSessions(), read_only_, run_benchmark_import::result, and DdlCommandExecutor::returnCacheType().

Referenced by sql_execute_impl().

7881  {
7882  DdlCommandExecutor executor = DdlCommandExecutor(query_ra, session_ptr);
7883  std::string commandStr = executor.commandStr();
7884 
7885  if (executor.isKillQuery()) {
7886  interruptQuery(*session_ptr, executor.getTargetQuerySessionToKill());
7887  } else {
7889  int64_t execution_time_ms;
7890  if (executor.isShowQueries()) {
7891  // getQueries still requires Thrift cannot be nested into DdlCommandExecutor
7892  _return.execution_time_ms +=
7893  measure<>::execution([&]() { result = getQueries(session_ptr); });
7894  } else if (executor.isShowUserSessions()) {
7895  // getUserSessions still requires Thrift cannot be nested into DdlCommandExecutor
7896  _return.execution_time_ms +=
7897  measure<>::execution([&]() { result = getUserSessions(session_ptr); });
7898  } else if (executor.isAlterSystemClear()) {
7899  alterSystemClear(session_ptr->get_session_id(),
7900  result,
7901  executor.returnCacheType(),
7902  execution_time_ms);
7903  _return.execution_time_ms += execution_time_ms;
7904 
7905  } else if (executor.isAlterSessionSet()) {
7906  alterSession(session_ptr->get_session_id(),
7907  result,
7908  executor.getSessionParameter(),
7909  execution_time_ms);
7910  _return.execution_time_ms += execution_time_ms;
7911  } else {
7912  _return.execution_time_ms +=
7913  measure<>::execution([&]() { result = executor.execute(read_only_); });
7914  }
7915 
7916  if (!result.empty()) {
7917  // reduce execution time by the time spent during queue waiting
7918  _return.execution_time_ms -= result.getRows()->getQueueTime();
7919  convertResultSet(result, *session_ptr, commandStr, _return);
7920  }
7921  }
7922 }
const std::string getTargetQuerySessionToKill() const
const std::string commandStr() const
static TimeT::rep execution(F func, Args &&...args)
Definition: sample.cpp:29
std::pair< std::string, std::string > getSessionParameter() const
void convertResultSet(ExecutionResult &result, const Catalog_Namespace::SessionInfo &session_info, const std::string &query_state_str, TQueryResult &_return)
Definition: DBHandler.cpp:7554
bool isAlterSystemClear() const
const std::shared_ptr< ResultSet > & getRows() const
bool isShowUserSessions() const
void alterSession(const std::string &sesson_id, ExecutionResult &result, const std::pair< std::string, std::string > &session_parameter, int64_t &execution_time_ms)
Definition: DBHandler.cpp:7853
bool isAlterSessionSet() const
ExecutionResult execute(bool read_only_mode)
const bool read_only_
Definition: DBHandler.h:640
std::string returnCacheType() const
void interruptQuery(const Catalog_Namespace::SessionInfo &session_info, const std::string &target_session)
Definition: DBHandler.cpp:7748
ExecutionResult getQueries(std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
Definition: DBHandler.cpp:7621
ExecutionResult getUserSessions(std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
Definition: DBHandler.cpp:7583
void alterSystemClear(const std::string &sesson_id, ExecutionResult &result, const std::string &cache_type, int64_t &execution_time_ms)
Definition: DBHandler.cpp:7837

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 7924 of file DBHandler.cpp.

References alterSession(), alterSystemClear(), ExecutionResult::CalciteDdl, DdlCommandExecutor::commandStr(), DdlCommandExecutor::execute(), measure< TimeT >::execution(), getQueries(), ExecutionResult::getResultType(), DdlCommandExecutor::getSessionParameter(), DdlCommandExecutor::getTargetQuerySessionToKill(), getUserSessions(), interruptQuery(), DdlCommandExecutor::isAlterSessionSet(), DdlCommandExecutor::isAlterSystemClear(), DdlCommandExecutor::isKillQuery(), DdlCommandExecutor::isShowQueries(), DdlCommandExecutor::isShowUserSessions(), ExecutionResult::QueryResult, read_only_, DdlCommandExecutor::returnCacheType(), ExecutionResult::setExecutionTime(), and ExecutionResult::setResultType().

7927  {
7928  DdlCommandExecutor executor = DdlCommandExecutor(query_ra, session_ptr);
7929  std::string commandStr = executor.commandStr();
7930 
7931  if (executor.isKillQuery()) {
7932  interruptQuery(*session_ptr, executor.getTargetQuerySessionToKill());
7933  } else {
7934  int64_t execution_time_ms;
7935  if (executor.isShowQueries()) {
7936  // getQueries still requires Thrift cannot be nested into DdlCommandExecutor
7937  execution_time_ms =
7938  measure<>::execution([&]() { _return = getQueries(session_ptr); });
7939  } else if (executor.isShowUserSessions()) {
7940  // getUserSessions still requires Thrift cannot be nested into DdlCommandExecutor
7941  execution_time_ms =
7942  measure<>::execution([&]() { _return = getUserSessions(session_ptr); });
7943  } else if (executor.isAlterSystemClear()) {
7944  alterSystemClear(session_ptr->get_session_id(),
7945  _return,
7946  executor.returnCacheType(),
7947  execution_time_ms);
7948  } else if (executor.isAlterSessionSet()) {
7949  alterSession(session_ptr->get_session_id(),
7950  _return,
7951  executor.getSessionParameter(),
7952  execution_time_ms);
7953  } else {
7954  execution_time_ms =
7955  measure<>::execution([&]() { _return = executor.execute(read_only_); });
7956  }
7957  _return.setExecutionTime(execution_time_ms);
7958  }
7959  if (_return.getResultType() == ExecutionResult::QueryResult) {
7960  // ResultType defaults to QueryResult => which can limit
7961  // the number of lines output via ConvertRow... use CalciteDdl instead
7963  }
7964 }
RType getResultType() const
const std::string getTargetQuerySessionToKill() const
const std::string commandStr() const
static TimeT::rep execution(F func, Args &&...args)
Definition: sample.cpp:29
std::pair< std::string, std::string > getSessionParameter() const
bool isAlterSystemClear() const
bool isShowUserSessions() const
void alterSession(const std::string &sesson_id, ExecutionResult &result, const std::pair< std::string, std::string > &session_parameter, int64_t &execution_time_ms)
Definition: DBHandler.cpp:7853
void setResultType(RType type)
bool isAlterSessionSet() const
ExecutionResult execute(bool read_only_mode)
const bool read_only_
Definition: DBHandler.h:640
std::string returnCacheType() const
void setExecutionTime(int64_t execution_time_ms)
void interruptQuery(const Catalog_Namespace::SessionInfo &session_info, const std::string &target_session)
Definition: DBHandler.cpp:7748
ExecutionResult getQueries(std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
Definition: DBHandler.cpp:7621
ExecutionResult getUserSessions(std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
Definition: DBHandler.cpp:7583
void alterSystemClear(const std::string &sesson_id, ExecutionResult &result, const std::string &cache_type, int64_t &execution_time_ms)
Definition: DBHandler.cpp:7837

+ Here is the call graph for this function:

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

Definition at line 1629 of file DBHandler.cpp.

References get_table_details_impl().

Referenced by get_token_based_completions().

1630  {
1631  std::unordered_map<std::string, std::unordered_set<std::string>> column_names_by_table;
1632  for (auto it = table_names.begin(); it != table_names.end();) {
1633  TTableDetails table_details;
1634  try {
1635  get_table_details_impl(table_details, stdlog, *it, false, false);
1636  } catch (const TDBException& e) {
1637  // Remove the corrupted Table/View name from the list for further processing.
1638  it = table_names.erase(it);
1639  continue;
1640  }
1641  for (const auto& column_type : table_details.row_desc) {
1642  column_names_by_table[*it].emplace(column_type.col_name);
1643  }
1644  ++it;
1645  }
1646  return column_names_by_table;
1647 }
void get_table_details_impl(TTableDetails &_return, query_state::StdLog &stdlog, const std::string &table_name, const bool get_system, const bool get_physical, const std::string &database_name={})
Definition: DBHandler.cpp:2372

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void DBHandler::fillGeoColumns ( const TSessionId &  session,
const Catalog_Namespace::Catalog catalog,
std::vector< std::unique_ptr< import_export::TypedImportBuffer >> &  import_buffers,
const ColumnDescriptor cd,
size_t &  col_idx,
size_t  num_rows,
const std::string &  table_name,
bool  assign_render_groups 
)
private

Definition at line 2957 of file DBHandler.cpp.

References CHECK, CHECK_EQ, ColumnDescriptor::columnName, ColumnDescriptor::columnType, g_enable_assign_render_groups, SQLTypeInfo::get_type(), Geospatial::GeoTypesFactory::getGeoColumns(), logger::INFO, IS_GEO_POLY, LOG, LOG_IF, render_group_assignment_map_, render_group_assignment_mutex_, import_export::Importer::set_geo_physical_import_buffer_columnar(), and THROW_DB_EXCEPTION.

Referenced by fillMissingBuffers(), load_table(), and loadTableBinaryColumnarInternal().

2965  {
2966  auto geo_col_idx = col_idx - 1;
2967  const auto wkt_or_wkb_hex_column = import_buffers[geo_col_idx]->getGeoStringBuffer();
2968  std::vector<std::vector<double>> coords_column, bounds_column;
2969  std::vector<std::vector<int>> ring_sizes_column, poly_rings_column;
2970  std::vector<int> render_groups_column;
2971  SQLTypeInfo ti = cd->columnType;
2972  if (num_rows != wkt_or_wkb_hex_column->size() ||
2973  !Geospatial::GeoTypesFactory::getGeoColumns(wkt_or_wkb_hex_column,
2974  ti,
2975  coords_column,
2976  bounds_column,
2977  ring_sizes_column,
2978  poly_rings_column,
2979  true)) {
2980  std::ostringstream oss;
2981  oss << "Invalid geometry in column " << cd->columnName;
2982  THROW_DB_EXCEPTION(oss.str());
2983  }
2984 
2985  // start or continue assigning render groups for poly columns?
2986  if (IS_GEO_POLY(cd->columnType.get_type()) && assign_render_groups &&
2988  // get RGA to use
2989  import_export::RenderGroupAnalyzer* render_group_analyzer{};
2990  {
2991  // mutex the map access
2992  std::lock_guard<std::mutex> lock(render_group_assignment_mutex_);
2993 
2994  // emplace new RGA or fetch existing RGA from map
2995  auto [itr_table, emplaced_table] = render_group_assignment_map_.try_emplace(
2996  session_id, RenderGroupAssignmentTableMap());
2997  LOG_IF(INFO, emplaced_table)
2998  << "load_table_binary_columnar_polys: Creating Render Group Assignment "
2999  "Persistent Data for Session '"
3000  << session_id << "'";
3001  auto [itr_column, emplaced_column] =
3002  itr_table->second.try_emplace(table_name, RenderGroupAssignmentColumnMap());
3003  LOG_IF(INFO, emplaced_column)
3004  << "load_table_binary_columnar_polys: Creating Render Group Assignment "
3005  "Persistent Data for Table '"
3006  << table_name << "'";
3007  auto [itr_analyzer, emplaced_analyzer] = itr_column->second.try_emplace(
3008  cd->columnName, std::make_unique<import_export::RenderGroupAnalyzer>());
3009  LOG_IF(INFO, emplaced_analyzer)
3010  << "load_table_binary_columnar_polys: Creating Render Group Assignment "
3011  "Persistent Data for Column '"
3012  << cd->columnName << "'";
3013  render_group_analyzer = itr_analyzer->second.get();
3014  CHECK(render_group_analyzer);
3015 
3016  // seed new RGA from existing table/column, to handle appends
3017  if (emplaced_analyzer) {
3018  LOG(INFO) << "load_table_binary_columnar_polys: Seeding Render Groups from "
3019  "existing table...";
3020  render_group_analyzer->seedFromExistingTableContents(
3021  catalog, table_name, cd->columnName);
3022  LOG(INFO) << "load_table_binary_columnar_polys: Done";
3023  }
3024  }
3025 
3026  // assign render groups for this set of bounds
3027  LOG(INFO) << "load_table_binary_columnar_polys: Assigning Render Groups...";
3028  render_groups_column.reserve(bounds_column.size());
3029  for (auto const& bounds : bounds_column) {
3030  CHECK_EQ(bounds.size(), 4u);
3031  int rg = render_group_analyzer->insertBoundsAndReturnRenderGroup(bounds);
3032  render_groups_column.push_back(rg);
3033  }
3034  LOG(INFO) << "load_table_binary_columnar_polys: Done";
3035  } else {
3036  // render groups all zero
3037  render_groups_column.resize(bounds_column.size(), 0);
3038  }
3039 
3040  // Populate physical columns, advance col_idx
3042  cd,
3043  import_buffers,
3044  col_idx,
3045  coords_column,
3046  bounds_column,
3047  ring_sizes_column,
3048  poly_rings_column,
3049  render_groups_column);
3050 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
std::unordered_map< std::string, RenderGroupAssignmentColumnMap > RenderGroupAssignmentTableMap
Definition: DBHandler.h:1080
std::mutex render_group_assignment_mutex_
Definition: DBHandler.h:1084
#define LOG(tag)
Definition: Logger.h:285
static void set_geo_physical_import_buffer_columnar(const Catalog_Namespace::Catalog &catalog, const ColumnDescriptor *cd, std::vector< std::unique_ptr< TypedImportBuffer >> &import_buffers, size_t &col_idx, std::vector< std::vector< double >> &coords_column, std::vector< std::vector< double >> &bounds_column, std::vector< std::vector< int >> &ring_sizes_column, std::vector< std::vector< int >> &poly_rings_column, std::vector< int > &render_groups_column)
Definition: Importer.cpp:1732
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:381
#define LOG_IF(severity, condition)
Definition: Logger.h:383
bool g_enable_assign_render_groups
static bool getGeoColumns(const std::string &wkt_or_wkb_hex, SQLTypeInfo &ti, std::vector< double > &coords, std::vector< double > &bounds, std::vector< int > &ring_sizes, std::vector< int > &poly_rings, const bool promote_poly_to_mpoly=false)
Definition: Types.cpp:1079
#define CHECK(condition)
Definition: Logger.h:291
RenderGroupAnalyzerSessionMap render_group_assignment_map_
Definition: DBHandler.h:1083
SQLTypeInfo columnType
std::unordered_map< std::string, std::unique_ptr< import_export::RenderGroupAnalyzer >> RenderGroupAssignmentColumnMap
Definition: DBHandler.h:1078
std::string columnName
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:136
#define IS_GEO_POLY(T)
Definition: sqltypes.h:305

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void DBHandler::fillMissingBuffers ( const TSessionId &  session,
const Catalog_Namespace::Catalog catalog,
std::vector< std::unique_ptr< import_export::TypedImportBuffer >> &  import_buffers,
const std::list< const ColumnDescriptor * > &  cds,
const std::vector< int > &  desc_id_to_column_id,
size_t  num_rows,
const std::string &  table_name,
bool  assign_render_groups 
)
private

Definition at line 3052 of file DBHandler.cpp.

References CHECK, and fillGeoColumns().

Referenced by load_table(), load_table_binary(), load_table_binary_arrow(), and loadTableBinaryColumnarInternal().

3060  {
3061  size_t skip_physical_cols = 0;
3062  size_t col_idx = 0, import_idx = 0;
3063  for (const auto& cd : cds) {
3064  if (skip_physical_cols > 0) {
3065  CHECK(cd->isGeoPhyCol);
3066  skip_physical_cols--;
3067  continue;
3068  } else if (cd->columnType.is_geometry()) {
3069  skip_physical_cols = cd->columnType.get_physical_cols();
3070  }
3071  if (desc_id_to_column_id[import_idx] == -1) {
3072  import_buffers[col_idx]->addDefaultValues(cd, num_rows);
3073  col_idx++;
3074  if (cd->columnType.is_geometry()) {
3075  fillGeoColumns(session_id,
3076  catalog,
3077  import_buffers,
3078  cd,
3079  col_idx,
3080  num_rows,
3081  table_name,
3082  assign_render_groups);
3083  }
3084  } else {
3085  col_idx++;
3086  col_idx += skip_physical_cols;
3087  }
3088  import_idx++;
3089  }
3090 }
void fillGeoColumns(const TSessionId &session, const Catalog_Namespace::Catalog &catalog, std::vector< std::unique_ptr< import_export::TypedImportBuffer >> &import_buffers, const ColumnDescriptor *cd, size_t &col_idx, size_t num_rows, const std::string &table_name, bool assign_render_groups)
Definition: DBHandler.cpp:2957
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Catalog_Namespace::SessionInfoPtr DBHandler::findCalciteSession ( TSessionId const &  session_id) const
private

Definition at line 5900 of file DBHandler.cpp.

References calcite_sessions_, and calcite_sessions_mtx_.

Referenced by get_session_ptr().

5901  {
5903  auto const itr = calcite_sessions_.find(session_id);
5904  return itr == calcite_sessions_.end() ? nullptr : itr->second;
5905 }
std::lock_guard< T > lock_guard
std::unordered_map< std::string, Catalog_Namespace::SessionInfoPtr > calcite_sessions_
Definition: DBHandler.h:946
heavyai::shared_mutex calcite_sessions_mtx_
Definition: DBHandler.h:947

+ Here is the caller graph for this function:

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

Definition at line 6158 of file DBHandler.cpp.

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

Referenced by get_table_details_impl(), and sql_validate().

6159  {
6160  TRowDescriptor fixedup_row_desc;
6161  for (const TColumnType& col_desc : row_desc) {
6162  auto fixedup_col_desc = col_desc;
6163  if (col_desc.col_type.encoding == TEncodingType::DICT &&
6164  col_desc.col_type.comp_param > 0) {
6165  const auto dd = cat.getMetadataForDict(col_desc.col_type.comp_param, false);
6166  fixedup_col_desc.col_type.comp_param = dd->dictNBits;
6167  }
6168  fixedup_row_desc.push_back(fixedup_col_desc);
6169  }
6170 
6171  return fixedup_row_desc;
6172 }
const DictDescriptor * getMetadataForDict(int dict_ref, bool loadDict=true) const
Definition: Catalog.cpp:1999

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 2130 of file DBHandler.cpp.

References get_session_ptr(), getAllRolesForUserImpl(), heavyai::RequestInfo::requestId(), heavyai::RequestInfo::sessionId(), SET_REQUEST_ID, and STDLOG.

2132  {
2133  heavyai::RequestInfo const request_info(session_id_or_json);
2134  SET_REQUEST_ID(request_info.requestId());
2135  auto stdlog = STDLOG(get_session_ptr(request_info.sessionId()));
2136  auto session_ptr = stdlog.getConstSessionInfo();
2137  getAllRolesForUserImpl(session_ptr, roles, granteeName, /*effective=*/true);
2138 }
void getAllRolesForUserImpl(std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr, std::vector< std::string > &roles, const std::string &granteeName, bool effective)
Definition: DBHandler.cpp:2085
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5935
#define SET_REQUEST_ID(parent_request_id)
Definition: DBHandler.cpp:130
#define STDLOG(...)
Definition: QueryState.h:234

+ Here is the call graph for this function:

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

Definition at line 5756 of file DBHandler.cpp.

References anonymous_namespace{DBHandler.cpp}::add_vsi_archive_prefix(), anonymous_namespace{DBHandler.cpp}::add_vsi_network_prefix(), import_export::Importer::gdalFileExists(), import_export::Importer::gdalGetAllFilesInArchive(), get_session_ptr(), getConnectionInfo(), import_path_, anonymous_namespace{DBHandler.cpp}::is_a_supported_archive_file(), anonymous_namespace{DBHandler.cpp}::path_is_relative(), heavyai::RequestInfo::requestId(), heavyai::RequestInfo::sessionId(), SET_REQUEST_ID, STDLOG, thrift_to_copyparams(), THROW_DB_EXCEPTION, toString(), and anonymous_namespace{DBHandler.cpp}::validate_import_file_path_if_local().

5759  {
5760  heavyai::RequestInfo const request_info(session_id_or_json);
5761  SET_REQUEST_ID(request_info.requestId());
5762  auto stdlog = STDLOG(get_session_ptr(request_info.sessionId()),
5763  "get_all_files_in_archive",
5764  archive_path_in);
5765  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
5766 
5767  std::string archive_path(archive_path_in);
5768  if (path_is_relative(archive_path)) {
5769  // assume relative paths are relative to data_path / import / <session>
5770  auto file_path = import_path_ /
5771  picosha2::hash256_hex_string(request_info.sessionId()) /
5772  boost::filesystem::path(archive_path).filename();
5773  archive_path = file_path.string();
5774  }
5775  validate_import_file_path_if_local(archive_path);
5776 
5777  if (is_a_supported_archive_file(archive_path)) {
5778  // find the archive file
5779  add_vsi_network_prefix(archive_path);
5780  if (!import_export::Importer::gdalFileExists(archive_path,
5781  thrift_to_copyparams(copy_params))) {
5782  THROW_DB_EXCEPTION("Archive does not exist: " + archive_path_in);
5783  }
5784  // find all files in archive
5785  add_vsi_archive_prefix(archive_path);
5787  archive_path, thrift_to_copyparams(copy_params));
5788  // prepend them all with original path
5789  for (auto& s : _return) {
5790  s = archive_path_in + '/' + s;
5791  }
5792  }
5793 }
boost::filesystem::path import_path_
Definition: DBHandler.h:633
void add_vsi_archive_prefix(std::string &path)
Definition: DBHandler.cpp:4001
bool is_a_supported_archive_file(const std::string &path)
Definition: DBHandler.cpp:4067
bool path_is_relative(const std::string &path)
Definition: DBHandler.cpp:4035
static bool gdalFileExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:5153
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5935
void validate_import_file_path_if_local(const std::string &file_path)
Definition: DBHandler.cpp:4121
#define SET_REQUEST_ID(parent_request_id)
Definition: DBHandler.cpp:130
std::string toString(const ExecutorDeviceType &device_type)
void add_vsi_network_prefix(std::string &path)
Definition: DBHandler.cpp:3972
static std::vector< std::string > gdalGetAllFilesInArchive(const std::string &archive_path, const CopyParams &copy_params)
Definition: Importer.cpp:5230
import_export::CopyParams thrift_to_copyparams(const TCopyParams &cp)
Definition: DBHandler.cpp:3645
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1649
#define STDLOG(...)
Definition: QueryState.h:234
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:136

+ Here is the call graph for this function:

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

Definition at line 2118 of file DBHandler.cpp.

References get_session_ptr(), getAllRolesForUserImpl(), heavyai::RequestInfo::requestId(), heavyai::RequestInfo::sessionId(), SET_REQUEST_ID, and STDLOG.

2120  {
2121  // WARNING: This function only returns directly granted roles.
2122  // See also: get_all_effective_roles_for_user() for all of a user's roles.
2123  heavyai::RequestInfo const request_info(session_id_or_json);
2124  SET_REQUEST_ID(request_info.requestId());
2125  auto stdlog = STDLOG(get_session_ptr(request_info.sessionId()));
2126  auto session_ptr = stdlog.getConstSessionInfo();
2127  getAllRolesForUserImpl(session_ptr, roles, granteeName, /*effective=*/false);
2128 }
void getAllRolesForUserImpl(std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr, std::vector< std::string > &roles, const std::string &granteeName, bool effective)
Definition: DBHandler.cpp:2085
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5935
#define SET_REQUEST_ID(parent_request_id)
Definition: DBHandler.cpp:130
#define STDLOG(...)
Definition: QueryState.h:234

+ Here is the call graph for this function:

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

Definition at line 1520 of file DBHandler.cpp.

References anonymous_namespace{DBHandler.cpp}::extract_projection_tokens_for_completion(), get_completion_hints_unsorted(), get_session_ptr(), get_uc_compatible_table_names_by_column(), heavyai::RequestInfo::requestId(), heavyai::RequestInfo::sessionId(), SET_REQUEST_ID, gpu_enabled::sort(), STDLOG, and to_upper().

1523  {
1524  heavyai::RequestInfo const request_info(session_id_or_json);
1525  SET_REQUEST_ID(request_info.requestId());
1526  auto stdlog = STDLOG(get_session_ptr(request_info.sessionId()));
1527  std::vector<std::string> visible_tables; // Tables allowed for the given session.
1528  get_completion_hints_unsorted(hints, visible_tables, stdlog, sql, cursor);
1529  const auto proj_tokens = extract_projection_tokens_for_completion(sql);
1530  auto compatible_table_names = get_uc_compatible_table_names_by_column(
1531  proj_tokens.uc_column_names, visible_tables, stdlog);
1532  // Add the table qualifiers explicitly specified by the user.
1533  compatible_table_names.insert(proj_tokens.uc_column_table_qualifiers.begin(),
1534  proj_tokens.uc_column_table_qualifiers.end());
1535  // Sort the hints by category, from COLUMN (most specific) to KEYWORD.
1536  std::sort(
1537  hints.begin(),
1538  hints.end(),
1539  [&compatible_table_names](const TCompletionHint& lhs, const TCompletionHint& rhs) {
1540  if (lhs.type == TCompletionHintType::TABLE &&
1541  rhs.type == TCompletionHintType::TABLE) {
1542  // Between two tables, one which is compatible with the specified
1543  // projections and one which isn't, pick the one which is compatible.
1544  if (compatible_table_names.find(to_upper(lhs.hints.back())) !=
1545  compatible_table_names.end() &&
1546  compatible_table_names.find(to_upper(rhs.hints.back())) ==
1547  compatible_table_names.end()) {
1548  return true;
1549  }
1550  }
1551  return lhs.type < rhs.type;
1552  });
1553 }
DEVICE void sort(ARGS &&...args)
Definition: gpu_enabled.h:105
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5935
ProjectionTokensForCompletion extract_projection_tokens_for_completion(const std::string &sql)
Definition: DBHandler.cpp:1496
void get_completion_hints_unsorted(std::vector< TCompletionHint > &hints, std::vector< std::string > &visible_tables, query_state::StdLog &stdlog, const std::string &sql, const int cursor)
Definition: DBHandler.cpp:1555
#define SET_REQUEST_ID(parent_request_id)
Definition: DBHandler.cpp:130
std::string to_upper(const std::string &str)
std::unordered_set< std::string > get_uc_compatible_table_names_by_column(const std::unordered_set< std::string > &uc_column_names, std::vector< std::string > &table_names, query_state::StdLog &stdlog)
Definition: DBHandler.cpp:1654
#define STDLOG(...)
Definition: QueryState.h:234

+ Here is the call graph for this function:

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

Definition at line 1555 of file DBHandler.cpp.

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

Referenced by get_completion_hints().

1559  {
1560  const auto& session_info = *stdlog.getConstSessionInfo();
1561  try {
1562  get_tables_impl(visible_tables, session_info, GET_PHYSICAL_TABLES_AND_VIEWS);
1563 
1564  // Filter out keywords suggested by Calcite which we don't support.
1566  calcite_->getCompletionHints(session_info, visible_tables, sql, cursor));
1567  } catch (const std::exception& e) {
1568  TDBException ex;
1569  ex.error_msg = std::string(e.what());
1570  LOG(ERROR) << ex.error_msg;
1571  throw ex;
1572  }
1573  boost::regex from_expr{R"(\s+from\s+)", boost::regex::extended | boost::regex::icase};
1574  const size_t length_to_cursor =
1575  cursor < 0 ? sql.size() : std::min(sql.size(), static_cast<size_t>(cursor));
1576  // Trust hints from Calcite after the FROM keyword.
1577  if (boost::regex_search(sql.cbegin(), sql.cbegin() + length_to_cursor, from_expr)) {
1578  return;
1579  }
1580  // Before FROM, the query is too incomplete for context-sensitive completions.
1581  get_token_based_completions(hints, stdlog, visible_tables, sql, cursor);
1582 }
#define LOG(tag)
Definition: Logger.h:285
std::vector< TCompletionHint > just_whitelisted_keyword_hints(const std::vector< TCompletionHint > &hints)
void get_tables_impl(std::vector< std::string > &table_names, const Catalog_Namespace::SessionInfo &, const GetTablesType get_tables_type, const std::string &database_name={})
Definition: DBHandler.cpp:2515
void get_token_based_completions(std::vector< TCompletionHint > &hints, query_state::StdLog &stdlog, std::vector< std::string > &visible_tables, const std::string &sql, const int cursor)
Definition: DBHandler.cpp:1584
std::shared_ptr< Calcite > calcite_
Definition: DBHandler.h:652
std::shared_ptr< Catalog_Namespace::SessionInfo const > getConstSessionInfo() const
Definition: QueryState.cpp:150

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 4434 of file DBHandler.cpp.

References anonymous_namespace{DBHandler.cpp}::create_thrift_obj_from_custom_expr(), custom_expressions_mutex_, get_session_ptr(), getConnectionInfo(), heavyai::RequestInfo::requestId(), heavyai::RequestInfo::sessionId(), SET_REQUEST_ID, STDLOG, and toString().

4435  {
4436  heavyai::RequestInfo const request_info(session_id_or_json);
4437  SET_REQUEST_ID(request_info.requestId());
4438  auto stdlog = STDLOG(get_session_ptr(request_info.sessionId()));
4439  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
4440 
4441  auto session_ptr = stdlog.getConstSessionInfo();
4442  auto& catalog = session_ptr->getCatalog();
4444  auto custom_expressions =
4445  catalog.getCustomExpressionsForUser(session_ptr->get_currentUser());
4446  for (const auto& custom_expression : custom_expressions) {
4447  _return.emplace_back(create_thrift_obj_from_custom_expr(*custom_expression, catalog));
4448  }
4449 }
heavyai::shared_lock< heavyai::shared_mutex > read_lock
std::shared_lock< T > shared_lock
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5935
#define SET_REQUEST_ID(parent_request_id)
Definition: DBHandler.cpp:130
std::string toString(const ExecutorDeviceType &device_type)
heavyai::shared_mutex custom_expressions_mutex_
Definition: DBHandler.h:1085
TCustomExpression create_thrift_obj_from_custom_expr(const CustomExpression &custom_expr, const Catalog &catalog)
Definition: DBHandler.cpp:4392
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1649
#define STDLOG(...)
Definition: QueryState.h:234

+ Here is the call graph for this function:

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

Definition at line 4489 of file DBHandler.cpp.

References cat(), get_dashboard_impl(), get_session_ptr(), getConnectionInfo(), is_allowed_on_dashboard(), heavyai::RequestInfo::requestId(), heavyai::RequestInfo::sessionId(), SET_REQUEST_ID, STDLOG, THROW_DB_EXCEPTION, to_string(), toString(), Catalog_Namespace::UserMetadata::userName, and AccessPrivileges::VIEW_DASHBOARD.

4491  {
4492  heavyai::RequestInfo const request_info(session_id_or_json);
4493  SET_REQUEST_ID(request_info.requestId());
4494  auto stdlog = STDLOG(get_session_ptr(request_info.sessionId()));
4495  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
4496  auto session_ptr = stdlog.getConstSessionInfo();
4497  auto const& cat = session_ptr->getCatalog();
4499  auto dash = cat.getMetadataForDashboard(dashboard_id);
4500  if (!dash) {
4501  THROW_DB_EXCEPTION("Dashboard with dashboard id " + std::to_string(dashboard_id) +
4502  " doesn't exist");
4503  }
4505  *session_ptr, dash->dashboardId, AccessPrivileges::VIEW_DASHBOARD)) {
4506  THROW_DB_EXCEPTION("User has no view privileges for the dashboard with id " +
4507  std::to_string(dashboard_id));
4508  }
4509  user_meta.userName = "";
4510  SysCatalog::instance().getMetadataForUserById(dash->userId, user_meta);
4511  dashboard = get_dashboard_impl(session_ptr, user_meta, dash);
4512 }
static const AccessPrivileges VIEW_DASHBOARD
Definition: DBObject.h:171
std::string cat(Ts &&...args)
std::string to_string(char const *&&v)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5935
#define SET_REQUEST_ID(parent_request_id)
Definition: DBHandler.cpp:130
TDashboard get_dashboard_impl(const std::shared_ptr< Catalog_Namespace::SessionInfo const > &session_ptr, Catalog_Namespace::UserMetadata &user_meta, const DashboardDescriptor *dash, const bool populate_state=true)
Definition: DBHandler.cpp:4536
std::string toString(const ExecutorDeviceType &device_type)
static bool is_allowed_on_dashboard(const Catalog_Namespace::SessionInfo &session_info, int32_t dashboard_id, AccessPrivileges requestedPermissions)
Definition: DBHandler.cpp:4356
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1649
#define STDLOG(...)
Definition: QueryState.h:234
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:136

+ Here is the call graph for this function:

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

Definition at line 4881 of file DBHandler.cpp.

References cat(), DashboardPrivileges::CREATE_DASHBOARD, DashboardDBObjectType, DashboardPrivileges::DELETE_DASHBOARD, DashboardPrivileges::EDIT_DASHBOARD, get_session_ptr(), getConnectionInfo(), heavyai::RequestInfo::requestId(), heavyai::RequestInfo::sessionId(), SET_REQUEST_ID, STDLOG, THROW_DB_EXCEPTION, to_string(), toString(), Catalog_Namespace::UserMetadata::userId, Catalog_Namespace::UserMetadata::userName, and DashboardPrivileges::VIEW_DASHBOARD.

4884  {
4885  heavyai::RequestInfo const request_info(session_id_or_json);
4886  SET_REQUEST_ID(request_info.requestId());
4887  auto stdlog = STDLOG(get_session_ptr(request_info.sessionId()));
4888  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
4889  auto session_ptr = stdlog.getConstSessionInfo();
4890  auto const& cat = session_ptr->getCatalog();
4892  auto dash = cat.getMetadataForDashboard(dashboard_id);
4893  if (!dash) {
4894  THROW_DB_EXCEPTION("Dashboard id " + std::to_string(dashboard_id) +
4895  " does not exist");
4896  } else if (session_ptr->get_currentUser().userId != dash->userId &&
4897  !session_ptr->get_currentUser().isSuper) {
4899  "User should be either owner of dashboard or super user to access grantees");
4900  }
4901  std::vector<ObjectRoleDescriptor*> objectsList;
4902  objectsList = SysCatalog::instance().getMetadataForObject(
4903  cat.getCurrentDB().dbId,
4904  static_cast<int>(DBObjectType::DashboardDBObjectType),
4905  dashboard_id); // By default objecttypecan be only dashabaords
4906  user_meta.userId = -1;
4907  user_meta.userName = "";
4908  SysCatalog::instance().getMetadataForUserById(dash->userId, user_meta);
4909  for (auto object : objectsList) {
4910  if (user_meta.userName == object->roleName) {
4911  // Mask owner
4912  continue;
4913  }
4914  TDashboardGrantees grantee;
4915  TDashboardPermissions perm;
4916  grantee.name = object->roleName;
4917  grantee.is_user = object->roleType;
4918  perm.create_ = object->privs.hasPermission(DashboardPrivileges::CREATE_DASHBOARD);
4919  perm.delete_ = object->privs.hasPermission(DashboardPrivileges::DELETE_DASHBOARD);
4920  perm.edit_ = object->privs.hasPermission(DashboardPrivileges::EDIT_DASHBOARD);
4921  perm.view_ = object->privs.hasPermission(DashboardPrivileges::VIEW_DASHBOARD);
4922  grantee.permissions = perm;
4923  dashboard_grantees.push_back(grantee);
4924  }
4925 }
std::string cat(Ts &&...args)
std::string to_string(char const *&&v)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5935
#define SET_REQUEST_ID(parent_request_id)
Definition: DBHandler.cpp:130
std::string toString(const ExecutorDeviceType &device_type)
static const int32_t EDIT_DASHBOARD
Definition: DBObject.h:104
static const int32_t DELETE_DASHBOARD
Definition: DBObject.h:102
static const int32_t VIEW_DASHBOARD
Definition: DBObject.h:103
static const int32_t CREATE_DASHBOARD
Definition: DBObject.h:101
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1649
#define STDLOG(...)
Definition: QueryState.h:234
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:136

+ Here is the call graph for this function:

TDashboard DBHandler::get_dashboard_impl ( const std::shared_ptr< Catalog_Namespace::SessionInfo const > &  session_ptr,
Catalog_Namespace::UserMetadata user_meta,
const DashboardDescriptor dash,
const bool  populate_state = true 
)
private

Definition at line 4536 of file DBHandler.cpp.

References cat(), DashboardPrivileges::CREATE_DASHBOARD, DashboardDBObjectType, DashboardDescriptor::dashboardId, DashboardDescriptor::dashboardMetadata, DashboardDescriptor::dashboardName, DashboardDescriptor::dashboardState, DashboardPrivileges::DELETE_DASHBOARD, DashboardPrivileges::EDIT_DASHBOARD, DBObject::getPrivileges(), AccessPrivileges::hasPermission(), DashboardDescriptor::imageHash, DashboardDescriptor::updateTime, DashboardDescriptor::user, DashboardDescriptor::userId, Catalog_Namespace::UserMetadata::userName, and DashboardPrivileges::VIEW_DASHBOARD.

Referenced by get_dashboard(), and get_dashboards().

4540  {
4541  auto const& cat = session_ptr->getCatalog();
4542  SysCatalog::instance().getMetadataForUserById(dash->userId, user_meta);
4543  auto objects_list = SysCatalog::instance().getMetadataForObject(
4544  cat.getCurrentDB().dbId,
4545  static_cast<int>(DBObjectType::DashboardDBObjectType),
4546  dash->dashboardId);
4547  TDashboard dashboard;
4548  dashboard.dashboard_name = dash->dashboardName;
4549  if (populate_state) {
4550  dashboard.dashboard_state = dash->dashboardState;
4551  }
4552  dashboard.image_hash = dash->imageHash;
4553  dashboard.update_time = dash->updateTime;
4554  dashboard.dashboard_metadata = dash->dashboardMetadata;
4555  dashboard.dashboard_id = dash->dashboardId;
4556  dashboard.dashboard_owner = dash->user;
4557  TDashboardPermissions perms;
4558  // Super user has all permissions.
4559  if (session_ptr->get_currentUser().isSuper) {
4560  perms.create_ = true;
4561  perms.delete_ = true;
4562  perms.edit_ = true;
4563  perms.view_ = true;
4564  } else {
4565  // Collect all grants on current user
4566  // add them to the permissions.
4567  auto obj_to_find =
4568  DBObject(dashboard.dashboard_id, DBObjectType::DashboardDBObjectType);
4569  obj_to_find.loadKey(cat);
4570  std::vector<std::string> grantees =
4571  SysCatalog::instance().getRoles(true,
4572  session_ptr->get_currentUser().isSuper,
4573  session_ptr->get_currentUser().userName);
4574  for (const auto& grantee : grantees) {
4575  DBObject* object_found;
4576  auto* gr = SysCatalog::instance().getGrantee(grantee);
4577  if (gr && (object_found = gr->findDbObject(obj_to_find.getObjectKey(), true))) {
4578  const auto obj_privs = object_found->getPrivileges();
4579  perms.create_ |= obj_privs.hasPermission(DashboardPrivileges::CREATE_DASHBOARD);
4580  perms.delete_ |= obj_privs.hasPermission(DashboardPrivileges::DELETE_DASHBOARD);
4581  perms.edit_ |= obj_privs.hasPermission(DashboardPrivileges::EDIT_DASHBOARD);
4582  perms.view_ |= obj_privs.hasPermission(DashboardPrivileges::VIEW_DASHBOARD);
4583  }
4584  }
4585  }
4586  dashboard.dashboard_permissions = perms;
4587  if (objects_list.empty() ||
4588  (objects_list.size() == 1 && objects_list[0]->roleName == user_meta.userName)) {
4589  dashboard.is_dash_shared = false;
4590  } else {
4591  dashboard.is_dash_shared = true;
4592  }
4593  return dashboard;
4594 }
std::string cat(Ts &&...args)
static const int32_t EDIT_DASHBOARD
Definition: DBObject.h:104
static const int32_t DELETE_DASHBOARD
Definition: DBObject.h:102
const AccessPrivileges & getPrivileges() const
Definition: DBObject.h:226
static const int32_t VIEW_DASHBOARD
Definition: DBObject.h:103
static const int32_t CREATE_DASHBOARD
Definition: DBObject.h:101
bool hasPermission(int permission) const
Definition: DBObject.h:141

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 4514 of file DBHandler.cpp.

References cat(), get_dashboard_impl(), get_session_ptr(), getConnectionInfo(), is_allowed_on_dashboard(), heavyai::RequestInfo::requestId(), heavyai::RequestInfo::sessionId(), SET_REQUEST_ID, STDLOG, toString(), Catalog_Namespace::UserMetadata::userName, and AccessPrivileges::VIEW_DASHBOARD.

4515  {
4516  heavyai::RequestInfo const request_info(session_id_or_json);
4517  SET_REQUEST_ID(request_info.requestId());
4518  auto stdlog = STDLOG(get_session_ptr(request_info.sessionId()));
4519  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
4520  auto session_ptr = stdlog.getConstSessionInfo();
4521  auto const& cat = session_ptr->getCatalog();
4523  const auto dashes = cat.getAllDashboardsMetadata();
4524  user_meta.userName = "";
4525  for (const auto dash : dashes) {
4527  *session_ptr, dash->dashboardId, AccessPrivileges::VIEW_DASHBOARD)) {
4528  // dashboardState is intentionally not populated here
4529  // for payload reasons
4530  // use get_dashboard call to get state
4531  dashboards.push_back(get_dashboard_impl(session_ptr, user_meta, dash, false));
4532  }
4533  }
4534 }
static const AccessPrivileges VIEW_DASHBOARD
Definition: DBObject.h:171
std::string cat(Ts &&...args)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5935
#define SET_REQUEST_ID(parent_request_id)
Definition: DBHandler.cpp:130
TDashboard get_dashboard_impl(const std::shared_ptr< Catalog_Namespace::SessionInfo const > &session_ptr, Catalog_Namespace::UserMetadata &user_meta, const DashboardDescriptor *dash, const bool populate_state=true)
Definition: DBHandler.cpp:4536
std::string toString(const ExecutorDeviceType &device_type)
static bool is_allowed_on_dashboard(const Catalog_Namespace::SessionInfo &session_info, int32_t dashboard_id, AccessPrivileges requestedPermissions)
Definition: DBHandler.cpp:4356
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1649
#define STDLOG(...)
Definition: QueryState.h:234

+ Here is the call graph for this function:

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

Definition at line 2844 of file DBHandler.cpp.

References get_session_ptr(), getConnectionInfo(), heavyai::RequestInfo::requestId(), heavyai::RequestInfo::sessionId(), SET_REQUEST_ID, STDLOG, and toString().

2845  {
2846  heavyai::RequestInfo const request_info(session_id_or_json);
2847  SET_REQUEST_ID(request_info.requestId());
2848  auto stdlog = STDLOG(get_session_ptr(request_info.sessionId()));
2849  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
2850  auto session_ptr = stdlog.getConstSessionInfo();
2851  const auto& user = session_ptr->get_currentUser();
2853  SysCatalog::instance().getDatabaseListForUser(user);
2854  for (auto& db : dbs) {
2855  TDBInfo dbinfo;
2856  dbinfo.db_name = std::move(db.dbName);
2857  dbinfo.db_owner = std::move(db.dbOwnerName);
2858  dbinfos.push_back(std::move(dbinfo));
2859  }
2860 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5935
#define SET_REQUEST_ID(parent_request_id)
Definition: DBHandler.cpp:130
std::string toString(const ExecutorDeviceType &device_type)
std::list< DBSummary > DBSummaryList
Definition: SysCatalog.h:145
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1649
#define STDLOG(...)
Definition: QueryState.h:234

+ Here is the call graph for this function:

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

Definition at line 1999 of file DBHandler.cpp.

References AccessPrivileges::ALL_TABLE, cat(), DashboardDBObjectType, DatabaseDBObjectType, get_session_ptr(), DBObject::getObjectKey(), DBObject::loadKey(), heavyai::RequestInfo::requestId(), serialize_db_object(), ServerDBObjectType, heavyai::RequestInfo::sessionId(), SET_REQUEST_ID, STDLOG, TableDBObjectType, THROW_DB_EXCEPTION, to_string(), and ViewDBObjectType.

2002  {
2003  heavyai::RequestInfo const request_info(session_id_or_json);
2004  SET_REQUEST_ID(request_info.requestId());
2005  auto session_ptr = get_session_ptr(request_info.sessionId());
2006  auto stdlog = STDLOG(session_ptr);
2007  const auto& cat = session_ptr->getCatalog();
2008  DBObjectType object_type;
2009  switch (type) {
2011  object_type = DBObjectType::DatabaseDBObjectType;
2012  break;
2014  object_type = DBObjectType::TableDBObjectType;
2015  break;
2018  break;
2020  object_type = DBObjectType::ViewDBObjectType;
2021  break;
2023  object_type = DBObjectType::ServerDBObjectType;
2024  break;
2025  default:
2026  THROW_DB_EXCEPTION("Failed to get object privileges for " + objectName +
2027  ": unknown object type (" + std::to_string(type) + ").");
2028  }
2029  DBObject object_to_find(objectName, object_type);
2030 
2031  // TODO(adb): Use DatabaseLock to protect method
2032  try {
2033  if (object_type == DashboardDBObjectType) {
2034  if (objectName == "") {
2035  object_to_find = DBObject(-1, object_type);
2036  } else {
2037  object_to_find = DBObject(std::stoi(objectName), object_type);
2038  }
2039  } else if ((object_type == TableDBObjectType || object_type == ViewDBObjectType) &&
2040  !objectName.empty()) {
2041  // special handling for view / table
2042  auto td = cat.getMetadataForTable(objectName, false);
2043  if (td) {
2044  object_type = td->isView ? ViewDBObjectType : TableDBObjectType;
2045  object_to_find = DBObject(objectName, object_type);
2046  }
2047  }
2048  object_to_find.loadKey(cat);
2049  } catch (const std::exception&) {
2050  THROW_DB_EXCEPTION("Object with name " + objectName + " does not exist.");
2051  }
2052 
2053  // object type on database level
2054  DBObject object_to_find_dblevel("", object_type);
2055  object_to_find_dblevel.loadKey(cat);
2056  // if user is superuser respond with a full priv
2057  if (session_ptr->get_currentUser().isSuper) {
2058  // using ALL_TABLE here to set max permissions
2059  DBObject dbObj{object_to_find.getObjectKey(),
2061  session_ptr->get_currentUser().userId};
2062  dbObj.setName("super");
2063  TDBObjects.push_back(
2064  serialize_db_object(session_ptr->get_currentUser().userName, dbObj));
2065  };
2066 
2067  std::vector<std::string> grantees =
2068  SysCatalog::instance().getRoles(true,
2069  session_ptr->get_currentUser().isSuper,
2070  session_ptr->get_currentUser().userName);
2071  for (const auto& grantee : grantees) {
2072  DBObject* object_found;
2073  auto* gr = SysCatalog::instance().getGrantee(grantee);
2074  if (gr && (object_found = gr->findDbObject(object_to_find.getObjectKey(), true))) {
2075  TDBObjects.push_back(serialize_db_object(grantee, *object_found));
2076  }
2077  // check object permissions on Database level
2078  if (gr &&
2079  (object_found = gr->findDbObject(object_to_find_dblevel.getObjectKey(), true))) {
2080  TDBObjects.push_back(serialize_db_object(grantee, *object_found));
2081  }
2082  }
2083 }
std::string cat(Ts &&...args)
DBObjectKey getObjectKey() const
Definition: DBObject.h:221
DBObjectType
Definition: DBObject.h:40
std::string to_string(char const *&&v)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5935
#define SET_REQUEST_ID(parent_request_id)
Definition: DBHandler.cpp:130
static TDBObject serialize_db_object(const std::string &roleName, const DBObject &inObject)
Definition: DBHandler.cpp:1756
static const AccessPrivileges ALL_TABLE
Definition: DBObject.h:157
#define STDLOG(...)
Definition: QueryState.h:234
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:136

+ Here is the call graph for this function:

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

Definition at line 1970 of file DBHandler.cpp.

References get_session_ptr(), heavyai::RequestInfo::requestId(), serialize_db_object(), heavyai::RequestInfo::sessionId(), SET_REQUEST_ID, STDLOG, and THROW_DB_EXCEPTION.

1972  {
1973  heavyai::RequestInfo const request_info(session_id_or_json);
1974  SET_REQUEST_ID(request_info.requestId());
1975  auto session_ptr = get_session_ptr(request_info.sessionId());
1976  auto stdlog = STDLOG(session_ptr);
1977  auto const& user = session_ptr->get_currentUser();
1978  if (!user.isSuper &&
1979  !SysCatalog::instance().isRoleGrantedToGrantee(user.userName, roleName, false)) {
1980  return;
1981  }
1982  auto* rl = SysCatalog::instance().getGrantee(roleName);
1983  if (rl) {
1984  auto dbId = session_ptr->getCatalog().getCurrentDB().dbId;
1985  for (auto& dbObject : *rl->getDbObjects(true)) {
1986  if (dbObject.first.dbId != dbId) {
1987  // TODO (max): it doesn't scale well in case we have many DBs (not a typical
1988  // usecase for now, though)
1989  continue;
1990  }
1991  TDBObject tdbObject = serialize_db_object(roleName, *dbObject.second);
1992  TDBObjectsForRole.push_back(tdbObject);
1993  }
1994  } else {
1995  THROW_DB_EXCEPTION("User or role " + roleName + " does not exist.");
1996  }
1997 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5935
#define SET_REQUEST_ID(parent_request_id)
Definition: DBHandler.cpp:130
static TDBObject serialize_db_object(const std::string &roleName, const DBObject &inObject)
Definition: DBHandler.cpp:1756
#define STDLOG(...)
Definition: QueryState.h:234
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:136

+ Here is the call graph for this function:

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

Definition at line 7392 of file DBHandler.cpp.

References cpu_mode_only_, EXPOSE_THRIFT_MAP, get_session_ptr(), getConnectionInfo(), heavyai::RequestInfo::requestId(), heavyai::RequestInfo::sessionId(), SET_REQUEST_ID, STDLOG, and toString().

7393  {
7394  heavyai::RequestInfo const request_info(session_id_or_json);
7395  SET_REQUEST_ID(request_info.requestId());
7396  auto stdlog = STDLOG(get_session_ptr(request_info.sessionId()));
7397  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
7398  auto params = ::get_device_parameters(cpu_mode_only_);
7399  for (auto item : params) {
7400  _return.insert(item);
7401  }
7402  EXPOSE_THRIFT_MAP(TDeviceType);
7403  EXPOSE_THRIFT_MAP(TDatumType);
7404  EXPOSE_THRIFT_MAP(TEncodingType);
7405  EXPOSE_THRIFT_MAP(TExtArgumentType);
7406  EXPOSE_THRIFT_MAP(TOutputBufferSizeType);
7407 }
#define EXPOSE_THRIFT_MAP(TYPENAME)
Definition: DBHandler.cpp:7381
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5935
#define SET_REQUEST_ID(parent_request_id)
Definition: DBHandler.cpp:130
std::string toString(const ExecutorDeviceType &device_type)
void get_device_parameters(std::map< std::string, std::string > &_return, const TSessionId &session) override
Definition: DBHandler.cpp:7392
bool cpu_mode_only_
Definition: DBHandler.h:642
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1649
#define STDLOG(...)
Definition: QueryState.h:234

+ Here is the call graph for this function:

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

Definition at line 5709 of file DBHandler.cpp.

References anonymous_namespace{DBHandler.cpp}::add_vsi_archive_prefix(), anonymous_namespace{DBHandler.cpp}::add_vsi_network_prefix(), anonymous_namespace{DBHandler.cpp}::find_first_geo_file_in_archive(), import_export::Importer::gdalFileExists(), get_session_ptr(), getConnectionInfo(), import_path_, anonymous_namespace{DBHandler.cpp}::is_a_supported_archive_file(), anonymous_namespace{DBHandler.cpp}::path_is_relative(), heavyai::RequestInfo::requestId(), heavyai::RequestInfo::sessionId(), SET_REQUEST_ID, STDLOG, thrift_to_copyparams(), THROW_DB_EXCEPTION, toString(), and anonymous_namespace{DBHandler.cpp}::validate_import_file_path_if_local().

5712  {
5713  heavyai::RequestInfo const request_info(session_id_or_json);
5714  SET_REQUEST_ID(request_info.requestId());
5715  auto stdlog = STDLOG(get_session_ptr(request_info.sessionId()),
5716  "get_first_geo_file_in_archive",
5717  archive_path_in);
5718  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
5719 
5720  std::string archive_path(archive_path_in);
5721 
5722  if (path_is_relative(archive_path)) {
5723  // assume relative paths are relative to data_path / import / <session>
5724  auto file_path = import_path_ /
5725  picosha2::hash256_hex_string(request_info.sessionId()) /
5726  boost::filesystem::path(archive_path).filename();
5727  archive_path = file_path.string();
5728  }
5729  validate_import_file_path_if_local(archive_path);
5730 
5731  if (is_a_supported_archive_file(archive_path)) {
5732  // find the archive file
5733  add_vsi_network_prefix(archive_path);
5734  if (!import_export::Importer::gdalFileExists(archive_path,
5735  thrift_to_copyparams(copy_params))) {
5736  THROW_DB_EXCEPTION("Archive does not exist: " + archive_path_in);
5737  }
5738  // find geo file in archive
5739  add_vsi_archive_prefix(archive_path);
5740  std::string geo_file =
5741  find_first_geo_file_in_archive(archive_path, thrift_to_copyparams(copy_params));
5742  // what did we get?
5743  if (geo_file.size()) {
5744  // prepend it with the original path
5745  _return = archive_path_in + std::string("/") + geo_file;
5746  } else {
5747  // just return the original path
5748  _return = archive_path_in;
5749  }
5750  } else {
5751  // just return the original path
5752  _return = archive_path_in;
5753  }
5754 }
boost::filesystem::path import_path_
Definition: DBHandler.h:633
void add_vsi_archive_prefix(std::string &path)
Definition: DBHandler.cpp:4001
bool is_a_supported_archive_file(const std::string &path)
Definition: DBHandler.cpp:4067
bool path_is_relative(const std::string &path)
Definition: DBHandler.cpp:4035
static bool gdalFileExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:5153
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5935
void validate_import_file_path_if_local(const std::string &file_path)
Definition: DBHandler.cpp:4121
#define SET_REQUEST_ID(parent_request_id)
Definition: DBHandler.cpp:130
std::string toString(const ExecutorDeviceType &device_type)
std::string find_first_geo_file_in_archive(const std::string &archive_path, const import_export::CopyParams &copy_params)
Definition: DBHandler.cpp:4080
void add_vsi_network_prefix(std::string &path)
Definition: DBHandler.cpp:3972
import_export::CopyParams thrift_to_copyparams(const TCopyParams &cp)
Definition: DBHandler.cpp:3645
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1649
#define STDLOG(...)
Definition: QueryState.h:234
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:136

+ Here is the call graph for this function:

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

Definition at line 7512 of file DBHandler.cpp.

References ExtensionFunctionsWhitelist::get_ext_funcs(), and ThriftSerializers::to_thrift().

7514  {
7515  for (const std::string& udf_name : udf_names) {
7516  for (auto udf : ExtensionFunctionsWhitelist::get_ext_funcs(udf_name)) {
7517  _return.emplace_back(ThriftSerializers::to_thrift(udf));
7518  }
7519  }
7520 }
static std::vector< ExtensionFunction > get_ext_funcs(const std::string &name)
TExtArgumentType::type to_thrift(const ExtArgumentType &t)

+ Here is the call graph for this function:

void DBHandler::get_function_names ( std::vector< std::string > &  _return,