OmniSciDB  06b3bd477c
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 ()
 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 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 removeChunks (const int table_id)
 
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 TableDescriptorgetMetadataForTableImpl (int tableId, const bool populateFragmenter) const
 
const TableDescriptorgetMetadataForTable (int tableId, bool populateFragmenter=true) const
 
const ColumnDescriptorgetMetadataForColumn (int tableId, const std::string &colName) const
 
const ColumnDescriptorgetMetadataForColumn (int tableId, int columnId) const
 
const ColumnDescriptorgetMetadataForColumnUnlocked (int tableId, int columnId) 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
 
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
ColumnDescriptor * > 
getAllColumnMetadataForTableUnlocked (const int tableId, const bool fetchSystemColumns, const bool fetchVirtualColumns, const bool fetchPhysicalColumns) const
 
std::list< const
TableDescriptor * > 
getAllTableMetadata () const
 
std::list< const
DashboardDescriptor * > 
getAllDashboardsMetadata () const
 
const DBMetadatagetCurrentDB () const
 
Data_Namespace::DataMgrgetDataMgr () const
 
std::shared_ptr< CalcitegetCalciteMgr () const
 
const std::string & getBasePath () const
 
const DictDescriptorgetMetadataForDict (int dict_ref, bool loadDict=true) const
 
const DictDescriptorgetMetadataForDictUnlocked (int dict_ref, bool loadDict) const
 
const std::vector< LeafHostInfo > & getStringDictionaryHosts () const
 
const ColumnDescriptorgetShardColumnMetadataForTable (const TableDescriptor *td) const
 
std::vector< const
TableDescriptor * > 
getPhysicalTablesDescriptors (const TableDescriptor *logicalTableDesc) const
 
std::vector< std::string > getTableNamesForUser (const UserMetadata &user, const GetTablesType get_tables_type) 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)
 
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)
 
void setDeletedColumnUnlocked (const TableDescriptor *td, const ColumnDescriptor *cd)
 
int getLogicalTableId (const int physicalTableId) const
 
void checkpoint (const int logicalTableId) const
 
std::string name () const
 
void eraseDBData ()
 
void eraseTablePhysicalData (const TableDescriptor *td)
 
void vacuumDeletedRows (const TableDescriptor *td) const
 
void vacuumDeletedRows (const int logicalTableId) const
 
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::string getColumnDictDirectory (const ColumnDescriptor *cd) const
 
std::string dumpSchema (const TableDescriptor *td) const
 
std::string dumpCreateTable (const TableDescriptor *td, 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)
 
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)
 

Static Public Member Functions

static void expandGeoColumn (const ColumnDescriptor &cd, std::list< ColumnDescriptor > &columns)
 
static void set (const std::string &dbName, std::shared_ptr< Catalog > cat)
 
static std::shared_ptr< Catalogget (const std::string &dbName)
 
static std::shared_ptr< Catalogget (const int32_t db_id)
 
static std::shared_ptr< Catalogget (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)
 
static void remove (const std::string &dbName)
 
static const std::string getForeignTableSchema (bool if_not_exists=false)
 
static const std::string getForeignServerSchema (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
 

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 updateFrontendViewsToDashboards ()
 
void createFsiSchemasAndDefaultServers ()
 
void dropFsiSchemasAndTables ()
 
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, const bool isLogicalTable)
 
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 doDropTable (const TableDescriptor *td)
 
void executeDropTableSqliteQueries (const TableDescriptor *td)
 
void doTruncateTable (const TableDescriptor *td)
 
void renamePhysicalTable (const TableDescriptor *td, const std::string &newTableName)
 
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_
 
SqliteConnector sqliteConnector_
 
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 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 buildForeignServerMap ()
 
void addForeignTableDetails ()
 
void setForeignServerProperty (const std::string &server_name, const std::string &property, const std::string &value)
 
void createForeignServerNoLocks (std::unique_ptr< foreign_storage::ForeignServer > foreign_server, bool if_not_exists)
 

Private Attributes

DeletedColumnPerTableMap deletedColumnPerTable_
 

Static Private Attributes

static std::map< std::string,
std::shared_ptr< Catalog > > 
mapd_cat_map_
 

Detailed Description

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

Catalog

Definition at line 86 of file Catalog.h.

Member Typedef Documentation

Definition at line 489 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

Definition at line 160 of file Catalog.cpp.

References basePath_, buildMaps(), CheckAndExecuteMigrations(), CheckAndExecuteMigrationsPostBuildMaps(), currentDB_, Catalog_Namespace::DBMetadata::dbName, g_serialize_temp_tables, and Catalog_Namespace::anonymous_namespace{Catalog.cpp}::table_json_filepath().

166  : basePath_(basePath)
167  , sqliteConnector_(curDB.dbName, basePath + "/mapd_catalogs/")
168  , currentDB_(curDB)
169  , dataMgr_(dataMgr)
170  , string_dict_hosts_(string_dict_hosts)
171  , calciteMgr_(calcite)
174  , sqliteMutex_()
175  , sharedMutex_()
178  if (!is_new_db) {
180  }
181  buildMaps();
182  if (!is_new_db) {
184  }
186  boost::filesystem::remove(table_json_filepath(basePath_, currentDB_.dbName));
187  }
188 }
const int MAPD_TEMP_TABLE_START_ID
Definition: Catalog.cpp:100
mapd_shared_mutex sharedMutex_
Definition: Catalog.h:518
SqliteConnector sqliteConnector_
Definition: Catalog.h:471
const std::vector< LeafHostInfo > string_dict_hosts_
Definition: Catalog.h:475
std::shared_ptr< Data_Namespace::DataMgr > dataMgr_
Definition: Catalog.h:473
auto table_json_filepath(const std::string &base_path, const std::string &db_name)
Definition: Catalog.cpp:152
const int MAPD_TEMP_DICT_START_ID
Definition: Catalog.cpp:102
std::atomic< std::thread::id > thread_holding_sqlite_lock
Definition: Catalog.h:519
bool g_serialize_temp_tables
Definition: Catalog.cpp:95
std::shared_ptr< Calcite > calciteMgr_
Definition: Catalog.h:476
std::atomic< std::thread::id > thread_holding_write_lock
Definition: Catalog.h:520
void CheckAndExecuteMigrationsPostBuildMaps()
Definition: Catalog.cpp:910

+ Here is the call graph for this function:

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 190 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_.

190  {
192  // must clean up heap-allocated TableDescriptor and ColumnDescriptor structs
193  for (TableDescriptorMap::iterator tableDescIt = tableDescriptorMap_.begin();
194  tableDescIt != tableDescriptorMap_.end();
195  ++tableDescIt) {
196  tableDescIt->second->fragmenter = nullptr;
197  delete tableDescIt->second;
198  }
199 
200  // TableDescriptorMapById points to the same descriptors. No need to delete
201 
202  for (ColumnDescriptorMap::iterator columnDescIt = columnDescriptorMap_.begin();
203  columnDescIt != columnDescriptorMap_.end();
204  ++columnDescIt) {
205  delete columnDescIt->second;
206  }
207 
208  // ColumnDescriptorMapById points to the same descriptors. No need to delete
209 
211  boost::filesystem::remove(table_json_filepath(basePath_, currentDB_.dbName));
212  }
213 }
ColumnDescriptorMap columnDescriptorMap_
Definition: Catalog.h:462
auto table_json_filepath(const std::string &base_path, const std::string &db_name)
Definition: Catalog.cpp:152
bool g_serialize_temp_tables
Definition: Catalog.cpp:95
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:112
mapd_unique_lock< mapd_shared_mutex > write_lock
TableDescriptorMap tableDescriptorMap_
Definition: Catalog.h:460

+ Here is the call graph for this function:

Member Function Documentation

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

Definition at line 1842 of file Catalog.cpp.

References addDictionary(), columnDescriptorMap_, columnDescriptorMapById_, columnDescriptorsForRoll, ColumnDescriptor::columnId, ColumnDescriptor::columnName, ColumnDescriptor::columnType, 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(), to_upper(), and ColumnDescriptor::virtualExpr.

1842  {
1843  cat_write_lock write_lock(this);
1844  // caller must handle sqlite/chunk transaction TOGETHER
1845  cd.tableId = td.tableId;
1846  if (td.nShards > 0 && td.shard < 0) {
1847  for (const auto shard : getPhysicalTablesDescriptors(&td)) {
1848  auto shard_cd = cd;
1849  addColumn(*shard, shard_cd);
1850  }
1851  }
1853  addDictionary(cd);
1854  }
1855 
1857  "INSERT INTO mapd_columns (tableid, columnid, name, coltype, colsubtype, coldim, "
1858  "colscale, is_notnull, "
1859  "compression, comp_param, size, chunks, is_systemcol, is_virtualcol, virtual_expr, "
1860  "is_deletedcol) "
1861  "VALUES (?, "
1862  "(SELECT max(columnid) + 1 FROM mapd_columns WHERE tableid = ?), "
1863  "?, ?, ?, "
1864  "?, "
1865  "?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
1866  std::vector<std::string>{std::to_string(td.tableId),
1867  std::to_string(td.tableId),
1868  cd.columnName,
1877  "",
1880  cd.virtualExpr,
1882 
1884  "UPDATE mapd_tables SET ncolumns = ncolumns + 1 WHERE tableid = ?",
1885  std::vector<std::string>{std::to_string(td.tableId)});
1886 
1888  "SELECT columnid FROM mapd_columns WHERE tableid = ? AND name = ?",
1889  std::vector<std::string>{std::to_string(td.tableId), cd.columnName});
1890  cd.columnId = sqliteConnector_.getData<int>(0, 0);
1891 
1892  ++tableDescriptorMapById_[td.tableId]->nColumns;
1893  auto ncd = new ColumnDescriptor(cd);
1896  columnDescriptorsForRoll.emplace_back(nullptr, ncd);
1897 }
std::string virtualExpr
HOST DEVICE SQLTypes get_subtype() const
Definition: sqltypes.h:259
std::tuple< int, std::string > ColumnKey
Definition: Types.h:36
HOST DEVICE int get_size() const
Definition: sqltypes.h:268
T getData(const int row, const int col)
ColumnDescriptorMap columnDescriptorMap_
Definition: Catalog.h:462
virtual void query_with_text_params(std::string const &query_only)
void addColumn(const TableDescriptor &td, ColumnDescriptor &cd)
Definition: Catalog.cpp:1842
SqliteConnector sqliteConnector_
Definition: Catalog.h:471
std::vector< const TableDescriptor * > getPhysicalTablesDescriptors(const TableDescriptor *logicalTableDesc) const
Definition: Catalog.cpp:3494
HOST DEVICE int get_scale() const
Definition: sqltypes.h:263
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:258
ColumnDescriptorMapById columnDescriptorMapById_
Definition: Catalog.h:463
std::string to_string(char const *&&v)
TableDescriptorMapById tableDescriptorMapById_
Definition: Catalog.h:461
specifies the content in-memory of a row in the column metadata table
std::string to_upper(const std::string &str)
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:266
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:260
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:112
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:267
mapd_unique_lock< mapd_shared_mutex > write_lock
SQLTypeInfo columnType
DictRef addDictionary(ColumnDescriptor &cd)
Definition: Catalog.cpp:1747
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:265
ColumnDescriptorsForRoll columnDescriptorsForRoll
Definition: Catalog.h:490
std::string columnName
std::tuple< int, int > ColumnIdKey
Definition: Types.h:38

+ Here is the call graph for this function:

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

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

1747  {
1748  const auto& td = *tableDescriptorMapById_[cd.tableId];
1749  list<DictDescriptor> dds;
1750  setColumnDictionary(cd, dds, td, true);
1751  auto& dd = dds.back();
1752  CHECK(dd.dictRef.dictId);
1753 
1754  std::unique_ptr<StringDictionaryClient> client;
1755  if (!string_dict_hosts_.empty()) {
1756  client.reset(new StringDictionaryClient(
1757  string_dict_hosts_.front(), DictRef(currentDB_.dbId, -1), true));
1758  }
1759  if (client) {
1760  client->create(dd.dictRef, dd.dictIsTemp);
1761  }
1762 
1763  DictDescriptor* new_dd = new DictDescriptor(dd);
1764  dictDescriptorMapByRef_[dd.dictRef].reset(new_dd);
1765  if (!dd.dictIsTemp) {
1766  boost::filesystem::create_directory(new_dd->dictFolderPath);
1767  }
1768  return dd.dictRef;
1769 }
std::string dictFolderPath
const std::vector< LeafHostInfo > string_dict_hosts_
Definition: Catalog.h:475
DictDescriptorMapById dictDescriptorMapByRef_
Definition: Catalog.h:464
CHECK(cgen_state)
TableDescriptorMapById tableDescriptorMapById_
Definition: Catalog.h:461
struct dict_ref_t DictRef
Definition: DictRef.h:37
Descriptor for a dictionary for a string columne.
void setColumnDictionary(ColumnDescriptor &cd, std::list< DictDescriptor > &dds, const TableDescriptor &td, const bool isLogicalTable)
Definition: Catalog.cpp:2925

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Catalog_Namespace::Catalog::addForeignTableDetails ( )
private

Definition at line 3760 of file Catalog.cpp.

References CHECK(), foreignServerMapById_, SqliteConnector::getData(), SqliteConnector::getNumRows(), num_rows, SqliteConnector::query(), sqliteConnector_, and tableDescriptorMapById_.

Referenced by buildMaps().

3760  {
3762  "SELECT table_id, server_id, options from omnisci_foreign_tables");
3764  for (size_t r = 0; r < num_rows; r++) {
3765  const auto table_id = sqliteConnector_.getData<int32_t>(r, 0);
3766  const auto server_id = sqliteConnector_.getData<int32_t>(r, 1);
3767  const auto& options = sqliteConnector_.getData<std::string>(r, 2);
3768 
3769  CHECK(tableDescriptorMapById_.find(table_id) != tableDescriptorMapById_.end());
3770  auto foreign_table =
3771  dynamic_cast<foreign_storage::ForeignTable*>(tableDescriptorMapById_[table_id]);
3772  CHECK(foreign_table);
3773  foreign_table->foreign_server = foreignServerMapById_[server_id].get();
3774  CHECK(foreign_table->foreign_server);
3775  foreign_table->populateOptionsMap(options);
3776  }
3777 }
T getData(const int row, const int col)
const int8_t const int64_t * num_rows
SqliteConnector sqliteConnector_
Definition: Catalog.h:471
virtual void query(const std::string &queryString)
CHECK(cgen_state)
TableDescriptorMapById tableDescriptorMapById_
Definition: Catalog.h:461
ForeignServerMapById foreignServerMapById_
Definition: Catalog.h:469
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::addFrontendViewToMap ( DashboardDescriptor vd)
protected

Definition at line 1278 of file Catalog.cpp.

References addFrontendViewToMapNoLock().

Referenced by createDashboard().

1278  {
1279  cat_write_lock write_lock(this);
1281 }
void addFrontendViewToMapNoLock(DashboardDescriptor &vd)
Definition: Catalog.cpp:1283
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:112
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::addFrontendViewToMapNoLock ( DashboardDescriptor vd)
protected

Definition at line 1283 of file Catalog.cpp.

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

Referenced by addFrontendViewToMap(), and replaceDashboard().

1283  {
1284  cat_write_lock write_lock(this);
1286  std::make_shared<DashboardDescriptor>(vd);
1287 }
DashboardDescriptorMap dashboardDescriptorMap_
Definition: Catalog.h:465
std::string to_string(char const *&&v)
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:112
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 1360 of file Catalog.cpp.

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

Referenced by createLink().

1360  {
1361  cat_write_lock write_lock(this);
1362  LinkDescriptor* new_ld = new LinkDescriptor();
1363  *new_ld = ld;
1365  linkDescriptorMapById_[ld.linkId] = new_ld;
1366 }
std::string to_string(char const *&&v)
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:112
mapd_unique_lock< mapd_shared_mutex > write_lock
LinkDescriptorMapById linkDescriptorMapById_
Definition: Catalog.h:467
LinkDescriptorMap linkDescriptorMap_
Definition: Catalog.h:466

+ Here is the call graph for this function:

+ Here is the caller 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 2834 of file Catalog.cpp.

References CHECK(), CHECK_GE, ColumnDescriptor::columnType, currentDB_, Catalog_Namespace::DBMetadata::dbId, dictDescriptorMapByRef_, SQLTypeInfo::get_comp_param(), Catalog_Namespace::anonymous_namespace{Catalog.cpp}::get_foreign_col(), SqliteConnector::query_with_text_params(), sqliteConnector_, and to_string().

Referenced by setColumnSharedDictionary().

2836  {
2837  cat_write_lock write_lock(this);
2838  const auto foreign_ref_col = get_foreign_col(*this, shared_dict_def);
2839  CHECK(foreign_ref_col);
2840  referencing_column.columnType = foreign_ref_col->columnType;
2841  const int dict_id = referencing_column.columnType.get_comp_param();
2842  const DictRef dict_ref(currentDB_.dbId, dict_id);
2843  const auto dictIt = dictDescriptorMapByRef_.find(dict_ref);
2844  CHECK(dictIt != dictDescriptorMapByRef_.end());
2845  const auto& dd = dictIt->second;
2846  CHECK_GE(dd->refcount, 1);
2847  ++dd->refcount;
2848  if (persist_reference) {
2849  cat_sqlite_lock sqlite_lock(this);
2851  "UPDATE mapd_dictionaries SET refcount = refcount + 1 WHERE dictid = ?",
2852  {std::to_string(dict_id)});
2853  }
2854 }
virtual void query_with_text_params(std::string const &query_only)
SqliteConnector sqliteConnector_
Definition: Catalog.h:471
DictDescriptorMapById dictDescriptorMapByRef_
Definition: Catalog.h:464
#define CHECK_GE(x, y)
Definition: Logger.h:210
const ColumnDescriptor * get_foreign_col(const Catalog &cat, const Parser::SharedDictionaryDef &shared_dict_def)
Definition: Catalog.cpp:2822
std::string to_string(char const *&&v)
CHECK(cgen_state)
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:112
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:267
mapd_unique_lock< mapd_shared_mutex > write_lock
SQLTypeInfo columnType
sqlite_lock< Catalog > cat_sqlite_lock
Definition: Catalog.cpp:113

