OmniSciDB  ca0c39ec8f
 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 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 &query_ra, 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
 
template<typename... ARGS>
std::shared_ptr
< query_state::QueryState
create_query_state (ARGS &&...args)
 
Catalog_Namespace::SessionInfo get_session_copy (const TSessionId &session)
 
void get_tables_meta_impl (std::vector< TTableMeta > &_return, QueryStateProxy query_state_proxy, const Catalog_Namespace::SessionInfo &session_info, const bool with_table_locks=true)
 
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 TSessionId &session, const std::string &table_name)
 
void check_table_load_privileges (const Catalog_Namespace::SessionInfo &session_info, const std::string &table_name)
 
void get_tables_impl (std::vector< std::string > &table_names, const Catalog_Namespace::SessionInfo &, const GetTablesType get_tables_type, 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 TSessionId &sessionId, 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)
 
TQueryResult validate_rel_alg (const std::string &query_ra, QueryStateProxy)
 
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)
 
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)
 

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::unique_ptr
< Catalog_Namespace::SessionsStore
sessions_store_
 
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 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_
 
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 1066 of file DBHandler.h.

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

Definition at line 1062 of file DBHandler.h.

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

Definition at line 1064 of file DBHandler.h.

Member Enumeration Documentation

Enumerator
kNone 
kAssign 
kCleanUp 

Definition at line 1049 of file DBHandler.h.

1049 { 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  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 157 of file DBHandler.cpp.

189  : leaf_aggregator_(db_leaves)
190  , db_leaves_(db_leaves)
191  , string_leaves_(string_leaves)
192  , base_data_path_(base_data_path)
193  , random_gen_(std::random_device{}())
194  , session_id_dist_(0, INT32_MAX)
195  , jit_debug_(jit_debug)
196  , intel_jit_profile_(intel_jit_profile)
197  , allow_multifrag_(allow_multifrag)
198  , read_only_(read_only)
199  , allow_loop_joins_(allow_loop_joins)
200  , authMetadata_(authMetadata)
201  , system_parameters_(system_parameters)
202  , legacy_syntax_(legacy_syntax)
203  , dispatch_queue_(
204  std::make_unique<QueryDispatchQueue>(system_parameters.num_executors))
206  base_data_path,
207  1,
208  idle_session_duration * 60,
209  max_session_duration * 60,
210  system_parameters.num_sessions,
211  [this](auto& session_ptr) { disconnect_impl(session_ptr); }))
std::vector< LeafHostInfo > string_leaves_
Definition: DBHandler.h:627
std::unique_ptr< QueryDispatchQueue > dispatch_queue_
Definition: DBHandler.h:651
LeafAggregator leaf_aggregator_
Definition: DBHandler.h:625
const std::string base_data_path_
Definition: DBHandler.h:628
const bool jit_debug_
Definition: DBHandler.h:633
void disconnect_impl(Catalog_Namespace::SessionInfoPtr &session_ptr)
Definition: DBHandler.cpp:559
std::vector< LeafHostInfo > db_leaves_
Definition: DBHandler.h:626
SystemParameters & system_parameters_
Definition: DBHandler.h:643
static std::unique_ptr< SessionsStore > create(const std::string &base_path, size_t n_workers, int idle_session_duration, int max_session_duration, int capacity, DisconnectCallback disconnect_callback)
const bool allow_loop_joins_
Definition: DBHandler.h:637
const bool intel_jit_profile_
Definition: DBHandler.h:634
std::unique_ptr< Catalog_Namespace::SessionsStore > sessions_store_
Definition: DBHandler.h:934
const bool read_only_
Definition: DBHandler.h:636
const bool legacy_syntax_
Definition: DBHandler.h:649
bool allow_multifrag_
Definition: DBHandler.h:635
const AuthMetadata & authMetadata_
Definition: DBHandler.h:642
std::default_random_engine random_gen_
Definition: DBHandler.h:631
std::uniform_int_distribution< int64_t > session_id_dist_
Definition: DBHandler.h:632
DBHandler::~DBHandler ( )
override

Definition at line 408 of file DBHandler.cpp.

References shutdown().

408  {
409  shutdown();
410 }
void shutdown()
Definition: DBHandler.cpp:7049

+ 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 7535 of file DBHandler.cpp.

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

Referenced by executeDdl().

7538  {
7539  result = ExecutionResult();
7540  if (session_parameter.first == "EXECUTOR_DEVICE") {
7541  std::string parameter_value = to_upper(session_parameter.second);
7542  TExecuteMode::type executorType;
7543  if (parameter_value == "GPU") {
7544  executorType = TExecuteMode::type::GPU;
7545  } else if (parameter_value == "CPU") {
7546  executorType = TExecuteMode::type::CPU;
7547  } else {
7548  throw std::runtime_error("Cannot set the " + session_parameter.first + " to " +
7549  session_parameter.second +
7550  ". Valid options are CPU and GPU");
7551  }
7552  execution_time_ms =
7553  measure<>::execution([&]() { set_execution_mode(session_id, executorType); });
7554  } else if (session_parameter.first == "CURRENT_DATABASE") {
7555  execution_time_ms = measure<>::execution(
7556  [&]() { switch_database(session_id, session_parameter.second); });
7557  }
7558 }
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:2749
std::string to_upper(const std::string &str)
void switch_database(const TSessionId &session, const std::string &dbname) override
Definition: DBHandler.cpp:584

+ 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 7519 of file DBHandler.cpp.

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

Referenced by executeDdl().

7522  {
7523  result = ExecutionResult();
7524  if (to_upper(cache_type) == "CPU") {
7525  execution_time_ms = measure<>::execution([&]() { clear_cpu_memory(session_id); });
7526  } else if (to_upper(cache_type) == "GPU") {
7527  execution_time_ms = measure<>::execution([&]() { clear_gpu_memory(session_id); });
7528  } else if (to_upper(cache_type) == "RENDER") {
7529  execution_time_ms = measure<>::execution([&]() { clearRenderMemory(session_id); });
7530  } else {
7531  throw std::runtime_error("Invalid cache type. Valid values are CPU,GPU or RENDER");
7532  }
7533 }
void clearRenderMemory(const TSessionId &session)
Definition: DBHandler.cpp:2634
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:2600
void clear_cpu_memory(const TSessionId &session) override
Definition: DBHandler.cpp:2617

+ 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 6616 of file DBHandler.cpp.

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

6620  {
6621  if (!leaf_handler_) {
6622  THROW_DB_EXCEPTION("Distributed support is disabled.");
6623  }
6624  LOG(INFO) << "BROADCAST-SERIALIZED-ROWS id:" << query_id;
6625  auto time_ms = measure<>::execution([&]() {
6626  try {
6627  leaf_handler_->broadcast_serialized_rows(
6628  serialized_rows, row_desc, query_id, subquery_id, is_final_subquery_result);
6629  } catch (std::exception& e) {
6630  THROW_DB_EXCEPTION(e.what());
6631  }
6632  });
6633  LOG(INFO) << "BROADCAST-SERIALIZED-ROWS COMPLETED " << time_ms << "ms";
6634 }
static TimeT::rep execution(F func, Args &&...args)
Definition: sample.cpp:29
#define LOG(tag)
Definition: Logger.h:216
std::unique_ptr< HeavyDBLeafHandler > leaf_handler_
Definition: DBHandler.h:647
QueryId query_id()
Definition: Logger.cpp:473
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:128

+ Here is the call graph for this function:

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

Definition at line 6009 of file DBHandler.cpp.

References sessions_store_.

6009  {
6010  if (const auto drop_db_stmt = dynamic_cast<Parser::DropDBStmt*>(ddl)) {
6011  sessions_store_->eraseByDB(*drop_db_stmt->getDatabaseName());
6012  } else if (const auto rename_db_stmt = dynamic_cast<Parser::RenameDBStmt*>(ddl)) {
6013  sessions_store_->eraseByDB(*rename_db_stmt->getPreviousDatabaseName());
6014  } else if (const auto drop_user_stmt = dynamic_cast<Parser::DropUserStmt*>(ddl)) {
6015  sessions_store_->eraseByUser(*drop_user_stmt->getUserName());
6016  } else if (const auto rename_user_stmt = dynamic_cast<Parser::RenameUserStmt*>(ddl)) {
6017  sessions_store_->eraseByUser(*rename_user_stmt->getOldUserName());
6018  }
6019 }
std::unique_ptr< Catalog_Namespace::SessionsStore > sessions_store_
Definition: DBHandler.h:934
void DBHandler::check_geospatial_files ( const boost::filesystem::path  file_path,
const import_export::CopyParams copy_params 
)
private

Definition at line 4780 of file DBHandler.cpp.

References import_export::Importer::gdalFileExists().

Referenced by detect_column_types(), and importGeoTableSingle().

4781  {
4782  const std::list<std::string> shp_ext{".shp", ".shx", ".dbf"};
4783  if (std::find(shp_ext.begin(),
4784  shp_ext.end(),
4785  boost::algorithm::to_lower_copy(file_path.extension().string())) !=
4786  shp_ext.end()) {
4787  for (auto ext : shp_ext) {
4788  auto aux_file = file_path;
4790  aux_file.replace_extension(boost::algorithm::to_upper_copy(ext)).string(),
4791  copy_params) &&
4793  aux_file.replace_extension(ext).string(), copy_params)) {
4794  throw std::runtime_error("required file for shapefile does not exist: " +
4795  aux_file.filename().string());
4796  }
4797  }
4798  }
4799 }
static bool gdalFileExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:5139

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

412  {
413  if (DBHandler::read_only_) {
414  THROW_DB_EXCEPTION(str + " disabled: server running in read-only mode.");
415  }
416 }
const bool read_only_
Definition: DBHandler.h:636
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:128

+ 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 6553 of file DBHandler.cpp.

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

