void PlanSimSubpanel::onSimulationFinished() { bool oldBlockTree = right->ui->treeSimViews->blockSignals(true); right->ui->treeSimViews->clear(); onTimeout(); timer.stop(); if (sim_process and not sim_process->error_simu.isEmpty()) { mLog->logExt(sim_process->error_simu, true); } else if (sim_process and sim_process->output_map) { const vle::value::Map& simu = *sim_process->output_map; QList<QTreeWidgetItem*> views_items; vle::value::Map::const_iterator itb = simu.begin(); vle::value::Map::const_iterator ite = simu.end(); for (; itb != ite; itb++) { QString viewName(itb->first.c_str()); QStringList viewType = mvpz->getViewTypeFromDoc(viewName); if (viewType.contains("finish")) { QTreeWidgetItem* vItem = new QTreeWidgetItem(); vItem->setText( 0, QString("%1 (%2)").arg(viewName).arg("finish")); vItem->setData(0, Qt::UserRole + 0, "view"); vItem->setData(0, Qt::UserRole + 1, viewName); const vle::value::Matrix& res = itb->second->toMatrix(); for (unsigned int i = 0; i < res.columns(); i++) { if (res.get(i, 0) and res.get(i, 0)->isString()) { QString portName = res.getString(i, 0).c_str(); if (portName.contains("AchievedPlan")) { QTreeWidgetItem* pItem = new QTreeWidgetItem(); pItem->setText(0, portName); pItem->setFlags(vItem->flags() | Qt::ItemIsUserCheckable); pItem->setCheckState(0, Qt::Unchecked); pItem->setData(0, Qt::UserRole + 0, "port"); pItem->setData(0, Qt::UserRole + 1, viewName); pItem->setData(0, Qt::UserRole + 2, portName); vItem->addChild(pItem); } } } views_items.append(vItem); } } right->ui->treeSimViews->addTopLevelItems(views_items); } updateCustomPlot(); right->ui->treeSimViews->blockSignals(oldBlockTree); thread->quit(); thread->wait(); delete thread; thread = 0; left->ui->runButton->setEnabled(true); }
ViewCatalog::ViewCatalog(OperationContext* txn, DurableViewCatalog* durable) : _durable(durable) { durable->iterate(txn, [&](const BSONObj& view) { NamespaceString viewName(view["_id"].str()); ViewDefinition def( viewName.db(), viewName.coll(), view["viewOn"].str(), view["pipeline"].Obj()); _viewMap[viewName.ns()] = std::make_shared<ViewDefinition>(def); }); }
Status ViewCatalog::_reloadIfNeeded(WithLock lk, OperationContext* opCtx) { if (_valid.load()) return Status::OK(); LOG(1) << "reloading view catalog for database " << _durable->getName(); // Need to reload, first clear our cache. _viewMap.clear(); Status status = _durable->iterate(opCtx, [&](const BSONObj& view) -> Status { BSONObj collationSpec = view.hasField("collation") ? view["collation"].Obj() : BSONObj(); auto collator = parseCollator(opCtx, collationSpec); if (!collator.isOK()) { return collator.getStatus(); } NamespaceString viewName(view["_id"].str()); auto pipeline = view["pipeline"].Obj(); for (auto&& stage : pipeline) { if (BSONType::Object != stage.type()) { return Status(ErrorCodes::InvalidViewDefinition, str::stream() << "View 'pipeline' entries must be objects, but " << viewName.toString() << " has a pipeline element of type " << stage.type()); } } _viewMap[viewName.ns()] = std::make_shared<ViewDefinition>(viewName.db(), viewName.coll(), view["viewOn"].str(), pipeline, std::move(collator.getValue())); return Status::OK(); }); _valid.store(status.isOK()); if (!status.isOK()) { LOG(0) << "could not load view catalog for database " << _durable->getName() << ": " << status; } return status; }
Status ViewCatalog::_reloadIfNeeded_inlock(OperationContext* txn) { if (_valid.load()) return Status::OK(); LOG(1) << "reloading view catalog for database " << _durable->getName(); // Need to reload, first clear our cache. _viewMap.clear(); Status status = _durable->iterate(txn, [&](const BSONObj& view) { NamespaceString viewName(view["_id"].str()); ViewDefinition def( viewName.db(), viewName.coll(), view["viewOn"].str(), view["pipeline"].Obj()); _viewMap[viewName.ns()] = std::make_shared<ViewDefinition>(def); }); _valid.store(status.isOK()); return status; }
TEST_F(ViewCatalogFixture, DropMissingView) { NamespaceString viewName("db.view"); ASSERT_NOT_OK(viewCatalog.dropView(opCtx.get(), viewName)); }
void VirtualTable::addColumn(const SRCP& column, const string& view) { // As of bug3695, make sure varbinary is not used in subquery. if (column->resultType().colDataType == CalpontSystemCatalog::VARBINARY && !fVarBinOK) throw runtime_error ("VARBINARY in subquery is not supported."); AggregateColumn* agc = NULL; ArithmeticColumn* arc = NULL; ConstantColumn* cc = NULL; FunctionColumn* fc = NULL; SimpleColumn* sc = NULL; WindowFunctionColumn* wc = NULL; string columnName; string viewName(view); ostringstream oss; UniqId colId; if ((sc = dynamic_cast<SimpleColumn*>(column.get())) != NULL) { columnName = sc->columnName(); colId = UniqId(sc); } else if ((agc = dynamic_cast<AggregateColumn*>(column.get())) != NULL) { // oss << agc->functionName() << "_" << agc->expressionId(); // oss << "Aggregate_" << agc->expressionId(); columnName = agc->data(); colId = UniqId(agc->expressionId(), "", "", ""); } else if ((wc = dynamic_cast<WindowFunctionColumn*>(column.get())) != NULL) { // oss << wc->functionName() << "_" << wc->expressionId(); // oss << "Window_" << wc->expressionId(); columnName = wc->data(); colId = UniqId(wc->expressionId(), "", "", ""); } else if ((arc = dynamic_cast<ArithmeticColumn*>(column.get())) != NULL) { // oss << "Arithmetic_" << arc->expressionId(); columnName = arc->data(); colId = UniqId(arc->expressionId(), "", "", ""); } else if ((fc = dynamic_cast<FunctionColumn*>(column.get())) != NULL) { // oss << fc->functionName() << "_" << fc->expressionId(); columnName = fc->data(); colId = UniqId(fc->expressionId(), "", "", ""); } else if ((cc = dynamic_cast<ConstantColumn*>(column.get())) != NULL) { // oss << "Constant_" << cc->expressionId(); columnName = cc->data(); colId = UniqId(cc->expressionId(), cc->alias(), "", viewName); } else // new column type has added, but this code is not updated. { oss << "not supported column type: " << typeid(*(column.get())).name(); throw runtime_error(oss.str()); } if (columnName.empty()) columnName = column->alias(); SimpleColumn* vc = new SimpleColumn(); vc->tableName(fName); vc->tableAlias(fAlias); vc->columnName(columnName); vc->alias(column->alias()); vc->viewName(viewName); uint index = fColumns.size(); vc->colPosition(index); vc->oid(fTableOid+index+1); vc->resultType(column->resultType()); SSC ssc(vc); fColumns.push_back(ssc); fColumnTypes.push_back(column->resultType()); fColumnMap.insert(make_pair(colId, index)); }
void CmpSeabaseDDL::dropSeabaseView( StmtDDLDropView * dropViewNode, NAString &currCatName, NAString &currSchName) { Lng32 cliRC = 0; Lng32 retcode = 0; const NAString &tabName = dropViewNode->getViewName(); ComObjectName viewName(tabName); ComAnsiNamePart currCatAnsiName(currCatName); ComAnsiNamePart currSchAnsiName(currSchName); viewName.applyDefaults(currCatAnsiName, currSchAnsiName); const NAString catalogNamePart = viewName.getCatalogNamePartAsAnsiString(); const NAString schemaNamePart = viewName.getSchemaNamePartAsAnsiString(TRUE); const NAString objectNamePart = viewName.getObjectNamePartAsAnsiString(TRUE); const NAString extViewName = viewName.getExternalName(TRUE); ExeCliInterface cliInterface(STMTHEAP, NULL, NULL, CmpCommon::context()->sqlSession()->getParentQid()); ExpHbaseInterface * ehi = allocEHI(); if (ehi == NULL) return; if ((isSeabaseReservedSchema(viewName)) && (!Get_SqlParser_Flags(INTERNAL_QUERY_FROM_EXEUTIL))) { *CmpCommon::diags() << DgSqlCode(-1119) << DgTableName(extViewName); deallocEHI(ehi); processReturn(); return; } retcode = existsInSeabaseMDTable(&cliInterface, catalogNamePart, schemaNamePart, objectNamePart, COM_VIEW_OBJECT, TRUE, FALSE); if (retcode < 0) { deallocEHI(ehi); processReturn(); return; } if (retcode == 0) // does not exist { *CmpCommon::diags() << DgSqlCode(-1389) << DgString0(extViewName); deallocEHI(ehi); processReturn(); return; } Int32 objectOwnerID = 0; Int32 schemaOwnerID = 0; Int64 objUID = getObjectUIDandOwners(&cliInterface, catalogNamePart.data(), schemaNamePart.data(), objectNamePart.data(), COM_VIEW_OBJECT, objectOwnerID,schemaOwnerID); if (objUID < 0 || objectOwnerID == 0) { if (CmpCommon::diags()->getNumber(DgSqlCode::ERROR_) == 0) SEABASEDDL_INTERNAL_ERROR("getting object UID and owner for drop view"); deallocEHI(ehi); processReturn(); return; } // Verify user can perform operation if (!isDDLOperationAuthorized(SQLOperation::DROP_VIEW,objectOwnerID,schemaOwnerID)) { *CmpCommon::diags() << DgSqlCode(-CAT_NOT_AUTHORIZED); deallocEHI(ehi); processReturn (); return; } Queue * usingViewsQueue = NULL; if (dropViewNode->getDropBehavior() == COM_RESTRICT_DROP_BEHAVIOR) { NAString usingObjName; cliRC = getUsingObject(&cliInterface, objUID, usingObjName); if (cliRC < 0) { deallocEHI(ehi); processReturn(); return; } if (cliRC != 100) // found an object { *CmpCommon::diags() << DgSqlCode(-1047) << DgTableName(usingObjName); deallocEHI(ehi); processReturn(); return; } } else if (dropViewNode->getDropBehavior() == COM_CASCADE_DROP_BEHAVIOR) { cliRC = getUsingViews(&cliInterface, objUID, usingViewsQueue); if (cliRC < 0) { deallocEHI(ehi); processReturn(); return; } } // get the list of all tables referenced by the view. Save this list so // referenced tables can be removed from cache later NAList<objectRefdByMe> tablesRefdList; short status = getListOfReferencedTables(&cliInterface, objUID, tablesRefdList); if (usingViewsQueue) { usingViewsQueue->position(); for (int idx = 0; idx < usingViewsQueue->numEntries(); idx++) { OutputInfo * vi = (OutputInfo*)usingViewsQueue->getNext(); char * viewName = vi->get(0); if (dropSeabaseObject(ehi, viewName, currCatName, currSchName, COM_VIEW_OBJECT)) { deallocEHI(ehi); processReturn(); return; } } } if (dropSeabaseObject(ehi, tabName, currCatName, currSchName, COM_VIEW_OBJECT)) { deallocEHI(ehi); processReturn(); return; } // clear view definition from my cache only. CorrName cn(objectNamePart, STMTHEAP, schemaNamePart, catalogNamePart); ActiveSchemaDB()->getNATableDB()->removeNATable(cn, NATableDB::REMOVE_MINE_ONLY, COM_VIEW_OBJECT); // clear view from all other caches here. This compensates for a // scenario where the object UID is not available in removeNATable, // and the look up failed too. Solution is just to use the objectUID // here. SQL_QIKEY qiKey; qiKey.operation[0] = 'O'; qiKey.operation[1] = 'R'; qiKey.ddlObjectUID = objUID; SQL_EXEC_SetSecInvalidKeys(1, &qiKey); // Now remove referenced tables from cache. // When a query that references a view is compiled, all views are converted // to the underlying base tables. Query plans are generated to access the // tables, and the views are no longer relevant. // When dropping a view, query plans that reference the dropped view will // continue to work if the plans are cached. This code removes the // referenced tables from caches to force recompilations so dropped views // are noticed. for (CollIndex i = 0; i < tablesRefdList.entries(); i++) { CorrName cn(tablesRefdList[i].objectName, STMTHEAP, tablesRefdList[i].schemaName, tablesRefdList[i].catalogName); ActiveSchemaDB()->getNATableDB()->removeNATable(cn, NATableDB::REMOVE_FROM_ALL_USERS, COM_BASE_TABLE_OBJECT); } deallocEHI(ehi); processReturn(); return; }
void CmpSeabaseDDL::createSeabaseView( StmtDDLCreateView * createViewNode, NAString &currCatName, NAString &currSchName) { Lng32 retcode = 0; Lng32 cliRC = 0; ComObjectName viewName(createViewNode->getViewName()); ComAnsiNamePart currCatAnsiName(currCatName); ComAnsiNamePart currSchAnsiName(currSchName); viewName.applyDefaults(currCatAnsiName, currSchAnsiName); const NAString catalogNamePart = viewName.getCatalogNamePartAsAnsiString(); const NAString schemaNamePart = viewName.getSchemaNamePartAsAnsiString(TRUE); const NAString objectNamePart = viewName.getObjectNamePartAsAnsiString(TRUE); const NAString extViewName = viewName.getExternalName(TRUE); const NAString extNameForHbase = catalogNamePart + "." + schemaNamePart + "." + objectNamePart; ExeCliInterface cliInterface(STMTHEAP, NULL, NULL, CmpCommon::context()->sqlSession()->getParentQid()); Int32 objectOwnerID = SUPER_USER; Int32 schemaOwnerID = SUPER_USER; ComSchemaClass schemaClass; retcode = verifyDDLCreateOperationAuthorized(&cliInterface, SQLOperation::CREATE_VIEW, catalogNamePart, schemaNamePart, schemaClass, objectOwnerID, schemaOwnerID); if (retcode != 0) { handleDDLCreateAuthorizationError(retcode,catalogNamePart,schemaNamePart); return; } ExpHbaseInterface * ehi = NULL; ehi = allocEHI(); if (ehi == NULL) { processReturn(); return; } if ((isSeabaseReservedSchema(viewName)) && (!Get_SqlParser_Flags(INTERNAL_QUERY_FROM_EXEUTIL))) { *CmpCommon::diags() << DgSqlCode(-1118) << DgTableName(extViewName); deallocEHI(ehi); return; } //if metadata views are being created and seabase is uninitialized, then this //indicates that these views are being created during 'initialize trafodion' //and this compiler contains stale version. //Reload version info. // if ((isSeabaseMD(viewName)) && (CmpCommon::context()->isUninitializedSeabase())) { CmpCommon::context()->setIsUninitializedSeabase(FALSE); CmpCommon::context()->uninitializedSeabaseErrNum() = 0; } retcode = existsInSeabaseMDTable(&cliInterface, catalogNamePart, schemaNamePart, objectNamePart, COM_UNKNOWN_OBJECT, FALSE, FALSE); if (retcode < 0) { deallocEHI(ehi); processReturn(); return; } if (retcode == 1) // already exists { if (NOT ((createViewNode->isCreateOrReplaceViewCascade())|| (createViewNode->isCreateOrReplaceView()))) { *CmpCommon::diags() << DgSqlCode(-1390) << DgString0(extViewName); deallocEHI(ehi); processReturn(); return; } } char * query = NULL; int64_t objectUID = -1; std::vector<ObjectPrivsRow> viewPrivsRows; bool replacingView = false; if ((retcode == 1) && // exists ((createViewNode->isCreateOrReplaceViewCascade())|| (createViewNode->isCreateOrReplaceView()))) { // Replace view. Drop this view and recreate it. Int32 objectOwnerID = 0; Int32 schemaOwnerID = 0; Int64 objUID = getObjectUIDandOwners(&cliInterface, catalogNamePart.data(), schemaNamePart.data(), objectNamePart.data(), COM_VIEW_OBJECT, objectOwnerID,schemaOwnerID); if (objUID < 0 || objectOwnerID == 0) { if (CmpCommon::diags()->getNumber(DgSqlCode::ERROR_) == 0) SEABASEDDL_INTERNAL_ERROR("getting object UID and owner for create or replace view"); deallocEHI(ehi); processReturn(); return; } if (isAuthorizationEnabled()) { // Verify user can perform operation if (!isDDLOperationAuthorized(SQLOperation::ALTER_VIEW,objectOwnerID,schemaOwnerID)) { *CmpCommon::diags() << DgSqlCode(-CAT_NOT_AUTHORIZED); deallocEHI(ehi); processReturn (); return; } // Initiate the privilege manager interface class NAString privMgrMDLoc; CONCAT_CATSCH(privMgrMDLoc,getSystemCatalog(),SEABASE_PRIVMGR_SCHEMA); PrivMgrCommands privInterface(std::string(privMgrMDLoc.data()), CmpCommon::diags()); PrivStatus privStatus = privInterface.getPrivRowsForObject(objUID,viewPrivsRows); if (privStatus != PrivStatus::STATUS_GOOD) { SEABASEDDL_INTERNAL_ERROR("Unable to retrieve privileges for replaced view"); deallocEHI(ehi); processReturn(); return; } } if (dropOneTableorView(cliInterface,extViewName.data(),COM_VIEW_OBJECT,false)) { deallocEHI(ehi); processReturn(); return; } replacingView = true; } // Gather the object and grantable privileges that the view creator has. // This code also verifies that the current user has the necessary // privileges to create the view. PrivMgrBitmap privilegesBitmap; PrivMgrBitmap grantableBitmap; privilegesBitmap.set(); grantableBitmap.set(); if (gatherViewPrivileges(createViewNode, &cliInterface, privilegesBitmap, grantableBitmap)) { processReturn(); deallocEHI(ehi); return; } NAString viewText(STMTHEAP); buildViewText(createViewNode, viewText); NAString newViewText(STMTHEAP); for (Lng32 i = 0; i < viewText.length(); i++) { if (viewText.data()[i] == '\'') newViewText += "''"; else newViewText += viewText.data()[i]; } ElemDDLColDefArray colDefArray(STMTHEAP); if (buildViewColInfo(createViewNode, &colDefArray)) { deallocEHI(ehi); processReturn(); return; } Lng32 numCols = colDefArray.entries(); ComTdbVirtTableColumnInfo * colInfoArray = new(STMTHEAP) ComTdbVirtTableColumnInfo[numCols]; if (buildColInfoArray(COM_VIEW_OBJECT, &colDefArray, colInfoArray, FALSE, 0, FALSE)) { deallocEHI(ehi); processReturn(); return; } Int64 objUID = -1; if (updateSeabaseMDTable(&cliInterface, catalogNamePart, schemaNamePart, objectNamePart, COM_VIEW_OBJECT, "N", NULL, numCols, colInfoArray, 0, NULL, 0, NULL, objectOwnerID, schemaOwnerID, objUID)) { deallocEHI(ehi); processReturn(); return; } if (objUID < 0) { deallocEHI(ehi); processReturn(); return; } // grant privileges for view if (isAuthorizationEnabled()) { char authName[MAX_AUTHNAME_LEN+1]; Int32 lActualLen = 0; Int16 status = ComUser::getAuthNameFromAuthID( (Int32) objectOwnerID , (char *)&authName , MAX_AUTHNAME_LEN , lActualLen ); if (status != FEOK) { *CmpCommon::diags() << DgSqlCode(-20235) << DgInt0(status) << DgInt1(objectOwnerID); deallocEHI(ehi); processReturn(); return; } // Initiate the privilege manager interface class NAString privMgrMDLoc; CONCAT_CATSCH(privMgrMDLoc, getSystemCatalog(), SEABASE_PRIVMGR_SCHEMA); PrivMgrCommands privInterface(std::string(privMgrMDLoc.data()), CmpCommon::diags()); retcode = privInterface.grantObjectPrivilege (objUID, std::string(extViewName.data()), COM_VIEW_OBJECT, objectOwnerID, std::string(authName), privilegesBitmap, grantableBitmap); if (retcode != STATUS_GOOD && retcode != STATUS_WARNING) { deallocEHI(ehi); processReturn(); return; } if (replacingView) { PrivStatus privStatus = privInterface.insertPrivRowsForObject(objUID,viewPrivsRows); if (privStatus != PrivStatus::STATUS_GOOD) { SEABASEDDL_INTERNAL_ERROR("Unable to restore privileges for replaced view"); deallocEHI(ehi); processReturn(); return; } } } query = new(STMTHEAP) char[newViewText.length() + 1000]; str_sprintf(query, "upsert into %s.\"%s\".%s values (%Ld, '%s', %d, %d, 0)", getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_VIEWS, objUID, computeCheckOption(createViewNode), (createViewNode->getIsUpdatable() ? 1 : 0), (createViewNode->getIsInsertable() ? 1 : 0)); cliRC = cliInterface.executeImmediate(query); NADELETEBASIC(query, STMTHEAP); if (cliRC < 0) { if (cliRC == -8402) // string overflow, view text does not fit into metadata table *CmpCommon::diags() << DgSqlCode(-1198); else cliInterface.retrieveSQLDiagnostics(CmpCommon::diags()); deallocEHI(ehi); processReturn(); return; } if (updateTextTable(&cliInterface, objUID, COM_VIEW_TEXT, 0, newViewText)) { deallocEHI(ehi); processReturn(); return; } if (updateViewUsage(createViewNode, objUID, &cliInterface)) { deallocEHI(ehi); processReturn(); return; } if (updateObjectValidDef(&cliInterface, catalogNamePart, schemaNamePart, objectNamePart, COM_VIEW_OBJECT_LIT, "Y")) { deallocEHI(ehi); processReturn(); return; } CorrName cn(objectNamePart, STMTHEAP, schemaNamePart, catalogNamePart); ActiveSchemaDB()->getNATableDB()->removeNATable(cn, NATableDB::REMOVE_MINE_ONLY, COM_VIEW_OBJECT); deallocEHI(ehi); processReturn(); return; }