OmniSciDB  085a039ca4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Catalog_Namespace::Catalog Class Referencefinal

class for a per-database catalog. also includes metadata for the current database and the current user. More...

#include <Catalog.h>

+ Collaboration diagram for Catalog_Namespace::Catalog:

Public Member Functions

 Catalog (const std::string &basePath, const DBMetadata &curDB, std::shared_ptr< Data_Namespace::DataMgr > dataMgr, const std::vector< LeafHostInfo > &string_dict_hosts, std::shared_ptr< Calcite > calcite, bool is_new_db)
 Constructor - takes basePath to already extant data directory for writing. More...
 
 Catalog ()
 Constructor builds a hollow catalog used during constructor of other catalogs. More...
 
 ~Catalog ()
 Destructor - deletes all ColumnDescriptor and TableDescriptor structures which were allocated on the heap and writes Catalog to Sqlite. More...
 
void createTable (TableDescriptor &td, const std::list< ColumnDescriptor > &columns, const std::vector< Parser::SharedDictionaryDef > &shared_dict_defs, bool isLogicalTable)
 
void createShardedTable (TableDescriptor &td, const std::list< ColumnDescriptor > &columns, const std::vector< Parser::SharedDictionaryDef > &shared_dict_defs)
 
int32_t createDashboard (DashboardDescriptor &vd)
 
void replaceDashboard (DashboardDescriptor &vd)
 
std::string createLink (LinkDescriptor &ld, size_t min_length)
 
void dropTable (const TableDescriptor *td)
 
void truncateTable (const TableDescriptor *td)
 
void renameTable (const TableDescriptor *td, const std::string &newTableName)
 
void renameTable (std::vector< std::pair< std::string, std::string >> &names)
 
void renameColumn (const TableDescriptor *td, const ColumnDescriptor *cd, const std::string &newColumnName)
 
void addColumn (const TableDescriptor &td, ColumnDescriptor &cd)
 
void dropColumn (const TableDescriptor &td, const ColumnDescriptor &cd)
 
void removeFragmenterForTable (const int table_id) const
 
const std::map< int, const
ColumnDescriptor * > 
getDictionaryToColumnMapping ()
 
const TableDescriptorgetMetadataForTable (const std::string &tableName, const bool populateFragmenter=true) const
 Returns a pointer to a const TableDescriptor struct matching the provided tableName. More...
 
const TableDescriptorgetMetadataForTable (int tableId, bool populateFragmenter=true) const
 
std::optional< std::string > getTableName (int32_t table_id) const
 
std::optional< int32_t > getTableId (const std::string &table_name) const
 
const ColumnDescriptorgetMetadataForColumn (int tableId, const std::string &colName) const
 
const ColumnDescriptorgetMetadataForColumn (int tableId, int columnId) const
 
const std::optional< std::string > getColumnName (int table_id, int column_id) const
 
const int getColumnIdBySpi (const int tableId, const size_t spi) const
 
const ColumnDescriptorgetMetadataForColumnBySpi (const int tableId, const size_t spi) const
 
const DashboardDescriptorgetMetadataForDashboard (const std::string &userId, const std::string &dashName) const
 
const DashboardDescriptorgetMetadataForDashboard (const int32_t dashboard_id) const
 
void deleteMetadataForDashboards (const std::vector< int32_t > ids, const UserMetadata &user)
 
const LinkDescriptorgetMetadataForLink (const std::string &link) const
 
const LinkDescriptorgetMetadataForLink (int linkId) const
 
const
foreign_storage::ForeignTable
getForeignTable (const std::string &tableName) const
 
const
foreign_storage::ForeignTable
getForeignTable (int table_id) const
 
std::list< const
ColumnDescriptor * > 
getAllColumnMetadataForTable (const int tableId, const bool fetchSystemColumns, const bool fetchVirtualColumns, const bool fetchPhysicalColumns) const
 Returns a list of pointers to constant ColumnDescriptor structs for all the columns from a particular table specified by table id. More...
 
std::list< const
TableDescriptor * > 
getAllTableMetadata () const
 
std::vector< TableDescriptorgetAllTableMetadataCopy () const
 
std::list< const
DashboardDescriptor * > 
getAllDashboardsMetadata () const
 
std::vector< DashboardDescriptorgetAllDashboardsMetadataCopy () const
 
const DBMetadatagetCurrentDB () const
 
Data_Namespace::DataMgrgetDataMgr () const
 
std::shared_ptr< CalcitegetCalciteMgr () const
 
const std::string & getCatalogBasePath () const
 
const DictDescriptorgetMetadataForDict (int dict_ref, bool loadDict=true) const
 
const std::vector< LeafHostInfo > & getStringDictionaryHosts () const
 
const ColumnDescriptorgetShardColumnMetadataForTable (const TableDescriptor *td) const
 
std::vector< const
TableDescriptor * > 
getPhysicalTablesDescriptors (const TableDescriptor *logical_table_desc, bool populate_fragmenter=true) const
 
std::vector< std::pair
< int32_t, int32_t > > 
getAllPersistedTableAndShardIds () const
 
std::vector< std::string > getTableNamesForUser (const UserMetadata &user, const GetTablesType get_tables_type) const
 
std::vector< TableMetadatagetTablesMetadataForUser (const UserMetadata &user_metadata, const GetTablesType get_tables_type, const std::string &filter_table_name) const
 
int32_t getTableEpoch (const int32_t db_id, const int32_t table_id) const
 
void setTableEpoch (const int db_id, const int table_id, const int new_epoch)
 
void setMaxRollbackEpochs (const int32_t table_id, const int32_t max_rollback_epochs)
 
void setMaxRows (const int32_t table_id, const int64_t max_rows)
 
std::vector< TableEpochInfogetTableEpochs (const int32_t db_id, const int32_t table_id) const
 
void setTableEpochs (const int32_t db_id, const std::vector< TableEpochInfo > &table_epochs) const
 
void setTableEpochsLogExceptions (const int32_t db_id, const std::vector< TableEpochInfo > &table_epochs) const
 
int getDatabaseId () const
 
SqliteConnectorgetSqliteConnector ()
 
void roll (const bool forward)
 
DictRef addDictionary (ColumnDescriptor &cd)
 
void delDictionary (const ColumnDescriptor &cd)
 
void getDictionary (const ColumnDescriptor &cd, std::map< int, StringDictionary * > &stringDicts)
 
const bool checkMetadataForDeletedRecs (const TableDescriptor *td, int column_id) const
 
const ColumnDescriptorgetDeletedColumn (const TableDescriptor *td) const
 
const ColumnDescriptorgetDeletedColumnIfRowsDeleted (const TableDescriptor *td) const
 
void setDeletedColumn (const TableDescriptor *td, const ColumnDescriptor *cd)
 
int getLogicalTableId (const int physicalTableId) const
 
void checkpoint (const int logicalTableId) const
 
void checkpointWithAutoRollback (const int logical_table_id) const
 
void resetTableEpochFloor (const int logicalTableId) const
 
std::string name () const
 
void eraseDbMetadata ()
 
void eraseDbPhysicalData ()
 
void eraseTablePhysicalData (const TableDescriptor *td)
 
void setForReload (const int32_t tableId)
 
std::vector< std::string > getTableDataDirectories (const TableDescriptor *td) const
 
std::vector< std::string > getTableDictDirectories (const TableDescriptor *td) const
 
std::set< std::string > getTableDictDirectoryPaths (int32_t table_id) const
 
std::string getColumnDictDirectory (const ColumnDescriptor *cd, bool file_name_only=true) const
 
std::string dumpSchema (const TableDescriptor *td) const
 
std::string dumpCreateTable (const TableDescriptor *td, bool multiline_formatting=true, bool dump_defaults=false) const
 
std::optional< std::string > dumpCreateTable (int32_t table_id, bool multiline_formatting=true, bool dump_defaults=false) const
 
void createForeignServer (std::unique_ptr< foreign_storage::ForeignServer > foreign_server, bool if_not_exists)
 
const
foreign_storage::ForeignServer
getForeignServer (const std::string &server_name) const
 
const std::unique_ptr< const
foreign_storage::ForeignServer
getForeignServerFromStorage (const std::string &server_name)
 
const std::unique_ptr< const
foreign_storage::ForeignTable
getForeignTableFromStorage (int table_id)
 
void changeForeignServerOwner (const std::string &server_name, const int new_owner_id)
 
void setForeignServerDataWrapper (const std::string &server_name, const std::string &data_wrapper)
 
void setForeignServerOptions (const std::string &server_name, const std::string &options)
 
void renameForeignServer (const std::string &server_name, const std::string &name)
 
void dropForeignServer (const std::string &server_name)
 
void getForeignServersForUser (const rapidjson::Value *filters, const UserMetadata &user, std::vector< const foreign_storage::ForeignServer * > &results)
 
void createDefaultServersIfNotExists ()
 
bool validateNonExistentTableOrView (const std::string &name, const bool if_not_exists)
 
std::vector< const
TableDescriptor * > 
getAllForeignTablesForRefresh () const
 
void updateForeignTableRefreshTimes (const int32_t table_id)
 
void setForeignTableOptions (const std::string &table_name, foreign_storage::OptionsMap &options_map, bool clear_existing_options=true)
 
void updateLeaf (const LeafHostInfo &string_dict_host)
 
void setUncappedTableEpoch (const std::string &table_name)
 
int32_t createCustomExpression (std::unique_ptr< CustomExpression > custom_expression)
 
const CustomExpressiongetCustomExpression (int32_t custom_expression_id) const
 
const std::unique_ptr< const
CustomExpression
getCustomExpressionFromStorage (int32_t custom_expression_id)
 
std::vector< const
CustomExpression * > 
getCustomExpressionsForUser (const UserMetadata &user) const
 
void updateCustomExpression (int32_t custom_expression_id, const std::string &expression_json)
 
void deleteCustomExpressions (const std::vector< int32_t > &custom_expression_ids, bool do_soft_delete)
 
void reassignOwners (const std::set< std::string > &old_owners, const std::string &new_owner)
 

Static Public Member Functions

static void expandGeoColumn (const ColumnDescriptor &cd, std::list< ColumnDescriptor > &columns)
 
static const std::string getForeignTableSchema (bool if_not_exists=false)
 
static const std::string getForeignServerSchema (bool if_not_exists=false)
 
static const std::string getCustomExpressionsSchema (bool if_not_exists=false)
 

Public Attributes

std::mutex sqliteMutex_
 
mapd_shared_mutex sharedMutex_
 
std::atomic< std::thread::id > thread_holding_sqlite_lock
 
std::atomic< std::thread::id > thread_holding_write_lock
 
bool initialized_ = false
 

Static Public Attributes

static thread_local bool thread_holds_read_lock = false
 

Protected Types

using ColumnDescriptorsForRoll = std::vector< std::pair< ColumnDescriptor *, ColumnDescriptor * >>
 

Protected Member Functions

void CheckAndExecuteMigrations ()
 
void CheckAndExecuteMigrationsPostBuildMaps ()
 
void updateDictionaryNames ()
 
void updateTableDescriptorSchema ()
 
void updateFixlenArrayColumns ()
 
void updateGeoColumns ()
 
void updateFrontendViewSchema ()
 
void updateLinkSchema ()
 
void updateFrontendViewAndLinkUsers ()
 
void updateLogicalToPhysicalTableLinkSchema ()
 
void updateLogicalToPhysicalTableMap (const int32_t logical_tb_id)
 
void updateDictionarySchema ()
 
void updatePageSize ()
 
void updateDeletedColumnIndicator ()
 
void updateDefaultColumnValues ()
 
void updateFrontendViewsToDashboards ()
 
void updateCustomExpressionsSchema ()
 
void updateFsiSchemas ()
 
void renameLegacyDataWrappers ()
 
void recordOwnershipOfObjectsInObjectPermissions ()
 
void checkDateInDaysColumnMigration ()
 
void createDashboardSystemRoles ()
 
void buildMaps ()
 
void addTableToMap (const TableDescriptor *td, const std::list< ColumnDescriptor > &columns, const std::list< DictDescriptor > &dicts)
 
void addReferenceToForeignDict (ColumnDescriptor &referencing_column, Parser::SharedDictionaryDef shared_dict_def, const bool persist_reference)
 
bool setColumnSharedDictionary (ColumnDescriptor &cd, std::list< ColumnDescriptor > &cdd, std::list< DictDescriptor > &dds, const TableDescriptor td, const std::vector< Parser::SharedDictionaryDef > &shared_dict_defs)
 
void setColumnDictionary (ColumnDescriptor &cd, std::list< DictDescriptor > &dds, const TableDescriptor &td, bool is_logical_table, bool use_temp_dictionary=false)
 
void addFrontendViewToMap (DashboardDescriptor &vd)
 
void addFrontendViewToMapNoLock (DashboardDescriptor &vd)
 
void addLinkToMap (LinkDescriptor &ld)
 
void removeTableFromMap (const std::string &tableName, const int tableId, const bool is_on_error=false)
 
void eraseTableMetadata (const TableDescriptor *td)
 
void executeDropTableSqliteQueries (const TableDescriptor *td)
 
void doTruncateTable (const TableDescriptor *td)
 
void renamePhysicalTable (const TableDescriptor *td, const std::string &newTableName)
 
void renamePhysicalTable (std::vector< std::pair< std::string, std::string >> &names, std::vector< int > &tableIds)
 
void instantiateFragmenter (TableDescriptor *td) const
 
void getAllColumnMetadataForTableImpl (const TableDescriptor *td, std::list< const ColumnDescriptor * > &colDescs, const bool fetchSystemColumns, const bool fetchVirtualColumns, const bool fetchPhysicalColumns) const
 
std::string calculateSHA1 (const std::string &data)
 
std::string generatePhysicalTableName (const std::string &logicalTableName, const int32_t &shardNumber)
 
std::vector< DBObjectparseDashboardObjects (const std::string &view_meta, const int &user_id)
 
void createOrUpdateDashboardSystemRole (const std::string &view_meta, const int32_t &user_id, const std::string &dash_role_name)
 
const int getColumnIdBySpiUnlocked (const int table_id, const size_t spi) const
 
void serializeTableJsonUnlocked (const TableDescriptor *td, const std::list< ColumnDescriptor > &cds) const
 
void dropTableFromJsonUnlocked (const std::string &table_name) const
 

Protected Attributes

std::string basePath_
 
TableDescriptorMap tableDescriptorMap_
 
TableDescriptorMapById tableDescriptorMapById_
 
ColumnDescriptorMap columnDescriptorMap_
 
ColumnDescriptorMapById columnDescriptorMapById_
 
DictDescriptorMapById dictDescriptorMapByRef_
 
DashboardDescriptorMap dashboardDescriptorMap_
 
LinkDescriptorMap linkDescriptorMap_
 
LinkDescriptorMapById linkDescriptorMapById_
 
ForeignServerMap foreignServerMap_
 
ForeignServerMapById foreignServerMapById_
 
CustomExpressionMapById custom_expr_map_by_id_
 
TableDictColumnsMap dict_columns_by_table_id_
 
SqliteConnector sqliteConnector_
 
const DBMetadata currentDB_
 
std::shared_ptr
< Data_Namespace::DataMgr
dataMgr_
 
const std::vector< LeafHostInfostring_dict_hosts_
 
std::shared_ptr< CalcitecalciteMgr_
 
LogicalToPhysicalTableMapById logicalToPhysicalTableMapById_
 
int nextTempTableId_
 
int nextTempDictId_
 
ColumnDescriptorsForRoll columnDescriptorsForRoll
 

Static Protected Attributes

static const std::string physicalTableNameTag_
 

Private Member Functions

void buildDictionaryMapUnlocked ()
 
void buildTablesMapUnlocked ()
 
void buildColumnsMapUnlocked ()
 
void updateViewsInMapUnlocked ()
 
void buildDashboardsMapUnlocked (const std::map< int32_t, std::string > &user_name_by_user_id)
 
void buildLinksMapUnlocked ()
 
void buildLogicalToPhysicalMapUnlocked ()
 
void updateForeignTablesInMapUnlocked ()
 
void gatherAdditionalInfo (std::vector< std::string > &additional_info, std::set< std::string > &shared_dict_column_names, const TableDescriptor *td) const
 
std::string quoteIfRequired (const std::string &column_name) const
 
void adjustAlteredTableFiles (const std::string &temp_data_dir, const std::unordered_map< int, int > &all_column_ids_map) const
 
void renameTableDirectories (const std::string &temp_data_dir, const std::vector< std::string > &target_paths, const std::string &name_prefix) const
 
void buildForeignServerMapUnlocked ()
 
void setForeignServerProperty (const std::string &server_name, const std::string &property, const std::string &value)
 
void setForeignTableProperty (const foreign_storage::ForeignTable *table, const std::string &property, const std::string &value)
 
void alterPhysicalTableMetadata (const TableDescriptor *td, const TableDescriptorUpdateParams &table_update_params)
 
void alterTableMetadata (const TableDescriptor *td, const TableDescriptorUpdateParams &table_update_params)
 
void setTableFileMgrParams (const int table_id, const File_Namespace::FileMgrParams &file_mgr_params)
 
bool filterTableByTypeAndUser (const TableDescriptor *td, const UserMetadata &user_metadata, const GetTablesType get_tables_type) const
 
TableDescriptorgetMutableMetadataForTableUnlocked (int table_id) const
 
TableDescriptorgetMutableMetadataForTableUnlocked (const std::string &table_name) const
 
void createForeignServerNoLocks (std::unique_ptr< foreign_storage::ForeignServer > foreign_server, bool if_not_exists)
 
foreign_storage::ForeignTablegetForeignTableUnlocked (const std::string &tableName) const
 
const CataloggetObjForLock ()
 
void removeChunks (const int table_id) const
 
void buildCustomExpressionsMapUnlocked ()
 
std::unique_ptr< CustomExpressiongetCustomExpressionFromConnector (size_t row)
 
void restoreOldOwners (const std::map< int32_t, std::string > &old_owners_user_name_by_id, const std::map< int32_t, std::vector< DBObject >> &old_owner_db_objects, int32_t new_owner_id)
 
void restoreOldOwnersInMemory (const std::map< int32_t, std::string > &old_owners_user_name_by_id, const std::map< int32_t, std::vector< DBObject >> &old_owner_db_objects, int32_t new_owner_id)
 
void conditionallyInitializeSystemObjects ()
 
void initializeSystemServers ()
 
void initializeSystemTables ()
 
void createSystemTableServer (const std::string &server_name, const std::string &data_wrapper_type)
 
std::pair
< foreign_storage::ForeignTable,
std::list< ColumnDescriptor > > 
getSystemTableSchema (const std::string &table_name, const std::string &server_name, const std::vector< std::pair< std::string, SQLTypeInfo >> &column_type_by_name)
 
void recreateSystemTableIfUpdated (foreign_storage::ForeignTable &foreign_table, const std::list< ColumnDescriptor > &columns)
 
void setDeletedColumnUnlocked (const TableDescriptor *td, const ColumnDescriptor *cd)
 
void addToColumnMap (ColumnDescriptor *cd)
 
void removeFromColumnMap (ColumnDescriptor *cd)
 
void deleteTableCatalogMetadata (const TableDescriptor *logical_table, const std::vector< const TableDescriptor * > &physical_tables)
 
std::string dumpCreateTableUnlocked (const TableDescriptor *td, bool multiline_formatting, bool dump_defaults) const
 
bool isInfoSchemaDb () const
 

Private Attributes

DeletedColumnPerTableMap deletedColumnPerTable_
 

Static Private Attributes

static constexpr const char * CATALOG_SERVER_NAME {"system_catalog_server"}
 
static constexpr const char * MEMORY_STATS_SERVER_NAME {"system_memory_stats_server"}
 
static constexpr const char * STORAGE_STATS_SERVER_NAME {"system_storage_stats_server"}
 
static constexpr std::array
< const char *, 3 > 
INTERNAL_SERVERS
 

Detailed Description

class for a per-database catalog. also includes metadata for the current database and the current user.

Catalog

Definition at line 114 of file Catalog.h.

Member Typedef Documentation

Definition at line 676 of file Catalog.h.

Constructor & Destructor Documentation

Catalog_Namespace::Catalog::Catalog ( const std::string &  basePath,
const DBMetadata curDB,
std::shared_ptr< Data_Namespace::DataMgr dataMgr,
const std::vector< LeafHostInfo > &  string_dict_hosts,
std::shared_ptr< Calcite calcite,
bool  is_new_db 
)

Constructor - takes basePath to already extant data directory for writing.

Parameters
basePathdirectory path for writing catalog
dbNamename of the database
fragmenterFragmenter object metadata - expects for this directory to already exist
Catalog_Namespace::Catalog::Catalog ( )

Constructor builds a hollow catalog used during constructor of other catalogs.

Definition at line 213 of file Catalog.cpp.

213 {}
Catalog_Namespace::Catalog::~Catalog ( )

Destructor - deletes all ColumnDescriptor and TableDescriptor structures which were allocated on the heap and writes Catalog to Sqlite.

Definition at line 215 of file Catalog.cpp.

References basePath_, columnDescriptorMap_, currentDB_, Catalog_Namespace::DBMetadata::dbName, g_serialize_temp_tables, Catalog_Namespace::anonymous_namespace{Catalog.cpp}::table_json_filepath(), and tableDescriptorMap_.