6555  {
6556  auto stdlog = STDLOG(get_session_ptr(session));
6557  if (!leaf_handler_) {
6558  THROW_DB_EXCEPTION("Distributed support is disabled.");
6559  }
6560  try {
6561  leaf_handler_->check_table_consistency(_return, session, table_id);
6562  } catch (std::exception& e) {
6563  THROW_DB_EXCEPTION(e.what());
6564  }
6565 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5692
std::unique_ptr< HeavyDBLeafHandler > leaf_handler_
Definition: DBHandler.h:647
#define STDLOG(...)
Definition: QueryState.h:235
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:128

+ Here is the call graph for this function:

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

Definition at line 5735 of file DBHandler.cpp.

References get_session_copy().

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

5736  {
5737  check_table_load_privileges(get_session_copy(session), table_name);
5738 }
void check_table_load_privileges(const TSessionId &session, const std::string &table_name)
Definition: DBHandler.cpp:5735
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
Definition: DBHandler.cpp:5681

+ Here is the call graph for this function:

+ Here is the caller 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 5718 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.

5720  {
5721  auto user_metadata = session_info.get_currentUser();
5722  auto& cat = session_info.getCatalog();
5723  DBObject dbObject(table_name, TableDBObjectType);
5724  dbObject.loadKey(cat);
5725  dbObject.setPrivileges(AccessPrivileges::INSERT_INTO_TABLE);
5726  std::vector<DBObject> privObjects;
5727  privObjects.push_back(dbObject);
5728  if (!SysCatalog::instance().checkPrivileges(user_metadata, privObjects)) {
5729  THROW_DB_EXCEPTION("Violation of access privileges: user " +
5730  user_metadata.userLoggable() +
5731  " has no insert privileges for table " + table_name + ".");
5732  }
5733 }
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:128

+ Here is the call graph for this function:

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

Definition at line 6850 of file DBHandler.cpp.

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

6850  {
6851  auto stdlog = STDLOG(get_session_ptr(session));
6852  auto session_ptr = stdlog.getConstSessionInfo();
6853  auto& cat = session_ptr->getCatalog();
6854  cat.checkpoint(table_id);
6855 }
std::string cat(Ts &&...args)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5692
#define STDLOG(...)
Definition: QueryState.h:235

+ Here is the call graph for this function:

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

Definition at line 2617 of file DBHandler.cpp.

References Executor::clearMemory(), Data_Namespace::CPU_LEVEL, get_session_ptr(), getConnectionInfo(), render_handler_, STDLOG, THROW_DB_EXCEPTION, and toString().

Referenced by alterSystemClear().

2617  {
2618  auto stdlog = STDLOG(get_session_ptr(session));
2619  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
2620  auto session_ptr = stdlog.getConstSessionInfo();
2621  if (!session_ptr->get_currentUser().isSuper) {
2622  THROW_DB_EXCEPTION("Superuser privilege is required to run clear_cpu_memory");
2623  }
2624  try {
2626  } catch (const std::exception& e) {
2627  THROW_DB_EXCEPTION(e.what());
2628  }
2629  if (render_handler_) {
2630  render_handler_->clear_cpu_memory();
2631  }
2632 }
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64
static void clearMemory(const Data_Namespace::MemoryLevel memory_level)
Definition: Execute.cpp:501
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5692
std::unique_ptr< RenderHandler > render_handler_
Definition: DBHandler.h:645
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1587
#define STDLOG(...)
Definition: QueryState.h:235
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:128

+ 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 2600 of file DBHandler.cpp.

References Executor::clearMemory(), get_session_ptr(), getConnectionInfo(), Data_Namespace::GPU_LEVEL, render_handler_, STDLOG, THROW_DB_EXCEPTION, and toString().

Referenced by alterSystemClear().

2600  {
2601  auto stdlog = STDLOG(get_session_ptr(session));
2602  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
2603  auto session_ptr = stdlog.getConstSessionInfo();
2604  if (!session_ptr->get_currentUser().isSuper) {
2605  THROW_DB_EXCEPTION("Superuser privilege is required to run clear_gpu_memory");
2606  }
2607  try {
2609  } catch (const std::exception& e) {
2610  THROW_DB_EXCEPTION(e.what());
2611  }
2612  if (render_handler_) {
2613  render_handler_->clear_gpu_memory();
2614  }
2615 }
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64
static void clearMemory(const Data_Namespace::MemoryLevel memory_level)
Definition: Execute.cpp:501
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5692
std::unique_ptr< RenderHandler > render_handler_
Definition: DBHandler.h:645
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1587
#define STDLOG(...)
Definition: QueryState.h:235
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:128

+ 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 2634 of file DBHandler.cpp.

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

Referenced by alterSystemClear().

2634  {
2635  auto stdlog = STDLOG(get_session_ptr(session));
2636  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
2637  auto session_ptr = stdlog.getConstSessionInfo();
2638  if (!session_ptr->get_currentUser().isSuper) {
2639  THROW_DB_EXCEPTION("Superuser privilege is required to run clear_render_memory");
2640  }
2641  if (render_handler_) {
2642  render_handler_->clear_cpu_memory();
2643  render_handler_->clear_gpu_memory();
2644  }
2645 }
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5692
std::unique_ptr< RenderHandler > render_handler_
Definition: DBHandler.h:645
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1587
#define STDLOG(...)
Definition: QueryState.h:235
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:128

+ 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 602 of file DBHandler.cpp.

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

602  {
603  auto session1_ptr = get_session_ptr(session1);
604  auto stdlog = STDLOG(session1_ptr);
605  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
606 
607  try {
608  const Catalog_Namespace::UserMetadata& user_meta = session1_ptr->get_currentUser();
609  std::shared_ptr<Catalog> cat = session1_ptr->get_catalog_ptr();
610  auto session2_ptr = sessions_store_->add(user_meta, cat, executor_device_type_);
611  session2 = session2_ptr->get_session_id();
612  LOG(INFO) << "User " << user_meta.userLoggable() << " connected to database "
613  << cat->name();
614  if (leaf_aggregator_.leafCount() > 0) {
615  leaf_aggregator_.clone_session(session1, session2);
616  return;
617  }
618  } catch (std::exception& e) {
619  THROW_DB_EXCEPTION(e.what());
620  }
621 }
std::string cat(Ts &&...args)
void clone_session(const TSessionId session1, const TSessionId session2)
#define LOG(tag)
Definition: Logger.h:216
LeafAggregator leaf_aggregator_
Definition: DBHandler.h:625
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64
ExecutorDeviceType executor_device_type_
Definition: DBHandler.h:630
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5692
size_t leafCount() const
std::unique_ptr< Catalog_Namespace::SessionsStore > sessions_store_
Definition: DBHandler.h:934
std::string userLoggable() const
Definition: SysCatalog.cpp:128
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1587
#define STDLOG(...)
Definition: QueryState.h:235
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:128

+ 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 491 of file DBHandler.cpp.

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

494  {
495  auto stdlog = STDLOG(); // session_info set by connect_impl()
496  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
497  std::string username2 = username; // login() may reset username given as argument
498  std::string dbname2 = dbname; // login() may reset dbname given as argument
500  std::shared_ptr<Catalog> cat = nullptr;
501  try {
502  cat = SysCatalog::instance().login(
503  dbname2, username2, passwd, user_meta, !super_user_rights_);
504  } catch (std::exception& e) {
505  stdlog.appendNameValuePairs("user", username, "db", dbname, "exception", e.what());
506  THROW_DB_EXCEPTION(e.what());
507  }
508 
509  DBObject dbObject(dbname2, DatabaseDBObjectType);
510  dbObject.loadKey(*cat);
511  dbObject.setPrivileges(AccessPrivileges::ACCESS);
512  std::vector<DBObject> dbObjects;
513  dbObjects.push_back(dbObject);
514  if (!SysCatalog::instance().checkPrivileges(user_meta, dbObjects)) {
515  stdlog.appendNameValuePairs(
516  "user", username, "db", dbname, "exception", "Missing Privileges");
517  THROW_DB_EXCEPTION("Unauthorized Access: user " + user_meta.userLoggable() +
518  " is not allowed to access database " + dbname2 + ".");
519  }
520  connect_impl(session, passwd, dbname2, user_meta, cat, stdlog);
521 
522  // if pki auth session will come back encrypted with user pubkey
523  SysCatalog::instance().check_for_session_encryption(passwd, session);
524 }
std::string cat(Ts &&...args)
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64
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:526
bool super_user_rights_
Definition: DBHandler.h:938
static const AccessPrivileges ACCESS
Definition: DBObject.h:153
std::string userLoggable() const
Definition: SysCatalog.cpp:128
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1587
#define STDLOG(...)
Definition: QueryState.h:235
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:128

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

531  {
532  // TODO(sy): Is there any reason to have dbname as a parameter
533  // here when the cat parameter already provides cat->name()?
534  // Should dbname and cat->name() ever differ?
535  auto session_ptr = sessions_store_->add(user_meta, cat, executor_device_type_);
536  session = session_ptr->get_session_id();
537  LOG(INFO) << "User " << user_meta.userLoggable() << " connected to database " << dbname;
538  stdlog.setSessionInfo(session_ptr);
539  session_ptr->set_connection_info(getConnectionInfo().toString());
540  if (!super_user_rights_) { // no need to connect to leaf_aggregator_ at this time
541  // while doing warmup
542  }
543  auto const roles =
544  stdlog.getConstSessionInfo()->get_currentUser().isSuper
545  ? std::vector<std::string>{{"super"}}
546  : SysCatalog::instance().getRoles(
547  false, false, stdlog.getConstSessionInfo()->get_currentUser().userName);
548  stdlog.appendNameValuePairs("roles", boost::algorithm::join(roles, ","));
549 }
std::string cat(Ts &&...args)
#define LOG(tag)
Definition: Logger.h:216
std::string join(T const &container, std::string const &delim)
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64
void setSessionInfo(std::shared_ptr< Catalog_Namespace::SessionInfo >)
Definition: QueryState.cpp:286
ExecutorDeviceType executor_device_type_
Definition: DBHandler.h:630
void appendNameValuePairs(Pairs &&...pairs)
Definition: QueryState.h:313
bool super_user_rights_
Definition: DBHandler.h:938
std::unique_ptr< Catalog_Namespace::SessionsStore > sessions_store_
Definition: DBHandler.h:934
std::shared_ptr< Catalog_Namespace::SessionInfo const > getConstSessionInfo() const
Definition: QueryState.cpp:159
std::string userLoggable() const
Definition: SysCatalog.cpp:128
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1587

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

1062  {
1063  _return.execution_time_ms += result.getExecutionTime();
1064  if (result.empty()) {
1065  return;
1066  }
1067 
1068  switch (result.getResultType()) {
1070  convertRows(_return,
1071  query_state_proxy,
1072  result.getTargetsMeta(),
1073  *result.getRows(),
1074  column_format,
1075  first_n,
1076  at_most_n);
1077  break;
1079  convertResult(_return, *result.getRows(), true);
1080  break;
1082  convertExplain(_return, *result.getRows(), true);
1083  break;
1085  convertRows(_return,
1086  query_state_proxy,
1087  result.getTargetsMeta(),
1088  *result.getRows(),
1089  column_format,
1090  -1,
1091  -1);
1092  break;
1093  }
1094 }
RType getResultType() const
static void convertExplain(TQueryResult &_return, const ResultSet &results, const bool column_format)
Definition: DBHandler.cpp:5981
static void convertResult(TQueryResult &_return, const ResultSet &results, const bool column_format)
Definition: DBHandler.cpp:5987
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:5873
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 5981 of file DBHandler.cpp.

References createSimpleResult().

Referenced by convertData().

5983  {
5984  createSimpleResult(_return, results, column_format, "Explanation");
5985 }
static void createSimpleResult(TQueryResult &_return, const ResultSet &results, const bool column_format, const std::string label)
Definition: DBHandler.cpp:5944

+ 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 5987 of file DBHandler.cpp.

References createSimpleResult().

Referenced by convertData().

5989  {
5990  createSimpleResult(_return, results, column_format, "Result");
5991 }
static void createSimpleResult(TQueryResult &_return, const ResultSet &results, const bool column_format, const std::string label)
Definition: DBHandler.cpp:5944

+ 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 7238 of file DBHandler.cpp.

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

Referenced by executeDdl().

7241  {
7242  // Stuff ResultSet into _return (which is a TQueryResult)
7243  // calls convertRows, but after some setup using session_info
7244 
7245  auto session_ptr = get_session_ptr(session_info.get_session_id());
7246  CHECK(session_ptr);
7247  auto qs = create_query_state(session_ptr, query_state_str);
7248  QueryStateProxy qsp = qs->createQueryStateProxy();
7249 
7250  // heavysql only accepts column format as being 'VALID",
7251  // assume that heavydb should only return column format
7252  int32_t nRows = result.getDataPtr()->rowCount();
7253 
7254  convertData(_return,
7255  result,
7256  qsp,
7257  /*column_format=*/true,
7258  /*first_n=*/nRows,
7259  /*at_most_n=*/nRows);
7260 }
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:1057
std::shared_ptr< query_state::QueryState > create_query_state(ARGS &&...args)
Definition: DBHandler.h:654
const ResultSetPtr & getDataPtr() const
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5692
std::string get_session_id() const
Definition: SessionInfo.h:93
#define CHECK(condition)
Definition: Logger.h:222

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

5879  {
5880  query_state::Timer timer = query_state_proxy.createTimer(__func__);
5881  _return.row_set.row_desc = ThriftSerializers::target_meta_infos_to_thrift(targets);
5882  int32_t fetched{0};
5883  if (column_format) {
5884  _return.row_set.is_columnar = true;
5885  std::vector<TColumn> tcolumns(results.colCount());
5886  while (first_n == -1 || fetched < first_n) {
5887  const auto crt_row = results.getNextRow(true, true);
5888  if (crt_row.empty()) {
5889  break;
5890  }
5891  ++fetched;
5892  if (at_most_n >= 0 && fetched > at_most_n) {
5893  THROW_DB_EXCEPTION("The result contains more rows than the specified cap of " +
5894  std::to_string(at_most_n));
5895  }
5896  for (size_t i = 0; i < results.colCount(); ++i) {
5897  const auto agg_result = crt_row[i];
5898  value_to_thrift_column(agg_result, targets[i].get_type_info(), tcolumns[i]);
5899  }
5900  }
5901  for (size_t i = 0; i < results.colCount(); ++i) {
5902  _return.row_set.columns.push_back(tcolumns[i]);
5903  }
5904  } else {
5905  _return.row_set.is_columnar = false;
5906  while (first_n == -1 || fetched < first_n) {
5907  const auto crt_row = results.getNextRow(true, true);
5908  if (crt_row.empty()) {
5909  break;
5910  }
5911  ++fetched;
5912  if (at_most_n >= 0 && fetched > at_most_n) {
5913  THROW_DB_EXCEPTION("The result contains more rows than the specified cap of " +
5914  std::to_string(at_most_n));
5915  }
5916  TRow trow;
5917  trow.cols.reserve(results.colCount());
5918  for (size_t i = 0; i < results.colCount(); ++i) {
5919  const auto agg_result = crt_row[i];
5920  trow.cols.push_back(value_to_thrift(agg_result, targets[i].get_type_info()));
5921  }
5922  _return.row_set.rows.push_back(trow);
5923  }
5924  }
5925 }
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:789
Timer createTimer(char const *event_name)
Definition: QueryState.cpp:138
std::string to_string(char const *&&v)
static TDatum value_to_thrift(const TargetValue &tv, const SQLTypeInfo &ti)
Definition: DBHandler.cpp:912
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:128

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

3696  {
3697  TCopyParams copy_params;
3698  copy_params.delimiter = cp.delimiter;
3699  copy_params.null_str = cp.null_str;
3700  switch (cp.has_header) {
3702  copy_params.has_header = TImportHeaderRow::AUTODETECT;
3703  break;
3705  copy_params.has_header = TImportHeaderRow::NO_HEADER;
3706  break;
3708  copy_params.has_header = TImportHeaderRow::HAS_HEADER;
3709  break;
3710  default:
3711  CHECK(false);
3712  }
3713  copy_params.quoted = cp.quoted;
3714  copy_params.quote = cp.quote;
3715  copy_params.escape = cp.escape;
3716  copy_params.line_delim = cp.line_delim;
3717  copy_params.array_delim = cp.array_delim;
3718  copy_params.array_begin = cp.array_begin;
3719  copy_params.array_end = cp.array_end;
3720  copy_params.threads = cp.threads;
3721  copy_params.s3_access_key = cp.s3_access_key;
3722  copy_params.s3_secret_key = cp.s3_secret_key;
3723  copy_params.s3_session_token = cp.s3_session_token;
3724  copy_params.s3_region = cp.s3_region;
3725  copy_params.s3_endpoint = cp.s3_endpoint;
3726  switch (cp.source_type) {
3728  copy_params.source_type = TSourceType::DELIMITED_FILE;
3729  break;
3731  copy_params.source_type = TSourceType::GEO_FILE;
3732  break;
3734  copy_params.source_type = TSourceType::PARQUET_FILE;
3735  break;
3737  copy_params.source_type = TSourceType::RASTER_FILE;
3738  break;
3740  copy_params.source_type = TSourceType::ODBC;
3741  break;
3742  default:
3743  CHECK(false);
3744  }
3745  switch (cp.geo_coords_encoding) {
3746  case kENCODING_GEOINT:
3747  copy_params.geo_coords_encoding = TEncodingType::GEOINT;
3748  break;
3749  default:
3750  copy_params.geo_coords_encoding = TEncodingType::NONE;
3751  break;
3752  }
3753  copy_params.geo_coords_comp_param = cp.geo_coords_comp_param;
3754  switch (cp.geo_coords_type) {
3755  case kGEOGRAPHY:
3756  copy_params.geo_coords_type = TDatumType::GEOGRAPHY;
3757  break;
3758  case kGEOMETRY:
3759  copy_params.geo_coords_type = TDatumType::GEOMETRY;
3760  break;
3761  default:
3762  CHECK(false);
3763  }
3764  copy_params.geo_coords_srid = cp.geo_coords_srid;
3765  copy_params.sanitize_column_names = cp.sanitize_column_names;
3766  copy_params.geo_layer_name = cp.geo_layer_name;
3767  copy_params.geo_assign_render_groups = cp.geo_assign_render_groups;
3768  copy_params.geo_explode_collections = cp.geo_explode_collections;
3769  copy_params.source_srid = cp.source_srid;
3770  switch (cp.raster_point_type) {
3772  copy_params.raster_point_type = TRasterPointType::NONE;
3773  break;
3775  copy_params.raster_point_type = TRasterPointType::AUTO;
3776  break;
3778  copy_params.raster_point_type = TRasterPointType::SMALLINT;
3779  break;
3781  copy_params.raster_point_type = TRasterPointType::INT;
3782  break;
3784  copy_params.raster_point_type = TRasterPointType::FLOAT;
3785  break;
3787  copy_params.raster_point_type = TRasterPointType::DOUBLE;
3788  break;
3790  copy_params.raster_point_type = TRasterPointType::POINT;
3791  break;
3792  default:
3793  CHECK(false);
3794  }
3795  copy_params.raster_import_bands = cp.raster_import_bands;
3796  copy_params.raster_scanlines_per_thread = cp.raster_scanlines_per_thread;
3797  switch (cp.raster_point_transform) {
3799  copy_params.raster_point_transform = TRasterPointTransform::NONE;
3800  break;
3802  copy_params.raster_point_transform = TRasterPointTransform::AUTO;
3803  break;
3805  copy_params.raster_point_transform = TRasterPointTransform::FILE;
3806  break;
3808  copy_params.raster_point_transform = TRasterPointTransform::WORLD;
3809  break;
3810  default:
3811  CHECK(false);
3812  }
3813  copy_params.raster_point_compute_angle = cp.raster_point_compute_angle;
3814  copy_params.raster_import_dimensions = cp.raster_import_dimensions;
3815  copy_params.odbc_dsn = cp.dsn;
3816  copy_params.odbc_connection_string = cp.connection_string;
3817  copy_params.odbc_sql_select = cp.sql_select;
3818  copy_params.odbc_sql_order_by = cp.sql_order_by;
3819  copy_params.odbc_username = cp.username;
3820  copy_params.odbc_password = cp.password;
3821  copy_params.odbc_credential_string = cp.credential_string;
3822  copy_params.add_metadata_columns = cp.add_metadata_columns;
3823  copy_params.trim_spaces = cp.trim_spaces;
3824  return copy_params;
3825 }
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:222
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 4266 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(), STDLOG, THROW_DB_EXCEPTION, and toString().

4267  {
4268  auto stdlog = STDLOG(get_session_ptr(session));
4269  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
4270  check_read_only("create_custom_expression");
4271 
4272  auto session_ptr = stdlog.getConstSessionInfo();
4273  if (!session_ptr->get_currentUser().isSuper) {
4274  THROW_DB_EXCEPTION("Custom expressions can only be created by super users.")
4275  }
4276  auto& catalog = session_ptr->getCatalog();
4278  return catalog.createCustomExpression(
4279  create_custom_expr_from_thrift_obj(t_custom_expr, catalog));
4280 }
heavyai::unique_lock< heavyai::shared_mutex > write_lock
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5692
std::unique_lock< T > unique_lock
heavyai::shared_mutex custom_expressions_mutex_
Definition: DBHandler.h:1069
void check_read_only(const std::string &str)
Definition: DBHandler.cpp:412
std::unique_ptr< Catalog_Namespace::CustomExpression > create_custom_expr_from_thrift_obj(const TCustomExpression &t_custom_expr, const Catalog &catalog)
Definition: DBHandler.cpp:4223
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1587
#define STDLOG(...)
Definition: QueryState.h:235
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:128

+ 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 4453 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, STDLOG, THROW_DB_EXCEPTION, toString(), DashboardDescriptor::user, and DashboardDescriptor::userId.

4457  {
4458  auto stdlog = STDLOG(get_session_ptr(session));
4459  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
4460  auto session_ptr = stdlog.getConstSessionInfo();
4461  CHECK(session_ptr);
4462  check_read_only("create_dashboard");
4463  auto& cat = session_ptr->getCatalog();
4466  }
4467 
4468  if (!session_ptr->checkDBAccessPrivileges(DBObjectType::DashboardDBObjectType,
4470  THROW_DB_EXCEPTION("Not enough privileges to create a dashboard.");
4471  }
4472 
4473  if (dashboard_exists(cat, session_ptr->get_currentUser().userId, dashboard_name)) {
4474  THROW_DB_EXCEPTION("Dashboard with name: " + dashboard_name + " already exists.");
4475  }
4476 
4478  dd.dashboardName = dashboard_name;
4479  dd.dashboardState = dashboard_state;
4480  dd.imageHash = image_hash;
4481  dd.dashboardMetadata = dashboard_metadata;
4482  dd.userId = session_ptr->get_currentUser().userId;
4483  dd.user = session_ptr->get_currentUser().userName;
4484 
4485  try {
4486  auto id = cat.createDashboard(dd);
4487  // TODO: transactionally unsafe
4488  SysCatalog::instance().createDBObject(
4489  session_ptr->get_currentUser(), dashboard_name, DashboardDBObjectType, cat, id);
4490  return id;
4491  } catch (const std::exception& e) {
4492  THROW_DB_EXCEPTION(e.what());
4493  }
4494 }
std::string cat(Ts &&...args)
static const AccessPrivileges CREATE_DASHBOARD
Definition: DBObject.h:170
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64
void check_not_info_schema_db(const std::string &db_name, bool throw_db_exception)
Definition: DBHandler.cpp:4440
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5692
void check_read_only(const std::string &str)
Definition: DBHandler.cpp:412
bool g_allow_system_dashboard_update
Definition: DBHandler.cpp:121
bool dashboard_exists(const Catalog_Namespace::Catalog &cat, const int32_t user_id, const std::string &dashboard_name)
Definition: DBHandler.cpp:141
#define CHECK(condition)
Definition: Logger.h:222
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1587
#define STDLOG(...)
Definition: QueryState.h:235
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:128

+ 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 4770 of file DBHandler.cpp.

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

4772  {
4773  TColumnType ct;
4774  ct.col_name = name;
4775  ct.col_type.type = type;
4776  ct.col_type.is_array = is_array;
4777  return ct;
4778 }
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 4748 of file DBHandler.cpp.

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

4751  {
4752  auto stdlog = STDLOG(get_session_ptr(session));
4753  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
4754  auto session_ptr = stdlog.getConstSessionInfo();
4755  // check_read_only("create_link");
4756  auto& cat = session_ptr->getCatalog();
4757 
4758  LinkDescriptor ld;
4759  ld.userId = session_ptr->get_currentUser().userId;
4760  ld.viewState = view_state;
4761  ld.viewMetadata = view_metadata;
4762 
4763  try {
4764  _return = cat.createLink(ld, 6);
4765  } catch (const std::exception& e) {
4766  THROW_DB_EXCEPTION(e.what());
4767  }
4768 }
std::string cat(Ts &&...args)
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5692
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1587
#define STDLOG(...)
Definition: QueryState.h:235
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:128

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

654  {
655  return query_states_.create(std::forward<ARGS>(args)...);
656  }
CircleBuffer::value_type create(ARGS &&...args)
Definition: QueryState.h:195
query_state::QueryStates query_states_
Definition: DBHandler.h:933

+ 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 4801 of file DBHandler.cpp.

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

Referenced by importGeoTableSingle().

4804  {
4805  // @TODO(se) remove file_type which is unused
4806  auto stdlog = STDLOG("table_name", table_name);
4807  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
4808  check_read_only("create_table");
4809 
4810  if (ImportHelpers::is_reserved_name(table_name)) {
4811  THROW_DB_EXCEPTION("Invalid table name (reserved keyword): " + table_name);
4812  } else if (table_name != ImportHelpers::sanitize_name(table_name)) {
4813  THROW_DB_EXCEPTION("Invalid characters in table name: " + table_name);
4814  }
4815 
4816  auto rds = rd;
4817 
4818  std::string stmt{"CREATE TABLE " + table_name};
4819  std::vector<std::string> col_stmts;
4820 
4821  for (auto col : rds) {
4822  if (ImportHelpers::is_reserved_name(col.col_name)) {
4823  THROW_DB_EXCEPTION("Invalid column name (reserved keyword): " + col.col_name);
4824  } else if (col.col_name != ImportHelpers::sanitize_name(col.col_name)) {
4825  THROW_DB_EXCEPTION("Invalid characters in column name: " + col.col_name);
4826  }
4827  if (col.col_type.type == TDatumType::INTERVAL_DAY_TIME ||
4828  col.col_type.type == TDatumType::INTERVAL_YEAR_MONTH) {
4829  THROW_DB_EXCEPTION("Unsupported type: " + thrift_to_name(col.col_type) +
4830  " for column: " + col.col_name);
4831  }
4832 
4833  if (col.col_type.type == TDatumType::DECIMAL) {
4834  // if no precision or scale passed in set to default 14,7
4835  if (col.col_type.precision == 0 && col.col_type.scale == 0) {
4836  col.col_type.precision = 14;
4837  col.col_type.scale = 7;
4838  }
4839  }
4840 
4841  std::string col_stmt;
4842  col_stmt.append(col.col_name + " " + thrift_to_name(col.col_type));
4843  if (col.__isset.default_value) {
4844  col_stmt.append(" DEFAULT " + col.default_value);
4845  }
4846 
4847  // As of 2016-06-27 the Immerse v1 frontend does not explicitly set the
4848  // `nullable` argument, leading this to default to false. Uncomment for v2.
4849  // if (!col.col_type.nullable) col_stmt.append(" NOT NULL");
4850 
4851  if (thrift_to_encoding(col.col_type.encoding) != kENCODING_NONE) {
4852  col_stmt.append(" ENCODING " + thrift_to_encoding_name(col.col_type));
4853  if (thrift_to_encoding(col.col_type.encoding) == kENCODING_DICT ||
4854  thrift_to_encoding(col.col_type.encoding) == kENCODING_FIXED ||
4855  thrift_to_encoding(col.col_type.encoding) == kENCODING_GEOINT ||
4856  thrift_to_encoding(col.col_type.encoding) == kENCODING_DATE_IN_DAYS) {
4857  col_stmt.append("(" + std::to_string(col.col_type.comp_param) + ")");
4858  }
4859  } else if (col.col_type.type == TDatumType::STR) {
4860  // non DICT encoded strings
4861  col_stmt.append(" ENCODING NONE");
4862  } else if (col.col_type.type == TDatumType::POINT ||
4863  col.col_type.type == TDatumType::MULTIPOINT ||
4864  col.col_type.type == TDatumType::LINESTRING ||
4865  col.col_type.type == TDatumType::MULTILINESTRING ||
4866  col.col_type.type == TDatumType::POLYGON ||
4867  col.col_type.type == TDatumType::MULTIPOLYGON) {
4868  // non encoded compressable geo
4869  if (col.col_type.scale == 4326) {
4870  col_stmt.append(" ENCODING NONE");
4871  }
4872  }
4873  col_stmts.push_back(col_stmt);
4874  }
4875 
4876  stmt.append(" (" + boost::algorithm::join(col_stmts, ", ") + ")");
4877 
4878  if (create_params.is_replicated) {
4879  stmt.append(" WITH (PARTITIONS = 'REPLICATED')");
4880  }
4881 
4882  stmt.append(";");
4883 
4884  TQueryResult ret;
4885  sql_execute(ret, session, stmt, true, "", -1, -1);
4886 }
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:1173
std::string join(T const &container, std::string const &delim)
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64
std::string to_string(char const *&&v)
bool is_reserved_name(const std::string &name)
std::string sanitize_name(const std::string &name)
std::string thrift_to_encoding_name(const TTypeInfo &ti)
std::string thrift_to_name(const TTypeInfo &ti)
void check_read_only(const std::string &str)
Definition: DBHandler.cpp:412
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1587
#define STDLOG(...)
Definition: QueryState.h:235
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:128

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

419  {
420  // We would create an in memory session for calcite with super user privileges which
421  // would be used for getting all tables metadata when a user runs the query. The
422  // session would be under the name of a proxy user/password which would only persist
423  // till server's lifetime or execution of calcite query(in memory) whichever is the
424  // earliest.
426  std::string session_id;
427  do {
429  } while (calcite_sessions_.find(session_id) != calcite_sessions_.end());
430  Catalog_Namespace::UserMetadata user_meta(-1,
431  calcite_->getInternalSessionProxyUserName(),
432  calcite_->getInternalSessionProxyPassword(),
433  true,
434  -1,
435  true,
436  false);
437  const auto emplace_ret = calcite_sessions_.emplace(
438  session_id,
439  std::make_shared<Catalog_Namespace::SessionInfo>(
440  catalog_ptr, user_meta, executor_device_type_, session_id));
441  CHECK(emplace_ret.second);
442  return session_id;
443 }
std::lock_guard< T > lock_guard
std::unordered_map< std::string, Catalog_Namespace::SessionInfoPtr > calcite_sessions_
Definition: DBHandler.h:935
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:630
heavyai::shared_mutex calcite_sessions_mtx_
Definition: DBHandler.h:936
std::shared_ptr< Calcite > calcite_
Definition: DBHandler.h:648
#define CHECK(condition)
Definition: Logger.h:222

+ 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 5944 of file DBHandler.cpp.

References CHECK, CHECK_EQ, and run_benchmark_import::label.

Referenced by convertExplain(), and convertResult().

5947  {
5948  CHECK_EQ(size_t(1), results.rowCount());
5949  TColumnType proj_info;
5950  proj_info.col_name = label;
5951  proj_info.col_type.type = TDatumType::STR;
5952  proj_info.col_type.nullable = false;
5953  proj_info.col_type.is_array = false;
5954  _return.row_set.row_desc.push_back(proj_info);
5955  const auto crt_row = results.getNextRow(true, true);
5956  const auto tv = crt_row[0];
5957  CHECK(results.getNextRow(true, true).empty());
5958  const auto scalar_tv = boost::get<ScalarTargetValue>(&tv);
5959  CHECK(scalar_tv);
5960  const auto s_n = boost::get<NullableString>(scalar_tv);
5961  CHECK(s_n);
5962  const auto s = boost::get<std::string>(s_n);
5963  CHECK(s);
5964  if (column_format) {
5965  TColumn tcol;
5966  tcol.data.str_col.push_back(*s);
5967  tcol.nulls.push_back(false);
5968  _return.row_set.is_columnar = true;
5969  _return.row_set.columns.push_back(tcol);
5970  } else {
5971  TDatum explanation;
5972  explanation.val.str_val = *s;
5973  explanation.is_null = false;
5974  TRow trow;
5975  trow.cols.push_back(explanation);
5976  _return.row_set.is_columnar = false;
5977  _return.row_set.rows.push_back(trow);
5978  }
5979 }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
#define CHECK(condition)
Definition: Logger.h:222

+ 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 1359 of file DBHandler.cpp.

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

1362  {
1363  auto stdlog = STDLOG(get_session_ptr(session));
1364  std::string serialized_cuda_handle = "";
1365  if (device_type == TDeviceType::GPU) {
1366  std::lock_guard<std::mutex> map_lock(handle_to_dev_ptr_mutex_);
1367  if (ipc_handle_to_dev_ptr_.count(df.df_handle) != size_t(1)) {
1368  TDBException ex;
1369  ex.error_msg = std::string(
1370  "Current data frame handle is not bookkept or been inserted "
1371  "twice");
1372  LOG(ERROR) << ex.error_msg;
1373  throw ex;
1374  }
1375  serialized_cuda_handle = ipc_handle_to_dev_ptr_[df.df_handle];
1376  ipc_handle_to_dev_ptr_.erase(df.df_handle);
1377  }
1378  std::vector<char> sm_handle(df.sm_handle.begin(), df.sm_handle.end());
1379  std::vector<char> df_handle(df.df_handle.begin(), df.df_handle.end());
1381  sm_handle, df.sm_size, df_handle, df.df_size, serialized_cuda_handle};
1383  result,
1384  device_type == TDeviceType::CPU ? ExecutorDeviceType::CPU : ExecutorDeviceType::GPU,
1385  device_id,
1386  data_mgr_);
1387 }
std::mutex handle_to_dev_ptr_mutex_
Definition: DBHandler.h:997
#define LOG(tag)
Definition: Logger.h:216
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5692
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:623
std::unordered_map< std::string, std::string > ipc_handle_to_dev_ptr_
Definition: DBHandler.h:998
#define STDLOG(...)
Definition: QueryState.h:235

+ 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 4313 of file DBHandler.cpp.

References check_read_only(), custom_expressions_mutex_, get_session_ptr(), getConnectionInfo(), STDLOG, THROW_DB_EXCEPTION, and toString().

4316  {
4317  auto stdlog = STDLOG(get_session_ptr(session));
4318  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
4319  check_read_only("delete_custom_expressions");
4320 
4321  auto session_ptr = stdlog.getConstSessionInfo();
4322  if (!session_ptr->get_currentUser().isSuper) {
4323  THROW_DB_EXCEPTION("Custom expressions can only be deleted by super users.")
4324  }
4325  auto& catalog = session_ptr->getCatalog();
4327  catalog.deleteCustomExpressions(custom_expression_ids, do_soft_delete);
4328 }
heavyai::unique_lock< heavyai::shared_mutex > write_lock
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5692
std::unique_lock< T > unique_lock
heavyai::shared_mutex custom_expressions_mutex_
Definition: DBHandler.h:1069
void check_read_only(const std::string &str)
Definition: DBHandler.cpp:412
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1587
#define STDLOG(...)
Definition: QueryState.h:235
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:128

+ Here is the call graph for this function:

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

Definition at line 4546 of file DBHandler.cpp.

References delete_dashboards().

4546  {
4547  delete_dashboards(session, {dashboard_id});
4548 }
void delete_dashboards(const TSessionId &session, const std::vector< int32_t > &dashboard_ids) override
Definition: DBHandler.cpp:4550

+ 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 4550 of file DBHandler.cpp.

References cat(), dbhandler::check_not_info_schema_db(), check_read_only(), g_allow_system_dashboard_update, get_session_ptr(), getConnectionInfo(), STDLOG, THROW_DB_EXCEPTION, and toString().

Referenced by delete_dashboard().

4551  {
4552  auto stdlog = STDLOG(get_session_ptr(session));
4553  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
4554  auto session_ptr = stdlog.getConstSessionInfo();
4555  check_read_only("delete_dashboards");
4556  auto& cat = session_ptr->getCatalog();
4559  }
4560  // Checks will be performed in catalog
4561  try {
4562  cat.deleteMetadataForDashboards(dashboard_ids, session_ptr->get_currentUser());
4563  } catch (const std::exception& e) {
4564  THROW_DB_EXCEPTION(e.what());
4565  }
4566 }
std::string cat(Ts &&...args)
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64
void check_not_info_schema_db(const std::string &db_name, bool throw_db_exception)
Definition: DBHandler.cpp:4440
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5692
void check_read_only(const std::string &str)
Definition: DBHandler.cpp:412
bool g_allow_system_dashboard_update
Definition: DBHandler.cpp:121
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1587
#define STDLOG(...)
Definition: QueryState.h:235
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:128

+ 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 3985 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, import_export::CopyParams::sanitize_column_names, ImportHelpers::sanitize_name(), 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().

3988  {
3989  auto stdlog = STDLOG(get_session_ptr(session));
3990  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
3991  check_read_only("detect_column_types");
3992 
3993  bool is_raster = false;
3994  boost::filesystem::path file_path;
3996  if (copy_params.source_type != import_export::SourceType::kOdbc) {
3997  std::string file_name{file_name_in};
3998  if (path_is_relative(file_name)) {
3999  // assume relative paths are relative to data_path / import / <session>
4000  auto temp_file_path = import_path_ / picosha2::hash256_hex_string(session) /
4001  boost::filesystem::path(file_name).filename();
4002  file_name = temp_file_path.string();
4003  }
4005 
4006  if ((copy_params.source_type == import_export::SourceType::kGeoFile ||
4008  is_local_file(file_name)) {
4009  const shared::FilePathOptions options{copy_params.regex_path_filter,
4010  copy_params.file_sort_order_by,
4011  copy_params.file_sort_regex};
4012  auto file_paths = shared::local_glob_filter_sort_files(file_name, options, false);
4013  // For geo and raster detect, pick the first file, if multiple files are provided
4014  // (e.g. through file globbing).
4015  CHECK(!file_paths.empty());
4016  file_name = file_paths[0];
4017  }
4018 
4019  // if it's a geo or raster import, handle alternative paths (S3, HTTP, archive etc.)
4020  if (copy_params.source_type == import_export::SourceType::kGeoFile) {
4021  if (is_a_supported_archive_file(file_name)) {
4022  // find the archive file
4023  add_vsi_network_prefix(file_name);
4024  if (!import_export::Importer::gdalFileExists(file_name, copy_params)) {
4025  THROW_DB_EXCEPTION("Archive does not exist: " + file_name_in);
4026  }
4027  // find geo file in archive
4028  add_vsi_archive_prefix(file_name);
4029  std::string geo_file = find_first_geo_file_in_archive(file_name, copy_params);
4030  // prepare to detect that geo file
4031  if (geo_file.size()) {
4032  file_name = file_name + std::string("/") + geo_file;
4033  }
4034  } else {
4035  // prepare to detect geo file directly
4036  add_vsi_network_prefix(file_name);
4037  add_vsi_geo_prefix(file_name);
4038  }
4039  } else if (copy_params.source_type == import_export::SourceType::kRasterFile) {
4040  // prepare to detect raster file directly
4041  add_vsi_network_prefix(file_name);
4042  add_vsi_geo_prefix(file_name);
4043  is_raster = true;
4044  }
4045 
4046  file_path = boost::filesystem::path(file_name);
4047  // can be a s3 url
4048  if (!boost::istarts_with(file_name, "s3://")) {
4049  if (!boost::filesystem::path(file_name).is_absolute()) {
4050  file_path = import_path_ / picosha2::hash256_hex_string(session) /
4051  boost::filesystem::path(file_name).filename();
4052  file_name = file_path.string();
4053  }
4054 
4055  if (copy_params.source_type == import_export::SourceType::kGeoFile ||
4057  // check for geo or raster file
4058  if (!import_export::Importer::gdalFileOrDirectoryExists(file_name, copy_params)) {
4059  THROW_DB_EXCEPTION("File or directory \"" + file_path.string() +
4060  "\" does not exist.")
4061  }
4062  } else {
4063  // check for regular file
4064  if (!shared::file_or_glob_path_exists(file_path.string())) {
4065  THROW_DB_EXCEPTION("File or directory \"" + file_path.string() +
4066  "\" does not exist.");
4067  }
4068  }
4069  }
4070  }
4071 
4072  try {
4074 #ifdef ENABLE_IMPORT_PARQUET
4076 #endif
4077  ) {
4078  import_export::Detector detector(file_path, copy_params);
4079  auto best_types = detector.getBestColumnTypes();
4080  std::vector<std::string> headers = detector.get_headers();
4081  copy_params = detector.get_copy_params();
4082 
4083  _return.copy_params = copyparams_to_thrift(copy_params);
4084  _return.row_set.row_desc.resize(best_types.size());
4085  for (size_t col_idx = 0; col_idx < best_types.size(); col_idx++) {
4086  TColumnType col;
4087  auto& ti = best_types[col_idx];
4088  col.col_type.precision = ti.get_precision();
4089  col.col_type.scale = ti.get_scale();
4090  col.col_type.comp_param = ti.get_comp_param();
4091  if (ti.is_geometry()) {
4092  // set this so encoding_to_thrift does the right thing
4093  ti.set_compression(copy_params.geo_coords_encoding);
4094  // fill in these directly
4095  col.col_type.precision = static_cast<int>(copy_params.geo_coords_type);
4096  col.col_type.scale = copy_params.geo_coords_srid;
4097  col.col_type.comp_param = copy_params.geo_coords_comp_param;
4098  }
4099  col.col_type.type = type_to_thrift(ti);
4100  col.col_type.encoding = encoding_to_thrift(ti);
4101  if (ti.is_array()) {
4102  col.col_type.is_array = true;
4103  }
4104  if (copy_params.sanitize_column_names) {
4105  col.col_name = ImportHelpers::sanitize_name(headers[col_idx]);
4106  } else {
4107  col.col_name = headers[col_idx];
4108  }
4109  col.is_reserved_keyword = ImportHelpers::is_reserved_name(col.col_name);
4110  _return.row_set.row_desc[col_idx] = col;
4111  }
4112  auto sample_data =
4113  detector.get_sample_rows(import_export::Detector::kDefaultSampleRowsCount);
4114 
4115  TRow sample_row;
4116  for (auto row : sample_data) {
4117  sample_row.cols.clear();
4118  for (const auto& s : row) {
4119  TDatum td;
4120  td.val.str_val = s;
4121  td.is_null = s.empty();
4122  sample_row.cols.push_back(td);
4123  }
4124  _return.row_set.rows.push_back(sample_row);
4125  }
4126  } else if (copy_params.source_type == import_export::SourceType::kGeoFile ||
4128  check_geospatial_files(file_path, copy_params);
4129  std::list<ColumnDescriptor> cds = import_export::Importer::gdalToColumnDescriptors(
4130  file_path.string(), is_raster, Geospatial::kGeoColumnName, copy_params);
4131  for (auto cd : cds) {
4132  if (copy_params.sanitize_column_names) {
4133  cd.columnName = ImportHelpers::sanitize_name(cd.columnName);
4134  }
4135  _return.row_set.row_desc.push_back(populateThriftColumnType(nullptr, &cd));
4136  }
4137  if (!is_raster) {
4138  // @TODO(se) support for raster?
4139  std::map<std::string, std::vector<std::string>> sample_data;
4141  file_path.string(),
4143  sample_data,
4145  copy_params);
4146  if (sample_data.size() > 0) {
4147  for (size_t i = 0; i < sample_data.begin()->second.size(); i++) {
4148  TRow sample_row;
4149  for (auto cd : cds) {
4150  TDatum td;
4151  td.val.str_val = sample_data[cd.sourceName].at(i);
4152  td.is_null = td.val.str_val.empty();
4153  sample_row.cols.push_back(td);
4154  }
4155  _return.row_set.rows.push_back(sample_row);
4156  }
4157  }
4158  }
4159  _return.copy_params = copyparams_to_thrift(copy_params);
4160  }
4161  } catch (const std::exception& e) {
4162  THROW_DB_EXCEPTION("detect_column_types error: " + std::string(e.what()));
4163  }
4164 }
boost::filesystem::path import_path_
Definition: DBHandler.h:629
void add_vsi_archive_prefix(std::string &path)
Definition: DBHandler.cpp:3857
bool is_a_supported_archive_file(const std::string &path)
Definition: DBHandler.cpp:3923
TDatumType::type type_to_thrift(const SQLTypeInfo &type_info)
bool path_is_relative(const std::string &path)
Definition: DBHandler.cpp:3891
TCopyParams copyparams_to_thrift(const import_export::CopyParams &cp)
Definition: DBHandler.cpp:3696
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64
static bool gdalFileExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:5139
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:2112
void check_geospatial_files(const boost::filesystem::path file_path, const import_export::CopyParams &copy_params)
Definition: DBHandler.cpp:4780
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:4723
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5692
void validate_import_file_path_if_local(const std::string &file_path)
Definition: DBHandler.cpp:3977
std::string sanitize_name(const std::string &name)
import_export::SourceType source_type
Definition: CopyParams.h:57
static constexpr size_t kDefaultSampleRowsCount
Definition: Importer.h:737
static bool gdalFileOrDirectoryExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:5144
bool file_or_glob_path_exists(const std::string &path)
void check_read_only(const std::string &str)
Definition: DBHandler.cpp:412
std::string find_first_geo_file_in_archive(const std::string &archive_path, const import_export::CopyParams &copy_params)
Definition: DBHandler.cpp:3936
void add_vsi_network_prefix(std::string &path)
Definition: DBHandler.cpp:3828
#define CHECK(condition)
Definition: Logger.h:222
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:4918
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:3501
std::optional< std::string > file_sort_order_by
Definition: CopyParams.h:86
void add_vsi_geo_prefix(std::string &path)
Definition: DBHandler.cpp:3850
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1587
#define STDLOG(...)
Definition: QueryState.h:235
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:128
EncodingType geo_coords_encoding
Definition: CopyParams.h:76
bool is_local_file(const std::string &file_path)
Definition: DBHandler.cpp:3971

+ 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 551 of file DBHandler.cpp.

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