+ Here is the call graph for this function:

+ Here is the caller 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 1137 of file Catalog.cpp.

References CHECK(), columnDescriptorMap_, columnDescriptorMapById_, ColumnDescriptor::columnId, TableDescriptor::columnIdBySpi_, ColumnDescriptor::columnName, currentDB_, Catalog_Namespace::DBMetadata::dbId, dictDescriptorMapByRef_, DictDescriptor::dictFolderPath, dict_ref_t::dictId, TableDescriptor::hasDeletedCol, TableDescriptor::mutex_, setDeletedColumnUnlocked(), string_dict_hosts_, tableDescriptorMap_, tableDescriptorMapById_, ColumnDescriptor::tableId, TableDescriptor::tableId, TableDescriptor::tableName, and to_upper().

Referenced by createTable().

1139  {
1140  cat_write_lock write_lock(this);
1141  TableDescriptor* new_td;
1142 
1143  auto foreign_table = dynamic_cast<const foreign_storage::ForeignTable*>(td);
1144  if (foreign_table) {
1145  auto new_foreign_table = new foreign_storage::ForeignTable();
1146  *new_foreign_table = *foreign_table;
1147  new_td = new_foreign_table;
1148  } else {
1149  new_td = new TableDescriptor();
1150  *new_td = *td;
1151  }
1152 
1153  new_td->mutex_ = std::make_shared<std::mutex>();
1154  tableDescriptorMap_[to_upper(td->tableName)] = new_td;
1155  tableDescriptorMapById_[td->tableId] = new_td;
1156  for (auto cd : columns) {
1157  ColumnDescriptor* new_cd = new ColumnDescriptor();
1158  *new_cd = cd;
1159  ColumnKey columnKey(new_cd->tableId, to_upper(new_cd->columnName));
1160  columnDescriptorMap_[columnKey] = new_cd;
1161  ColumnIdKey columnIdKey(new_cd->tableId, new_cd->columnId);
1162  columnDescriptorMapById_[columnIdKey] = new_cd;
1163 
1164  // Add deleted column to the map
1165  if (cd.isDeletedCol) {
1166  CHECK(new_td->hasDeletedCol);
1167  setDeletedColumnUnlocked(new_td, new_cd);
1168  }
1169  }
1170 
1171  std::sort(new_td->columnIdBySpi_.begin(),
1172  new_td->columnIdBySpi_.end(),
1173  [](const size_t a, const size_t b) -> bool { return a < b; });
1174 
1175  std::unique_ptr<StringDictionaryClient> client;
1176  DictRef dict_ref(currentDB_.dbId, -1);
1177  if (!string_dict_hosts_.empty()) {
1178  client.reset(new StringDictionaryClient(string_dict_hosts_.front(), dict_ref, true));
1179  }
1180  for (auto dd : dicts) {
1181  if (!dd.dictRef.dictId) {
1182  // Dummy entry created for a shard of a logical table, nothing to do.
1183  continue;
1184  }
1185  dict_ref.dictId = dd.dictRef.dictId;
1186  if (client) {
1187  client->create(dict_ref, dd.dictIsTemp);
1188  }
1189  DictDescriptor* new_dd = new DictDescriptor(dd);
1190  dictDescriptorMapByRef_[dict_ref].reset(new_dd);
1191  if (!dd.dictIsTemp) {
1192  boost::filesystem::create_directory(new_dd->dictFolderPath);
1193  }
1194  }
1195 }
std::string dictFolderPath
std::tuple< int, std::string > ColumnKey
Definition: Types.h:36
std::string tableName
ColumnDescriptorMap columnDescriptorMap_
Definition: Catalog.h:462
const std::vector< LeafHostInfo > string_dict_hosts_
Definition: Catalog.h:475
DictDescriptorMapById dictDescriptorMapByRef_
Definition: Catalog.h:464
std::vector< int > columnIdBySpi_
ColumnDescriptorMapById columnDescriptorMapById_
Definition: Catalog.h:463
std::shared_ptr< std::mutex > mutex_
CHECK(cgen_state)
void setDeletedColumnUnlocked(const TableDescriptor *td, const ColumnDescriptor *cd)
Definition: Catalog.cpp:2813
TableDescriptorMapById tableDescriptorMapById_
Definition: Catalog.h:461
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:112
Descriptor for a dictionary for a string columne.
mapd_unique_lock< mapd_shared_mutex > write_lock
specifies the content in-memory of a row in the table metadata table
std::string columnName
TableDescriptorMap tableDescriptorMap_
Definition: Catalog.h:460
std::tuple< int, int > ColumnIdKey
Definition: Types.h:38

+ 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::buildForeignServerMap ( )
private

Definition at line 3742 of file Catalog.cpp.

References foreignServerMap_, foreignServerMapById_, SqliteConnector::getData(), SqliteConnector::getNumRows(), num_rows, SqliteConnector::query(), and sqliteConnector_.

Referenced by buildMaps().

3742  {
3744  "SELECT id, name, data_wrapper_type, options, owner_user_id, creation_time FROM "
3745  "omnisci_foreign_servers");
3747  for (size_t row = 0; row < num_rows; row++) {
3748  auto foreign_server = std::make_shared<foreign_storage::ForeignServer>(
3749  sqliteConnector_.getData<int>(row, 0),
3750  sqliteConnector_.getData<std::string>(row, 1),
3751  sqliteConnector_.getData<std::string>(row, 2),
3752  sqliteConnector_.getData<std::string>(row, 3),
3753  sqliteConnector_.getData<std::int32_t>(row, 4),
3754  sqliteConnector_.getData<std::int32_t>(row, 5));
3755  foreignServerMap_[foreign_server->name] = foreign_server;
3756  foreignServerMapById_[foreign_server->id] = foreign_server;
3757  }
3758 }
T getData(const int row, const int col)
const int8_t const int64_t * num_rows
SqliteConnector sqliteConnector_
Definition: Catalog.h:471
virtual void query(const std::string &queryString)
ForeignServerMapById foreignServerMapById_
Definition: Catalog.h:469
ForeignServerMap foreignServerMap_
Definition: Catalog.h:468
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::buildMaps ( )
protected

Definition at line 926 of file Catalog.cpp.

References addForeignTableDetails(), basePath_, buildForeignServerMap(), CHECK(), ColumnDescriptor::chunks, columnDescriptorMap_, columnDescriptorMapById_, ColumnDescriptor::columnId, ColumnDescriptor::columnName, ColumnDescriptor::columnType, currentDB_, dashboardDescriptorMap_, Catalog_Namespace::DBMetadata::dbId, Catalog_Namespace::DBMetadata::dbName, dictDescriptorMapByRef_, logger::FATAL, StorageType::FOREIGN_TABLE, TableDescriptor::fragmenter, TableDescriptor::fragments, TableDescriptor::fragPageSize, TableDescriptor::fragType, g_enable_fsi, generate_dashboard_system_rolename(), SQLTypeInfo::get_physical_cols(), SqliteConnector::getData(), SqliteConnector::getNumRows(), Catalog_Namespace::anonymous_namespace{Catalog.cpp}::getUserFromId(), TableDescriptor::hasDeletedCol, SQLTypeInfo::is_geometry(), ColumnDescriptor::isDeletedCol, ColumnDescriptor::isGeoPhyCol, SqliteConnector::isNull(), ColumnDescriptor::isSystemCol, TableDescriptor::isView, ColumnDescriptor::isVirtualCol, TableDescriptor::keyMetainfo, LinkDescriptor::link, linkDescriptorMap_, linkDescriptorMapById_, LinkDescriptor::linkId, LOG, logicalToPhysicalTableMapById_, TableDescriptor::maxChunkSize, TableDescriptor::maxFragRows, TableDescriptor::maxRows, TableDescriptor::nColumns, TableDescriptor::nShards, TableDescriptor::partitions, 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(), TableDescriptor::shard, TableDescriptor::shardedColumnId, TableDescriptor::sortedColumnId, sqliteConnector_, TableDescriptor::storageType, tableDescriptorMap_, tableDescriptorMapById_, ColumnDescriptor::tableId, TableDescriptor::tableId, TableDescriptor::tableName, to_string(), to_upper(), LinkDescriptor::updateTime, LinkDescriptor::userId, TableDescriptor::userId, LinkDescriptor::viewMetadata, TableDescriptor::viewSQL, LinkDescriptor::viewState, and ColumnDescriptor::virtualExpr.

Referenced by Catalog().

