Lng32 HSSqTableDef::getColumnNames() { HSErrorCatcher errorCatcher(retcode_, - UERR_UNABLE_TO_DESCRIBE_COLUMN_NAMES, "HSSqTableDef::DescribeColumnNames", TRUE); HSFuncExecQuery("CONTROL QUERY DEFAULT DISPLAY_DIVISION_BY_COLUMNS 'ON'"); Lng32 retcode = DescribeColumnNames(); HSFuncExecQuery("CONTROL QUERY DEFAULT DISPLAY_DIVISION_BY_COLUMNS RESET"); return retcode; }
// ----------------------------------------------------------------------- // Construct a fully qualified table name. // ----------------------------------------------------------------------- Lng32 AddTableName( const hs_table_type type , const char *table , const char *schema , const char *catalog ) { HSGlobalsClass *hs_globals = GetHSContext(); NAString catName, schName, objName; NAString extName; NAString defaultCat, defaultSch; NAString userLocation; Lng32 retcode = 0; hs_globals->tableType = type; HSLogMan *LM = HSLogMan::Instance(); // SET MPLOC is converted to CQD (setting values for default // attributes MP_SYSTEM, MP_VOLUME, MP_SUBVOLUME). It does not // update the global MPLOC value stored in SqlParser_MPLOC. The // following updates the global MPLOC value to be consistent with // the default attribute values set by SET MPLOC/CQD. ActiveSchemaDB()->getDefaults().getSqlParser_NADefaults(); if (type == GUARDIAN_TABLE) { if (*table == '$') { // Qualify with system name. extName = SqlParser_MPLOC.getSystemName(); extName += "."; extName += table; } else extName = table; hs_globals->tableFormat = SQLMP; } else { // When CQD DEFAULT_SCHEMA_ACCESS_ONLY is on, // users cannot update stats on tables not in the default/public schemas. if ( schema && ActiveSchemaDB()->getDefaults().getToken(DEFAULT_SCHEMA_ACCESS_ONLY)==DF_ON ) { SchemaName objSchName; NAString curSchName(schema); NAString curCatName; objSchName.setSchemaName(curSchName); if (catalog) { curCatName = catalog; objSchName.setCatalogName(curCatName); } else curCatName = ActiveSchemaDB()->getDefaultSchema().getCatalogName(); // If the schema is neither default nor public, // issue inaccessible error. if (!objSchName.matchDefaultPublicSchema()) { NAString dataObj(curCatName); if (!dataObj.isNull()) dataObj += "."; dataObj += curSchName + "."; dataObj += table; HSFuncMergeDiags(-UERR_OBJECT_INACCESSIBLE, dataObj.data()); retcode = -1; HSHandleError(retcode); } } if (catalog) catName = catalog; else { // LCOV_EXCL_START :nsk if (SqlParser_NAMETYPE == DF_NSK) { catName = SqlParser_MPLOC.getSysDotVol(); hs_globals->tableType = GUARDIAN_TABLE; hs_globals->tableFormat = SQLMP; } else // LCOV_EXCL_STOP catName = ActiveSchemaDB()->getDefaultSchema().getCatalogName(); } if (schema) schName = schema; else { // LCOV_EXCL_START :nsk if (SqlParser_NAMETYPE == DF_NSK) { schName = SqlParser_MPLOC.getSubvolName(); hs_globals->tableFormat = SQLMP; } else // LCOV_EXCL_STOP schName = ActiveSchemaDB()->getDefaultSchema().getSchemaName(); } objName = table; extName = catName + "." + schName + "." + objName; } // LCOV_EXCL_START :nsk if (hs_globals->tableFormat == SQLMP) { ComMPLoc loc(extName, ComMPLoc::FILE); if (loc.getFormat() == ComMPLoc::INVALID) { HSFuncMergeDiags(-UERR_OBJECT_INACCESSIBLE, extName); retcode = -1; HSHandleError(retcode); } catName = loc.getSysDotVol(); schName = loc.getSubvolName(); objName = loc.getFileName(); } // LCOV_EXCL_STOP hs_globals->objDef = NULL; // Search in volatile schema first. If not found, search in regular cat/sch. if ((CmpCommon::context()->sqlSession()->volatileSchemaInUse()) && (type != GUARDIAN_TABLE) && (! catalog)) { // search using the volatile schema name. NAString &volCatName = CmpCommon::context()->sqlSession()->volatileCatalogName(); NAString &volSchName = CmpCommon::context()->sqlSession()->volatileSchemaName(); NAString volObjName = table; ComObjectName volIntName(volCatName, volSchName, volObjName, COM_UNKNOWN_NAME, ComAnsiNamePart::INTERNAL_FORMAT); if (NOT volIntName.isValid()) { LM->Log("***[ERROR] Unable to create an ObjectClass"); HSFuncMergeDiags(-UERR_OBJECT_INACCESSIBLE, extName); retcode = -1; HSHandleError(retcode); } if (LM->LogNeeded()) { LM->Log("Searching in volatile schema, since catalog not specified.\n"); sprintf(LM->msg, "Checking volatile name (volIntName) %s.%s.%s\n", volIntName.getCatalogNamePart().getInternalName().data(), volIntName.getSchemaNamePart().getInternalName().data(), volIntName.getObjectNamePart().getInternalName().data()); LM->Log(LM->msg); } hs_globals->objDef = HSTableDef::create(STMTHEAP, volIntName, hs_globals->tableType, hs_globals->nameSpace); if (NOT hs_globals->objDef->objExists(HSTableDef::MAX_INFO)) { // now look into the regular schema delete hs_globals->objDef; hs_globals->objDef = NULL; } else { // if schema name was specified, validate that it is the // current username. if (schema) { QualifiedName qn(volObjName, schName); if (NOT CmpCommon::context()->sqlSession()->validateVolatileQualifiedName(qn)) { // table was found in the volatile schema but it is // not a valid volatile name. // Look for it in regular schema. // error info was moved to CmpCommon::diags. Clear it. CmpCommon::diags()->clear(); delete hs_globals->objDef; hs_globals->objDef = NULL; } } } } if (hs_globals->objDef == NULL) { ComObjectName intName(catName, schName, objName, COM_UNKNOWN_NAME, ComAnsiNamePart::INTERNAL_FORMAT); if (NOT intName.isValid()) { LM->Log("***[ERROR] Unable to create an ObjectClass"); HSFuncMergeDiags(-UERR_OBJECT_INACCESSIBLE, extName); retcode = -1; HSHandleError(retcode); } hs_globals->objDef = HSTableDef::create(STMTHEAP, intName, hs_globals->tableType, hs_globals->nameSpace); // try public schema if an object is not qualified and not found if ((NOT schema) && (NOT hs_globals->objDef->objExists(HSTableDef::MAX_INFO))) { NAString pubSch = ActiveSchemaDB()->getDefaults().getValue(PUBLIC_SCHEMA_NAME); ComSchemaName pubSchema(pubSch); if (NOT pubSchema.getSchemaNamePart().isEmpty()) { NAString pubSchName = pubSchema.getSchemaNamePart().getInternalName(); NAString pubCatName = (pubSchema.getCatalogNamePart().isEmpty() ? catName:pubSchema.getCatalogNamePart().getInternalName()); ComObjectName pubIntName(pubCatName, pubSchName, objName, COM_UNKNOWN_NAME, ComAnsiNamePart::INTERNAL_FORMAT); if (pubIntName.isValid()) { HSTableDef *pubObjDef = HSTableDef::create(STMTHEAP, pubIntName, hs_globals->tableType, hs_globals->nameSpace); if (pubObjDef->objExists(HSTableDef::MAX_INFO)) { hs_globals->objDef = pubObjDef; } } } } if (NOT hs_globals->objDef->objExists(HSTableDef::MAX_INFO)) { HSFuncMergeDiags(-UERR_OBJECT_INACCESSIBLE, extName); retcode = -1; HSHandleError(retcode); } } //10-040123-2660 We only support tables. We do not allow views. // Tables can be metadata tables. if ((hs_globals->objDef->getObjectType() != COM_BASE_TABLE_OBJECT) && (hs_globals->objDef->getObjectType() != COM_MV_OBJECT)) { HSFuncMergeDiags(-UERR_INVALID_OBJECT, extName); retcode = -1; HSHandleError(retcode); } retcode = hs_globals->objDef->getColumnNames(); HSFuncExecQuery("CONTROL QUERY DEFAULT DISPLAY_DIVISION_BY_COLUMNS RESET"); HSHandleError(retcode); hs_globals->tableFormat = hs_globals->objDef->getObjectFormat(); *hs_globals->catSch = hs_globals->objDef->getPrimaryLoc(HSTableDef::EXTERNAL_FORMAT); *hs_globals->user_table = hs_globals->objDef->getObjectFullName(); hs_globals->tableFormat = hs_globals->objDef->getObjectFormat(); hs_globals->isHbaseTable = HSGlobalsClass::isHbaseCat(catName); if (hs_globals->tableFormat == SQLMX) { // Determine the schema version for this MX table. if (LM->LogNeeded()) { sprintf(LM->msg, "\nCHECK SCHEMA VERSION FOR TABLE: %s\n", hs_globals->user_table->data()); LM->Log(LM->msg); } HSGlobalsClass::schemaVersion = getTableSchemaVersion(hs_globals->user_table->data()); // LCOV_EXCL_START :rfi if (HSGlobalsClass::schemaVersion == COM_VERS_UNKNOWN) { HSFuncMergeDiags(-UERR_INTERNAL_ERROR, "GET_SCHEMA_VERSION"); return -1; } // LCOV_EXCL_STOP if (HSGlobalsClass::schemaVersion >= COM_VERS_2300) HSGlobalsClass::autoInterval = CmpCommon::getDefaultLong(USTAT_AUTOMATION_INTERVAL); if (LM->LogNeeded()) { sprintf(LM->msg, "\nUpdateStats: TABLE: %s; SCHEMA VERSION: %d; AUTOMATION INTERVAL: %d\n", hs_globals->user_table->data(), HSGlobalsClass::schemaVersion, HSGlobalsClass::autoInterval); LM->Log(LM->msg); } const char* period = strchr(hs_globals->catSch->data(), '.'); NAString catName(hs_globals->catSch->data(), period - hs_globals->catSch->data()); NABoolean isHbaseOrHive = HSGlobalsClass::isHbaseCat(catName) || HSGlobalsClass::isHiveCat(catName); *hs_globals->hstogram_table = getHistogramsTableLocation(hs_globals->catSch->data(), FALSE); if (isHbaseOrHive) hs_globals->hstogram_table->append(".").append(HBASE_HIST_NAME); else hs_globals->hstogram_table->append(".HISTOGRAMS"); *hs_globals->hsintval_table = getHistogramsTableLocation(hs_globals->catSch->data(), FALSE); if (isHbaseOrHive) hs_globals->hsintval_table->append(".").append(HBASE_HISTINT_NAME); else hs_globals->hsintval_table->append(".HISTOGRAM_INTERVALS"); } else { // LCOV_EXCL_START :nsk *hs_globals->hstogram_table = hs_globals->objDef->getCatalogLoc(HSTableDef::EXTERNAL_FORMAT); hs_globals->hstogram_table->append(".HISTOGRM"); *hs_globals->hsintval_table = hs_globals->objDef->getCatalogLoc(HSTableDef::EXTERNAL_FORMAT); hs_globals->hsintval_table->append(".HISTINTS"); // RESET CQDS: HSFuncExecQuery("CONTROL QUERY DEFAULT DETAILED_STATISTICS RESET"); HSFuncExecQuery("CONTROL QUERY DEFAULT ALLOW_DP2_ROW_SAMPLING RESET"); HSFuncExecQuery("CONTROL QUERY DEFAULT POS RESET"); HSFuncExecQuery("CONTROL QUERY DEFAULT POS_NUM_OF_PARTNS RESET"); // LCOV_EXCL_STOP } return 0; }