215  {
217  // must clean up heap-allocated TableDescriptor and ColumnDescriptor structs
218  for (TableDescriptorMap::iterator tableDescIt = tableDescriptorMap_.begin();
219  tableDescIt != tableDescriptorMap_.end();
220  ++tableDescIt) {
221  tableDescIt->second->fragmenter = nullptr;
222  delete tableDescIt->second;
223  }
224 
225  // TableDescriptorMapById points to the same descriptors. No need to delete
226 
227  for (ColumnDescriptorMap::iterator columnDescIt = columnDescriptorMap_.begin();
228  columnDescIt != columnDescriptorMap_.end();
229  ++columnDescIt) {
230  delete columnDescIt->second;
231  }
232 
233  // ColumnDescriptorMapById points to the same descriptors. No need to delete
234 
236  boost::filesystem::remove(table_json_filepath(basePath_, currentDB_.dbName));
237  }
238 }
ColumnDescriptorMap columnDescriptorMap_
Definition: Catalog.h:647
const DBMetadata currentDB_
Definition: Catalog.h:659
auto table_json_filepath(const std::string &base_path, const std::string &db_name)
Definition: Catalog.cpp:162
bool g_serialize_temp_tables
Definition: Catalog.cpp:106
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:122
mapd_unique_lock< mapd_shared_mutex > write_lock
TableDescriptorMap tableDescriptorMap_
Definition: Catalog.h:645

+ Here is the call graph for this function:

Member Function Documentation

void Catalog_Namespace::Catalog::addColumn ( const TableDescriptor td,
ColumnDescriptor cd 
)

Definition at line 2092 of file Catalog.cpp.

References addDictionary(), addToColumnMap(), columnDescriptorsForRoll, ColumnDescriptor::columnId, ColumnDescriptor::columnName, ColumnDescriptor::columnType, ColumnDescriptor::default_value, SQLTypeInfo::get_comp_param(), SQLTypeInfo::get_compression(), SQLTypeInfo::get_dimension(), SQLTypeInfo::get_notnull(), SQLTypeInfo::get_scale(), SQLTypeInfo::get_size(), SQLTypeInfo::get_subtype(), SQLTypeInfo::get_type(), SqliteConnector::getData(), getPhysicalTablesDescriptors(), ColumnDescriptor::isDeletedCol, ColumnDescriptor::isSystemCol, ColumnDescriptor::isVirtualCol, kENCODING_DICT, TableDescriptor::nShards, SqliteConnector::query_with_text_params(), TableDescriptor::shard, sqliteConnector_, tableDescriptorMapById_, ColumnDescriptor::tableId, TableDescriptor::tableId, to_string(), and ColumnDescriptor::virtualExpr.

2092  {
2093  // caller must handle sqlite/chunk transaction TOGETHER
2094  cd.tableId = td.tableId;
2095  if (td.nShards > 0 && td.shard < 0) {
2096  for (const auto shard : getPhysicalTablesDescriptors(&td)) {
2097  auto shard_cd = cd;
2098  addColumn(*shard, shard_cd);
2099  }
2100  }
2102  addDictionary(cd);
2103  }
2104 
2105  using BindType = SqliteConnector::BindType;
2106  std::vector<BindType> types(17, BindType::TEXT);
2107  if (!cd.default_value.has_value()) {
2108  types[16] = BindType::NULL_TYPE;
2109  }
2111  "INSERT INTO mapd_columns (tableid, columnid, name, coltype, colsubtype, coldim, "
2112  "colscale, is_notnull, "
2113  "compression, comp_param, size, chunks, is_systemcol, is_virtualcol, virtual_expr, "
2114  "is_deletedcol, default_value) "
2115  "VALUES (?, "
2116  "(SELECT max(columnid) + 1 FROM mapd_columns WHERE tableid = ?), "
2117  "?, ?, ?, "
2118  "?, "
2119  "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
2120  std::vector<std::string>{std::to_string(td.tableId),
2121  std::to_string(td.tableId),
2122  cd.columnName,
2131  "",
2134  cd.virtualExpr,
2136  cd.default_value.value_or("NULL")},
2137  types);
2138 
2140  "UPDATE mapd_tables SET ncolumns = ncolumns + 1 WHERE tableid = ?",
2141  std::vector<std::string>{std::to_string(td.tableId)});
2142 
2144  "SELECT columnid FROM mapd_columns WHERE tableid = ? AND name = ?",
2145  std::vector<std::string>{std::to_string(td.tableId), cd.columnName});
2146  cd.columnId = sqliteConnector_.getData<int>(0, 0);
2147 
2148  ++tableDescriptorMapById_[td.tableId]->nColumns;
2149  auto ncd = new ColumnDescriptor(cd);
2150  addToColumnMap(ncd);
2151  columnDescriptorsForRoll.emplace_back(nullptr, ncd);
2152 }
std::string virtualExpr
HOST DEVICE SQLTypes get_subtype() const
Definition: sqltypes.h:330
HOST DEVICE int get_size() const
Definition: sqltypes.h:339
T getData(const int row, const int col)
virtual void query_with_text_params(std::string const &query_only)
void addColumn(const TableDescriptor &td, ColumnDescriptor &cd)
Definition: Catalog.cpp:2092
SqliteConnector sqliteConnector_
Definition: Catalog.h:658
HOST DEVICE int get_scale() const
Definition: sqltypes.h:334
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:329
std::string to_string(char const *&&v)
TableDescriptorMapById tableDescriptorMapById_
Definition: Catalog.h:646
specifies the content in-memory of a row in the column metadata table
std::vector< const TableDescriptor * > getPhysicalTablesDescriptors(const TableDescriptor *logical_table_desc, bool populate_fragmenter=true) const
Definition: Catalog.cpp:4265
std::optional< std::string > default_value
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:337
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:331
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:338
SQLTypeInfo columnType
DictRef addDictionary(ColumnDescriptor &cd)
Definition: Catalog.cpp:1996
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:336
ColumnDescriptorsForRoll columnDescriptorsForRoll
Definition: Catalog.h:677
std::string columnName
void addToColumnMap(ColumnDescriptor *cd)
Definition: Catalog.cpp:5855

+ Here is the call graph for this function:

DictRef Catalog_Namespace::Catalog::addDictionary ( ColumnDescriptor cd)

Definition at line 1996 of file Catalog.cpp.

References CHECK, currentDB_, Catalog_Namespace::DBMetadata::dbId, dictDescriptorMapByRef_, DictDescriptor::dictFolderPath, setColumnDictionary(), string_dict_hosts_, tableDescriptorMapById_, and ColumnDescriptor::tableId.

Referenced by addColumn().

1996  {
1997  cat_write_lock write_lock(this);
1998  const auto& td = *tableDescriptorMapById_[cd.tableId];
1999  list<DictDescriptor> dds;
2000  setColumnDictionary(cd, dds, td, true);
2001  auto& dd = dds.back();
2002  CHECK(dd.dictRef.dictId);
2003 
2004  std::unique_ptr<StringDictionaryClient> client;
2005  if (!string_dict_hosts_.empty()) {
2006  client.reset(new StringDictionaryClient(
2007  string_dict_hosts_.front(), DictRef(currentDB_.dbId, -1), true));
2008  }
2009  if (client) {
2010  client->create(dd.dictRef, dd.dictIsTemp);
2011  }
2012 
2013  DictDescriptor* new_dd = new DictDescriptor(dd);
2014  dictDescriptorMapByRef_[dd.dictRef].reset(new_dd);
2015  if (!dd.dictIsTemp) {
2016  boost::filesystem::create_directory(new_dd->dictFolderPath);
2017  }
2018  return dd.dictRef;
2019 }
std::string dictFolderPath
const std::vector< LeafHostInfo > string_dict_hosts_
Definition: Catalog.h:662
const DBMetadata currentDB_
Definition: Catalog.h:659
DictDescriptorMapById dictDescriptorMapByRef_
Definition: Catalog.h:649
void setColumnDictionary(ColumnDescriptor &cd, std::list< DictDescriptor > &dds, const TableDescriptor &td, bool is_logical_table, bool use_temp_dictionary=false)
Definition: Catalog.cpp:3478
TableDescriptorMapById tableDescriptorMapById_
Definition: Catalog.h:646
struct dict_ref_t DictRef
Definition: DictRef.h:49
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:122
#define CHECK(condition)
Definition: Logger.h:223
Descriptor for a dictionary for a string columne.
mapd_unique_lock< mapd_shared_mutex > write_lock

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Catalog_Namespace::Catalog::addFrontendViewToMap ( DashboardDescriptor vd)
protected

Definition at line 1452 of file Catalog.cpp.

References addFrontendViewToMapNoLock().

1452  {
1453  cat_write_lock write_lock(this);
1455 }
void addFrontendViewToMapNoLock(DashboardDescriptor &vd)
Definition: Catalog.cpp:1457
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:122
mapd_unique_lock< mapd_shared_mutex > write_lock

+ Here is the call graph for this function:

void Catalog_Namespace::Catalog::addFrontendViewToMapNoLock ( DashboardDescriptor vd)
protected

Definition at line 1457 of file Catalog.cpp.

References dashboardDescriptorMap_, DashboardDescriptor::dashboardName, to_string(), and DashboardDescriptor::userId.

Referenced by addFrontendViewToMap().

1457  {
1458  cat_write_lock write_lock(this);
1460  std::make_shared<DashboardDescriptor>(vd);
1461 }
DashboardDescriptorMap dashboardDescriptorMap_
Definition: Catalog.h:650
std::string to_string(char const *&&v)
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:122
mapd_unique_lock< mapd_shared_mutex > write_lock

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Catalog_Namespace::Catalog::addLinkToMap ( LinkDescriptor ld)
protected

Definition at line 1539 of file Catalog.cpp.

References currentDB_, Catalog_Namespace::DBMetadata::dbId, LinkDescriptor::link, linkDescriptorMap_, linkDescriptorMapById_, LinkDescriptor::linkId, and to_string().

1539  {
1540  cat_write_lock write_lock(this);
1541  LinkDescriptor* new_ld = new LinkDescriptor();
1542  *new_ld = ld;
1544  linkDescriptorMapById_[ld.linkId] = new_ld;
1545 }
const DBMetadata currentDB_
Definition: Catalog.h:659
std::string to_string(char const *&&v)
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:122
mapd_unique_lock< mapd_shared_mutex > write_lock
LinkDescriptorMapById linkDescriptorMapById_
Definition: Catalog.h:652
LinkDescriptorMap linkDescriptorMap_
Definition: Catalog.h:651

+ Here is the call graph for this function:

void Catalog_Namespace::Catalog::addReferenceToForeignDict ( ColumnDescriptor referencing_column,
Parser::SharedDictionaryDef  shared_dict_def,
const bool  persist_reference 
)
protected

Definition at line 3387 of file Catalog.cpp.

References CHECK, CHECK_GE, ColumnDescriptor::columnType, SQLTypeInfo::get_comp_param(), Catalog_Namespace::anonymous_namespace{Catalog.cpp}::get_foreign_col(), and to_string().

3389  {
3390  cat_write_lock write_lock(this);
3391  const auto foreign_ref_col = get_foreign_col(*this, shared_dict_def);
3392  CHECK(foreign_ref_col);
3393  referencing_column.columnType = foreign_ref_col->columnType;
3394  const int dict_id = referencing_column.columnType.get_comp_param();
3395  const DictRef dict_ref(currentDB_.dbId, dict_id);
3396  const auto dictIt = dictDescriptorMapByRef_.find(dict_ref);
3397  CHECK(dictIt != dictDescriptorMapByRef_.end());
3398  const auto& dd = dictIt->second;
3399  CHECK_GE(dd->refcount, 1);
3400  ++dd->refcount;
3401  if (persist_reference) {
3402  cat_sqlite_lock sqlite_lock(getObjForLock());
3404  "UPDATE mapd_dictionaries SET refcount = refcount + 1 WHERE dictid = ?",
3405  {std::to_string(dict_id)});
3406  }
3407 }
virtual void query_with_text_params(std::string const &query_only)
SqliteConnector sqliteConnector_
Definition: Catalog.h:658
const DBMetadata currentDB_
Definition: Catalog.h:659
DictDescriptorMapById dictDescriptorMapByRef_
Definition: Catalog.h:649
#define CHECK_GE(x, y)
Definition: Logger.h:236
const ColumnDescriptor * get_foreign_col(const Catalog &cat, const Parser::SharedDictionaryDef &shared_dict_def)
Definition: Catalog.cpp:3375
std::string to_string(char const *&&v)
const Catalog * getObjForLock()
Definition: Catalog.cpp:240
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:122
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:338
#define CHECK(condition)
Definition: Logger.h:223
mapd_unique_lock< mapd_shared_mutex > write_lock
SQLTypeInfo columnType
sqlite_lock< Catalog > cat_sqlite_lock
Definition: Catalog.cpp:123

+ Here is the call graph for this function:

void Catalog_Namespace::Catalog::addTableToMap ( const TableDescriptor td,
const std::list< ColumnDescriptor > &  columns,
const std::list< DictDescriptor > &  dicts 
)
protected

Definition at line 1313 of file Catalog.cpp.

References anonymous_namespace{Utm.h}::a, addToColumnMap(), CHECK, TableDescriptor::columnIdBySpi_, currentDB_, Catalog_Namespace::DBMetadata::dbId, dictDescriptorMapByRef_, DictDescriptor::dictFolderPath, dict_ref_t::dictId, TableDescriptor::hasDeletedCol, TableDescriptor::mutex_, setDeletedColumnUnlocked(), gpu_enabled::sort(), string_dict_hosts_, tableDescriptorMap_, tableDescriptorMapById_, TableDescriptor::tableId, TableDescriptor::tableName, and to_upper().

Referenced by createTable().

1315  {
1316  cat_write_lock write_lock(this);
1317  TableDescriptor* new_td;
1318 
1319  auto foreign_table = dynamic_cast<const foreign_storage::ForeignTable*>(td);
1320  if (foreign_table) {
1321  auto new_foreign_table = new foreign_storage::ForeignTable();
1322  *new_foreign_table = *foreign_table;
1323  new_td = new_foreign_table;
1324  } else {
1325  new_td = new TableDescriptor();
1326  *new_td = *td;
1327  }
1328 
1329  new_td->mutex_ = std::make_shared<std::mutex>();
1330  tableDescriptorMap_[to_upper(td->tableName)] = new_td;
1331  tableDescriptorMapById_[td->tableId] = new_td;
1332  for (auto cd : columns) {
1333  ColumnDescriptor* new_cd = new ColumnDescriptor();
1334  *new_cd = cd;
1335  addToColumnMap(new_cd);
1336 
1337  // Add deleted column to the map
1338  if (cd.isDeletedCol) {
1339  CHECK(new_td->hasDeletedCol);
1340  setDeletedColumnUnlocked(new_td, new_cd);
1341  }
1342  }
1343 
1344  std::sort(new_td->columnIdBySpi_.begin(),
1345  new_td->columnIdBySpi_.end(),
1346  [](const size_t a, const size_t b) -> bool { return a < b; });
1347 
1348  std::unique_ptr<StringDictionaryClient> client;
1349  DictRef dict_ref(currentDB_.dbId, -1);
1350  if (!string_dict_hosts_.empty()) {
1351  client.reset(new StringDictionaryClient(string_dict_hosts_.front(), dict_ref, true));
1352  }
1353  for (auto dd : dicts) {
1354  if (!dd.dictRef.dictId) {
1355  // Dummy entry created for a shard of a logical table, nothing to do.
1356  continue;
1357  }
1358  dict_ref.dictId = dd.dictRef.dictId;
1359  if (client) {
1360  client->create(dict_ref, dd.dictIsTemp);
1361  }
1362  DictDescriptor* new_dd = new DictDescriptor(dd);
1363  dictDescriptorMapByRef_[dict_ref].reset(new_dd);
1364  if (!dd.dictIsTemp) {
1365  boost::filesystem::create_directory(new_dd->dictFolderPath);
1366  }
1367  }
1368 }
std::string dictFolderPath
std::string tableName
const std::vector< LeafHostInfo > string_dict_hosts_
Definition: Catalog.h:662
const DBMetadata currentDB_
Definition: Catalog.h:659
DictDescriptorMapById dictDescriptorMapByRef_
Definition: Catalog.h:649
DEVICE void sort(ARGS &&...args)
Definition: gpu_enabled.h:105
std::vector< int > columnIdBySpi_
std::shared_ptr< std::mutex > mutex_
constexpr double a
Definition: Utm.h:32
void setDeletedColumnUnlocked(const TableDescriptor *td, const ColumnDescriptor *cd)
Definition: Catalog.cpp:3366
TableDescriptorMapById tableDescriptorMapById_
Definition: Catalog.h:646
specifies the content in-memory of a row in the column metadata table
std::string to_upper(const std::string &str)
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:122
#define CHECK(condition)
Definition: Logger.h:223
Descriptor for a dictionary for a string columne.
mapd_unique_lock< mapd_shared_mutex > write_lock
void addToColumnMap(ColumnDescriptor *cd)
Definition: Catalog.cpp:5855
TableDescriptorMap tableDescriptorMap_
Definition: Catalog.h:645

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Catalog_Namespace::Catalog::addToColumnMap ( ColumnDescriptor cd)
private

Definition at line 5855 of file Catalog.cpp.

References ColumnDescriptor::columnId, ColumnDescriptor::columnName, ColumnDescriptor::columnType, SQLTypeInfo::is_dict_encoded_type(), ColumnDescriptor::tableId, and to_upper().

Referenced by addColumn(), addTableToMap(), buildColumnsMapUnlocked(), and roll().

5855  {
5858  if (cd->columnType.is_dict_encoded_type()) {
5859  dict_columns_by_table_id_[cd->tableId].emplace(cd);
5860  }
5861 }
TableDictColumnsMap dict_columns_by_table_id_
Definition: Catalog.h:656
std::tuple< int, std::string > ColumnKey
Definition: Types.h:37
ColumnDescriptorMap columnDescriptorMap_
Definition: Catalog.h:647
ColumnDescriptorMapById columnDescriptorMapById_
Definition: Catalog.h:648
bool is_dict_encoded_type() const
Definition: sqltypes.h:560
std::string to_upper(const std::string &str)
SQLTypeInfo columnType
std::string columnName
std::tuple< int, int > ColumnIdKey
Definition: Types.h:39

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Catalog_Namespace::Catalog::adjustAlteredTableFiles ( const std::string &  temp_data_dir,
const std::unordered_map< int, int > &  all_column_ids_map 
) const
private
void Catalog_Namespace::Catalog::alterPhysicalTableMetadata ( const TableDescriptor td,
const TableDescriptorUpdateParams table_update_params 
)
private

Definition at line 3100 of file Catalog.cpp.

References CHECK, TableDescriptorUpdateParams::max_rollback_epochs, TableDescriptorUpdateParams::max_rows, TableDescriptor::maxRollbackEpochs, TableDescriptor::maxRows, TableDescriptor::tableId, and to_string().

3102  {
3103  // Only called from parent alterTableParamMetadata, expect already to have catalog and
3104  // sqlite write locks
3105 
3106  // Sqlite transaction should have already been begun in parent alterTableCatalogMetadata
3107 
3109  CHECK(mutable_td);
3110  if (td->maxRollbackEpochs != table_update_params.max_rollback_epochs) {
3112  "UPDATE mapd_tables SET max_rollback_epochs = ? WHERE tableid = ?",
3113  std::vector<std::string>{std::to_string(table_update_params.max_rollback_epochs),
3114  std::to_string(td->tableId)});
3115  mutable_td->maxRollbackEpochs = table_update_params.max_rollback_epochs;
3116  }
3117 
3118  if (td->maxRows != table_update_params.max_rows) {
3120  "UPDATE mapd_tables SET max_rows = ? WHERE tableid = ?",
3121  std::vector<std::string>{std::to_string(table_update_params.max_rows),
3122  std::to_string(td->tableId)});
3123  mutable_td->maxRows = table_update_params.max_rows;
3124  }
3125 }
int32_t maxRollbackEpochs
virtual void query_with_text_params(std::string const &query_only)
SqliteConnector sqliteConnector_
Definition: Catalog.h:658
TableDescriptor * getMutableMetadataForTableUnlocked(int table_id) const
Definition: Catalog.cpp:1665
std::string to_string(char const *&&v)
#define CHECK(condition)
Definition: Logger.h:223

+ Here is the call graph for this function:

void Catalog_Namespace::Catalog::alterTableMetadata ( const TableDescriptor td,
const TableDescriptorUpdateParams table_update_params 
)
private

Definition at line 3127 of file Catalog.cpp.

References CHECK, logger::FATAL, LOG, TableDescriptor::tableId, and TableDescriptor::tableName.