926  {
928  cat_sqlite_lock sqlite_lock(this);
929 
930  string dictQuery(
931  "SELECT dictid, name, nbits, is_shared, refcount from mapd_dictionaries");
932  sqliteConnector_.query(dictQuery);
933  size_t numRows = sqliteConnector_.getNumRows();
934  for (size_t r = 0; r < numRows; ++r) {
935  int dictId = sqliteConnector_.getData<int>(r, 0);
936  std::string dictName = sqliteConnector_.getData<string>(r, 1);
937  int dictNBits = sqliteConnector_.getData<int>(r, 2);
938  bool is_shared = sqliteConnector_.getData<bool>(r, 3);
939  int refcount = sqliteConnector_.getData<int>(r, 4);
940  std::string fname = basePath_ + "/mapd_data/DB_" + std::to_string(currentDB_.dbId) +
941  "_DICT_" + std::to_string(dictId);
942  DictRef dict_ref(currentDB_.dbId, dictId);
943  DictDescriptor* dd = new DictDescriptor(
944  dict_ref, dictName, dictNBits, is_shared, refcount, fname, false);
945  dictDescriptorMapByRef_[dict_ref].reset(dd);
946  }
947 
948  string tableQuery(
949  "SELECT tableid, name, ncolumns, isview, fragments, frag_type, max_frag_rows, "
950  "max_chunk_size, frag_page_size, "
951  "max_rows, partitions, shard_column_id, shard, num_shards, key_metainfo, userid, "
952  "sort_column_id, storage_type "
953  "from mapd_tables");
954  sqliteConnector_.query(tableQuery);
955  numRows = sqliteConnector_.getNumRows();
956  for (size_t r = 0; r < numRows; ++r) {
957  TableDescriptor* td;
958  const auto& storage_type = sqliteConnector_.getData<string>(r, 17);
959  if (!storage_type.empty() &&
960  (!g_enable_fsi || storage_type != StorageType::FOREIGN_TABLE)) {
961  const auto table_id = sqliteConnector_.getData<int>(r, 0);
962  const auto& table_name = sqliteConnector_.getData<string>(r, 1);
963  LOG(FATAL) << "Unable to read Catalog metadata: storage type is currently not a "
964  "supported table option (table "
965  << table_name << " [" << table_id << "] in database "
966  << currentDB_.dbName << ").";
967  }
968 
969  if (storage_type == StorageType::FOREIGN_TABLE) {
971  } else {
972  td = new TableDescriptor();
973  }
974 
975  td->storageType = storage_type;
976  td->tableId = sqliteConnector_.getData<int>(r, 0);
977  td->tableName = sqliteConnector_.getData<string>(r, 1);
978  td->nColumns = sqliteConnector_.getData<int>(r, 2);
979  td->isView = sqliteConnector_.getData<bool>(r, 3);
980  td->fragments = sqliteConnector_.getData<string>(r, 4);
981  td->fragType =
983  td->maxFragRows = sqliteConnector_.getData<int>(r, 6);
984  td->maxChunkSize = sqliteConnector_.getData<int>(r, 7);
985  td->fragPageSize = sqliteConnector_.getData<int>(r, 8);
986  td->maxRows = sqliteConnector_.getData<int64_t>(r, 9);
987  td->partitions = sqliteConnector_.getData<string>(r, 10);
988  td->shardedColumnId = sqliteConnector_.getData<int>(r, 11);
989  td->shard = sqliteConnector_.getData<int>(r, 12);
990  td->nShards = sqliteConnector_.getData<int>(r, 13);
991  td->keyMetainfo = sqliteConnector_.getData<string>(r, 14);
992  td->userId = sqliteConnector_.getData<int>(r, 15);
993  td->sortedColumnId =
994  sqliteConnector_.isNull(r, 16) ? 0 : sqliteConnector_.getData<int>(r, 16);
995  if (!td->isView) {
996  td->fragmenter = nullptr;
997  }
998  td->hasDeletedCol = false;
999 
1001  tableDescriptorMapById_[td->tableId] = td;
1002  }
1003 
1004  if (g_enable_fsi) {
1007  }
1008 
1009  string columnQuery(
1010  "SELECT tableid, columnid, name, coltype, colsubtype, coldim, colscale, "
1011  "is_notnull, compression, comp_param, "
1012  "size, chunks, is_systemcol, is_virtualcol, virtual_expr, is_deletedcol from "
1013  "mapd_columns ORDER BY tableid, "
1014  "columnid");
1015  sqliteConnector_.query(columnQuery);
1016  numRows = sqliteConnector_.getNumRows();
1017  int32_t skip_physical_cols = 0;
1018  for (size_t r = 0; r < numRows; ++r) {
1019  ColumnDescriptor* cd = new ColumnDescriptor();
1020  cd->tableId = sqliteConnector_.getData<int>(r, 0);
1021  cd->columnId = sqliteConnector_.getData<int>(r, 1);
1022  cd->columnName = sqliteConnector_.getData<string>(r, 2);
1026  cd->columnType.set_scale(sqliteConnector_.getData<int>(r, 6));
1030  cd->columnType.set_size(sqliteConnector_.getData<int>(r, 10));
1031  cd->chunks = sqliteConnector_.getData<string>(r, 11);
1032  cd->isSystemCol = sqliteConnector_.getData<bool>(r, 12);
1033  cd->isVirtualCol = sqliteConnector_.getData<bool>(r, 13);
1034  cd->virtualExpr = sqliteConnector_.getData<string>(r, 14);
1035  cd->isDeletedCol = sqliteConnector_.getData<bool>(r, 15);
1036  cd->isGeoPhyCol = skip_physical_cols > 0;
1037  ColumnKey columnKey(cd->tableId, to_upper(cd->columnName));
1038  columnDescriptorMap_[columnKey] = cd;
1039  ColumnIdKey columnIdKey(cd->tableId, cd->columnId);
1040  columnDescriptorMapById_[columnIdKey] = cd;
1041 
1042  if (skip_physical_cols <= 0) {
1043  skip_physical_cols = cd->columnType.get_physical_cols();
1044  }
1045 
1046  auto td_itr = tableDescriptorMapById_.find(cd->tableId);
1047  CHECK(td_itr != tableDescriptorMapById_.end());
1048 
1049  if (cd->isDeletedCol) {
1050  td_itr->second->hasDeletedCol = true;
1051  setDeletedColumnUnlocked(td_itr->second, cd);
1052  } else if (cd->columnType.is_geometry() || skip_physical_cols-- <= 0) {
1053  tableDescriptorMapById_[cd->tableId]->columnIdBySpi_.push_back(cd->columnId);
1054  }
1055  }
1056  // sort columnIdBySpi_ based on columnId
1057  for (auto& tit : tableDescriptorMapById_) {
1058  std::sort(tit.second->columnIdBySpi_.begin(),
1059  tit.second->columnIdBySpi_.end(),
1060  [](const size_t a, const size_t b) -> bool { return a < b; });
1061  }
1062 
1063  string viewQuery("SELECT tableid, sql FROM mapd_views");
1064  sqliteConnector_.query(viewQuery);
1065  numRows = sqliteConnector_.getNumRows();
1066  for (size_t r = 0; r < numRows; ++r) {
1067  int32_t tableId = sqliteConnector_.getData<int>(r, 0);
1068  TableDescriptor* td = tableDescriptorMapById_[tableId];
1069  td->viewSQL = sqliteConnector_.getData<string>(r, 1);
1070  td->fragmenter = nullptr;
1071  }
1072 
1073  string frontendViewQuery(
1074  "SELECT id, state, name, image_hash, strftime('%Y-%m-%dT%H:%M:%SZ', update_time), "
1075  "userid, "
1076  "metadata "
1077  "FROM mapd_dashboards");
1078  sqliteConnector_.query(frontendViewQuery);
1079  numRows = sqliteConnector_.getNumRows();
1080  for (size_t r = 0; r < numRows; ++r) {
1081  std::shared_ptr<DashboardDescriptor> vd = std::make_shared<DashboardDescriptor>();
1082  vd->dashboardId = sqliteConnector_.getData<int>(r, 0);
1083  vd->dashboardState = sqliteConnector_.getData<string>(r, 1);
1084  vd->dashboardName = sqliteConnector_.getData<string>(r, 2);
1085  vd->imageHash = sqliteConnector_.getData<string>(r, 3);
1086  vd->updateTime = sqliteConnector_.getData<string>(r, 4);
1087  vd->userId = sqliteConnector_.getData<int>(r, 5);
1088  vd->dashboardMetadata = sqliteConnector_.getData<string>(r, 6);
1089  vd->user = getUserFromId(vd->userId);
1090  vd->dashboardSystemRoleName = generate_dashboard_system_rolename(
1092  dashboardDescriptorMap_[std::to_string(vd->userId) + ":" + vd->dashboardName] = vd;
1093  }
1094 
1095  string linkQuery(
1096  "SELECT linkid, userid, link, view_state, strftime('%Y-%m-%dT%H:%M:%SZ', "
1097  "update_time), view_metadata "
1098  "FROM mapd_links");
1099  sqliteConnector_.query(linkQuery);
1100  numRows = sqliteConnector_.getNumRows();
1101  for (size_t r = 0; r < numRows; ++r) {
1102  LinkDescriptor* ld = new LinkDescriptor();
1103  ld->linkId = sqliteConnector_.getData<int>(r, 0);
1104  ld->userId = sqliteConnector_.getData<int>(r, 1);
1105  ld->link = sqliteConnector_.getData<string>(r, 2);
1106  ld->viewState = sqliteConnector_.getData<string>(r, 3);
1107  ld->updateTime = sqliteConnector_.getData<string>(r, 4);
1108  ld->viewMetadata = sqliteConnector_.getData<string>(r, 5);
1110  linkDescriptorMapById_[ld->linkId] = ld;
1111  }
1112 
1113  /* rebuild map linking logical tables to corresponding physical ones */
1114  string logicalToPhysicalTableMapQuery(
1115  "SELECT logical_table_id, physical_table_id "
1116  "FROM mapd_logical_to_physical");
1117  sqliteConnector_.query(logicalToPhysicalTableMapQuery);
1118  numRows = sqliteConnector_.getNumRows();
1119  for (size_t r = 0; r < numRows; ++r) {
1120  int32_t logical_tb_id = sqliteConnector_.getData<int>(r, 0);
1121  int32_t physical_tb_id = sqliteConnector_.getData<int>(r, 1);
1122  const auto physicalTableIt = logicalToPhysicalTableMapById_.find(logical_tb_id);
1123  if (physicalTableIt == logicalToPhysicalTableMapById_.end()) {
1124  /* add new entity to the map logicalToPhysicalTableMapById_ */
1125  std::vector<int32_t> physicalTables;
1126  physicalTables.push_back(physical_tb_id);
1127  const auto it_ok =
1128  logicalToPhysicalTableMapById_.emplace(logical_tb_id, physicalTables);
1129  CHECK(it_ok.second);
1130  } else {
1131  /* update map logicalToPhysicalTableMapById_ */
1132  physicalTableIt->second.push_back(physical_tb_id);
1133  }
1134  }
1135 }
std::string virtualExpr
void set_compression(EncodingType c)
Definition: sqltypes.h:358
void set_size(int s)
Definition: sqltypes.h:356
std::string partitions
std::tuple< int, std::string > ColumnKey
Definition: Types.h:36
T getData(const int row, const int col)
SQLTypes
Definition: sqltypes.h:39
std::string tableName
ColumnDescriptorMap columnDescriptorMap_
Definition: Catalog.h:462
EncodingType
Definition: encodetypes.h:22
#define LOG(tag)
Definition: Logger.h:188
SqliteConnector sqliteConnector_
Definition: Catalog.h:471
DictDescriptorMapById dictDescriptorMapByRef_
Definition: Catalog.h:464
std::string storageType
HOST DEVICE void set_subtype(SQLTypes st)
Definition: sqltypes.h:349
virtual void query(const std::string &queryString)
std::string fragments
ColumnDescriptorMapById columnDescriptorMapById_
Definition: Catalog.h:463
DashboardDescriptorMap dashboardDescriptorMap_
Definition: Catalog.h:465
std::string to_string(char const *&&v)
std::string chunks
int get_physical_cols() const
Definition: sqltypes.h:279
CHECK(cgen_state)
std::string getUserFromId(const int32_t id)
Definition: Catalog.cpp:916
void set_scale(int s)
Definition: sqltypes.h:353
void setDeletedColumnUnlocked(const TableDescriptor *td, const ColumnDescriptor *cd)
Definition: Catalog.cpp:2813
TableDescriptorMapById tableDescriptorMapById_
Definition: Catalog.h:461
specifies the content in-memory of a row in the column metadata table
std::string keyMetainfo
std::shared_ptr< Fragmenter_Namespace::AbstractFragmenter > fragmenter
std::string to_upper(const std::string &str)
void set_comp_param(int p)
Definition: sqltypes.h:359
bool isNull(const int row, const int col) const
void set_dimension(int d)
Definition: sqltypes.h:350
Fragmenter_Namespace::FragmenterType fragType
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:112
void set_notnull(bool n)
Definition: sqltypes.h:355
bool is_geometry() const
Definition: sqltypes.h:427
Descriptor for a dictionary for a string columne.
std::string viewSQL
mapd_unique_lock< mapd_shared_mutex > write_lock
SQLTypeInfo columnType
specifies the content in-memory of a row in the table metadata table
sqlite_lock< Catalog > cat_sqlite_lock
Definition: Catalog.cpp:113
LinkDescriptorMapById linkDescriptorMapById_
Definition: Catalog.h:467
static constexpr char const * FOREIGN_TABLE
bool g_enable_fsi
Definition: Catalog.cpp:90
std::string columnName
virtual size_t getNumRows() const
LogicalToPhysicalTableMapById logicalToPhysicalTableMapById_
Definition: Catalog.h:478
TableDescriptorMap tableDescriptorMap_
Definition: Catalog.h:460
LinkDescriptorMap linkDescriptorMap_
Definition: Catalog.h:466
std::string generate_dashboard_system_rolename(const std::string &db_id, const std::string &dash_id)
std::tuple< int, int > ColumnIdKey
Definition: Types.h:38
HOST DEVICE void set_type(SQLTypes t)
Definition: sqltypes.h:348

+ 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 3425 of file Catalog.cpp.

Referenced by createLink().

3425  {
3426  boost::uuids::detail::sha1 sha1;
3427  unsigned int digest[5];
3428  sha1.process_bytes(data.c_str(), data.length());
3429  sha1.get_digest(digest);
3430  std::stringstream ss;
3431  for (size_t i = 0; i < 5; i++) {
3432  ss << std::hex << digest[i];
3433  }
3434  return ss.str();
3435 }

+ Here is the caller graph for this function:

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 2498 of file Catalog.cpp.

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

2499  {
2500  cat_write_lock write_lock(this);
2501  foreign_storage::ForeignServer* foreign_server =
2502  foreignServerMap_.find(server_name)->second.get();
2503  CHECK(foreign_server);
2504  setForeignServerProperty(server_name, "owner_user_id", std::to_string(new_owner_id));
2505  // update in-memory server
2506  foreign_server->user_id = new_owner_id;
2507 }
std::string to_string(char const *&&v)
CHECK(cgen_state)
ForeignServerMap foreignServerMap_
Definition: Catalog.h:468
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:112
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:3779

+ Here is the call graph for this function:

void Catalog_Namespace::Catalog::CheckAndExecuteMigrations ( )
protected

Definition at line 888 of file Catalog.cpp.

References createFsiSchemasAndDefaultServers(), dropFsiSchemasAndTables(), g_enable_fsi, recordOwnershipOfObjectsInObjectPermissions(), updateDeletedColumnIndicator(), updateDictionaryNames(), updateDictionarySchema(), updateFixlenArrayColumns(), updateFrontendViewAndLinkUsers(), updateFrontendViewSchema(), updateFrontendViewsToDashboards(), updateGeoColumns(), updateLinkSchema(), updateLogicalToPhysicalTableLinkSchema(), updatePageSize(), and updateTableDescriptorSchema().

Referenced by Catalog().

888  {
898  updatePageSize();
902 
903  if (g_enable_fsi) {
905  } else {
907  }
908 }
void updateFrontendViewAndLinkUsers()
Definition: Catalog.cpp:407
void recordOwnershipOfObjectsInObjectPermissions()
Definition: Catalog.cpp:686
void updateFrontendViewsToDashboards()
Definition: Catalog.cpp:119
void createFsiSchemasAndDefaultServers()
Definition: Catalog.cpp:608
void updateLogicalToPhysicalTableLinkSchema()
Definition: Catalog.cpp:547
bool g_enable_fsi
Definition: Catalog.cpp:90

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Catalog_Namespace::Catalog::CheckAndExecuteMigrationsPostBuildMaps ( )
protected

Definition at line 910 of file Catalog.cpp.

References checkDateInDaysColumnMigration(), and createDashboardSystemRoles().

Referenced by Catalog().

910  {
913 }
void checkDateInDaysColumnMigration()
Definition: Catalog.cpp:814

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Catalog_Namespace::Catalog::checkDateInDaysColumnMigration ( )
protected

Definition at line 814 of file Catalog.cpp.

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

Referenced by CheckAndExecuteMigrationsPostBuildMaps().

814  {
815  cat_sqlite_lock sqlite_lock(this);
818 }
SqliteConnector sqliteConnector_
Definition: Catalog.h:471
const DBMetadata & getCurrentDB() const
Definition: Catalog.h:194
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:461
sqlite_lock< Catalog > cat_sqlite_lock
Definition: Catalog.cpp:113

+ 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 2748 of file Catalog.cpp.

References CHECK(), currentDB_, dataMgr_, Catalog_Namespace::DBMetadata::dbId, TableDescriptor::fragmenter, table_is_temporary(), and TableDescriptor::tableId.

Referenced by getDeletedColumnIfRowsDeleted().

2749  {
2750  // check if there are rows deleted by examining the deletedColumn metadata
2751  CHECK(td);
2752 
2753  if (table_is_temporary(td)) {
2754  auto fragmenter = td->fragmenter;
2755  CHECK(fragmenter);
2756  return fragmenter->hasDeletedRows(delete_column_id);
2757  } else {
2758  ChunkKey chunk_key_prefix = {currentDB_.dbId, td->tableId, delete_column_id};
2759  ChunkMetadataVector chunk_metadata_vec;
2760  dataMgr_->getChunkMetadataVecForKeyPrefix(chunk_metadata_vec, chunk_key_prefix);
2761  int64_t chunk_max{0};
2762 
2763  for (auto chunk_metadata : chunk_metadata_vec) {
2764  chunk_max = chunk_metadata.second->chunkStats.max.tinyintval;
2765  // delete has occured
2766  if (chunk_max == 1) {
2767  return true;
2768  }
2769  }
2770  return false;
2771  }
2772 }
std::vector< int > ChunkKey
Definition: types.h:35
std::shared_ptr< Data_Namespace::DataMgr > dataMgr_
Definition: Catalog.h:473
CHECK(cgen_state)
std::vector< std::pair< ChunkKey, std::shared_ptr< ChunkMetadata >>> ChunkMetadataVector
std::shared_ptr< Fragmenter_Namespace::AbstractFragmenter > fragmenter
bool table_is_temporary(const TableDescriptor *const td)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Catalog_Namespace::Catalog::checkpoint ( const int  logicalTableId) const

Definition at line 3598 of file Catalog.cpp.

References Data_Namespace::DataMgr::checkpoint(), getCurrentDB(), getDataMgr(), getMetadataForTable(), and getPhysicalTablesDescriptors().

Referenced by import_export::Loader::checkpoint(), and TableOptimizer::vacuumDeletedRows().

3598  {
3599  const auto td = getMetadataForTable(logicalTableId);
3600  const auto shards = getPhysicalTablesDescriptors(td);
3601  for (const auto shard : shards) {
3602  getDataMgr().checkpoint(getCurrentDB().dbId, shard->tableId);
3603  }
3604 }
Data_Namespace::DataMgr & getDataMgr() const
Definition: Catalog.h:195
void checkpoint(const int db_id, const int tb_id)
Definition: DataMgr.cpp:481
std::vector< const TableDescriptor * > getPhysicalTablesDescriptors(const TableDescriptor *logicalTableDesc) const
Definition: Catalog.cpp:3494
const DBMetadata & getCurrentDB() const
Definition: Catalog.h:194
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 call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 3291 of file Catalog.cpp.

References addFrontendViewToMap(), createOrUpdateDashboardSystemRole(), currentDB_, DashboardDescriptor::dashboardId, DashboardDescriptor::dashboardMetadata, DashboardDescriptor::dashboardName, DashboardDescriptor::dashboardState, DashboardDescriptor::dashboardSystemRoleName, Catalog_Namespace::DBMetadata::dbId, generate_dashboard_system_rolename(), SqliteConnector::getData(), SqliteConnector::getNumRows(), DashboardDescriptor::imageHash, SqliteConnector::query(), SqliteConnector::query_with_text_params(), sqliteConnector_, to_string(), DashboardDescriptor::updateTime, and DashboardDescriptor::userId.

3291  {
3292  {
3293  cat_write_lock write_lock(this);
3294  cat_sqlite_lock sqlite_lock(this);
3295  sqliteConnector_.query("BEGIN TRANSACTION");
3296  try {
3297  // TODO(andrew): this should be an upsert
3299  "SELECT id FROM mapd_dashboards WHERE name = ? and userid = ?",
3300  std::vector<std::string>{vd.dashboardName, std::to_string(vd.userId)});
3301  if (sqliteConnector_.getNumRows() > 0) {
3303  "UPDATE mapd_dashboards SET state = ?, image_hash = ?, metadata = ?, "
3304  "update_time = "
3305  "datetime('now') where name = ? "
3306  "and userid = ?",
3307  std::vector<std::string>{vd.dashboardState,
3308  vd.imageHash,
3309  vd.dashboardMetadata,
3310  vd.dashboardName,
3311  std::to_string(vd.userId)});
3312  } else {
3314  "INSERT INTO mapd_dashboards (name, state, image_hash, metadata, "
3315  "update_time, "
3316  "userid) "
3317  "VALUES "
3318  "(?,?,?,?, "
3319  "datetime('now'), ?)",
3320  std::vector<std::string>{vd.dashboardName,
3321  vd.dashboardState,
3322  vd.imageHash,
3323  vd.dashboardMetadata,
3324  std::to_string(vd.userId)});
3325  }
3326  } catch (std::exception& e) {
3327  sqliteConnector_.query("ROLLBACK TRANSACTION");
3328  throw;
3329  }
3330  sqliteConnector_.query("END TRANSACTION");
3331 
3332  // now get the auto generated dashboardId
3333  try {
3335  "SELECT id, strftime('%Y-%m-%dT%H:%M:%SZ', update_time) FROM mapd_dashboards "
3336  "WHERE name = ? and userid = ?",
3337  std::vector<std::string>{vd.dashboardName, std::to_string(vd.userId)});
3338  vd.dashboardId = sqliteConnector_.getData<int>(0, 0);
3339  vd.updateTime = sqliteConnector_.getData<std::string>(0, 1);
3340  } catch (std::exception& e) {
3341  throw;
3342  }
3346  }
3347  // NOTE(wamsi): Transactionally unsafe
3350  return vd.dashboardId;
3351 }
T getData(const int row, const int col)
virtual void query_with_text_params(std::string const &query_only)
SqliteConnector sqliteConnector_
Definition: Catalog.h:471
virtual void query(const std::string &queryString)
void addFrontendViewToMap(DashboardDescriptor &vd)
Definition: Catalog.cpp:1278
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:1319
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:112
mapd_unique_lock< mapd_shared_mutex > write_lock
sqlite_lock< Catalog > cat_sqlite_lock
Definition: Catalog.cpp:113
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 820 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(), 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().

820  {
821  std::unordered_map<std::string, std::pair<int, std::string>> dashboards;
822  std::vector<std::string> dashboard_ids;
823  static const std::string migration_name{"dashboard_roles_migration"};
824  {
825  cat_sqlite_lock sqlite_lock(this);
826  sqliteConnector_.query("BEGIN TRANSACTION");
827  try {
828  // migration_history should be present in all catalogs by now
829  // if not then would be created before this migration
831  "select * from mapd_version_history where migration_history = '" +
832  migration_name + "'");
833  if (sqliteConnector_.getNumRows() != 0) {
834  // no need for further execution
835  sqliteConnector_.query("END TRANSACTION");
836  return;
837  }
838  LOG(INFO) << "Performing dashboard internal roles Migration.";
839  sqliteConnector_.query("select id, userid, metadata from mapd_dashboards");
840  for (size_t i = 0; i < sqliteConnector_.getNumRows(); ++i) {
843  sqliteConnector_.getData<string>(i, 0)))) {
844  // Successfully created roles during previous migration/crash
845  // No need to include them
846  continue;
847  }
848  dashboards[sqliteConnector_.getData<string>(i, 0)] = std::make_pair(
849  sqliteConnector_.getData<int>(i, 1), sqliteConnector_.getData<string>(i, 2));
850  dashboard_ids.push_back(sqliteConnector_.getData<string>(i, 0));
851  }
852  } catch (const std::exception& e) {
853  sqliteConnector_.query("ROLLBACK TRANSACTION");
854  throw;
855  }
856  sqliteConnector_.query("END TRANSACTION");
857  }
858  // All current grantees with shared dashboards.
859  const auto active_grantees =
861 
862  try {
863  // NOTE(wamsi): Transactionally unsafe
864  for (auto dash : dashboards) {
865  createOrUpdateDashboardSystemRole(dash.second.second,
866  dash.second.first,
868  std::to_string(currentDB_.dbId), dash.first));
869  auto result = active_grantees.find(dash.first);
870  if (result != active_grantees.end()) {
873  dash.first)},
874  result->second);
875  }
876  }
878  "INSERT INTO mapd_version_history(version, migration_history) values(?,?)",
879  std::vector<std::string>{std::to_string(MAPD_VERSION), migration_name});
880  } catch (const std::exception& e) {
881  LOG(ERROR) << "Failed to create dashboard system roles during migration: "
882  << e.what();
883  throw;
884  }
885  LOG(INFO) << "Successfully created dashboard system roles during migration.";
886 }
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:188
SqliteConnector sqliteConnector_
Definition: Catalog.h:471
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:288
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:1319
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:113
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 3800 of file Catalog.cpp.

References createForeignServerNoLocks(), foreign_storage::DataWrapperType::CSV, OMNISCI_ROOT_USER_ID, foreign_storage::DataWrapperType::PARQUET, and foreign_storage::ForeignServer::validate().

Referenced by createFsiSchemasAndDefaultServers().