551  {
552  auto stdlog = STDLOG();
553  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
554  auto session_ptr = get_session_ptr(session);
555  stdlog.setSessionInfo(session_ptr);
556  sessions_store_->disconnect(session);
557 }
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5692
std::unique_ptr< Catalog_Namespace::SessionsStore > sessions_store_
Definition: DBHandler.h:934
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1587
#define STDLOG(...)
Definition: QueryState.h:235

+ Here is the call graph for this function:

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

Definition at line 559 of file DBHandler.cpp.

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

559  {
560  const auto session_id = session_ptr->get_session_id();
561  std::exception_ptr leaf_exception = nullptr;
562  try {
563  if (leaf_aggregator_.leafCount() > 0) {
564  leaf_aggregator_.disconnect(session_id);
565  }
566  } catch (...) {
567  leaf_exception = std::current_exception();
568  }
569 
570  {
571  std::lock_guard<std::mutex> lock(render_group_assignment_mutex_);
572  render_group_assignment_map_.erase(session_id);
573  }
574 
575  if (render_handler_) {
576  render_handler_->disconnect(session_id);
577  }
578 
579  if (leaf_exception) {
580  std::rethrow_exception(leaf_exception);
581  }
582 }
std::mutex render_group_assignment_mutex_
Definition: DBHandler.h:1068
LeafAggregator leaf_aggregator_
Definition: DBHandler.h:625
void disconnect(const TSessionId session)
std::unique_ptr< RenderHandler > render_handler_
Definition: DBHandler.h:645
size_t leafCount() const
RenderGroupAnalyzerSessionMap render_group_assignment_map_
Definition: DBHandler.h:1067

+ Here is the call graph for this function:

void DBHandler::emergency_shutdown ( )

Definition at line 7061 of file DBHandler.cpp.

References calcite_.

Referenced by shutdown().

7061  {
7062  if (calcite_) {
7063  calcite_->close_calcite_server(false);
7064  }
7065 }
std::shared_ptr< Calcite > calcite_
Definition: DBHandler.h:648

+ 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 6396 of file DBHandler.cpp.

Referenced by sql_execute_impl().

6398  {}

+ 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 6831 of file DBHandler.cpp.

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

6833  {
6834  if (!render_handler_) {
6835  THROW_DB_EXCEPTION("Backend rendering is disabled.");
6836  }
6837 
6838  LOG(INFO) << "execute_next_render_step: id:" << pending_render.id;
6839  auto time_ms = measure<>::execution([&]() {
6840  try {
6841  render_handler_->execute_next_render_step(_return, pending_render, merged_data);
6842  } catch (std::exception& e) {
6843  THROW_DB_EXCEPTION(e.what());
6844  }
6845  });
6846  LOG(INFO) << "execute_next_render_step-COMPLETED id: " << pending_render.id
6847  << ", time: " << time_ms << "ms ";
6848 }
static TimeT::rep execution(F func, Args &&...args)
Definition: sample.cpp:29
#define LOG(tag)
Definition: Logger.h:216
std::unique_ptr< RenderHandler > render_handler_
Definition: DBHandler.h:645
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:128

+ 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 6597 of file DBHandler.cpp.

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

6600  {
6601  if (!leaf_handler_) {
6602  THROW_DB_EXCEPTION("Distributed support is disabled.");
6603  }
6604  LOG(INFO) << "execute_query_step : id:" << pending_query.id;
6605  auto time_ms = measure<>::execution([&]() {
6606  try {
6607  leaf_handler_->execute_query_step(
6608  _return, pending_query, subquery_id, start_time_str);
6609  } catch (std::exception& e) {
6610  THROW_DB_EXCEPTION(e.what());
6611  }
6612  });
6613  LOG(INFO) << "execute_query_step-COMPLETED " << time_ms << "ms";
6614 }
static TimeT::rep execution(F func, Args &&...args)
Definition: sample.cpp:29
#define LOG(tag)
Definition: Logger.h:216
std::unique_ptr< HeavyDBLeafHandler > leaf_handler_
Definition: DBHandler.h:647
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:128

+ 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 5760 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_pending_query_interrupt_freq, g_running_query_interrupt_freq, query_state::QueryState::getConstSessionInfo(), ExecutionResult::getExecutionTime(), Executor::getExecutor(), ExecutionResult::getPushedDownFilterInfo(), query_state::QueryStateProxy::getQueryState(), 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().