3128  {
3129  cat_write_lock write_lock(this);
3130  cat_sqlite_lock sqlite_lock(getObjForLock());
3131  sqliteConnector_.query("BEGIN TRANSACTION");
3132  try {
3133  const auto physical_table_it = logicalToPhysicalTableMapById_.find(td->tableId);
3134  if (physical_table_it != logicalToPhysicalTableMapById_.end()) {
3135  const auto physical_tables = physical_table_it->second;
3136  CHECK(!physical_tables.empty());
3137  for (size_t i = 0; i < physical_tables.size(); i++) {
3138  int32_t physical_tb_id = physical_tables[i];
3139  const TableDescriptor* phys_td = getMetadataForTable(physical_tb_id, false);
3140  CHECK(phys_td);
3141  alterPhysicalTableMetadata(phys_td, table_update_params);
3142  }
3143  }
3144  alterPhysicalTableMetadata(td, table_update_params);
3145  } catch (std::exception& e) {
3146  sqliteConnector_.query("ROLLBACK TRANSACTION");
3147  LOG(FATAL) << "Table '" << td->tableName << "' catalog update failed";
3148  }
3149  sqliteConnector_.query("END TRANSACTION");
3150 }
std::string tableName
#define LOG(tag)
Definition: Logger.h:217
SqliteConnector sqliteConnector_
Definition: Catalog.h:658
virtual void query(const std::string &queryString)
void alterPhysicalTableMetadata(const TableDescriptor *td, const TableDescriptorUpdateParams &table_update_params)
Definition: Catalog.cpp:3100
const Catalog * getObjForLock()
Definition: Catalog.cpp:240
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:122
#define CHECK(condition)
Definition: Logger.h:223
mapd_unique_lock< mapd_shared_mutex > write_lock
const TableDescriptor * getMetadataForTable(const std::string &tableName, const bool populateFragmenter=true) const
Returns a pointer to a const TableDescriptor struct matching the provided tableName.
sqlite_lock< Catalog > cat_sqlite_lock
Definition: Catalog.cpp:123
LogicalToPhysicalTableMapById logicalToPhysicalTableMapById_
Definition: Catalog.h:665
void Catalog_Namespace::Catalog::buildColumnsMapUnlocked ( )
private

Definition at line 1116 of file Catalog.cpp.

References anonymous_namespace{Utm.h}::a, addToColumnMap(), CHECK, ColumnDescriptor::chunks, ColumnDescriptor::columnId, ColumnDescriptor::columnName, ColumnDescriptor::columnType, ColumnDescriptor::default_value, SQLTypeInfo::get_physical_cols(), SqliteConnector::getData(), SqliteConnector::getNumRows(), SQLTypeInfo::is_geometry(), ColumnDescriptor::isDeletedCol, ColumnDescriptor::isGeoPhyCol, SqliteConnector::isNull(), ColumnDescriptor::isSystemCol, ColumnDescriptor::isVirtualCol, SqliteConnector::query(), SQLTypeInfo::set_comp_param(), SQLTypeInfo::set_compression(), SQLTypeInfo::set_dimension(), SQLTypeInfo::set_notnull(), SQLTypeInfo::set_scale(), SQLTypeInfo::set_size(), SQLTypeInfo::set_subtype(), SQLTypeInfo::set_type(), setDeletedColumnUnlocked(), gpu_enabled::sort(), sqliteConnector_, tableDescriptorMapById_, ColumnDescriptor::tableId, and ColumnDescriptor::virtualExpr.

Referenced by buildMaps().

1116  {
1117  std::string columnQuery(
1118  "SELECT tableid, columnid, name, coltype, colsubtype, coldim, colscale, "
1119  "is_notnull, compression, comp_param, "
1120  "size, chunks, is_systemcol, is_virtualcol, virtual_expr, is_deletedcol, "
1121  "default_value from "
1122  "mapd_columns ORDER BY tableid, "
1123  "columnid");
1124  sqliteConnector_.query(columnQuery);
1125  auto numRows = sqliteConnector_.getNumRows();
1126  int32_t skip_physical_cols = 0;
1127  for (size_t r = 0; r < numRows; ++r) {
1128  ColumnDescriptor* cd = new ColumnDescriptor();
1129  cd->tableId = sqliteConnector_.getData<int>(r, 0);
1130  cd->columnId = sqliteConnector_.getData<int>(r, 1);
1131  cd->columnName = sqliteConnector_.getData<string>(r, 2);
1135  cd->columnType.set_scale(sqliteConnector_.getData<int>(r, 6));
1139  cd->columnType.set_size(sqliteConnector_.getData<int>(r, 10));
1140  cd->chunks = sqliteConnector_.getData<string>(r, 11);
1141  cd->isSystemCol = sqliteConnector_.getData<bool>(r, 12);
1142  cd->isVirtualCol = sqliteConnector_.getData<bool>(r, 13);
1143  cd->virtualExpr = sqliteConnector_.getData<string>(r, 14);
1144  cd->isDeletedCol = sqliteConnector_.getData<bool>(r, 15);
1145  if (sqliteConnector_.isNull(r, 16)) {
1146  cd->default_value = std::nullopt;
1147  } else {
1148  cd->default_value = std::make_optional(sqliteConnector_.getData<string>(r, 16));
1149  }
1150  cd->isGeoPhyCol = skip_physical_cols > 0;
1151  addToColumnMap(cd);
1152 
1153  if (skip_physical_cols <= 0) {
1154  skip_physical_cols = cd->columnType.get_physical_cols();
1155  }
1156 
1157  auto td_itr = tableDescriptorMapById_.find(cd->tableId);
1158  CHECK(td_itr != tableDescriptorMapById_.end());
1159 
1160  if (cd->isDeletedCol) {
1161  td_itr->second->hasDeletedCol = true;
1162  setDeletedColumnUnlocked(td_itr->second, cd);
1163  } else if (cd->columnType.is_geometry() || skip_physical_cols-- <= 0) {
1164  tableDescriptorMapById_[cd->tableId]->columnIdBySpi_.push_back(cd->columnId);
1165  }
1166  }
1167 
1168  // sort columnIdBySpi_ based on columnId
1169  for (auto& tit : tableDescriptorMapById_) {
1170  std::sort(tit.second->columnIdBySpi_.begin(),
1171  tit.second->columnIdBySpi_.end(),
1172  [](const size_t a, const size_t b) -> bool { return a < b; });
1173  }
1174 } // namespace Catalog_Namespace
std::string virtualExpr
void set_compression(EncodingType c)
Definition: sqltypes.h:440
void set_size(int s)
Definition: sqltypes.h:437
T getData(const int row, const int col)
SQLTypes
Definition: sqltypes.h:38
SqliteConnector sqliteConnector_
Definition: Catalog.h:658
HOST DEVICE void set_subtype(SQLTypes st)
Definition: sqltypes.h:430
DEVICE void sort(ARGS &&...args)
Definition: gpu_enabled.h:105
virtual void query(const std::string &queryString)
std::string chunks
constexpr double a
Definition: Utm.h:32
EncodingType
Definition: sqltypes.h:233
int get_physical_cols() const
Definition: sqltypes.h:360
void set_scale(int s)
Definition: sqltypes.h:434
void setDeletedColumnUnlocked(const TableDescriptor *td, const ColumnDescriptor *cd)
Definition: Catalog.cpp:3366
TableDescriptorMapById tableDescriptorMapById_
Definition: Catalog.h:646
specifies the content in-memory of a row in the column metadata table
void set_comp_param(int p)
Definition: sqltypes.h:441
std::optional< std::string > default_value
bool isNull(const int row, const int col) const
void set_dimension(int d)
Definition: sqltypes.h:431
void set_notnull(bool n)
Definition: sqltypes.h:436
#define CHECK(condition)
Definition: Logger.h:223
bool is_geometry() const
Definition: sqltypes.h:522
SQLTypeInfo columnType
std::string columnName
void addToColumnMap(ColumnDescriptor *cd)
Definition: Catalog.cpp:5855
virtual size_t getNumRows() const
HOST DEVICE void set_type(SQLTypes t)
Definition: sqltypes.h:429

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Catalog_Namespace::Catalog::buildCustomExpressionsMapUnlocked ( )
private

Definition at line 1285 of file Catalog.cpp.

References custom_expr_map_by_id_, getCustomExpressionFromConnector(), SqliteConnector::getNumRows(), SqliteConnector::query(), and sqliteConnector_.

Referenced by buildMaps().

1285  {
1287  "SELECT id, name, expression_json, data_source_type, data_source_id, "
1288  "is_deleted "
1289  "FROM omnisci_custom_expressions");
1290  auto num_rows = sqliteConnector_.getNumRows();
1291  for (size_t row = 0; row < num_rows; row++) {
1292  auto custom_expr = getCustomExpressionFromConnector(row);
1293  custom_expr_map_by_id_[custom_expr->id] = std::move(custom_expr);
1294  }
1295 }
SqliteConnector sqliteConnector_
Definition: Catalog.h:658
virtual void query(const std::string &queryString)
std::unique_ptr< CustomExpression > getCustomExpressionFromConnector(size_t row)
Definition: Catalog.cpp:1297
CustomExpressionMapById custom_expr_map_by_id_
Definition: Catalog.h:655
virtual size_t getNumRows() const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Catalog_Namespace::Catalog::buildDashboardsMapUnlocked ( const std::map< int32_t, std::string > &  user_name_by_user_id)
private

Definition at line 1188 of file Catalog.cpp.

References currentDB_, dashboardDescriptorMap_, Catalog_Namespace::DBMetadata::dbId, generate_dashboard_system_rolename(), Catalog_Namespace::anonymous_namespace{Catalog.cpp}::get_user_name_from_id(), SqliteConnector::getData(), SqliteConnector::getNumRows(), SqliteConnector::query(), sqliteConnector_, and to_string().

Referenced by buildMaps().

1189  {
1190  std::string frontendViewQuery(
1191  "SELECT id, state, name, image_hash, strftime('%Y-%m-%dT%H:%M:%SZ', update_time), "
1192  "userid, "
1193  "metadata "
1194  "FROM mapd_dashboards");
1195  sqliteConnector_.query(frontendViewQuery);
1196  auto numRows = sqliteConnector_.getNumRows();
1197  for (size_t r = 0; r < numRows; ++r) {
1198  auto vd = std::make_shared<DashboardDescriptor>();
1199  vd->dashboardId = sqliteConnector_.getData<int>(r, 0);
1200  vd->dashboardState = sqliteConnector_.getData<string>(r, 1);
1201  vd->dashboardName = sqliteConnector_.getData<string>(r, 2);
1202  vd->imageHash = sqliteConnector_.getData<string>(r, 3);
1203  vd->updateTime = sqliteConnector_.getData<string>(r, 4);
1204  vd->userId = sqliteConnector_.getData<int>(r, 5);
1205  vd->dashboardMetadata = sqliteConnector_.getData<string>(r, 6);
1206  vd->user = get_user_name_from_id(vd->userId, user_name_by_user_id);
1207  vd->dashboardSystemRoleName = generate_dashboard_system_rolename(
1209  dashboardDescriptorMap_[std::to_string(vd->userId) + ":" + vd->dashboardName] = vd;
1210  }
1211 }
T getData(const int row, const int col)
SqliteConnector sqliteConnector_
Definition: Catalog.h:658
const DBMetadata currentDB_
Definition: Catalog.h:659
virtual void query(const std::string &queryString)
DashboardDescriptorMap dashboardDescriptorMap_
Definition: Catalog.h:650
std::string to_string(char const *&&v)
std::string get_user_name_from_id(int32_t id, const std::map< int32_t, std::string > &user_name_by_user_id)
Definition: Catalog.cpp:1025
virtual size_t getNumRows() const
std::string generate_dashboard_system_rolename(const std::string &db_id, const std::string &dash_id)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Catalog_Namespace::Catalog::buildDictionaryMapUnlocked ( )
private

Definition at line 1037 of file Catalog.cpp.

References currentDB_, Catalog_Namespace::DBMetadata::dbId, dictDescriptorMapByRef_, g_base_path, SqliteConnector::getData(), SqliteConnector::getNumRows(), shared::kDataDirectoryName, SqliteConnector::query(), sqliteConnector_, and to_string().

Referenced by buildMaps().

1037  {
1038  std::string dictQuery(
1039  "SELECT dictid, name, nbits, is_shared, refcount from mapd_dictionaries");
1040  sqliteConnector_.query(dictQuery);
1041  auto numRows = sqliteConnector_.getNumRows();
1042  for (size_t r = 0; r < numRows; ++r) {
1043  auto dictId = sqliteConnector_.getData<int>(r, 0);
1044  auto dictName = sqliteConnector_.getData<string>(r, 1);
1045  auto dictNBits = sqliteConnector_.getData<int>(r, 2);
1046  auto is_shared = sqliteConnector_.getData<bool>(r, 3);
1047  auto refcount = sqliteConnector_.getData<int>(r, 4);
1048  auto fname = g_base_path + "/" + shared::kDataDirectoryName + "/DB_" +
1049  std::to_string(currentDB_.dbId) + "_DICT_" + std::to_string(dictId);
1050  DictRef dict_ref(currentDB_.dbId, dictId);
1051  auto dd = new DictDescriptor(
1052  dict_ref, dictName, dictNBits, is_shared, refcount, fname, false);
1053  dictDescriptorMapByRef_[dict_ref].reset(dd);
1054  }
1055 }
const std::string kDataDirectoryName
T getData(const int row, const int col)
SqliteConnector sqliteConnector_
Definition: Catalog.h:658
const DBMetadata currentDB_
Definition: Catalog.h:659
DictDescriptorMapById dictDescriptorMapByRef_
Definition: Catalog.h:649
virtual void query(const std::string &queryString)
std::string to_string(char const *&&v)
std::string g_base_path
Definition: SysCatalog.cpp:64
Descriptor for a dictionary for a string columne.
virtual size_t getNumRows() const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Catalog_Namespace::Catalog::buildForeignServerMapUnlocked ( )
private

Definition at line 4488 of file Catalog.cpp.

References CHECK, and g_enable_fsi.

Referenced by buildMaps().

4488  {
4491  "SELECT id, name, data_wrapper_type, options, owner_user_id, creation_time FROM "
4492  "omnisci_foreign_servers");
4493  auto num_rows = sqliteConnector_.getNumRows();
4494 
4495  for (size_t row = 0; row < num_rows; row++) {
4496  auto foreign_server = std::make_shared<foreign_storage::ForeignServer>(
4497  sqliteConnector_.getData<int>(row, 0),
4498  sqliteConnector_.getData<std::string>(row, 1),
4499  sqliteConnector_.getData<std::string>(row, 2),
4500  sqliteConnector_.getData<std::string>(row, 3),
4501  sqliteConnector_.getData<std::int32_t>(row, 4),
4502  sqliteConnector_.getData<std::int32_t>(row, 5));
4503  foreignServerMap_[foreign_server->name] = foreign_server;
4504  foreignServerMapById_[foreign_server->id] = foreign_server;
4505  }
4506 }
T getData(const int row, const int col)
SqliteConnector sqliteConnector_
Definition: Catalog.h:658
virtual void query(const std::string &queryString)
ForeignServerMapById foreignServerMapById_
Definition: Catalog.h:654
ForeignServerMap foreignServerMap_
Definition: Catalog.h:653
#define CHECK(condition)
Definition: Logger.h:223
bool g_enable_fsi
Definition: Catalog.cpp:97
virtual size_t getNumRows() const

+ Here is the caller graph for this function:

void Catalog_Namespace::Catalog::buildLinksMapUnlocked ( )
private

Definition at line 1213 of file Catalog.cpp.

References currentDB_, Catalog_Namespace::DBMetadata::dbId, SqliteConnector::getData(), SqliteConnector::getNumRows(), linkDescriptorMap_, linkDescriptorMapById_, SqliteConnector::query(), sqliteConnector_, and to_string().

Referenced by buildMaps().

1213  {
1214  std::string linkQuery(
1215  "SELECT linkid, userid, link, view_state, strftime('%Y-%m-%dT%H:%M:%SZ', "
1216  "update_time), view_metadata "
1217  "FROM mapd_links");
1218  sqliteConnector_.query(linkQuery);
1219  auto numRows = sqliteConnector_.getNumRows();
1220  for (size_t r = 0; r < numRows; ++r) {
1221  auto ld = new LinkDescriptor();
1222  ld->linkId = sqliteConnector_.getData<int>(r, 0);
1223  ld->userId = sqliteConnector_.getData<int>(r, 1);
1224  ld->link = sqliteConnector_.getData<string>(r, 2);
1225  ld->viewState = sqliteConnector_.getData<string>(r, 3);
1226  ld->updateTime = sqliteConnector_.getData<string>(r, 4);
1227  ld->viewMetadata = sqliteConnector_.getData<string>(r, 5);
1229  linkDescriptorMapById_[ld->linkId] = ld;
1230  }
1231 }
T getData(const int row, const int col)
SqliteConnector sqliteConnector_
Definition: Catalog.h:658
const DBMetadata currentDB_
Definition: Catalog.h:659
virtual void query(const std::string &queryString)
std::string to_string(char const *&&v)
LinkDescriptorMapById linkDescriptorMapById_
Definition: Catalog.h:652
virtual size_t getNumRows() const
LinkDescriptorMap linkDescriptorMap_
Definition: Catalog.h:651

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Catalog_Namespace::Catalog::buildLogicalToPhysicalMapUnlocked ( )
private

Definition at line 1233 of file Catalog.cpp.

References CHECK, SqliteConnector::getData(), SqliteConnector::getNumRows(), logicalToPhysicalTableMapById_, SqliteConnector::query(), and sqliteConnector_.

Referenced by buildMaps().

1233  {
1234  /* rebuild map linking logical tables to corresponding physical ones */
1235  std::string logicalToPhysicalTableMapQuery(
1236  "SELECT logical_table_id, physical_table_id "
1237  "FROM mapd_logical_to_physical");
1238  sqliteConnector_.query(logicalToPhysicalTableMapQuery);
1239  auto numRows = sqliteConnector_.getNumRows();
1240  for (size_t r = 0; r < numRows; ++r) {
1241  auto logical_tb_id = sqliteConnector_.getData<int>(r, 0);
1242  auto physical_tb_id = sqliteConnector_.getData<int>(r, 1);
1243  const auto physicalTableIt = logicalToPhysicalTableMapById_.find(logical_tb_id);
1244  if (physicalTableIt == logicalToPhysicalTableMapById_.end()) {
1245  /* add new entity to the map logicalToPhysicalTableMapById_ */
1246  std::vector<int32_t> physicalTables{physical_tb_id};
1247  const auto it_ok =
1248  logicalToPhysicalTableMapById_.emplace(logical_tb_id, physicalTables);
1249  CHECK(it_ok.second);
1250  } else {
1251  /* update map logicalToPhysicalTableMapById_ */
1252  physicalTableIt->second.push_back(physical_tb_id);
1253  }
1254  }
1255 }
T getData(const int row, const int col)
SqliteConnector sqliteConnector_
Definition: Catalog.h:658
virtual void query(const std::string &queryString)
#define CHECK(condition)
Definition: Logger.h:223
virtual size_t getNumRows() const
LogicalToPhysicalTableMapById logicalToPhysicalTableMapById_
Definition: Catalog.h:665

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Catalog_Namespace::Catalog::buildMaps ( )
protected

Definition at line 1260 of file Catalog.cpp.

References buildColumnsMapUnlocked(), buildCustomExpressionsMapUnlocked(), buildDashboardsMapUnlocked(), buildDictionaryMapUnlocked(), buildForeignServerMapUnlocked(), buildLinksMapUnlocked(), buildLogicalToPhysicalMapUnlocked(), buildTablesMapUnlocked(), g_enable_fsi, Catalog_Namespace::anonymous_namespace{Catalog.cpp}::get_user_id_to_user_name_map(), getObjForLock(), updateForeignTablesInMapUnlocked(), and updateViewsInMapUnlocked().

1260  {
1261  // Get all user id to username mapping here in order to avoid making a call to
1262  // SysCatalog (and attempting to acquire SysCatalog locks) while holding locks for this
1263  // catalog.
1264  const auto user_name_by_user_id = get_user_id_to_user_name_map();
1265 
1266  cat_write_lock write_lock(this);
1267  cat_sqlite_lock sqlite_lock(getObjForLock());
1268 
1271 
1272  if (g_enable_fsi) {
1275  }
1276 
1279  buildDashboardsMapUnlocked(user_name_by_user_id);
1283 }
void buildLogicalToPhysicalMapUnlocked()
Definition: Catalog.cpp:1233
void buildDashboardsMapUnlocked(const std::map< int32_t, std::string > &user_name_by_user_id)
Definition: Catalog.cpp:1188
void buildCustomExpressionsMapUnlocked()
Definition: Catalog.cpp:1285
const Catalog * getObjForLock()
Definition: Catalog.cpp:240
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:122
std::map< int32_t, std::string > get_user_id_to_user_name_map()
Definition: Catalog.cpp:1016
void updateForeignTablesInMapUnlocked()
Definition: Catalog.cpp:4508
mapd_unique_lock< mapd_shared_mutex > write_lock
sqlite_lock< Catalog > cat_sqlite_lock
Definition: Catalog.cpp:123
bool g_enable_fsi
Definition: Catalog.cpp:97

+ Here is the call graph for this function:

void Catalog_Namespace::Catalog::buildTablesMapUnlocked ( )
private

Definition at line 1057 of file Catalog.cpp.

References currentDB_, Catalog_Namespace::DBMetadata::dbName, logger::FATAL, StorageType::FOREIGN_TABLE, TableDescriptor::fragmenter, TableDescriptor::fragments, TableDescriptor::fragPageSize, TableDescriptor::fragType, SqliteConnector::getData(), SqliteConnector::getNumRows(), TableDescriptor::hasDeletedCol, TableDescriptor::is_system_table, SqliteConnector::isNull(), TableDescriptor::isView, TableDescriptor::keyMetainfo, LOG, TableDescriptor::maxChunkSize, TableDescriptor::maxFragRows, TableDescriptor::maxRollbackEpochs, TableDescriptor::maxRows, TableDescriptor::nColumns, TableDescriptor::nShards, TableDescriptor::partitions, SqliteConnector::query(), TableDescriptor::shard, TableDescriptor::shardedColumnId, TableDescriptor::sortedColumnId, sqliteConnector_, TableDescriptor::storageType, tableDescriptorMap_, tableDescriptorMapById_, TableDescriptor::tableId, TableDescriptor::tableName, to_upper(), and TableDescriptor::userId.

Referenced by buildMaps().

