OmniSciDB  ba1bac9284
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ShowDiskCacheUsageCommand Class Reference

#include <DdlCommandExecutor.h>

+ Inheritance diagram for ShowDiskCacheUsageCommand:
+ Collaboration diagram for ShowDiskCacheUsageCommand:

Public Member Functions

 ShowDiskCacheUsageCommand (const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
 
ExecutionResult execute () override
 
- Public Member Functions inherited from DdlCommand
 DdlCommand (const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
 

Private Member Functions

std::vector< std::string > getFilteredTableNames ()
 

Additional Inherited Members

- Protected Member Functions inherited from DdlCommand
bool isDefaultServer (const std::string &server_name)
 
- Protected Attributes inherited from DdlCommand
const DdlCommandDataddl_data_
 
std::shared_ptr
< Catalog_Namespace::SessionInfo
const
session_ptr_
 

Detailed Description

Definition at line 164 of file DdlCommandExecutor.h.

Constructor & Destructor Documentation

ShowDiskCacheUsageCommand::ShowDiskCacheUsageCommand ( const DdlCommandData ddl_data,
std::shared_ptr< Catalog_Namespace::SessionInfo const session_ptr 
)

Definition at line 1451 of file DdlCommandExecutor.cpp.

References CHECK, DdlCommand::ddl_data_, and anonymous_namespace{DdlCommandExecutor.cpp}::extractPayload().

1454  : DdlCommand(ddl_data, session_ptr) {
1455  auto& ddl_payload = extractPayload(ddl_data_);
1456  if (ddl_payload.HasMember("tableNames")) {
1457  CHECK(ddl_payload["tableNames"].IsArray());
1458  for (auto const& tablename_def : ddl_payload["tableNames"].GetArray()) {
1459  CHECK(tablename_def.IsString());
1460  }
1461  }
1462 }
const DdlCommandData & ddl_data_
const rapidjson::Value & extractPayload(const DdlCommandData &ddl_data)
DdlCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
#define CHECK(condition)
Definition: Logger.h:206

+ Here is the call graph for this function:

Member Function Documentation

ExecutionResult ShowDiskCacheUsageCommand::execute ( )
overridevirtual

Executes the DDL command corresponding to provided JSON payload.

Parameters
_returnresult of DDL command execution (if applicable)

Implements DdlCommand.

Definition at line 1487 of file DdlCommandExecutor.cpp.

References ResultSetLogicalValuesBuilder::create(), anonymous_namespace{DdlCommandExecutor.cpp}::genLiteralBigInt(), genLiteralStr(), getFilteredTableNames(), kBIGINT, kTEXT, and DdlCommand::session_ptr_.

Referenced by omnisci.cursor.Cursor::executemany().

1487  {
1488  auto cat_ptr = session_ptr_->get_catalog_ptr();
1489  auto table_names = getFilteredTableNames();
1490 
1491  const auto disk_cache = cat_ptr->getDataMgr().getPersistentStorageMgr()->getDiskCache();
1492  if (!disk_cache) {
1493  throw std::runtime_error{"Disk cache not enabled. Cannot show disk cache usage."};
1494  }
1495 
1496  // label_infos -> column labels
1497  std::vector<std::string> labels{"table name", "current cache size"};
1498  std::vector<TargetMetaInfo> label_infos;
1499  label_infos.emplace_back(labels[0], SQLTypeInfo(kTEXT, true));
1500  label_infos.emplace_back(labels[1], SQLTypeInfo(kBIGINT, true));
1501 
1502  std::vector<RelLogicalValues::RowValues> logical_values;
1503 
1504  for (auto& table_name : table_names) {
1505  auto [td, td_with_lock] =
1506  get_table_descriptor_with_lock<lockmgr::ReadLock>(*cat_ptr, table_name, false);
1507 
1508  auto table_cache_size =
1509  disk_cache->getSpaceReservedByTable(cat_ptr->getDatabaseId(), td->tableId);
1510 
1511  // logical_values -> table data
1512  logical_values.emplace_back(RelLogicalValues::RowValues{});
1513  logical_values.back().emplace_back(genLiteralStr(table_name));
1514  logical_values.back().emplace_back(genLiteralBigInt(table_cache_size));
1515  }
1516 
1517  std::shared_ptr<ResultSet> rSet = std::shared_ptr<ResultSet>(
1518  ResultSetLogicalValuesBuilder::create(label_infos, logical_values));
1519 
1520  return ExecutionResult(rSet, label_infos);
1521 }
std::unique_ptr< RexLiteral > genLiteralBigInt(int64_t val)
static ResultSet * create(std::vector< TargetMetaInfo > &label_infos, std::vector< RelLogicalValues::RowValues > &logical_values)
Definition: sqltypes.h:51
std::vector< std::string > getFilteredTableNames()
static std::unique_ptr< RexLiteral > genLiteralStr(std::string val)
Definition: DBHandler.cpp:6909
std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr_
std::vector< std::unique_ptr< const RexScalar >> RowValues

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector< std::string > ShowDiskCacheUsageCommand::getFilteredTableNames ( )
private

Definition at line 1464 of file DdlCommandExecutor.cpp.

References DdlCommand::ddl_data_, anonymous_namespace{DdlCommandExecutor.cpp}::extractPayload(), GET_PHYSICAL_TABLES, and DdlCommand::session_ptr_.

Referenced by execute().

1464  {
1465  auto table_names = session_ptr_->get_catalog_ptr()->getTableNamesForUser(
1466  session_ptr_->get_currentUser(), GET_PHYSICAL_TABLES);
1467 
1468  auto& ddl_payload = extractPayload(ddl_data_);
1469  if (ddl_payload.HasMember("tableNames")) {
1470  std::vector<std::string> filtered_names;
1471  for (const auto& tablename_def : ddl_payload["tableNames"].GetArray()) {
1472  std::string filter_name = tablename_def.GetString();
1473  if (std::find(table_names.begin(), table_names.end(), filter_name) !=
1474  table_names.end()) {
1475  filtered_names.emplace_back(filter_name);
1476  } else {
1477  throw std::runtime_error("Can not show disk cache usage for table: " +
1478  filter_name + ". Table does not exist.");
1479  }
1480  }
1481  return filtered_names;
1482  } else {
1483  return table_names;
1484  }
1485 }
const DdlCommandData & ddl_data_
const rapidjson::Value & extractPayload(const DdlCommandData &ddl_data)
std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:


The documentation for this class was generated from the following files: