// ---------------------------------------------------------------------------- // method: getAuthDetails // // Creates the CmpSeabaseDDLauth class containing auth details for the // requested authName // // Input: // authName - the database auth name to retrieve details for // isExternal - // true - the auth name is the external name (auth_ext_name) // false - the auth name is the database name (auth_db_name) // // Output: // A returned parameter: // 0 - authorization details are available // < 0 - an error was returned trying to get details // 100 - authorization details were not found // > 0 - (not 100) warning was returned // ---------------------------------------------------------------------------- Int32 CmpSeabaseDDLauth::getAuthDetails(const char *pAuthName, bool isExternal) { try { NAString sysCat = CmpSeabaseDDL::getSystemCatalogStatic(); char buf[1000]; NAString authNameCol = isExternal ? "auth_ext_name " : "auth_db_name "; str_sprintf(buf, "select auth_id, auth_db_name, auth_ext_name, auth_type, auth_creator, auth_is_valid, auth_create_time, auth_redef_time from %s.\"%s\".%s where %s = '%s' ", sysCat.data(), SEABASE_MD_SCHEMA, SEABASE_AUTHS, authNameCol.data(), pAuthName); NAString cmd (buf); if (selectExactRow(cmd)) return 0; return 100; } catch (DDLException e) { return e.getSqlcode(); } catch (...) { return -1; } }
// ---------------------------------------------------------------------------- // method: authExists // // Input: none // // Output: // Returns true if authorization row exists in the metadata // Returns false if authorization row does not exist in the metadata // // An exception is thrown if any unexpected errors occurred. // ---------------------------------------------------------------------------- bool CmpSeabaseDDLauth::authExists (bool isExternal) { // Read the auths table based on the auth_db_name NAString sysCat = CmpSeabaseDDL::getSystemCatalogStatic(); NAString colName = (isExternal) ? "auth_ext_name" : "auth_db_name"; NAString authName = (isExternal) ? getAuthExtName() : getAuthDbName(); char buf[1000]; str_sprintf(buf, "select count(*) from %s.\"%s\".%s where %s = '%s' ", sysCat.data(), SEABASE_MD_SCHEMA, SEABASE_AUTHS, colName.data(), authName.data()); Lng32 len = 0; Int64 rowCount = 0; ExeCliInterface cliInterface(STMTHEAP); Lng32 cliRC = cliInterface.executeImmediate(buf, (char*)&rowCount, &len, NULL); // If unexpected error occurred, return an exception if (cliRC < 0) { cliInterface.retrieveSQLDiagnostics(CmpCommon::diags()); UserException excp (NULL, 0); excp.throwException(); } return (rowCount > 0) ? true : false; }
HDFS_Client_RetCode HdfsClient::hdfsExists( const NAString& uldPath, NABoolean & exist) { QRLogger::log(CAT_SQL_HDFS, LL_DEBUG, "HdfsClient::hdfsExists(%s) called.", uldPath.data()); if (initJNIEnv() != JOI_OK) return HDFS_CLIENT_ERROR_HDFS_EXISTS_PARAM; if (getInstance() == NULL) return HDFS_CLIENT_ERROR_HDFS_EXISTS_PARAM; jstring js_UldPath = jenv_->NewStringUTF(uldPath.data()); if (js_UldPath == NULL) { jenv_->PopLocalFrame(NULL); return HDFS_CLIENT_ERROR_HDFS_EXISTS_PARAM; } tsRecentJMFromJNI = JavaMethods_[JM_HDFS_EXISTS].jm_full_name; jboolean jresult = jenv_->CallStaticBooleanMethod(javaClass_, JavaMethods_[JM_HDFS_EXISTS].methodID, js_UldPath); exist = jresult; if (jenv_->ExceptionCheck()) { getExceptionDetails(); logError(CAT_SQL_HDFS, __FILE__, __LINE__); logError(CAT_SQL_HDFS, "HdfsClient::hdfsExists()", getLastError()); jenv_->PopLocalFrame(NULL); return HDFS_CLIENT_ERROR_HDFS_EXISTS_EXCEPTION; } jenv_->PopLocalFrame(NULL); return HDFS_CLIENT_OK; }
short IsolatedScalarUDF::generateShape(CollHeap * c, char * buf, NAString * shapeStr) { Space *space = (Space *)c; char mybuf[100]; sprintf (mybuf, "isolated_scalar_udf"); outputBuffer (space, buf, mybuf, shapeStr); if (getRoutineDesc() && getRoutineDesc()->getNARoutine() && getRoutineDesc()->getNARoutine()->getRoutineName()) { NAString fmtdStr; ToQuotedString(fmtdStr, getRoutineDesc()->getNARoutine()-> getRoutineName()->getQualifiedNameObj(). getQualifiedNameAsAnsiString().data()); snprintf (mybuf, 100, "(scalar_udf %s", fmtdStr.data()); outputBuffer (space, buf, mybuf, shapeStr); if (getRoutineDesc()->isUUDFRoutine() && getRoutineDesc()->getActionNARoutine() && getRoutineDesc()->getActionNARoutine()->getActionName()) { ToQuotedString(fmtdStr, getRoutineDesc()->getActionNARoutine()-> getActionName()->data()); snprintf (mybuf, 100, ", udf_action %s", fmtdStr.data()); outputBuffer (space, buf, mybuf, shapeStr); } strcpy(mybuf, ")"); outputBuffer (space, buf, mybuf, shapeStr); } return 0; }
HDFS_Client_RetCode HdfsClient::hdfsCleanUnloadPath( const NAString& uldPath) { QRLogger::log(CAT_SQL_HDFS, LL_DEBUG, "HdfsClient::hdfsCleanUnloadPath(%s) called.", uldPath.data()); if (initJNIEnv() != JOI_OK) return HDFS_CLIENT_ERROR_HDFS_CLEANUP_PARAM; if (getInstance() == NULL) return HDFS_CLIENT_ERROR_HDFS_CLEANUP_PARAM; jstring js_UldPath = jenv_->NewStringUTF(uldPath.data()); if (js_UldPath == NULL) { GetCliGlobals()->setJniErrorStr(getErrorText(HDFS_CLIENT_ERROR_HDFS_CLEANUP_PARAM)); jenv_->PopLocalFrame(NULL); return HDFS_CLIENT_ERROR_HDFS_CLEANUP_PARAM; } tsRecentJMFromJNI = JavaMethods_[JM_HDFS_CLEAN_UNLOAD_PATH].jm_full_name; jboolean jresult = jenv_->CallStaticBooleanMethod(javaClass_, JavaMethods_[JM_HDFS_CLEAN_UNLOAD_PATH].methodID, js_UldPath); if (jenv_->ExceptionCheck()) { getExceptionDetails(); logError(CAT_SQL_HDFS, __FILE__, __LINE__); logError(CAT_SQL_HDFS, "HdfsClient::hdfsCleanUnloadPath()", getLastError()); jenv_->PopLocalFrame(NULL); return HDFS_CLIENT_ERROR_HDFS_CLEANUP_EXCEPTION; } jenv_->PopLocalFrame(NULL); return HDFS_CLIENT_OK; }
NABoolean CmpInternalSP::OutputFormat(CmpSPOutputFormat& t) { NABoolean retStatus = TRUE; CMPASSERT(state_ == COMPILE); initSP_ERROR_STRUCT(); Lng32 num; NAString outTableName = OutTableName(); if ( (*(procFuncs_.outNumFormatFunc_))( &num, compHandle_, procFuncs_.spHandle_, &spError_[0]) == SP_SUCCESS ) { if ( num == 0 ) { // Create a dummy column if there is no output, since otherwise // NATable generated later on will break later in binder. SP_FIELDDESC_STRUCT fields; strcpy(fields.COLUMN_DEF, "Dummy1 int"); if ( !(t.SetFormat(1, outTableName.data(), &fields, 0, 0) ) ) retStatus = FALSE; } else { SP_FIELDDESC_STRUCT* fields = allocSP_FIELDDESC_STRUCT(num); SP_KEYDESC_STRUCT* keys = allocSP_KEYDESC_STRUCT(num); Lng32 nKeys = 0; initSP_ERROR_STRUCT(); if ( (*(procFuncs_.outFormatFunc_)) (fields, keys, &nKeys, compHandle_, procFuncs_.spHandle_, &spError_[0]) == SP_SUCCESS ) { if (!(t.SetFormat(num, outTableName.data(), fields, nKeys, keys ) ) ) { retStatus = FALSE; } } else { appendDiags(); retStatus = FALSE; } // It is not supposed to jump out of this function before this // delete[] deleteSP_FIELDDESC_STRUCT(fields); deleteSP_KEYDESC_STRUCT(keys); } } else { appendDiags(); retStatus = FALSE; } if ( !retStatus ) *(cmpContext()->diags()) << DgSqlCode(arkcmpErrorISPFieldDef); return retStatus; }
NABoolean HHDFSTableStats::connectHDFS(const NAString &host, Int32 port) { NABoolean result = TRUE; // establish connection to HDFS . Conect to the connection cached in the context. fs_ = ((GetCliGlobals()->currContext())->getHdfsServerConnection((char *)host.data(),port)); if (fs_ == NULL) { NAString errMsg("hdfsConnect to "); errMsg += host; errMsg += ":"; errMsg += port; errMsg += " failed"; diags_.recordError(errMsg, "HHDFSTableStats::connectHDFS"); result = FALSE; } currHdfsHost_ = host; currHdfsPort_ = port; // } return result; }
// // data (begin or end) is in this format: // <length><data> ... <length><data> // // a). length is 2-bytes long // b). data is <length>-bytes long // c). there are <n> such pairs, where <n> is determined by // the total length of the source and the length of each pair. // static NABoolean extractKeyValuePairs(const NAString& source, NAString& result) { char buf[1024]; const char* data = source.data(); const char* end = data + source.length(); NABoolean hasData = ( data < end); while ( data < end ) { UInt16 len = 0; memcpy((char*)&len, data, sizeof(len)); memcpy(buf, data+sizeof(len), len); buf[len] = NULL; result.append(buf); data += sizeof(len) + len; if ( data < end ) result.append(","); } return hasData; }
HDFS_Client_RetCode HdfsClient::hdfsCreateDirectory(const NAString &dirName) { QRLogger::log(CAT_SQL_HBASE, LL_DEBUG, "Enter HDFSClient_JNI::createDirectory() called."); if (initJNIEnv() != JOI_OK) return HDFS_CLIENT_ERROR_CREATE_DIRECTORY_PARAM; if (getInstance() == NULL) return HDFS_CLIENT_ERROR_CREATE_DIRECTORY_PARAM; jstring js_dirName = jenv_->NewStringUTF(dirName.data()); if (js_dirName == NULL) { jenv_->PopLocalFrame(NULL); return HDFS_CLIENT_ERROR_CREATE_DIRECTORY_PARAM; } tsRecentJMFromJNI = JavaMethods_[JM_HDFS_CREATE_DIRECTORY].jm_full_name; jstring jresult = (jstring)jenv_->CallStaticObjectMethod(javaClass_, JavaMethods_[JM_HDFS_CREATE_DIRECTORY].methodID, js_dirName); if (jenv_->ExceptionCheck()) { getExceptionDetails(jenv_); logError(CAT_SQL_HBASE, __FILE__, __LINE__); logError(CAT_SQL_HBASE, "HDFSClient_JNI::hdfsCreateDirectory()", getLastError()); jenv_->PopLocalFrame(NULL); return HDFS_CLIENT_ERROR_CREATE_DIRECTORY_EXCEPTION; } if (jresult == false) { logError(CAT_SQL_HDFS, "HdfsClient::hdfsCreateDirectory()", getLastError()); jenv_->PopLocalFrame(NULL); return HDFS_CLIENT_ERROR_HDFS_DELETE_PATH_EXCEPTION; } jenv_->PopLocalFrame(NULL); return HDFS_CLIENT_OK; }
void QRLogger::logDiags(ComDiagsArea* diagsArea, std::string &cat) { const NAWchar* diagMsg; NAString* diagStr; Int32 i; ComCondition* condition; log4cxx::LoggerPtr myLogger = log4cxx::Logger::getLogger(cat); if ( myLogger ) { log4cxx::LevelPtr myLevel = myLogger->getLevel(); if ( myLevel ) { // If configured Level is the same or less restrictive than WARN (30000) // than report the warning if ( myLevel != log4cxx::Level::getOff() && myLevel->toInt() <= LL_WARN ) { for (i=1; i<=diagsArea->getNumber(DgSqlCode::WARNING_); i++) { condition = diagsArea->getWarningEntry(i); diagMsg = condition->getMessageText(); diagStr = unicodeToChar(diagMsg, NAWstrlen(diagMsg), CharInfo::ISO88591, NULL, TRUE); log(cat, LL_WARN, condition->getSQLCODE(), "", " warn condition %d: %s", i, diagStr->data()); delete diagStr; } } } } }
// Delete a row from the AUTHS table based on the AUTH_ID void CmpSeabaseDDLauth::deleteRow(const NAString &authName) { NAString systemCatalog = CmpSeabaseDDL::getSystemCatalogStatic(); char buf[1000]; ExeCliInterface cliInterface(STMTHEAP); str_sprintf(buf, "delete from %s.\"%s\".%s where auth_db_name = '%s'", systemCatalog.data(), SEABASE_MD_SCHEMA, SEABASE_AUTHS, authName.data()); Lng32 cliRC = cliInterface.executeImmediate(buf); if (cliRC < 0) { cliInterface.retrieveSQLDiagnostics(CmpCommon::diags()); UserException excp (NULL, 0); excp.throwException(); } }
// ---------------------------------------------------------------------------- // method: getAuthDetails // // Create the CmpSeabaseDDLauth class containing auth details for the // request authID // // Input: // authID - the database authorization ID to search for // // Output: // A returned parameter: // 0 - authorization details are available // < 0 - an error was returned trying to get details // 100 - authorization details were not found // > 0 - (not 100) warning was returned // ---------------------------------------------------------------------------- Int32 CmpSeabaseDDLauth::getAuthDetails (Int32 authID) { try { NAString sysCat = CmpSeabaseDDL::getSystemCatalogStatic(); char buf[1000]; str_sprintf(buf, "select auth_id, auth_db_name, auth_ext_name, auth_type, auth_creator, auth_is_valid, auth_create_time, auth_redef_time from %s.\"%s\".%s where auth_id = %s ", sysCat.data(), SEABASE_MD_SCHEMA, SEABASE_AUTHS, authID); NAString cmd (buf); if (selectExactRow(cmd)) return 0; return 100; } catch (DDLException e) { // At this time, an error should be in the diags area. return e.getSqlcode(); } catch (...) { // If there is no error in the diags area, set up an internal error Int32 numErrors = CmpCommon::diags()->getNumber(DgSqlCode::ERROR_); if (numErrors == 0) *CmpCommon::diags() << DgSqlCode (-CAT_INTERNAL_EXCEPTION_ERROR) << DgInt0(__LINE__) << DgString0("getAuthDetails for authID"); return -CAT_INTERNAL_EXCEPTION_ERROR; } }
static NABoolean getCharsetsToUse( Lng32 msgCharSet, Lng32 &inputCS, Lng32 &defaultCS) { if (msgCharSet == SQLCHARSETCODE_ISO_MAPPING) { // return the value isoMapping set for this system. NAString cs; CmpCommon::getDefault(ISO_MAPPING, cs); inputCS = (Lng32)CharInfo::getCharSetEnum(cs.data()); defaultCS = (Lng32)SQLCHARSETCODE_ISO88591; SetSqlParser_DEFAULT_CHARSET(CharInfo::ISO88591); } else { inputCS = msgCharSet; defaultCS = (Lng32)SQLCHARSETCODE_UNKNOWN; // no change to default charset, if ISO_MAPPING was not specified. // Just set it to the same value as the original charset. SetSqlParser_DEFAULT_CHARSET(SqlParser_ORIG_DEFAULT_CHARSET); } return FALSE; }
void MvQueryRewriteHandler::dumpAnalysisToFile(QueryAnalysis* qa, RelExpr* expr) { // Dump the QueryAnalysis data to a file. NAString analysisFileName = fileNamePrefix_ + ".analysis"; NAString str; expr->unparse(str, OPTIMIZER_PHASE, MVINFO_FORMAT); str += "\n"; str += qa->getText(); // Add in some stuff to look at join predicates for the JBBCs. str += "Join Predicates\n"; str += "==============="; char buffer[20]; ARRAY(JBB*) jbbs = qa->getJBBs(); for (CollIndex jbbInx = 0; jbbInx < jbbs.entries(); jbbInx++) { JBB* jbb = jbbs[jbbInx]; str_itoa(jbbInx, buffer); ((str += "\nJBB #") += NAString(buffer)) += ":\n"; CANodeIdSet jbbcs = jbb->getJBBCs(); for (CANodeId jbbcId=jbbcs.init(); jbbcs.next(jbbcId); jbbcs.advance(jbbcId) ) { str_itoa(jbbcId, buffer); ((str += "\nJBBC with CANodeId ") += NAString(buffer)) += ":\n"; ValueIdSet joinPreds = jbbcId.getNodeAnalysis()->getJBBC()->getJoinPreds(); str += valueIdSetGetText(joinPreds); if (joinPreds.entries() > 0) { str.append("\n(value ids of predicates are "); NABoolean first = true; for (ValueId jpVid=joinPreds.init(); joinPreds.next(jpVid); joinPreds.advance(jpVid)) { if (first) first = FALSE; else str.append(", "); str_itoa(jpVid, buffer); str.append(buffer); } str.append(")\n"); } } str += '\n'; } dumpToFile(analysisFileName.data(), str.data()); } // dumpAnalysisToFile()
HDFS_Client_RetCode HdfsClient::hdfsMergeFiles( const NAString& srcPath, const NAString& dstPath) { QRLogger::log(CAT_SQL_HDFS, LL_DEBUG, "HdfsClient::hdfsMergeFiles(%s, %s) called.", srcPath.data(), dstPath.data()); if (initJNIEnv() != JOI_OK) return HDFS_CLIENT_ERROR_HDFS_MERGE_FILES_PARAM; if (getInstance() == NULL) return HDFS_CLIENT_ERROR_HDFS_MERGE_FILES_PARAM; jstring js_SrcPath = jenv_->NewStringUTF(srcPath.data()); if (js_SrcPath == NULL) { GetCliGlobals()->setJniErrorStr(getErrorText(HDFS_CLIENT_ERROR_HDFS_MERGE_FILES_PARAM)); jenv_->PopLocalFrame(NULL); return HDFS_CLIENT_ERROR_HDFS_MERGE_FILES_PARAM; } jstring js_DstPath= jenv_->NewStringUTF(dstPath.data()); if (js_DstPath == NULL) { GetCliGlobals()->setJniErrorStr(getErrorText(HDFS_CLIENT_ERROR_HDFS_MERGE_FILES_PARAM)); jenv_->PopLocalFrame(NULL); return HDFS_CLIENT_ERROR_HDFS_MERGE_FILES_PARAM; } tsRecentJMFromJNI = JavaMethods_[JM_HDFS_MERGE_FILES].jm_full_name; jboolean jresult = jenv_->CallStaticBooleanMethod(javaClass_, JavaMethods_[JM_HDFS_MERGE_FILES].methodID, js_SrcPath, js_DstPath); if (jenv_->ExceptionCheck()) { getExceptionDetails(); logError(CAT_SQL_HDFS, __FILE__, __LINE__); logError(CAT_SQL_HDFS, "HdfsClient::hdfsMergeFiles()", getLastError()); jenv_->PopLocalFrame(NULL); return HDFS_CLIENT_ERROR_HDFS_MERGE_FILES_EXCEPTION; } if (jresult == false) { logError(CAT_SQL_HDFS, "HdfsClient::hdfsMergeFiles()", getLastError()); jenv_->PopLocalFrame(NULL); return HDFS_CLIENT_ERROR_HDFS_MERGE_FILES_EXCEPTION; } jenv_->PopLocalFrame(NULL); return HDFS_CLIENT_OK; }
// ----------------------------------------------------------------------------- // Method: describe // // This method returns the showddl text for the requested user in string format // // Input: // authName - name of user to describe // // Input/Output: // authText - the REGISTER USER text // // returns result: // true - successful // false - failed (ComDiags area will be set up with appropriate error) //----------------------------------------------------------------------------- bool CmpSeabaseDDLuser::describe (const NAString &authName, NAString &authText) { Int32 retcode = 0; try { retcode = getUserDetails(authName.data()); if (retcode == 100) { *CmpCommon::diags() << DgSqlCode(-CAT_USER_NOT_EXIST) << DgString0 (authName.data()); return false; } // throw an exception so the catch handler will put a value in ComDiags // area in case no message exists if (retcode < 0) { UserException excp (NULL, 0); throw excp; } authText = "REGISTER USER "; authText += getAuthExtName(); if (getAuthExtName() != getAuthDbName()) { authText += " AS "; authText += getAuthDbName(); } authText += ";\n"; } catch (...) { // At this time, an error should be in the diags area. // If there is no error, set up an internal error Int32 numErrors = CmpCommon::diags()->getNumber(DgSqlCode::ERROR_); if (numErrors == 0) *CmpCommon::diags() << DgSqlCode(-CAT_INTERNAL_EXCEPTION_ERROR) << DgInt0(__LINE__) << DgString0("describe"); return false; } return true; }
//============================================================================ // This method writes the information related to the NAClusterInfo class to a // logfile called "NAClusterInfo.txt". //============================================================================ void NAClusterInfo::captureNAClusterInfo(ofstream & naclfile) { CollIndex i, ci; char filepath[OSIM_PATHMAX]; char filename[OSIM_FNAMEMAX]; // We don't capture data members that are computed during the compilation of // a query. These include: // // * smpCount_; // * tableToClusterMap_; // * activeClusters_; // naclfile << "localCluster_: " << localCluster_ << endl << "localSMP_: " << localSMP_ << endl; CollIndex *key_collindex; maps *val_maps; // Iterator for logging all the entries in clusterToCPUMap_ HashDictionary. NAHashDictionaryIterator<CollIndex, maps> C2CPUIter (*clusterToCPUMap_, NULL, NULL); naclfile << "clusterToCPUMap_: " << C2CPUIter.entries() << " :" << endl; if (C2CPUIter.entries() > 0) { // Write the header line for the table. naclfile << " "; naclfile.width(10); naclfile << "clusterNum" << " "; naclfile << "cpuList" << endl; for (i=0; i<C2CPUIter.entries(); i++) { C2CPUIter.getNext(key_collindex, val_maps); naclfile << " "; naclfile.width(10); naclfile << *key_collindex << " "; naclfile << val_maps->list->entries() << " : "; for (ci=0; ci<val_maps->list->entries(); ci++) { naclfile.width(3); naclfile << (*(val_maps->list))[ci] << " "; } naclfile << endl; } } Int32 * nodeID = NULL; NAString* nodeName = NULL; NAHashDictionaryIterator<Int32, NAString> nodeNameAndIDIter (*nodeIdToNodeNameMap_); naclfile << "nodeIdAndNodeNameMap: " << nodeNameAndIDIter.entries() << endl; for(nodeNameAndIDIter.getNext(nodeID, nodeName); nodeID && nodeName; nodeNameAndIDIter.getNext(nodeID, nodeName)) { naclfile << *nodeID << " " << nodeName->data() << endl; } // Now save the OS-specific information to the NAClusterInfo.txt file captureOSInfo(naclfile); }
// Insert a row into the AUTHS table void CmpSeabaseDDLauth::insertRow() { char buf[1000]; ExeCliInterface cliInterface(STMTHEAP); NAString authType; switch (getAuthType()) { case COM_ROLE_CLASS: authType = COM_ROLE_CLASS_LIT; break; case COM_USER_CLASS: authType = COM_USER_CLASS_LIT; break; default: authType = COM_UNKNOWN_ID_CLASS_LIT; } NAString authValid = isAuthValid() ? "Y" : "N"; NAString immutable = isAuthImmutable() ? "Y" : "N"; NAString sysCat = CmpSeabaseDDL::getSystemCatalogStatic(); str_sprintf(buf, "insert into %s.\"%s\".%s values (%d, '%s', '%s', '%s', %d, '%s', %Ld, %Ld)", sysCat.data(), SEABASE_MD_SCHEMA, SEABASE_AUTHS, getAuthID(), getAuthDbName().data(), getAuthExtName().data(), authType.data(), getAuthCreator(), authValid.data(), getAuthCreateTime(), getAuthRedefTime()); Int32 cliRC = cliInterface.executeImmediate(buf); if (cliRC < 0) { cliInterface.retrieveSQLDiagnostics(CmpCommon::diags()); UserException excp (NULL, 0); excp.throwException(); } }
NABoolean HHDFSListPartitionStats::populate(hdfsFS fs, const NAString &dir, Int32 numOfBuckets, NABoolean doEstimation, char recordTerminator, NABoolean isSequenceFile) { NABoolean result = TRUE; int numFiles = 0; // remember parameters partitionDir_ = dir; defaultBucketIdx_ = (numOfBuckets >= 1) ? numOfBuckets : 0; doEstimation_ = doEstimation; recordTerminator_ = recordTerminator; isSequenceFile_ = isSequenceFile; // list all the files in this directory, they all belong // to this partition and either belong to a specific bucket // or to the default bucket hdfsFileInfo *fileInfos = hdfsListDirectory(fs, dir.data(), &numFiles); // populate partition stats for (int f=0; f<numFiles && result; f++) if (fileInfos[f].mKind == kObjectKindFile) { // the default (unbucketed) bucket number is // defaultBucketIdx_ Int32 bucketNum = determineBucketNum(fileInfos[f].mName); HHDFSBucketStats *bucketStats = NULL; if (! bucketStatsList_.used(bucketNum)) { bucketStats = new(heap_) HHDFSBucketStats(heap_); bucketStatsList_.insertAt(bucketNum, bucketStats); } else bucketStats = bucketStatsList_[bucketNum]; if (! bucketStats->addFile(fs, &fileInfos[f], doEstimation, recordTerminator, isSequenceFile)) result = FALSE; } hdfsFreeFileInfo(fileInfos, numFiles); // aggregate statistics over all buckets for (Int32 b=0; b<=defaultBucketIdx_; b++) if (bucketStatsList_.used(b)) add(bucketStatsList_[b]); return result; }
Int32 parseMVAge(const NAString& mvAge) { Int32 result = 0; float number=0; char textChars[20]; if (mvAge.length() < 15) { if (sscanf(mvAge.data(), "%f %s", &number, textChars) == 2) { const NAString text(textChars); if (!text.compareTo("Seconds", NAString::ignoreCase)) { result = (Int32)floor(number); } else if (!text.compareTo("Minutes", NAString::ignoreCase)) { result = (Int32)floor(number*60); } else if (!text.compareTo("Hours", NAString::ignoreCase)) { result = (Int32)floor(number*60*60); } else if (!text.compareTo("Days", NAString::ignoreCase)) { result = (Int32)floor(number*60*60*24); } } } if (result == 0) { QRLogger::log(CAT_MVCAND, LL_ERROR, "Invalid setting for MV_AGE default value: %s, Using only fresh MVs.", mvAge.data()); } return result; }
CmpStatement::ReturnStatus CmpStatement::process(const CmpMessageDatabaseUser &statement) { NABoolean doDebug = FALSE; NAString message = statement.data(); size_t delimPos = message.first(','); CMPASSERT(delimPos <= MAX_AUTHID_AS_STRING_LEN); NAString userIDStr (message.data(), delimPos); Int32 userID = atoi(userIDStr.data()); char * userName = (char *)message.data(); userName += delimPos + 1; if (doDebug) { printf("[DBUSER:%d] Received user ID %d\n", (int) getpid(), (int) userID); printf("[DBUSER:%d] Received username %s\n", (int) getpid(), userName); } CmpSqlSession *session = CmpCommon::context()->sqlSession(); CMPASSERT(session); Lng32 sqlcode = session->setDatabaseUser(userID, userName); if (doDebug) printf("[DBUSER:%d] session->setDatabaseUser() returned %d\n", (int) getpid(), (int) sqlcode); if (doDebug) printf("[DBUSER:%d] END process(CmpMessageDatabaseUser)\n", (int) getpid()); if (sqlcode < 0) return CmpStatement_ERROR; return CmpStatement_SUCCESS; }
// *************************************************************************** // Get the output list element, that represents the output expression that // matches text (or NULL if not found). // *************************************************************************** const QROutputPtr MVDetails::getOutputByExprText(const NAString& text) { QRElementPtr output = outputByExprText_.getFirstValue(&text); QRLogger::log(CAT_MATCHTST_MVDETAILS, LL_DEBUG, "Checking for output expression: %s, %s.", text.data(), (output == NULL) ? "Not found it" : "Found it"); if (output == NULL) return NULL; else return output->downCastToQROutput(); }
void QRLogger::log(std::string &cat, logLevel level, int sqlCode, const char *queryId, const char *logMsgTemplate...) { log4cxx::LoggerPtr myLogger = log4cxx::Logger::getLogger(cat); if ( myLogger ) { log4cxx::LevelPtr myLevel = myLogger->getLevel(); log4cxx::LevelPtr paramLevel = log4cxx::Level::toLevel(level); if ( myLevel && paramLevel ) { if ( myLevel == log4cxx::Level::getOff() ) return; int_32 configuredLevel = myLevel->toInt(); int_32 requestedLevel = paramLevel->toInt(); // If the configured logging level is greater (more restrictive) than // the requested level, don't log. if ( configuredLevel > requestedLevel) return; } } else return; va_list args ; va_start(args, logMsgTemplate); char* buffer = buildMsgBuffer(cat, level, logMsgTemplate, args); NAString logData = QRLogger::instance().getMyProcessInfo(); char sqlCodeBuf[30]; snprintf(sqlCodeBuf, sizeof(sqlCodeBuf), "%d", sqlCode); logData += ","; if (sqlCode != 0) { logData += " SQLCODE: "; logData += sqlCodeBuf; } logData += ","; if (queryId != NULL && queryId[0] != '\0') { logData += " QID: "; logData += queryId; } logData += ", "; logData += buffer; log1(cat, level, logData.data()); va_end(args); }
// Constructor that parses a 1-, 2-, or 3-part external (Ansi) name string // and optionally applies default catalog and schema to it. // Use this on a string gotten from a trusted source (Sql Catalog), because // if it doesn't parse, the ctor cannot return an error so it CMPASSERTs. // // This code cloned for CorrName::applyPrototype below. // QualifiedName::QualifiedName(const NAString &ansiString, Int32 minNameParts, CollHeap * h, BindWA *bindWA) : SchemaName(h), objectName_(h), objectNameSpace_(COM_UNKNOWN_NAME), flagbits_(0) { if (HasMPLocPrefix(ansiString.data())) { ComMPLoc loc(ansiString); catalogName_ = loc.getSysDotVol(); schemaName_ = loc.getSubvolName(); objectName_ = loc.getFileName(); } else { CmpContext *cmpContext = bindWA ? bindWA->currentCmpContext() : NULL; Parser parser(cmpContext); NAString ns("TABLE " + ansiString + ";", CmpCommon::statementHeap()); #pragma nowarn(1506) // warning elimination // save the current parserflags setting ULng32 savedParserFlags = Get_SqlParser_Flags (0xFFFFFFFF); StmtQuery *stmt = (StmtQuery *)parser.parseDML(ns, ns.length(), GetAnsiNameCharSet()); // Restore parser flags settings Set_SqlParser_Flags (savedParserFlags); #pragma warn(1506) // warning elimination if (stmt) { CMPASSERT(stmt->getOperatorType() == STM_QUERY); *this = stmt->getQueryExpression()->getScanNode()->getTableName().getQualifiedNameObj(); delete stmt; } else { // It is possible for the parser to get errors when parsing SQL/MP // stored text. The caller is expected to check the contents of // this QualifiedName. // return; } } Int32 nameParts = 0; if (minNameParts > 0) { nameParts = getCatalogName() != "" ? 3 : getSchemaName() != "" ? 2 : getObjectName() != "" ? 1 : 0; CMPASSERT(nameParts >= minNameParts); } if (bindWA && nameParts < 3) applyDefaults(bindWA->getDefaultSchema()); } // end of QualifiedName::QualifiedName
NABoolean ISPIterator::initializeISPCaches(SP_ROW_DATA inputData, SP_EXTRACT_FUNCPTR eFunc, SP_ERROR_STRUCT* error, const NAArray<CmpContextInfo*> & ctxs, //input NAString & contextName, Int32 & index //output, set initial index in arrary of CmpContextInfos ) { //extract ISP input, find QueryCache belonging to specified context //and use it for fetch later Lng32 maxSize = 16; char receivingField[maxSize+1]; if (eFunc (0, inputData, (Lng32)maxSize, receivingField, FALSE) == SP_ERROR_EXTRACT_DATA) { error->error = arkcmpErrorISPFieldDef; return FALSE; } //choose context // 1. Search ctxInfos_ for all context with specified name('USER', 'META', 'USTATS'), // 'ALL' option will fetch all context in ctxInfos_, index is set to 0, qcache is always NULL, // 2. For remote arkcmp, which has 0 context in ctxInfos_, index is always -1, NAString qCntxt = receivingField; qCntxt.toLower(); //the receivingField is of pattern xxx$trafodion.yyy, //where xxx is the desired input string. Int32 dollarIdx = qCntxt.index("$"); CMPASSERT(dollarIdx > 0); //find the specified context if(ctxs.entries() == 0){ //for remote compiler if( (dollarIdx==3 && strncmp(qCntxt.data(), "all", dollarIdx)==0) ||(dollarIdx==4 && strncmp(qCntxt.data(), "user", dollarIdx)==0) ) index = -1; } else { if(dollarIdx==3 && strncmp(qCntxt.data(), "all", dollarIdx)==0) { contextName = "ALL"; index = 0; } else if(dollarIdx==4 && strncmp(qCntxt.data(), "user", dollarIdx)==0) { contextName = "NONE"; index = 0; } else if(dollarIdx==4 && strncmp(qCntxt.data(), "meta", dollarIdx)==0) { contextName = "META"; index = 0; } else if(dollarIdx==6 && strncmp(qCntxt.data(), "ustats", dollarIdx)==0) { contextName = "USTATS"; index = 0; } } return TRUE; }
void CmpSqlSession::setSessionId(NAString &sessionID) { sessionID_ = sessionID; if (NOT sessionID_.isNull()) { volatileSchemaName_ = COM_VOLATILE_SCHEMA_PREFIX; volatileSchemaName_ += COM_SESSION_ID_PREFIX; char sName[200]; Int64 cpu_l; Int64 pin_l; Int64 schemaNameCreateTime = 0; Int64 sessionUniqNum; Lng32 userNameLen = 0; Lng32 userSessionNameLen = 0; ComSqlId::extractSqlSessionIdAttrs ((char*)sessionID.data(), sessionID.length(), segmentNum_, cpu_l, pin_l, schemaNameCreateTime, sessionUniqNum, userNameLen, NULL, userSessionNameLen, NULL); str_sprintf(sName, "%02d%03Ld%06Ld%018Ld%010Ld", ComSqlId::SQ_SQL_ID_VERSION, segmentNum_, pin_l, schemaNameCreateTime, sessionUniqNum); volatileSchemaName_ += sName; volatileSchemaName_.toUpper(); // get segment name segmentName_ = "NSK"; sessionInUse_ = TRUE; volatileSchemaInUse_ = FALSE; // // it's a new session numSessions_++; } else { sessionInUse_ = FALSE; volatileSchemaInUse_ = FALSE; } }
// ************************************************************************** // Log an exception-type error message: // First log "Error thrown at line <line> in file <filename>:" // Then log the actual error message, which is passed with a variable // number of parameters. The error message is epected to be a single line // of text not exceeding 2K. // This error message can be logged as either ERROR or FATAL type. // Both lines of text are sent to the log file // MVQR failures that prevent only rewrite, and not execution of the original // form of the query, cause an informational rather than an error notification // to be entered in the system log. // ************************************************************************** // LCOV_EXCL_START :rfi void QRLogger::logError(const char* file, Int32 line, std::string &cat, logLevel level, const char* logMsgTemplate...) { #define BUFFER_SIZE 2048 char buffer[BUFFER_SIZE]; // This method expects a single line to text. NAString logData = QRLogger::instance().getMyProcessInfo(); if (level == LL_MVQR_FAIL) snprintf(buffer, sizeof(buffer), "%s,,, Attempted MVQR operation (rewrite of query or publication of MV) failed at line %d in file %s:", logData.data(), line, file); else snprintf(buffer, sizeof(buffer), "%s,,, Error thrown at line %d in file %s:", logData.data(), line, file); va_list args; va_start(args, logMsgTemplate); if (level == LL_FATAL) { LOG4CXX_FATAL(log4cxx::Logger::getLogger(cat), buffer); } else { LOG4CXX_ERROR(log4cxx::Logger::getLogger(cat), buffer); } // format actual error message vsnprintf(buffer, BUFFER_SIZE, logMsgTemplate, args); NAString logData2 = QRLogger::instance().getMyProcessInfo(); logData2 += ",,, "; logData2 += buffer; // log actual error msg to logfile. if (level == LL_FATAL) { LOG4CXX_FATAL(log4cxx::Logger::getLogger(cat), logData2.data()); } else { LOG4CXX_ERROR(log4cxx::Logger::getLogger(cat), logData2.data()); } va_end(args); }
// traverse queryExpr and put together its cacheKey void CacheWA::generateCacheKey(RelExpr *queryExpr, const char *sText, Lng32 charset, const NAString& viewsUsed) { if (viewsUsed.length() > 0) { qryText_ += "v:"; qryText_ += viewsUsed.data(); useView_ = TRUE; } if (isViewJoin_) { // prepend view join's text into its cache key qryText_ += sText; char cs[20]; sprintf(cs, "%d", charset); qryText_ += cs; } // save parameterized statement text into cwa.qryText_ queryExpr->generateCacheKey(*this); }
// ----------------------------------------------------------------------- // Translate ANSI SQL names from Default ANSI SQL Name character set // to UCS-2 encoding values. The contents of the outWcs parameter is // clear and set to the newly computed UCS2 string // ----------------------------------------------------------------------- void CmAnsiNameToUCS2(const NAString &inMbs, NAWString &outWcs) { outWcs.remove(0); // set to an empty string if (inMbs.length() <= 0) { return; } NAWString * pTargetNAWString = charToUnicode ( (Lng32)ComGetNameInterfaceCharSet() // in - Lng32 strCharSet , inMbs.data() // in - const char * str , (Int32)inMbs.length() // in - Int32 len , (NAMemory *)STMTHEAP // in - NAMemory * h ); ComASSERT(pTargetNAWString != NULL AND pTargetNAWString->length() > 0 AND pTargetNAWString->length() <= ComMAX_ANSI_IDENTIFIER_INTERNAL_LEN/*in NAWchars*/); outWcs.append(pTargetNAWString->data(), pTargetNAWString->length()); delete pTargetNAWString; }
NABoolean NAClusterInfo::NODE_ID_TO_NAME(Int32 nodeId, char *nodeName, short maxLen, short *actualLen) { //Currently, this method behaves as same as NODENUMBER_TO_NODENAME_(), //which always returns "\\NSK", the only reason for doing this is to //avoid diff in regression test and core file dumped when exiting sqlci.(don't know why.) NODENUMBER_TO_NODENAME_(nodeId, nodeName, maxLen, actualLen); return TRUE; //Following code may be used in future to provide real node id to name map. *actualLen = 0; if (nodeIdToNodeNameMap_->contains(&nodeId)) { NAString * value = nodeIdToNodeNameMap_->getFirstValue(&nodeId); *actualLen = value->length(); strncpy(nodeName, value->data(), maxLen < (*actualLen) ? maxLen : (*actualLen)); return TRUE; } return FALSE; }