1057  {
1058  std::string tableQuery(
1059  "SELECT tableid, name, ncolumns, isview, fragments, frag_type, max_frag_rows, "
1060  "max_chunk_size, frag_page_size, "
1061  "max_rows, partitions, shard_column_id, shard, num_shards, key_metainfo, userid, "
1062  "sort_column_id, storage_type, max_rollback_epochs, is_system_table "
1063  "from mapd_tables");
1064  sqliteConnector_.query(tableQuery);
1065  auto numRows = sqliteConnector_.getNumRows();
1066  for (size_t r = 0; r < numRows; ++r) {
1067  TableDescriptor* td;
1068  const auto& storage_type = sqliteConnector_.getData<string>(r, 17);
1069  if (!storage_type.empty() && storage_type != StorageType::FOREIGN_TABLE) {
1070  const auto table_id = sqliteConnector_.getData<int>(r, 0);
1071  const auto& table_name = sqliteConnector_.getData<string>(r, 1);
1072  LOG(FATAL) << "Unable to read Catalog metadata: storage type is currently not a "
1073  "supported table option (table "
1074  << table_name << " [" << table_id << "] in database "
1075  << currentDB_.dbName << ").";
1076  }
1077 
1078  if (storage_type == StorageType::FOREIGN_TABLE) {
1079  td = new foreign_storage::ForeignTable();
1080  } else {
1081  td = new TableDescriptor();
1082  }
1083 
1084  td->storageType = storage_type;
1085  td->tableId = sqliteConnector_.getData<int>(r, 0);
1086  td->tableName = sqliteConnector_.getData<string>(r, 1);
1087  td->nColumns = sqliteConnector_.getData<int>(r, 2);
1088  td->isView = sqliteConnector_.getData<bool>(r, 3);
1089  td->fragments = sqliteConnector_.getData<string>(r, 4);
1090  td->fragType =
1092  td->maxFragRows = sqliteConnector_.getData<int>(r, 6);
1093  td->maxChunkSize = sqliteConnector_.getData<int64_t>(r, 7);
1094  td->fragPageSize = sqliteConnector_.getData<int>(r, 8);
1095  td->maxRows = sqliteConnector_.getData<int64_t>(r, 9);
1096  td->partitions = sqliteConnector_.getData<string>(r, 10);
1097  td->shardedColumnId = sqliteConnector_.getData<int>(r, 11);
1098  td->shard = sqliteConnector_.getData<int>(r, 12);
1099  td->nShards = sqliteConnector_.getData<int>(r, 13);
1100  td->keyMetainfo = sqliteConnector_.getData<string>(r, 14);
1101  td->userId = sqliteConnector_.getData<int>(r, 15);
1102  td->sortedColumnId =
1103  sqliteConnector_.isNull(r, 16) ? 0 : sqliteConnector_.getData<int>(r, 16);
1104  if (!td->isView) {
1105  td->fragmenter = nullptr;
1106  }
1107  td->maxRollbackEpochs = sqliteConnector_.getData<int>(r, 18);
1108  td->is_system_table = sqliteConnector_.getData<bool>(r, 19);
1109  td->hasDeletedCol = false;
1110 
1112  tableDescriptorMapById_[td->tableId] = td;
1113  }
1114 }
int32_t maxRollbackEpochs
std::string partitions
T getData(const int row, const int col)
std::string tableName
#define LOG(tag)
Definition: Logger.h:217
SqliteConnector sqliteConnector_
Definition: Catalog.h:658
const DBMetadata currentDB_
Definition: Catalog.h:659
std::string storageType
virtual void query(const std::string &queryString)
std::string fragments
TableDescriptorMapById tableDescriptorMapById_
Definition: Catalog.h:646
std::string keyMetainfo
std::shared_ptr< Fragmenter_Namespace::AbstractFragmenter > fragmenter
std::string to_upper(const std::string &str)
bool isNull(const int row, const int col) const
Fragmenter_Namespace::FragmenterType fragType
static constexpr char const * FOREIGN_TABLE
virtual size_t getNumRows() const
TableDescriptorMap tableDescriptorMap_
Definition: Catalog.h:645

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string Catalog_Namespace::Catalog::calculateSHA1 ( const std::string &  data)
protected

Definition at line 4197 of file Catalog.cpp.

4197  {
4198  boost::uuids::detail::sha1 sha1;
4199  unsigned int digest[5];
4200  sha1.process_bytes(data.c_str(), data.length());
4201  sha1.get_digest(digest);
4202  std::stringstream ss;
4203  for (size_t i = 0; i < 5; i++) {
4204  ss << std::hex << digest[i];
4205  }
4206  return ss.str();
4207 }
void Catalog_Namespace::Catalog::changeForeignServerOwner ( const std::string &  server_name,
const int  new_owner_id 
)

Change the owner of a Foreign Server to a new owner.

Parameters
server_name- Name of the foreign server whose owner to change
new_owner_id- New owner's user id

Definition at line 2823 of file Catalog.cpp.

References CHECK, to_string(), and foreign_storage::ForeignServer::user_id.

2824  {
2825  cat_write_lock write_lock(this);
2826  foreign_storage::ForeignServer* foreign_server =
2827  foreignServerMap_.find(server_name)->second.get();
2828  CHECK(foreign_server);
2829  setForeignServerProperty(server_name, "owner_user_id", std::to_string(new_owner_id));
2830  // update in-memory server
2831  foreign_server->user_id = new_owner_id;
2832 }
std::string to_string(char const *&&v)
ForeignServerMap foreignServerMap_
Definition: Catalog.h:653
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:122
#define CHECK(condition)
Definition: Logger.h:223
mapd_unique_lock< mapd_shared_mutex > write_lock
void setForeignServerProperty(const std::string &server_name, const std::string &property, const std::string &value)
Definition: Catalog.cpp:4533

+ Here is the call graph for this function:

void Catalog_Namespace::Catalog::CheckAndExecuteMigrations ( )
protected

Definition at line 988 of file Catalog.cpp.

References g_enable_fsi, recordOwnershipOfObjectsInObjectPermissions(), renameLegacyDataWrappers(), updateCustomExpressionsSchema(), updateDefaultColumnValues(), updateDeletedColumnIndicator(), updateDictionaryNames(), updateDictionarySchema(), updateFixlenArrayColumns(), updateFrontendViewAndLinkUsers(), updateFrontendViewSchema(), updateFrontendViewsToDashboards(), updateFsiSchemas(), updateGeoColumns(), updateLinkSchema(), updateLogicalToPhysicalTableLinkSchema(), updatePageSize(), and updateTableDescriptorSchema().

988  {
998  updatePageSize();
1002  if (g_enable_fsi) {
1003  updateFsiSchemas();
1005  }
1008 }
void updateFrontendViewAndLinkUsers()
Definition: Catalog.cpp:451
void recordOwnershipOfObjectsInObjectPermissions()
Definition: Catalog.cpp:778
void updateFrontendViewsToDashboards()
Definition: Catalog.cpp:129
void updateCustomExpressionsSchema()
Definition: Catalog.cpp:744
void updateLogicalToPhysicalTableLinkSchema()
Definition: Catalog.cpp:612
bool g_enable_fsi
Definition: Catalog.cpp:97

+ Here is the call graph for this function:

void Catalog_Namespace::Catalog::CheckAndExecuteMigrationsPostBuildMaps ( )
protected

Definition at line 1010 of file Catalog.cpp.

References checkDateInDaysColumnMigration(), and createDashboardSystemRoles().

1010  {
1013 }
void checkDateInDaysColumnMigration()
Definition: Catalog.cpp:906

+ Here is the call graph for this function:

void Catalog_Namespace::Catalog::checkDateInDaysColumnMigration ( )
protected

Definition at line 906 of file Catalog.cpp.

References getCurrentDB(), getObjForLock(), migrations::MigrationMgr::migrateDateInDaysMetadata(), sqliteConnector_, and tableDescriptorMapById_.

Referenced by CheckAndExecuteMigrationsPostBuildMaps().

906  {
907  cat_sqlite_lock sqlite_lock(getObjForLock());
910 }
SqliteConnector sqliteConnector_
Definition: Catalog.h:658
const DBMetadata & getCurrentDB() const
Definition: Catalog.h:228
static void migrateDateInDaysMetadata(const Catalog_Namespace::TableDescriptorMapById &table_descriptors_by_id, const int database_id, const Catalog_Namespace::Catalog *cat, SqliteConnector &sqlite)
TableDescriptorMapById tableDescriptorMapById_
Definition: Catalog.h:646
const Catalog * getObjForLock()
Definition: Catalog.cpp:240
sqlite_lock< Catalog > cat_sqlite_lock
Definition: Catalog.cpp:123

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const bool Catalog_Namespace::Catalog::checkMetadataForDeletedRecs ( const TableDescriptor td,
int  column_id 
) const

Definition at line 3324 of file Catalog.cpp.

References CHECK, and TableDescriptor::fragmenter.

3325  {
3326  // check if there are rows deleted by examining the deletedColumn metadata
3327  CHECK(td);
3328  auto fragmenter = td->fragmenter;
3329  if (fragmenter) {
3330  return fragmenter->hasDeletedRows(delete_column_id);
3331  } else {
3332  return false;
3333  }
3334 }
std::shared_ptr< Fragmenter_Namespace::AbstractFragmenter > fragmenter
#define CHECK(condition)
Definition: Logger.h:223
void Catalog_Namespace::Catalog::checkpoint ( const int  logicalTableId) const

Definition at line 4418 of file Catalog.cpp.

Referenced by UpdelRoll::commitUpdate(), TableOptimizer::vacuumDeletedRows(), and TableOptimizer::vacuumFragmentsAboveMinSelectivity().

4418  {
4419  const auto td = getMetadataForTable(logicalTableId);
4420  const auto shards = getPhysicalTablesDescriptors(td);
4421  for (const auto shard : shards) {
4422  getDataMgr().checkpoint(getCurrentDB().dbId, shard->tableId);
4423  }
4424 }
Data_Namespace::DataMgr & getDataMgr() const
Definition: Catalog.h:229
void checkpoint(const int db_id, const int tb_id)
Definition: DataMgr.cpp:548
const DBMetadata & getCurrentDB() const
Definition: Catalog.h:228
std::vector< const TableDescriptor * > getPhysicalTablesDescriptors(const TableDescriptor *logical_table_desc, bool populate_fragmenter=true) const
Definition: Catalog.cpp:4265
const TableDescriptor * getMetadataForTable(const std::string &tableName, const bool populateFragmenter=true) const
Returns a pointer to a const TableDescriptor struct matching the provided tableName.

+ Here is the caller graph for this function:

void Catalog_Namespace::Catalog::checkpointWithAutoRollback ( const int  logical_table_id) const

Definition at line 4426 of file Catalog.cpp.

Referenced by Fragmenter_Namespace::LocalInsertConnector::checkpoint(), import_export::Loader::checkpoint(), StorageIOFacility::TransactionParameters::finalizeTransaction(), and TableOptimizer::vacuumFragmentsAboveMinSelectivity().

4426  {
4427  auto table_epochs = getTableEpochs(getDatabaseId(), logical_table_id);
4428  try {
4429  checkpoint(logical_table_id);
4430  } catch (...) {
4431  setTableEpochsLogExceptions(getDatabaseId(), table_epochs);
4432  throw;
4433  }
4434 }
int getDatabaseId() const
Definition: Catalog.h:284
void checkpoint(const int logicalTableId) const
Definition: Catalog.cpp:4418
void setTableEpochsLogExceptions(const int32_t db_id, const std::vector< TableEpochInfo > &table_epochs) const
Definition: Catalog.cpp:3306
std::vector< TableEpochInfo > getTableEpochs(const int32_t db_id, const int32_t table_id) const
Definition: Catalog.cpp:3242

+ Here is the caller graph for this function:

void Catalog_Namespace::Catalog::conditionallyInitializeSystemObjects ( )
private

Definition at line 5579 of file Catalog.cpp.

References g_enable_system_tables.

5579  {
5583  }
5584 }
bool g_enable_system_tables
Definition: SysCatalog.cpp:66
bool isInfoSchemaDb() const
Definition: Catalog.cpp:5586
int32_t Catalog_Namespace::Catalog::createCustomExpression ( std::unique_ptr< CustomExpression custom_expression)

Creates a new custom expression.

Parameters
custom_expression- unique pointer to struct containing custom expression details.
Returns
id of created custom expression

Definition at line 5141 of file Catalog.cpp.

References CHECK, CHECK_EQ, CHECK_GT, and to_string().

5142  {
5143  cat_write_lock write_lock(this);
5144  cat_sqlite_lock sqlite_lock(getObjForLock());
5145  sqliteConnector_.query("BEGIN TRANSACTION");
5146  int32_t custom_expression_id{-1};
5147  try {
5148  auto data_source_type_str =
5149  CustomExpression::dataSourceTypeToString(custom_expression->data_source_type);
5150  auto data_source_id_str = std::to_string(custom_expression->data_source_id);
5151  std::string custom_expr_select_query{
5152  "SELECT id FROM omnisci_custom_expressions WHERE name = ? and data_source_type = "
5153  "? and data_source_id = ? and is_deleted = ?"};
5154  std::vector<std::string> custom_expr_select_params{custom_expression->name,
5155  data_source_type_str,
5156  data_source_id_str,
5157  std::to_string(false)};
5158  sqliteConnector_.query_with_text_params(custom_expr_select_query,
5159  custom_expr_select_params);
5160  if (sqliteConnector_.getNumRows() > 0) {
5161  throw std::runtime_error{
5162  "A custom expression with the given "
5163  "name and data source already exists."};
5164  }
5166  "INSERT INTO omnisci_custom_expressions(name, expression_json, "
5167  "data_source_type, data_source_id, is_deleted) VALUES (?,?,?,?,?)",
5168  std::vector<std::string>{custom_expression->name,
5169  custom_expression->expression_json,
5170  data_source_type_str,
5171  data_source_id_str,
5172  std::to_string(false)});
5173  sqliteConnector_.query_with_text_params(custom_expr_select_query,
5174  custom_expr_select_params);
5175  CHECK_EQ(sqliteConnector_.getNumRows(), static_cast<size_t>(1));
5176  custom_expression->id = sqliteConnector_.getData<int32_t>(0, 0);
5177  custom_expression_id = custom_expression->id;
5178  CHECK(custom_expr_map_by_id_.find(custom_expression->id) ==
5179  custom_expr_map_by_id_.end());
5180  custom_expr_map_by_id_[custom_expression->id] = std::move(custom_expression);
5181  } catch (std::exception& e) {
5182  sqliteConnector_.query("ROLLBACK TRANSACTION");
5183  throw;
5184  }
5185  sqliteConnector_.query("END TRANSACTION");
5186  CHECK_GT(custom_expression_id, 0);
5187  return custom_expression_id;
5188 }
#define CHECK_EQ(x, y)
Definition: Logger.h:231
T getData(const int row, const int col)
virtual void query_with_text_params(std::string const &query_only)
SqliteConnector sqliteConnector_
Definition: Catalog.h:658
virtual void query(const std::string &queryString)
#define CHECK_GT(x, y)
Definition: Logger.h:235
std::string to_string(char const *&&v)
static std::string dataSourceTypeToString(DataSourceType type_enum)
const Catalog * getObjForLock()
Definition: Catalog.cpp:240
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:122
#define CHECK(condition)
Definition: Logger.h:223
CustomExpressionMapById custom_expr_map_by_id_
Definition: Catalog.h:655
mapd_unique_lock< mapd_shared_mutex > write_lock
sqlite_lock< Catalog > cat_sqlite_lock
Definition: Catalog.cpp:123
virtual size_t getNumRows() const

+ Here is the call graph for this function:

int32_t Catalog_Namespace::Catalog::createDashboard ( DashboardDescriptor vd)

Definition at line 4056 of file Catalog.cpp.

References DashboardDescriptor::dashboardId, DashboardDescriptor::dashboardMetadata, DashboardDescriptor::dashboardName, DashboardDescriptor::dashboardState, DashboardDescriptor::dashboardSystemRoleName, generate_dashboard_system_rolename(), DashboardDescriptor::imageHash, to_string(), Catalog_Namespace::sqlite_lock< T >::unlock(), Catalog_Namespace::write_lock< T >::unlock(), DashboardDescriptor::updateTime, and DashboardDescriptor::userId.

4056  {
4057  cat_write_lock write_lock(this);
4058  cat_sqlite_lock sqlite_lock(getObjForLock());
4059  sqliteConnector_.query("BEGIN TRANSACTION");
4060  try {
4061  // TODO(andrew): this should be an upsert
4063  "SELECT id FROM mapd_dashboards WHERE name = ? and userid = ?",
4064  std::vector<std::string>{vd.dashboardName, std::to_string(vd.userId)});
4065  if (sqliteConnector_.getNumRows() > 0) {
4067  "UPDATE mapd_dashboards SET state = ?, image_hash = ?, metadata = ?, "
4068  "update_time = "
4069  "datetime('now') where name = ? "
4070  "and userid = ?",
4071  std::vector<std::string>{vd.dashboardState,
4072  vd.imageHash,
4073  vd.dashboardMetadata,
4074  vd.dashboardName,
4075  std::to_string(vd.userId)});
4076  } else {
4078  "INSERT INTO mapd_dashboards (name, state, image_hash, metadata, "
4079  "update_time, "
4080  "userid) "
4081  "VALUES "
4082  "(?,?,?,?, "
4083  "datetime('now'), ?)",
4084  std::vector<std::string>{vd.dashboardName,
4085  vd.dashboardState,
4086  vd.imageHash,
4087  vd.dashboardMetadata,
4088  std::to_string(vd.userId)});
4089  }
4090  } catch (std::exception& e) {
4091  sqliteConnector_.query("ROLLBACK TRANSACTION");
4092  throw;
4093  }
4094  sqliteConnector_.query("END TRANSACTION");
4095 
4096  // now get the auto generated dashboardId
4097  try {
4099  "SELECT id, strftime('%Y-%m-%dT%H:%M:%SZ', update_time) FROM mapd_dashboards "
4100  "WHERE name = ? and userid = ?",
4101  std::vector<std::string>{vd.dashboardName, std::to_string(vd.userId)});
4102  vd.dashboardId = sqliteConnector_.getData<int>(0, 0);
4103  vd.updateTime = sqliteConnector_.getData<std::string>(0, 1);
4104  } catch (std::exception& e) {
4105  throw;
4106  }
4110  sqlite_lock.unlock();
4111  write_lock.unlock();
4112  if (!isInfoSchemaDb()) {
4113  // NOTE(wamsi): Transactionally unsafe
4116  }
4117  return vd.dashboardId;
4118 }
T getData(const int row, const int col)
virtual void query_with_text_params(std::string const &query_only)
SqliteConnector sqliteConnector_
Definition: Catalog.h:658
const DBMetadata currentDB_
Definition: Catalog.h:659
virtual void query(const std::string &queryString)
void addFrontendViewToMap(DashboardDescriptor &vd)
Definition: Catalog.cpp:1452
std::string to_string(char const *&&v)
std::string dashboardSystemRoleName
void createOrUpdateDashboardSystemRole(const std::string &view_meta, const int32_t &user_id, const std::string &dash_role_name)
Definition: Catalog.cpp:1493
const Catalog * getObjForLock()
Definition: Catalog.cpp:240
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:122
bool isInfoSchemaDb() const
Definition: Catalog.cpp:5586
mapd_unique_lock< mapd_shared_mutex > write_lock
sqlite_lock< Catalog > cat_sqlite_lock
Definition: Catalog.cpp:123
virtual size_t getNumRows() const
std::string generate_dashboard_system_rolename(const std::string &db_id, const std::string &dash_id)

+ Here is the call graph for this function:

void Catalog_Namespace::Catalog::createDashboardSystemRoles ( )
protected

Definition at line 912 of file Catalog.cpp.

References createOrUpdateDashboardSystemRole(), currentDB_, Catalog_Namespace::DBMetadata::dbId, logger::ERROR, generate_dashboard_system_rolename(), SqliteConnector::getData(), Catalog_Namespace::SysCatalog::getGranteesOfSharedDashboards(), SqliteConnector::getNumRows(), getObjForLock(), Catalog_Namespace::SysCatalog::getRoleGrantee(), Catalog_Namespace::SysCatalog::grantRoleBatch(), logger::INFO, Catalog_Namespace::SysCatalog::instance(), LOG, MAPD_VERSION, SqliteConnector::query(), SqliteConnector::query_with_text_params(), run_benchmark_import::result, sqliteConnector_, and to_string().

Referenced by CheckAndExecuteMigrationsPostBuildMaps().

912  {
913  std::unordered_map<std::string, std::pair<int, std::string>> dashboards;
914  std::vector<std::string> dashboard_ids;
915  static const std::string migration_name{"dashboard_roles_migration"};
916  {
917  cat_sqlite_lock sqlite_lock(getObjForLock());
918  sqliteConnector_.query("BEGIN TRANSACTION");
919  try {
920  // migration_history should be present in all catalogs by now
921  // if not then would be created before this migration
923  "select * from mapd_version_history where migration_history = '" +
924  migration_name + "'");
925  if (sqliteConnector_.getNumRows() != 0) {
926  // no need for further execution
927  sqliteConnector_.query("END TRANSACTION");
928  return;
929  }
930  LOG(INFO) << "Performing dashboard internal roles Migration.";
931  sqliteConnector_.query("select id, userid, metadata from mapd_dashboards");
932  for (size_t i = 0; i < sqliteConnector_.getNumRows(); ++i) {
935  sqliteConnector_.getData<string>(i, 0)))) {
936  // Successfully created roles during previous migration/crash
937  // No need to include them
938  continue;
939  }
940  dashboards[sqliteConnector_.getData<string>(i, 0)] = std::make_pair(
941  sqliteConnector_.getData<int>(i, 1), sqliteConnector_.getData<string>(i, 2));
942  dashboard_ids.push_back(sqliteConnector_.getData<string>(i, 0));
943  }
944  } catch (const std::exception& e) {
945  sqliteConnector_.query("ROLLBACK TRANSACTION");
946  throw;
947  }
948  sqliteConnector_.query("END TRANSACTION");
949  }
950  // All current grantees with shared dashboards.
951  const auto active_grantees =
953 
954  try {
955  // NOTE(wamsi): Transactionally unsafe
956  for (auto dash : dashboards) {
957  createOrUpdateDashboardSystemRole(dash.second.second,
958  dash.second.first,
960  std::to_string(currentDB_.dbId), dash.first));
961  auto result = active_grantees.find(dash.first);
962  if (result != active_grantees.end()) {
965  dash.first)},
966  result->second);
967  }
968  }
969  cat_sqlite_lock sqlite_lock(getObjForLock());
970  // check if this has already been completed
972  "select * from mapd_version_history where migration_history = '" +
973  migration_name + "'");
974  if (sqliteConnector_.getNumRows() != 0) {
975  return;
976  }
978  "INSERT INTO mapd_version_history(version, migration_history) values(?,?)",
979  std::vector<std::string>{std::to_string(MAPD_VERSION), migration_name});
980  } catch (const std::exception& e) {
981  LOG(ERROR) << "Failed to create dashboard system roles during migration: "
982  << e.what();
983  throw;
984  }
985  LOG(INFO) << "Successfully created dashboard system roles during migration.";
986 }
T getData(const int row, const int col)
virtual void query_with_text_params(std::string const &query_only)
#define LOG(tag)
Definition: Logger.h:217
SqliteConnector sqliteConnector_
Definition: Catalog.h:658
const DBMetadata currentDB_
Definition: Catalog.h:659
virtual void query(const std::string &queryString)
std::string to_string(char const *&&v)
void grantRoleBatch(const std::vector< std::string > &roles, const std::vector< std::string > &grantees)
static SysCatalog & instance()
Definition: SysCatalog.h:337
static const int32_t MAPD_VERSION
Definition: release.h:33
Role * getRoleGrantee(const std::string &name) const
void createOrUpdateDashboardSystemRole(const std::string &view_meta, const int32_t &user_id, const std::string &dash_role_name)
Definition: Catalog.cpp:1493
const Catalog * getObjForLock()
Definition: Catalog.cpp:240
std::unordered_map< std::string, std::vector< std::string > > getGranteesOfSharedDashboards(const std::vector< std::string > &dashboard_ids)
sqlite_lock< Catalog > cat_sqlite_lock
Definition: Catalog.cpp:123
virtual size_t getNumRows() const
std::string generate_dashboard_system_rolename(const std::string &db_id, const std::string &dash_id)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Catalog_Namespace::Catalog::createDefaultServersIfNotExists ( )

Creates default local file servers (if they don't already exist).

Definition at line 4554 of file Catalog.cpp.

References CHECK, foreign_storage::DataWrapperType::CSV, g_enable_fsi, shared::kRootUserId, foreign_storage::AbstractFileStorageDataWrapper::LOCAL_FILE_STORAGE_TYPE, foreign_storage::DataWrapperType::PARQUET, foreign_storage::DataWrapperType::REGEX_PARSER, and foreign_storage::AbstractFileStorageDataWrapper::STORAGE_TYPE_KEY.

4554  {
4559 
4560  auto local_csv_server = std::make_unique<foreign_storage::ForeignServer>(
4561  "default_local_delimited",
4563  options,
4565  local_csv_server->validate();
4566  createForeignServerNoLocks(std::move(local_csv_server), true);
4567 
4568 #ifdef ENABLE_IMPORT_PARQUET
4569  auto local_parquet_server = std::make_unique<foreign_storage::ForeignServer>(
4570  "default_local_parquet",
4572  options,
4574  local_parquet_server->validate();
4575  createForeignServerNoLocks(std::move(local_parquet_server), true);
4576 #endif
4577 
4578  auto local_regex_parser_server = std::make_unique<foreign_storage::ForeignServer>(
4579  "default_local_regex_parsed",
4581  options,
4583  local_regex_parser_server->validate();
4584  createForeignServerNoLocks(std::move(local_regex_parser_server), true);
4585 }
const int kRootUserId
static constexpr char const * REGEX_PARSER
void createForeignServerNoLocks(std::unique_ptr< foreign_storage::ForeignServer > foreign_server, bool if_not_exists)
Definition: Catalog.cpp:2728
#define CHECK(condition)
Definition: Logger.h:223
static constexpr char const * CSV
std::map< std::string, std::string, std::less<>> OptionsMap
bool g_enable_fsi
Definition: Catalog.cpp:97
static constexpr char const * PARQUET
void Catalog_Namespace::Catalog::createForeignServer ( std::unique_ptr< foreign_storage::ForeignServer foreign_server,
bool  if_not_exists 
)

Creates a new foreign server DB object.

Parameters
foreign_server- unique pointer to struct containing foreign server details
if_not_exists- flag indicating whether or not an attempt to create a new foreign server should occur if a server with the same name already exists. An exception is thrown if this flag is set to "false" and an attempt is made to create a pre-existing foreign server

Definition at line 2720 of file Catalog.cpp.

2722  {
2723  cat_write_lock write_lock(this);
2724  cat_sqlite_lock sqlite_lock(getObjForLock());
2725  createForeignServerNoLocks(std::move(foreign_server), if_not_exists);
2726 }
void createForeignServerNoLocks(std::unique_ptr< foreign_storage::ForeignServer > foreign_server, bool if_not_exists)
Definition: Catalog.cpp:2728
const Catalog * getObjForLock()
Definition: Catalog.cpp:240
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:122
mapd_unique_lock< mapd_shared_mutex > write_lock
sqlite_lock< Catalog > cat_sqlite_lock
Definition: Catalog.cpp:123
void Catalog_Namespace::Catalog::createForeignServerNoLocks ( std::unique_ptr< foreign_storage::ForeignServer foreign_server,
bool  if_not_exists 
)
private

Same as createForeignServer() but without acquiring locks. This should only be called from within a function/code block that already acquires appropriate locks.

Definition at line 2728 of file Catalog.cpp.

References CHECK, CHECK_EQ, setup::name, and to_string().

2730  {
2731  const auto& name = foreign_server->name;
2732 
2734  "SELECT name from omnisci_foreign_servers where name = ?",
2735  std::vector<std::string>{name});
2736 
2737  if (sqliteConnector_.getNumRows() == 0) {
2738  foreign_server->creation_time = std::time(nullptr);
2740  "INSERT INTO omnisci_foreign_servers (name, data_wrapper_type, owner_user_id, "
2741  "creation_time, "
2742  "options) "
2743  "VALUES (?, ?, ?, ?, ?)",
2744  std::vector<std::string>{name,
2745  foreign_server->data_wrapper_type,
2746  std::to_string(foreign_server->user_id),
2747  std::to_string(foreign_server->creation_time),
2748  foreign_server->getOptionsAsJsonString()});
2750  "SELECT id from omnisci_foreign_servers where name = ?",
2751  std::vector<std::string>{name});
2752  CHECK_EQ(sqliteConnector_.getNumRows(), size_t(1));
2753  foreign_server->id = sqliteConnector_.getData<int32_t>(0, 0);
2754  std::shared_ptr<foreign_storage::ForeignServer> foreign_server_shared =
2755  std::move(foreign_server);
2757  << "Attempting to insert a foreign server into foreign server map that already "
2758  "exists.";
2759  foreignServerMap_[name] = foreign_server_shared;
2760  foreignServerMapById_[foreign_server_shared->id] = foreign_server_shared;
2761  } else if (!if_not_exists) {
2762  throw std::runtime_error{"A foreign server with name \"" + foreign_server->name +
2763  "\" already exists."};
2764  }
2765 
2766  const auto& server_it = foreignServerMap_.find(name);
2767  CHECK(server_it != foreignServerMap_.end());
2768  CHECK(foreignServerMapById_.find(server_it->second->id) != foreignServerMapById_.end());
2769 }
#define CHECK_EQ(x, y)
Definition: Logger.h:231
T getData(const int row, const int col)
virtual void query_with_text_params(std::string const &query_only)
SqliteConnector sqliteConnector_
Definition: Catalog.h:658
std::string to_string(char const *&&v)
std::string name() const
Definition: Catalog.h:301
ForeignServerMapById foreignServerMapById_
Definition: Catalog.h:654
ForeignServerMap foreignServerMap_
Definition: Catalog.h:653
#define CHECK(condition)
Definition: Logger.h:223
virtual size_t getNumRows() const

+ Here is the call graph for this function:

std::string Catalog_Namespace::Catalog::createLink ( LinkDescriptor ld,
size_t  min_length 
)

Definition at line 4209 of file Catalog.cpp.

References LinkDescriptor::link, LinkDescriptor::linkId, to_string(), LinkDescriptor::updateTime, LinkDescriptor::userId, LinkDescriptor::viewMetadata, and LinkDescriptor::viewState.

4209  {
4210  cat_write_lock write_lock(this);
4211  cat_sqlite_lock sqlite_lock(getObjForLock());
4212  sqliteConnector_.query("BEGIN TRANSACTION");
4213  try {
4215  .substr(0, 8);
4217  "SELECT linkid FROM mapd_links WHERE link = ? and userid = ?",
4218  std::vector<std::string>{ld.link, std::to_string(ld.userId)});
4219  if (sqliteConnector_.getNumRows() > 0) {
4221  "UPDATE mapd_links SET update_time = datetime('now') WHERE userid = ? AND "
4222  "link = ?",
4223  std::vector<std::string>{std::to_string(ld.userId), ld.link});
4224  } else {
4226  "INSERT INTO mapd_links (userid, link, view_state, view_metadata, "
4227  "update_time) VALUES (?,?,?,?, datetime('now'))",
4228  std::vector<std::string>{
4229  std::to_string(ld.userId), ld.link, ld.viewState, ld.viewMetadata});
4230  }
4231  // now get the auto generated dashid
4233  "SELECT linkid, strftime('%Y-%m-%dT%H:%M:%SZ', update_time) FROM mapd_links "
4234  "WHERE link = ?",
4235  ld.link);
4236  ld.linkId = sqliteConnector_.getData<int>(0, 0);
4237  ld.updateTime = sqliteConnector_.getData<std::string>(0, 1);
4238  } catch (std::exception& e) {
4239  sqliteConnector_.query("ROLLBACK TRANSACTION");
4240  throw;
4241  }
4242  sqliteConnector_.query("END TRANSACTION");
4243  addLinkToMap(ld);
4244  return ld.link;
4245 }
T getData(const int row, const int col)
virtual void query_with_text_params(std::string const &query_only)
SqliteConnector sqliteConnector_
Definition: Catalog.h:658
virtual void query(const std::string &queryString)
std::string to_string(char const *&&v)
std::string calculateSHA1(const std::string &data)
Definition: Catalog.cpp:4197
void addLinkToMap(LinkDescriptor &ld)
Definition: Catalog.cpp:1539
const Catalog * getObjForLock()
Definition: Catalog.cpp:240
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:122
mapd_unique_lock< mapd_shared_mutex > write_lock
sqlite_lock< Catalog > cat_sqlite_lock
Definition: Catalog.cpp:123
virtual void query_with_text_param(const std::string &queryString, const std::string &text_param)
virtual size_t getNumRows() const

+ Here is the call graph for this function:

void Catalog_Namespace::Catalog::createOrUpdateDashboardSystemRole ( const std::string &  view_meta,
const int32_t &  user_id,
const std::string &  dash_role_name 
)
protected

Definition at line 1493 of file Catalog.cpp.

References Catalog_Namespace::SysCatalog::createRole(), Grantee::findDbObject(), Grantee::getDbObjects(), Catalog_Namespace::SysCatalog::getRoleGrantee(), Catalog_Namespace::SysCatalog::grantDBObjectPrivilegesBatch(), Catalog_Namespace::SysCatalog::instance(), parseDashboardObjects(), Catalog_Namespace::SysCatalog::revokeDBObjectPrivileges(), TableDBObjectType, and ViewDBObjectType.

Referenced by createDashboardSystemRoles().

1495  {
1496  auto objects = parseDashboardObjects(view_meta, user_id);
1497  Role* rl = SysCatalog::instance().getRoleGrantee(dash_role_name);
1498  if (!rl) {
1499  // Dashboard role does not exist
1500  // create role and grant privileges
1501  // NOTE(wamsi): Transactionally unsafe
1503  dash_role_name, /*user_private_role=*/false, /*is_temporary=*/false);
1504  SysCatalog::instance().grantDBObjectPrivilegesBatch({dash_role_name}, objects, *this);
1505  } else {
1506  // Dashboard system role already exists
1507  // Add/remove privileges on objects
1508  std::set<DBObjectKey> revoke_keys;
1509  auto ex_objects = rl->getDbObjects(true);
1510  for (auto key : *ex_objects | boost::adaptors::map_keys) {
1511  if (key.permissionType != TableDBObjectType &&
1512  key.permissionType != ViewDBObjectType) {
1513  continue;
1514  }
1515  bool found = false;
1516  for (auto obj : objects) {
1517  found = key == obj.getObjectKey() ? true : false;
1518  if (found) {
1519  break;
1520  }
1521  }
1522  if (!found) {
1523  revoke_keys.insert(key);
1524  }
1525  }
1526  for (auto& key : revoke_keys) {
1527  // revoke privs on object since the object is no
1528  // longer used by the dashboard as source
1529  // NOTE(wamsi): Transactionally unsafe
1531  dash_role_name, *rl->findDbObject(key, true), *this);
1532  }
1533  // Update privileges on remaining objects
1534  // NOTE(wamsi): Transactionally unsafe
1535  SysCatalog::instance().grantDBObjectPrivilegesBatch({dash_role_name}, objects, *this);
1536  }
1537 }
void revokeDBObjectPrivileges(const std::string &grantee, const DBObject &object, const Catalog_Namespace::Catalog &catalog)
void createRole(const std::string &roleName, const bool user_private_role, const bool is_temporary=false)
Definition: Grantee.h:81
DBObject * findDbObject(const DBObjectKey &objectKey, bool only_direct) const
Definition: Grantee.cpp:85
static SysCatalog & instance()
Definition: SysCatalog.h:337
Role * getRoleGrantee(const std::string &name) const
void grantDBObjectPrivilegesBatch(const std::vector< std::string > &grantees, const std::vector< DBObject > &objects, const Catalog_Namespace::Catalog &catalog)
const DBObjectMap * getDbObjects(bool only_direct) const
Definition: Grantee.h:56
std::vector< DBObject > parseDashboardObjects(const std::string &view_meta, const int &user_id)
Definition: Catalog.cpp:1463

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Catalog_Namespace::Catalog::createShardedTable ( TableDescriptor td,
const std::list< ColumnDescriptor > &  columns,
const std::vector< Parser::SharedDictionaryDef > &  shared_dict_defs 
)

Definition at line 3520 of file Catalog.cpp.

References CHECK, TableDescriptor::nShards, TableDescriptor::shard, table_is_temporary(), TableDescriptor::tableId, and TableDescriptor::tableName.

3523  {
3524  /* create logical table */
3525  TableDescriptor* tdl = &td;
3526  createTable(*tdl, cols, shared_dict_defs, true); // create logical table
3527  int32_t logical_tb_id = tdl->tableId;
3528  std::string logical_table_name = tdl->tableName;
3529 
3530  /* create physical tables and link them to the logical table */
3531  std::vector<int32_t> physicalTables;
3532  for (int32_t i = 1; i <= td.nShards; i++) {
3533  TableDescriptor* tdp = &td;
3534  tdp->tableName = generatePhysicalTableName(logical_table_name, i);
3535  tdp->shard = i - 1;
3536  createTable(*tdp, cols, shared_dict_defs, false); // create physical table
3537  int32_t physical_tb_id = tdp->tableId;
3538 
3539  /* add physical table to the vector of physical tables */
3540  physicalTables.push_back(physical_tb_id);
3541  }
3542 
3543  if (!physicalTables.empty()) {
3544  cat_write_lock write_lock(this);
3545  /* add logical to physical tables correspondence to the map */
3546  const auto it_ok =
3547  logicalToPhysicalTableMapById_.emplace(logical_tb_id, physicalTables);
3548  CHECK(it_ok.second);
3549  /* update sqlite mapd_logical_to_physical in sqlite database */
3550  if (!table_is_temporary(&td)) {
3551  updateLogicalToPhysicalTableMap(logical_tb_id);
3552  }
3553  }
3554 }
std::string tableName
void createTable(TableDescriptor &td, const std::list< ColumnDescriptor > &columns, const std::vector< Parser::SharedDictionaryDef > &shared_dict_defs, bool isLogicalTable)
Definition: Catalog.cpp:2387
std::string generatePhysicalTableName(const std::string &logicalTableName, const int32_t &shardNumber)
Definition: Catalog.cpp:4481
bool table_is_temporary(const TableDescriptor *const td)
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:122
#define CHECK(condition)
Definition: Logger.h:223
mapd_unique_lock< mapd_shared_mutex > write_lock
LogicalToPhysicalTableMapById logicalToPhysicalTableMapById_
Definition: Catalog.h:665
void updateLogicalToPhysicalTableMap(const int32_t logical_tb_id)
Definition: Catalog.cpp:626

+ Here is the call graph for this function:

void Catalog_Namespace::Catalog::createSystemTableServer ( const std::string &  server_name,
const std::string &  data_wrapper_type 
)
private

Definition at line 5761 of file Catalog.cpp.

References shared::kRootUserId.

5762  {
5763  auto server = std::make_unique<foreign_storage::ForeignServer>(
5764  server_name, data_wrapper_type, foreign_storage::OptionsMap{}, shared::kRootUserId);
5765  server->validate();
5766  createForeignServer(std::move(server), true);
5767 }
const int kRootUserId
void createForeignServer(std::unique_ptr< foreign_storage::ForeignServer > foreign_server, bool if_not_exists)
Definition: Catalog.cpp:2720
std::map< std::string, std::string, std::less<>> OptionsMap
void Catalog_Namespace::Catalog::createTable ( TableDescriptor td,
const std::list< ColumnDescriptor > &  columns,
const std::vector< Parser::SharedDictionaryDef > &  shared_dict_defs,
bool  isLogicalTable 
)

Definition at line 2387 of file Catalog.cpp.

References addTableToMap(), calciteMgr_, CHECK, ColumnDescriptor::columnId, TableDescriptor::columnIdBySpi_, ColumnDescriptor::columnName, ColumnDescriptor::columnType, currentDB_, dataMgr_, Catalog_Namespace::DBMetadata::dbId, Catalog_Namespace::DBMetadata::dbName, ColumnDescriptor::default_value, dict_ref_t::dictId, Data_Namespace::DISK_LEVEL, expandGeoColumn(), StorageType::FOREIGN_TABLE, TableDescriptor::fragPageSize, TableDescriptor::fragType, g_enable_fsi, g_serialize_temp_tables, SQLTypeInfo::get_comp_param(), SQLTypeInfo::get_compression(), SQLTypeInfo::get_dimension(), Catalog_Namespace::anonymous_namespace{Catalog.cpp}::get_next_refresh_time(), SQLTypeInfo::get_notnull(), SQLTypeInfo::get_scale(), SQLTypeInfo::get_size(), SQLTypeInfo::get_subtype(), SQLTypeInfo::get_type(), getCurrentDB(), SqliteConnector::getData(), getObjForLock(), TableDescriptor::hasDeletedCol, SQLTypeInfo::is_array(), TableDescriptor::is_system_table, ColumnDescriptor::isDeletedCol, ColumnDescriptor::isGeoPhyCol, ColumnDescriptor::isSystemCol, TableDescriptor::isView, ColumnDescriptor::isVirtualCol, kBIGINT, kBOOLEAN, kENCODING_DICT, TableDescriptor::keyMetainfo, TableDescriptor::maxChunkSize, TableDescriptor::maxFragRows, TableDescriptor::maxRollbackEpochs, TableDescriptor::maxRows, TableDescriptor::nColumns, foreign_storage::ForeignTable::next_refresh_time, nextTempDictId_, nextTempTableId_, TableDescriptor::nShards, TableDescriptor::partitions, TableDescriptor::persistenceLevel, SqliteConnector::query(), SqliteConnector::query_with_text_param(), SqliteConnector::query_with_text_params(), serializeTableJsonUnlocked(), SQLTypeInfo::set_comp_param(), SQLTypeInfo::set_size(), setColumnDictionary(), setColumnSharedDictionary(), TableDescriptor::shard, TableDescriptor::shardedColumnId, TableDescriptor::sortedColumnId, sqliteConnector_, TableDescriptor::storageType, ColumnDescriptor::tableId, TableDescriptor::tableId, TableDescriptor::tableName, to_string(), TableDescriptor::userId, TableDescriptor::viewSQL, and ColumnDescriptor::virtualExpr.

Referenced by Parser::CreateTableAsSelectStmt::execute(), and Parser::CreateViewStmt::execute().