3800  {
3802  std::map<std::string, std::string, std::less<>> options;
3803  options[std::string{ForeignServer::STORAGE_TYPE_KEY}] =
3804  ForeignServer::LOCAL_FILE_STORAGE_TYPE;
3805  options[std::string{ForeignServer::BASE_PATH_KEY}] =
3806  boost::filesystem::path::preferred_separator;
3807 
3808  auto local_csv_server =
3809  std::make_unique<ForeignServer>("omnisci_local_csv",
3811  options,
3813  local_csv_server->validate();
3814  createForeignServerNoLocks(std::move(local_csv_server), true);
3815 
3816  auto local_parquet_server =
3817  std::make_unique<ForeignServer>("omnisci_local_parquet",
3819  options,
3821  local_parquet_server->validate();
3822  createForeignServerNoLocks(std::move(local_parquet_server), true);
3823 }
void createForeignServerNoLocks(std::unique_ptr< foreign_storage::ForeignServer > foreign_server, bool if_not_exists)
Definition: Catalog.cpp:2433
const int OMNISCI_ROOT_USER_ID
Definition: SysCatalog.h:60
static constexpr char const * CSV
Definition: ForeignServer.h:35
static constexpr char const * PARQUET
Definition: ForeignServer.h:36

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 2425 of file Catalog.cpp.

References createForeignServerNoLocks().

2427  {
2428  cat_write_lock write_lock(this);
2429  cat_sqlite_lock sqlite_lock(this);
2430  createForeignServerNoLocks(std::move(foreign_server), if_not_exists);
2431 }
void createForeignServerNoLocks(std::unique_ptr< foreign_storage::ForeignServer > foreign_server, bool if_not_exists)
Definition: Catalog.cpp:2433
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:112
mapd_unique_lock< mapd_shared_mutex > write_lock
sqlite_lock< Catalog > cat_sqlite_lock
Definition: Catalog.cpp:113

+ Here is the call graph for this function:

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 2433 of file Catalog.cpp.

References CHECK_EQ, foreignServerMap_, foreignServerMapById_, SqliteConnector::getData(), SqliteConnector::getNumRows(), SqliteConnector::query_with_text_params(), sqliteConnector_, and to_string().

Referenced by createDefaultServersIfNotExists(), and createForeignServer().

2435  {
2437  "SELECT name from omnisci_foreign_servers where name = ?",
2438  std::vector<std::string>{foreign_server->name});
2439 
2440  if (sqliteConnector_.getNumRows() == 0) {
2441  foreign_server->creation_time = std::time(nullptr);
2443  "INSERT INTO omnisci_foreign_servers (name, data_wrapper_type, owner_user_id, "
2444  "creation_time, "
2445  "options) "
2446  "VALUES (?, ?, ?, ?, ?)",
2447  std::vector<std::string>{foreign_server->name,
2448  foreign_server->data_wrapper_type,
2449  std::to_string(foreign_server->user_id),
2450  std::to_string(foreign_server->creation_time),
2451  foreign_server->getOptionsAsJsonString()});
2453  "SELECT id from omnisci_foreign_servers where name = ?",
2454  std::vector<std::string>{foreign_server->name});
2455  CHECK_EQ(sqliteConnector_.getNumRows(), size_t(1));
2456  foreign_server->id = sqliteConnector_.getData<int32_t>(0, 0);
2457  } else if (!if_not_exists) {
2458  throw std::runtime_error{"A foreign server with name \"" + foreign_server->name +
2459  "\" already exists."};
2460  }
2461 
2462  std::shared_ptr<foreign_storage::ForeignServer> foreign_server_shared =
2463  std::move(foreign_server);
2464  foreignServerMap_[foreign_server_shared->name] = foreign_server_shared;
2465  foreignServerMapById_[foreign_server_shared->id] = foreign_server_shared;
2466 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
T getData(const int row, const int col)
virtual void query_with_text_params(std::string const &query_only)
SqliteConnector sqliteConnector_
Definition: Catalog.h:471
std::string to_string(char const *&&v)
ForeignServerMapById foreignServerMapById_
Definition: Catalog.h:469
ForeignServerMap foreignServerMap_
Definition: Catalog.h:468
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::createFsiSchemasAndDefaultServers ( )
protected

Definition at line 608 of file Catalog.cpp.

References createDefaultServersIfNotExists(), getForeignServerSchema(), getForeignTableSchema(), SqliteConnector::query(), and sqliteConnector_.

Referenced by CheckAndExecuteMigrations().

608  {
609  cat_sqlite_lock sqlite_lock(this);
610  sqliteConnector_.query("BEGIN TRANSACTION");
611  try {
615  } catch (std::exception& e) {
616  sqliteConnector_.query("ROLLBACK TRANSACTION");
617  throw;
618  }
619  sqliteConnector_.query("END TRANSACTION");
620 }
SqliteConnector sqliteConnector_
Definition: Catalog.h:471
virtual void query(const std::string &queryString)
static const std::string getForeignTableSchema(bool if_not_exists=false)
Definition: Catalog.cpp:679
static const std::string getForeignServerSchema(bool if_not_exists=false)
Definition: Catalog.cpp:672
sqlite_lock< Catalog > cat_sqlite_lock
Definition: Catalog.cpp:113
void createDefaultServersIfNotExists()
Definition: Catalog.cpp:3800

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 3437 of file Catalog.cpp.

References addLinkToMap(), calculateSHA1(), SqliteConnector::getData(), SqliteConnector::getNumRows(), LinkDescriptor::link, LinkDescriptor::linkId, SqliteConnector::query(), SqliteConnector::query_with_text_param(), SqliteConnector::query_with_text_params(), sqliteConnector_, to_string(), LinkDescriptor::updateTime, LinkDescriptor::userId, LinkDescriptor::viewMetadata, and LinkDescriptor::viewState.

3437  {
3438  cat_write_lock write_lock(this);
3439  cat_sqlite_lock sqlite_lock(this);
3440  sqliteConnector_.query("BEGIN TRANSACTION");
3441  try {
3443  .substr(0, 8);
3445  "SELECT linkid FROM mapd_links WHERE link = ? and userid = ?",
3446  std::vector<std::string>{ld.link, std::to_string(ld.userId)});
3447  if (sqliteConnector_.getNumRows() > 0) {
3449  "UPDATE mapd_links SET update_time = datetime('now') WHERE userid = ? AND link "
3450  "= ?",
3451  std::vector<std::string>{std::to_string(ld.userId), ld.link});
3452  } else {
3454  "INSERT INTO mapd_links (userid, link, view_state, view_metadata, update_time) "
3455  "VALUES (?,?,?,?, "
3456  "datetime('now'))",
3457  std::vector<std::string>{
3458  std::to_string(ld.userId), ld.link, ld.viewState, ld.viewMetadata});
3459  }
3460  // now get the auto generated dashid
3462  "SELECT linkid, strftime('%Y-%m-%dT%H:%M:%SZ', update_time) FROM mapd_links "
3463  "WHERE link = ?",
3464  ld.link);
3465  ld.linkId = sqliteConnector_.getData<int>(0, 0);
3466  ld.updateTime = sqliteConnector_.getData<std::string>(0, 1);
3467  } catch (std::exception& e) {
3468  sqliteConnector_.query("ROLLBACK TRANSACTION");
3469  throw;
3470  }
3471  sqliteConnector_.query("END TRANSACTION");
3472  addLinkToMap(ld);
3473  return ld.link;
3474 }
T getData(const int row, const int col)
virtual void query_with_text_params(std::string const &query_only)
SqliteConnector sqliteConnector_
Definition: Catalog.h:471
virtual void query(const std::string &queryString)
std::string to_string(char const *&&v)
std::string calculateSHA1(const std::string &data)
Definition: Catalog.cpp:3425
void addLinkToMap(LinkDescriptor &ld)
Definition: Catalog.cpp:1360
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:112
mapd_unique_lock< mapd_shared_mutex > write_lock
sqlite_lock< Catalog > cat_sqlite_lock
Definition: Catalog.cpp:113
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 1319 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 createDashboard(), createDashboardSystemRoles(), and replaceDashboard().

1321  {
1322  auto objects = parseDashboardObjects(view_meta, user_id);
1323  Role* rl = SysCatalog::instance().getRoleGrantee(dash_role_name);
1324  if (!rl) {
1325  // Dashboard role does not exist
1326  // create role and grant privileges
1327  // NOTE(wamsi): Transactionally unsafe
1328  SysCatalog::instance().createRole(dash_role_name, false);
1329  SysCatalog::instance().grantDBObjectPrivilegesBatch({dash_role_name}, objects, *this);
1330  } else {
1331  // Dashboard system role already exists
1332  // Add/remove privileges on objects
1333  auto ex_objects = rl->getDbObjects(true);
1334  for (auto key : *ex_objects | boost::adaptors::map_keys) {
1335  if (key.permissionType != TableDBObjectType &&
1336  key.permissionType != ViewDBObjectType) {
1337  continue;
1338  }
1339  bool found = false;
1340  for (auto obj : objects) {
1341  found = key == obj.getObjectKey() ? true : false;
1342  if (found) {
1343  break;
1344  }
1345  }
1346  if (!found) {
1347  // revoke privs on object since the object is no
1348  // longer used by the dashboard as source
1349  // NOTE(wamsi): Transactionally unsafe
1351  dash_role_name, *rl->findDbObject(key, true), *this);
1352  }
1353  }
1354  // Update privileges on remaining objects
1355  // NOTE(wamsi): Transactionally unsafe
1356  SysCatalog::instance().grantDBObjectPrivilegesBatch({dash_role_name}, objects, *this);
1357  }
1358 }
void revokeDBObjectPrivileges(const std::string &grantee, const DBObject &object, const Catalog_Namespace::Catalog &catalog)
Definition: Grantee.h:76
DBObject * findDbObject(const DBObjectKey &objectKey, bool only_direct) const
Definition: Grantee.cpp:72
void createRole(const std::string &roleName, const bool &userPrivateRole=false)
static SysCatalog & instance()
Definition: SysCatalog.h:288
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:1289

+ 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 2966 of file Catalog.cpp.

References CHECK(), createTable(), generatePhysicalTableName(), logicalToPhysicalTableMapById_, TableDescriptor::nShards, TableDescriptor::shard, table_is_temporary(), TableDescriptor::tableId, TableDescriptor::tableName, and updateLogicalToPhysicalTableMap().

2969  {
2970  cat_write_lock write_lock(this);
2971 
2972  /* create logical table */
2973  TableDescriptor* tdl = &td;
2974  createTable(*tdl, cols, shared_dict_defs, true); // create logical table
2975  int32_t logical_tb_id = tdl->tableId;
2976 
2977  /* create physical tables and link them to the logical table */
2978  std::vector<int32_t> physicalTables;
2979  for (int32_t i = 1; i <= td.nShards; i++) {
2980  TableDescriptor* tdp = &td;
2982  tdp->shard = i - 1;
2983  createTable(*tdp, cols, shared_dict_defs, false); // create physical table
2984  int32_t physical_tb_id = tdp->tableId;
2985 
2986  /* add physical table to the vector of physical tables */
2987  physicalTables.push_back(physical_tb_id);
2988  }
2989 
2990  if (!physicalTables.empty()) {
2991  /* add logical to physical tables correspondence to the map */
2992  const auto it_ok =
2993  logicalToPhysicalTableMapById_.emplace(logical_tb_id, physicalTables);
2994  CHECK(it_ok.second);
2995  /* update sqlite mapd_logical_to_physical in sqlite database */
2996  if (!table_is_temporary(&td)) {
2997  updateLogicalToPhysicalTableMap(logical_tb_id);
2998  }
2999  }
3000 }
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:2118
std::string generatePhysicalTableName(const std::string &logicalTableName, const int32_t &shardNumber)
Definition: Catalog.cpp:3647
CHECK(cgen_state)
bool table_is_temporary(const TableDescriptor *const td)
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:112
mapd_unique_lock< mapd_shared_mutex > write_lock
specifies the content in-memory of a row in the table metadata table
LogicalToPhysicalTableMapById logicalToPhysicalTableMapById_
Definition: Catalog.h:478
void updateLogicalToPhysicalTableMap(const int32_t logical_tb_id)
Definition: Catalog.cpp:561

+ Here is the call graph for this function:

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 2118 of file Catalog.cpp.

References addTableToMap(), calciteMgr_, ColumnDescriptor::columnId, TableDescriptor::columnIdBySpi_, ColumnDescriptor::columnName, ColumnDescriptor::columnType, currentDB_, Catalog_Namespace::DBMetadata::dbId, Catalog_Namespace::DBMetadata::dbName, dict_ref_t::dictId, Data_Namespace::DISK_LEVEL, expandGeoColumn(), StorageType::FOREIGN_TABLE, TableDescriptor::fragPageSize, TableDescriptor::fragType, g_enable_fsi, g_serialize_temp_tables, g_test_against_columnId_gap, 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(), getCurrentDB(), SqliteConnector::getData(), TableDescriptor::hasDeletedCol, SQLTypeInfo::is_array(), ColumnDescriptor::isDeletedCol, ColumnDescriptor::isGeoPhyCol, ColumnDescriptor::isSystemCol, TableDescriptor::isView, ColumnDescriptor::isVirtualCol, kBIGINT, kBOOLEAN, kENCODING_DICT, TableDescriptor::keyMetainfo, TableDescriptor::maxChunkSize, TableDescriptor::maxFragRows, TableDescriptor::maxRows, TableDescriptor::nColumns, nextTempDictId_, nextTempTableId_, TableDescriptor::nShards, TableDescriptor::partitions, TableDescriptor::persistenceLevel, ForeignStorageInterface::prepareTable(), SqliteConnector::query(), SqliteConnector::query_with_text_param(), SqliteConnector::query_with_text_params(), ForeignStorageInterface::registerTable(), removeTableFromMap(), 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 createShardedTable().

2122  {
2123  cat_write_lock write_lock(this);
2124  list<ColumnDescriptor> cds = cols;
2125  list<DictDescriptor> dds;
2126  std::set<std::string> toplevel_column_names;
2127  list<ColumnDescriptor> columns;
2128 
2129  if (!td.storageType.empty() &&
2132  throw std::runtime_error("Only temporary tables can be backed by foreign storage.");
2133  }
2135  }
2136 
2137  for (auto cd : cds) {
2138  if (cd.columnName == "rowid") {
2139  throw std::runtime_error(
2140  "Cannot create column with name rowid. rowid is a system defined column.");
2141  }
2142  columns.push_back(cd);
2143  toplevel_column_names.insert(cd.columnName);
2144  if (cd.columnType.is_geometry()) {
2145  expandGeoColumn(cd, columns);
2146  }
2147  }
2148  cds.clear();
2149 
2150  ColumnDescriptor cd;
2151  // add row_id column -- Must be last column in the table
2152  cd.columnName = "rowid";
2153  cd.isSystemCol = true;
2154  cd.columnType = SQLTypeInfo(kBIGINT, true);
2155 #ifdef MATERIALIZED_ROWID
2156  cd.isVirtualCol = false;
2157 #else
2158  cd.isVirtualCol = true;
2159  cd.virtualExpr = "MAPD_FRAG_ID * MAPD_ROWS_PER_FRAG + MAPD_FRAG_ROW_ID";
2160 #endif
2161  columns.push_back(cd);
2162  toplevel_column_names.insert(cd.columnName);
2163 
2164  if (td.hasDeletedCol) {
2165  ColumnDescriptor cd_del;
2166  cd_del.columnName = "$deleted$";
2167  cd_del.isSystemCol = true;
2168  cd_del.isVirtualCol = false;
2169  cd_del.columnType = SQLTypeInfo(kBOOLEAN, true);
2170  cd_del.isDeletedCol = true;
2171 
2172  columns.push_back(cd_del);
2173  }
2174 
2175  td.nColumns = columns.size();
2176  cat_sqlite_lock sqlite_lock(this);
2177  sqliteConnector_.query("BEGIN TRANSACTION");
2179  try {
2181  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, key_metainfo) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?))",
2182  std::vector<std::string>{td.tableName,
2183  std::to_string(td.userId),
2185  std::to_string(td.isView),
2186  "",
2191  std::to_string(td.maxRows),
2192  td.partitions,
2194  std::to_string(td.shard),
2195  std::to_string(td.nShards),
2197  td.storageType,
2198  td.keyMetainfo});
2199 
2200  // now get the auto generated tableid
2202  "SELECT tableid FROM mapd_tables WHERE name = ?", td.tableName);
2203  td.tableId = sqliteConnector_.getData<int>(0, 0);
2204  int colId = 1;
2205  for (auto cd : columns) {
2207  const bool is_foreign_col =
2208  setColumnSharedDictionary(cd, cds, dds, td, shared_dict_defs);
2209  if (!is_foreign_col) {
2210  setColumnDictionary(cd, dds, td, isLogicalTable);
2211  }
2212  }
2213 
2214  if (toplevel_column_names.count(cd.columnName)) {
2215  // make up colId gap for sanity test (begin with 1 bc much code depends on it!)
2216  if (colId > 1) {
2217  colId += g_test_against_columnId_gap;
2218  }
2219  if (!cd.isGeoPhyCol) {
2220  td.columnIdBySpi_.push_back(colId);
2221  }
2222  }
2223 
2225  "INSERT INTO mapd_columns (tableid, columnid, name, coltype, colsubtype, "
2226  "coldim, colscale, is_notnull, "
2227  "compression, comp_param, size, chunks, is_systemcol, is_virtualcol, "
2228  "virtual_expr, is_deletedcol) "
2229  "VALUES (?, ?, ?, ?, ?, "
2230  "?, "
2231  "?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
2232  std::vector<std::string>{std::to_string(td.tableId),
2233  std::to_string(colId),
2234  cd.columnName,
2243  "",
2246  cd.virtualExpr,
2248  cd.tableId = td.tableId;
2249  cd.columnId = colId++;
2250  cds.push_back(cd);
2251  }
2252  if (td.isView) {
2254  "INSERT INTO mapd_views (tableid, sql) VALUES (?,?)",
2255  std::vector<std::string>{std::to_string(td.tableId), td.viewSQL});
2256  }
2258  auto& foreignTable = dynamic_cast<foreign_storage::ForeignTable&>(td);
2260  "INSERT INTO omnisci_foreign_tables (table_id, server_id, options) VALUES "
2261  "(?, ?, ?)",
2262  std::vector<std::string>{std::to_string(foreignTable.tableId),
2263  std::to_string(foreignTable.foreign_server->id),
2264  foreignTable.getOptionsAsJsonString()});
2265  }
2266  } catch (std::exception& e) {
2267  sqliteConnector_.query("ROLLBACK TRANSACTION");
2268  throw;
2269  }
2270  } else { // Temporary table
2271  td.tableId = nextTempTableId_++;
2272  int colId = 1;
2273  for (auto cd : columns) {
2275  const bool is_foreign_col =
2276  setColumnSharedDictionary(cd, cds, dds, td, shared_dict_defs);
2277 
2278  if (!is_foreign_col) {
2279  // Create a new temporary dictionary
2280  std::string fileName("");
2281  std::string folderPath("");
2283  nextTempDictId_++;
2284  DictDescriptor dd(dict_ref,
2285  fileName,
2287  false,
2288  1,
2289  folderPath,
2290  true); // Is dictName (2nd argument) used?
2291  dds.push_back(dd);
2292  if (!cd.columnType.is_array()) {
2294  }
2295  cd.columnType.set_comp_param(dict_ref.dictId);
2296  }
2297  }
2298  if (toplevel_column_names.count(cd.columnName)) {
2299  // make up colId gap for sanity test (begin with 1 bc much code depends on it!)
2300  if (colId > 1) {
2301  colId += g_test_against_columnId_gap;
2302  }
2303  if (!cd.isGeoPhyCol) {
2304  td.columnIdBySpi_.push_back(colId);
2305  }
2306  }
2307  cd.tableId = td.tableId;
2308  cd.columnId = colId++;
2309  cds.push_back(cd);
2310  }
2311 
2313  serializeTableJsonUnlocked(&td, cds);
2314  }
2315  }
2316 
2317  try {
2318  addTableToMap(&td, cds, dds);
2319  calciteMgr_->updateMetadata(currentDB_.dbName, td.tableName);
2320  if (!td.storageType.empty() && td.storageType != StorageType::FOREIGN_TABLE) {
2322  }
2323  } catch (std::exception& e) {
2324  sqliteConnector_.query("ROLLBACK TRANSACTION");
2325  removeTableFromMap(td.tableName, td.tableId, true);
2326  throw;
2327  }
2328  sqliteConnector_.query("END TRANSACTION");
2329 }
void serializeTableJsonUnlocked(const TableDescriptor *td, const std::list< ColumnDescriptor > &cds) const
Definition: Catalog.cpp:2331
std::string virtualExpr
HOST DEVICE SQLTypes get_subtype() const
Definition: sqltypes.h:259
void set_size(int s)
Definition: sqltypes.h:356
std::string partitions
HOST DEVICE int get_size() const
Definition: sqltypes.h:268
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:471
HOST DEVICE int get_scale() const
Definition: sqltypes.h:263
std::string storageType
virtual void query(const std::string &queryString)
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:258
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:1137
const DBMetadata & getCurrentDB() const
Definition: Catalog.h:194
specifies the content in-memory of a row in the column metadata table
static void registerTable(Catalog_Namespace::Catalog *catalog, const TableDescriptor &td, const std::list< ColumnDescriptor > &cols)
ids are created
static void expandGeoColumn(const ColumnDescriptor &cd, std::list< ColumnDescriptor > &columns)
Definition: Catalog.cpp:1988
std::string keyMetainfo
int g_test_against_columnId_gap
Definition: Catalog.cpp:89
bool g_serialize_temp_tables
Definition: Catalog.cpp:95
void set_comp_param(int p)
Definition: sqltypes.h:359
std::shared_ptr< Calcite > calciteMgr_
Definition: Catalog.h:476
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:266
Fragmenter_Namespace::FragmenterType fragType
Data_Namespace::MemoryLevel persistenceLevel
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:260
void removeTableFromMap(const std::string &tableName, const int tableId, const bool is_on_error=false)
Definition: Catalog.cpp:1197
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:112
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:267
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:2856
Descriptor for a dictionary for a string columne.
std::string viewSQL
mapd_unique_lock< mapd_shared_mutex > write_lock
SQLTypeInfo columnType
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:265
sqlite_lock< Catalog > cat_sqlite_lock
Definition: Catalog.cpp:113
void setColumnDictionary(ColumnDescriptor &cd, std::list< DictDescriptor > &dds, const TableDescriptor &td, const bool isLogicalTable)
Definition: Catalog.cpp:2925
static constexpr char const * FOREIGN_TABLE
bool g_enable_fsi
Definition: Catalog.cpp:90
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:423
static void prepareTable(const int db_id, TableDescriptor &td, std::list< ColumnDescriptor > &cols)
prepare table options and modify columns

+ 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 1771 of file Catalog.cpp.

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

Referenced by roll().

1771  {
1772  cat_write_lock write_lock(this);
1773  cat_sqlite_lock sqlite_lock(this);
1774  if (!(cd.columnType.is_string() || cd.columnType.is_string_array())) {
1775  return;
1776  }
1777  if (!(cd.columnType.get_compression() == kENCODING_DICT)) {
1778  return;
1779  }
1780  const auto dictId = cd.columnType.get_comp_param();
1781  CHECK_GT(dictId, 0);
1782  // decrement and zero check dict ref count
1783  const auto td = getMetadataForTable(cd.tableId);
1784  CHECK(td);
1786  "UPDATE mapd_dictionaries SET refcount = refcount - 1 WHERE dictid = ?",
1787  std::to_string(dictId));
1789  "SELECT refcount FROM mapd_dictionaries WHERE dictid = ?", std::to_string(dictId));
1790  const auto refcount = sqliteConnector_.getData<int>(0, 0);
1791  VLOG(3) << "Dictionary " << dictId << "from dropped table has reference count "
1792  << refcount;
1793  if (refcount > 0) {
1794  return;
1795  }
1796  const DictRef dictRef(currentDB_.dbId, dictId);
1797  sqliteConnector_.query_with_text_param("DELETE FROM mapd_dictionaries WHERE dictid = ?",
1798  std::to_string(dictId));
1799  File_Namespace::renameForDelete(basePath_ + "/mapd_data/DB_" +
1800  std::to_string(currentDB_.dbId) + "_DICT_" +
1801  std::to_string(dictId));
1802 
1803  std::unique_ptr<StringDictionaryClient> client;
1804  if (!string_dict_hosts_.empty()) {
1805  client.reset(new StringDictionaryClient(string_dict_hosts_.front(), dictRef, true));
1806  }
1807  if (client) {
1808  client->drop(dictRef);
1809  }
1810 
1811  dictDescriptorMapByRef_.erase(dictRef);
1812 }
T getData(const int row, const int col)
SqliteConnector sqliteConnector_
Definition: Catalog.h:471
const std::vector< LeafHostInfo > string_dict_hosts_
Definition: Catalog.h:475
DictDescriptorMapById dictDescriptorMapByRef_
Definition: Catalog.h:464
#define CHECK_GT(x, y)
Definition: Logger.h:209
std::string to_string(char const *&&v)
CHECK(cgen_state)
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:266
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:112
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:267
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:415
void renameForDelete(const std::string directoryName)
Renames a directory to DELETE_ME_&lt;EPOCH&gt;_&lt;oldname&gt;.
Definition: File.cpp:182
sqlite_lock< Catalog > cat_sqlite_lock
Definition: Catalog.cpp:113
bool is_string_array() const
Definition: sqltypes.h:416
virtual void query_with_text_param(const std::string &queryString, const std::string &text_param)
#define VLOG(n)
Definition: Logger.h:291

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 1555 of file Catalog.cpp.

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

1556  {
1557  std::stringstream invalid_ids, restricted_ids;
1558 
1559  for (int32_t dashboard_id : dashboard_ids) {
1560  if (!getMetadataForDashboard(dashboard_id)) {
1561  invalid_ids << (!invalid_ids.str().empty() ? ", " : "") << dashboard_id;
1562  continue;
1563  }
1564  DBObject object(dashboard_id, DashboardDBObjectType);
1565  object.loadKey(*this);
1566  object.setPrivileges(AccessPrivileges::DELETE_DASHBOARD);
1567  std::vector<DBObject> privs = {object};
1568  if (!SysCatalog::instance().checkPrivileges(user, privs))
1569  restricted_ids << (!restricted_ids.str().empty() ? ", " : "") << dashboard_id;
1570  }
1571 
1572  if (invalid_ids.str().size() > 0 || restricted_ids.str().size() > 0) {
1573  std::stringstream error_message;
1574  error_message << "Delete dashboard(s) failed with error(s):";
1575  if (invalid_ids.str().size() > 0)
1576  error_message << "\nDashboard id: " << invalid_ids.str()
1577  << " - Dashboard id does not exist";
1578  if (restricted_ids.str().size() > 0)
1579  error_message
1580  << "\nDashboard id: " << restricted_ids.str()
1581  << " - User should be either owner of dashboard or super user to delete it";
1582  throw std::runtime_error(error_message.str());
1583  }
1584  std::vector<DBObject> dash_objs;
1585 
1586  for (int32_t dashboard_id : dashboard_ids) {
1587  dash_objs.push_back(DBObject(dashboard_id, DashboardDBObjectType));
1588  }
1589  // BE-5245: Transactionally unsafe (like other combined Catalog/Syscatalog operations)
1591  {
1592  cat_write_lock write_lock(this);
1593  cat_sqlite_lock sqlite_lock(this);
1594 
1595  sqliteConnector_.query("BEGIN TRANSACTION");
1596  try {
1597  for (int32_t dashboard_id : dashboard_ids) {
1598  auto dash = getMetadataForDashboard(dashboard_id);
1599  // Dash should still exist if revokeDBObjectPrivileges passed but throw and
1600  // rollback if already deleted
1601  if (!dash) {
1602  throw std::runtime_error(
1603  std::string("Delete dashboard(s) failed with error(s):\nDashboard id: ") +
1604  std::to_string(dashboard_id) + " - Dashboard id does not exist ");
1605  }
1606  std::string user_id = std::to_string(dash->userId);
1607  std::string dash_name = dash->dashboardName;
1608  auto viewDescIt = dashboardDescriptorMap_.find(user_id + ":" + dash_name);
1609  dashboardDescriptorMap_.erase(viewDescIt);
1611  "DELETE FROM mapd_dashboards WHERE name = ? and userid = ?",
1612  std::vector<std::string>{dash_name, user_id});
1613  }
1614  } catch (std::exception& e) {
1615  sqliteConnector_.query("ROLLBACK TRANSACTION");
1616  throw;
1617  }
1618  sqliteConnector_.query("END TRANSACTION");
1619  }
1620 }
virtual void query_with_text_params(std::string const &query_only)
SqliteConnector sqliteConnector_
Definition: Catalog.h:471
virtual void query(const std::string &queryString)
DashboardDescriptorMap dashboardDescriptorMap_
Definition: Catalog.h:465
std::string to_string(char const *&&v)
static SysCatalog & instance()
Definition: SysCatalog.h:288
const DashboardDescriptor * getMetadataForDashboard(const std::string &userId, const std::string &dashName) const
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:112
static const AccessPrivileges DELETE_DASHBOARD
Definition: DBObject.h:174
mapd_unique_lock< mapd_shared_mutex > write_lock
sqlite_lock< Catalog > cat_sqlite_lock
Definition: Catalog.cpp:113
void revokeDBObjectPrivilegesFromAllBatch(std::vector< DBObject > &objects, Catalog *catalog)

+ Here is the call graph for this function:

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

Definition at line 3144 of file Catalog.cpp.

References dropTableFromJsonUnlocked(), eraseTablePhysicalData(), executeDropTableSqliteQueries(), g_serialize_temp_tables, table_is_temporary(), and TableDescriptor::tableName.

Referenced by dropTable().

3144  {
3148  }
3150 }
void executeDropTableSqliteQueries(const TableDescriptor *td)
Definition: Catalog.cpp:3152
void eraseTablePhysicalData(const TableDescriptor *td)
Definition: Catalog.cpp:3618
std::string tableName
void dropTableFromJsonUnlocked(const std::string &table_name) const
Definition: Catalog.cpp:2393
bool g_serialize_temp_tables
Definition: Catalog.cpp:95
bool table_is_temporary(const TableDescriptor *const td)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 3020 of file Catalog.cpp.

References CHECK(), CHECK_GE, columnDescriptorMapById_, ColumnDescriptor::columnType, Data_Namespace::CPU_LEVEL, currentDB_, dataMgr_, Catalog_Namespace::DBMetadata::dbId, dictDescriptorMapByRef_, dict_ref_t::dictId, DictDescriptor::dictIsTemp, DictDescriptor::dictRef, TableDescriptor::fragmenter, SQLTypeInfo::get_comp_param(), SQLTypeInfo::get_compression(), getMetadataForDict(), Data_Namespace::GPU_LEVEL, Catalog_Namespace::SysCatalog::instance(), kENCODING_DICT, File_Namespace::renameForDelete(), string_dict_hosts_, tableDescriptorMapById_, ColumnDescriptor::tableId, and TableDescriptor::tableId.

Referenced by truncateTable().

3020  {
3021  cat_write_lock write_lock(this);
3022 
3023  const int tableId = td->tableId;
3024  // must destroy fragmenter before deleteChunks is called.
3025  if (td->fragmenter != nullptr) {
3026  auto tableDescIt = tableDescriptorMapById_.find(tableId);
3027  CHECK(tableDescIt != tableDescriptorMapById_.end());
3028  tableDescIt->second->fragmenter = nullptr;
3029  CHECK(td->fragmenter == nullptr);
3030  }
3031  ChunkKey chunkKeyPrefix = {currentDB_.dbId, tableId};
3032  // assuming deleteChunksWithPrefix is atomic
3033  dataMgr_->deleteChunksWithPrefix(chunkKeyPrefix, MemoryLevel::CPU_LEVEL);
3034  dataMgr_->deleteChunksWithPrefix(chunkKeyPrefix, MemoryLevel::GPU_LEVEL);
3035 
3036  dataMgr_->removeTableRelatedDS(currentDB_.dbId, tableId);
3037 
3038  std::unique_ptr<StringDictionaryClient> client;
3039  if (SysCatalog::instance().isAggregator()) {
3040  CHECK(!string_dict_hosts_.empty());
3041  DictRef dict_ref(currentDB_.dbId, -1);
3042  client.reset(new StringDictionaryClient(string_dict_hosts_.front(), dict_ref, true));
3043  }
3044  // clean up any dictionaries
3045  // delete all column descriptors for the table
3046  for (const auto& columnDescriptor : columnDescriptorMapById_) {
3047  auto cd = columnDescriptor.second;
3048  if (cd->tableId != td->tableId) {
3049  continue;
3050  }
3051  const int dict_id = cd->columnType.get_comp_param();
3052  // Dummy dictionaries created for a shard of a logical table have the id set to zero.
3053  if (cd->columnType.get_compression() == kENCODING_DICT && dict_id) {
3054  const DictRef dict_ref(currentDB_.dbId, dict_id);
3055  const auto dictIt = dictDescriptorMapByRef_.find(dict_ref);
3056  CHECK(dictIt != dictDescriptorMapByRef_.end());
3057  const auto& dd = dictIt->second;
3058  CHECK_GE(dd->refcount, 1);
3059  // if this is the only table using this dict reset the dict
3060  if (dd->refcount == 1) {
3061  // close the dictionary
3062  dd->stringDict.reset();
3063  File_Namespace::renameForDelete(dd->dictFolderPath);
3064  if (client) {
3065  client->drop(dd->dictRef);
3066  }
3067  if (!dd->dictIsTemp) {
3068  boost::filesystem::create_directory(dd->dictFolderPath);
3069  }
3070  }
3071 
3072  DictDescriptor* new_dd = new DictDescriptor(dd->dictRef,
3073  dd->dictName,
3074  dd->dictNBits,
3075  dd->dictIsShared,
3076  dd->refcount,
3077  dd->dictFolderPath,
3078  dd->dictIsTemp);
3079  dictDescriptorMapByRef_.erase(dictIt);
3080  // now create new Dict -- need to figure out what to do here for temp tables
3081  if (client) {
3082  client->create(new_dd->dictRef, new_dd->dictIsTemp);
3083  }
3084  dictDescriptorMapByRef_[new_dd->dictRef].reset(new_dd);
3086  }
3087  }
3088 }
std::vector< int > ChunkKey
Definition: types.h:35
const std::vector< LeafHostInfo > string_dict_hosts_
Definition: Catalog.h:475
DictDescriptorMapById dictDescriptorMapByRef_
Definition: Catalog.h:464
std::shared_ptr< Data_Namespace::DataMgr > dataMgr_
Definition: Catalog.h:473
#define CHECK_GE(x, y)
Definition: Logger.h:210
ColumnDescriptorMapById columnDescriptorMapById_
Definition: Catalog.h:463
static SysCatalog & instance()
Definition: SysCatalog.h:288
CHECK(cgen_state)
TableDescriptorMapById tableDescriptorMapById_
Definition: Catalog.h:461
const DictDescriptor * getMetadataForDict(int dict_ref, bool loadDict=true) const
Definition: Catalog.cpp:1449
int32_t dictId
Definition: DictRef.h:10
std::shared_ptr< Fragmenter_Namespace::AbstractFragmenter > fragmenter
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:112
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:182

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 1899 of file Catalog.cpp.

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