5771  {
5772  query_state::Timer timer = query_state_proxy.createTimer(__func__);
5773 
5774  VLOG(1) << "Table Schema Locks:\n" << lockmgr::TableSchemaLockMgr::instance();
5775  VLOG(1) << "Table Data Locks:\n" << lockmgr::TableDataLockMgr::instance();
5776 
5777  auto& cat = query_state_proxy.getQueryState().getConstSessionInfo()->getCatalog();
5778  auto executor = Executor::getExecutor(
5779  executor_index ? *executor_index : Executor::UNITARY_EXECUTOR_ID,
5780  jit_debug_ ? "/tmp" : "",
5781  jit_debug_ ? "mapdquery" : "",
5783  RelAlgExecutor ra_executor(executor.get(),
5784  cat,
5785  query_ra,
5786  query_state_proxy.getQueryState().shared_from_this());
5787  CompilationOptions co = {executor_device_type,
5788  /*hoist_literals=*/true,
5791  /*allow_lazy_fetch=*/true,
5792  /*filter_on_deleted_column=*/true,
5793  explain_info.isOptimizedExplain()
5797  auto validate_or_explain_query =
5798  explain_info.isJustExplain() || explain_info.isCalciteExplain() || just_validate;
5800  false,
5802  explain_info.isJustExplain(),
5803  allow_loop_joins_ || just_validate,
5805  jit_debug_,
5806  just_validate,
5809  find_push_down_candidates,
5810  explain_info.isCalciteExplain(),
5812  g_enable_runtime_query_interrupt && !validate_or_explain_query &&
5813  !query_state_proxy.getQueryState()
5815  ->get_session_id()
5816  .empty(),
5819  auto execution_time_ms = _return.getExecutionTime() + measure<>::execution([&]() {
5820  _return = ra_executor.executeRelAlgQuery(
5821  co, eo, explain_info.isPlanExplain(), nullptr);
5822  });
5823  // reduce execution time by the time spent during queue waiting
5824  const auto rs = _return.getRows();
5825  if (rs) {
5826  execution_time_ms -= rs->getQueueTime();
5827  }
5828  _return.setExecutionTime(execution_time_ms);
5829  VLOG(1) << cat.getDataMgr().getSystemMemoryUsage();
5830  const auto& filter_push_down_info = _return.getPushedDownFilterInfo();
5831  if (!filter_push_down_info.empty()) {
5832  return filter_push_down_info;
5833  }
5834  if (explain_info.isJustExplain()) {
5836  } else if (!explain_info.isCalciteExplain()) {
5838  }
5839  return {};
5840 }
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:633
bool g_enable_dynamic_watchdog
Definition: Execute.cpp:80
Timer createTimer(char const *event_name)
Definition: QueryState.cpp:138
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:477
bool g_enable_columnar_output
Definition: Execute.cpp:99
QueryState & getQueryState()
Definition: QueryState.h:181
const std::shared_ptr< ResultSet > & getRows() const
bool g_enable_watchdog
SystemParameters & system_parameters_
Definition: DBHandler.h:643
bool isOptimizedExplain() const
Definition: ParserWrapper.h:57
void setResultType(RType type)
bool isJustExplain() const
Definition: ParserWrapper.h:40
const bool allow_loop_joins_
Definition: DBHandler.h:637
const bool intel_jit_profile_
Definition: DBHandler.h:634
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:635
unsigned g_dynamic_watchdog_time_limit
Definition: Execute.cpp:85
std::shared_ptr< Catalog_Namespace::SessionInfo const > getConstSessionInfo() const
Definition: QueryState.cpp:88
int64_t getExecutionTime() const
bool g_enable_runtime_query_interrupt
Definition: Execute.cpp:125
#define VLOG(n)
Definition: Logger.h:316
bool isPlanExplain() const
Definition: ParserWrapper.h:59
static const ExecutorId UNITARY_EXECUTOR_ID
Definition: Execute.h:376

+ 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 6346 of file DBHandler.cpp.

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

Referenced by sql_execute_impl().

6356  {
6357  // collecting the selected filters' info to be sent to Calcite:
6358  std::vector<TFilterPushDownInfo> filter_push_down_info;
6359  for (const auto& req : filter_push_down_requests) {
6360  TFilterPushDownInfo filter_push_down_info_for_request;
6361  filter_push_down_info_for_request.input_prev = req.input_prev;
6362  filter_push_down_info_for_request.input_start = req.input_start;
6363  filter_push_down_info_for_request.input_next = req.input_next;
6364  filter_push_down_info.push_back(filter_push_down_info_for_request);
6365  }
6366  // deriving the new relational algebra plan with respect to the pushed down filters
6367  _return.addExecutionTime(measure<>::execution([&]() {
6368  query_ra = parse_to_ra(query_state_proxy,
6369  query_state_proxy.getQueryState().getQueryStr(),
6370  filter_push_down_info,
6371  false,
6373  .first.plan_result;
6374  }));
6375 
6376  if (is_calcite_explain) {
6377  // return the new ra as the result
6378  _return.updateResultSet(query_ra, ExecutionResult::Explanation);
6379  return;
6380  }
6381 
6382  // execute the new relational algebra plan:
6383  auto explain_info = ExplainInfo(ExplainInfo::ExplainType::IR);
6384  execute_rel_alg(_return,
6385  query_state_proxy,
6386  query_ra,
6387  column_format,
6388  executor_device_type,
6389  first_n,
6390  at_most_n,
6391  /*just_validate=*/false,
6392  /*find_push_down_candidates=*/false,
6393  explain_info);
6394 }
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:5760
std::string const & getQueryStr() const
Definition: QueryState.h:157
void addExecutionTime(int64_t execution_time_ms)
QueryState & getQueryState()
Definition: QueryState.h:181
void updateResultSet(const std::string &query_ra, RType type, bool success=true)
SystemParameters & system_parameters_
Definition: DBHandler.h:643
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:6400

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

7563  {
7564  DdlCommandExecutor executor = DdlCommandExecutor(query_ra, session_ptr);
7565  std::string commandStr = executor.commandStr();
7566 
7567  if (executor.isKillQuery()) {
7568  interruptQuery(*session_ptr, executor.getTargetQuerySessionToKill());
7569  } else {
7571  int64_t execution_time_ms;
7572  if (executor.isShowQueries()) {
7573  // getQueries still requires Thrift cannot be nested into DdlCommandExecutor
7574  _return.execution_time_ms +=
7575  measure<>::execution([&]() { result = getQueries(session_ptr); });
7576  } else if (executor.isShowUserSessions()) {
7577  // getUserSessions still requires Thrift cannot be nested into DdlCommandExecutor
7578  _return.execution_time_ms +=
7579  measure<>::execution([&]() { result = getUserSessions(session_ptr); });
7580  } else if (executor.isAlterSystemClear()) {
7581  alterSystemClear(session_ptr->get_session_id(),
7582  result,
7583  executor.returnCacheType(),
7584  execution_time_ms);
7585  _return.execution_time_ms += execution_time_ms;
7586 
7587  } else if (executor.isAlterSessionSet()) {
7588  alterSession(session_ptr->get_session_id(),
7589  result,
7590  executor.getSessionParameter(),
7591  execution_time_ms);
7592  _return.execution_time_ms += execution_time_ms;
7593  } else {
7594  _return.execution_time_ms +=
7595  measure<>::execution([&]() { result = executor.execute(read_only_); });
7596  }
7597 
7598  if (!result.empty()) {
7599  // reduce execution time by the time spent during queue waiting
7600  _return.execution_time_ms -= result.getRows()->getQueueTime();
7601  convertResultSet(result, *session_ptr, commandStr, _return);
7602  }
7603  }
7604 }
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:7238
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:7535
bool isAlterSessionSet() const
ExecutionResult execute(bool read_only_mode)
const bool read_only_
Definition: DBHandler.h:636
std::string returnCacheType() const
void interruptQuery(const Catalog_Namespace::SessionInfo &session_info, const std::string &target_session)
Definition: DBHandler.cpp:7430
ExecutionResult getQueries(std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
Definition: DBHandler.cpp:7305
ExecutionResult getUserSessions(std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
Definition: DBHandler.cpp:7267
void alterSystemClear(const std::string &sesson_id, ExecutionResult &result, const std::string &cache_type, int64_t &execution_time_ms)
Definition: DBHandler.cpp:7519

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

7609  {
7610  DdlCommandExecutor executor = DdlCommandExecutor(query_ra, session_ptr);
7611  std::string commandStr = executor.commandStr();
7612 
7613  if (executor.isKillQuery()) {
7614  interruptQuery(*session_ptr, executor.getTargetQuerySessionToKill());
7615  } else {
7616  int64_t execution_time_ms;
7617  if (executor.isShowQueries()) {
7618  // getQueries still requires Thrift cannot be nested into DdlCommandExecutor
7619  execution_time_ms =
7620  measure<>::execution([&]() { _return = getQueries(session_ptr); });
7621  } else if (executor.isShowUserSessions()) {
7622  // getUserSessions still requires Thrift cannot be nested into DdlCommandExecutor
7623  execution_time_ms =
7624  measure<>::execution([&]() { _return = getUserSessions(session_ptr); });
7625  } else if (executor.isAlterSystemClear()) {
7626  alterSystemClear(session_ptr->get_session_id(),
7627  _return,
7628  executor.returnCacheType(),
7629  execution_time_ms);
7630  } else if (executor.isAlterSessionSet()) {
7631  alterSession(session_ptr->get_session_id(),
7632  _return,
7633  executor.getSessionParameter(),
7634  execution_time_ms);
7635  } else {
7636  execution_time_ms =
7637  measure<>::execution([&]() { _return = executor.execute(read_only_); });
7638  }
7639  _return.setExecutionTime(execution_time_ms);
7640  }
7641  if (_return.getResultType() == ExecutionResult::QueryResult) {
7642  // ResultType defaults to QueryResult => which can limit
7643  // the number of lines output via ConvertRow... use CalciteDdl instead
7645  }
7646 }
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:7535
void setResultType(RType type)
bool isAlterSessionSet() const
ExecutionResult execute(bool read_only_mode)
const bool read_only_
Definition: DBHandler.h:636
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:7430
ExecutionResult getQueries(std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
Definition: DBHandler.cpp:7305
ExecutionResult getUserSessions(std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
Definition: DBHandler.cpp:7267
void alterSystemClear(const std::string &sesson_id, ExecutionResult &result, const std::string &cache_type, int64_t &execution_time_ms)
Definition: DBHandler.cpp:7519

+ 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 1567 of file DBHandler.cpp.

References get_table_details_impl().

Referenced by get_token_based_completions().

1568  {
1569  std::unordered_map<std::string, std::unordered_set<std::string>> column_names_by_table;
1570  for (auto it = table_names.begin(); it != table_names.end();) {
1571  TTableDetails table_details;
1572  try {
1573  get_table_details_impl(table_details, stdlog, *it, false, false);
1574  } catch (const TDBException& e) {
1575  // Remove the corrupted Table/View name from the list for further processing.
1576  it = table_names.erase(it);
1577  continue;
1578  }
1579  for (const auto& column_type : table_details.row_desc) {
1580  column_names_by_table[*it].emplace(column_type.col_name);
1581  }
1582  ++it;
1583  }
1584  return column_names_by_table;
1585 }
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:2272

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

2837  {
2838  auto geo_col_idx = col_idx - 1;
2839  const auto wkt_or_wkb_hex_column = import_buffers[geo_col_idx]->getGeoStringBuffer();
2840  std::vector<std::vector<double>> coords_column, bounds_column;
2841  std::vector<std::vector<int>> ring_sizes_column, poly_rings_column;
2842  std::vector<int> render_groups_column;
2843  SQLTypeInfo ti = cd->columnType;
2844  if (num_rows != wkt_or_wkb_hex_column->size() ||
2845  !Geospatial::GeoTypesFactory::getGeoColumns(wkt_or_wkb_hex_column,
2846  ti,
2847  coords_column,
2848  bounds_column,
2849  ring_sizes_column,
2850  poly_rings_column,
2851  true)) {
2852  std::ostringstream oss;
2853  oss << "Invalid geometry in column " << cd->columnName;
2854  THROW_DB_EXCEPTION(oss.str());
2855  }
2856 
2857  // start or continue assigning render groups for poly columns?
2858  if (IS_GEO_POLY(cd->columnType.get_type()) && assign_render_groups &&
2860  // get RGA to use
2861  import_export::RenderGroupAnalyzer* render_group_analyzer{};
2862  {
2863  // mutex the map access
2864  std::lock_guard<std::mutex> lock(render_group_assignment_mutex_);
2865 
2866  // emplace new RGA or fetch existing RGA from map
2867  auto [itr_table, emplaced_table] = render_group_assignment_map_.try_emplace(
2868  session, RenderGroupAssignmentTableMap());
2869  LOG_IF(INFO, emplaced_table)
2870  << "load_table_binary_columnar_polys: Creating Render Group Assignment "
2871  "Persistent Data for Session '"
2872  << session << "'";
2873  auto [itr_column, emplaced_column] =
2874  itr_table->second.try_emplace(table_name, RenderGroupAssignmentColumnMap());
2875  LOG_IF(INFO, emplaced_column)
2876  << "load_table_binary_columnar_polys: Creating Render Group Assignment "
2877  "Persistent Data for Table '"
2878  << table_name << "'";
2879  auto [itr_analyzer, emplaced_analyzer] = itr_column->second.try_emplace(
2880  cd->columnName, std::make_unique<import_export::RenderGroupAnalyzer>());
2881  LOG_IF(INFO, emplaced_analyzer)
2882  << "load_table_binary_columnar_polys: Creating Render Group Assignment "
2883  "Persistent Data for Column '"
2884  << cd->columnName << "'";
2885  render_group_analyzer = itr_analyzer->second.get();
2886  CHECK(render_group_analyzer);
2887 
2888  // seed new RGA from existing table/column, to handle appends
2889  if (emplaced_analyzer) {
2890  LOG(INFO) << "load_table_binary_columnar_polys: Seeding Render Groups from "
2891  "existing table...";
2892  render_group_analyzer->seedFromExistingTableContents(
2893  catalog, table_name, cd->columnName);
2894  LOG(INFO) << "load_table_binary_columnar_polys: Done";
2895  }
2896  }
2897 
2898  // assign render groups for this set of bounds
2899  LOG(INFO) << "load_table_binary_columnar_polys: Assigning Render Groups...";
2900  render_groups_column.reserve(bounds_column.size());
2901  for (auto const& bounds : bounds_column) {
2902  CHECK_EQ(bounds.size(), 4u);
2903  int rg = render_group_analyzer->insertBoundsAndReturnRenderGroup(bounds);
2904  render_groups_column.push_back(rg);
2905  }
2906  LOG(INFO) << "load_table_binary_columnar_polys: Done";
2907  } else {
2908  // render groups all zero
2909  render_groups_column.resize(bounds_column.size(), 0);
2910  }
2911 
2912  // Populate physical columns, advance col_idx
2914  cd,
2915  import_buffers,
2916  col_idx,
2917  coords_column,
2918  bounds_column,
2919  ring_sizes_column,
2920  poly_rings_column,
2921  render_groups_column);
2922 }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
std::unordered_map< std::string, RenderGroupAssignmentColumnMap > RenderGroupAssignmentTableMap
Definition: DBHandler.h:1064
std::mutex render_group_assignment_mutex_
Definition: DBHandler.h:1068
#define LOG(tag)
Definition: Logger.h:216
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:1728
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:379
#define LOG_IF(severity, condition)
Definition: Logger.h:312
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:222
RenderGroupAnalyzerSessionMap render_group_assignment_map_
Definition: DBHandler.h:1067
SQLTypeInfo columnType
std::unordered_map< std::string, std::unique_ptr< import_export::RenderGroupAnalyzer >> RenderGroupAssignmentColumnMap
Definition: DBHandler.h:1062
std::string columnName
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:128
#define IS_GEO_POLY(T)
Definition: sqltypes.h:303

+ 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 2924 of file DBHandler.cpp.

References CHECK, and fillGeoColumns().

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

2932  {
2933  size_t skip_physical_cols = 0;
2934  size_t col_idx = 0, import_idx = 0;
2935  for (const auto& cd : cds) {
2936  if (skip_physical_cols > 0) {
2937  CHECK(cd->isGeoPhyCol);
2938  skip_physical_cols--;
2939  continue;
2940  } else if (cd->columnType.is_geometry()) {
2941  skip_physical_cols = cd->columnType.get_physical_cols();
2942  }
2943  if (desc_id_to_column_id[import_idx] == -1) {
2944  import_buffers[col_idx]->addDefaultValues(cd, num_rows);
2945  col_idx++;
2946  if (cd->columnType.is_geometry()) {
2947  fillGeoColumns(session,
2948  catalog,
2949  import_buffers,
2950  cd,
2951  col_idx,
2952  num_rows,
2953  table_name,
2954  assign_render_groups);
2955  }
2956  } else {
2957  col_idx++;
2958  col_idx += skip_physical_cols;
2959  }
2960  import_idx++;
2961  }
2962 }
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:2829
#define CHECK(condition)
Definition: Logger.h:222

+ Here is the call graph for this function:

+ 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 5927 of file DBHandler.cpp.

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

Referenced by get_table_details_impl(), and sql_validate().

5928  {
5929  TRowDescriptor fixedup_row_desc;
5930  for (const TColumnType& col_desc : row_desc) {
5931  auto fixedup_col_desc = col_desc;
5932  if (col_desc.col_type.encoding == TEncodingType::DICT &&
5933  col_desc.col_type.comp_param > 0) {
5934  const auto dd = cat.getMetadataForDict(col_desc.col_type.comp_param, false);
5935  fixedup_col_desc.col_type.comp_param = dd->dictNBits;
5936  }
5937  fixedup_row_desc.push_back(fixedup_col_desc);
5938  }
5939 
5940  return fixedup_row_desc;
5941 }
const DictDescriptor * getMetadataForDict(int dict_ref, bool loadDict=true) const
Definition: Catalog.cpp:1960

+ 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 2046 of file DBHandler.cpp.

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

2048  {
2049  auto stdlog = STDLOG(get_session_ptr(sessionId));
2050  auto session_ptr = stdlog.getConstSessionInfo();
2051  getAllRolesForUserImpl(session_ptr, roles, sessionId, granteeName, /*effective=*/true);
2052 }
void getAllRolesForUserImpl(std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr, std::vector< std::string > &roles, const TSessionId &sessionId, const std::string &granteeName, bool effective)
Definition: DBHandler.cpp:2002
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5692
#define STDLOG(...)
Definition: QueryState.h:235

+ 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 5535 of file DBHandler.cpp.

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

5538  {
5539  auto stdlog =
5540  STDLOG(get_session_ptr(session), "get_all_files_in_archive", archive_path_in);
5541  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
5542 
5543  std::string archive_path(archive_path_in);
5544  if (path_is_relative(archive_path)) {
5545  // assume relative paths are relative to data_path / import / <session>
5546  auto file_path = import_path_ / picosha2::hash256_hex_string(session) /
5547  boost::filesystem::path(archive_path).filename();
5548  archive_path = file_path.string();
5549  }
5550  validate_import_file_path_if_local(archive_path);
5551 
5552  if (is_a_supported_archive_file(archive_path)) {
5553  // find the archive file
5554  add_vsi_network_prefix(archive_path);
5555  if (!import_export::Importer::gdalFileExists(archive_path,
5556  thrift_to_copyparams(copy_params))) {
5557  THROW_DB_EXCEPTION("Archive does not exist: " + archive_path_in);
5558  }
5559  // find all files in archive
5560  add_vsi_archive_prefix(archive_path);
5562  archive_path, thrift_to_copyparams(copy_params));
5563  // prepend them all with original path
5564  for (auto& s : _return) {
5565  s = archive_path_in + '/' + s;
5566  }
5567  }
5568 }
boost::filesystem::path import_path_
Definition: DBHandler.h:629
void add_vsi_archive_prefix(std::string &path)
Definition: DBHandler.cpp:3857
bool is_a_supported_archive_file(const std::string &path)
Definition: DBHandler.cpp:3923
bool path_is_relative(const std::string &path)
Definition: DBHandler.cpp:3891
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64
static bool gdalFileExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:5139
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5692
void validate_import_file_path_if_local(const std::string &file_path)
Definition: DBHandler.cpp:3977
void add_vsi_network_prefix(std::string &path)
Definition: DBHandler.cpp:3828
static std::vector< std::string > gdalGetAllFilesInArchive(const std::string &archive_path, const CopyParams &copy_params)
Definition: Importer.cpp:5216
import_export::CopyParams thrift_to_copyparams(const TCopyParams &cp)
Definition: DBHandler.cpp:3501
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1587
#define STDLOG(...)
Definition: QueryState.h:235
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:128

+ 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 2036 of file DBHandler.cpp.

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

2038  {
2039  // WARNING: This function only returns directly granted roles.
2040  // See also: get_all_effective_roles_for_user() for all of a user's roles.
2041  auto stdlog = STDLOG(get_session_ptr(sessionId));
2042  auto session_ptr = stdlog.getConstSessionInfo();
2043  getAllRolesForUserImpl(session_ptr, roles, sessionId, granteeName, /*effective=*/false);
2044 }
void getAllRolesForUserImpl(std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr, std::vector< std::string > &roles, const TSessionId &sessionId, const std::string &granteeName, bool effective)
Definition: DBHandler.cpp:2002
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5692
#define STDLOG(...)
Definition: QueryState.h:235

+ 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 1460 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(), gpu_enabled::sort(), STDLOG, and to_upper().

1463  {
1464  auto stdlog = STDLOG(get_session_ptr(session));
1465  std::vector<std::string> visible_tables; // Tables allowed for the given session.
1466  get_completion_hints_unsorted(hints, visible_tables, stdlog, sql, cursor);
1467  const auto proj_tokens = extract_projection_tokens_for_completion(sql);
1468  auto compatible_table_names = get_uc_compatible_table_names_by_column(
1469  proj_tokens.uc_column_names, visible_tables, stdlog);
1470  // Add the table qualifiers explicitly specified by the user.
1471  compatible_table_names.insert(proj_tokens.uc_column_table_qualifiers.begin(),
1472  proj_tokens.uc_column_table_qualifiers.end());
1473  // Sort the hints by category, from COLUMN (most specific) to KEYWORD.
1474  std::sort(
1475  hints.begin(),
1476  hints.end(),
1477  [&compatible_table_names](const TCompletionHint& lhs, const TCompletionHint& rhs) {
1478  if (lhs.type == TCompletionHintType::TABLE &&
1479  rhs.type == TCompletionHintType::TABLE) {
1480  // Between two tables, one which is compatible with the specified
1481  // projections and one which isn't, pick the one which is compatible.
1482  if (compatible_table_names.find(to_upper(lhs.hints.back())) !=
1483  compatible_table_names.end() &&
1484  compatible_table_names.find(to_upper(rhs.hints.back())) ==
1485  compatible_table_names.end()) {
1486  return true;
1487  }
1488  }
1489  return lhs.type < rhs.type;
1490  });
1491 }
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:5692
ProjectionTokensForCompletion extract_projection_tokens_for_completion(const std::string &sql)
Definition: DBHandler.cpp:1436
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:1493
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:1592
#define STDLOG(...)
Definition: QueryState.h:235

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

1497  {
1498  const auto& session_info = *stdlog.getConstSessionInfo();
1499  try {
1500  get_tables_impl(visible_tables, session_info, GET_PHYSICAL_TABLES_AND_VIEWS);
1501 
1502  // Filter out keywords suggested by Calcite which we don't support.
1504  calcite_->getCompletionHints(session_info, visible_tables, sql, cursor));
1505  } catch (const std::exception& e) {
1506  TDBException ex;
1507  ex.error_msg = std::string(e.what());
1508  LOG(ERROR) << ex.error_msg;
1509  throw ex;
1510  }
1511  boost::regex from_expr{R"(\s+from\s+)", boost::regex::extended | boost::regex::icase};
1512  const size_t length_to_cursor =
1513  cursor < 0 ? sql.size() : std::min(sql.size(), static_cast<size_t>(cursor));
1514  // Trust hints from Calcite after the FROM keyword.
1515  if (boost::regex_search(sql.cbegin(), sql.cbegin() + length_to_cursor, from_expr)) {
1516  return;
1517  }
1518  // Before FROM, the query is too incomplete for context-sensitive completions.
1519  get_token_based_completions(hints, stdlog, visible_tables, sql, cursor);
1520 }
#define LOG(tag)
Definition: Logger.h:216
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:2413
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:1522
std::shared_ptr< Calcite > calcite_
Definition: DBHandler.h:648
std::shared_ptr< Catalog_Namespace::SessionInfo const > getConstSessionInfo() const
Definition: QueryState.cpp:159

+ 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 4282 of file DBHandler.cpp.

References anonymous_namespace{DBHandler.cpp}::create_thrift_obj_from_custom_expr(), custom_expressions_mutex_, get_session_ptr(), getConnectionInfo(), STDLOG, and toString().

4283  {
4284  auto stdlog = STDLOG(get_session_ptr(session));
4285  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
4286 
4287  auto session_ptr = stdlog.getConstSessionInfo();
4288  auto& catalog = session_ptr->getCatalog();
4290  auto custom_expressions =
4291  catalog.getCustomExpressionsForUser(session_ptr->get_currentUser());
4292  for (const auto& custom_expression : custom_expressions) {
4293  _return.emplace_back(create_thrift_obj_from_custom_expr(*custom_expression, catalog));
4294  }
4295 }
heavyai::shared_lock< heavyai::shared_mutex > read_lock
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64
std::shared_lock< T > shared_lock
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5692
heavyai::shared_mutex custom_expressions_mutex_
Definition: DBHandler.h:1069
TCustomExpression create_thrift_obj_from_custom_expr(const CustomExpression &custom_expr, const Catalog &catalog)
Definition: DBHandler.cpp:4242
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1587
#define STDLOG(...)
Definition: QueryState.h:235

+ 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 4331 of file DBHandler.cpp.

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

4333  {
4334  auto stdlog = STDLOG(get_session_ptr(session));
4335  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
4336  auto session_ptr = stdlog.getConstSessionInfo();
4337  auto const& cat = session_ptr->getCatalog();
4339  auto dash = cat.getMetadataForDashboard(dashboard_id);
4340  if (!dash) {
4341  THROW_DB_EXCEPTION("Dashboard with dashboard id " + std::to_string(dashboard_id) +
4342  " doesn't exist");
4343  }
4345  *session_ptr, dash->dashboardId, AccessPrivileges::VIEW_DASHBOARD)) {
4346  THROW_DB_EXCEPTION("User has no view privileges for the dashboard with id " +
4347  std::to_string(dashboard_id));
4348  }
4349  user_meta.userName = "";
4350  SysCatalog::instance().getMetadataForUserById(dash->userId, user_meta);
4351  dashboard = get_dashboard_impl(session_ptr, user_meta, dash);
4352 }
static const AccessPrivileges VIEW_DASHBOARD
Definition: DBObject.h:171
std::string cat(Ts &&...args)
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64
std::string to_string(char const *&&v)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5692
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:4374
static bool is_allowed_on_dashboard(const Catalog_Namespace::SessionInfo &session_info, int32_t dashboard_id, AccessPrivileges requestedPermissions)
Definition: DBHandler.cpp:4206
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1587
#define STDLOG(...)
Definition: QueryState.h:235
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:128

+ 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 4704 of file DBHandler.cpp.

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

4707  {
4708  auto stdlog = STDLOG(get_session_ptr(session));
4709  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
4710  auto session_ptr = stdlog.getConstSessionInfo();
4711  auto const& cat = session_ptr->getCatalog();
4713  auto dash = cat.getMetadataForDashboard(dashboard_id);
4714  if (!dash) {
4715  THROW_DB_EXCEPTION("Dashboard id " + std::to_string(dashboard_id) +
4716  " does not exist");
4717  } else if (session_ptr->get_currentUser().userId != dash->userId &&
4718  !session_ptr->get_currentUser().isSuper) {
4720  "User should be either owner of dashboard or super user to access grantees");
4721  }
4722  std::vector<ObjectRoleDescriptor*> objectsList;
4723  objectsList = SysCatalog::instance().getMetadataForObject(
4724  cat.getCurrentDB().dbId,
4725  static_cast<int>(DBObjectType::DashboardDBObjectType),
4726  dashboard_id); // By default objecttypecan be only dashabaords
4727  user_meta.userId = -1;
4728  user_meta.userName = "";
4729  SysCatalog::instance().getMetadataForUserById(dash->userId, user_meta);
4730  for (auto object : objectsList) {
4731  if (user_meta.userName == object->roleName) {
4732  // Mask owner
4733  continue;
4734  }
4735  TDashboardGrantees grantee;
4736  TDashboardPermissions perm;
4737  grantee.name = object->roleName;
4738  grantee.is_user = object->roleType;
4739  perm.create_ = object->privs.hasPermission(DashboardPrivileges::CREATE_DASHBOARD);
4740  perm.delete_ = object->privs.hasPermission(DashboardPrivileges::DELETE_DASHBOARD);
4741  perm.edit_ = object->privs.hasPermission(DashboardPrivileges::EDIT_DASHBOARD);
4742  perm.view_ = object->privs.hasPermission(DashboardPrivileges::VIEW_DASHBOARD);
4743  grantee.permissions = perm;
4744  dashboard_grantees.push_back(grantee);
4745  }
4746 }
std::string cat(Ts &&...args)
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64
std::string to_string(char const *&&v)
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5692
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:1587
#define STDLOG(...)
Definition: QueryState.h:235
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:128

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

4378  {
4379  auto const& cat = session_ptr->getCatalog();
4380  SysCatalog::instance().getMetadataForUserById(dash->userId, user_meta);
4381  auto objects_list = SysCatalog::instance().getMetadataForObject(
4382  cat.getCurrentDB().dbId,
4383  static_cast<int>(DBObjectType::DashboardDBObjectType),
4384  dash->dashboardId);
4385  TDashboard dashboard;
4386  dashboard.dashboard_name = dash->dashboardName;
4387  if (populate_state) {
4388  dashboard.dashboard_state = dash->dashboardState;
4389  }
4390  dashboard.image_hash = dash->imageHash;
4391  dashboard.update_time = dash->updateTime;
4392  dashboard.dashboard_metadata = dash->dashboardMetadata;
4393  dashboard.dashboard_id = dash->dashboardId;
4394  dashboard.dashboard_owner = dash->user;
4395  TDashboardPermissions perms;
4396  // Super user has all permissions.
4397  if (session_ptr->get_currentUser().isSuper) {
4398  perms.create_ = true;
4399  perms.delete_ = true;
4400  perms.edit_ = true;
4401  perms.view_ = true;
4402  } else {
4403  // Collect all grants on current user
4404  // add them to the permissions.
4405  auto obj_to_find =
4406  DBObject(dashboard.dashboard_id, DBObjectType::DashboardDBObjectType);
4407  obj_to_find.loadKey(cat);
4408  std::vector<std::string> grantees =
4409  SysCatalog::instance().getRoles(true,
4410  session_ptr->get_currentUser().isSuper,
4411  session_ptr->get_currentUser().userName);
4412  for (const auto& grantee : grantees) {
4413  DBObject* object_found;
4414  auto* gr = SysCatalog::instance().getGrantee(grantee);
4415  if (gr && (object_found = gr->findDbObject(obj_to_find.getObjectKey(), true))) {
4416  const auto obj_privs = object_found->getPrivileges();
4417  perms.create_ |= obj_privs.hasPermission(DashboardPrivileges::CREATE_DASHBOARD);
4418  perms.delete_ |= obj_privs.hasPermission(DashboardPrivileges::DELETE_DASHBOARD);
4419  perms.edit_ |= obj_privs.hasPermission(DashboardPrivileges::EDIT_DASHBOARD);
4420  perms.view_ |= obj_privs.hasPermission(DashboardPrivileges::VIEW_DASHBOARD);
4421  }
4422  }
4423  }
4424  dashboard.dashboard_permissions = perms;
4425  if (objects_list.empty() ||
4426  (objects_list.size() == 1 && objects_list[0]->roleName == user_meta.userName)) {
4427  dashboard.is_dash_shared = false;
4428  } else {
4429  dashboard.is_dash_shared = true;
4430  }
4431  return dashboard;
4432 }
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 4354 of file DBHandler.cpp.

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

4355  {
4356  auto stdlog = STDLOG(get_session_ptr(session));
4357  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
4358  auto session_ptr = stdlog.getConstSessionInfo();
4359  auto const& cat = session_ptr->getCatalog();
4361  const auto dashes = cat.getAllDashboardsMetadata();
4362  user_meta.userName = "";
4363  for (const auto dash : dashes) {
4365  *session_ptr, dash->dashboardId, AccessPrivileges::VIEW_DASHBOARD)) {
4366  // dashboardState is intentionally not populated here
4367  // for payload reasons
4368  // use get_dashboard call to get state
4369  dashboards.push_back(get_dashboard_impl(session_ptr, user_meta, dash, false));
4370  }
4371  }
4372 }
static const AccessPrivileges VIEW_DASHBOARD
Definition: DBObject.h:171
std::string cat(Ts &&...args)
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5692
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:4374
static bool is_allowed_on_dashboard(const Catalog_Namespace::SessionInfo &session_info, int32_t dashboard_id, AccessPrivileges requestedPermissions)
Definition: DBHandler.cpp:4206
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1587
#define STDLOG(...)
Definition: QueryState.h:235