2391  {
2392  cat_write_lock write_lock(this);
2393  list<ColumnDescriptor> cds = cols;
2394  list<DictDescriptor> dds;
2395  std::set<std::string> toplevel_column_names;
2396  list<ColumnDescriptor> columns;
2397 
2398  if (!td.storageType.empty() &&
2401  throw std::runtime_error("Only temporary tables can be backed by foreign storage.");
2402  }
2403  dataMgr_->getForeignStorageInterface()->prepareTable(getCurrentDB().dbId, td, cds);
2404  }
2405 
2406  for (auto cd : cds) {
2407  if (cd.columnName == "rowid") {
2408  throw std::runtime_error(
2409  "Cannot create column with name rowid. rowid is a system defined column.");
2410  }
2411  columns.push_back(cd);
2412  toplevel_column_names.insert(cd.columnName);
2413  if (cd.columnType.is_geometry()) {
2414  expandGeoColumn(cd, columns);
2415  }
2416  }
2417  cds.clear();
2418 
2419  ColumnDescriptor cd;
2420  // add row_id column -- Must be last column in the table
2421  cd.columnName = "rowid";
2422  cd.isSystemCol = true;
2423  cd.columnType = SQLTypeInfo(kBIGINT, true);
2424 #ifdef MATERIALIZED_ROWID
2425  cd.isVirtualCol = false;
2426 #else
2427  cd.isVirtualCol = true;
2428  cd.virtualExpr = "MAPD_FRAG_ID * MAPD_ROWS_PER_FRAG + MAPD_FRAG_ROW_ID";
2429 #endif
2430  columns.push_back(cd);
2431  toplevel_column_names.insert(cd.columnName);
2432 
2433  if (td.hasDeletedCol) {
2434  ColumnDescriptor cd_del;
2435  cd_del.columnName = "$deleted$";
2436  cd_del.isSystemCol = true;
2437  cd_del.isVirtualCol = false;
2438  cd_del.columnType = SQLTypeInfo(kBOOLEAN, true);
2439  cd_del.isDeletedCol = true;
2440 
2441  columns.push_back(cd_del);
2442  }
2443 
2444  td.nColumns = columns.size();
2445  cat_sqlite_lock sqlite_lock(getObjForLock());
2446  sqliteConnector_.query("BEGIN TRANSACTION");
2448  try {
2450  R"(INSERT INTO mapd_tables (name, userid, ncolumns, isview, fragments, frag_type, max_frag_rows, max_chunk_size, frag_page_size, max_rows, partitions, shard_column_id, shard, num_shards, sort_column_id, storage_type, max_rollback_epochs, is_system_table, key_metainfo) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?))",
2451  std::vector<std::string>{td.tableName,
2452  std::to_string(td.userId),
2454  std::to_string(td.isView),
2455  "",
2460  std::to_string(td.maxRows),
2461  td.partitions,
2463  std::to_string(td.shard),
2464  std::to_string(td.nShards),
2466  td.storageType,
2469  td.keyMetainfo});
2470 
2471  // now get the auto generated tableid
2473  "SELECT tableid FROM mapd_tables WHERE name = ?", td.tableName);
2474  td.tableId = sqliteConnector_.getData<int>(0, 0);
2475  int colId = 1;
2476  for (auto cd : columns) {
2478  const bool is_foreign_col =
2479  setColumnSharedDictionary(cd, cds, dds, td, shared_dict_defs);
2480  if (!is_foreign_col) {
2481  // Ideally we would like to not persist string dictionaries for system tables,
2482  // since system table content can be highly dynamic and string dictionaries
2483  // are not currently vacuumed. However, in distributed this causes issues
2484  // when the cluster is out of sync (when the agg resets but leaves persist) so
2485  // for the sake of testing we need to leave this as normal dictionaries until
2486  // we solve the distributed issue.
2487  auto use_temp_dictionary = false; // td.is_system_table;
2488  setColumnDictionary(cd, dds, td, isLogicalTable, use_temp_dictionary);
2489  }
2490  }
2491 
2492  if (toplevel_column_names.count(cd.columnName)) {
2493  if (!cd.isGeoPhyCol) {
2494  td.columnIdBySpi_.push_back(colId);
2495  }
2496  }
2497 
2498  using BindType = SqliteConnector::BindType;
2499  std::vector<BindType> types(17, BindType::TEXT);
2500  if (!cd.default_value.has_value()) {
2501  types[16] = BindType::NULL_TYPE;
2502  }
2504  "INSERT INTO mapd_columns (tableid, columnid, name, coltype, colsubtype, "
2505  "coldim, colscale, is_notnull, "
2506  "compression, comp_param, size, chunks, is_systemcol, is_virtualcol, "
2507  "virtual_expr, is_deletedcol, default_value) "
2508  "VALUES (?, ?, ?, ?, ?, "
2509  "?, "
2510  "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
2511  std::vector<std::string>{std::to_string(td.tableId),
2512  std::to_string(colId),
2513  cd.columnName,
2522  "",
2525  cd.virtualExpr,
2527  cd.default_value.value_or("NULL")},
2528  types);
2529  cd.tableId = td.tableId;
2530  cd.columnId = colId++;
2531  cds.push_back(cd);
2532  }
2533  if (td.isView) {
2535  "INSERT INTO mapd_views (tableid, sql) VALUES (?,?)",
2536  std::vector<std::string>{std::to_string(td.tableId), td.viewSQL});
2537  }
2539  auto& foreign_table = dynamic_cast<foreign_storage::ForeignTable&>(td);
2540  foreign_table.next_refresh_time = get_next_refresh_time(foreign_table);
2542  "INSERT INTO omnisci_foreign_tables (table_id, server_id, options, "
2543  "last_refresh_time, next_refresh_time) VALUES (?, ?, ?, ?, ?)",
2544  std::vector<std::string>{std::to_string(foreign_table.tableId),
2545  std::to_string(foreign_table.foreign_server->id),
2546  foreign_table.getOptionsAsJsonString(),
2547  std::to_string(foreign_table.last_refresh_time),
2548  std::to_string(foreign_table.next_refresh_time)});
2549  }
2550  } catch (std::exception& e) {
2551  sqliteConnector_.query("ROLLBACK TRANSACTION");
2552  throw;
2553  }
2554  } else { // Temporary table
2555  td.tableId = nextTempTableId_++;
2556  int colId = 1;
2557  for (auto cd : columns) {
2559  const bool is_foreign_col =
2560  setColumnSharedDictionary(cd, cds, dds, td, shared_dict_defs);
2561 
2562  if (!is_foreign_col) {
2563  // Create a new temporary dictionary
2564  std::string fileName("");
2565  std::string folderPath("");
2567  nextTempDictId_++;
2568  DictDescriptor dd(dict_ref,
2569  fileName,
2571  false,
2572  1,
2573  folderPath,
2574  true); // Is dictName (2nd argument) used?
2575  dds.push_back(dd);
2576  if (!cd.columnType.is_array()) {
2578  }
2579  cd.columnType.set_comp_param(dict_ref.dictId);
2580  }
2581  }
2582  if (toplevel_column_names.count(cd.columnName)) {
2583  if (!cd.isGeoPhyCol) {
2584  td.columnIdBySpi_.push_back(colId);
2585  }
2586  }
2587  cd.tableId = td.tableId;
2588  cd.columnId = colId++;
2589  cds.push_back(cd);
2590  }
2591 
2593  serializeTableJsonUnlocked(&td, cds);
2594  }
2595  }
2596 
2597  try {
2598  auto cache = dataMgr_->getPersistentStorageMgr()->getDiskCache();
2599  if (cache) {
2600  CHECK(!cache->hasCachedMetadataForKeyPrefix({getCurrentDB().dbId, td.tableId}))
2601  << "Disk cache at " + cache->getCacheDirectory()
2602  << " contains preexisting data for new table. Please "
2603  "delete or clear cache before continuing";
2604  }
2605 
2606  addTableToMap(&td, cds, dds);
2607  calciteMgr_->updateMetadata(currentDB_.dbName, td.tableName);
2608  if (!td.storageType.empty() && td.storageType != StorageType::FOREIGN_TABLE) {
2609  dataMgr_->getForeignStorageInterface()->registerTable(this, td, cds);
2610  }
2611  } catch (std::exception& e) {
2612  sqliteConnector_.query("ROLLBACK TRANSACTION");
2613  removeTableFromMap(td.tableName, td.tableId, true);
2614  throw;
2615  }
2616  sqliteConnector_.query("END TRANSACTION");
2617 
2619  write_lock.unlock();
2620  sqlite_lock.unlock();
2622  true); // cause instantiateFragmenter() to be called
2623  }
2624 }
int32_t maxRollbackEpochs
void serializeTableJsonUnlocked(const TableDescriptor *td, const std::list< ColumnDescriptor > &cds) const
Definition: Catalog.cpp:2626
int64_t get_next_refresh_time(const foreign_storage::ForeignTable &foreign_table)
Definition: Catalog.cpp:2374
std::string virtualExpr
HOST DEVICE SQLTypes get_subtype() const
Definition: sqltypes.h:330
void set_size(int s)
Definition: sqltypes.h:437
std::string partitions
HOST DEVICE int get_size() const
Definition: sqltypes.h:339
T getData(const int row, const int col)
std::string tableName
virtual void query_with_text_params(std::string const &query_only)
SqliteConnector sqliteConnector_
Definition: Catalog.h:658
const DBMetadata currentDB_
Definition: Catalog.h:659
HOST DEVICE int get_scale() const
Definition: sqltypes.h:334
std::string storageType
void setColumnDictionary(ColumnDescriptor &cd, std::list< DictDescriptor > &dds, const TableDescriptor &td, bool is_logical_table, bool use_temp_dictionary=false)
Definition: Catalog.cpp:3478
std::shared_ptr< Data_Namespace::DataMgr > dataMgr_
Definition: Catalog.h:660
virtual void query(const std::string &queryString)
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:329
std::vector< int > columnIdBySpi_
std::string to_string(char const *&&v)
void addTableToMap(const TableDescriptor *td, const std::list< ColumnDescriptor > &columns, const std::list< DictDescriptor > &dicts)
Definition: Catalog.cpp:1313
const DBMetadata & getCurrentDB() const
Definition: Catalog.h:228
specifies the content in-memory of a row in the column metadata table
static void expandGeoColumn(const ColumnDescriptor &cd, std::list< ColumnDescriptor > &columns)
Definition: Catalog.cpp:2243
std::string keyMetainfo
bool g_serialize_temp_tables
Definition: Catalog.cpp:106
void set_comp_param(int p)
Definition: sqltypes.h:441
std::optional< std::string > default_value
std::shared_ptr< Calcite > calciteMgr_
Definition: Catalog.h:663
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:337
Fragmenter_Namespace::FragmenterType fragType
Data_Namespace::MemoryLevel persistenceLevel
const Catalog * getObjForLock()
Definition: Catalog.cpp:240
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:331
void removeTableFromMap(const std::string &tableName, const int tableId, const bool is_on_error=false)
Definition: Catalog.cpp:1370
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:122
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:338
bool setColumnSharedDictionary(ColumnDescriptor &cd, std::list< ColumnDescriptor > &cdd, std::list< DictDescriptor > &dds, const TableDescriptor td, const std::vector< Parser::SharedDictionaryDef > &shared_dict_defs)
Definition: Catalog.cpp:3409
#define CHECK(condition)
Definition: Logger.h:223
Descriptor for a dictionary for a string columne.
std::string viewSQL
mapd_unique_lock< mapd_shared_mutex > write_lock
SQLTypeInfo columnType
const TableDescriptor * getMetadataForTable(const std::string &tableName, const bool populateFragmenter=true) const
Returns a pointer to a const TableDescriptor struct matching the provided tableName.
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:336
sqlite_lock< Catalog > cat_sqlite_lock
Definition: Catalog.cpp:123
static constexpr char const * FOREIGN_TABLE
bool g_enable_fsi
Definition: Catalog.cpp:97
std::string columnName
virtual void query_with_text_param(const std::string &queryString, const std::string &text_param)
bool is_array() const
Definition: sqltypes.h:518

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Catalog_Namespace::Catalog::delDictionary ( const ColumnDescriptor cd)

Definition at line 2021 of file Catalog.cpp.

References CHECK, CHECK_GT, ColumnDescriptor::columnType, currentDB_, Catalog_Namespace::DBMetadata::dbId, dictDescriptorMapByRef_, g_base_path, SQLTypeInfo::get_comp_param(), SQLTypeInfo::get_compression(), SqliteConnector::getData(), getMetadataForTable(), getObjForLock(), SQLTypeInfo::is_string(), SQLTypeInfo::is_string_array(), shared::kDataDirectoryName, kENCODING_DICT, SqliteConnector::query_with_text_param(), File_Namespace::renameForDelete(), sqliteConnector_, string_dict_hosts_, ColumnDescriptor::tableId, to_string(), and VLOG.

Referenced by roll().

2021  {
2022  cat_write_lock write_lock(this);
2023  cat_sqlite_lock sqlite_lock(getObjForLock());
2024  if (!(cd.columnType.is_string() || cd.columnType.is_string_array())) {
2025  return;
2026  }
2027  if (!(cd.columnType.get_compression() == kENCODING_DICT)) {
2028  return;
2029  }
2030  const auto dictId = cd.columnType.get_comp_param();
2031  CHECK_GT(dictId, 0);
2032  // decrement and zero check dict ref count
2033  const auto td = getMetadataForTable(cd.tableId, false);
2034  CHECK(td);
2036  "UPDATE mapd_dictionaries SET refcount = refcount - 1 WHERE dictid = ?",
2037  std::to_string(dictId));
2039  "SELECT refcount FROM mapd_dictionaries WHERE dictid = ?", std::to_string(dictId));
2040  const auto refcount = sqliteConnector_.getData<int>(0, 0);
2041  VLOG(3) << "Dictionary " << dictId << "from dropped table has reference count "
2042  << refcount;
2043  if (refcount > 0) {
2044  return;
2045  }
2046  const DictRef dictRef(currentDB_.dbId, dictId);
2047  sqliteConnector_.query_with_text_param("DELETE FROM mapd_dictionaries WHERE dictid = ?",
2048  std::to_string(dictId));
2050  "/DB_" + std::to_string(currentDB_.dbId) + "_DICT_" +
2051  std::to_string(dictId));
2052 
2053  std::unique_ptr<StringDictionaryClient> client;
2054  if (!string_dict_hosts_.empty()) {
2055  client.reset(new StringDictionaryClient(string_dict_hosts_.front(), dictRef, true));
2056  }
2057  if (client) {
2058  client->drop(dictRef);
2059  }
2060 
2061  dictDescriptorMapByRef_.erase(dictRef);
2062 }
const std::string kDataDirectoryName
T getData(const int row, const int col)
SqliteConnector sqliteConnector_
Definition: Catalog.h:658
const std::vector< LeafHostInfo > string_dict_hosts_
Definition: Catalog.h:662
const DBMetadata currentDB_
Definition: Catalog.h:659
DictDescriptorMapById dictDescriptorMapByRef_
Definition: Catalog.h:649
#define CHECK_GT(x, y)
Definition: Logger.h:235
std::string to_string(char const *&&v)
std::string g_base_path
Definition: SysCatalog.cpp:64
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:337
const Catalog * getObjForLock()
Definition: Catalog.cpp:240
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:122
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:338
#define CHECK(condition)
Definition: Logger.h:223
mapd_unique_lock< mapd_shared_mutex > write_lock
SQLTypeInfo columnType
const TableDescriptor * getMetadataForTable(const std::string &tableName, const bool populateFragmenter=true) const
Returns a pointer to a const TableDescriptor struct matching the provided tableName.
bool is_string() const
Definition: sqltypes.h:510
void renameForDelete(const std::string directoryName)
Renames a directory to DELETE_ME_&lt;EPOCH&gt;_&lt;oldname&gt;.
Definition: File.cpp:227
sqlite_lock< Catalog > cat_sqlite_lock
Definition: Catalog.cpp:123
bool is_string_array() const
Definition: sqltypes.h:511
virtual void query_with_text_param(const std::string &queryString, const std::string &text_param)
#define VLOG(n)
Definition: Logger.h:317

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Catalog_Namespace::Catalog::deleteCustomExpressions ( const std::vector< int32_t > &  custom_expression_ids,
bool  do_soft_delete 
)

Deletes custom expressions with the given ids.

Parameters
custom_expression_ids- ids of custom expressions to delete
do_soft_delete- flag indicating whether or not to do a soft delete

Definition at line 5266 of file Catalog.cpp.

References CHECK, CHECK_EQ, join(), and to_string().

5267  {
5268  cat_write_lock write_lock(this);
5269  cat_sqlite_lock sqlite_lock(getObjForLock());
5270 
5271  std::vector<int32_t> invalid_ids;
5272  for (const auto id : custom_expression_ids) {
5273  if (custom_expr_map_by_id_.find(id) == custom_expr_map_by_id_.end()) {
5274  invalid_ids.emplace_back(id);
5275  }
5276  }
5277  if (!invalid_ids.empty()) {
5278  throw std::runtime_error{"Custom expressions with ids: " + join(invalid_ids, ",") +
5279  " do not exist."};
5280  }
5281  sqliteConnector_.query("BEGIN TRANSACTION");
5282  try {
5283  for (const auto id : custom_expression_ids) {
5285  "SELECT id FROM omnisci_custom_expressions WHERE id = ?",
5286  std::vector<std::string>{std::to_string(id)});
5287  CHECK_EQ(sqliteConnector_.getNumRows(), static_cast<size_t>(1));
5288  if (do_soft_delete) {
5290  "UPDATE omnisci_custom_expressions SET is_deleted = ? WHERE id = ?",
5291  std::vector<std::string>{std::to_string(true), std::to_string(id)});
5292  } else {
5294  "DELETE FROM omnisci_custom_expressions WHERE id = ?",
5295  std::vector<std::string>{std::to_string(id)});
5296  }
5297  }
5298 
5299  for (const auto id : custom_expression_ids) {
5300  if (do_soft_delete) {
5301  auto it = custom_expr_map_by_id_.find(id);
5302  CHECK(it != custom_expr_map_by_id_.end());
5303  it->second->is_deleted = true;
5304  } else {
5305  custom_expr_map_by_id_.erase(id);
5306  }
5307  }
5308  } catch (std::exception& e) {
5309  sqliteConnector_.query("ROLLBACK TRANSACTION");
5310  throw;
5311  }
5312  sqliteConnector_.query("END TRANSACTION");
5313 }
#define CHECK_EQ(x, y)
Definition: Logger.h:231
virtual void query_with_text_params(std::string const &query_only)
SqliteConnector sqliteConnector_
Definition: Catalog.h:658
std::string join(T const &container, std::string const &delim)
virtual void query(const std::string &queryString)
std::string to_string(char const *&&v)
const Catalog * getObjForLock()
Definition: Catalog.cpp:240
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:122
#define CHECK(condition)
Definition: Logger.h:223
CustomExpressionMapById custom_expr_map_by_id_
Definition: Catalog.h:655
mapd_unique_lock< mapd_shared_mutex > write_lock
sqlite_lock< Catalog > cat_sqlite_lock
Definition: Catalog.cpp:123
virtual size_t getNumRows() const

+ Here is the call graph for this function:

void Catalog_Namespace::Catalog::deleteMetadataForDashboards ( const std::vector< int32_t >  ids,
const UserMetadata user 
)

Definition at line 1780 of file Catalog.cpp.

References DashboardDBObjectType, dashboardDescriptorMap_, AccessPrivileges::DELETE_DASHBOARD, getMetadataForDashboard(), getObjForLock(), Catalog_Namespace::SysCatalog::instance(), SqliteConnector::query(), SqliteConnector::query_with_text_params(), Catalog_Namespace::SysCatalog::revokeDBObjectPrivilegesFromAllBatch(), sqliteConnector_, and to_string().