1899  {
1900  cat_write_lock write_lock(this);
1901  cat_sqlite_lock sqlite_lock(this);
1902  // caller must handle sqlite/chunk transaction TOGETHER
1904  "DELETE FROM mapd_columns where tableid = ? and columnid = ?",
1905  std::vector<std::string>{std::to_string(td.tableId), std::to_string(cd.columnId)});
1906 
1908  "UPDATE mapd_tables SET ncolumns = ncolumns - 1 WHERE tableid = ?",
1909  std::vector<std::string>{std::to_string(td.tableId)});
1910 
1911  ColumnDescriptorMap::iterator columnDescIt =
1913  CHECK(columnDescIt != columnDescriptorMap_.end());
1914 
1915  columnDescriptorsForRoll.emplace_back(columnDescIt->second, nullptr);
1916 
1917  columnDescriptorMap_.erase(columnDescIt);
1919  --tableDescriptorMapById_[td.tableId]->nColumns;
1920  // for each shard
1921  if (td.nShards > 0 && td.shard < 0) {
1922  for (const auto shard : getPhysicalTablesDescriptors(&td)) {
1923  const auto shard_cd = getMetadataForColumn(shard->tableId, cd.columnId);
1924  CHECK(shard_cd);
1925  dropColumn(*shard, *shard_cd);
1926  }
1927  }
1928 }
std::tuple< int, std::string > ColumnKey
Definition: Types.h:36
ColumnDescriptorMap columnDescriptorMap_
Definition: Catalog.h:462
virtual void query_with_text_params(std::string const &query_only)
SqliteConnector sqliteConnector_
Definition: Catalog.h:471
std::vector< const TableDescriptor * > getPhysicalTablesDescriptors(const TableDescriptor *logicalTableDesc) const
Definition: Catalog.cpp:3494
void dropColumn(const TableDescriptor &td, const ColumnDescriptor &cd)
Definition: Catalog.cpp:1899
ColumnDescriptorMapById columnDescriptorMapById_
Definition: Catalog.h:463
std::string to_string(char const *&&v)
CHECK(cgen_state)
const ColumnDescriptor * getMetadataForColumn(int tableId, const std::string &colName) const
TableDescriptorMapById tableDescriptorMapById_
Definition: Catalog.h:461
std::string to_upper(const std::string &str)
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:112
mapd_unique_lock< mapd_shared_mutex > write_lock
sqlite_lock< Catalog > cat_sqlite_lock
Definition: Catalog.cpp:113
ColumnDescriptorsForRoll columnDescriptorsForRoll
Definition: Catalog.h:490
std::string columnName
std::tuple< int, int > ColumnIdKey
Definition: Types.h:38

+ 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 2562 of file Catalog.cpp.

References CHECK_EQ, foreignServerMap_, foreignServerMapById_, SqliteConnector::getData(), SqliteConnector::getNumRows(), num_rows, SqliteConnector::query(), SqliteConnector::query_with_text_param(), SqliteConnector::query_with_text_params(), sqliteConnector_, and to_string().

2562  {
2563  cat_write_lock write_lock(this);
2564  cat_sqlite_lock sqlite_lock(this);
2565 
2567  "SELECT id from omnisci_foreign_servers where name = ?",
2568  std::vector<std::string>{server_name});
2570  if (num_rows > 0) {
2571  CHECK_EQ(size_t(1), num_rows);
2572  auto server_id = sqliteConnector_.getData<int32_t>(0, 0);
2574  "SELECT table_id from omnisci_foreign_tables where server_id = ?",
2575  std::to_string(server_id));
2576  if (sqliteConnector_.getNumRows() > 0) {
2577  throw std::runtime_error{"Foreign server \"" + server_name +
2578  "\" is referenced "
2579  "by existing foreign tables and cannot be dropped."};
2580  }
2581  sqliteConnector_.query("BEGIN TRANSACTION");
2582  try {
2584  "DELETE FROM omnisci_foreign_servers WHERE name = ?",
2585  std::vector<std::string>{server_name});
2586  } catch (const std::exception& e) {
2587  sqliteConnector_.query("ROLLBACK TRANSACTION");
2588  throw;
2589  }
2590  sqliteConnector_.query("END TRANSACTION");
2591  foreignServerMap_.erase(server_name);
2592  foreignServerMapById_.erase(server_id);
2593  }
2594 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
T getData(const int row, const int col)
const int8_t const int64_t * num_rows
virtual void query_with_text_params(std::string const &query_only)
SqliteConnector sqliteConnector_
Definition: Catalog.h:471
virtual void query(const std::string &queryString)
std::string to_string(char const *&&v)
ForeignServerMapById foreignServerMapById_
Definition: Catalog.h:469
ForeignServerMap foreignServerMap_
Definition: Catalog.h:468
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:112
mapd_unique_lock< mapd_shared_mutex > write_lock
sqlite_lock< Catalog > cat_sqlite_lock
Definition: Catalog.cpp:113
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::dropFsiSchemasAndTables ( )
protected

Definition at line 622 of file Catalog.cpp.

References CHECK_EQ, executeDropTableSqliteQueries(), SqliteConnector::getData(), SqliteConnector::getNumRows(), Catalog_Namespace::SysCatalog::instance(), num_rows, SqliteConnector::query(), Catalog_Namespace::SysCatalog::revokeDBObjectPrivilegesFromAll(), sqliteConnector_, TableDBObjectType, tableDescriptorMap_, tableDescriptorMapById_, TableDescriptor::tableId, and to_upper().

Referenced by CheckAndExecuteMigrations().

622  {
623  std::vector<foreign_storage::ForeignTable> foreign_tables{};
624  {
625  cat_sqlite_lock sqlite_lock(this);
626  sqliteConnector_.query("BEGIN TRANSACTION");
627  try {
629  "SELECT name FROM sqlite_master WHERE type='table' AND "
630  "name IN ('omnisci_foreign_servers', 'omnisci_foreign_tables', "
631  "'omnisci_user_mappings')");
632  if (sqliteConnector_.getNumRows() > 0) {
634  "SELECT tableid, name, isview, storage_type FROM mapd_tables "
635  "WHERE storage_type = 'FOREIGN_TABLE'");
637  for (size_t r = 0; r < num_rows; r++) {
638  foreign_storage::ForeignTable foreign_table{};
639  foreign_table.tableId = sqliteConnector_.getData<int>(r, 0);
640  foreign_table.tableName = sqliteConnector_.getData<std::string>(r, 1);
641  foreign_table.isView = sqliteConnector_.getData<bool>(r, 2);
642  foreign_table.storageType = sqliteConnector_.getData<std::string>(r, 3);
643  foreign_tables.emplace_back(foreign_table);
644  }
645  for (auto& foreign_table : foreign_tables) {
646  tableDescriptorMap_[to_upper(foreign_table.tableName)] = &foreign_table;
647  tableDescriptorMapById_[foreign_table.tableId] = &foreign_table;
648  executeDropTableSqliteQueries(&foreign_table);
649  }
650  sqliteConnector_.query("SELECT COUNT(*) FROM omnisci_foreign_tables");
651  CHECK_EQ(size_t(1), sqliteConnector_.getNumRows());
652  CHECK_EQ(0, sqliteConnector_.getData<int>(0, 0));
653 
654  sqliteConnector_.query("DROP TABLE omnisci_foreign_tables");
655  sqliteConnector_.query("DROP TABLE omnisci_foreign_servers");
656  }
657  } catch (std::exception& e) {
658  sqliteConnector_.query("ROLLBACK TRANSACTION");
659  throw;
660  }
661  sqliteConnector_.query("END TRANSACTION");
662  }
663 
664  for (auto& foreign_table : foreign_tables) {
666  DBObject(foreign_table.tableName, TableDBObjectType), this);
667  tableDescriptorMap_.erase(to_upper(foreign_table.tableName));
668  tableDescriptorMapById_.erase(foreign_table.tableId);
669  }
670 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
void executeDropTableSqliteQueries(const TableDescriptor *td)
Definition: Catalog.cpp:3152
T getData(const int row, const int col)
const int8_t const int64_t * num_rows
SqliteConnector sqliteConnector_
Definition: Catalog.h:471
void revokeDBObjectPrivilegesFromAll(DBObject object, Catalog *catalog)
virtual void query(const std::string &queryString)
static SysCatalog & instance()
Definition: SysCatalog.h:288
TableDescriptorMapById tableDescriptorMapById_
Definition: Catalog.h:461
std::string to_upper(const std::string &str)
sqlite_lock< Catalog > cat_sqlite_lock
Definition: Catalog.cpp:113
virtual size_t getNumRows() const
TableDescriptorMap tableDescriptorMap_
Definition: Catalog.h:460

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 3111 of file Catalog.cpp.

References CHECK(), doDropTable(), getMetadataForTable(), Catalog_Namespace::SysCatalog::instance(), TableDescriptor::isView, logicalToPhysicalTableMapById_, SqliteConnector::query(), SqliteConnector::query_with_text_param(), Catalog_Namespace::SysCatalog::revokeDBObjectPrivilegesFromAll(), sqliteConnector_, TableDBObjectType, TableDescriptor::tableId, TableDescriptor::tableName, to_string(), and ViewDBObjectType.

3111  {
3114  cat_write_lock write_lock(this);
3115  cat_sqlite_lock sqlite_lock(this);
3116  const auto physicalTableIt = logicalToPhysicalTableMapById_.find(td->tableId);
3117  sqliteConnector_.query("BEGIN TRANSACTION");
3118  try {
3119  if (physicalTableIt != logicalToPhysicalTableMapById_.end()) {
3120  // remove all corresponding physical tables if this is a logical table
3121  const auto physicalTables = physicalTableIt->second;
3122  CHECK(!physicalTables.empty());
3123  for (size_t i = 0; i < physicalTables.size(); i++) {
3124  int32_t physical_tb_id = physicalTables[i];
3125  const TableDescriptor* phys_td = getMetadataForTable(physical_tb_id);
3126  CHECK(phys_td);
3127  doDropTable(phys_td);
3128  }
3129 
3130  // remove corresponding record from the logicalToPhysicalTableMap in sqlite database
3132  "DELETE FROM mapd_logical_to_physical WHERE logical_table_id = ?",
3133  std::to_string(td->tableId));
3135  }
3136  doDropTable(td);
3137  } catch (std::exception& e) {
3138  sqliteConnector_.query("ROLLBACK TRANSACTION");
3139  throw;
3140  }
3141  sqliteConnector_.query("END TRANSACTION");
3142 }
void doDropTable(const TableDescriptor *td)
Definition: Catalog.cpp:3144
std::string tableName
SqliteConnector sqliteConnector_
Definition: Catalog.h:471
void revokeDBObjectPrivilegesFromAll(DBObject object, Catalog *catalog)
virtual void query(const std::string &queryString)
std::string to_string(char const *&&v)
static SysCatalog & instance()
Definition: SysCatalog.h:288
CHECK(cgen_state)
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:112
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.
specifies the content in-memory of a row in the table metadata table
sqlite_lock< Catalog > cat_sqlite_lock
Definition: Catalog.cpp:113
virtual void query_with_text_param(const std::string &queryString, const std::string &text_param)
LogicalToPhysicalTableMapById logicalToPhysicalTableMapById_
Definition: Catalog.h:478

+ Here is the call graph for this function:

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

Definition at line 2393 of file Catalog.cpp.

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

Referenced by doDropTable().

2393  {
2394  // relies on the catalog write lock
2395  using namespace rapidjson;
2396 
2397  VLOG(1) << "Dropping temporary table " << table_name << " to JSON for Calcite.";
2398 
2399  const auto db_name = currentDB_.dbName;
2400  const auto file_path = table_json_filepath(basePath_, db_name);
2401 
2402  CHECK(boost::filesystem::exists(file_path));
2403  Document d;
2404 
2405  std::ifstream reader(file_path.string());
2406  CHECK(reader.is_open());
2407  IStreamWrapper json_read_wrapper(reader);
2408  d.ParseStream(json_read_wrapper);
2409 
2410  CHECK(d.IsObject());
2411  auto table_name_ref = StringRef(table_name.c_str());
2412  CHECK(d.HasMember(table_name_ref));
2413  CHECK(d.RemoveMember(table_name_ref));
2414 
2415  // Overwrite the existing file
2416  std::ofstream writer(file_path.string(), writer.trunc | writer.out);
2417  CHECK(writer.is_open());
2418  OStreamWrapper json_wrapper(writer);
2419 
2420  Writer<OStreamWrapper> json_writer(json_wrapper);
2421  d.Accept(json_writer);
2422  writer.close();
2423 }
auto table_json_filepath(const std::string &base_path, const std::string &db_name)
Definition: Catalog.cpp:152
CHECK(cgen_state)
#define VLOG(n)
Definition: Logger.h:291

+ Here is the call graph for this function:

+ Here is the caller 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 4020 of file Catalog.cpp.

References CHECK(), ColumnDescriptor::columnName, ColumnDescriptor::columnType, Catalog_Namespace::contains_spaces(), Catalog_Namespace::contains_sql_reserved_chars(), Data_Namespace::CPU_LEVEL, DEFAULT_FRAGMENT_ROWS, DEFAULT_MAX_CHUNK_SIZE, DEFAULT_MAX_ROWS, DEFAULT_PAGE_SIZE, TableDescriptor::fragPageSize, getAllColumnMetadataForTable(), getMetadataForColumn(), TableDescriptor::hasDeletedCol, Catalog_Namespace::is_reserved_sql_keyword(), ColumnDescriptor::isSystemCol, TableDescriptor::isView, ColumnDescriptor::isVirtualCol, join(), kCHAR, kENCODING_DICT, TableDescriptor::keyMetainfo, TableDescriptor::maxChunkSize, TableDescriptor::maxFragRows, TableDescriptor::maxRows, TableDescriptor::nShards, TableDescriptor::partitions, TableDescriptor::persistenceLevel, TableDescriptor::shardedColumnId, TableDescriptor::sortedColumnId, TableDescriptor::tableId, TableDescriptor::tableName, to_string(), Catalog_Namespace::anonymous_namespace{Catalog.cpp}::unserialize_key_metainfo(), and TableDescriptor::viewSQL.

4022  {
4023  cat_read_lock read_lock(this);
4024 
4025  std::ostringstream os;
4026 
4027  if (!td->isView) {
4028  os << "CREATE ";
4030  os << "TEMPORARY ";
4031  }
4032  os << "TABLE " + td->tableName + " (";
4033  } else {
4034  os << "CREATE VIEW " + td->tableName + " AS " << td->viewSQL;
4035  return os.str();
4036  }
4037  // scan column defines
4038  std::vector<std::string> shared_dicts;
4039  std::set<std::string> shared_dict_column_names;
4040  unserialize_key_metainfo(shared_dicts, shared_dict_column_names, td->keyMetainfo);
4041  // gather column defines
4042  const auto cds = getAllColumnMetadataForTable(td->tableId, false, false, false);
4043  std::map<const std::string, const ColumnDescriptor*> dict_root_cds;
4044  bool first = true;
4045  for (const auto cd : cds) {
4046  if (!(cd->isSystemCol || cd->isVirtualCol)) {
4047  const auto& ti = cd->columnType;
4048  if (!first) {
4049  os << ",";
4050  if (!multiline_formatting) {
4051  os << " ";
4052  }
4053  } else {
4054  first = false;
4055  }
4056  if (multiline_formatting) {
4057  os << "\n ";
4058  }
4059  // column name
4060  bool column_name_needs_quotes = is_reserved_sql_keyword(cd->columnName) ||
4061  contains_spaces(cd->columnName) ||
4062  contains_sql_reserved_chars(cd->columnName);
4063  if (!column_name_needs_quotes) {
4064  os << cd->columnName;
4065  } else {
4066  os << "\"" << cd->columnName << "\"";
4067  }
4068  // CHAR is perculiar... better dump it as TEXT(32) like \d does
4069  if (ti.get_type() == SQLTypes::kCHAR) {
4070  os << " "
4071  << "TEXT";
4072  } else if (ti.get_subtype() == SQLTypes::kCHAR) {
4073  os << " "
4074  << "TEXT[]";
4075  } else {
4076  os << " " << ti.get_type_name();
4077  }
4078  os << (ti.get_notnull() ? " NOT NULL" : "");
4079  if (shared_dict_column_names.find(cd->columnName) ==
4080  shared_dict_column_names.end()) {
4081  // avoids "Exception: Column ... shouldn't specify an encoding, it borrows it from
4082  // the referenced column"
4083  if (ti.is_string()) {
4084  if (ti.get_compression() == kENCODING_DICT) {
4085  os << " ENCODING " << ti.get_compression_name() << "(" << (ti.get_size() * 8)
4086  << ")";
4087  } else {
4088  os << " ENCODING NONE";
4089  }
4090  } else if (ti.is_date_in_days() ||
4091  (ti.get_size() > 0 && ti.get_size() != ti.get_logical_size())) {
4092  const auto comp_param = ti.get_comp_param() ? ti.get_comp_param() : 32;
4093  os << " ENCODING " << ti.get_compression_name() << "(" << comp_param << ")";
4094  }
4095  }
4096  }
4097  }
4098  // gather SHARED DICTIONARYs
4099  if (shared_dicts.size()) {
4100  std::string comma;
4101  if (!multiline_formatting) {
4102  comma = ", ";
4103  } else {
4104  comma = ",\n ";
4105  }
4106  os << comma;
4107  os << boost::algorithm::join(shared_dicts, comma);
4108  }
4109  // gather WITH options ...
4110  std::vector<std::string> with_options;
4111  if (dump_defaults || td->maxFragRows != DEFAULT_FRAGMENT_ROWS) {
4112  with_options.push_back("FRAGMENT_SIZE=" + std::to_string(td->maxFragRows));
4113  }
4114  if (dump_defaults || td->maxChunkSize != DEFAULT_MAX_CHUNK_SIZE) {
4115  with_options.push_back("MAX_CHUNK_SIZE=" + std::to_string(td->maxChunkSize));
4116  }
4117  if (dump_defaults || td->fragPageSize != DEFAULT_PAGE_SIZE) {
4118  with_options.push_back("PAGE_SIZE=" + std::to_string(td->fragPageSize));
4119  }
4120  if (dump_defaults || td->maxRows != DEFAULT_MAX_ROWS) {
4121  with_options.push_back("MAX_ROWS=" + std::to_string(td->maxRows));
4122  }
4123  if (dump_defaults || !td->hasDeletedCol) {
4124  with_options.push_back(td->hasDeletedCol ? "VACUUM='DELAYED'" : "VACUUM='IMMEDIATE'");
4125  }
4126  if (!td->partitions.empty()) {
4127  with_options.push_back("PARTITIONS='" + td->partitions + "'");
4128  }
4129  if (td->nShards > 0) {
4130  const auto shard_cd = getMetadataForColumn(td->tableId, td->shardedColumnId);
4131  CHECK(shard_cd);
4132  with_options.push_back("SHARD_COUNT=" + std::to_string(td->nShards));
4133  }
4134  if (td->sortedColumnId > 0) {
4135  const auto sort_cd = getMetadataForColumn(td->tableId, td->sortedColumnId);
4136  CHECK(sort_cd);
4137  with_options.push_back("SORT_COLUMN='" + sort_cd->columnName + "'");
4138  }
4139  os << ")";
4140  if (!with_options.empty()) {
4141  if (!multiline_formatting) {
4142  os << " ";
4143  } else {
4144  os << "\n";
4145  }
4146  os << "WITH (" + boost::algorithm::join(with_options, ", ") + ")";
4147  }
4148  os << ";";
4149  return os.str();
4150 }
std::string partitions
std::string tableName
std::string join(T const &container, std::string const &delim)
#define DEFAULT_MAX_CHUNK_SIZE
read_lock< Catalog > cat_read_lock
Definition: Catalog.cpp:111
void unserialize_key_metainfo(std::vector< std::string > &shared_dicts, std::set< std::string > &shared_dict_column_names, const std::string keyMetainfo)
Definition: Catalog.cpp:3970
bool contains_spaces(std::string_view str)
returns true if the string contains one or more spaces
Definition: Catalog.cpp:4001
std::string to_string(char const *&&v)
bool contains_sql_reserved_chars(std::string_view str, std::string_view chars="`~!@#$%^&*()-=+[{]}\\|;:'\",<.>/?")
returns true if the string contains one or more OmniSci SQL reserved characters
Definition: Catalog.cpp:4008
#define DEFAULT_MAX_ROWS
CHECK(cgen_state)
const ColumnDescriptor * getMetadataForColumn(int tableId, const std::string &colName) const
std::string keyMetainfo
#define DEFAULT_PAGE_SIZE
#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:1704
Data_Namespace::MemoryLevel persistenceLevel
Definition: sqltypes.h:42
mapd_shared_lock< mapd_shared_mutex > read_lock
std::string viewSQL
bool is_reserved_sql_keyword(std::string_view str)
returns true if the string equals an OmniSci SQL reserved keyword
Definition: Catalog.cpp:4015