+ Here is the call graph for this function:

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

Definition at line 2720 of file DBHandler.cpp.

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

2720  {
2721  auto stdlog = STDLOG(get_session_ptr(session));
2722  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
2723  auto session_ptr = stdlog.getConstSessionInfo();
2724  const auto& user = session_ptr->get_currentUser();
2726  SysCatalog::instance().getDatabaseListForUser(user);
2727  for (auto& db : dbs) {
2728  TDBInfo dbinfo;
2729  dbinfo.db_name = std::move(db.dbName);
2730  dbinfo.db_owner = std::move(db.dbOwnerName);
2731  dbinfos.push_back(std::move(dbinfo));
2732  }
2733 }
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5692
std::list< DBSummary > DBSummaryList
Definition: SysCatalog.h:145
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1587
#define STDLOG(...)
Definition: QueryState.h:235

+ 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 1918 of file DBHandler.cpp.

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

1921  {
1922  auto stdlog = STDLOG(get_session_ptr(sessionId));
1923  auto session_ptr = stdlog.getConstSessionInfo();
1924  const auto& cat = session_ptr->getCatalog();
1925  DBObjectType object_type;
1926  switch (type) {
1928  object_type = DBObjectType::DatabaseDBObjectType;
1929  break;
1931  object_type = DBObjectType::TableDBObjectType;
1932  break;
1935  break;
1937  object_type = DBObjectType::ViewDBObjectType;
1938  break;
1940  object_type = DBObjectType::ServerDBObjectType;
1941  break;
1942  default:
1943  THROW_DB_EXCEPTION("Failed to get object privileges for " + objectName +
1944  ": unknown object type (" + std::to_string(type) + ").");
1945  }
1946  DBObject object_to_find(objectName, object_type);
1947 
1948  // TODO(adb): Use DatabaseLock to protect method
1949  try {
1950  if (object_type == DashboardDBObjectType) {
1951  if (objectName == "") {
1952  object_to_find = DBObject(-1, object_type);
1953  } else {
1954  object_to_find = DBObject(std::stoi(objectName), object_type);
1955  }
1956  } else if ((object_type == TableDBObjectType || object_type == ViewDBObjectType) &&
1957  !objectName.empty()) {
1958  // special handling for view / table
1959  auto td = cat.getMetadataForTable(objectName, false);
1960  if (td) {
1961  object_type = td->isView ? ViewDBObjectType : TableDBObjectType;
1962  object_to_find = DBObject(objectName, object_type);
1963  }
1964  }
1965  object_to_find.loadKey(cat);
1966  } catch (const std::exception&) {
1967  THROW_DB_EXCEPTION("Object with name " + objectName + " does not exist.");
1968  }
1969 
1970  // object type on database level
1971  DBObject object_to_find_dblevel("", object_type);
1972  object_to_find_dblevel.loadKey(cat);
1973  // if user is superuser respond with a full priv
1974  if (session_ptr->get_currentUser().isSuper) {
1975  // using ALL_TABLE here to set max permissions
1976  DBObject dbObj{object_to_find.getObjectKey(),
1978  session_ptr->get_currentUser().userId};
1979  dbObj.setName("super");
1980  TDBObjects.push_back(
1981  serialize_db_object(session_ptr->get_currentUser().userName, dbObj));
1982  };
1983 
1984  std::vector<std::string> grantees =
1985  SysCatalog::instance().getRoles(true,
1986  session_ptr->get_currentUser().isSuper,
1987  session_ptr->get_currentUser().userName);
1988  for (const auto& grantee : grantees) {
1989  DBObject* object_found;
1990  auto* gr = SysCatalog::instance().getGrantee(grantee);
1991  if (gr && (object_found = gr->findDbObject(object_to_find.getObjectKey(), true))) {
1992  TDBObjects.push_back(serialize_db_object(grantee, *object_found));
1993  }
1994  // check object permissions on Database level
1995  if (gr &&
1996  (object_found = gr->findDbObject(object_to_find_dblevel.getObjectKey(), true))) {
1997  TDBObjects.push_back(serialize_db_object(grantee, *object_found));
1998  }
1999  }
2000 }
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:5692
static TDBObject serialize_db_object(const std::string &roleName, const DBObject &inObject)
Definition: DBHandler.cpp:1679
static const AccessPrivileges ALL_TABLE
Definition: DBObject.h:157
#define STDLOG(...)
Definition: QueryState.h:235
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:128

+ 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 1891 of file DBHandler.cpp.

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