1781  {
1782  std::stringstream invalid_ids, restricted_ids;
1783 
1784  for (int32_t dashboard_id : dashboard_ids) {
1785  if (!getMetadataForDashboard(dashboard_id)) {
1786  invalid_ids << (!invalid_ids.str().empty() ? ", " : "") << dashboard_id;
1787  continue;
1788  }
1789  DBObject object(dashboard_id, DashboardDBObjectType);
1790  object.loadKey(*this);
1791  object.setPrivileges(AccessPrivileges::DELETE_DASHBOARD);
1792  std::vector<DBObject> privs = {object};
1793  if (!SysCatalog::instance().checkPrivileges(user, privs)) {
1794  restricted_ids << (!restricted_ids.str().empty() ? ", " : "") << dashboard_id;
1795  }
1796  }
1797 
1798  if (invalid_ids.str().size() > 0 || restricted_ids.str().size() > 0) {
1799  std::stringstream error_message;
1800  error_message << "Delete dashboard(s) failed with error(s):";
1801  if (invalid_ids.str().size() > 0) {
1802  error_message << "\nDashboard id: " << invalid_ids.str()
1803  << " - Dashboard id does not exist";
1804  }
1805  if (restricted_ids.str().size() > 0) {
1806  error_message
1807  << "\nDashboard id: " << restricted_ids.str()
1808  << " - User should be either owner of dashboard or super user to delete it";
1809  }
1810  throw std::runtime_error(error_message.str());
1811  }
1812  std::vector<DBObject> dash_objs;
1813 
1814  for (int32_t dashboard_id : dashboard_ids) {
1815  dash_objs.emplace_back(dashboard_id, DashboardDBObjectType);
1816  }
1817  // BE-5245: Transactionally unsafe (like other combined Catalog/Syscatalog operations)
1819  {
1820  cat_write_lock write_lock(this);
1821  cat_sqlite_lock sqlite_lock(getObjForLock());
1822 
1823  sqliteConnector_.query("BEGIN TRANSACTION");
1824  try {
1825  for (int32_t dashboard_id : dashboard_ids) {
1826  auto dash = getMetadataForDashboard(dashboard_id);
1827  // Dash should still exist if revokeDBObjectPrivileges passed but throw and
1828  // rollback if already deleted
1829  if (!dash) {
1830  throw std::runtime_error(
1831  std::string("Delete dashboard(s) failed with error(s):\nDashboard id: ") +
1832  std::to_string(dashboard_id) + " - Dashboard id does not exist ");
1833  }
1834  std::string user_id = std::to_string(dash->userId);
1835  std::string dash_name = dash->dashboardName;
1836  auto viewDescIt = dashboardDescriptorMap_.find(user_id + ":" + dash_name);
1837  dashboardDescriptorMap_.erase(viewDescIt);
1839  "DELETE FROM mapd_dashboards WHERE name = ? and userid = ?",
1840  std::vector<std::string>{dash_name, user_id});
1841  }
1842  } catch (std::exception& e) {
1843  sqliteConnector_.query("ROLLBACK TRANSACTION");
1844  throw;
1845  }
1846  sqliteConnector_.query("END TRANSACTION");
1847  }
1848 }
virtual void query_with_text_params(std::string const &query_only)
SqliteConnector sqliteConnector_
Definition: Catalog.h:658
virtual void query(const std::string &queryString)
DashboardDescriptorMap dashboardDescriptorMap_
Definition: Catalog.h:650
std::string to_string(char const *&&v)
static SysCatalog & instance()
Definition: SysCatalog.h:337
const DashboardDescriptor * getMetadataForDashboard(const std::string &userId, const std::string &dashName) const
const Catalog * getObjForLock()
Definition: Catalog.cpp:240
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:122
static const AccessPrivileges DELETE_DASHBOARD
Definition: DBObject.h:175
mapd_unique_lock< mapd_shared_mutex > write_lock
sqlite_lock< Catalog > cat_sqlite_lock
Definition: Catalog.cpp:123
void revokeDBObjectPrivilegesFromAllBatch(std::vector< DBObject > &objects, Catalog *catalog)

+ Here is the call graph for this function:

void Catalog_Namespace::Catalog::deleteTableCatalogMetadata ( const TableDescriptor logical_table,
const std::vector< const TableDescriptor * > &  physical_tables 
)
private

Definition at line 3679 of file Catalog.cpp.

References TableDescriptor::tableId, and to_string().

3681  {
3682  cat_write_lock write_lock(this);
3683  cat_sqlite_lock sqlite_lock(getObjForLock());
3684  sqliteConnector_.query("BEGIN TRANSACTION");
3685  try {
3686  // remove corresponding record from the logicalToPhysicalTableMap in sqlite database
3688  "DELETE FROM mapd_logical_to_physical WHERE logical_table_id = ?",
3689  std::to_string(logical_table->tableId));
3690  logicalToPhysicalTableMapById_.erase(logical_table->tableId);
3691  for (auto table : physical_tables) {
3692  eraseTableMetadata(table);
3693  }
3694  } catch (std::exception& e) {
3695  sqliteConnector_.query("ROLLBACK TRANSACTION");
3696  throw;
3697  }
3698  sqliteConnector_.query("END TRANSACTION");
3699 }
SqliteConnector sqliteConnector_
Definition: Catalog.h:658
virtual void query(const std::string &queryString)
std::string to_string(char const *&&v)
const Catalog * getObjForLock()
Definition: Catalog.cpp:240
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:122
void eraseTableMetadata(const TableDescriptor *td)
Definition: Catalog.cpp:3701
mapd_unique_lock< mapd_shared_mutex > write_lock
sqlite_lock< Catalog > cat_sqlite_lock
Definition: Catalog.cpp:123
virtual void query_with_text_param(const std::string &queryString, const std::string &text_param)
LogicalToPhysicalTableMapById logicalToPhysicalTableMapById_
Definition: Catalog.h:665

+ Here is the call graph for this function:

void Catalog_Namespace::Catalog::doTruncateTable ( const TableDescriptor td)
protected

Definition at line 3564 of file Catalog.cpp.

References CHECK, CHECK_GE, ColumnDescriptor::columnType, Data_Namespace::CPU_LEVEL, dict_ref_t::dictId, DictDescriptor::dictIsTemp, DictDescriptor::dictRef, SQLTypeInfo::get_comp_param(), SQLTypeInfo::get_compression(), Data_Namespace::GPU_LEVEL, kENCODING_DICT, File_Namespace::renameForDelete(), ColumnDescriptor::tableId, and TableDescriptor::tableId.

3564  {
3565  // must destroy fragmenter before deleteChunks is called.
3567 
3568  const int tableId = td->tableId;
3569  ChunkKey chunkKeyPrefix = {currentDB_.dbId, tableId};
3570  // assuming deleteChunksWithPrefix is atomic
3571  dataMgr_->deleteChunksWithPrefix(chunkKeyPrefix, MemoryLevel::CPU_LEVEL);
3572  dataMgr_->deleteChunksWithPrefix(chunkKeyPrefix, MemoryLevel::GPU_LEVEL);
3573 
3574  dataMgr_->removeTableRelatedDS(currentDB_.dbId, tableId);
3575 
3576  cat_write_lock write_lock(this);
3577  std::unique_ptr<StringDictionaryClient> client;
3578  if (SysCatalog::instance().isAggregator()) {
3579  CHECK(!string_dict_hosts_.empty());
3580  DictRef dict_ref(currentDB_.dbId, -1);
3581  client.reset(new StringDictionaryClient(string_dict_hosts_.front(), dict_ref, true));
3582  }
3583  // clean up any dictionaries
3584  // delete all column descriptors for the table
3585  for (const auto& columnDescriptor : columnDescriptorMapById_) {
3586  auto cd = columnDescriptor.second;
3587  if (cd->tableId != td->tableId) {
3588  continue;
3589  }
3590  const int dict_id = cd->columnType.get_comp_param();
3591  // Dummy dictionaries created for a shard of a logical table have the id set to zero.
3592  if (cd->columnType.get_compression() == kENCODING_DICT && dict_id) {
3593  const DictRef dict_ref(currentDB_.dbId, dict_id);
3594  const auto dictIt = dictDescriptorMapByRef_.find(dict_ref);
3595  CHECK(dictIt != dictDescriptorMapByRef_.end());
3596  const auto& dd = dictIt->second;
3597  CHECK_GE(dd->refcount, 1);
3598  // if this is the only table using this dict reset the dict
3599  if (dd->refcount == 1) {
3600  // close the dictionary
3601  dd->stringDict.reset();
3602  File_Namespace::renameForDelete(dd->dictFolderPath);
3603  if (client) {
3604  client->drop(dd->dictRef);
3605  }
3606  if (!dd->dictIsTemp) {
3607  boost::filesystem::create_directory(dd->dictFolderPath);
3608  }
3609  }
3610 
3611  DictDescriptor* new_dd = new DictDescriptor(dd->dictRef,
3612  dd->dictName,
3613  dd->dictNBits,
3614  dd->dictIsShared,
3615  dd->refcount,
3616  dd->dictFolderPath,
3617  dd->dictIsTemp);
3618  dictDescriptorMapByRef_.erase(dictIt);
3619  // now create new Dict -- need to figure out what to do here for temp tables
3620  if (client) {
3621  client->create(new_dd->dictRef, new_dd->dictIsTemp);
3622  }
3623  dictDescriptorMapByRef_[new_dd->dictRef].reset(new_dd);
3625  }
3626  }
3627 }
std::vector< int > ChunkKey
Definition: types.h:37
const std::vector< LeafHostInfo > string_dict_hosts_
Definition: Catalog.h:662
const DBMetadata currentDB_
Definition: Catalog.h:659
DictDescriptorMapById dictDescriptorMapByRef_
Definition: Catalog.h:649
std::shared_ptr< Data_Namespace::DataMgr > dataMgr_
Definition: Catalog.h:660
#define CHECK_GE(x, y)
Definition: Logger.h:236
ColumnDescriptorMapById columnDescriptorMapById_
Definition: Catalog.h:648
static SysCatalog & instance()
Definition: SysCatalog.h:337
const DictDescriptor * getMetadataForDict(int dict_ref, bool loadDict=true) const
Definition: Catalog.cpp:1673
int32_t dictId
Definition: DictRef.h:11
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:122
void removeFragmenterForTable(const int table_id) const
Definition: Catalog.cpp:3629
#define CHECK(condition)
Definition: Logger.h:223
Descriptor for a dictionary for a string columne.
mapd_unique_lock< mapd_shared_mutex > write_lock
void renameForDelete(const std::string directoryName)
Renames a directory to DELETE_ME_&lt;EPOCH&gt;_&lt;oldname&gt;.
Definition: File.cpp:227

+ Here is the call graph for this function:

void Catalog_Namespace::Catalog::dropColumn ( const TableDescriptor td,
const ColumnDescriptor cd 
)

Definition at line 2154 of file Catalog.cpp.

References CHECK, columnDescriptorMap_, columnDescriptorsForRoll, ColumnDescriptor::columnId, ColumnDescriptor::columnName, getMetadataForColumn(), getObjForLock(), getPhysicalTablesDescriptors(), TableDescriptor::nShards, SqliteConnector::query_with_text_params(), removeFromColumnMap(), TableDescriptor::shard, sqliteConnector_, tableDescriptorMapById_, ColumnDescriptor::tableId, TableDescriptor::tableId, to_string(), and to_upper().

2154  {
2155  {
2156  cat_write_lock write_lock(this);
2157  cat_sqlite_lock sqlite_lock(getObjForLock());
2158  // caller must handle sqlite/chunk transaction TOGETHER
2160  "DELETE FROM mapd_columns where tableid = ? and columnid = ?",
2161  std::vector<std::string>{std::to_string(td.tableId),
2162  std::to_string(cd.columnId)});
2163 
2165  "UPDATE mapd_tables SET ncolumns = ncolumns - 1 WHERE tableid = ?",
2166  std::vector<std::string>{std::to_string(td.tableId)});
2167 
2168  ColumnDescriptorMap::iterator columnDescIt =
2170  CHECK(columnDescIt != columnDescriptorMap_.end());
2171 
2172  columnDescriptorsForRoll.emplace_back(columnDescIt->second, nullptr);
2173  removeFromColumnMap(columnDescIt->second);
2174  --tableDescriptorMapById_[td.tableId]->nColumns;
2175  }
2176 
2177  // for each shard
2178  if (td.nShards > 0 && td.shard < 0) {
2179  for (const auto shard : getPhysicalTablesDescriptors(&td)) {
2180  const auto shard_cd = getMetadataForColumn(shard->tableId, cd.columnId);
2181  CHECK(shard_cd);
2182  dropColumn(*shard, *shard_cd);
2183  }
2184  }
2185 }
void removeFromColumnMap(ColumnDescriptor *cd)
Definition: Catalog.cpp:5863
std::tuple< int, std::string > ColumnKey
Definition: Types.h:37
ColumnDescriptorMap columnDescriptorMap_
Definition: Catalog.h:647
virtual void query_with_text_params(std::string const &query_only)
SqliteConnector sqliteConnector_
Definition: Catalog.h:658
void dropColumn(const TableDescriptor &td, const ColumnDescriptor &cd)
Definition: Catalog.cpp:2154
std::string to_string(char const *&&v)
const ColumnDescriptor * getMetadataForColumn(int tableId, const std::string &colName) const
TableDescriptorMapById tableDescriptorMapById_
Definition: Catalog.h:646
std::vector< const TableDescriptor * > getPhysicalTablesDescriptors(const TableDescriptor *logical_table_desc, bool populate_fragmenter=true) const
Definition: Catalog.cpp:4265
std::string to_upper(const std::string &str)
const Catalog * getObjForLock()
Definition: Catalog.cpp:240
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:122
#define CHECK(condition)
Definition: Logger.h:223
mapd_unique_lock< mapd_shared_mutex > write_lock
sqlite_lock< Catalog > cat_sqlite_lock
Definition: Catalog.cpp:123
ColumnDescriptorsForRoll columnDescriptorsForRoll
Definition: Catalog.h:677
std::string columnName

+ Here is the call graph for this function:

void Catalog_Namespace::Catalog::dropForeignServer ( const std::string &  server_name)

Drops/deletes a foreign server DB object.

Parameters
server_name- Name of foreign server that will be deleted

Definition at line 2887 of file Catalog.cpp.

References CHECK_EQ, and to_string().

2887  {
2888  cat_write_lock write_lock(this);
2889  cat_sqlite_lock sqlite_lock(getObjForLock());
2890 
2892  "SELECT id from omnisci_foreign_servers where name = ?",
2893  std::vector<std::string>{server_name});
2894  auto num_rows = sqliteConnector_.getNumRows();
2895  if (num_rows > 0) {
2896  CHECK_EQ(size_t(1), num_rows);
2897  auto server_id = sqliteConnector_.getData<int32_t>(0, 0);
2899  "SELECT table_id from omnisci_foreign_tables where server_id = ?",
2900  std::to_string(server_id));
2901  if (sqliteConnector_.getNumRows() > 0) {
2902  throw std::runtime_error{"Foreign server \"" + server_name +
2903  "\" is referenced "
2904  "by existing foreign tables and cannot be dropped."};
2905  }
2906  sqliteConnector_.query("BEGIN TRANSACTION");
2907  try {
2909  "DELETE FROM omnisci_foreign_servers WHERE name = ?",
2910  std::vector<std::string>{server_name});
2911  } catch (const std::exception& e) {
2912  sqliteConnector_.query("ROLLBACK TRANSACTION");
2913  throw;
2914  }
2915  sqliteConnector_.query("END TRANSACTION");
2916  foreignServerMap_.erase(server_name);
2917  foreignServerMapById_.erase(server_id);
2918  }
2919 }
#define CHECK_EQ(x, y)
Definition: Logger.h:231
T getData(const int row, const int col)
virtual void query_with_text_params(std::string const &query_only)
SqliteConnector sqliteConnector_
Definition: Catalog.h:658
virtual void query(const std::string &queryString)
std::string to_string(char const *&&v)
ForeignServerMapById foreignServerMapById_
Definition: Catalog.h:654
ForeignServerMap foreignServerMap_
Definition: Catalog.h:653
const Catalog * getObjForLock()
Definition: Catalog.cpp:240
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:122
mapd_unique_lock< mapd_shared_mutex > write_lock
sqlite_lock< Catalog > cat_sqlite_lock
Definition: Catalog.cpp:123
virtual void query_with_text_param(const std::string &queryString, const std::string &text_param)
virtual size_t getNumRows() const

+ Here is the call graph for this function:

void Catalog_Namespace::Catalog::dropTable ( const TableDescriptor td)

Definition at line 3651 of file Catalog.cpp.

References CHECK, TableDescriptor::isView, TableDBObjectType, TableDescriptor::tableId, TableDescriptor::tableName, and ViewDBObjectType.

Referenced by Parser::CreateTableAsSelectStmt::execute(), and Parser::DropViewStmt::execute().

3651  {
3654  std::vector<const TableDescriptor*> tables_to_drop;
3655  {
3656  cat_read_lock read_lock(this);
3657  const auto physicalTableIt = logicalToPhysicalTableMapById_.find(td->tableId);
3658  if (physicalTableIt != logicalToPhysicalTableMapById_.end()) {
3659  // remove all corresponding physical tables if this is a logical table
3660  const auto physicalTables = physicalTableIt->second;
3661  CHECK(!physicalTables.empty());
3662  for (size_t i = 0; i < physicalTables.size(); i++) {
3663  int32_t physical_tb_id = physicalTables[i];
3664  const TableDescriptor* phys_td =
3665  getMutableMetadataForTableUnlocked(physical_tb_id);
3666  CHECK(phys_td);
3667  tables_to_drop.emplace_back(phys_td);
3668  }
3669  }
3670  tables_to_drop.emplace_back(td);
3671  }
3672 
3673  for (auto table : tables_to_drop) {
3674  eraseTablePhysicalData(table);
3675  }
3676  deleteTableCatalogMetadata(td, tables_to_drop);
3677 }
void eraseTablePhysicalData(const TableDescriptor *td)
Definition: Catalog.cpp:4463
std::string tableName
void revokeDBObjectPrivilegesFromAll(DBObject object, Catalog *catalog)
read_lock< Catalog > cat_read_lock
Definition: Catalog.cpp:121
void deleteTableCatalogMetadata(const TableDescriptor *logical_table, const std::vector< const TableDescriptor * > &physical_tables)
Definition: Catalog.cpp:3679
TableDescriptor * getMutableMetadataForTableUnlocked(int table_id) const
Definition: Catalog.cpp:1665
static SysCatalog & instance()
Definition: SysCatalog.h:337
mapd_shared_lock< mapd_shared_mutex > read_lock
#define CHECK(condition)
Definition: Logger.h:223
LogicalToPhysicalTableMapById logicalToPhysicalTableMapById_
Definition: Catalog.h:665

+ Here is the caller graph for this function:

void Catalog_Namespace::Catalog::dropTableFromJsonUnlocked ( const std::string &  table_name) const
protected

Definition at line 2688 of file Catalog.cpp.

References CHECK, Catalog_Namespace::anonymous_namespace{Catalog.cpp}::table_json_filepath(), and VLOG.

2688  {
2689  // relies on the catalog write lock
2690  using namespace rapidjson;
2691 
2692  VLOG(1) << "Dropping temporary table " << table_name << " to JSON for Calcite.";
2693 
2694  const auto db_name = currentDB_.dbName;
2695  const auto file_path = table_json_filepath(basePath_, db_name);
2696 
2697  CHECK(boost::filesystem::exists(file_path));
2698  Document d;
2699 
2700  std::ifstream reader(file_path.string());
2701  CHECK(reader.is_open());
2702  IStreamWrapper json_read_wrapper(reader);
2703  d.ParseStream(json_read_wrapper);
2704 
2705  CHECK(d.IsObject());
2706  auto table_name_ref = StringRef(table_name.c_str());
2707  CHECK(d.HasMember(table_name_ref));
2708  CHECK(d.RemoveMember(table_name_ref));
2709 
2710  // Overwrite the existing file
2711  std::ofstream writer(file_path.string(), std::ios::trunc | std::ios::out);
2712  CHECK(writer.is_open());
2713  OStreamWrapper json_wrapper(writer);
2714 
2715  Writer<OStreamWrapper> json_writer(json_wrapper);
2716  d.Accept(json_writer);
2717  writer.close();
2718 }
const DBMetadata currentDB_
Definition: Catalog.h:659
auto table_json_filepath(const std::string &base_path, const std::string &db_name)
Definition: Catalog.cpp:162
#define CHECK(condition)
Definition: Logger.h:223
#define VLOG(n)
Definition: Logger.h:317

+ Here is the call graph for this function:

std::string Catalog_Namespace::Catalog::dumpCreateTable ( const TableDescriptor td,
bool  multiline_formatting = true,
bool  dump_defaults = false 
) const

Definition at line 4790 of file Catalog.cpp.

Referenced by Parser::ShowCreateTableStmt::execute().

4792  {
4793  cat_read_lock read_lock(this);
4794  return dumpCreateTableUnlocked(td, multiline_formatting, dump_defaults);
4795 }
read_lock< Catalog > cat_read_lock
Definition: Catalog.cpp:121
std::string dumpCreateTableUnlocked(const TableDescriptor *td, bool multiline_formatting, bool dump_defaults) const
Definition: Catalog.cpp:4808
mapd_shared_lock< mapd_shared_mutex > read_lock

+ Here is the caller graph for this function:

std::optional< std::string > Catalog_Namespace::Catalog::dumpCreateTable ( int32_t  table_id,
bool  multiline_formatting = true,
bool  dump_defaults = false 
) const

Definition at line 4797 of file Catalog.cpp.

4799  {
4800  cat_read_lock read_lock(this);
4801  const auto td = getMutableMetadataForTableUnlocked(table_id);
4802  if (!td) {
4803  return {};
4804  }
4805  return dumpCreateTableUnlocked(td, multiline_formatting, dump_defaults);
4806 }
read_lock< Catalog > cat_read_lock
Definition: Catalog.cpp:121
std::string dumpCreateTableUnlocked(const TableDescriptor *td, bool multiline_formatting, bool dump_defaults) const
Definition: Catalog.cpp:4808
TableDescriptor * getMutableMetadataForTableUnlocked(int table_id) const
Definition: Catalog.cpp:1665
mapd_shared_lock< mapd_shared_mutex > read_lock
std::string Catalog_Namespace::Catalog::dumpCreateTableUnlocked ( const TableDescriptor td,
bool  multiline_formatting,
bool  dump_defaults 
) const
private

Definition at line 4808 of file Catalog.cpp.

References CHECK, ColumnDescriptor::columnName, ColumnDescriptor::columnType, Data_Namespace::CPU_LEVEL, DEFAULT_FRAGMENT_ROWS, DEFAULT_MAX_CHUNK_SIZE, DEFAULT_MAX_ROLLBACK_EPOCHS, DEFAULT_MAX_ROWS, DEFAULT_PAGE_SIZE, ColumnDescriptor::default_value, TableDescriptor::fragPageSize, g_leaf_count, ColumnDescriptor::getDefaultValueLiteral(), TableDescriptor::hasDeletedCol, TableDescriptor::is_system_table, ColumnDescriptor::isSystemCol, TableDescriptor::isView, ColumnDescriptor::isVirtualCol, join(), kCHAR, kENCODING_DICT, kENCODING_GEOINT, kTEXT, TableDescriptor::maxChunkSize, TableDescriptor::maxFragRows, TableDescriptor::maxRollbackEpochs, TableDescriptor::maxRows, TableDescriptor::nShards, TableDescriptor::partitions, TableDescriptor::persistenceLevel, TableDescriptor::shardedColumnId, TableDescriptor::sortedColumnId, TableDescriptor::tableId, TableDescriptor::tableName, to_string(), and TableDescriptor::viewSQL.