+ Here is the call graph for this function:

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

Definition at line 3882 of file Catalog.cpp.

References CHECK(), ColumnDescriptor::columnName, ColumnDescriptor::columnType, currentDB_, Catalog_Namespace::DBMetadata::dbId, dictDescriptorMapByRef_, TableDescriptor::fragPageSize, getAllColumnMetadataForTable(), getMetadataForColumn(), TableDescriptor::hasDeletedCol, ColumnDescriptor::isSystemCol, ColumnDescriptor::isVirtualCol, join(), kCHAR, kENCODING_DICT, TableDescriptor::maxChunkSize, TableDescriptor::maxFragRows, TableDescriptor::maxRows, TableDescriptor::nShards, TableDescriptor::partitions, TableDescriptor::shardedColumnId, TableDescriptor::sortedColumnId, TableDescriptor::tableId, and to_string().

Referenced by TableArchiver::dumpTable().

3882  {
3883  cat_read_lock read_lock(this);
3884 
3885  std::ostringstream os;
3886  os << "CREATE TABLE @T (";
3887  // gather column defines
3888  const auto cds = getAllColumnMetadataForTable(td->tableId, false, false, false);
3889  std::string comma;
3890  std::vector<std::string> shared_dicts;
3891  std::map<const std::string, const ColumnDescriptor*> dict_root_cds;
3892  for (const auto cd : cds) {
3893  if (!(cd->isSystemCol || cd->isVirtualCol)) {
3894  const auto& ti = cd->columnType;
3895  os << comma << cd->columnName;
3896  // CHAR is perculiar... better dump it as TEXT(32) like \d does
3897  if (ti.get_type() == SQLTypes::kCHAR) {
3898  os << " "
3899  << "TEXT";
3900  } else if (ti.get_subtype() == SQLTypes::kCHAR) {
3901  os << " "
3902  << "TEXT[]";
3903  } else {
3904  os << " " << ti.get_type_name();
3905  }
3906  os << (ti.get_notnull() ? " NOT NULL" : "");
3907  if (ti.is_string()) {
3908  if (ti.get_compression() == kENCODING_DICT) {
3909  // if foreign reference, get referenced tab.col
3910  const auto dict_id = ti.get_comp_param();
3911  const DictRef dict_ref(currentDB_.dbId, dict_id);
3912  const auto dict_it = dictDescriptorMapByRef_.find(dict_ref);
3913  CHECK(dict_it != dictDescriptorMapByRef_.end());
3914  const auto dict_name = dict_it->second->dictName;
3915  // when migrating a table, any foreign dict ref will be dropped
3916  // and the first cd of a dict will become root of the dict
3917  if (dict_root_cds.end() == dict_root_cds.find(dict_name)) {
3918  dict_root_cds[dict_name] = cd;
3919  os << " ENCODING " << ti.get_compression_name() << "(" << (ti.get_size() * 8)
3920  << ")";
3921  } else {
3922  const auto dict_root_cd = dict_root_cds[dict_name];
3923  shared_dicts.push_back("SHARED DICTIONARY (" + cd->columnName +
3924  ") REFERENCES @T(" + dict_root_cd->columnName + ")");
3925  // "... shouldn't specify an encoding, it borrows from the referenced column"
3926  }
3927  } else {
3928  os << " ENCODING NONE";
3929  }
3930  } else if (ti.is_date_in_days() ||
3931  (ti.get_size() > 0 && ti.get_size() != ti.get_logical_size())) {
3932  const auto comp_param = ti.get_comp_param() ? ti.get_comp_param() : 32;
3933  os << " ENCODING " << ti.get_compression_name() << "(" << comp_param << ")";
3934  }
3935  comma = ", ";
3936  }
3937  }
3938  // gather SHARED DICTIONARYs
3939  if (shared_dicts.size()) {
3940  os << ", " << boost::algorithm::join(shared_dicts, ", ");
3941  }
3942  // gather WITH options ...
3943  std::vector<std::string> with_options;
3944  with_options.push_back("FRAGMENT_SIZE=" + std::to_string(td->maxFragRows));
3945  with_options.push_back("MAX_CHUNK_SIZE=" + std::to_string(td->maxChunkSize));
3946  with_options.push_back("PAGE_SIZE=" + std::to_string(td->fragPageSize));
3947  with_options.push_back("MAX_ROWS=" + std::to_string(td->maxRows));
3948  with_options.emplace_back(td->hasDeletedCol ? "VACUUM='DELAYED'"
3949  : "VACUUM='IMMEDIATE'");
3950  if (!td->partitions.empty()) {
3951  with_options.push_back("PARTITIONS='" + td->partitions + "'");
3952  }
3953  if (td->nShards > 0) {
3954  const auto shard_cd = getMetadataForColumn(td->tableId, td->shardedColumnId);
3955  CHECK(shard_cd);
3956  os << ", SHARD KEY(" << shard_cd->columnName << ")";
3957  with_options.push_back("SHARD_COUNT=" + std::to_string(td->nShards));
3958  }
3959  if (td->sortedColumnId > 0) {
3960  const auto sort_cd = getMetadataForColumn(td->tableId, td->sortedColumnId);
3961  CHECK(sort_cd);
3962  with_options.push_back("SORT_COLUMN='" + sort_cd->columnName + "'");
3963  }
3964  os << ") WITH (" + boost::algorithm::join(with_options, ", ") + ");";
3965  return os.str();
3966 }
std::string partitions
DictDescriptorMapById dictDescriptorMapByRef_
Definition: Catalog.h:464
std::string join(T const &container, std::string const &delim)
read_lock< Catalog > cat_read_lock
Definition: Catalog.cpp:111
std::string to_string(char const *&&v)
CHECK(cgen_state)
const ColumnDescriptor * getMetadataForColumn(int tableId, const std::string &colName) 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...
Definition: Catalog.cpp:1704
Definition: sqltypes.h:42
mapd_shared_lock< mapd_shared_mutex > read_lock

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Catalog_Namespace::Catalog::eraseDBData ( )

Definition at line 3606 of file Catalog.cpp.

References basePath_, calciteMgr_, currentDB_, Catalog_Namespace::DBMetadata::dbName, eraseTablePhysicalData(), getAllTableMetadata(), and run_benchmark_import::tables.

3606  {
3607  cat_write_lock write_lock(this);
3608  // Physically erase all tables and dictionaries from disc and memory
3609  const auto tables = getAllTableMetadata();
3610  for (const auto table : tables) {
3611  eraseTablePhysicalData(table);
3612  }
3613  // Physically erase database metadata
3614  boost::filesystem::remove(basePath_ + "/mapd_catalogs/" + currentDB_.dbName);
3615  calciteMgr_->updateMetadata(currentDB_.dbName, "");
3616 }
void eraseTablePhysicalData(const TableDescriptor *td)
Definition: Catalog.cpp:3618
std::list< const TableDescriptor * > getAllTableMetadata() const
Definition: Catalog.cpp:1730
std::shared_ptr< Calcite > calciteMgr_
Definition: Catalog.h:476
write_lock< Catalog > cat_write_lock
Definition: Catalog.cpp:112
mapd_unique_lock< mapd_shared_mutex > write_lock

+ Here is the call graph for this function:

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

Definition at line 3618 of file Catalog.cpp.

References calciteMgr_, CHECK(), Data_Namespace::CPU_LEVEL, currentDB_, dataMgr_, Catalog_Namespace::DBMetadata::dbId, Catalog_Namespace::DBMetadata::dbName, TableDescriptor::fragmenter, Data_Namespace::GPU_LEVEL, INJECT_TIMER, TableDescriptor::isView, removeTableFromMap(), tableDescriptorMapById_, TableDescriptor::tableId, and TableDescriptor::tableName.

Referenced by doDropTable(), and eraseDBData().

3618  {
3619  const int tableId = td->tableId;
3620  // must destroy fragmenter before deleteChunks is called.
3621  if (td->fragmenter != nullptr) {
3622  auto tableDescIt = tableDescriptorMapById_.find(tableId);
3623  CHECK(tableDescIt != tableDescriptorMapById_.end());
3624  {
3625  INJECT_TIMER(deleting_fragmenter);
3626  tableDescIt->second->fragmenter = nullptr;
3627  }
3628  }
3629  ChunkKey chunkKeyPrefix = {currentDB_.dbId, tableId};
3630  {
3631  INJECT_TIMER(deleteChunksWithPrefix);
3632  // assuming deleteChunksWithPrefix is atomic
3633  dataMgr_->deleteChunksWithPrefix(chunkKeyPrefix, MemoryLevel::CPU_LEVEL);
3634  dataMgr_->deleteChunksWithPrefix(chunkKeyPrefix, MemoryLevel::GPU_LEVEL);
3635  }
3636  if (!td->isView) {
3637  INJECT_TIMER(Remove_Table);
3638  dataMgr_->removeTableRelatedDS(currentDB_.dbId, tableId);
3639  }
3640  calciteMgr_->updateMetadata(currentDB_.dbName, td->tableName);
3641  {
3642  INJECT_TIMER(removeTableFromMap_);
3643  removeTableFromMap(td->tableName, tableId);
3644  }
3645 }
std::vector< int > ChunkKey
Definition: types.h:35
std::string tableName
std::shared_ptr< Data_Namespace::DataMgr > dataMgr_
Definition: Catalog.h:473
CHECK(cgen_state)
#define INJECT_TIMER(DESC)
Definition: measure.h:91
TableDescriptorMapById tableDescriptorMapById_
Definition: Catalog.h:461
std::shared_ptr< Fragmenter_Namespace::AbstractFragmenter > fragmenter
std::shared_ptr< Calcite > calciteMgr_
Definition: Catalog.h:476
void removeTableFromMap(const std::string &tableName, const int tableId, const bool is_on_error=false)
Definition: Catalog.cpp:1197

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 3152 of file Catalog.cpp.

References StorageType::FOREIGN_TABLE, SqliteConnector::getData(), SqliteConnector::getNumRows(), TableDescriptor::isView, kENCODING_DICT, SqliteConnector::query_with_text_param(), SqliteConnector::query_with_text_params(), sqliteConnector_, TableDescriptor::storageType, TableDescriptor::tableId, and to_string().

Referenced by doDropTable(), and dropFsiSchemasAndTables().

3152  {
3153  const int tableId = td->tableId;
3154  sqliteConnector_.query_with_text_param("DELETE FROM mapd_tables WHERE tableid = ?",
3155  std::to_string(tableId));
3157  "select comp_param from mapd_columns where compression = ? and tableid = ?",
3158  std::vector<std::string>{std::to_string(kENCODING_DICT), std::to_string(tableId)});
3159  int numRows = sqliteConnector_.getNumRows();
3160  std::vector<int> dict_id_list;
3161  for (int r = 0; r < numRows; ++r) {
3162  dict_id_list.push_back(sqliteConnector_.getData<int>(r, 0));
3163  }
3164  for (auto dict_id : dict_id_list) {
3166  "UPDATE mapd_dictionaries SET refcount = refcount - 1 WHERE dictid = ?",
3167  std::vector<std::string>{std::to_string(dict_id)});
3168  }
3170  "DELETE FROM mapd_dictionaries WHERE dictid in (select comp_param from "
3171  "mapd_columns where compression = ? "
3172  "and tableid = ?) and refcount = 0",
3173  std::vector<std::string>{std::to_string(kENCODING_DICT), std::to_string(tableId)});
3174  sqliteConnector_.query_with_text_param("DELETE FROM mapd_columns WHERE tableid = ?",
3175  std::to_string(tableId));
3176  if (td->isView) {
3177  sqliteConnector_.query_with_text_param("DELETE FROM mapd_views WHERE tableid = ?",
3178  std::to_string(tableId));
3179  }
3182  "DELETE FROM omnisci_foreign_tables WHERE table_id = ?", std::to_string(tableId));
3183  }
3184 }
T getData(const int row, const int col)
virtual void query_with_text_params(std::string const &query_only)
SqliteConnector sqliteConnector_
Definition: Catalog.h:471
std::string storageType
std::string to_string(char const *&&v)
static constexpr char const * FOREIGN_TABLE
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:

+ Here is the caller graph for this function:

void Catalog_Namespace::Catalog::expandGeoColumn ( const ColumnDescriptor cd,
std::list< ColumnDescriptor > &  columns 
)
static

Definition at line 1988 of file Catalog.cpp.

References CHECK(), ColumnDescriptor::columnName, ColumnDescriptor::columnType, IS_GEO, kARRAY, kDOUBLE, kENCODING_GEOINT, kENCODING_NONE, kINT, kLINESTRING, kMULTIPOLYGON, kPOINT, kPOLYGON, kTINYINT, SQLTypeInfo::set_size(), and SQLTypeInfo::set_subtype().

Referenced by createTable().