1893  {
1894  auto stdlog = STDLOG(get_session_ptr(sessionId));
1895  auto session_ptr = stdlog.getConstSessionInfo();
1896  auto const& user = session_ptr->get_currentUser();
1897  if (!user.isSuper &&
1898  !SysCatalog::instance().isRoleGrantedToGrantee(user.userName, roleName, false)) {
1899  return;
1900  }
1901  auto* rl = SysCatalog::instance().getGrantee(roleName);
1902  if (rl) {
1903  auto dbId = session_ptr->getCatalog().getCurrentDB().dbId;
1904  for (auto& dbObject : *rl->getDbObjects(true)) {
1905  if (dbObject.first.dbId != dbId) {
1906  // TODO (max): it doesn't scale well in case we have many DBs (not a typical
1907  // usecase for now, though)
1908  continue;
1909  }
1910  TDBObject tdbObject = serialize_db_object(roleName, *dbObject.second);
1911  TDBObjectsForRole.push_back(tdbObject);
1912  }
1913  } else {
1914  THROW_DB_EXCEPTION("User or role " + roleName + " does not exist.");
1915  }
1916 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5692
static TDBObject serialize_db_object(const std::string &roleName, const DBObject &inObject)
Definition: DBHandler.cpp:1679
#define STDLOG(...)
Definition: QueryState.h:235
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:128

+ 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 7080 of file DBHandler.cpp.

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

7081  {
7082  auto stdlog = STDLOG(get_session_ptr(session));
7083  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
7084  auto params = ::get_device_parameters(cpu_mode_only_);
7085  for (auto item : params) {
7086  _return.insert(item);
7087  }
7088  EXPOSE_THRIFT_MAP(TDeviceType);
7089  EXPOSE_THRIFT_MAP(TDatumType);
7090  EXPOSE_THRIFT_MAP(TEncodingType);
7091  EXPOSE_THRIFT_MAP(TExtArgumentType);
7092  EXPOSE_THRIFT_MAP(TOutputBufferSizeType);
7093 }
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64
#define EXPOSE_THRIFT_MAP(TYPENAME)
Definition: DBHandler.cpp:7069
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5692
void get_device_parameters(std::map< std::string, std::string > &_return, const TSessionId &session) override
Definition: DBHandler.cpp:7080
bool cpu_mode_only_
Definition: DBHandler.h:638
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1587
#define STDLOG(...)
Definition: QueryState.h:235

+ 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 5492 of file DBHandler.cpp.

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

5495  {
5496  auto stdlog =
5497  STDLOG(get_session_ptr(session), "get_first_geo_file_in_archive", archive_path_in);
5498  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
5499 
5500  std::string archive_path(archive_path_in);
5501 
5502  if (path_is_relative(archive_path)) {
5503  // assume relative paths are relative to data_path / import / <session>
5504  auto file_path = import_path_ / picosha2::hash256_hex_string(session) /
5505  boost::filesystem::path(archive_path).filename();
5506  archive_path = file_path.string();
5507  }
5508  validate_import_file_path_if_local(archive_path);
5509 
5510  if (is_a_supported_archive_file(archive_path)) {
5511  // find the archive file
5512  add_vsi_network_prefix(archive_path);
5513  if (!import_export::Importer::gdalFileExists(archive_path,
5514  thrift_to_copyparams(copy_params))) {
5515  THROW_DB_EXCEPTION("Archive does not exist: " + archive_path_in);
5516  }
5517  // find geo file in archive
5518  add_vsi_archive_prefix(archive_path);
5519  std::string geo_file =
5520  find_first_geo_file_in_archive(archive_path, thrift_to_copyparams(copy_params));
5521  // what did we get?
5522  if (geo_file.size()) {
5523  // prepend it with the original path
5524  _return = archive_path_in + std::string("/") + geo_file;
5525  } else {
5526  // just return the original path
5527  _return = archive_path_in;
5528  }
5529  } else {
5530  // just return the original path
5531  _return = archive_path_in;
5532  }
5533 }
boost::filesystem::path import_path_
Definition: DBHandler.h:629
void add_vsi_archive_prefix(std::string &path)
Definition: DBHandler.cpp:3857
bool is_a_supported_archive_file(const std::string &path)
Definition: DBHandler.cpp:3923
bool path_is_relative(const std::string &path)
Definition: DBHandler.cpp:3891
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64
static bool gdalFileExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:5139
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5692
void validate_import_file_path_if_local(const std::string &file_path)
Definition: DBHandler.cpp:3977
std::string find_first_geo_file_in_archive(const std::string &archive_path, const import_export::CopyParams &copy_params)
Definition: DBHandler.cpp:3936
void add_vsi_network_prefix(std::string &path)
Definition: DBHandler.cpp:3828
import_export::CopyParams thrift_to_copyparams(const TCopyParams &cp)
Definition: DBHandler.cpp:3501
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1587
#define STDLOG(...)
Definition: QueryState.h:235
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:128

+ 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 7196 of file DBHandler.cpp.

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

7198  {
7199  for (const std::string& udf_name : udf_names) {
7200  for (auto udf : ExtensionFunctionsWhitelist::get_ext_funcs(udf_name)) {
7201  _return.emplace_back(ThriftSerializers::to_thrift(udf));
7202  }
7203  }
7204 }
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,
const TSessionId &  session 
)
override

Definition at line 7176 of file DBHandler.cpp.

References ExtensionFunctionsWhitelist::get_udfs_name().

7177  {
7178  for (auto udf_name :
7179  ExtensionFunctionsWhitelist::get_udfs_name(/* is_runtime */ false)) {
7180  if (std::find(_return.begin(), _return.end(), udf_name) == _return.end()) {
7181  _return.emplace_back(udf_name);
7182  }
7183  }
7184 }
static std::unordered_set< std::string > get_udfs_name(const bool is_runtime)

+ Here is the call graph for this function:

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

Definition at line 739 of file DBHandler.cpp.

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

740  {
741  auto stdlog = STDLOG(get_session_ptr(session));
742  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
743  THardwareInfo ret;
744  const auto cuda_mgr = data_mgr_->getCudaMgr();
745  if (cuda_mgr) {
746  ret.num_gpu_hw = cuda_mgr->getDeviceCount();
747  ret.start_gpu = cuda_mgr->getStartGpu();
748  if (ret.start_gpu >= 0) {
749  ret.num_gpu_allocated = cuda_mgr->getDeviceCount() - cuda_mgr->getStartGpu();
750  // ^ This will break as soon as we allow non contiguous GPU allocations to MapD
751  }
752  for (int16_t device_id = 0; device_id < ret.num_gpu_hw; device_id++) {
753  TGpuSpecification gpu_spec;
754  auto deviceProperties = cuda_mgr->getDeviceProperties(device_id);
755  gpu_spec.num_sm = deviceProperties->numMPs;
756  gpu_spec.clock_frequency_kHz = deviceProperties->clockKhz;
757  gpu_spec.memory = deviceProperties->globalMem;
758  gpu_spec.compute_capability_major = deviceProperties->computeMajor;
759  gpu_spec.compute_capability_minor = deviceProperties->computeMinor;
760  ret.gpu_info.push_back(gpu_spec);
761  }
762  }
763 
764  // start hardware/OS dependent code
765  ret.num_cpu_hw = std::thread::hardware_concurrency();
766  // ^ This might return diffrent results in case of hyper threading
767  // end hardware/OS dependent code
768 
769  _return.hardware_info.push_back(ret);
770 }
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5692
std::shared_ptr< Data_Namespace::DataMgr > data_mgr_
Definition: DBHandler.h:623
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1587
#define STDLOG(...)
Definition: QueryState.h:235

+ Here is the call graph for this function:

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

Definition at line 5667 of file DBHandler.cpp.

References get_session_ptr(), STDLOG, and THROW_DB_EXCEPTION.

5667  {
5668  auto stdlog = STDLOG(get_session_ptr(session));
5669 #ifdef HAVE_PROFILER
5670  if (!IsHeapProfilerRunning()) {
5671  THROW_DB_EXCEPTION("Profiler not running");
5672  }
5673  auto profile_buff = GetHeapProfile();
5674  profile = profile_buff;
5675  free(profile_buff);
5676 #else
5677  THROW_DB_EXCEPTION("Profiler not enabled");
5678 #endif // HAVE_PROFILER
5679 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5692
#define STDLOG(...)
Definition: QueryState.h:235
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:128

+ Here is the call graph for this function:

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

Definition at line 2159 of file DBHandler.cpp.

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

2162  {
2163  auto stdlog = STDLOG(get_session_ptr(session), "table_name", table_name);
2164  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
2165  get_table_details_impl(_return, stdlog, table_name, include_system_columns, false);
2166 }
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:2272
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5692
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1587
#define STDLOG(...)
Definition: QueryState.h:235

+ Here is the call graph for this function:

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

Definition at line 2168 of file DBHandler.cpp.

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

2172  {
2173  auto stdlog = STDLOG(get_session_ptr(session), "table_name", table_name);
2174  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
2175  get_table_details_impl(_return, stdlog, table_name, true, false, database_name);
2176 }
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:2272
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5692
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1587
#define STDLOG(...)
Definition: QueryState.h:235

+ Here is the call graph for this function:

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

Definition at line 5570 of file DBHandler.cpp.

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

5573  {
5574  auto stdlog = STDLOG(get_session_ptr(session), "get_layers_in_geo_file", file_name_in);
5575  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
5576 
5577  std::string file_name(file_name_in);
5578 
5580 
5581  // handle relative paths
5582  if (path_is_relative(file_name)) {
5583  // assume relative paths are relative to data_path / import / <session>
5584  auto file_path = import_path_ / picosha2::hash256_hex_string(session) /
5585  boost::filesystem::path(file_name).filename();
5586  file_name = file_path.string();
5587  }
5589 
5590  // archive or file?
5591  if (is_a_supported_archive_file(file_name)) {
5592  // find the archive file
5593  add_vsi_network_prefix(file_name);
5594  if (!import_export::Importer::gdalFileExists(file_name, copy_params)) {
5595  THROW_DB_EXCEPTION("Archive does not exist: " + file_name_in);
5596  }
5597  // find geo file in archive
5598  add_vsi_archive_prefix(file_name);
5599  std::string geo_file = find_first_geo_file_in_archive(file_name, copy_params);
5600  // prepare to load that geo file
5601  if (geo_file.size()) {
5602  file_name = file_name + std::string("/") + geo_file;
5603  }
5604  } else {
5605  // prepare to load geo file directly
5606  add_vsi_network_prefix(file_name);
5607  add_vsi_geo_prefix(file_name);
5608  }
5609 
5610  // check the file actually exists
5611  if (!import_export::Importer::gdalFileOrDirectoryExists(file_name, copy_params)) {
5612  THROW_DB_EXCEPTION("Geo file/archive does not exist: " + file_name_in);
5613  }
5614 
5615  // find all layers
5616  auto internal_layer_info =
5617  import_export::Importer::gdalGetLayersInGeoFile(file_name, copy_params);
5618 
5619  // convert to Thrift type
5620  for (const auto& internal_layer : internal_layer_info) {
5621  TGeoFileLayerInfo layer;
5622  layer.name = internal_layer.name;
5623  switch (internal_layer.contents) {
5625  layer.contents = TGeoFileLayerContents::EMPTY;
5626  break;
5628  layer.contents = TGeoFileLayerContents::GEO;
5629  break;
5631  layer.contents = TGeoFileLayerContents::NON_GEO;
5632  break;
5634  layer.contents = TGeoFileLayerContents::UNSUPPORTED_GEO;
5635  break;
5636  default:
5637  CHECK(false);
5638  }
5639  _return.emplace_back(layer); // no suitable constructor to just pass parameters
5640  }
5641 }
boost::filesystem::path import_path_
Definition: DBHandler.h:629
void add_vsi_archive_prefix(std::string &path)
Definition: DBHandler.cpp:3857
bool is_a_supported_archive_file(const std::string &path)
Definition: DBHandler.cpp:3923
bool path_is_relative(const std::string &path)
Definition: DBHandler.cpp:3891
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64
static std::vector< GeoFileLayerInfo > gdalGetLayersInGeoFile(const std::string &file_name, const CopyParams &copy_params)
Definition: Importer.cpp:5243
static bool gdalFileExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:5139
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5692
void validate_import_file_path_if_local(const std::string &file_path)
Definition: DBHandler.cpp:3977
static bool gdalFileOrDirectoryExists(const std::string &path, const CopyParams &copy_params)
Definition: Importer.cpp:5144
std::string find_first_geo_file_in_archive(const std::string &archive_path, const import_export::CopyParams &copy_params)
Definition: DBHandler.cpp:3936
void add_vsi_network_prefix(std::string &path)
Definition: DBHandler.cpp:3828
#define CHECK(condition)
Definition: Logger.h:222
import_export::CopyParams thrift_to_copyparams(const TCopyParams &cp)
Definition: DBHandler.cpp:3501
void add_vsi_geo_prefix(std::string &path)
Definition: DBHandler.cpp:3850
ConnectionInfo getConnectionInfo() const
Definition: DBHandler.cpp:1587
#define STDLOG(...)
Definition: QueryState.h:235
#define THROW_DB_EXCEPTION(errstr)
Definition: DBHandler.cpp:128

+ Here is the call graph for this function:

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

Definition at line 7041 of file DBHandler.cpp.

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

7043  {
7044  auto stdlog = STDLOG(get_session_ptr(session));
7045  const auto session_info = get_session_copy(session);
7046  _return.claims.emplace_back("");
7047 }
std::shared_ptr< Catalog_Namespace::SessionInfo > get_session_ptr(const TSessionId &session_id)
Definition: DBHandler.cpp:5692
Catalog_Namespace::SessionInfo get_session_copy(const TSessionId &session)
Definition: DBHandler.cpp:5681
#define STDLOG(...)
Definition: QueryState.h:235

+ Here is the call graph for this function:

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

Definition at line 2379 of file DBHandler.cpp.

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

2381  {
2382  auto stdlog = STDLOG(get_session_ptr(session));
2383  stdlog.appendNameValuePairs("client", getConnectionInfo().toString());
2384  auto session_ptr = stdlog.getConstSessionInfo();
2385  auto const& cat = session_ptr->getCatalog();
2386  auto ld = cat.getMetadataForLink(std::to_string(cat.getCurrentDB().dbId) + link);
2387  if (!ld) {
2388  THROW_DB_EXCEPTION("Link " + link + " is not valid.");
2389  }
2390  _return.view_state = ld->viewState;
2391  _return.view_name = ld->link;
2392  _return.update_time = ld->updateTime;
2393  _return.