4810  {
4811  auto foreign_table = dynamic_cast<const foreign_storage::ForeignTable*>(td);
4812  std::ostringstream os;
4813 
4814  if (foreign_table && !td->is_system_table) {
4815  os << "CREATE FOREIGN TABLE " << td->tableName << " (";
4816  } else if (!td->isView) {
4817  os << "CREATE ";
4819  os << "TEMPORARY ";
4820  }
4821  os << "TABLE " + td->tableName + " (";
4822  } else {
4823  os << "CREATE VIEW " + td->tableName + " AS " << td->viewSQL;
4824  return os.str();
4825  }
4826  // scan column defines
4827  std::vector<std::string> additional_info;
4828  std::set<std::string> shared_dict_column_names;
4829 
4830  gatherAdditionalInfo(additional_info, shared_dict_column_names, td);
4831 
4832  // gather column defines
4833  const auto cds = getAllColumnMetadataForTable(td->tableId, false, false, false);
4834  std::map<const std::string, const ColumnDescriptor*> dict_root_cds;
4835  bool first = true;
4836  for (const auto cd : cds) {
4837  if (!(cd->isSystemCol || cd->isVirtualCol)) {
4838  const auto& ti = cd->columnType;
4839  if (!first) {
4840  os << ",";
4841  if (!multiline_formatting) {
4842  os << " ";
4843  }
4844  } else {
4845  first = false;
4846  }
4847  if (multiline_formatting) {
4848  os << "\n ";
4849  }
4850  // column name
4851  os << quoteIfRequired(cd->columnName);
4852  // CHAR is perculiar... better dump it as TEXT(32) like \d does
4853  if (ti.get_type() == SQLTypes::kCHAR) {
4854  os << " "
4855  << "TEXT";
4856  } else if (ti.get_subtype() == SQLTypes::kCHAR) {
4857  os << " "
4858  << "TEXT[]";
4859  } else {
4860  os << " " << ti.get_type_name();
4861  }
4862  os << (ti.get_notnull() ? " NOT NULL" : "");
4863  if (cd->default_value.has_value()) {
4864  os << " DEFAULT " << cd->getDefaultValueLiteral();
4865  }
4866  if (shared_dict_column_names.find(cd->columnName) ==
4867  shared_dict_column_names.end()) {
4868  // avoids "Column ... shouldn't specify an encoding, it borrows it
4869  // from the referenced column"
4870  if (ti.is_string() || (ti.is_array() && ti.get_subtype() == kTEXT)) {
4871  auto size = ti.is_array() ? ti.get_logical_size() : ti.get_size();
4872  if (ti.get_compression() == kENCODING_DICT) {
4873  os << " ENCODING " << ti.get_compression_name() << "(" << (size * 8) << ")";
4874  } else {
4875  os << " ENCODING NONE";
4876  }
4877  } else if (ti.is_date_in_days() ||
4878  (ti.get_size() > 0 && ti.get_size() != ti.get_logical_size())) {
4879  const auto comp_param = ti.get_comp_param() ? ti.get_comp_param() : 32;
4880  os << " ENCODING " << ti.get_compression_name() << "(" << comp_param << ")";
4881  } else if (ti.is_geometry()) {
4882  if (ti.get_compression() == kENCODING_GEOINT) {
4883  os << " ENCODING " << ti.get_compression_name() << "(" << ti.get_comp_param()
4884  << ")";
4885  } else {
4886  os << " ENCODING NONE";
4887  }
4888  }
4889  }
4890  }
4891  }
4892  // gather SHARED DICTIONARYs
4893  if (additional_info.size()) {
4894  std::string comma;
4895  if (!multiline_formatting) {
4896  comma = ", ";
4897  } else {
4898  comma = ",\n ";
4899  }
4900  os << comma;
4901  os << boost::algorithm::join(additional_info, comma);
4902  }
4903  os << ")";
4904 
4905  std::vector<std::string> with_options;
4906  if (foreign_table && !td->is_system_table) {
4907  if (multiline_formatting) {
4908  os << "\n";
4909  } else {
4910  os << " ";
4911  }
4912  os << "SERVER " << foreign_table->foreign_server->name;
4913 
4914  // gather WITH options ...
4915  for (const auto& [option, value] : foreign_table->options) {
4916  with_options.emplace_back(option + "='" + value + "'");
4917  }
4918  }
4919 
4920  if (dump_defaults || td->maxFragRows != DEFAULT_FRAGMENT_ROWS) {
4921  with_options.push_back("FRAGMENT_SIZE=" + std::to_string(td->maxFragRows));
4922  }
4923  if (dump_defaults || td->maxChunkSize != DEFAULT_MAX_CHUNK_SIZE) {
4924  with_options.push_back("MAX_CHUNK_SIZE=" + std::to_string(td->maxChunkSize));
4925  }
4926  if (!foreign_table && (dump_defaults || td->fragPageSize != DEFAULT_PAGE_SIZE)) {
4927  with_options.push_back("PAGE_SIZE=" + std::to_string(td->fragPageSize));
4928  }
4929  if (!foreign_table && (dump_defaults || td->maxRows != DEFAULT_MAX_ROWS)) {
4930  with_options.push_back("MAX_ROWS=" + std::to_string(td->maxRows));
4931  }
4932  if ((dump_defaults || td->maxRollbackEpochs != DEFAULT_MAX_ROLLBACK_EPOCHS) &&
4933  td->maxRollbackEpochs != -1) {
4934  with_options.push_back("MAX_ROLLBACK_EPOCHS=" +
4936  }
4937  if (!foreign_table && (dump_defaults || !td->hasDeletedCol)) {
4938  with_options.emplace_back(td->hasDeletedCol ? "VACUUM='DELAYED'"
4939  : "VACUUM='IMMEDIATE'");
4940  }
4941  if (!foreign_table && !td->partitions.empty()) {
4942  with_options.push_back("PARTITIONS='" + td->partitions + "'");
4943  }
4944  if (!foreign_table && td->nShards > 0) {
4945  const auto shard_cd = getMetadataForColumn(td->tableId, td->shardedColumnId);
4946  CHECK(shard_cd);
4947  with_options.push_back(
4948  "SHARD_COUNT=" +
4949  std::to_string(td->nShards * std::max(g_leaf_count, static_cast<size_t>(1))));
4950  }
4951  if (!foreign_table && td->sortedColumnId > 0) {
4952  const auto sort_cd = getMetadataForColumn(td->tableId, td->sortedColumnId);
4953  CHECK(sort_cd);
4954  with_options.push_back("SORT_COLUMN='" + sort_cd->columnName + "'");
4955  }
4956 
4957  if (!with_options.empty()) {
4958  if (!multiline_formatting) {
4959  os << " ";
4960  } else {
4961  os << "\n";
4962  }
4963  os << "WITH (" + boost::algorithm::join(with_options, ", ") + ")";
4964  }
4965  os << ";";
4966  return os.str();
4967 }
int32_t maxRollbackEpochs
std::string partitions
std::string tableName
std::string join(T const &container, std::string const &delim)
#define DEFAULT_MAX_CHUNK_SIZE
std::string to_string(char const *&&v)
std::string quoteIfRequired(const std::string &column_name) const
Definition: Catalog.cpp:5064
#define DEFAULT_MAX_ROWS
void gatherAdditionalInfo(std::vector< std::string > &additional_info, std::set< std::string > &shared_dict_column_names, const TableDescriptor *td) const
Definition: Catalog.cpp:5075
const ColumnDescriptor * getMetadataForColumn(int tableId, const std::string &colName) const
#define DEFAULT_MAX_ROLLBACK_EPOCHS
specifies the content in-memory of a row in the table metadata table
#define DEFAULT_PAGE_SIZE
Definition: sqltypes.h:52
#define DEFAULT_FRAGMENT_ROWS
std::list< const ColumnDescriptor * > getAllColumnMetadataForTable(const int tableId, const bool fetchSystemColumns, const bool fetchVirtualColumns, const bool fetchPhysicalColumns) const
Returns a list of pointers to constant ColumnDescriptor structs for all the columns from a particular...
Definition: Catalog.cpp:1941
Data_Namespace::MemoryLevel persistenceLevel
Definition: sqltypes.h:41
#define CHECK(condition)
Definition: Logger.h:223
std::string viewSQL
size_t g_leaf_count
Definition: ParserNode.cpp:78

+ Here is the call graph for this function:

std::string Catalog_Namespace::Catalog::dumpSchema ( const TableDescriptor td) const

Definition at line 4663 of file Catalog.cpp.

References CHECK, ColumnDescriptor::columnName, ColumnDescriptor::columnType, DEFAULT_MAX_ROLLBACK_EPOCHS, ColumnDescriptor::default_value, TableDescriptor::fragPageSize, g_leaf_count, ColumnDescriptor::getDefaultValueLiteral(), TableDescriptor::hasDeletedCol, TableDescriptor::is_system_table, ColumnDescriptor::isSystemCol, ColumnDescriptor::isVirtualCol, join(), kCHAR, kENCODING_DICT, kENCODING_GEOINT, kTEXT, TableDescriptor::maxChunkSize, TableDescriptor::maxFragRows, TableDescriptor::maxRollbackEpochs, TableDescriptor::maxRows, TableDescriptor::nShards, TableDescriptor::partitions, TableDescriptor::shardedColumnId, TableDescriptor::sortedColumnId, TableDescriptor::tableId, and to_string().

Referenced by TableArchiver::dumpTable().

4663  {
4664  CHECK(!td->is_system_table);
4665  cat_read_lock read_lock(this);
4666 
4667  std::ostringstream os;
4668  os << "CREATE TABLE @T (";
4669  // gather column defines
4670  const auto cds = getAllColumnMetadataForTable(td->tableId, false, false, false);
4671  std::string comma;
4672  std::vector<std::string> shared_dicts;
4673  std::map<const std::string, const ColumnDescriptor*> dict_root_cds;
4674  for (const auto cd : cds) {
4675  if (!(cd->isSystemCol || cd->isVirtualCol)) {
4676  const auto& ti = cd->columnType;
4677  os << comma << cd->columnName;
4678  // CHAR is perculiar... better dump it as TEXT(32) like \d does
4679  if (ti.get_type() == SQLTypes::kCHAR) {
4680  os << " "
4681  << "TEXT";
4682  } else if (ti.get_subtype() == SQLTypes::kCHAR) {
4683  os << " "
4684  << "TEXT[]";
4685  } else {
4686  os << " " << ti.get_type_name();
4687  }
4688  os << (ti.get_notnull() ? " NOT NULL" : "");
4689  if (cd->default_value.has_value()) {
4690  os << " DEFAULT " << cd->getDefaultValueLiteral();
4691  }
4692  if (ti.is_string() || (ti.is_array() && ti.get_subtype() == kTEXT)) {
4693  auto size = ti.is_array() ? ti.get_logical_size() : ti.get_size();
4694  if (ti.get_compression() == kENCODING_DICT) {
4695  // if foreign reference, get referenced tab.col
4696  const auto dict_id = ti.get_comp_param();
4697  const DictRef dict_ref(currentDB_.dbId, dict_id);
4698  const auto dict_it = dictDescriptorMapByRef_.find(dict_ref);
4699  CHECK(dict_it != dictDescriptorMapByRef_.end());
4700  const auto dict_name = dict_it->second->dictName;
4701  // when migrating a table, any foreign dict ref will be dropped
4702  // and the first cd of a dict will become root of the dict
4703  if (dict_root_cds.end() == dict_root_cds.find(dict_name)) {
4704  dict_root_cds[dict_name] = cd;
4705  os << " ENCODING " << ti.get_compression_name() << "(" << (size * 8) << ")";
4706  } else {
4707  const auto dict_root_cd = dict_root_cds[dict_name];
4708  shared_dicts.push_back("SHARED DICTIONARY (" + cd->columnName +
4709  ") REFERENCES @T(" + dict_root_cd->columnName + ")");
4710  // "... shouldn't specify an encoding, it borrows from the referenced
4711  // column"
4712  }
4713  } else {
4714  os << " ENCODING NONE";
4715  }
4716  } else if (ti.is_date_in_days() ||
4717  (ti.get_size() > 0 && ti.get_size() != ti.get_logical_size())) {
4718  const auto comp_param = ti.get_comp_param() ? ti.get_comp_param() : 32;
4719  os << " ENCODING " << ti.get_compression_name() << "(" << comp_param << ")";
4720  } else if (ti.is_geometry()) {
4721  if (ti.get_compression() == kENCODING_GEOINT) {
4722  os << " ENCODING " << ti.get_compression_name() << "(" << ti.get_comp_param()
4723  << ")";
4724  } else {
4725  os << " ENCODING NONE";
4726  }
4727  }
4728  comma = ", ";
4729  }
4730  }
4731  // gather SHARED DICTIONARYs
4732  if (shared_dicts.size()) {
4733  os << ", " << boost::algorithm::join(shared_dicts, ", ");
4734  }
4735  // gather WITH options ...
4736  std::vector<std::string> with_options;
4737  with_options.push_back("FRAGMENT_SIZE=" + std::to_string(td->maxFragRows));
4738  with_options.push_back("MAX_CHUNK_SIZE=" + std::to_string(td->maxChunkSize));
4739  with_options.push_back("PAGE_SIZE=" + std::to_string(td->fragPageSize));
4740  with_options.push_back("MAX_ROWS=" + std::to_string(td->maxRows));
4741  with_options.emplace_back(td->hasDeletedCol ? "VACUUM='DELAYED'"
4742  : "VACUUM='IMMEDIATE'");
4743  if (!td->partitions.empty()) {
4744  with_options.push_back("PARTITIONS='" + td->partitions + "'");
4745  }
4746  if (td->nShards > 0) {
4747  const auto shard_cd = getMetadataForColumn(td->tableId, td->shardedColumnId);
4748  CHECK(shard_cd);
4749  os << ", SHARD KEY(" << shard_cd->columnName << ")";
4750  with_options.push_back(
4751  "SHARD_COUNT=" +
4752  std::to_string(td->nShards * std::max(g_leaf_count, static_cast<size_t>(1))));
4753  }
4754  if (td->sortedColumnId > 0) {
4755  const auto sort_cd = getMetadataForColumn(td->tableId, td->sortedColumnId);
4756  CHECK(sort_cd);
4757  with_options.push_back("SORT_COLUMN='" + sort_cd->columnName + "'");
4758  }
4760  td->maxRollbackEpochs != -1) {
4761  with_options.push_back("MAX_ROLLBACK_EPOCHS=" +
4763  }
4764  os << ") WITH (" + boost::algorithm::join(with_options, ", ") + ");";
4765  return os.str();
4766 }
int32_t maxRollbackEpochs
std::string partitions
const DBMetadata currentDB_
Definition: Catalog.h:659
DictDescriptorMapById dictDescriptorMapByRef_
Definition: Catalog.h:649
std::string join(T const &container, std::string const &delim)
read_lock< Catalog > cat_read_lock
Definition: Catalog.cpp:121
std::string to_string(char const *&&v)
const ColumnDescriptor * getMetadataForColumn(int tableId, const std::string &colName) const
#define DEFAULT_MAX_ROLLBACK_EPOCHS
specifies the content in-memory of a row in the table metadata table
Definition: sqltypes.h:52
std::list< const ColumnDescriptor * > getAllColumnMetadataForTable(const int tableId, const bool fetchSystemColumns, const bool fetchVirtualColumns, const bool fetchPhysicalColumns) const
Returns a list of pointers to constant ColumnDescriptor structs for all the columns from a particular...
Definition: Catalog.cpp:1941
Definition: sqltypes.h:41
mapd_shared_lock< mapd_shared_mutex > read_lock
#define CHECK(condition)
Definition: Logger.h:223
size_t g_leaf_count
Definition: ParserNode.cpp:78

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Catalog_Namespace::Catalog::eraseDbMetadata ( )

Definition at line 4445 of file Catalog.cpp.

References shared::kCatalogDirectoryName, and run_benchmark_import::tables.

4445  {
4446  const auto tables = getAllTableMetadata();
4447  for (const auto table : tables) {
4448  eraseTableMetadata(table);
4449  }
4450  // Physically erase database metadata
4451  boost::filesystem::remove(basePath_ + "/" + shared::kCatalogDirectoryName + "/" +
4452  currentDB_.dbName);
4453  calciteMgr_->updateMetadata(currentDB_.dbName, "");
4454 }
std::list< const TableDescriptor * > getAllTableMetadata() const
Definition: Catalog.cpp:1957
const DBMetadata currentDB_
Definition: Catalog.h:659
std::shared_ptr< Calcite > calciteMgr_
Definition: Catalog.h:663
const std::string kCatalogDirectoryName
void eraseTableMetadata(const TableDescriptor *td)
Definition: Catalog.cpp:3701
void Catalog_Namespace::Catalog::eraseDbPhysicalData ( )

Definition at line 4456 of file Catalog.cpp.

References run_benchmark_import::tables.

4456  {
4457  const auto tables = getAllTableMetadata();
4458  for (const auto table : tables) {
4459  eraseTablePhysicalData(table);
4460  }
4461 }
void eraseTablePhysicalData(const TableDescriptor *td)
Definition: Catalog.cpp:4463
std::list< const TableDescriptor * > getAllTableMetadata() const
Definition: Catalog.cpp:1957
void Catalog_Namespace::Catalog::eraseTableMetadata ( const TableDescriptor td)
protected

Definition at line 3701 of file Catalog.cpp.

References g_serialize_temp_tables, INJECT_TIMER, table_is_temporary(), TableDescriptor::tableId, and TableDescriptor::tableName.

3701  {
3705  }
3706  calciteMgr_->updateMetadata(currentDB_.dbName, td->tableName);
3707  {
3708  INJECT_TIMER(removeTableFromMap_);
3710  }
3711 }
void executeDropTableSqliteQueries(const TableDescriptor *td)
Definition: Catalog.cpp:3713
std::string tableName
const DBMetadata currentDB_
Definition: Catalog.h:659
void dropTableFromJsonUnlocked(const std::string &table_name) const
Definition: Catalog.cpp:2688
#define INJECT_TIMER(DESC)
Definition: measure.h:93
bool g_serialize_temp_tables
Definition: Catalog.cpp:106
std::shared_ptr< Calcite > calciteMgr_
Definition: Catalog.h:663
bool table_is_temporary(const TableDescriptor *const td)
void removeTableFromMap(const std::string &tableName, const int tableId, const bool is_on_error=false)
Definition: Catalog.cpp:1370

+ Here is the call graph for this function:

void Catalog_Namespace::Catalog::eraseTablePhysicalData ( const TableDescriptor td)

Definition at line 4463 of file Catalog.cpp.

References Data_Namespace::CPU_LEVEL, Data_Namespace::GPU_LEVEL, INJECT_TIMER, TableDescriptor::isView, and TableDescriptor::tableId.

4463  {
4464  const int tableId = td->tableId;
4465  // must destroy fragmenter before deleteChunks is called.
4466  removeFragmenterForTable(tableId);
4467 
4468  ChunkKey chunkKeyPrefix = {currentDB_.dbId, tableId};
4469  {
4470  INJECT_TIMER(deleteChunksWithPrefix);
4471  // assuming deleteChunksWithPrefix is atomic
4472  dataMgr_->deleteChunksWithPrefix(chunkKeyPrefix, MemoryLevel::CPU_LEVEL);
4473  dataMgr_->deleteChunksWithPrefix(chunkKeyPrefix, MemoryLevel::GPU_LEVEL);
4474  }
4475  if (!td->isView) {
4476  INJECT_TIMER(Remove_Table);
4477  dataMgr_->removeTableRelatedDS(currentDB_.dbId, tableId);
4478  }
4479 }
std::vector< int > ChunkKey
Definition: types.h:37
const DBMetadata currentDB_
Definition: Catalog.h:659
std::shared_ptr< Data_Namespace::DataMgr > dataMgr_
Definition: Catalog.h:660
#define INJECT_TIMER(DESC)
Definition: measure.h:93
void removeFragmenterForTable(const int table_id) const
Definition: Catalog.cpp:3629
void Catalog_Namespace::Catalog::executeDropTableSqliteQueries ( const TableDescriptor td)
protected

Definition at line 3713 of file Catalog.cpp.

References StorageType::FOREIGN_TABLE, TableDescriptor::isView, kENCODING_DICT, TableDescriptor::storageType, TableDescriptor::tableId, and to_string().

3713  {
3714  const int tableId = td->tableId;
3715  sqliteConnector_.query_with_text_param("DELETE FROM mapd_tables WHERE tableid = ?",
3716  std::to_string(tableId));
3718  "select comp_param from mapd_columns where compression = ? and tableid = ?",
3719  std::vector<std::string>{std::to_string(kENCODING_DICT), std::to_string(tableId)});
3720  int numRows = sqliteConnector_.getNumRows();
3721  std::vector<int> dict_id_list;
3722  for (int r = 0; r < numRows; ++r) {
3723  dict_id_list.push_back(sqliteConnector_.getData<int>(r, 0));
3724  }
3725  for (auto dict_id : dict_id_list) {
3727<