1989  {
1990  const auto& col_ti = cd.columnType;
1991  if (IS_GEO(col_ti.get_type())) {
1992  switch (col_ti.get_type()) {
1993  case kPOINT: {
1994  ColumnDescriptor physical_cd_coords(true);
1995  physical_cd_coords.columnName = cd.columnName + "_coords";
1996  SQLTypeInfo coords_ti = SQLTypeInfo(kARRAY, col_ti.get_notnull());
1997  // Raw data: compressed/uncompressed coords
1998  coords_ti.set_subtype(kTINYINT);
1999  size_t unit_size;
2000  if (col_ti.get_compression() == kENCODING_GEOINT &&
2001  col_ti.get_comp_param() == 32) {
2002  unit_size = 4 * sizeof(int8_t);
2003  } else {
2004  CHECK(col_ti.get_compression() == kENCODING_NONE);
2005  unit_size = 8 * sizeof(int8_t);
2006  }
2007  coords_ti.set_size(2 * unit_size);
2008  physical_cd_coords.columnType = coords_ti;
2009  columns.push_back(physical_cd_coords);
2010 
2011  // If adding more physical columns - update SQLTypeInfo::get_physical_cols()
2012 
2013  break;
2014  }
2015  case kLINESTRING: {
2016  ColumnDescriptor physical_cd_coords(true);
2017  physical_cd_coords.columnName = cd.columnName + "_coords";
2018  SQLTypeInfo coords_ti = SQLTypeInfo(kARRAY, col_ti.get_notnull());
2019  // Raw data: compressed/uncompressed coords
2020  coords_ti.set_subtype(kTINYINT);
2021  physical_cd_coords.columnType = coords_ti;
2022  columns.push_back(physical_cd_coords);
2023 
2024  ColumnDescriptor physical_cd_bounds(true);
2025  physical_cd_bounds.columnName = cd.columnName + "_bounds";
2026  SQLTypeInfo bounds_ti = SQLTypeInfo(kARRAY, col_ti.get_notnull());
2027  bounds_ti.set_subtype(kDOUBLE);
2028  bounds_ti.set_size(4 * sizeof(double));
2029  physical_cd_bounds.columnType = bounds_ti;
2030  columns.push_back(physical_cd_bounds);
2031 
2032  // If adding more physical columns - update SQLTypeInfo::get_physical_cols()
2033 
2034  break;
2035  }
2036  case kPOLYGON: {
2037  ColumnDescriptor physical_cd_coords(true);
2038  physical_cd_coords.columnName = cd.columnName + "_coords";
2039  SQLTypeInfo coords_ti = SQLTypeInfo(kARRAY, col_ti.get_notnull());
2040  // Raw data: compressed/uncompressed coords
2041  coords_ti.set_subtype(kTINYINT);
2042  physical_cd_coords.columnType = coords_ti;
2043  columns.push_back(physical_cd_coords);
2044 
2045  ColumnDescriptor physical_cd_ring_sizes(true);
2046  physical_cd_ring_sizes.columnName = cd.columnName + "_ring_sizes";
2047  SQLTypeInfo ring_sizes_ti = SQLTypeInfo(kARRAY, col_ti.get_notnull());
2048  ring_sizes_ti.set_subtype(kINT);
2049  physical_cd_ring_sizes.columnType = ring_sizes_ti;
2050  columns.push_back(physical_cd_ring_sizes);
2051 
2052  ColumnDescriptor physical_cd_bounds(true);
2053  physical_cd_bounds.columnName = cd.columnName + "_bounds";
2054  SQLTypeInfo bounds_ti = SQLTypeInfo(kARRAY, col_ti.get_notnull());
2055  bounds_ti.set_subtype(kDOUBLE);
2056  bounds_ti.set_size(4 * sizeof(double));
2057  physical_cd_bounds.columnType = bounds_ti;
2058  columns.push_back(physical_cd_bounds);
2059 
2060  ColumnDescriptor physical_cd_render_group(true);
2061  physical_cd_render_group.columnName = cd.columnName + "_render_group";
2062  SQLTypeInfo render_group_ti = SQLTypeInfo(kINT, col_ti.get_notnull());
2063  physical_cd_render_group.columnType = render_group_ti;
2064  columns.push_back(physical_cd_render_group);
2065 
2066  // If adding more physical columns - update SQLTypeInfo::get_physical_cols()
2067 
2068  break;
2069  }
2070  case kMULTIPOLYGON: {
2071  ColumnDescriptor physical_cd_coords(true);
2072  physical_cd_coords.columnName = cd.columnName + "_coords";
2073  SQLTypeInfo coords_ti = SQLTypeInfo(kARRAY, col_ti.get_notnull());
2074  // Raw data: compressed/uncompressed coords
2075  coords_ti.set_subtype(kTINYINT);
2076  physical_cd_coords.columnType = coords_ti;
2077  columns.push_back(physical_cd_coords);
2078 
2079  ColumnDescriptor physical_cd_ring_sizes(true);
2080  physical_cd_ring_sizes.columnName = cd.columnName + "_ring_sizes";
2081  SQLTypeInfo ring_sizes_ti = SQLTypeInfo(kARRAY, col_ti.get_notnull());
2082  ring_sizes_ti.set_subtype(kINT);
2083  physical_cd_ring_sizes.columnType = ring_sizes_ti;
2084  columns.push_back(physical_cd_ring_sizes);
2085 
2086  ColumnDescriptor physical_cd_poly_rings(true);
2087  physical_cd_poly_rings.columnName = cd.columnName + "_poly_rings";
2088  SQLTypeInfo poly_rings_ti = SQLTypeInfo(kARRAY, col_ti.get_notnull());
2089  poly_rings_ti.set_subtype(kINT);
2090  physical_cd_poly_rings.columnType = poly_rings_ti;
2091  columns.push_back(physical_cd_poly_rings);
2092 
2093  ColumnDescriptor physical_cd_bounds(true);
2094  physical_cd_bounds.columnName = cd.columnName + "_bounds";
2095  SQLTypeInfo bounds_ti = SQLTypeInfo(kARRAY, col_ti.get_notnull());
2096  bounds_ti.set_subtype(kDOUBLE);
2097  bounds_ti.set_size(4 * sizeof(double));
2098  physical_cd_bounds.columnType = bounds_ti;
2099  columns.push_back(physical_cd_bounds);
2100 
2101  ColumnDescriptor physical_cd_render_group(true);
2102  physical_cd_render_group.columnName = cd.columnName + "_render_group";
2103  SQLTypeInfo render_group_ti = SQLTypeInfo(kINT, col_ti.get_notnull());
2104  physical_cd_render_group.columnType = render_group_ti;
2105  columns.push_back(physical_cd_render_group);
2106 
2107  // If adding more physical columns - update SQLTypeInfo::get_physical_cols()
2108 
2109  break;
2110  }
2111  default:
2112  throw runtime_error("Unrecognized geometry type.");
2113  break;
2114  }
2115  }
2116 }
void set_size(int s)
Definition: sqltypes.h:356
HOST DEVICE void set_subtype(SQLTypes st)
Definition: sqltypes.h:349
CHECK(cgen_state)
specifies the content in-memory of a row in the column metadata table
Definition: sqltypes.h:46
SQLTypeInfo columnType
std::string columnName
#define IS_GEO(T)
Definition: sqltypes.h:173

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string Catalog_Namespace::Catalog::generatePhysicalTableName ( const std::string &  logicalTableName,
const int32_t &  shardNumber 
)
protected

Definition at line 3647 of file Catalog.cpp.

References physicalTableNameTag_, and to_string().

Referenced by createShardedTable(), and renameTable().

3648  {
3649  std::string physicalTableName =
3650  logicalTableName + physicalTableNameTag_ + std::to_string(shardNumber);
3651  return (physicalTableName);
3652 }
std::string to_string(char const *&&v)
static const std::string physicalTableNameTag_
Definition: Catalog.h:480

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::shared_ptr< Catalog > Catalog_Namespace::Catalog::get ( const std::string &  dbName)
static

Definition at line 3658 of file Catalog.cpp.

References mapd_cat_map_.

Referenced by foreign_storage::ForeignStorageMgr::createDataWrapperIfNotExists(), EmbeddedDatabase::DBEngineImpl::DBEngineImpl(), foreign_storage::ParquetDataWrapper::fetchChunkMetadata(), foreign_storage::CsvDataWrapper::getChunkBuffer(), foreign_storage::ParquetDataWrapper::getColumnsToInitialize(), PersistentStorageMgr::isForeignStorage(), foreign_storage::ParquetDataWrapper::loadBufferIntoMap(), main(), foreign_storage::CsvDataWrapper::populateChunk(), and foreign_storage::CsvDataWrapper::populateMetadataForChunkKeyPrefix().

3658  {
3659  auto cat_it = mapd_cat_map_.find(dbName);
3660  if (cat_it != mapd_cat_map_.end()) {
3661  return cat_it->second;
3662  }
3663  return nullptr;
3664 }
static std::map< std::string, std::shared_ptr< Catalog > > mapd_cat_map_
Definition: Catalog.h:493

+ Here is the caller graph for this function:

std::shared_ptr< Catalog > Catalog_Namespace::Catalog::get ( const int32_t  db_id)
static

Definition at line 3666 of file Catalog.cpp.

References mapd_cat_map_.

3666  {
3667  for (const auto& entry : mapd_cat_map_) {
3668  if (entry.second->currentDB_.dbId == db_id) {
3669  return entry.second;
3670  }
3671  }
3672  return nullptr;
3673 }
static std::map< std::string, std::shared_ptr< Catalog > > mapd_cat_map_
Definition: Catalog.h:493
static std::shared_ptr<Catalog> Catalog_Namespace::Catalog::get ( 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 
)
static
std::list< const ColumnDescriptor * > Catalog_Namespace::Catalog::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.

Parameters
tableIdtable id we want the column metadata for
Returns
list of pointers to const ColumnDescriptor structs - one for each and every column in the table

Definition at line 1704 of file Catalog.cpp.

References getAllColumnMetadataForTableUnlocked().

Referenced by Analyzer::RangeTableEntry::add_all_column_descs(), Parser::InsertStmt::analyze(), Parser::InsertValuesStmt::analyze(), Fragmenter_Namespace::copyDataOfShard(), Parser::InsertValuesStmt::determineLeafIndex(), dumpCreateTable(), dumpSchema(), TableArchiver::dumpTable(), Analyzer::RangeTableEntry::expand_star_in_targetlist(), getDictionaryToColumnMapping(), getShardColumnMetadataForTable(), getTableDictDirectories(), TableOptimizer::recomputeMetadata(), TableArchiver::restoreTable(), and validate_shared_dictionary().

1708  {
1709  cat_read_lock read_lock(this);
1711  tableId, fetchSystemColumns, fetchVirtualColumns, fetchPhysicalColumns);
1712 }
std::list< const ColumnDescriptor * > getAllColumnMetadataForTableUnlocked(const int tableId, const bool fetchSystemColumns, const bool fetchVirtualColumns, const bool fetchPhysicalColumns) const
Definition: Catalog.cpp:1714
read_lock< Catalog > cat_read_lock
Definition: Catalog.cpp:111
mapd_shared_lock< mapd_shared_mutex > read_lock

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Catalog_Namespace::Catalog::getAllColumnMetadataForTableImpl ( const TableDescriptor td,
std::list< const ColumnDescriptor * > &  colDescs,
const bool  fetchSystemColumns,
const bool  fetchVirtualColumns,
const bool  fetchPhysicalColumns 
) const
protected

Definition at line 1674 of file Catalog.cpp.

References columnDescriptorMapById_, and TableDescriptor::tableId.

Referenced by getAllColumnMetadataForTableUnlocked(), and instantiateFragmenter().

1679  {
1680  int32_t skip_physical_cols = 0;
1681  for (const auto& columnDescriptor : columnDescriptorMapById_) {
1682  if (!fetchPhysicalColumns && skip_physical_cols > 0) {
1683  --skip_physical_cols;
1684  continue;
1685  }
1686  auto cd = columnDescriptor.second;
1687  if (cd->tableId != td->tableId) {
1688  continue;
1689  }
1690  if (!fetchSystemColumns && cd->isSystemCol) {
1691  continue;
1692  }
1693  if (!fetchVirtualColumns && cd->isVirtualCol) {
1694  continue;
1695  }
1696  if (!fetchPhysicalColumns) {
1697  const auto& col_ti = cd->columnType;
1698  skip_physical_cols = col_ti.get_physical_cols();
1699  }
1700  columnDescriptors.push_back(cd);
1701  }
1702 }
ColumnDescriptorMapById columnDescriptorMapById_
Definition: Catalog.h:463

+ Here is the caller graph for this function:

std::list< const ColumnDescriptor * > Catalog_Namespace::Catalog::getAllColumnMetadataForTableUnlocked ( const int  tableId,
const bool  fetchSystemColumns,
const bool  fetchVirtualColumns,
const bool  fetchPhysicalColumns 
) const

Same as above, but without first taking a catalog read lock.

Definition at line 1714 of file Catalog.cpp.

References getAllColumnMetadataForTableImpl(), and getMetadataForTableImpl().

Referenced by getAllColumnMetadataForTable(), and foreign_storage::ForeignTableColumnMap::mapColumns().

1718  {
1719  std::list<const ColumnDescriptor*> columnDescriptors;
1720  const TableDescriptor* td =
1721  getMetadataForTableImpl(tableId, false); // dont instantiate fragmenter
1723  columnDescriptors,
1724  fetchSystemColumns,
1725  fetchVirtualColumns,
1726  fetchPhysicalColumns);
1727  return columnDescriptors;
1728 }
void getAllColumnMetadataForTableImpl(const TableDescriptor *td, std::list< const ColumnDescriptor * > &colDescs, const bool fetchSystemColumns, const bool fetchVirtualColumns, const bool fetchPhysicalColumns) const
Definition: Catalog.cpp:1674
const TableDescriptor * getMetadataForTableImpl(int tableId, const bool populateFragmenter) const
Definition: Catalog.cpp:1426
specifies the content in-memory of a row in the table metadata table

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

list< const DashboardDescriptor * > Catalog_Namespace::Catalog::getAllDashboardsMetadata ( ) const

Definition at line 1739 of file Catalog.cpp.

References dashboardDescriptorMap_.

1739  {
1740  list<const DashboardDescriptor*> view_list;
1741  for (auto p : dashboardDescriptorMap_) {
1742  view_list.push_back(p.second.get());
1743  }
1744  return view_list;
1745 }
DashboardDescriptorMap dashboardDescriptorMap_
Definition: Catalog.h:465
list< const TableDescriptor * > Catalog_Namespace::Catalog::getAllTableMetadata ( ) const

Definition at line 1730 of file Catalog.cpp.

References tableDescriptorMapById_.

Referenced by eraseDBData(), getDictionaryToColumnMapping(), and getTableNamesForUser().

1730  {
1731  cat_read_lock read_lock(this);
1732  list<const TableDescriptor*> table_list;
1733  for (auto p : tableDescriptorMapById_) {
1734  table_list.push_back(p.second);
1735  }
1736  return table_list;
1737 }
read_lock< Catalog > cat_read_lock
Definition: Catalog.cpp:111
TableDescriptorMapById tableDescriptorMapById_
Definition: Catalog.h:461
mapd_shared_lock< mapd_shared_mutex > read_lock

+ Here is the caller graph for this function:

const std::string& Catalog_Namespace::Catalog::getBasePath ( ) const
inline

Definition at line 197 of file Catalog.h.

References basePath_.

197 { return basePath_; }
std::shared_ptr<Calcite> Catalog_Namespace::Catalog::getCalciteMgr ( ) const
inline

Definition at line 196 of file Catalog.h.

References calciteMgr_.

196 { return calciteMgr_; }
std::shared_ptr< Calcite > calciteMgr_
Definition: Catalog.h:476
std::string Catalog_Namespace::Catalog::getColumnDictDirectory ( const ColumnDescriptor cd) const

Definition at line 3850 of file Catalog.cpp.

References CHECK(), ColumnDescriptor::columnType, currentDB_, Catalog_Namespace::DBMetadata::dbId, dictDescriptorMapByRef_, SQLTypeInfo::get_comp_param(), SQLTypeInfo::get_compression(), SQLTypeInfo::is_string(), SQLTypeInfo::is_string_array(), and kENCODING_DICT.

Referenced by TableArchiver::dumpTable(), getTableDictDirectories(), and TableArchiver::restoreTable().

3850  {
3851  if ((cd->columnType.is_string() || cd->columnType.is_string_array()) &&
3853  cd->columnType.get_comp_param() > 0) {
3854  const auto dictId = cd->columnType.get_comp_param();
3855  const DictRef dictRef(currentDB_.dbId, dictId);
3856  const auto dit = dictDescriptorMapByRef_.find(dictRef);
3857  CHECK(dit != dictDescriptorMapByRef_.end());
3858  CHECK(dit->second);
3859  boost::filesystem::path file_path(dit->second->dictFolderPath);
3860  return file_path.filename().string();
3861  }
3862  return std::string();
3863 }
DictDescriptorMapById dictDescriptorMapByRef_
Definition: Catalog.h:464
CHECK(cgen_state)
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:266
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:267
SQLTypeInfo columnType
bool is_string() const
Definition: sqltypes.h:415
bool is_string_array() const
Definition: sqltypes.h:416

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const int Catalog_Namespace::Catalog::getColumnIdBySpi ( const int  tableId,
const size_t  spi 
) const

Definition at line 1540 of file Catalog.cpp.

References getColumnIdBySpiUnlocked().

Referenced by anonymous_namespace{RelAlgExecutor.cpp}::collect_used_input_desc(), and anonymous_namespace{RelAlgExecutor.cpp}::get_physical_inputs().

1540  {
1541  cat_read_lock read_lock(this);
1542  return getColumnIdBySpiUnlocked(table_id, spi);
1543 }
read_lock< Catalog > cat_read_lock
Definition: Catalog.cpp:111
const int getColumnIdBySpiUnlocked(const int table_id, const size_t spi) const
Definition: Catalog.cpp:1523
mapd_shared_lock< mapd_shared_mutex > read_lock

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const int Catalog_Namespace::Catalog::getColumnIdBySpiUnlocked ( const int  table_id,
const size_t  spi 
) const
protected

Definition at line 1523 of file Catalog.cpp.

References CHECK(), SPIMAP_MAGIC1, SPIMAP_MAGIC2, and tableDescriptorMapById_.

Referenced by getColumnIdBySpi(), and getMetadataForColumnBySpi().

1523  {
1524  const auto tabDescIt = tableDescriptorMapById_.find(table_id);
1525  CHECK(tableDescriptorMapById_.end() != tabDescIt);
1526  const auto& columnIdBySpi = tabDescIt->second->columnIdBySpi_;
1527 
1528  auto spx = spi;
1529  int phi = 0;
1530  if (spx >= SPIMAP_MAGIC1) // see Catalog.h
1531  {
1532  phi = (spx - SPIMAP_MAGIC1) % SPIMAP_MAGIC2;
1533  spx = (spx - SPIMAP_MAGIC1) / SPIMAP_MAGIC2;
1534  }
1535 
1536  CHECK(0 < spx && spx <= columnIdBySpi.size());
1537  return columnIdBySpi[spx - 1] + phi;
1538 }
#define SPIMAP_MAGIC1
Definition: Catalog.h:73
#define SPIMAP_MAGIC2
Definition: Catalog.h:74
CHECK(cgen_state)
TableDescriptorMapById tableDescriptorMapById_
Definition: Catalog.h:461

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int Catalog_Namespace::Catalog::getDatabaseId ( ) const
inline

Definition at line 223 of file Catalog.h.

References currentDB_, and Catalog_Namespace::DBMetadata::dbId.

Referenced by RelAlgTranslator::getInIntegerSetExpr().

223 { return currentDB_.dbId; }

+ Here is the caller graph for this function:

Data_Namespace::DataMgr& Catalog_Namespace::Catalog::getDataMgr ( ) const
inline