You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafodion.apache.org by sa...@apache.org on 2018/11/06 05:31:33 UTC

[1/8] trafodion git commit: Fixees to support stroring Udr libraries s Blobs.

Repository: trafodion
Updated Branches:
  refs/heads/master d83b97efe -> 8058e144f


http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/sqlcomp/CmpSeabaseDDLupgrade.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLupgrade.cpp b/core/sql/sqlcomp/CmpSeabaseDDLupgrade.cpp
index b2cea77..fe09364 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLupgrade.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLupgrade.cpp
@@ -39,6 +39,7 @@
 #include "CmpDDLCatErrorCodes.h"
 #include "CmpSeabaseDDLupgrade.h"
 #include "CmpSeabaseDDLrepos.h"
+#include "CmpSeabaseDDLroutine.h"
 #include "PrivMgrMD.h"
 
 NABoolean CmpSeabaseMDupgrade::isOldMDtable(const NAString &objName)
@@ -84,6 +85,17 @@ NABoolean CmpSeabaseMDupgrade::isReposUpgradeNeeded()
   return FALSE;
 }
 
+NABoolean CmpSeabaseMDupgrade::isLibrariesUpgradeNeeded()
+{
+  for (Lng32 i = 0; i < sizeof(allLibrariesUpgradeInfo)/sizeof(MDUpgradeInfo); i++)
+    {
+      const MDUpgradeInfo &mdti = allLibrariesUpgradeInfo[i];
+      if (mdti.upgradeNeeded)
+        return TRUE;
+    }
+  return FALSE;
+}
+
 // ----------------------------------------------------------------------------
 // isPrivsUpgradeNeeded
 //
@@ -314,7 +326,7 @@ short CmpSeabaseMDupgrade::executeSeabaseMDupgrade(CmpDDLwithStatusInfo *mdui,
   // now as they are stateless
   CmpSeabaseUpgradeRepository upgradeRepository;
   CmpSeabaseUpgradePrivMgr upgradePrivMgr;
-
+  CmpSeabaseUpgradeLibraries upgradeLibraries;
   ExeCliInterface cliInterface(STMTHEAP, 0, NULL,
     CmpCommon::context()->sqlSession()->getParentQid());
   ExpHbaseInterface * ehi = NULL;
@@ -323,8 +335,8 @@ short CmpSeabaseMDupgrade::executeSeabaseMDupgrade(CmpDDLwithStatusInfo *mdui,
     {
       // The line below is useful when debugging upgrade; it shows the step progression
       // through the upgrade state machine.
-      // cout << "mdui->step() is " << mdui->step() 
-      //      << ", mdui->subStep() is " << mdui->subStep() << endl;
+       cout << "mdui->step() is " << mdui->step() 
+            << ", mdui->subStep() is " << mdui->subStep() << endl;
 
       switch (mdui->step())
 	{
@@ -649,9 +661,11 @@ short CmpSeabaseMDupgrade::executeSeabaseMDupgrade(CmpDDLwithStatusInfo *mdui,
 
 		  Int64 mdCurrMajorVersion;
 		  Int64 mdCurrMinorVersion;
+                  Int64 mdCurrUpdateVersion;
 		  retcode = validateVersions(&ActiveSchemaDB()->getDefaults(), ehi,
 					     &mdCurrMajorVersion,
-					     &mdCurrMinorVersion);
+					     &mdCurrMinorVersion,
+                                             &mdCurrUpdateVersion);
 
 		  deallocEHI(ehi);
 
@@ -668,10 +682,13 @@ short CmpSeabaseMDupgrade::executeSeabaseMDupgrade(CmpDDLwithStatusInfo *mdui,
 		      
 		      return 0;
 		    }
-		  else if (retcode == -1395) // mismatch in MAJOR version. Need to upgrade
+		  else if (retcode == -1395) // mismatch in version. Need to upgrade
 		    {
-		      if ((mdCurrMajorVersion == METADATA_OLD_MAJOR_VERSION) &&
-			  (mdCurrMinorVersion == METADATA_OLD_MINOR_VERSION))
+		      if (((mdCurrMajorVersion == METADATA_OLD_MAJOR_VERSION) &&
+			  (mdCurrMinorVersion == METADATA_OLD_MINOR_VERSION)) ||
+                          ((mdCurrMajorVersion == METADATA_MAJOR_VERSION) && 
+                           (mdCurrMinorVersion == METADATA_MINOR_VERSION) &&
+                           (mdCurrUpdateVersion == METADATA_OLD_UPDATE_VERSION)/*update version only*/))
 			{
                           NAString upgItems;
                           if (isUpgradeNeeded())
@@ -694,12 +711,18 @@ short CmpSeabaseMDupgrade::executeSeabaseMDupgrade(CmpDDLwithStatusInfo *mdui,
                                 {
                                   upgItems += " Repository,";
                                 }
+                              if (upgradeLibraries.needsUpgrade(this))
+                                {
+                                  upgItems += " Libraries,";
+                                }
                               if (NOT upgItems.isNull())
                                 {
                                   upgItems = upgItems.strip(NAString::trailing, ',');
                                   upgItems += ".";
                                 }
                             }
+                          // The VERSIONS table hs only a Major and Minor version so we have this funny encoding below
+                          // mdUpdate version can be 0 to 10 max. 
 			  str_sprintf(msgBuf, "  Metadata needs to be upgraded from Version %ld.%ld.%ld to %d.%d.%d.%s",
 				      mdCurrMajorVersion, mdCurrMinorVersion/10, 
                                       (mdCurrMinorVersion - (mdCurrMinorVersion/10)*10),
@@ -1603,7 +1626,7 @@ short CmpSeabaseMDupgrade::executeSeabaseMDupgrade(CmpDDLwithStatusInfo *mdui,
           {
             if (NOT isReposUpgradeNeeded())
               {
-                mdui->setStep(UPGRADE_PRIV_MGR);
+                mdui->setStep(UPGRADE_LIBRARIES);
                 mdui->setSubstep(0);
                 break;
               }
@@ -1637,6 +1660,43 @@ short CmpSeabaseMDupgrade::executeSeabaseMDupgrade(CmpDDLwithStatusInfo *mdui,
           }
           break;
 
+        case UPGRADE_LIBRARIES:
+          {
+             if (NOT isLibrariesUpgradeNeeded())
+              {
+                mdui->setStep(UPGRADE_PRIV_MGR);
+                mdui->setSubstep(0);
+                break;
+              }
+
+            if (xnInProgress(&cliInterface))
+              {
+                *CmpCommon::diags() << DgSqlCode(-20123);
+                
+                mdui->setStep(UPGRADE_FAILED_RESTORE_OLD_REPOS);
+                mdui->setSubstep(0);
+                
+                break;
+              }
+            
+            cliRC = upgradeLibraries.doUpgrade(&cliInterface, mdui, this, ddlXns);
+            if (cliRC != 0)
+              {
+                mdui->setStep(UPGRADE_FAILED_RESTORE_OLD_LIBRARIES);
+                mdui->setSubstep(-(cliRC+1));
+                
+                break;
+              }
+            
+            if (mdui->endStep())
+              {
+                mdui->setStep(UPGRADE_PRIV_MGR);
+                mdui->setSubstep(0);
+              }
+            
+            return 0;
+          }
+          break;
 	case UPDATE_VERSION:
 	  {
 	    switch (mdui->subStep())
@@ -1657,7 +1717,7 @@ short CmpSeabaseMDupgrade::executeSeabaseMDupgrade(CmpDDLwithStatusInfo *mdui,
 		    {
 		      *CmpCommon::diags() << DgSqlCode(-20123);
 
-		      mdui->setStep(UPGRADE_FAILED_RESTORE_OLD_REPOS);
+		      mdui->setStep(UPGRADE_FAILED_RESTORE_OLD_LIBRARIES);
 		      mdui->setSubstep(0);
 
 		      break;
@@ -1668,7 +1728,7 @@ short CmpSeabaseMDupgrade::executeSeabaseMDupgrade(CmpDDLwithStatusInfo *mdui,
 		    {
 		      cliInterface.retrieveSQLDiagnostics(CmpCommon::diags());
 
-		      mdui->setStep(UPGRADE_FAILED_RESTORE_OLD_REPOS);
+		      mdui->setStep(UPGRADE_FAILED_RESTORE_OLD_LIBRARIES);
 		      mdui->setSubstep(0);
 
 		      break;
@@ -1677,7 +1737,7 @@ short CmpSeabaseMDupgrade::executeSeabaseMDupgrade(CmpDDLwithStatusInfo *mdui,
 		  cliRC = updateSeabaseVersions(&cliInterface, TRAFODION_SYSCAT_LIT);
 		  if (cliRC < 0)
 		    {
-		      mdui->setStep(UPGRADE_FAILED_RESTORE_OLD_REPOS);
+		      mdui->setStep(UPGRADE_FAILED_RESTORE_OLD_LIBRARIES);
 		      mdui->setSubstep(0);
 
 		      break;
@@ -1691,7 +1751,7 @@ short CmpSeabaseMDupgrade::executeSeabaseMDupgrade(CmpDDLwithStatusInfo *mdui,
 		    {
 		      cliInterface.retrieveSQLDiagnostics(CmpCommon::diags());
 		    
-		      mdui->setStep(UPGRADE_FAILED_RESTORE_OLD_REPOS);
+		      mdui->setStep(UPGRADE_FAILED_RESTORE_OLD_LIBRARIES);
 		      mdui->setSubstep(0);
 
 		      break;
@@ -1703,7 +1763,7 @@ short CmpSeabaseMDupgrade::executeSeabaseMDupgrade(CmpDDLwithStatusInfo *mdui,
                       (NOT isViewsUpgradeNeeded()))
                     mdui->setStep(METADATA_UPGRADED);
                   else
-                    mdui->setStep(OLD_REPOS_DROP);
+                    mdui->setStep(OLD_LIBRARIES_DROP);
 		  mdui->setSubstep(0);
 		  mdui->setEndStep(TRUE);
                   
@@ -1739,7 +1799,31 @@ short CmpSeabaseMDupgrade::executeSeabaseMDupgrade(CmpDDLwithStatusInfo *mdui,
               }
 	  }
 	  break;
-
+	case OLD_LIBRARIES_DROP:
+	  {
+            if (upgradeLibraries.needsUpgrade(this))
+              {
+                if (upgradeLibraries.doDrops(&cliInterface,mdui,this))
+                  {
+                    // no status message in this case so no return
+                    cliInterface.clearGlobalDiags();
+                    mdui->setStep(OLD_REPOS_DROP);
+                    mdui->setSubstep(0);
+                    mdui->setEndStep(TRUE);
+                  }
+                else
+                  {
+                    if (mdui->endStep())
+                      {
+                        mdui->setStep(OLD_REPOS_DROP);
+                        mdui->setSubstep(0);
+                        mdui->setEndStep(TRUE);
+                      }                   
+                    return 0;
+                  }
+              }
+	  }
+	  break;
 	case OLD_MD_TABLES_HBASE_DELETE:
 	  {
 	    switch (mdui->subStep())
@@ -1901,7 +1985,50 @@ short CmpSeabaseMDupgrade::executeSeabaseMDupgrade(CmpDDLwithStatusInfo *mdui,
               }
           }
           break;
+        case UPGRADE_FAILED_RESTORE_OLD_LIBRARIES:
+          {
+            // Note: We can't combine this case with UPGRADE_FAILED etc.
+            // below, because the subsystem code uses mdui->subStep()
+            // to keep track of its progress.
+
+            if (upgradeLibraries.needsUpgrade(this))
+              {
+                if (xnInProgress(&cliInterface))
+                  {
+                    cliRC = rollbackXn(&cliInterface);
+                    if (cliRC < 0)
+                      {
+                        // ignore errors
+                      }
+                  }
 
+                if (upgradeLibraries.doUndo(&cliInterface,mdui,this))
+                  {
+                    // ignore errors; no status message so just continue on
+                    cliInterface.clearGlobalDiags();
+                    mdui->setStep(OLD_REPOS_DROP);
+                    mdui->setSubstep(0);
+                    mdui->setEndStep(TRUE);
+                  }
+                else
+                  {
+                    if (mdui->endStep())
+                      {
+                        mdui->setStep(OLD_REPOS_DROP);
+                        mdui->setSubstep(0);
+                        mdui->setEndStep(TRUE);
+                      }
+                    return 0;
+                  }
+              }
+            else
+              {
+                mdui->setStep(OLD_REPOS_DROP);
+                mdui->setSubstep(0);
+                mdui->setEndStep(TRUE);
+              }
+          }
+          break;
 	case UPGRADE_FAILED:
 	case UPGRADE_FAILED_RESTORE_OLD_MD:
 	case UPGRADE_FAILED_DROP_OLD_MD:
@@ -2502,6 +2629,35 @@ short CmpSeabaseMDupgrade::customizeNewMDv23tov30(CmpDDLwithStatusInfo *mdui,
 }
 
 // ----------------------------------------------------------------------------
+// Methods for class CmpSeabaseUpgradeLibraries
+// ----------------------------------------------------------------------------
+NABoolean CmpSeabaseUpgradeLibraries::needsUpgrade(CmpSeabaseMDupgrade * ddlState)
+{ 
+  return ddlState->isLibrariesUpgradeNeeded();
+}
+
+short CmpSeabaseUpgradeLibraries::doUpgrade(ExeCliInterface * cliInterface,
+  CmpDDLwithStatusInfo * mdui,
+  CmpSeabaseMDupgrade * ddlState,
+  NABoolean /* ddlXns */)
+{
+  return ddlState->upgradeLibraries(cliInterface,mdui);
+}
+
+short CmpSeabaseUpgradeLibraries::doDrops(ExeCliInterface * cliInterface,
+  CmpDDLwithStatusInfo * mdui, CmpSeabaseMDupgrade * ddlState)
+{
+  return ddlState->upgradeLibrariesComplete(cliInterface,mdui);
+}
+
+short CmpSeabaseUpgradeLibraries::doUndo(ExeCliInterface * cliInterface,
+  CmpDDLwithStatusInfo * mdui, CmpSeabaseMDupgrade * ddlState)
+{
+  return ddlState->upgradeLibrariesUndo(cliInterface,mdui);
+}
+
+
+// ----------------------------------------------------------------------------
 // Methods for class CmpSeabaseUpgradeRepository
 // ----------------------------------------------------------------------------
 NABoolean CmpSeabaseUpgradeRepository::needsUpgrade(CmpSeabaseMDupgrade * ddlState)

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/sqlcomp/CmpSeabaseDDLupgrade.h
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLupgrade.h b/core/sql/sqlcomp/CmpSeabaseDDLupgrade.h
index 1c3b2ee..8d37766 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLupgrade.h
+++ b/core/sql/sqlcomp/CmpSeabaseDDLupgrade.h
@@ -212,8 +212,8 @@ struct MDDescsInfo
 // This section should reflect the upgrade steps needed to go from
 // previous to current version.
 // Modify it as needed.
-// Currently it is set to upgrade from V11(source major version 1, minor version 1)
-// to V21.
+// Currently it is set to upgrade from V210(source major version 1, minor version 1)
+// to V211.
 //////////////////////////////////////////////////////////////
 static const MDUpgradeInfo allMDupgradeInfo[] = {
   {SEABASE_AUTHS, SEABASE_AUTHS_OLD_MD,
@@ -230,6 +230,141 @@ static const MDUpgradeInfo allMDupgradeInfo[] = {
 
   {SEABASE_DEFAULTS, SEABASE_DEFAULTS_OLD_MD,
    seabaseDefaultsDDL, sizeof(seabaseDefaultsDDL),
+   NULL,0,
+   NULL, 0,
+   FALSE, NULL, NULL, NULL, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE},
+  
+  {SEABASE_INDEXES, SEABASE_INDEXES_OLD_MD,
+   seabaseIndexesDDL, sizeof(seabaseIndexesDDL),
+   NULL, 0,
+   NULL, 0,
+   FALSE, NULL, NULL, NULL, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE},
+
+  {SEABASE_KEYS, SEABASE_KEYS_OLD_MD,
+   seabaseKeysDDL, sizeof(seabaseKeysDDL),
+   NULL, 0,
+   NULL, 0,
+   FALSE, NULL, NULL, NULL, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE},
+
+
+  {SEABASE_LIBRARIES_USAGE, SEABASE_LIBRARIES_USAGE_OLD_MD,
+   seabaseLibrariesUsageDDL, sizeof(seabaseLibrariesUsageDDL),
+   NULL,0,
+   NULL, 0,
+   FALSE, NULL, NULL, NULL, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE},
+
+
+  {SEABASE_OBJECTS, SEABASE_OBJECTS_OLD_MD,
+   seabaseObjectsDDL, sizeof(seabaseObjectsDDL),
+   NULL, 0,
+   NULL, 0,
+   FALSE,NULL,NULL,NULL, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE},
+
+  {SEABASE_OBJECTS_UNIQ_IDX, SEABASE_OBJECTS_UNIQ_IDX_OLD_MD,
+   seabaseObjectsUniqIdxDDL, sizeof(seabaseObjectsUniqIdxDDL),
+   NULL, 0,
+   NULL, 0,
+   FALSE, NULL, NULL, NULL, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE},
+
+  {SEABASE_REF_CONSTRAINTS, SEABASE_REF_CONSTRAINTS_OLD_MD,
+   seabaseRefConstraintsDDL, sizeof(seabaseRefConstraintsDDL),
+   NULL, 0,
+   NULL, 0,
+   FALSE, NULL, NULL, NULL, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE},
+
+  {SEABASE_ROUTINES, SEABASE_ROUTINES_OLD_MD,
+   seabaseRoutinesDDL, sizeof(seabaseRoutinesDDL),
+   NULL,NULL,
+   NULL, 0,
+   FALSE, NULL, NULL, NULL, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE},
+
+  {SEABASE_SEQ_GEN, SEABASE_SEQ_GEN_OLD_MD,
+   seabaseSeqGenDDL, sizeof(seabaseSeqGenDDL),
+   NULL, 0,
+   NULL, 0,
+   FALSE, NULL, NULL, NULL, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE},
+
+  {SEABASE_TABLES, SEABASE_TABLES_OLD_MD,
+   seabaseTablesDDL, sizeof(seabaseTablesDDL),
+   NULL, 0,
+   NULL, 0,
+   FALSE, NULL, NULL, NULL, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE},
+
+  {SEABASE_TABLE_CONSTRAINTS, SEABASE_TABLE_CONSTRAINTS_OLD_MD,
+   seabaseTableConstraintsDDL, sizeof(seabaseTableConstraintsDDL),
+   NULL, 0,
+   NULL, 0,
+   FALSE, NULL, NULL, NULL, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE},
+
+   
+  {SEABASE_TABLE_CONSTRAINTS_IDX, SEABASE_TABLE_CONSTRAINTS_IDX_OLD_MD, 
+   seabaseTableConstraintsIdxDDL, sizeof(seabaseTableConstraintsIdxDDL),
+   NULL, 0,
+   NULL, 0,
+   FALSE, NULL, NULL, NULL, FALSE, FALSE, TRUE, FALSE, TRUE, FALSE},
+
+  {SEABASE_TEXT, SEABASE_TEXT_OLD_MD,
+   seabaseTextDDL, sizeof(seabaseTextDDL),
+   NULL, 0,
+   NULL, 0,
+   FALSE, NULL, NULL, NULL, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE},
+
+  {SEABASE_UNIQUE_REF_CONSTR_USAGE, SEABASE_UNIQUE_REF_CONSTR_USAGE_OLD_MD,
+   seabaseUniqueRefConstrUsageDDL, sizeof(seabaseUniqueRefConstrUsageDDL),
+   NULL, 0,
+   NULL, 0,
+   FALSE, NULL, NULL, NULL, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE},
+
+  {SEABASE_VERSIONS, SEABASE_VERSIONS_OLD_MD,
+   seabaseVersionsDDL, sizeof(seabaseVersionsDDL),
+   NULL, 0,
+   NULL, 0,
+   FALSE, NULL, NULL, NULL, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE},
+
+  {SEABASE_VIEWS, SEABASE_VIEWS_OLD_MD,
+   seabaseViewsDDL, sizeof(seabaseViewsDDL),
+   NULL, 0,
+   NULL, 0,
+   FALSE, NULL, NULL, NULL, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE},
+
+  {SEABASE_VIEWS_USAGE, SEABASE_VIEWS_USAGE_OLD_MD,
+   seabaseViewsUsageDDL, sizeof(seabaseViewsUsageDDL),
+   NULL, 0,
+   NULL, 0,
+   FALSE, NULL, NULL, NULL, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE},
+
+  {SEABASE_VALIDATE_SPJ, SEABASE_VALIDATE_SPJ_OLD_MD,
+   NULL, 0,
+   NULL, 0,
+   NULL, 0,
+   FALSE, NULL, NULL, NULL, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE},
+
+  {SEABASE_VALIDATE_LIBRARY, SEABASE_VALIDATE_LIBRARY_OLD_MD,
+   NULL, 0,
+   NULL, 0,
+   NULL, 0,
+   FALSE, NULL, NULL, NULL, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE}
+
+};
+
+//////////////////////////////////////////////////////////////
+// This struct is set up for V110 to V210 upgrade.
+//////////////////////////////////////////////////////////////
+static const MDUpgradeInfo allMDv110tov210TablesInfo[] = {
+ {SEABASE_AUTHS, SEABASE_AUTHS_OLD_MD,
+   seabaseAuthsDDL, sizeof(seabaseAuthsDDL),
+   NULL, 0,
+   NULL, 0,
+   FALSE, NULL, NULL, NULL, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE},
+
+  {SEABASE_COLUMNS, SEABASE_COLUMNS_OLD_MD,
+   seabaseColumnsDDL, sizeof(seabaseColumnsDDL),
+   NULL, 0,
+   NULL, 0,
+   FALSE, NULL, NULL, NULL, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE},
+
+  {SEABASE_DEFAULTS, SEABASE_DEFAULTS_OLD_MD,
+   seabaseDefaultsDDL, sizeof(seabaseDefaultsDDL),
    seabaseOldTrafMDv11DefaultsDDL, sizeof(seabaseOldTrafMDv11DefaultsDDL),
    NULL, 0,
    TRUE, 
@@ -385,6 +520,9 @@ static const MDUpgradeInfo allMDupgradeInfo[] = {
 
 };
 
+
+
+
 //////////////////////////////////////////////////////////////
 // This struct is set up for V23 to V30 upgrade.
 //////////////////////////////////////////////////////////////
@@ -431,11 +569,11 @@ static const MDUpgradeInfo allMDv23tov30TablesInfo[] = {
    "object_uid, column_name, keyseq_number, column_number, ordering, nonkeycol, 0",
    NULL, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE},
 
-  {SEABASE_LIBRARIES, SEABASE_LIBRARIES_OLD_MD,
+  /*{SEABASE_LIBRARIES, SEABASE_LIBRARIES_OLD_MD,
    seabaseLibrariesDDL, sizeof(seabaseLibrariesDDL),
    NULL, 0,
    NULL, 0,
-   FALSE, NULL, NULL, NULL, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE},
+   FALSE, NULL, NULL, NULL, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE},*/
 
   {SEABASE_LIBRARIES_USAGE, SEABASE_LIBRARIES_USAGE_OLD_MD,
    seabaseLibrariesUsageDDL, sizeof(seabaseLibrariesUsageDDL),
@@ -578,12 +716,15 @@ class CmpSeabaseMDupgrade : public CmpSeabaseDDL
     UPDATE_MD_VIEWS,
     UPGRADE_REPOS,
     UPGRADE_PRIV_MGR,
+    UPGRADE_LIBRARIES,
     UPDATE_VERSION,
     OLD_REPOS_DROP,
+    OLD_LIBRARIES_DROP,
     METADATA_UPGRADED,
     UPGRADE_DONE,
     UPGRADE_FAILED,
     UPGRADE_FAILED_RESTORE_OLD_REPOS,
+    UPGRADE_FAILED_RESTORE_OLD_LIBRARIES,
     UPGRADE_FAILED_RESTORE_OLD_MD,
     UPGRADE_FAILED_DROP_OLD_MD,
     GET_MD_VERSION,
@@ -601,18 +742,21 @@ class CmpSeabaseMDupgrade : public CmpSeabaseDDL
   NABoolean isViewsUpgradeNeeded();
   NABoolean isReposUpgradeNeeded();
   NABoolean isPrivsUpgradeNeeded();
+  NABoolean isLibrariesUpgradeNeeded();
   NABoolean isUpgradeNeeded() 
   { return (isMDUpgradeNeeded() || 
             isViewsUpgradeNeeded() ||
             isReposUpgradeNeeded() ||
-            isPrivsUpgradeNeeded());
+            isPrivsUpgradeNeeded() ||
+            isLibrariesUpgradeNeeded());
   }
 
   short dropMDtables(ExpHbaseInterface *ehi, NABoolean oldTbls,
 		     NABoolean useOldNameForNewTables = FALSE);
 
   short dropReposTables(ExpHbaseInterface *ehi, NABoolean oldTbls);
-
+  short dropLibrariesTables(ExpHbaseInterface *ehi,
+                            NABoolean oldLibraries);
   short restoreOldMDtables(ExpHbaseInterface *ehi);
 
   short upgradePrivMgr(ExeCliInterface *cliInterface, 
@@ -712,6 +856,35 @@ class CmpSeabaseUpgradeRepository : public CmpSeabaseUpgradeSubsystem
 
 };
 
+//Libraries specialization
+class CmpSeabaseUpgradeLibraries : public CmpSeabaseUpgradeSubsystem
+{
+public:
+
+  CmpSeabaseUpgradeLibraries(void) { } ;
+  ~CmpSeabaseUpgradeLibraries(void) { } ;
+  
+  NABoolean needsUpgrade(CmpSeabaseMDupgrade * ddlState);
+
+  short doUpgrade(ExeCliInterface * cliInterface,
+                  CmpDDLwithStatusInfo * mdui,
+                  CmpSeabaseMDupgrade * ddlState,
+                  NABoolean ddlXns);
+
+  short doDrops(ExeCliInterface * cliInterface,
+                CmpDDLwithStatusInfo * mdui,
+                CmpSeabaseMDupgrade * ddlState);
+
+  short doUndo(ExeCliInterface * cliInterface,
+               CmpDDLwithStatusInfo * mdui,
+               CmpSeabaseMDupgrade * ddlState);
+  
+private:
+
+  // avoid having state for now
+
+};
+
 // Privilege Manager specialization
 
 class CmpSeabaseUpgradePrivMgr : public CmpSeabaseUpgradeSubsystem

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/sqlcomp/DefaultConstants.h
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/DefaultConstants.h b/core/sql/sqlcomp/DefaultConstants.h
index 2098024..de79a27 100644
--- a/core/sql/sqlcomp/DefaultConstants.h
+++ b/core/sql/sqlcomp/DefaultConstants.h
@@ -3349,6 +3349,8 @@ enum DefaultConstants
   // Used to read compressed hdfs text files and to write
   // both compressed and uncompressed hdfs files
   HDFS_IO_INTERIM_BYTEARRAY_SIZE_IN_KB,
+  // Use BLOB column in LIBRARIES tables to store libraries.
+  USE_LIB_BLOB_STORE,
 
   // This enum constant must be the LAST one in the list; it's a count,
   // not an Attribute (it's not IN DefaultDefaults; it's the SIZE of it)!

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/sqlcomp/nadefaults.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/nadefaults.cpp b/core/sql/sqlcomp/nadefaults.cpp
index e56efa5..a43a201 100644
--- a/core/sql/sqlcomp/nadefaults.cpp
+++ b/core/sql/sqlcomp/nadefaults.cpp
@@ -2874,13 +2874,13 @@ XDDkwd__(SUBQUERY_UNNESTING,			"ON"),
 
   DDkwd__(TRAF_AUTO_CREATE_SCHEMA,                 "OFF"),   
 
-  DDkwd__(TRAF_BLOB_AS_VARCHAR,                 "ON"), //set to OFF to enable Lobs support  
+  DDkwd__(TRAF_BLOB_AS_VARCHAR,                 "OFF"), //set to OFF to enable Lobs support  
 
   DDkwd__(TRAF_BOOLEAN_IO,                        "OFF"),
 
-  DDkwd__(TRAF_BOOTSTRAP_MD_MODE,                            "OFF"),   
+  DDkwd__(TRAF_BOOTSTRAP_MD_MODE,                            "OFF"),     
 
-  DDkwd__(TRAF_CLOB_AS_VARCHAR,                 "ON"), //set to OFF to enable Lobs support  
+  DDkwd__(TRAF_CLOB_AS_VARCHAR,                 "OFF"), //set to OFF to enable Lobs support  
 
   DDkwd__(TRAF_COL_LENGTH_IS_CHAR,                 "ON"),   
 
@@ -3059,8 +3059,11 @@ XDDkwd__(SUBQUERY_UNNESTING,			"ON"),
   // Use large queues on RHS of Flow/Nested Join when appropriate
   DDkwd__(USE_LARGE_QUEUES,                     "ON"),
 
+
  XDDkwd__(USE_LIBHDFS,                          "OFF"),
 
+  DDkwd__(USE_LIB_BLOB_STORE,                   "ON"),         
+
   DDkwd__(USE_MAINTAIN_CONTROL_TABLE,          "OFF"),
 
   DDkwd__(USE_OLD_DT_CONSTRUCTOR,      "OFF"),


[8/8] trafodion git commit: Merge remote branch 'origin/pr/1721/head' into merge_1721

Posted by sa...@apache.org.
Merge remote branch 'origin/pr/1721/head' into merge_1721


Project: http://git-wip-us.apache.org/repos/asf/trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafodion/commit/8058e144
Tree: http://git-wip-us.apache.org/repos/asf/trafodion/tree/8058e144
Diff: http://git-wip-us.apache.org/repos/asf/trafodion/diff/8058e144

Branch: refs/heads/master
Commit: 8058e144fd328ddefc2b6ee7ba11b7150705657b
Parents: d83b97e d82d650
Author: Sandhya Sundaresan <sa...@apache.org>
Authored: Tue Nov 6 05:30:57 2018 +0000
Committer: Sandhya Sundaresan <sa...@apache.org>
Committed: Tue Nov 6 05:30:57 2018 +0000

----------------------------------------------------------------------
 core/sqf/sqenvcom.sh                      |   12 +-
 core/sqf/sql/scripts/createhooks          |    2 +
 core/sqf/sql/scripts/genms                |    8 +-
 core/sqf/sql/scripts/install_local_hadoop |    5 +
 core/sql/bin/SqlciErrors.txt              |    4 +-
 core/sql/cli/Cli.cpp                      |   16 +-
 core/sql/cli/sqlcli.h                     |    2 +-
 core/sql/comexe/ComTdb.h                  |   10 +-
 core/sql/comexe/ComTdbUdr.cpp             |   36 +-
 core/sql/comexe/ComTdbUdr.h               |   11 +-
 core/sql/common/ComMisc.cpp               |  120 ++
 core/sql/common/ComMisc.h                 |    5 +
 core/sql/executor/ExExeUtil.h             |    1 +
 core/sql/executor/ExExeUtilLoad.cpp       |   39 +
 core/sql/executor/ExUdr.cpp               |  100 +-
 core/sql/executor/ExUdr.h                 |   14 +-
 core/sql/generator/GenUdr.cpp             |   31 +-
 core/sql/generator/Generator.cpp          |    8 +
 core/sql/optimizer/NARoutine.cpp          |   26 +
 core/sql/optimizer/NARoutine.h            |   16 +-
 core/sql/optimizer/UdfDllInteraction.cpp  |   71 +-
 core/sql/regress/executor/EXPECTED130     |   82 +-
 core/sql/regress/tools/rgrCleanup         |    4 +
 core/sql/regress/tools/runregr            |    2 +
 core/sql/regress/udr/EXPECTED001          |   24 +-
 core/sql/regress/udr/EXPECTED103          |   10 +-
 core/sql/regress/udr/EXPECTED108          |    4 +-
 core/sql/regress/udr/FILTER001            |    2 +-
 core/sql/regress/udr/FILTER108            |    2 +-
 core/sql/regress/udr/TEST001              |    4 +-
 core/sql/sqlcat/TrafDDLdesc.cpp           |    6 +-
 core/sql/sqlcat/TrafDDLdesc.h             |    6 +-
 core/sql/sqlcomp/CmpDDLCatErrorCodes.h    |    3 +-
 core/sql/sqlcomp/CmpSeabaseDDL.h          |   32 +-
 core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp  |   79 +-
 core/sql/sqlcomp/CmpSeabaseDDLincludes.h  |    2 +-
 core/sql/sqlcomp/CmpSeabaseDDLinitraf.cpp |   78 +-
 core/sql/sqlcomp/CmpSeabaseDDLmd.h        |   12 +-
 core/sql/sqlcomp/CmpSeabaseDDLrepos.h     |   29 +-
 core/sql/sqlcomp/CmpSeabaseDDLroutine.cpp | 1658 +++++++++++++++++++++---
 core/sql/sqlcomp/CmpSeabaseDDLroutine.h   |   77 ++
 core/sql/sqlcomp/CmpSeabaseDDLtable.cpp   |  149 ++-
 core/sql/sqlcomp/CmpSeabaseDDLupgrade.cpp |  185 ++-
 core/sql/sqlcomp/CmpSeabaseDDLupgrade.h   |  185 ++-
 core/sql/sqlcomp/DefaultConstants.h       |    2 +
 core/sql/sqlcomp/nadefaults.cpp           |    9 +-
 46 files changed, 2773 insertions(+), 410 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafodion/blob/8058e144/core/sqf/sqenvcom.sh
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/trafodion/blob/8058e144/core/sqf/sql/scripts/genms
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/trafodion/blob/8058e144/core/sqf/sql/scripts/install_local_hadoop
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/trafodion/blob/8058e144/core/sql/bin/SqlciErrors.txt
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/trafodion/blob/8058e144/core/sql/cli/Cli.cpp
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/trafodion/blob/8058e144/core/sql/comexe/ComTdb.h
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/trafodion/blob/8058e144/core/sql/generator/Generator.cpp
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/trafodion/blob/8058e144/core/sql/optimizer/NARoutine.cpp
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/trafodion/blob/8058e144/core/sql/optimizer/NARoutine.h
----------------------------------------------------------------------
diff --cc core/sql/optimizer/NARoutine.h
index 0ffc83b,9b536d4..304b11f
--- a/core/sql/optimizer/NARoutine.h
+++ b/core/sql/optimizer/NARoutine.h
@@@ -174,10 -174,13 +174,14 @@@ public
    inline Int32                        getActionPosition() const { return actionPosition_; }
  
    inline PrivMgrUserPrivs *              getPrivInfo()    const { return privInfo_; }
 +  inline PrivMgrDescList  *              getPrivDescs()   const { return privDescs_; }
    inline Int32                           getObjectOwner() const { return objectOwner_; }
    inline Int32                           getSchemaOwner() const { return schemaOwner_; }
- 
+   inline Int64  getLibRedefTime() const {return libRedefTime_;}
+   inline const NAString  &getLibBlobHandle() const {return libBlobHandle_;}
+   inline const NAString  &getLibSchName() const {return libSchName_;}
+   inline Int32 getLibVersion() const {return libVersion_;}
+   inline Int64 getLibObjUID() const {return libObjUID_;}
    inline void  setudfFanOut      (Int32 fanOut)       { udfFanOut_ = fanOut; }
    inline void  setExternalPath   (ComString path)     { externalPath_   = path; }
    inline void  setFile           (ComString file)     { externalFile_   = file; }  

http://git-wip-us.apache.org/repos/asf/trafodion/blob/8058e144/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/trafodion/blob/8058e144/core/sql/sqlcomp/DefaultConstants.h
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/trafodion/blob/8058e144/core/sql/sqlcomp/nadefaults.cpp
----------------------------------------------------------------------


[5/8] trafodion git commit: Fixees to support stroring Udr libraries s Blobs.

Posted by sa...@apache.org.
Fixees to support stroring Udr libraries s Blobs.


Project: http://git-wip-us.apache.org/repos/asf/trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafodion/commit/9528f8c0
Tree: http://git-wip-us.apache.org/repos/asf/trafodion/tree/9528f8c0
Diff: http://git-wip-us.apache.org/repos/asf/trafodion/diff/9528f8c0

Branch: refs/heads/master
Commit: 9528f8c0d2c75bb7f783c4b1589d11b1d4b64869
Parents: 5f230e2
Author: Sandhya Sundaresan <sa...@apache.org>
Authored: Fri Sep 28 19:44:56 2018 +0000
Committer: Sandhya Sundaresan <sa...@apache.org>
Committed: Fri Sep 28 19:44:56 2018 +0000

----------------------------------------------------------------------
 core/sqf/sqenvcom.sh                      |    8 +
 core/sqf/sql/scripts/createhooks          |    2 +
 core/sqf/sql/scripts/genms                |    2 +
 core/sqf/sql/scripts/install_local_hadoop |    5 +
 core/sql/bin/SqlciErrors.txt              |    4 +-
 core/sql/cli/Cli.cpp                      |   16 +-
 core/sql/cli/sqlcli.h                     |    2 +-
 core/sql/comexe/ComTdb.h                  |   10 +-
 core/sql/comexe/ComTdbUdr.cpp             |   36 +-
 core/sql/comexe/ComTdbUdr.h               |   11 +-
 core/sql/common/ComMisc.cpp               |  117 ++
 core/sql/common/ComMisc.h                 |    5 +
 core/sql/executor/ExExeUtil.h             |    1 +
 core/sql/executor/ExExeUtilLoad.cpp       |   39 +
 core/sql/executor/ExUdr.cpp               |   92 +-
 core/sql/executor/ExUdr.h                 |   14 +-
 core/sql/generator/GenUdr.cpp             |   31 +-
 core/sql/generator/Generator.cpp          |    8 +
 core/sql/optimizer/NARoutine.cpp          |   26 +
 core/sql/optimizer/NARoutine.h            |   16 +-
 core/sql/optimizer/UdfDllInteraction.cpp  |   65 +-
 core/sql/regress/executor/EXPECTED130     |   82 +-
 core/sql/regress/tools/rgrCleanup         |    4 +
 core/sql/regress/tools/runregr            |    2 +
 core/sql/regress/udr/EXPECTED001          |   24 +-
 core/sql/regress/udr/EXPECTED103          |   10 +-
 core/sql/regress/udr/EXPECTED108          |    4 +-
 core/sql/regress/udr/FILTER001            |    2 +-
 core/sql/regress/udr/FILTER108            |    2 +-
 core/sql/regress/udr/TEST001              |    4 +-
 core/sql/sqlcat/TrafDDLdesc.cpp           |    4 +-
 core/sql/sqlcat/TrafDDLdesc.h             |    6 +-
 core/sql/sqlcomp/CmpDDLCatErrorCodes.h    |    2 +-
 core/sql/sqlcomp/CmpSeabaseDDL.h          |   33 +-
 core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp  |   89 +-
 core/sql/sqlcomp/CmpSeabaseDDLincludes.h  |    2 +-
 core/sql/sqlcomp/CmpSeabaseDDLinitraf.cpp |   36 +
 core/sql/sqlcomp/CmpSeabaseDDLmd.h        |   12 +-
 core/sql/sqlcomp/CmpSeabaseDDLrepos.h     |   29 +-
 core/sql/sqlcomp/CmpSeabaseDDLroutine.cpp | 1800 +++++++++++++++++++++---
 core/sql/sqlcomp/CmpSeabaseDDLroutine.h   |   77 +
 core/sql/sqlcomp/CmpSeabaseDDLtable.cpp   |  149 +-
 core/sql/sqlcomp/CmpSeabaseDDLupgrade.cpp |  184 ++-
 core/sql/sqlcomp/CmpSeabaseDDLupgrade.h   |  185 ++-
 core/sql/sqlcomp/DefaultConstants.h       |    2 +
 core/sql/sqlcomp/nadefaults.cpp           |    9 +-
 46 files changed, 2878 insertions(+), 385 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sqf/sqenvcom.sh
----------------------------------------------------------------------
diff --git a/core/sqf/sqenvcom.sh b/core/sqf/sqenvcom.sh
index 1010a44..804e03f 100644
--- a/core/sqf/sqenvcom.sh
+++ b/core/sqf/sqenvcom.sh
@@ -61,6 +61,13 @@ fi
 export SQ_IC=${SQ_IC:-TCP}
 export MPI_IC_ORDER=$SQ_IC
 
+export ARCH=`arch`
+if [ "${ARCH:0:3}" == "ppc" ]; then
+    export JRE_LIB_DIR=${ARCH}
+else
+    export JRE_LIB_DIR="amd64"
+fi
+
 # use sock
 #export SQ_TRANS_SOCK=1
 
@@ -200,6 +207,7 @@ export DTM_COMMON_JAR=trafodion-dtm-cdh-${TRAFODION_VER}.jar
 export SQL_JAR=trafodion-sql-cdh-${TRAFODION_VER}.jar
 export UTIL_JAR=trafodion-utility-${TRAFODION_VER}.jar
 export JDBCT4_JAR=jdbcT4-${TRAFODION_VER}.jar
+export MY_UDR_CACHE_LIBDIR=cached_libs
 
 
 if [[ "$HBASE_DISTRO" == "HDP" ]]; then

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sqf/sql/scripts/createhooks
----------------------------------------------------------------------
diff --git a/core/sqf/sql/scripts/createhooks b/core/sqf/sql/scripts/createhooks
index e83b4c3..eb2b483 100755
--- a/core/sqf/sql/scripts/createhooks
+++ b/core/sqf/sql/scripts/createhooks
@@ -41,6 +41,8 @@ touch revive.hook
 touch snmppa.hook
 touch spp.hook
 touch sqlci.hook
+touch tdm_arkcmp.hook
+touch tdm_arkesp.hook
 touch tdm_arkqvp.hook
 touch tm.hook
 touch TPA.hook

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sqf/sql/scripts/genms
----------------------------------------------------------------------
diff --git a/core/sqf/sql/scripts/genms b/core/sqf/sql/scripts/genms
index 29ac957..794e2e2 100755
--- a/core/sqf/sql/scripts/genms
+++ b/core/sqf/sql/scripts/genms
@@ -183,6 +183,8 @@ else
   echo "MY_UDR_ROOT=\$TRAF_HOME/udr"
 fi
 
+echo "MY_UDR_CACHE_LIBDIR=cached_libs"
+
 echo ""
 echo "#creating sqllogs folder for capturing osim data"
 sqllogdir=$HOME/sqllogs

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sqf/sql/scripts/install_local_hadoop
----------------------------------------------------------------------
diff --git a/core/sqf/sql/scripts/install_local_hadoop b/core/sqf/sql/scripts/install_local_hadoop
index ca7789a..807ba74 100755
--- a/core/sqf/sql/scripts/install_local_hadoop
+++ b/core/sqf/sql/scripts/install_local_hadoop
@@ -1373,6 +1373,11 @@ echo "$MY_LOCAL_SW_DIST/${MYSQL_JDBC_TAR}"
 fi
 # end of MySQL JDBC setup
 
+#udr cached lib setup
+echo "Creating udr cached lib : ${MY_UDR_CACHE_LIBDIR}"
+mkdir -p $MY_PUBLIC_UDR_CACHE_LIBDIR
+#end of udr cached lib setup
+
 cd $MY_SW_ROOT
 
 if [ -d hive/bin ]; then

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/bin/SqlciErrors.txt
----------------------------------------------------------------------
diff --git a/core/sql/bin/SqlciErrors.txt b/core/sql/bin/SqlciErrors.txt
index 7032bf7..6f88b9f 100644
--- a/core/sql/bin/SqlciErrors.txt
+++ b/core/sql/bin/SqlciErrors.txt
@@ -37,7 +37,7 @@
 1035 ZZZZZ 99999 BEGINNER MAJOR DBADMIN Catalog $0~CatalogName already exists.
 1036 ZZZZZ 99999 BEGINNER MAJOR DBADMIN Authorization ID $0~String0 cannot grant to authorization ID $1~String1 because it could create a circular dependency.
 1037 ZZZZZ 99999 BEGINNER MAJOR DBADMIN Revoke failed because of a dependent grant between authorization ID $0~string0 and authorization ID $1~string1.
-1038 ZZZZZ 99999 BEGINNER MAJOR DBADMIN --- unused ---
+1038 ZZZZZ 99999 BEGINNER MAJOR DBADMIN Unable to upgrade library management
 1039 ZZZZZ 99999 BEGINNER MAJOR DBADMIN No privileges were revoked. You lack the grant option for the specified privilege(s).
 1040 ZZZZZ 99999 BEGINNER MAJOR DBADMIN The use of ALTER on metadata tables is not permitted.
 1041 ZZZZZ 99999 BEGINNER MINOR DBADMIN The primary key has already been defined.
@@ -1327,7 +1327,7 @@ $1~String1 --------------------------------
 4313 ZZZZZ 99999 BEGINNER MAJOR DBADMIN Function rand() is not supported.
 4314 ZZZZZ 99999 BEGINNER MAJOR DBADMIN An error was detected while creating an audit row image for $0~TableName. AUDIT_IMAGE function is only supported on index tables.
 4315 ZZZZZ 99999 BEGINNER MAJOR DBADMIN An error was detected while creating an audit row image. The columns defined for the index $0~TableName do not match what was requested for the audit row image.
-4316 ZZZZZ 99999 BEGINNER MAJOR DBADMIN An error was detected while creating an audit row image. The data type defined for the index $0~TableName and $0~ColumnName do not match what was requested for the audit row image.
+4316 ZZZZZ 99999 BEGINNER MAJOR DBADMIN An error was detected while extracting a udr routine library to local cache : $0~string0 .
 4320 ZZZZZ 99999 BEGINNER MAJOR DBADMIN Stream access is not allowed on multi-partitioned table or index, when flag ATTEMPT_ASYNCHRONOUS_ACCESS is set to OFF. Object in scope: $0~TableName.
 4321 ZZZZZ 99999 BEGINNER MAJOR DBADMIN An embedded update/delete is not allowed on a partitioned table, when flag ATTEMPT_ASYNCHRONOUS_ACCESS is set to OFF. Object in scope: $0~TableName.
 4322 0A000 99999 BEGINNER MAJOR DBADMIN A column with BLOB datatype cannot be used in this clause or function.

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/cli/Cli.cpp
----------------------------------------------------------------------
diff --git a/core/sql/cli/Cli.cpp b/core/sql/cli/Cli.cpp
index 9e14307..9fdc051 100644
--- a/core/sql/cli/Cli.cpp
+++ b/core/sql/cli/Cli.cpp
@@ -2203,6 +2203,14 @@ Lng32 SQLCLI_ProcessRetryQuery(
                 } 
             }
         }
+
+      // if this is a udr/call statement and not a standalone statement, return an error
+      //The caller will need to reprepare the query so we have an updated tdb to execute.
+      // If it's a standalone statement, the statement will get reprepared and executed. 
+      if ((rootTdb->getUdrCount() > 0) && !stmt->isStandaloneQ())
+      {
+        return retcode;
+      }
     }
 
   AQRStatementInfo * aqrSI = NULL;
@@ -9541,7 +9549,7 @@ Lng32 SQLCLI_LOBddlInterface
         exLobGlob = ExpLOBoper::initLOBglobal(currContext.exHeap(), &currContext, useLibHdfs);
         if (exLobGlob == NULL) 
           {
-            cliRC = 0;
+            cliRC = -1;
             ComDiagsArea * da = &diags;
             ExRaiseSqlError(currContext.exHeap(), &da, 
 			    (ExeErrorCode)(8442), NULL, &cliRC    , 
@@ -9560,7 +9568,7 @@ Lng32 SQLCLI_LOBddlInterface
 	    
 	    if (rc)
 	      {
-		cliRC = 0;
+		cliRC = -1;
 		ComDiagsArea * da = &diags;
 		ExRaiseSqlError(currContext.exHeap(), &da, 
 			    (ExeErrorCode)(8442), NULL, &cliRC    , 
@@ -9656,7 +9664,7 @@ Lng32 SQLCLI_LOBddlInterface
         exLobGlob = ExpLOBoper::initLOBglobal(currContext.exHeap(), &currContext, useLibHdfs);
         if (exLobGlob == NULL) 
           {
-            cliRC = 0;
+            cliRC = -1;
             ComDiagsArea * da = &diags;
             ExRaiseSqlError(currContext.exHeap(), &da, 
 			    (ExeErrorCode)(8442), NULL, &cliRC    , 
@@ -9705,7 +9713,7 @@ Lng32 SQLCLI_LOBddlInterface
         exLobGlob = ExpLOBoper::initLOBglobal(currContext.exHeap(), &currContext, useLibHdfs);
         if (exLobGlob == NULL) 
           {
-            cliRC = 0;
+            cliRC = -1;
             ComDiagsArea * da = &diags;
             ExRaiseSqlError(currContext.exHeap(), &da, 
 			    (ExeErrorCode)(8442), NULL, &cliRC    , 

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/cli/sqlcli.h
----------------------------------------------------------------------
diff --git a/core/sql/cli/sqlcli.h b/core/sql/cli/sqlcli.h
index 00ae7b2..d01048e 100644
--- a/core/sql/cli/sqlcli.h
+++ b/core/sql/cli/sqlcli.h
@@ -1,4 +1,4 @@
-/**********************************************************************
+/*********************************************************************y
 // @@@ START COPYRIGHT @@@
 //
 // Licensed to the Apache Software Foundation (ASF) under one

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/comexe/ComTdb.h
----------------------------------------------------------------------
diff --git a/core/sql/comexe/ComTdb.h b/core/sql/comexe/ComTdb.h
index e00728f..5271784 100644
--- a/core/sql/comexe/ComTdb.h
+++ b/core/sql/comexe/ComTdb.h
@@ -44,6 +44,7 @@
 #include "sqlcli.h"
 #include "ComSmallDefs.h"
 #include "PrivMgrDesc.h"        // Privilege descriptors
+#include "ExpLOBenums.h"
 
 // -----------------------------------------------------------------------
 // Classes defined in this file
@@ -1013,11 +1014,12 @@ class ComTdbVirtTableRoutineInfo : public ComTdbVirtTableBase
                              Int16 d, const char * sa, Int16 con, Int16 i, const char * ps,
                              const char * ta, Int32 mr, Int32 sas, const char * en,
                              const char * p, const char * uv, const char * es, const char * em,
-                             const char * lf, Int32 lv, const char * s, const char *ls)
+                             const char * lf, Int32 lv, const char * s, const char *ls, Int64 luid
+                             )
     : ComTdbVirtTableBase(),
     routine_name(rn), deterministic(d), call_on_null(con), isolate(i), max_results(mr),
     state_area_size(sas), external_name(en), library_filename(lf), library_version(lv),
-      signature(s), library_sqlname(ls)
+      signature(s), library_sqlname(ls),lib_obj_uid(luid)
       {
         strcpy(UDR_type, ut);
         strcpy(language_type, lt);
@@ -1061,6 +1063,10 @@ class ComTdbVirtTableRoutineInfo : public ComTdbVirtTableBase
   Int64 object_uid;
   Int32 object_owner_id;
   Int32 schema_owner_id;
+  Int64 lib_redef_time;
+  char *lib_blob_handle;
+  char *lib_sch_name;
+  Int64 lib_obj_uid;
 };
 
 class ComTdbVirtTableSequenceInfo : public ComTdbVirtTableBase

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/comexe/ComTdbUdr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/comexe/ComTdbUdr.cpp b/core/sql/comexe/ComTdbUdr.cpp
index ab29c3a..08c0ba3 100644
--- a/core/sql/comexe/ComTdbUdr.cpp
+++ b/core/sql/comexe/ComTdbUdr.cpp
@@ -45,7 +45,10 @@ ComTdbUdr::ComTdbUdr(char *sqlName,
                      char *containerName,
                      char *externalPath,
                      char *librarySqlName,
-                     
+                     Int64 libraryRedefTime,
+                     char *libraryBlobHandle,
+                     char *librarySchName,
+                     Int32 libraryVersion,
                      char *runtimeOptions,
                      char *runtimeOptionDelimiters,
 
@@ -111,7 +114,10 @@ ComTdbUdr::ComTdbUdr(char *sqlName,
   containerName_(containerName),
   externalPath_(externalPath),
   librarySqlName_(librarySqlName),
-
+  libraryRedefTime_(libraryRedefTime),
+  libraryBlobHandle_(libraryBlobHandle),
+  librarySchName_(librarySchName),
+  libraryVersion_(libraryVersion),
   runtimeOptions_(runtimeOptions),
   runtimeOptionDelimiters_(runtimeOptionDelimiters),
 
@@ -206,6 +212,8 @@ Long ComTdbUdr::pack(void *space)
   optionalData_.pack(space);
   udrSerInvocationInfo_.pack(space);
   udrSerPlanInfo_.pack(space);
+  libraryBlobHandle_.pack(space);
+  librarySchName_.pack(space);
   udrChildTableDescInfo_.pack(space,(Lng32)numChildTableInputs_);
   childInputExprs_.pack(space,(Lng32)numChildTableInputs_);
   childTdbs_.pack(space,(Lng32)numChildTableInputs_);
@@ -228,7 +236,7 @@ Lng32 ComTdbUdr::unpack(void *base, void *reallocator)
   if (outputExpr_.unpack(base, reallocator)) return -1;
   if (scanExpr_.unpack(base, reallocator)) return -1;
   if (projExpr_.unpack(base, reallocator)) return -1;
-  
+ 
   //
   // The NAVersionedObject array templates use long values to index
   // into the array, so we cast numParams_ to long here. This is assumed
@@ -251,7 +259,8 @@ Lng32 ComTdbUdr::unpack(void *base, void *reallocator)
     return -1;
   if (udrSerPlanInfo_.unpack(base))
     return -1;
-
+  if (libraryBlobHandle_.unpack(base)) return -1;
+  if (librarySchName_.unpack(base)) return -1;
   return ComTdb::unpack(base, reallocator);
 }
 
@@ -306,7 +315,24 @@ void ComTdbUdr::displayContents(Space *space, ULng32 flag)
       str_sprintf(buf, "librarySqlName = %s", s);
       space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sz);
     }
-
+    if (libraryBlobHandle_)
+      {
+        char *s = libraryBlobHandle_;
+        str_sprintf(buf, "libraryBlobHandle = %s", s);
+        space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sz);
+      }
+     if (librarySchName_)
+      {
+        char *s = librarySchName_;
+        str_sprintf(buf, "librarySchName = %s", s);
+        space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sz);
+      }
+    str_sprintf(buf, "\nlibrayRedefTimestamp = %ld",
+                libraryRedefTime_);
+    space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sz);
+    str_sprintf(buf, "\nlibrayVersion = %d",
+                libraryVersion_);
+    space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sz);
     // Some strings come from the user and there is no limit on the
     // maximum length. For these strings we will print two lines, the
     // first a header line and the second the actual string. For

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/comexe/ComTdbUdr.h
----------------------------------------------------------------------
diff --git a/core/sql/comexe/ComTdbUdr.h b/core/sql/comexe/ComTdbUdr.h
index 4bb4a88..d9f9752 100644
--- a/core/sql/comexe/ComTdbUdr.h
+++ b/core/sql/comexe/ComTdbUdr.h
@@ -68,7 +68,10 @@ public:
     char *containerName,
     char *externalPath,
     char *librarySqlName,
-
+    Int64 libraryRedefTime,
+    char *libraryBlobHandle,
+    char *librarySchName,
+    Int32 libraryVersion,
     char *javaOptions,
     char *javaOptionDelimiters,
 
@@ -322,8 +325,12 @@ protected:
 
   Int32 javaDebugPort_;                                   // 236-239
   Int32 javaDebugTimeout_;                                // 240-243
+  Int64 libraryRedefTime_;                                // 244-251
+  NABasicPtr libraryBlobHandle_;                          // 252-259
+  NABasicPtr librarySchName_;                             // 260-267
+  Int32 libraryVersion_;                                  // 268-271
   // Make sure class size is a multiple of 8
-  char fillerComTdbUdr2_[28];                             // 244-271
+  char fillerComTdbUdr2_[24];                             // 272-295
 };
 
 

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/common/ComMisc.cpp
----------------------------------------------------------------------
diff --git a/core/sql/common/ComMisc.cpp b/core/sql/common/ComMisc.cpp
index 387b309..baa3a00 100644
--- a/core/sql/common/ComMisc.cpp
+++ b/core/sql/common/ComMisc.cpp
@@ -41,6 +41,7 @@
 #include "ComMisc.h"
 #include "ComDistribution.h" // enumToLiteral, literalToEnum, literalAndEnumStruct
 #include "CmpSeabaseDDL.h"
+#include <sys/stat.h>
 
 // define the enum-to-literal function
 #define ComDefXLateE2L(E2L,eType,array) void E2L (const eType e, NAString &l) \
@@ -357,3 +358,119 @@ NABoolean ComTrafReservedColName(
 
   return FALSE;
 }
+
+
+Int32  ComGenerateUdrCachedLibName(NAString libname,Int64 redeftime, NAString schemaName, NAString userid, NAString &cachedLibName, NAString &cachedLibPath)
+{
+  NAString libPrefix, libSuffix;
+  struct stat statbuf;
+  NAString redefTimeString = Int64ToNAString(redeftime);
+  size_t lastDot = libname.last('.');
+  if (lastDot != NA_NPOS)
+    {
+      libSuffix = libname(lastDot,libname.length()-lastDot);
+      libPrefix = libname(0,lastDot);
+    }
+ 
+  //when isolated user support is added   
+  if (userid.length()!=0)       
+    {
+
+      cachedLibPath = getenv("TRAF_HOME") ;
+      cachedLibPath += "/udr";
+      if ( stat(cachedLibPath, &statbuf) != 0)
+         {
+           if (mkdir(cachedLibPath,S_IRWXU|S_IRWXG|S_IRWXO))
+             {
+               return -1;
+             }
+               
+         }
+      cachedLibPath += "/";
+      cachedLibPath += getenv("MY_UDR_CACHE_LIBDIR");
+      if ( stat(cachedLibPath, &statbuf) != 0)
+         {
+           if (mkdir(cachedLibPath,S_IRWXU|S_IRWXG|S_IRWXO))
+             {
+               return -1;
+             }
+               
+         }
+      cachedLibPath +=  "/"+ userid ;
+      if (stat(cachedLibPath, &statbuf) != 0)
+        {
+          if (mkdir(cachedLibPath,S_IRUSR|S_IWUSR|S_IXUSR))//Only this user has 
+            //permission to read/write/execute in this directory and below.
+            {
+              return -1;
+            }
+               
+        }
+      cachedLibPath += "/" + schemaName;
+      if ( stat(cachedLibPath, &statbuf) != 0)
+         {
+           if (mkdir(cachedLibPath,S_IRWXU|S_IRWXG|S_IRWXO))
+             {
+               return -1;
+             }
+               
+         }
+     
+      
+    }
+  else
+    {
+      cachedLibPath = getenv("TRAF_HOME") ;
+      cachedLibPath += "/udr";
+      if ( stat(cachedLibPath, &statbuf) != 0)
+         {
+           if (mkdir(cachedLibPath,S_IRWXU|S_IRWXG|S_IRWXO))
+             {
+               return -1;
+             }
+               
+         }
+      cachedLibPath += "/";
+      cachedLibPath += getenv("MY_UDR_CACHE_LIBDIR");
+      if ( stat(cachedLibPath, &statbuf) != 0)
+         {
+           if (mkdir(cachedLibPath,S_IRWXU|S_IRWXG|S_IRWXO))
+             {
+               return -1;
+             }
+               
+         }
+      cachedLibPath +=  "/"+ NAString("DB__ROOT") ;
+      if (stat(cachedLibPath, &statbuf) != 0)
+        {
+          if (mkdir(cachedLibPath,S_IRWXU|S_IRWXG|S_IRWXO)) // these permissions
+            //need to change when we have isolated user support so only DB_ROOT 
+            //can access this directory. Right now we allow all to access this directory
+            {
+              return -1;
+            }
+               
+        }
+      cachedLibPath += "/" + schemaName;
+      if ( stat(cachedLibPath, &statbuf) != 0)
+         {
+           if (mkdir(cachedLibPath,S_IRWXU|S_IRWXG|S_IRWXO))
+             {
+               return -1;
+             }
+               
+         }
+     
+    }
+      
+  
+  
+  cachedLibName += libPrefix + "_" ;
+  cachedLibName += redefTimeString;
+  cachedLibName += libSuffix ;
+
+  return 0;
+  
+}
+
+

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/common/ComMisc.h
----------------------------------------------------------------------
diff --git a/core/sql/common/ComMisc.h b/core/sql/common/ComMisc.h
index 1581489..7b1cebb 100644
--- a/core/sql/common/ComMisc.h
+++ b/core/sql/common/ComMisc.h
@@ -112,4 +112,9 @@ NAString ComConvertTrafHiveNameToNativeHiveName(
 //                   with underscore(_)
 NABoolean ComTrafReservedColName(const NAString &colName);
 
+// Converts a library name like myfile.jar or myfile.so to this format
+// $TRAF_HOME/$MY_UDR_CACHE_LIBDIR/<user>|public/myfile_<redeftime>.jar|so 
+Int32 ComGenerateUdrCachedLibName(NAString libname,Int64 redeftime,NAString schemaName, NAString user, NAString&cachedLibName, NAString &cachedPathName );
+
+
 #endif // COMMISC_H

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/executor/ExExeUtil.h
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtil.h b/core/sql/executor/ExExeUtil.h
index 435dfb5..49acbad 100644
--- a/core/sql/executor/ExExeUtil.h
+++ b/core/sql/executor/ExExeUtil.h
@@ -4183,6 +4183,7 @@ public:
 protected:
 };
 
+short ExExeUtilLobExtractLibrary(ExeCliInterface *cliInterface,char *libHandle, char *cachedLibName,ComDiagsArea *toDiags);
 #endif
 
 

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/executor/ExExeUtilLoad.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtilLoad.cpp b/core/sql/executor/ExExeUtilLoad.cpp
index 7c051c4..ff4564b 100644
--- a/core/sql/executor/ExExeUtilLoad.cpp
+++ b/core/sql/executor/ExExeUtilLoad.cpp
@@ -3288,6 +3288,45 @@ short ExExeUtilLobExtractTcb::work()
   return 0;
 }
 
+
+short ExExeUtilLobExtractLibrary(ExeCliInterface *cliInterface,char *libHandle, char *cachedLibName,ComDiagsArea *toDiags)
+{
+  char buf[1000];
+  Int32 cliRC =0;
+  str_sprintf(buf, "extract lobtofile(LOB '%s','%s');",libHandle,cachedLibName);
+               
+
+  cliRC = cliInterface->fetchRowsPrologue(buf, TRUE/*no exec*/);
+  if (cliRC < 0)
+    {
+      cliInterface->retrieveSQLDiagnostics(toDiags);
+      return cliRC;
+    }
+
+  cliRC = cliInterface->clearExecFetchClose(NULL, 0);
+  if (cliRC < 0)
+    {
+      cliInterface->retrieveSQLDiagnostics(toDiags);
+      //Ignore error if the target file exists. This could be because the cached
+      // file already got created by another process at the same time. So we can ignore
+      // the error and use the already cached file.
+      ComCondition *cond = NULL;
+      Int32 entryNumber;
+      cond = toDiags->findCondition(-EXE_ERROR_FROM_LOB_INTERFACE, &entryNumber);
+      if (cond)
+        {
+          if (cond->getOptionalInteger(0) == LOB_TARGET_FILE_EXISTS_ERROR)
+            {
+              toDiags->deleteError(entryNumber);
+              return 0;
+            }
+        }
+                      
+      return cliRC;
+    }
+  return cliRC;
+}
+
 ExExeUtilFileExtractTcb::ExExeUtilFileExtractTcb
 (
  const ComTdbExeUtilLobExtract & exe_util_tdb,

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/executor/ExUdr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExUdr.cpp b/core/sql/executor/ExUdr.cpp
index 230aa42..fc2686a 100644
--- a/core/sql/executor/ExUdr.cpp
+++ b/core/sql/executor/ExUdr.cpp
@@ -62,7 +62,8 @@
 #include "Statement.h"
 #include "ExRsInfo.h"
 #include "Descriptor.h"
-
+#include "ExExeUtil.h"
+#include <sys/stat.h>
 #define TF_STRING(x) ((x) ? ("TRUE") : ("FALSE"))
 #define YN_STRING(x) ((x) ? ("YES") : ("NO"))
 
@@ -631,7 +632,10 @@ Int32 ExUdrTcb::fixup()
 
   UdrDebug1("[BEGIN TCB FIXUP] %p", this);
   setUdrTcbState(FIXUP);
-    
+  // CliGlobals *cliGlobals = getGlobals()->castToExExeStmtGlobals()->
+  // castToExMasterStmtGlobals()->getCliGlobals();
+  CliGlobals *cliGlobals = GetCliGlobals();
+  ExeCliInterface cliInterface(getHeap(), 0, cliGlobals->currContext());
   //
   // Non-zero return value indicates an error
   //
@@ -792,9 +796,57 @@ Int32 ExUdrTcb::fixup()
                      this, udrServer_->getUdrControlConnection());
         }
       }
-
+      
+      NAString cachedLibName, cachedLibPath;
+      if ((myTdb().getLibraryRedefTime() != -1) && (myTdb().getLibraryRedefTime() != 0))
+        {
+          // Cache library locally. 
+          NAString dummyUser;
+          NAString libOrJarName;
+        
+          if (myTdb().getLanguage() == COM_LANGUAGE_JAVA)
+            libOrJarName = myTdb().getPathName();
+          else
+            libOrJarName = myTdb().getContainerName();
+          if(ComGenerateUdrCachedLibName(libOrJarName.data(),
+                                         myTdb().getLibraryRedefTime(),
+                                         myTdb().getLibrarySchName(),
+                                         dummyUser,
+                                         cachedLibName, cachedLibPath))
+            {
+              NAString cachedFullName = cachedLibPath+"/"+cachedLibName;
+                  *getOrCreateStmtDiags() <<  DgSqlCode(-4316)
+                                << DgString0(( char *)cachedFullName.data());;
+                  return FIXUP_ERROR;
+            }
+           NAString cachedFullName = cachedLibPath+"/"+cachedLibName;
+          //If the local copy already exists, don't bother extracting.
+          struct stat statbuf;
+          if (stat(cachedFullName, &statbuf) != 0)
+            {
+              ComDiagsArea *returnedDiags = ComDiagsArea::allocate(getHeap());
+              if (ExExeUtilLobExtractLibrary(&cliInterface,
+                                             (char *)myTdb().getLibraryBlobHandle(), 
+                                             ( char *)cachedFullName.data(),returnedDiags))
+                {
+                  *returnedDiags <<  DgSqlCode(-4316)
+                                << DgString0(( char *)cachedFullName.data());
+                  getOrCreateStmtDiags()->mergeAfter(*returnedDiags);
+                  returnedDiags->decrRefCount();
+                  returnedDiags = NULL;
+                  return FIXUP_ERROR;
+                }
+        
+              returnedDiags->decrRefCount();
+              returnedDiags = NULL;
+            }
+          
+        }
+      
       if (sendControlMessage(isResultSet ? UDR_MSG_RS_LOAD : UDR_MSG_LOAD, 
-                             TRUE))
+                             TRUE, 
+                             cachedLibName.length()? (char *)cachedLibName.data():NULL, 
+                             cachedLibPath.length()? (char *)cachedLibPath.data():NULL))
       {
         if (verifyUdrServerProcessId())
         {
@@ -1816,7 +1868,7 @@ void ExUdrTcb::releaseServerResources()
 // - RS CLOSE is sent by the RS operator when down queue entries are
 //   cancelled.
 NABoolean ExUdrTcb::sendControlMessage(UdrIpcObjectType t,
-                                       NABoolean callbackRequired)
+                                       NABoolean callbackRequired, char *cachedLibName, char *cachedLibPath)
 {
   // Determine the transid we should send in the message. We
   // use the statement transid if all the following are true
@@ -1837,7 +1889,7 @@ NABoolean ExUdrTcb::sendControlMessage(UdrIpcObjectType t,
   {
     transIdToSend = stmtTransId;
   }
-  
+ 
 #ifdef UDR_DEBUG
   {
     char stmtTx[256];
@@ -1848,7 +1900,8 @@ NABoolean ExUdrTcb::sendControlMessage(UdrIpcObjectType t,
     UdrDebug2("    stmt tx %s, msg tx %s", stmtTx, msgTx);
   }
 #endif
-
+ 
+ 
   ex_assert(outstandingControlStream_ == NULL,
     "Sending a UDR control message while one is already outstanding");
 
@@ -1882,17 +1935,38 @@ NABoolean ExUdrTcb::sendControlMessage(UdrIpcObjectType t,
       if (numInstances == 0)
         numInstances = 1; // I compute, therefore I am.
 
+      
       // Steps to create a LOAD message:
       // - First create a UdrLoadMsg instance on the IPC heap and initialize
       //   it with a UDR handle and UDR metadata
       // - Next put metadata for each formal parameter into the object
+
+      //In the case of java, the path name contains the fully qualified jar file location
+      NAString pathName, containerName;
+      if (udrTdb.getLanguage() == COM_LANGUAGE_JAVA)
+        {
+          pathName = cachedLibPath? cachedLibPath :udrTdb.getPathName();
+          if (cachedLibName)
+            {
+            pathName+= "/";
+            pathName+=cachedLibName;
+            }
+          containerName = udrTdb.getContainerName();
+        }
+      else
+        //In the case of C/C++ the DLL name and the path names need to be sent
+        //separately so langman can process them properly
+        {
+          pathName = cachedLibPath? cachedLibPath :udrTdb.getPathName();
+          containerName = cachedLibName?cachedLibName: udrTdb.getContainerName();
+        }
       UdrLoadMsg *loadMsg = new (h) UdrLoadMsg(
         h,
         udrTdb.getSqlName(),
         udrTdb.getRoutineName(),
         udrTdb.getSignature(),
-        udrTdb.getContainerName(),
-        udrTdb.getPathName(),
+        containerName,
+        pathName,
         udrTdb.getLibrarySqlName(),
         udrTdb.getTransactionAttrs(),
         udrTdb.getSqlAccessMode(),

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/executor/ExUdr.h
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExUdr.h b/core/sql/executor/ExUdr.h
index 3ba2838..ba6822b 100644
--- a/core/sql/executor/ExUdr.h
+++ b/core/sql/executor/ExUdr.h
@@ -122,6 +122,18 @@ public:
   {
     return externalPath_;
   }
+  inline const Int64 getLibraryRedefTime() const
+  {
+    return libraryRedefTime_;
+  }
+  inline const char *getLibraryBlobHandle() const
+  {
+    return libraryBlobHandle_;
+  }
+  inline const char *getLibrarySchName() const
+  {
+    return librarySchName_;
+  }
   inline const char *getLibrarySqlName() const
   {
     return librarySqlName_;
@@ -512,7 +524,7 @@ protected:
   // Helper function to send control messages
   //
   NABoolean sendControlMessage(UdrIpcObjectType t,
-                               NABoolean callbackRequired);
+                               NABoolean callbackRequired, char *cachedLibName=NULL, char *cachedLibPath = NULL);
 
   // ---------------------------------------------------------------------
   // Helper functions called by the work method. See comments in the

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/generator/GenUdr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/generator/GenUdr.cpp b/core/sql/generator/GenUdr.cpp
index 96767b3..a31af77 100644
--- a/core/sql/generator/GenUdr.cpp
+++ b/core/sql/generator/GenUdr.cpp
@@ -876,6 +876,11 @@ static short udr_codegen(Generator *generator,
   char *container = NULL;
   char *path = NULL;
   char *librarySqlName = NULL;
+  Int64 libraryRedefTime = NULL;
+  char * libraryBlobHandle;
+  char *librarySchName = NULL;
+  Int32 libraryVersion = 0;
+  Int64 libraryObjUID = 0;
   char *runtimeOptions = NULL;
   char *runtimeOptionDelimiters = NULL;
   ComRoutineType rtype = COM_UNKNOWN_ROUTINE_TYPE;
@@ -941,7 +946,11 @@ static short udr_codegen(Generator *generator,
 
     const ComObjectName &libName = metadata->getLibrarySqlName();
     librarySqlName = AllocStringInSpace(*space, libName.getExternalName());
-    
+    libraryRedefTime = metadata->getLibRedefTime();
+    libraryBlobHandle = AllocStringInSpace (*space,metadata->getLibBlobHandle());
+    librarySchName = AllocStringInSpace(*space,metadata->getLibSchName());
+    libraryVersion = metadata->getLibVersion();
+    libraryObjUID = metadata->getLibObjUID();
     rtype = metadata->getRoutineType();
     sqlmode = metadata->getSqlAccess();
 
@@ -1055,7 +1064,10 @@ static short udr_codegen(Generator *generator,
     container,
     path,
     librarySqlName,
-    
+    libraryRedefTime,
+    libraryBlobHandle,
+    librarySchName,
+    libraryVersion,
     runtimeOptions,
     runtimeOptionDelimiters,
     
@@ -1567,7 +1579,10 @@ IsolatedScalarUDF::codeGen(Generator *generator)
                            NULL);              // TMUDF only
   
   if (effectiveMetadata.getRoutineID() > 0)
-    generator->objectUids().insert(effectiveMetadata.getRoutineID());
+    {
+      generator->objectUids().insert(effectiveMetadata.getRoutineID());
+      generator->objectUids().insert(metadata.getLibObjUID());
+    }
 
   return result;
 }
@@ -1664,7 +1679,10 @@ short CallSP::codeGen(Generator *generator)
                        NULL);               // TMUDF only
 
   if (metadata.getRoutineID() > 0)
-    generator->objectUids().insert(metadata.getRoutineID());
+    {
+      generator->objectUids().insert(metadata.getRoutineID());
+      generator->objectUids().insert(metadata.getLibObjUID());
+    }
 
   return result;
 
@@ -1899,7 +1917,10 @@ PhysicalTableMappingUDF::codeGen(Generator *generator)
   }
 
   if (metadata.getRoutineID() > 0)
-    generator->objectUids().insert(metadata.getRoutineID());
+    {
+      generator->objectUids().insert(metadata.getRoutineID());
+      generator->objectUids().insert(metadata.getLibObjUID());
+    }
 
   return result;
 }

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/generator/Generator.cpp
----------------------------------------------------------------------
diff --git a/core/sql/generator/Generator.cpp b/core/sql/generator/Generator.cpp
index d9e736a..5e43266 100644
--- a/core/sql/generator/Generator.cpp
+++ b/core/sql/generator/Generator.cpp
@@ -2352,6 +2352,14 @@ TrafDesc *Generator::createVirtualRoutineDesc(
    strcpy(routine_desc->routineDesc()->signature, routineInfo->signature);
    routine_desc->routineDesc()->librarySqlName = new GENHEAP(space) char[strlen(routineInfo->library_sqlname)+1];
    strcpy(routine_desc->routineDesc()->librarySqlName, routineInfo->library_sqlname);
+   routine_desc->routineDesc()->libRedefTime = routineInfo->lib_redef_time;
+   routine_desc->routineDesc()->libBlobHandle = routineInfo->lib_blob_handle;
+
+   routine_desc->routineDesc()->libVersion = routineInfo->library_version;
+   routine_desc->routineDesc()->libObjUID = routineInfo->lib_obj_uid;
+   //routine_desc->routineDesc()->libSchName = new GENHEAP(space) char[strlen(routineInfo->lib_sch_name)+1];
+   //strcpy(routine_desc->routineDesc()->libSchName ,routineInfo->lib_sch_name);
+   routine_desc->routineDesc()->libSchName = routineInfo->lib_sch_name;
    routine_desc->routineDesc()->language  = 
            CmGetComRoutineLanguageAsRoutineLanguage(routineInfo->language_type);
    routine_desc->routineDesc()->UDRType  = 

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/optimizer/NARoutine.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/NARoutine.cpp b/core/sql/optimizer/NARoutine.cpp
index 905e374..bfd831b 100644
--- a/core/sql/optimizer/NARoutine.cpp
+++ b/core/sql/optimizer/NARoutine.cpp
@@ -114,6 +114,11 @@ NARoutine::NARoutine (CollHeap *heap)
     , dataSource_             ("", heap)
     , fileSuffix_             ("", heap)
     , schemaVersionOfRoutine_ (COM_VERS_UNKNOWN)
+    , libRedefTime_(0)
+    , libBlobHandle_("",heap)
+    , libSchName_("",heap)
+    , libVersion_(1)
+    , libObjUID_(0)
     , objectOwner_            (0)
     , schemaOwner_            (0)
     , privInfo_               (NULL)
@@ -143,6 +148,11 @@ NARoutine::NARoutine (  const QualifiedName &name
     , externalPath_           ("", heap)
     , externalName_           ("", heap)
     , librarySqlName_         (NULL)
+    , libRedefTime_(-1)
+    , libBlobHandle_("",heap)
+    , libSchName_("",heap)
+    , libVersion_(1)
+    , libObjUID_(0)
     , signature_              ("", heap)
     , paramStyle_             (COM_STYLE_SQLROW)
     , paramStyleVersion_      (COM_ROUTINE_PARAM_STYLE_VERSION_1)
@@ -275,6 +285,11 @@ NARoutine::NARoutine (const NARoutine &old, CollHeap *h)
     , externalName_           (old.externalName_, h)
     , signature_              (old.signature_, h)
     , librarySqlName_         (old.librarySqlName_, h)
+    , libRedefTime_           (old.libRedefTime_)
+    , libBlobHandle_          (old.libBlobHandle_,h)
+    , libSchName_             (old.libSchName_,h)
+    , libVersion_             (old.libVersion_)
+    , libObjUID_              (old.libObjUID_)
     , paramStyle_             (old.paramStyle_)
     , paramStyleVersion_      (old.paramStyleVersion_)
     , isDeterministic_        (old.isDeterministic_)
@@ -357,6 +372,9 @@ NARoutine::NARoutine(const QualifiedName   &name,
     , externalPath_           (routine_desc->routineDesc()->libraryFileName, heap)
     , externalName_           ("", heap)
     , librarySqlName_         (routine_desc->routineDesc()->librarySqlName, COM_UNKNOWN_NAME, FALSE, heap) //TODO
+    , libRedefTime_            (routine_desc->routineDesc()->libRedefTime)
+    , libVersion_             (routine_desc->routineDesc()->libVersion)
+    , libObjUID_              (routine_desc->routineDesc()->libObjUID)
     , signature_              (routine_desc->routineDesc()->signature, heap)
     , paramStyle_             (routine_desc->routineDesc()->paramStyle)
     , paramStyleVersion_      (COM_ROUTINE_PARAM_STYLE_VERSION_1)
@@ -393,6 +411,14 @@ NARoutine::NARoutine(const QualifiedName   &name,
   char parallelism[5];
   CmGetComRoutineParallelismAsLit(routine_desc->routineDesc()->parallelism, parallelism);
   comRoutineParallelism_ = ((char *)parallelism);
+  if (routine_desc->routineDesc()->libBlobHandle)
+    libBlobHandle_   =       NAString(routine_desc->routineDesc()->libBlobHandle,heap);
+  else
+    libBlobHandle_ = NAString();
+  if (routine_desc->routineDesc()->libSchName)
+    libSchName_ = NAString(routine_desc->routineDesc()->libSchName,heap);
+  else
+    libSchName_ = NAString();
 
   if (paramStyle_ == COM_STYLE_JAVA_CALL)
   {

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/optimizer/NARoutine.h
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/NARoutine.h b/core/sql/optimizer/NARoutine.h
index 65aa473..9b536d4 100644
--- a/core/sql/optimizer/NARoutine.h
+++ b/core/sql/optimizer/NARoutine.h
@@ -176,11 +176,20 @@ public:
   inline PrivMgrUserPrivs *              getPrivInfo()    const { return privInfo_; }
   inline Int32                           getObjectOwner() const { return objectOwner_; }
   inline Int32                           getSchemaOwner() const { return schemaOwner_; }
-
+  inline Int64  getLibRedefTime() const {return libRedefTime_;}
+  inline const NAString  &getLibBlobHandle() const {return libBlobHandle_;}
+  inline const NAString  &getLibSchName() const {return libSchName_;}
+  inline Int32 getLibVersion() const {return libVersion_;}
+  inline Int64 getLibObjUID() const {return libObjUID_;}
   inline void  setudfFanOut      (Int32 fanOut)       { udfFanOut_ = fanOut; }
   inline void  setExternalPath   (ComString path)     { externalPath_   = path; }
   inline void  setFile           (ComString file)     { externalFile_   = file; }  
   inline void  setExternalName   (ComString fname)    { externalName_   = fname; } 
+  inline void  setLibRedefTime (Int64 rtime) { libRedefTime_ = rtime;}
+  inline void  setLibBlobHandle(NAString lobHandle)  {libBlobHandle_ = lobHandle;}
+  inline void  setLibVersion(Int32 version) { libVersion_ = version;}
+  inline void  setLibObjUID(Int64 libobjuid) { libObjUID_ = libobjuid;}
+  inline void  setLibSchName(NAString schName)  {libSchName_ = schName;}
   inline void  setLibrarySqlName (ComObjectName lib)  { librarySqlName_   = lib; }
   inline void  setLanguage  (ComRoutineLanguage lang) { language_ = lang; }  
   inline void  setRoutineType    (ComRoutineType typ) { UDRType_ = typ; }  
@@ -247,6 +256,11 @@ private:
   ComString            externalPath_;   // URL
   ComString            externalFile_;
   ComString            externalName_;   // Java method name
+  Int64                libRedefTime_;
+  NAString             libBlobHandle_;
+  NAString             libSchName_;
+  Int32                libVersion_;
+  Int64                libObjUID_;
   ComString            signature_;
   ComObjectName        librarySqlName_;        // ANSI name of JAR/DLL
   ComRoutineParamStyle paramStyle_;

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/optimizer/UdfDllInteraction.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/UdfDllInteraction.cpp b/core/sql/optimizer/UdfDllInteraction.cpp
index 79df4ae..951833d 100644
--- a/core/sql/optimizer/UdfDllInteraction.cpp
+++ b/core/sql/optimizer/UdfDllInteraction.cpp
@@ -46,8 +46,9 @@
 #include "exp_attrs.h"
 #include "LmError.h"
 #include "ComUser.h"
+#include "sys/stat.h"
 
-
+short ExExeUtilLobExtractLibrary(ExeCliInterface *cliInterface,char *libHandle, char *cachedLibName,ComDiagsArea *toDiags);
 // -----------------------------------------------------------------------
 // methods for class TMUDFDllInteraction
 // -----------------------------------------------------------------------
@@ -136,6 +137,64 @@ NABoolean TMUDFDllInteraction::describeParamsAndMaxOutputs(
       bindWA->setErrStatus();
       return FALSE;
     }
+  NAString externalPath, container;
+  
+  // If the library is old style (no blob) and it's not a predfined udf with no entry in metadata
+  // i.e redeftime of library is not -1
+  if(  routine->getLibRedefTime() !=-1)
+    {
+      // Cache library locally. 
+      NAString dummyUser;
+      NAString libOrJarName;
+      NAString cachedLibName,cachedLibPath;  
+      if (routine->getLanguage() == COM_LANGUAGE_JAVA)
+        libOrJarName = routine->getExternalPath();
+      else
+        libOrJarName = routine->getContainerName();
+      if(ComGenerateUdrCachedLibName(libOrJarName.data(),
+                                  routine->getLibRedefTime(),
+                                  routine->getLibSchName(),
+                                  dummyUser,
+                                     cachedLibName, cachedLibPath))
+        {
+           NAString cachedFullName = cachedLibPath+"/"+cachedLibName;
+           *CmpCommon::diags() <<  DgSqlCode(-4316)
+                                  << DgString0(( char *)cachedFullName.data());
+           bindWA->setErrStatus();
+           return FALSE;
+        }
+      
+      NAString cachedFullName = cachedLibPath+"/"+cachedLibName;
+      //If the local copy already exists, don't bother extracting.
+      struct stat statbuf;
+      if (stat(cachedFullName, &statbuf) != 0)
+        {
+          //ComDiagsArea *returnedDiags = ComDiagsArea::allocate(CmpCommon::statementHeap());
+          if (ExExeUtilLobExtractLibrary(&cliInterface_,(char *)routine->getLibBlobHandle().data(), 
+                                         ( char *)cachedFullName.data(),CmpCommon::diags()))
+            {
+              *CmpCommon::diags() <<  DgSqlCode(-4316)
+                                  << DgString0(( char *)cachedFullName.data());
+              bindWA->setErrStatus();
+              return FALSE;
+            }
+        }
+      if  (routine->getLanguage() == COM_LANGUAGE_JAVA)
+        {
+          externalPath = cachedFullName;
+          container = routine->getContainerName();
+        }
+      else
+        {
+          externalPath = cachedLibPath;
+          container = cachedLibName;
+        }
+    }
+  else
+    {
+      externalPath = routine->getExternalPath();
+      container = routine->getContainerName();
+    }
 
   Int32 cliRC = cliInterface_.getRoutine(
        serializedUDRInvocationInfo,
@@ -147,8 +206,8 @@ NABoolean TMUDFDllInteraction::describeParamsAndMaxOutputs(
        routine->getMethodName(),
        // for C/C++ the container that gets loaded is the library file
        // name, for Java it's the class name
-       routine->getContainerName(),
-       routine->getExternalPath(),
+       container,
+       externalPath,
        routine->getLibrarySqlName().getExternalName(),
        &routineHandle,
        CmpCommon::diags());


[4/8] trafodion git commit: Fixees to support stroring Udr libraries s Blobs.

Posted by sa...@apache.org.
http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/regress/executor/EXPECTED130
----------------------------------------------------------------------
diff --git a/core/sql/regress/executor/EXPECTED130 b/core/sql/regress/executor/EXPECTED130
index 506dda2..6aeb277 100644
--- a/core/sql/regress/executor/EXPECTED130
+++ b/core/sql/regress/executor/EXPECTED130
@@ -63,10 +63,12 @@ C1
 C1           C2
 -----------  ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 ----------------------------------------
 
+
           1  LOBH0000000200010189730973312766405019189730973325743020118212400522666936189020"TRAFODION"."LOB130"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
                                         
           2  LOBH0000000200010189730973312766405019189730973325822915418212400522668231546020"TRAFODION"."LOB130"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
                                         
           3  LOBH0000000200010189730973312766405019189730973325854670118212400522668551834020"TRAFODION"."LOB130"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
                                         
 
+
 --- 3 row(s) selected.
 >>
 >>
@@ -668,7 +670,9 @@ And the dish ran away with the fork !
 >>sh grep "^LOBH" TMP130 | sed "s/^/extract lobtofile(LOB '/g" | sed "s/$/' , 'tlob130_txt1.txt');/g" >> t130_extract_command;
 >>
 >>obey t130_extract_command;
+
 >>extract lobtofile(LOB 'LOBH0000000200010189730973312770821219189730973368818826218212400523097801680020"TRAFODION"."LOB130"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                                                     ' , 'tlob130_txt1.txt');
+
 Success. Targetfile :tlob130_txt1.txt  Length : 19
 
 --- SQL operation complete.
@@ -684,7 +688,9 @@ Success. Targetfile :tlob130_txt1.txt  Length : 19
 >>sh rm t130_extract_command;
 >>sh grep "^LOBH" TMP130 | sed "s/^/extract lobtofile(LOB '/g" | sed "s/$/' , 'tlob130_deep.jpg');/g" >> t130_extract_command;
 >>obey t130_extract_command;
+
 >>extract lobtofile(LOB 'LOBH0000000200010189730973312770991919189730973372704796118212400523136699585020"TRAFODION"."LOB130"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                                                     ' , 'tlob130_deep.jpg');
+
 Success. Targetfile :tlob130_deep.jpg  Length : 159018
 
 --- SQL operation complete.
@@ -700,7 +706,9 @@ Success. Targetfile :tlob130_deep.jpg  Length : 159018
 >>sh grep "^LOBH" TMP130 | sed "s/^/extract lobtofile(LOB '/g" | sed "s/$/' , 'tlob130_anoush.jpg');/g" >> t130_extract_command;
 >>
 >>obey t130_extract_command;
+
 >>extract lobtofile(LOB 'LOBH0000000200010189730973312770991919189730973372704796118212400523136699585020"TRAFODION"."LOB130"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                                                     ' , 'tlob130_anoush.jpg');
+
 Success. Targetfile :tlob130_anoush.jpg  Length : 230150
 
 --- SQL operation complete.
@@ -821,7 +829,9 @@ And the dish ran away with the fork !
 >>
 >>sh grep "^LOBH" TMP130 | sed "s/^/extract lobtofile(LOB '/g" | sed "s/$/' , 'hdfs:\/\/\/user\/trafodion\/lobs\/tlob130_txt2.txt');/g" >> t130_extract_command;
 >>obey t130_extract_command;
+
 >>extract lobtofile(LOB 'LOBH0000000200010189730973312772090419189730973379454400718212400523204167938020"TRAFODION"."LOB130"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                                                     ' , 'hdfs:///user/trafodion/lobs/tlob130_txt2.txt');
+
 Success. Targetfile :hdfs:///user/trafodion/lobs/tlob130_txt2.txt  Length : 19
 
 --- SQL operation complete.
@@ -837,7 +847,9 @@ Success. Targetfile :hdfs:///user/trafodion/lobs/tlob130_txt2.txt  Length : 19
 >>sh rm t130_extract_command;
 >>sh grep "^LOBH" TMP130 | sed "s/^/extract lobtofile(LOB '/g" | sed "s/$/' , 'hdfs:\/\/\/user\/trafodion\/lobs\/tlob130_deep.jpg');/g" >> t130_extract_command;
 >>obey t130_extract_command;
+
 >>extract lobtofile(LOB 'LOBH0000000200010189730973312772260419189730973382656270118212400523236180902020"TRAFODION"."LOB130"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                                                     ' , 'hdfs:///user/trafodion/lobs/tlob130_deep.jpg');
+
 Success. Targetfile :hdfs:///user/trafodion/lobs/tlob130_deep.jpg  Length : 159018
 
 --- SQL operation complete.
@@ -853,7 +865,9 @@ Success. Targetfile :hdfs:///user/trafodion/lobs/tlob130_deep.jpg  Length : 1590
 >>sh grep "^LOBH" TMP130 | sed "s/^/extract lobtofile(LOB '/g" | sed "s/$/' , 'hdfs:\/\/\/user\/trafodion\/lobs\/tlob130_anoush.jpg');/g" >> t130_extract_command;
 >>
 >>obey t130_extract_command;
+
 >>extract lobtofile(LOB 'LOBH0000000200010189730973312770991919189730973372704796118212400523136699585020"TRAFODION"."LOB130"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                                                     ' , 'hdfs:///user/trafodion/lobs/tlob130_anoush.jpg');
+
 Success. Targetfile :hdfs:///user/trafodion/lobs/tlob130_anoush.jpg  Length : 230150
 
 --- SQL operation complete.
@@ -872,7 +886,7 @@ Column Name : c2
 Input a filename to extract to : 
 Output File Name : lobc2out.jpg
 Extracting  lob handle for column c2...
-LOB handle for c2: LOBH0000000200010492540128525797109219492540128672143163118212384276675380782020"TRAFODION"."LOB130"
+LOB handle for c2: LOBH000000020001001786226097943372181817862261042772793218212399607632028402020"TRAFODION"."LOB130"
 Extracting LOB data length for the above handle...
 LOB data length :230150
 Extracting lob data into file in chunks ...
@@ -946,7 +960,7 @@ And the dish ran away with the spoon.
 >>sh rm t130_extract_command;
 >>sh grep "^LOBH" TMP130 | sed "s/^/extract lobtofile(LOB '/g" | sed "s/$/' , 'tlob130_deep2.jpg');/g" >> t130_extract_command;
 >>obey t130_extract_command;
->>extract lobtofile(LOB 'LOBH0000000200020492540128525802271019492540128707944124018212384277034197183020"TRAFODION"."LOB130"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                                                     ' , 'tlob130_deep2.jpg');
+>>extract lobtofile(LOB 'LOBH000000020002001786226097943695171817862261069432940218212399607898537297020"TRAFODION"."LOB130"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
                                                     ' , 'tlob130_deep2.jpg');
 Success. Targetfile :tlob130_deep2.jpg  Length : 159018
 
 --- SQL operation complete.
@@ -955,7 +969,9 @@ Success. Targetfile :tlob130_deep2.jpg  Length : 159018
 >>sh rm t130_extract_command;
 >>sh grep "^LOBH" TMP130 | sed "s/^/extract lobtofile(LOB '/g" | sed "s/$/' , 'hdfs:\/\/\/user\/trafodion\/lobs\/tlob130_anoush2.jpg');/g" >> t130_extract_command;
 >>obey t130_extract_command;
+
 >>extract lobtofile(LOB 'LOBH0000000200030189730973312773623919189730973392250459518212400523332159942020"TRAFODION"."LOB130"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                                                     ' , 'hdfs:///user/trafodion/lobs/tlob130_anoush2.jpg');
+
 Success. Targetfile :hdfs:///user/trafodion/lobs/tlob130_anoush2.jpg  Length : 230150
 
 --- SQL operation complete.
@@ -982,7 +998,7 @@ Hey diddle diddle,
 >>sh rm t130_extract_command;
 >>sh grep "^LOBH" TMP130 | sed "s/^/extract lobtofile(LOB '/g" | sed "s/$/' , 'tlob130_anoush3.jpg',create,truncate);/g" >> t130_extract_command;
 >>obey t130_extract_command;
->>extract lobtofile(LOB 'LOBH0000000200030492540128525802824819492540128714305550118212384277098509118020"TRAFODION"."LOB130"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                                                     ' , 'tlob130_anoush3.jpg',create,truncate);
+>>extract lobtofile(LOB 'LOBH000000020003001786226097943740601817862261074243267718212399607946607514020"TRAFODION"."LOB130"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
                                                     ' , 'tlob130_anoush3.jpg',create,truncate);
 Success. Targetfile :tlob130_anoush3.jpg  Length : 230150
 
 --- SQL operation complete.
@@ -1083,12 +1099,12 @@ Lob Information for table: "TRAFODION".LOB130.TLOB130GT2
 
   ColumnName :  C2
   Lob Location :  /user/trafodion/lobs
-  LOB Data File:  LOBP_04925401285258067632_0001
+  LOB Data File:  LOBP_00178622609794394274_0001
   LOB EOD :  0
   LOB Used Len :  0
   ColumnName :  C3
   Lob Location :  /user/trafodion/lobs
-  LOB Data File:  LOBP_04925401285258067632_0002
+  LOB Data File:  LOBP_00178622609794394274_0002
   LOB EOD :  0
   LOB Used Len :  0
   ColumnName :  C4
@@ -1103,8 +1119,8 @@ Lob Information for table: "TRAFODION".LOB130.TLOB130GT2
 CATALOG_NAME                                                                                                                                                                                                                                                      SCHEMA_NAME                                                                                                                                                                                                                                                       OBJECT_NAME                                                                                                                                                                                                                                                       COLUMN_NAME                                                                                                                                                                                                                    
                                    LOB_LOCATION                                                                                                                                                                                                                                                      LOB_DATA_FILE                                                                                                                                                                                                                                                     LOB_DATA_FILE_SIZE_EOD  LOB_DATA_FILE_SIZE_USED
 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 ---------------------------------  ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  ----------------------  -----------------------
 
-TRAFODION                                                                                                                                                                                                                                                         LOB130                                                                                                                                                                                                                                                            TLOB130GT2                                                                                                                                                                                                                                                        C2                                                                                                                                                                                                                             
                                    /user/trafodion/lobs                                                                                                                                                                                                                                              LOBP_04925401285258067632_0001                                                                                                                                                                                                                                                         0                        0
-TRAFODION                                                                                                                                                                                                                                                         LOB130                                                                                                                                                                                                                                                            TLOB130GT2                                                                                                                                                                                                                                                        C3                                                                                                                                                                                                                             
                                    /user/trafodion/lobs                                                                                                                                                                                                                                              LOBP_04925401285258067632_0002                                                                                                                                                                                                                                                         0                        0
+TRAFODION                                                                                                                                                                                                                                                         LOB130                                                                                                                                                                                                                                                            TLOB130GT2                                                                                                                                                                                                                                                        C2                                                                                                                                                                                                                             
                                    /user/trafodion/lobs                                                                                                                                                                                                                                              LOBP_00178622609794394274_0001                                                                                                                                                                                                                                                         0                        0
+TRAFODION                                                                                                                                                                                                                                                         LOB130                                                                                                                                                                                                                                                            TLOB130GT2                                                                                                                                                                                                                                                        C3                                                                                                                                                                                                                             
                                    /user/trafodion/lobs                                                                                                                                                                                                                                              LOBP_00178622609794394274_0002                                                                                                                                                                                                                                                         0                        0
 TRAFODION                                                                                                                                                                                                                                                         LOB130                                                                                                                                                                                                                                                            TLOB130GT2                                                                                                                                                                                                                                                        C4                                                                                                                                                                                                                             
                                    External HDFS Location                                                                                                                                                                                                                                            External HDFS File                                                                                                                                                                                                                                                                     0                        0
 
 --- 3 row(s) selected.
@@ -1125,17 +1141,17 @@ Lob Information for table: "TRAFODION".LOB130.TLOB130GT
 
   ColumnName :  C2
   Lob Location :  /user/trafodion/lobs
-  LOB Data File:  LOBP_04925401285258063762_0001
+  LOB Data File:  LOBP_00178622609794390525_0001
   LOB EOD :  15
   LOB Used Len :  15
   ColumnName :  C3
   Lob Location :  /user/trafodion/lobs
-  LOB Data File:  LOBP_04925401285258063762_0002
+  LOB Data File:  LOBP_00178622609794390525_0002
   LOB EOD :  15
   LOB Used Len :  15
   ColumnName :  C4
   Lob Location :  /user/trafodion/lobs
-  LOB Data File:  LOBP_04925401285258063762_0003
+  LOB Data File:  LOBP_00178622609794390525_0003
   LOB EOD :  45
   LOB Used Len :  45
 
@@ -1145,9 +1161,9 @@ Lob Information for table: "TRAFODION".LOB130.TLOB130GT
 CATALOG_NAME                                                                                                                                                                                                                                                      SCHEMA_NAME                                                                                                                                                                                                                                                       OBJECT_NAME                                                                                                                                                                                                                                                       COLUMN_NAME                                                                                                                                                                                                                    
                                    LOB_LOCATION                                                                                                                                                                                                                                                      LOB_DATA_FILE                                                                                                                                                                                                                                                     LOB_DATA_FILE_SIZE_EOD  LOB_DATA_FILE_SIZE_USED
 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 ---------------------------------  ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  ----------------------  -----------------------
 
-TRAFODION                                                                                                                                                                                                                                                         LOB130                                                                                                                                                                                                                                                            TLOB130GT                                                                                                                                                                                                                                                         C2                                                                                                                                                                                                                             
                                    /user/trafodion/lobs                                                                                                                                                                                                                                              LOBP_04925401285258063762_0001                                                                                                                                                                                                                                                        15                       15
-TRAFODION                                                                                                                                                                                                                                                         LOB130                                                                                                                                                                                                                                                            TLOB130GT                                                                                                                                                                                                                                                         C3                                                                                                                                                                                                                             
                                    /user/trafodion/lobs                                                                                                                                                                                                                                              LOBP_04925401285258063762_0002                                                                                                                                                                                                                                                        15                       15
-TRAFODION                                                                                                                                                                                                                                                         LOB130                                                                                                                                                                                                                                                            TLOB130GT                                                                                                                                                                                                                                                         C4                                                                                                                                                                                                                             
                                    /user/trafodion/lobs                                                                                                                                                                                                                                              LOBP_04925401285258063762_0003                                                                                                                                                                                                                                                        45                       45
+TRAFODION                                                                                                                                                                                                                                                         LOB130                                                                                                                                                                                                                                                            TLOB130GT                                                                                                                                                                                                                                                         C2                                                                                                                                                                                                                             
                                    /user/trafodion/lobs                                                                                                                                                                                                                                              LOBP_00178622609794390525_0001                                                                                                                                                                                                                                                        15                       15
+TRAFODION                                                                                                                                                                                                                                                         LOB130                                                                                                                                                                                                                                                            TLOB130GT                                                                                                                                                                                                                                                         C3                                                                                                                                                                                                                             
                                    /user/trafodion/lobs                                                                                                                                                                                                                                              LOBP_00178622609794390525_0002                                                                                                                                                                                                                                                        15                       15
+TRAFODION                                                                                                                                                                                                                                                         LOB130                                                                                                                                                                                                                                                            TLOB130GT                                                                                                                                                                                                                                                         C4                                                                                                                                                                                                                             
                                    /user/trafodion/lobs                                                                                                                                                                                                                                              LOBP_00178622609794390525_0003                                                                                                                                                                                                                                                        45                       45
 
 --- 3 row(s) selected.
 >>delete from tlob130gt where c1=2;
@@ -1164,17 +1180,17 @@ Lob Information for table: "TRAFODION".LOB130.TLOB130GT
 
   ColumnName :  C2
   Lob Location :  /user/trafodion/lobs
-  LOB Data File:  LOBP_04925401285258063762_0001
+  LOB Data File:  LOBP_00178622609794390525_0001
   LOB EOD :  30
   LOB Used Len :  25
   ColumnName :  C3
   Lob Location :  /user/trafodion/lobs
-  LOB Data File:  LOBP_04925401285258063762_0002
+  LOB Data File:  LOBP_00178622609794390525_0002
   LOB EOD :  31
   LOB Used Len :  26
   ColumnName :  C4
   Lob Location :  /user/trafodion/lobs
-  LOB Data File:  LOBP_04925401285258063762_0003
+  LOB Data File:  LOBP_00178622609794390525_0003
   LOB EOD :  71
   LOB Used Len :  56
 
@@ -1184,9 +1200,9 @@ Lob Information for table: "TRAFODION".LOB130.TLOB130GT
 CATALOG_NAME                                                                                                                                                                                                                                                      SCHEMA_NAME                                                                                                                                                                                                                                                       OBJECT_NAME                                                                                                                                                                                                                                                       COLUMN_NAME                                                                                                                                                                                                                    
                                    LOB_LOCATION                                                                                                                                                                                                                                                      LOB_DATA_FILE                                                                                                                                                                                                                                                     LOB_DATA_FILE_SIZE_EOD  LOB_DATA_FILE_SIZE_USED
 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 ---------------------------------  ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  ----------------------  -----------------------
 
-TRAFODION                                                                                                                                                                                                                                                         LOB130                                                                                                                                                                                                                                                            TLOB130GT                                                                                                                                                                                                                                                         C2                                                                                                                                                                                                                             
                                    /user/trafodion/lobs                                                                                                                                                                                                                                              LOBP_04925401285258063762_0001                                                                                                                                                                                                                                                        30                       25
-TRAFODION                                                                                                                                                                                                                                                         LOB130                                                                                                                                                                                                                                                            TLOB130GT                                                                                                                                                                                                                                                         C3                                                                                                                                                                                                                             
                                    /user/trafodion/lobs                                                                                                                                                                                                                                              LOBP_04925401285258063762_0002                                                                                                                                                                                                                                                        31                       26
-TRAFODION                                                                                                                                                                                                                                                         LOB130                                                                                                                                                                                                                                                            TLOB130GT                                                                                                                                                                                                                                                         C4                                                                                                                                                                                                                             
                                    /user/trafodion/lobs                                                                                                                                                                                                                                              LOBP_04925401285258063762_0003                                                                                                                                                                                                                                                        71                       56
+TRAFODION                                                                                                                                                                                                                                                         LOB130                                                                                                                                                                                                                                                            TLOB130GT                                                                                                                                                                                                                                                         C2                                                                                                                                                                                                                             
                                    /user/trafodion/lobs                                                                                                                                                                                                                                              LOBP_00178622609794390525_0001                                                                                                                                                                                                                                                        30                       25
+TRAFODION                                                                                                                                                                                                                                                         LOB130                                                                                                                                                                                                                                                            TLOB130GT                                                                                                                                                                                                                                                         C3                                                                                                                                                                                                                             
                                    /user/trafodion/lobs                                                                                                                                                                                                                                              LOBP_00178622609794390525_0002                                                                                                                                                                                                                                                        31                       26
+TRAFODION                                                                                                                                                                                                                                                         LOB130                                                                                                                                                                                                                                                            TLOB130GT                                                                                                                                                                                                                                                         C4                                                                                                                                                                                                                             
                                    /user/trafodion/lobs                                                                                                                                                                                                                                              LOBP_00178622609794390525_0003                                                                                                                                                                                                                                                        71                       56
 
 --- 3 row(s) selected.
 >>
@@ -1217,6 +1233,7 @@ TRAFODION
 >>sh rm t130_extract_command;
 >>sh grep "^LOBH" TMP130 | sed "s/^/extract name(LOB '/g" | sed "s/$/');/g" >> t130_extract_command;
 >>obey t130_extract_command;
+
 >>extract name(LOB 'LOBH0000000200020189730973312776402419189730973430096815918212400523710965517020"TRAFODION"."LOB130"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                ');
  LOB filename : /user/trafodion/lobs/LOBP_01897309733127764024_0002
 
@@ -1225,6 +1242,7 @@ TRAFODION
 >>sh grep "^LOBH" TMP130 | sed "s/^/extract offset(LOB '/g" | sed "s/$/');/g" >> t130_extract_command;
 >>obey t130_extract_command;
 >>extract offset(LOB 'LOBH0000000200020189730973312776402419189730973430096815918212400523710965517020"TRAFODION"."LOB130"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
                                                  ');
+
  LOB Offset : 43
 
 --- SQL operation complete.
@@ -1377,12 +1395,12 @@ Lob Information for table: "TRAFODION".LOB130.TLOB130EXT
 
   ColumnName :  C2
   Lob Location :  /user/trafodion/lobs
-  LOB Data File:  LOBP_04925401285258083086_0001
+  LOB Data File:  LOBP_00178622609794405852_0001
   LOB EOD :  70
   LOB Used Len :  42
   ColumnName :  C3
   Lob Location :  /user/trafodion/lobs
-  LOB Data File:  LOBP_04925401285258083086_0002
+  LOB Data File:  LOBP_00178622609794405852_0002
   LOB EOD :  125
   LOB Used Len :  68
   ColumnName :  C4
@@ -1397,8 +1415,8 @@ Lob Information for table: "TRAFODION".LOB130.TLOB130EXT
 CATALOG_NAME                                                                                                                                                                                                                                                      SCHEMA_NAME                                                                                                                                                                                                                                                       OBJECT_NAME                                                                                                                                                                                                                                                       COLUMN_NAME                                                                                                                                                                                                                    
                                    LOB_LOCATION                                                                                                                                                                                                                                                      LOB_DATA_FILE                                                                                                                                                                                                                                                     LOB_DATA_FILE_SIZE_EOD  LOB_DATA_FILE_SIZE_USED
 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 ---------------------------------  ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  ----------------------  -----------------------
 
-TRAFODION                                                                                                                                                                                                                                                         LOB130                                                                                                                                                                                                                                                            TLOB130EXT                                                                                                                                                                                                                                                        C2                                                                                                                                                                                                                             
                                    /user/trafodion/lobs                                                                                                                                                                                                                                              LOBP_04925401285258083086_0001                                                                                                                                                                                                                                                        70                       42
-TRAFODION                                                                                                                                                                                                                                                         LOB130                                                                                                                                                                                                                                                            TLOB130EXT                                                                                                                                                                                                                                                        C3                                                                                                                                                                                                                             
                                    /user/trafodion/lobs                                                                                                                                                                                                                                              LOBP_04925401285258083086_0002                                                                                                                                                                                                                                                       125                       68
+TRAFODION                                                                                                                                                                                                                                                         LOB130                                                                                                                                                                                                                                                            TLOB130EXT                                                                                                                                                                                                                                                        C2                                                                                                                                                                                                                             
                                    /user/trafodion/lobs                                                                                                                                                                                                                                              LOBP_00178622609794405852_0001                                                                                                                                                                                                                                                        70                       42
+TRAFODION                                                                                                                                                                                                                                                         LOB130                                                                                                                                                                                                                                                            TLOB130EXT                                                                                                                                                                                                                                                        C3                                                                                                                                                                                                                             
                                    /user/trafodion/lobs                                                                                                                                                                                                                                              LOBP_00178622609794405852_0002                                                                                                                                                                                                                                                       125                       68
 TRAFODION                                                                                                                                                                                                                                                         LOB130                                                                                                                                                                                                                                                            TLOB130EXT                                                                                                                                                                                                                                                        C4                                                                                                                                                                                                                             
                                    External HDFS Location                                                                                                                                                                                                                                            External HDFS File                                                                                                                                                                                                                                                                     0                        0
 
 --- 3 row(s) selected.
@@ -1415,7 +1433,7 @@ Column Name : c4
 Input a filename to extract to : 
 Output File Name : lobc4ext.txt
 Extracting  lob handle for column c4...
-LOB handle for c4: LOBH0000000800030492540128525808308619492540128786993345718212384277825571287020"TRAFODION"."LOB130"
+LOB handle for c4: LOBH000000080003001786226097944058521817862261119125928418212399608396514208020"TRAFODION"."LOB130"
 Extracting LOB data length for the above handle...
 LOB data length :19
 Extracting lob data into file in chunks ...
@@ -1481,7 +1499,7 @@ Table name : TRAFODION.LOB130.t130lob5
 Input lob column name to get handle from :
 Column Name : c2
 Extracting  lob handle for column c2...
-LOB handle for c2: LOBH0000000200010492540128525814570219492540128830098955718212384278256374414020"TRAFODION"."LOB130"
+LOB handle for c2: LOBH000000020001001786226097944338431817862261132439379818212399608528506845020"TRAFODION"."LOB130"
 >>select lobtostring(c2,20) from t130lob5;
 
 (EXPR)              
@@ -1498,7 +1516,7 @@ Table name : TRAFODION.LOB130.t130lob5
 Input lob column name to get handle from :
 Column Name : c2
 Extracting  lob handle for column c2...
-LOB handle for c2: LOBH0000000200010492540128525814570219492540128830098955718212384278256374414020"TRAFODION"."LOB130"
+LOB handle for c2: LOBH000000020001001786226097944338431817862261132439379818212399608528506845020"TRAFODION"."LOB130"
 >>select lobtostring(c2,40) from t130lob5;
 
 (EXPR)                                  
@@ -1515,7 +1533,7 @@ Table name : TRAFODION.LOB130.t130lob5
 Input lob column name to get handle from :
 Column Name : c2
 Extracting  lob handle for column c2...
-LOB handle for c2: LOBH0000000200010492540128525814570219492540128830098955718212384278256374414020"TRAFODION"."LOB130"
+LOB handle for c2: LOBH000000020001001786226097944338431817862261132439379818212399608528506845020"TRAFODION"."LOB130"
 >>select lobtostring(c2,20) from t130lob5;
 
 (EXPR)              
@@ -1532,7 +1550,7 @@ Table name : TRAFODION.LOB130.t130lob5
 Input lob column name to get handle from :
 Column Name : c2
 Extracting  lob handle for column c2...
-LOB handle for c2: LOBH0000000200010492540128525814570219492540128830098955718212384278256374414020"TRAFODION"."LOB130"
+LOB handle for c2: LOBH000000020001001786226097944338431817862261132439379818212399608528506845020"TRAFODION"."LOB130"
 >>select lobtostring(c2,40) from t130lob5;
 
 (EXPR)                                  
@@ -1559,7 +1577,7 @@ zzzzzzzzzzzzzzzzzzzz
 C2
 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 ---------------------------
 
-LOBH0000000200010492540128525808308619492540128846057880518212384278416137106020"TRAFODION"."LOB130"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
                            
+LOBH000000020001001786226097944058521817862261143587581118212399608641118580020"TRAFODION"."LOB130"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
                            
 
 --- 1 row(s) selected.
 >>-- following should return error since only external lobs will be allowed
@@ -1602,9 +1620,9 @@ LOBH0000000200010492540128525808308619492540128846057880518212384278416137106020
 Tables in Schema TRAFODION.LOBSCH
 =================================
 
-LOBDescChunks__04925401285258169438_0001
-LOBDescHandle__04925401285258169438_0001
-LOBMD__04925401285258169438
+LOBDescChunks__00178622609794451968_0001
+LOBDescHandle__00178622609794451968_0001
+LOBMD__00178622609794451968
 SB_HISTOGRAMS
 SB_HISTOGRAM_INTERVALS
 SB_PERSISTENT_SAMPLES

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/regress/tools/rgrCleanup
----------------------------------------------------------------------
diff --git a/core/sql/regress/tools/rgrCleanup b/core/sql/regress/tools/rgrCleanup
new file mode 100755
index 0000000..452a6ec
--- /dev/null
+++ b/core/sql/regress/tools/rgrCleanup
@@ -0,0 +1,4 @@
+#temp solution to cleanup udr cached files
+#can be removed when cleanup mechanism for cached files in implemented
+echo "rm -rf $TRAF_HOME/udr/$MY_UDR_CACHE_LIBDIR/* 2>$NULL"
+rm -rf $TRAF_HOME/udr/$MY_UDR_CACHE_LIBDIR/* 2>$NULL

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/regress/tools/runregr
----------------------------------------------------------------------
diff --git a/core/sql/regress/tools/runregr b/core/sql/regress/tools/runregr
index 820531b..4c497e9 100755
--- a/core/sql/regress/tools/runregr
+++ b/core/sql/regress/tools/runregr
@@ -320,6 +320,8 @@ if [ "$REGREXCLUSIVE" -ne 0 ]; then
   fi
 fi
 
+export REGR_POSTOP="$scriptsdir/tools/rgrCleanup"
+echo $REGR_POSTOP
 $REGR_POSTOP		# you can set this envvar to any command you like
 			# e.g.  export REGR_POSTOP="$HOME/bin/rgrCleanup"
 echo "***** Done running regressions *****"

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/regress/udr/EXPECTED001
----------------------------------------------------------------------
diff --git a/core/sql/regress/udr/EXPECTED001 b/core/sql/regress/udr/EXPECTED001
index adcf75e..99607f0 100644
--- a/core/sql/regress/udr/EXPECTED001
+++ b/core/sql/regress/udr/EXPECTED001
@@ -43,7 +43,12 @@
 --- 4 row(s) inserted.
 >>
 >>-- for now use VARCHARs for LOBs
->>--cqd TRAF_BLOB_AS_VARCHAR 'OFF'; 
+>>cqd TRAF_BLOB_AS_VARCHAR 'ON';
+
+--- SQL operation complete.
+>>cqd TRAF_CLOB_AS_VARCHAR 'ON';
+
+--- SQL operation complete.
 >>
 >>create table t001_Datatypes (
 +>c_char char(15),
@@ -183,7 +188,6 @@
 +>library TEST001_Java;
 
 --- SQL operation complete.
->>
 >>-- negative test case, the entry point SESSIONIZE_ERR does not exist
 >>create table_mapping function sessionize_err(dummy char(10))
 +>returns (session_id largeint)
@@ -191,10 +195,10 @@
 +>language cpp
 +>library TEST001;
 
-*** ERROR[11246] An error occurred locating function or class 'SESSIONIZE_NON_EXISTENT' in library 'TEST001.dll'.
+*** ERROR[11246] An error occurred locating function or class 'SESSIONIZE_NON_EXISTENT' in library 'TEST001_212404320583911835.dll'.
 
 *** ERROR[11248] A call to dlsym returned errors 0 and 0. Details: 
-/mnt2/ansharma/ansharma_bool/incubator-trafodion/core/sqf/rundir/udr/TEST001.dll: undefined symbol: SESSIONIZE_NON_EXISTENT.
+/mnt3/sandhyasun/trafodion/core/sqf/udr/cached_libs/SCH/TEST001_212404320583911835.dll: undefined symbol: SESSIONIZE_NON_EXISTENT.
 
 --- SQL operation failed with errors.
 >>-- For now this will succeed, since we don't load the library during
@@ -358,10 +362,10 @@ CREATE TABLE_MAPPING FUNCTION TRAFODION.SCH.SESSIONIZE_JAVA
 SESSION_ID            SEQUENCE_NO           USERID                            TS                    IPADDR
 --------------------  --------------------  --------------------------------  --------------------  ---------------
 
-                   1                     1  super-user                          212365360799500000  12.345.567.345 
-                   2                     1  super-user                          212365367999500000  12.345.567.345 
-                   2                     2  super-services                      212365367999500000  12.345.567.345 
-                   2                     3  super-services                      212365367999550000  12.345.567.345 
+                   1                     1  super-user                          212404327199500000  12.345.567.345 
+                   2                     1  super-user                          212404334399500000  12.345.567.345 
+                   2                     2  super-services                      212404334399500000  12.345.567.345 
+                   2                     3  super-services                      212404334399550000  12.345.567.345 
 
 --- 4 row(s) selected.
 >>
@@ -427,7 +431,7 @@ LC   RC   OP   OPERATOR              OPT       DESCRIPTION           CARD
 SESSION_ID            SEQUENCE_NO           USERID                            TS                    IPADDR
 --------------------  --------------------  --------------------------------  --------------------  ---------------
 
-                   1                     1  super-user                          212334861599500000  12.345.567.345 
+                   1                     1  super-user                          212404327199500000  12.345.567.345 
 
 --- 1 row(s) selected.
 >>
@@ -525,7 +529,7 @@ IPADDR           SESSION_ID            SEQUENCE_NO
 SESSION_ID            SEQUENCE_NO           USERID                            TS                    IPADDR
 --------------------  --------------------  --------------------------------  --------------------  ---------------
 
-                   1                     1  super-user                          212373741599500000  12.345.567.345 
+                   1                     1  super-user                          212404327199500000  12.345.567.345 
 
 --- 1 row(s) selected.
 >>

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/regress/udr/EXPECTED103
----------------------------------------------------------------------
diff --git a/core/sql/regress/udr/EXPECTED103 b/core/sql/regress/udr/EXPECTED103
index 0d471f6..5941b79 100644
--- a/core/sql/regress/udr/EXPECTED103
+++ b/core/sql/regress/udr/EXPECTED103
@@ -166,7 +166,7 @@
 
 --- SQL operation complete.
 >>showddl library functionsForTest103;
-CREATE LIBRARY TRAFODION.UDR103SCH.FUNCTIONSFORTEST103 FILE '/mnt2/ansharma/ansharma_trafr21/incubator-trafodion/core/sqf/rundir/udr/TEST103_functions.dll'
+CREATE LIBRARY TRAFODION.UDR103SCH.FUNCTIONSFORTEST103 FILE 'TEST103_functions.dll'
 ;
 
 -- GRANT UPDATE, USAGE ON LIBRARY TRAFODION.UDR103SCH.FUNCTIONSFORTEST103 TO DB__ROOT WITH GRANT OPTION;
@@ -296,18 +296,18 @@ A       R1           R2              R3
 >>-- try to drop libraries - should fail
 >>drop library functionsForTest103;
 
-*** ERROR[1366] Request failed.  One or more dependent procedures exist.
+*** ERROR[1366] Request failed. One or more dependent procedures exist.
 
 --- SQL operation failed with errors.
 >>drop library procsForTest103;
 
-*** ERROR[1366] Request failed.  One or more dependent procedures exist.
+*** ERROR[1366] Request failed. One or more dependent procedures exist.
 
 --- SQL operation failed with errors.
 >>
 >>-- make sure query invalidation works when dropping routines and libraries
 >>showddl library functionsForTest103;
-CREATE LIBRARY TRAFODION.UDR103SCH.FUNCTIONSFORTEST103 FILE '/mnt2/ansharma/ansharma_trafr21/incubator-trafodion/core/sqf/rundir/udr/TEST103_functions.dll'
+CREATE LIBRARY TRAFODION.UDR103SCH.FUNCTIONSFORTEST103 FILE 'TEST103_functions.dll'
 ;
 
 -- GRANT UPDATE, USAGE ON LIBRARY TRAFODION.UDR103SCH.FUNCTIONSFORTEST103 TO DB__ROOT WITH GRANT OPTION;
@@ -418,7 +418,7 @@ CREATE PROCEDURE TRAFODION.UDR103SCH.UPDATESUBSCRIPTIONS
 
 --- SQL operation complete.
 >>showddl library functionsForTest103;
-CREATE LIBRARY TRAFODION.UDR103SCH.FUNCTIONSFORTEST103 FILE '/mnt2/ansharma/ansharma_trafr21/incubator-trafodion/core/sqf/rundir/udr/TEST103_functions.dll'
+CREATE LIBRARY TRAFODION.UDR103SCH.FUNCTIONSFORTEST103 FILE 'TEST103_functions.dll'
 ;
 
 -- GRANT UPDATE, USAGE ON LIBRARY TRAFODION.UDR103SCH.FUNCTIONSFORTEST103 TO DB__ROOT WITH GRANT OPTION;

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/regress/udr/EXPECTED108
----------------------------------------------------------------------
diff --git a/core/sql/regress/udr/EXPECTED108 b/core/sql/regress/udr/EXPECTED108
index 5263730..091ae56 100644
--- a/core/sql/regress/udr/EXPECTED108
+++ b/core/sql/regress/udr/EXPECTED108
@@ -46,10 +46,10 @@
 +>external name 'SESSIONIZE'
 +>library TEST108;
 
-*** ERROR[11246] An error occurred locating function or class 'SESSIONIZE' in library 'TEST002.dll'.
+*** ERROR[11246] An error occurred locating function or class 'SESSIONIZE' in library 'TEST002_212404327644014105.dll'.
 
 *** ERROR[11248] A call to dlsym returned errors 0 and 0. Details: 
-/home/centos/ansharma_trafr21/incubator-trafodion/core/sqf/rundir/udr/TEST002.dll: undefined symbol: SESSIONIZE.
+/mnt3/sandhyasun/trafodion/core/sqf/udr/cached_libs/SCH/TEST002_212404327644014105.dll: undefined symbol: SESSIONIZE.
 
 --- SQL operation failed with errors.
 >>

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/regress/udr/FILTER001
----------------------------------------------------------------------
diff --git a/core/sql/regress/udr/FILTER001 b/core/sql/regress/udr/FILTER001
index 283c153..4598093 100755
--- a/core/sql/regress/udr/FILTER001
+++ b/core/sql/regress/udr/FILTER001
@@ -21,6 +21,6 @@
 # @@@ END COPYRIGHT @@@
 
 sed "
-s#[^ ]*/TEST001.dll#dir/TEST001.dll#g
+s/^\/\([[:graph:]]*\/\)*/#udr_cached_lib_dir#\//g
 s/212[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]/#JULIANTIMESTAMP#/g
 " "$1"

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/regress/udr/FILTER108
----------------------------------------------------------------------
diff --git a/core/sql/regress/udr/FILTER108 b/core/sql/regress/udr/FILTER108
index c42af27..4598093 100755
--- a/core/sql/regress/udr/FILTER108
+++ b/core/sql/regress/udr/FILTER108
@@ -21,6 +21,6 @@
 # @@@ END COPYRIGHT @@@
 
 sed "
-s#[^ ]*/TEST002.dll#dir/TEST002.dll#g
+s/^\/\([[:graph:]]*\/\)*/#udr_cached_lib_dir#\//g
 s/212[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]/#JULIANTIMESTAMP#/g
 " "$1"


[7/8] trafodion git commit: iChanges based on review comments

Posted by sa...@apache.org.
iChanges based on review comments


Project: http://git-wip-us.apache.org/repos/asf/trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafodion/commit/d82d650e
Tree: http://git-wip-us.apache.org/repos/asf/trafodion/tree/d82d650e
Diff: http://git-wip-us.apache.org/repos/asf/trafodion/diff/d82d650e

Branch: refs/heads/master
Commit: d82d650eeb6c67fc1da622225a24c6b10cdbcb97
Parents: fab3c41
Author: Sandhya Sundaresan <sa...@apache.org>
Authored: Wed Oct 17 04:34:13 2018 +0000
Committer: Sandhya Sundaresan <sa...@apache.org>
Committed: Wed Oct 17 04:34:13 2018 +0000

----------------------------------------------------------------------
 core/sqf/sqenvcom.sh                      |   6 +-
 core/sqf/sql/scripts/genms                |   8 +-
 core/sql/cli/sqlcli.h                     |   2 +-
 core/sql/common/ComMisc.cpp               |  59 +++++-----
 core/sql/common/ComMisc.h                 |   2 +-
 core/sql/executor/ExExeUtilLoad.cpp       |   2 +-
 core/sql/executor/ExUdr.cpp               |  14 ++-
 core/sql/optimizer/UdfDllInteraction.cpp  |  10 +-
 core/sql/regress/tools/rgrCleanup         |   4 +-
 core/sql/sqlcat/TrafDDLdesc.cpp           |   2 +
 core/sql/sqlcomp/CmpDDLCatErrorCodes.h    |   3 +-
 core/sql/sqlcomp/CmpSeabaseDDL.h          |   3 +-
 core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp  |   5 -
 core/sql/sqlcomp/CmpSeabaseDDLroutine.cpp | 142 +------------------------
 core/sql/sqlcomp/CmpSeabaseDDLupgrade.cpp |   5 +-
 15 files changed, 70 insertions(+), 197 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafodion/blob/d82d650e/core/sqf/sqenvcom.sh
----------------------------------------------------------------------
diff --git a/core/sqf/sqenvcom.sh b/core/sqf/sqenvcom.sh
index 804e03f..7cb9fd5 100644
--- a/core/sqf/sqenvcom.sh
+++ b/core/sqf/sqenvcom.sh
@@ -113,10 +113,10 @@ export MAKEFLAGS="-j$cpucnt"
 if [ -z "$TOOLSDIR" ]; then
   if [[ -n "$CLUSTERNAME" ]]; then
     export TOOLSDIR=${TOOLSDIR:-/home/tools}
-    export MY_UDR_ROOT=/home/udr
+    export UDR_ROOT=/home/udr
   else
     export TOOLSDIR=${TOOLSDIR:-/opt/home/tools}
-    export MY_UDR_ROOT=$PWD
+    export UDR_ROOT=$PWD
   fi
 fi
 
@@ -207,7 +207,7 @@ export DTM_COMMON_JAR=trafodion-dtm-cdh-${TRAFODION_VER}.jar
 export SQL_JAR=trafodion-sql-cdh-${TRAFODION_VER}.jar
 export UTIL_JAR=trafodion-utility-${TRAFODION_VER}.jar
 export JDBCT4_JAR=jdbcT4-${TRAFODION_VER}.jar
-export MY_UDR_CACHE_LIBDIR=cached_libs
+export UDR_CACHE_LIBDIR=cached_libs
 
 
 if [[ "$HBASE_DISTRO" == "HDP" ]]; then

http://git-wip-us.apache.org/repos/asf/trafodion/blob/d82d650e/core/sqf/sql/scripts/genms
----------------------------------------------------------------------
diff --git a/core/sqf/sql/scripts/genms b/core/sqf/sql/scripts/genms
index 794e2e2..de66199 100755
--- a/core/sqf/sql/scripts/genms
+++ b/core/sqf/sql/scripts/genms
@@ -168,22 +168,22 @@ echo "SQ_PROPS_TDM_ARKESP=tdm_arkesp.env"
 echo ""
 echo "STFS_HDD_LOCATION=\$TRAF_VAR"
 echo ""
-echo "#setting MY_UDR_ROOT"
+echo "#setting UDR_ROOT"
 if [ -d "/home/udr" ]; then
   w=`whoami`
   dircreate=/home/udr/$w
   if [ ! -d $dircreate ]; then
     mkdir --mode=775 $dircreate 2>/dev/null
   fi
-  echo "MY_UDR_ROOT=$dircreate"
+  echo "UDR_ROOT=$dircreate"
 else
   if [ ! -d "$TRAF_HOME/udr" ]; then
     mkdir $TRAF_HOME/udr 2>/dev/null
   fi
-  echo "MY_UDR_ROOT=\$TRAF_HOME/udr"
+  echo "UDR_ROOT=\$TRAF_HOME/udr"
 fi
 
-echo "MY_UDR_CACHE_LIBDIR=cached_libs"
+echo "UDR_CACHE_LIBDIR=cached_libs"
 
 echo ""
 echo "#creating sqllogs folder for capturing osim data"

http://git-wip-us.apache.org/repos/asf/trafodion/blob/d82d650e/core/sql/cli/sqlcli.h
----------------------------------------------------------------------
diff --git a/core/sql/cli/sqlcli.h b/core/sql/cli/sqlcli.h
index d01048e..8f8dd42 100644
--- a/core/sql/cli/sqlcli.h
+++ b/core/sql/cli/sqlcli.h
@@ -1,4 +1,4 @@
-/*********************************************************************y
+/*********************************************************************
 // @@@ START COPYRIGHT @@@
 //
 // Licensed to the Apache Software Foundation (ASF) under one

http://git-wip-us.apache.org/repos/asf/trafodion/blob/d82d650e/core/sql/common/ComMisc.cpp
----------------------------------------------------------------------
diff --git a/core/sql/common/ComMisc.cpp b/core/sql/common/ComMisc.cpp
index baa3a00..3ea50d5 100644
--- a/core/sql/common/ComMisc.cpp
+++ b/core/sql/common/ComMisc.cpp
@@ -372,7 +372,8 @@ Int32  ComGenerateUdrCachedLibName(NAString libname,Int64 redeftime, NAString sc
       libPrefix = libname(0,lastDot);
     }
  
-  //when isolated user support is added   
+  //when isolated user support is added we will pass an actual userid.
+  //By default we assume DB__ROOT.
   if (userid.length()!=0)       
     {
 
@@ -382,17 +383,7 @@ Int32  ComGenerateUdrCachedLibName(NAString libname,Int64 redeftime, NAString sc
          {
            if (mkdir(cachedLibPath,S_IRWXU|S_IRWXG|S_IRWXO))
              {
-               return -1;
-             }
-               
-         }
-      cachedLibPath += "/";
-      cachedLibPath += getenv("MY_UDR_CACHE_LIBDIR");
-      if ( stat(cachedLibPath, &statbuf) != 0)
-         {
-           if (mkdir(cachedLibPath,S_IRWXU|S_IRWXG|S_IRWXO))
-             {
-               return -1;
+               return errno;
              }
                
          }
@@ -402,61 +393,73 @@ Int32  ComGenerateUdrCachedLibName(NAString libname,Int64 redeftime, NAString sc
           if (mkdir(cachedLibPath,S_IRUSR|S_IWUSR|S_IXUSR))//Only this user has 
             //permission to read/write/execute in this directory and below.
             {
-              return -1;
+              return errno;
             }
                
         }
-      cachedLibPath += "/" + schemaName;
+      cachedLibPath += "/";
+      cachedLibPath += getenv("UDR_CACHE_LIBDIR");
       if ( stat(cachedLibPath, &statbuf) != 0)
          {
            if (mkdir(cachedLibPath,S_IRWXU|S_IRWXG|S_IRWXO))
              {
-               return -1;
+               return errno;
              }
                
          }
      
-      
-    }
-  else
-    {
-      cachedLibPath = getenv("TRAF_HOME") ;
-      cachedLibPath += "/udr";
+      cachedLibPath += "/" + schemaName;
       if ( stat(cachedLibPath, &statbuf) != 0)
          {
            if (mkdir(cachedLibPath,S_IRWXU|S_IRWXG|S_IRWXO))
              {
-               return -1;
+               return errno;
              }
                
          }
-      cachedLibPath += "/";
-      cachedLibPath += getenv("MY_UDR_CACHE_LIBDIR");
+     
+      
+    }
+  else
+    {
+      cachedLibPath = getenv("TRAF_HOME") ;
+      cachedLibPath += "/udr";
       if ( stat(cachedLibPath, &statbuf) != 0)
          {
            if (mkdir(cachedLibPath,S_IRWXU|S_IRWXG|S_IRWXO))
              {
-               return -1;
+               return errno;
              }
                
          }
       cachedLibPath +=  "/"+ NAString("DB__ROOT") ;
       if (stat(cachedLibPath, &statbuf) != 0)
         {
-          if (mkdir(cachedLibPath,S_IRWXU|S_IRWXG|S_IRWXO)) // these permissions
+          if (mkdir(cachedLibPath,S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)) // these permissions
             //need to change when we have isolated user support so only DB_ROOT 
             //can access this directory. Right now we allow all to access this directory
             {
-              return -1;
+              return errno;
             }
                
         }
+      cachedLibPath += "/";
+      cachedLibPath += getenv("UDR_CACHE_LIBDIR");
+      if ( stat(cachedLibPath, &statbuf) != 0)
+         {
+           if (mkdir(cachedLibPath,S_IRWXU|S_IRWXG|S_IRWXO))
+             {
+               return errno;
+             }
+               
+         }
+    
       cachedLibPath += "/" + schemaName;
       if ( stat(cachedLibPath, &statbuf) != 0)
          {
            if (mkdir(cachedLibPath,S_IRWXU|S_IRWXG|S_IRWXO))
              {
-               return -1;
+               return errno;
              }
                
          }

http://git-wip-us.apache.org/repos/asf/trafodion/blob/d82d650e/core/sql/common/ComMisc.h
----------------------------------------------------------------------
diff --git a/core/sql/common/ComMisc.h b/core/sql/common/ComMisc.h
index 7b1cebb..d13832e 100644
--- a/core/sql/common/ComMisc.h
+++ b/core/sql/common/ComMisc.h
@@ -113,7 +113,7 @@ NAString ComConvertTrafHiveNameToNativeHiveName(
 NABoolean ComTrafReservedColName(const NAString &colName);
 
 // Converts a library name like myfile.jar or myfile.so to this format
-// $TRAF_HOME/$MY_UDR_CACHE_LIBDIR/<user>|public/myfile_<redeftime>.jar|so 
+// $TRAF_HOME/$UDR_CACHE_LIBDIR/<user>|myfile_<redeftime>.jar|so 
 Int32 ComGenerateUdrCachedLibName(NAString libname,Int64 redeftime,NAString schemaName, NAString user, NAString&cachedLibName, NAString &cachedPathName );
 
 

http://git-wip-us.apache.org/repos/asf/trafodion/blob/d82d650e/core/sql/executor/ExExeUtilLoad.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtilLoad.cpp b/core/sql/executor/ExExeUtilLoad.cpp
index ff4564b..436f2d2 100644
--- a/core/sql/executor/ExExeUtilLoad.cpp
+++ b/core/sql/executor/ExExeUtilLoad.cpp
@@ -3291,7 +3291,7 @@ short ExExeUtilLobExtractTcb::work()
 
 short ExExeUtilLobExtractLibrary(ExeCliInterface *cliInterface,char *libHandle, char *cachedLibName,ComDiagsArea *toDiags)
 {
-  char buf[1000];
+  char buf[strlen(cachedLibName) + strlen(libHandle)+200];
   Int32 cliRC =0;
   str_sprintf(buf, "extract lobtofile(LOB '%s','%s');",libHandle,cachedLibName);
                

http://git-wip-us.apache.org/repos/asf/trafodion/blob/d82d650e/core/sql/executor/ExUdr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExUdr.cpp b/core/sql/executor/ExUdr.cpp
index fc2686a..45f90cc 100644
--- a/core/sql/executor/ExUdr.cpp
+++ b/core/sql/executor/ExUdr.cpp
@@ -808,6 +808,7 @@ Int32 ExUdrTcb::fixup()
             libOrJarName = myTdb().getPathName();
           else
             libOrJarName = myTdb().getContainerName();
+          Int32 err = 0;
           if(ComGenerateUdrCachedLibName(libOrJarName.data(),
                                          myTdb().getLibraryRedefTime(),
                                          myTdb().getLibrarySchName(),
@@ -815,9 +816,16 @@ Int32 ExUdrTcb::fixup()
                                          cachedLibName, cachedLibPath))
             {
               NAString cachedFullName = cachedLibPath+"/"+cachedLibName;
-                  *getOrCreateStmtDiags() <<  DgSqlCode(-4316)
-                                << DgString0(( char *)cachedFullName.data());;
-                  return FIXUP_ERROR;
+               char errString[200];
+               NAString errNAString;
+               sprintf(errString , "Error %d creating directory :",err); 
+               errNAString = errString;
+               errNAString += cachedFullName;
+             
+              
+               *getOrCreateStmtDiags() <<  DgSqlCode(-4316)
+                                       << DgString0(( char *)errNAString.data());
+               return FIXUP_ERROR;
             }
            NAString cachedFullName = cachedLibPath+"/"+cachedLibName;
           //If the local copy already exists, don't bother extracting.

http://git-wip-us.apache.org/repos/asf/trafodion/blob/d82d650e/core/sql/optimizer/UdfDllInteraction.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/UdfDllInteraction.cpp b/core/sql/optimizer/UdfDllInteraction.cpp
index 951833d..b7444cb 100644
--- a/core/sql/optimizer/UdfDllInteraction.cpp
+++ b/core/sql/optimizer/UdfDllInteraction.cpp
@@ -151,15 +151,21 @@ NABoolean TMUDFDllInteraction::describeParamsAndMaxOutputs(
         libOrJarName = routine->getExternalPath();
       else
         libOrJarName = routine->getContainerName();
-      if(ComGenerateUdrCachedLibName(libOrJarName.data(),
+      Int32 err = 0;
+      if(err = ComGenerateUdrCachedLibName(libOrJarName.data(),
                                   routine->getLibRedefTime(),
                                   routine->getLibSchName(),
                                   dummyUser,
                                      cachedLibName, cachedLibPath))
         {
            NAString cachedFullName = cachedLibPath+"/"+cachedLibName;
+           char errString[200];
+           NAString errNAString;
+           sprintf(errString , "Error %d creating directory :",err); 
+           errNAString = errString;
+           errNAString += cachedFullName;
            *CmpCommon::diags() <<  DgSqlCode(-4316)
-                                  << DgString0(( char *)cachedFullName.data());
+                                  << DgString0(( char *)errNAString.data());
            bindWA->setErrStatus();
            return FALSE;
         }

http://git-wip-us.apache.org/repos/asf/trafodion/blob/d82d650e/core/sql/regress/tools/rgrCleanup
----------------------------------------------------------------------
diff --git a/core/sql/regress/tools/rgrCleanup b/core/sql/regress/tools/rgrCleanup
index 452a6ec..c99de5b 100755
--- a/core/sql/regress/tools/rgrCleanup
+++ b/core/sql/regress/tools/rgrCleanup
@@ -1,4 +1,4 @@
 #temp solution to cleanup udr cached files
 #can be removed when cleanup mechanism for cached files in implemented
-echo "rm -rf $TRAF_HOME/udr/$MY_UDR_CACHE_LIBDIR/* 2>$NULL"
-rm -rf $TRAF_HOME/udr/$MY_UDR_CACHE_LIBDIR/* 2>$NULL
+echo "rm -rf $TRAF_HOME/udr/*/$UDR_CACHE_LIBDIR/* 2>$NULL"
+rm -rf $TRAF_HOME/udr/*/$UDR_CACHE_LIBDIR/* 2>$NULL

http://git-wip-us.apache.org/repos/asf/trafodion/blob/d82d650e/core/sql/sqlcat/TrafDDLdesc.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcat/TrafDDLdesc.cpp b/core/sql/sqlcat/TrafDDLdesc.cpp
index f54a79e..29788c7 100644
--- a/core/sql/sqlcat/TrafDDLdesc.cpp
+++ b/core/sql/sqlcat/TrafDDLdesc.cpp
@@ -591,6 +591,7 @@ Long TrafRoutineDesc::pack(void * space)
   libraryFileName = (libraryFileName ? (char*)(((Space*)space)->convertToOffset(libraryFileName)) : NULL);
   signature = (signature ? (char*)(((Space*)space)->convertToOffset(signature)) : NULL);
   libBlobHandle = (libBlobHandle ? (char*)(((Space*)space)->convertToOffset(libBlobHandle)) : NULL);
+ libSchName = (libSchName ? (char*)(((Space*)space)->convertToOffset(libSchName)) : NULL);
   params.pack(space);
 
   return TrafDesc::pack(space);
@@ -604,6 +605,7 @@ Lng32 TrafRoutineDesc::unpack(void * base, void * reallocator)
   libraryFileName = (libraryFileName ? (char*)((char*)base - (Long)libraryFileName) : NULL);
   signature = (signature ? (char*)((char*)base - (Long)signature) : NULL);
   libBlobHandle = (libBlobHandle ? (char*)((char*)base - (Long)libBlobHandle) : NULL);
+  libSchName = (libSchName ? (char*)((char*)base - (Long)libSchName) : NULL);
   if (params.unpack(base, reallocator)) return -1;
 
   return TrafDesc::unpack(base, reallocator);

http://git-wip-us.apache.org/repos/asf/trafodion/blob/d82d650e/core/sql/sqlcomp/CmpDDLCatErrorCodes.h
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpDDLCatErrorCodes.h b/core/sql/sqlcomp/CmpDDLCatErrorCodes.h
index 0e385e1..dedd2c4 100644
--- a/core/sql/sqlcomp/CmpDDLCatErrorCodes.h
+++ b/core/sql/sqlcomp/CmpDDLCatErrorCodes.h
@@ -1,5 +1,4 @@
 /**********************************************************************
-
 // @@@ START COPYRIGHT @@@
 //
 // Licensed to the Apache Software Foundation (ASF) under one
@@ -69,7 +68,7 @@ enum CatErrorCode { CAT_FIRST_ERROR = 1000
                   , CAT_CATALOG_ALREADY_EXISTS                    = 1035
                   , CAT_CIRCULAR_PRIVS                            = 1036
                   , CAT_DEPENDENT_PRIV_EXISTS                     = 1037
-                  , CAT_UNABLE_TO_UPGRADE                         = 1037
+                  //unused                         = 1038
                   , CAT_PRIVILEGE_NOT_REVOKED                     = 1039
                   , CAT_SMD_CANNOT_BE_ALTERED                     = 1040
                   , CAT_PRIMARY_KEY_ALREADY_DEFINED               = 1041

http://git-wip-us.apache.org/repos/asf/trafodion/blob/d82d650e/core/sql/sqlcomp/CmpSeabaseDDL.h
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDL.h b/core/sql/sqlcomp/CmpSeabaseDDL.h
index 08ba746..dc0d63b 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDL.h
+++ b/core/sql/sqlcomp/CmpSeabaseDDL.h
@@ -1330,8 +1330,7 @@ protected:
 
   void dropSeabaseLibrary(StmtDDLDropLibrary  * dropLibraryNode,
                           NAString &currCatName, NAString &currSchName);
-  void dropSeabaseLibrary2(StmtDDLDropLibrary  * dropLibraryNode,
-                          NAString &currCatName, NAString &currSchName);
+ 
   void  alterSeabaseLibrary(StmtDDLAlterLibrary  *alterLibraryNode,
 			    NAString &currCatName, NAString &currSchName);
   void  alterSeabaseLibrary2(StmtDDLAlterLibrary  *alterLibraryNode,

http://git-wip-us.apache.org/repos/asf/trafodion/blob/d82d650e/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
index 8945254..6aaa084 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
@@ -9297,12 +9297,7 @@ short CmpSeabaseDDL::executeSeabaseDDL(DDLExpr * ddlExpr, ExprNode * ddlNode,
           // drop seabase library
           StmtDDLDropLibrary * dropLibraryParseNode =
             ddlNode->castToStmtDDLNode()->castToStmtDDLDropLibrary();
-          if( (CmpCommon::getDefault(USE_LIB_BLOB_STORE) == DF_OFF))
             dropSeabaseLibrary(dropLibraryParseNode, currCatName, currSchName);
-          else
-            {          
-              dropSeabaseLibrary2(dropLibraryParseNode, currCatName, currSchName);
-            }
         }
        else if (ddlNode->getOperatorType() == DDL_ALTER_LIBRARY)
          {

http://git-wip-us.apache.org/repos/asf/trafodion/blob/d82d650e/core/sql/sqlcomp/CmpSeabaseDDLroutine.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLroutine.cpp b/core/sql/sqlcomp/CmpSeabaseDDLroutine.cpp
index f6bd227..1501661 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLroutine.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLroutine.cpp
@@ -403,6 +403,7 @@ void CmpSeabaseDDL::createSeabaseLibrary(
   NADELETEBASIC(query, STMTHEAP);
   if (cliRC < 0)
     {
+      deallocEHI(ehi); 
       cliInterface.retrieveSQLDiagnostics(CmpCommon::diags());
       processReturn();
       return;
@@ -653,148 +654,7 @@ void CmpSeabaseDDL::createSeabaseLibrary2(
   return;
 }
 
-void CmpSeabaseDDL::dropSeabaseLibrary2(StmtDDLDropLibrary * dropLibraryNode,
-                                       NAString &currCatName, 
-                                       NAString &currSchName)
-{
-  Lng32 cliRC = 0;
-  Lng32 retcode = 0;
-
-  BindWA bindWA(ActiveSchemaDB(), CmpCommon::context(), FALSE/*inDDL*/);
-  NARoutineDB *pRoutineDBCache  = ActiveSchemaDB()->getNARoutineDB();
-  const NAString &objName = dropLibraryNode->getLibraryName();
-
-  ComObjectName libraryName(objName);
-  ComAnsiNamePart currCatAnsiName(currCatName);
-  ComAnsiNamePart currSchAnsiName(currSchName);
-  libraryName.applyDefaults(currCatAnsiName, currSchAnsiName);
-
-  const NAString catalogNamePart = libraryName.
-    getCatalogNamePartAsAnsiString();
-  const NAString schemaNamePart = libraryName.
-    getSchemaNamePartAsAnsiString(TRUE);
-  const NAString objectNamePart = libraryName.
-    getObjectNamePartAsAnsiString(TRUE);
-  const NAString extLibraryName = libraryName.getExternalName(TRUE);
-
-  ExeCliInterface cliInterface(STMTHEAP, 0, NULL, 
-    CmpCommon::context()->sqlSession()->getParentQid());
-
-  ExpHbaseInterface * ehi = allocEHI();
-  if (ehi == NULL)
-    return;
 
-  retcode = existsInSeabaseMDTable(&cliInterface, 
-				   catalogNamePart, schemaNamePart, 
-                                   objectNamePart,
-				   COM_LIBRARY_OBJECT, TRUE, FALSE);
-  if (retcode < 0)
-    {
-      deallocEHI(ehi); 
-      processReturn();
-      return;
-    }
-
-  if (retcode == 0) // does not exist
-    {
-      *CmpCommon::diags() << DgSqlCode(-1389)
-			  << DgString0(extLibraryName);
-      deallocEHI(ehi); 
-      processReturn();
-      return;
-    }
-
-  Int32 objectOwnerID = 0;
-  Int32 schemaOwnerID = 0;
-  Int64 objectFlags = 0;
-  Int64 objUID = getObjectInfo(&cliInterface,
-			      catalogNamePart.data(), schemaNamePart.data(), 
-			      objectNamePart.data(), COM_LIBRARY_OBJECT,
-                              objectOwnerID,schemaOwnerID,objectFlags);
-  if (objUID < 0 || objectOwnerID == 0 || schemaOwnerID == 0)
-    {
-      deallocEHI(ehi); 
-      processReturn();
-      return;
-    }
-
-  if (!isDDLOperationAuthorized(SQLOperation::DROP_LIBRARY,
-                                objectOwnerID,
-                                schemaOwnerID))
-  {
-     *CmpCommon::diags() << DgSqlCode(-CAT_NOT_AUTHORIZED);
-     processReturn ();
-     return;
-  }
-  
-  Queue * usingRoutinesQueue = NULL;
-  cliRC = getUsingRoutines(&cliInterface, objUID, usingRoutinesQueue);
-  if (cliRC < 0)
-    {
-      deallocEHI(ehi); 
-      processReturn();
-      return;
-    }
-  // If RESTRICT and the library is being used, return an error
-  if (cliRC != 100 && dropLibraryNode->getDropBehavior() == COM_RESTRICT_DROP_BEHAVIOR) 
-    {
-      *CmpCommon::diags() << DgSqlCode(-CAT_DEPENDENT_ROUTINES_EXIST);
-
-      deallocEHI(ehi); 
-      processReturn();
-      return;
-    }
-    
-  usingRoutinesQueue->position();
-  for (size_t i = 0; i < usingRoutinesQueue->numEntries(); i++)
-  { 
-     OutputInfo * rou = (OutputInfo*)usingRoutinesQueue->getNext(); 
-     
-     char * routineName = rou->get(0);
-     ComObjectType objectType = PrivMgr::ObjectLitToEnum(rou->get(1));
-
-     if (dropSeabaseObject(ehi, routineName,
-                           currCatName, currSchName, objectType,
-                           dropLibraryNode->ddlXns(),
-                           TRUE, FALSE))
-     {
-       deallocEHI(ehi); 
-       processReturn();
-       return;
-     }
-
-     // Remove routine from DBRoutinCache
-     ComObjectName objectName(routineName);
-     QualifiedName qualRoutineName(objectName, STMTHEAP);
-     NARoutineDBKey key(qualRoutineName, STMTHEAP);
-     NARoutine *cachedNARoutine = pRoutineDBCache->get(&bindWA, &key);
-
-     if (cachedNARoutine)
-     {
-       Int64 routineUID = *(Int64*)rou->get(2);
-       pRoutineDBCache->removeNARoutine(qualRoutineName,
-                                        ComQiScope::REMOVE_FROM_ALL_USERS,
-                                        routineUID,
-                                        dropLibraryNode->ddlXns(), FALSE);
-     }
-
-   }
- 
-  // can get a slight perf. gain if we pass in objUID
-  if (dropSeabaseObject(ehi, objName,
-                        currCatName, currSchName, COM_LIBRARY_OBJECT,
-                        dropLibraryNode->ddlXns(),
-                        TRUE, FALSE))
-    {
-      deallocEHI(ehi); 
-      processReturn();
-      return;
-    }
-
-  deallocEHI(ehi);      
-  processReturn();
-  return;
-}
 void CmpSeabaseDDL::dropSeabaseLibrary(StmtDDLDropLibrary * dropLibraryNode,
                                        NAString &currCatName, 
                                        NAString &currSchName)

http://git-wip-us.apache.org/repos/asf/trafodion/blob/d82d650e/core/sql/sqlcomp/CmpSeabaseDDLupgrade.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLupgrade.cpp b/core/sql/sqlcomp/CmpSeabaseDDLupgrade.cpp
index fe09364..3871b4b 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLupgrade.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLupgrade.cpp
@@ -325,8 +325,9 @@ short CmpSeabaseMDupgrade::executeSeabaseMDupgrade(CmpDDLwithStatusInfo *mdui,
   // interfaces for upgrading subsystems; OK to create on stack for
   // now as they are stateless
   CmpSeabaseUpgradeRepository upgradeRepository;
-  CmpSeabaseUpgradePrivMgr upgradePrivMgr;
   CmpSeabaseUpgradeLibraries upgradeLibraries;
+  CmpSeabaseUpgradePrivMgr upgradePrivMgr;
+  
   ExeCliInterface cliInterface(STMTHEAP, 0, NULL,
     CmpCommon::context()->sqlSession()->getParentQid());
   ExpHbaseInterface * ehi = NULL;
@@ -1673,7 +1674,7 @@ short CmpSeabaseMDupgrade::executeSeabaseMDupgrade(CmpDDLwithStatusInfo *mdui,
               {
                 *CmpCommon::diags() << DgSqlCode(-20123);
                 
-                mdui->setStep(UPGRADE_FAILED_RESTORE_OLD_REPOS);
+                mdui->setStep(UPGRADE_FAILED_RESTORE_OLD_LIBRARIES);
                 mdui->setSubstep(0);
                 
                 break;


[3/8] trafodion git commit: Fixees to support stroring Udr libraries s Blobs.

Posted by sa...@apache.org.
http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/regress/udr/TEST001
----------------------------------------------------------------------
diff --git a/core/sql/regress/udr/TEST001 b/core/sql/regress/udr/TEST001
index 395cee8..3c8e794 100644
--- a/core/sql/regress/udr/TEST001
+++ b/core/sql/regress/udr/TEST001
@@ -77,7 +77,8 @@ insert into clicks values
  ('super-services',cast(time'11:59:59.55 pm' as TIME(6)),'12.345.567.345');
 
 -- for now use VARCHARs for LOBs
---cqd TRAF_BLOB_AS_VARCHAR 'OFF'; 
+cqd TRAF_BLOB_AS_VARCHAR 'ON'; 
+cqd TRAF_CLOB_AS_VARCHAR 'ON';
 
 create table t001_Datatypes (
 c_char char(15),
@@ -203,7 +204,6 @@ create table_mapping function sessionize_java(user_colname char(10),
 external name 'TEST001_Sessionize'
 language java
 library TEST001_Java;
-
 -- negative test case, the entry point SESSIONIZE_ERR does not exist
 create table_mapping function sessionize_err(dummy char(10))
 returns (session_id largeint)

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/sqlcat/TrafDDLdesc.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcat/TrafDDLdesc.cpp b/core/sql/sqlcat/TrafDDLdesc.cpp
index e1d4597..f54a79e 100644
--- a/core/sql/sqlcat/TrafDDLdesc.cpp
+++ b/core/sql/sqlcat/TrafDDLdesc.cpp
@@ -590,7 +590,7 @@ Long TrafRoutineDesc::pack(void * space)
   librarySqlName = (librarySqlName ? (char*)(((Space*)space)->convertToOffset(librarySqlName)) : NULL);
   libraryFileName = (libraryFileName ? (char*)(((Space*)space)->convertToOffset(libraryFileName)) : NULL);
   signature = (signature ? (char*)(((Space*)space)->convertToOffset(signature)) : NULL);
-
+  libBlobHandle = (libBlobHandle ? (char*)(((Space*)space)->convertToOffset(libBlobHandle)) : NULL);
   params.pack(space);
 
   return TrafDesc::pack(space);
@@ -603,7 +603,7 @@ Lng32 TrafRoutineDesc::unpack(void * base, void * reallocator)
   librarySqlName = (librarySqlName ? (char*)((char*)base - (Long)librarySqlName) : NULL);
   libraryFileName = (libraryFileName ? (char*)((char*)base - (Long)libraryFileName) : NULL);
   signature = (signature ? (char*)((char*)base - (Long)signature) : NULL);
-
+  libBlobHandle = (libBlobHandle ? (char*)((char*)base - (Long)libBlobHandle) : NULL);
   if (params.unpack(base, reallocator)) return -1;
 
   return TrafDesc::unpack(base, reallocator);

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/sqlcat/TrafDDLdesc.h
----------------------------------------------------------------------
diff --git a/core/sql/sqlcat/TrafDDLdesc.h b/core/sql/sqlcat/TrafDDLdesc.h
index 7065924..adf7419 100644
--- a/core/sql/sqlcat/TrafDDLdesc.h
+++ b/core/sql/sqlcat/TrafDDLdesc.h
@@ -881,7 +881,11 @@ public:
   DescStructPtr priv_desc;
 
   Int64 routineDescFlags; // my flags
-
+  Int64 libRedefTime; 
+  char *libBlobHandle;
+  char *libSchName;
+  Int32 libVersion;
+  Int64 libObjUID;
   char filler[24];
 };
 

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/sqlcomp/CmpDDLCatErrorCodes.h
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpDDLCatErrorCodes.h b/core/sql/sqlcomp/CmpDDLCatErrorCodes.h
index 8ecf17e..0e385e1 100644
--- a/core/sql/sqlcomp/CmpDDLCatErrorCodes.h
+++ b/core/sql/sqlcomp/CmpDDLCatErrorCodes.h
@@ -69,7 +69,7 @@ enum CatErrorCode { CAT_FIRST_ERROR = 1000
                   , CAT_CATALOG_ALREADY_EXISTS                    = 1035
                   , CAT_CIRCULAR_PRIVS                            = 1036
                   , CAT_DEPENDENT_PRIV_EXISTS                     = 1037
-                  // unused                                       = 1038
+                  , CAT_UNABLE_TO_UPGRADE                         = 1037
                   , CAT_PRIVILEGE_NOT_REVOKED                     = 1039
                   , CAT_SMD_CANNOT_BE_ALTERED                     = 1040
                   , CAT_PRIMARY_KEY_ALREADY_DEFINED               = 1041

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/sqlcomp/CmpSeabaseDDL.h
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDL.h b/core/sql/sqlcomp/CmpSeabaseDDL.h
index 22ee692..08ba746 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDL.h
+++ b/core/sql/sqlcomp/CmpSeabaseDDL.h
@@ -412,7 +412,8 @@ class CmpSeabaseDDL
        Int64 & objectFlags,
        bool reportErrorNow = true,
        NABoolean checkForValidDef = FALSE,
-       Int64 * createTime = NULL);
+       Int64 * createTime = NULL,
+       Int64 * redefTime = NULL);
   
   short getObjectName(
        ExeCliInterface *cliInterface,
@@ -529,8 +530,9 @@ protected:
 		  NAString &colName);
 
   TrafDesc *getSeabaseRoutineDescInternal(const NAString &catName,
-                                             const NAString &schName,
-                                             const NAString &objName);
+                                          const NAString &schName,
+                                          const NAString &objName
+                                          );
 
   // note: this function expects hbaseCreateOptionsArray to have
   // HBASE_MAX_OPTIONS elements
@@ -1011,7 +1013,8 @@ protected:
      
   short createDefaultSystemSchema(ExeCliInterface * cliInterface);
   short createSchemaObjects(ExeCliInterface * cliInterface);
-  
+  short createLibrariesObject(ExeCliInterface * cliInterface);
+  short extractLibrary(ExeCliInterface *cliInterface,char *libHandle, char *cachedLibName);
   void  createSeabaseSchema(
      StmtDDLCreateSchema  * createSchemaNode,
      NAString             & currCatName);
@@ -1314,7 +1317,8 @@ protected:
 
   void createSeabaseLibrary(StmtDDLCreateLibrary  * createLibraryNode,
                             NAString &currCatName, NAString &currSchName);
-  
+  void createSeabaseLibrary2(StmtDDLCreateLibrary  * createLibraryNode,
+                            NAString &currCatName, NAString &currSchName);
   void registerSeabaseUser (
                             StmtDDLRegisterUser        * registerUserNode);
   void alterSeabaseUser (
@@ -1326,10 +1330,13 @@ protected:
 
   void dropSeabaseLibrary(StmtDDLDropLibrary  * dropLibraryNode,
                           NAString &currCatName, NAString &currSchName);
-
+  void dropSeabaseLibrary2(StmtDDLDropLibrary  * dropLibraryNode,
+                          NAString &currCatName, NAString &currSchName);
   void  alterSeabaseLibrary(StmtDDLAlterLibrary  *alterLibraryNode,
 			    NAString &currCatName, NAString &currSchName);
-
+  void  alterSeabaseLibrary2(StmtDDLAlterLibrary  *alterLibraryNode,
+			    NAString &currCatName, NAString &currSchName);
+  short isLibBlobStoreValid(ExeCliInterface * cliInterface);
   void createSeabaseRoutine(StmtDDLCreateRoutine  * createRoutineNode,
                             NAString &currCatName, NAString &currSchName);
   
@@ -1338,6 +1345,7 @@ protected:
 
   short createSeabaseLibmgr(ExeCliInterface * cliInterface);
   short upgradeSeabaseLibmgr(ExeCliInterface * inCliInterface);
+  short upgradeSeabaseLibmgr2(ExeCliInterface * inCliInterface);
   short dropSeabaseLibmgr(ExeCliInterface *inCliInterface);
   short createLibmgrProcs(ExeCliInterface * cliInterface);
   short grantLibmgrPrivs(ExeCliInterface *cliInterface);
@@ -1497,15 +1505,24 @@ protected:
                   NABoolean inRecovery = FALSE);
   short alterRenameRepos(ExeCliInterface * cliInterface, NABoolean newToOld);
   short copyOldReposToNew(ExeCliInterface * cliInterface);
+
   short dropAndLogReposViews(ExeCliInterface * cliInterface,
                              NABoolean & someViewSaved /* out */);
+  short createLibraries(ExeCliInterface * cliInterface);
+  short dropLibraries(ExeCliInterface * cliInterface, 
+                  NABoolean oldLibraries = FALSE, 
+                  NABoolean inRecovery = FALSE);
+  short alterRenameLibraries(ExeCliInterface * cliInterface, NABoolean newToOld);
+  short copyOldLibrariesToNew(ExeCliInterface * cliInterface);
 
 public:
 
   short upgradeRepos(ExeCliInterface * cliInterface, CmpDDLwithStatusInfo *mdui);
   short upgradeReposComplete(ExeCliInterface * cliInterface, CmpDDLwithStatusInfo *mdui);
   short upgradeReposUndo(ExeCliInterface * cliInterface, CmpDDLwithStatusInfo *mdui);
-
+  short upgradeLibraries(ExeCliInterface * cliInterface, CmpDDLwithStatusInfo *mdui);
+  short upgradeLibrariesComplete(ExeCliInterface * cliInterface, CmpDDLwithStatusInfo *mdui);
+  short upgradeLibrariesUndo(ExeCliInterface * cliInterface, CmpDDLwithStatusInfo *mdui);
   NAString genHBaseObjName(const NAString &catName, 
 			   const NAString &schName,
 			   const NAString &objName);

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
index 79ed311..8b78f5f 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
@@ -3735,7 +3735,8 @@ Int64 CmpSeabaseDDL::getObjectInfo(
                                    Int64 & objectFlags,
                                    bool reportErrorNow,
                                    NABoolean checkForValidDef,
-                                   Int64 *createTime)
+                                   Int64 *createTime,
+                                   Int64 *redefTime)
 {
   Lng32 retcode = 0;
   Lng32 cliRC = 0;
@@ -3754,7 +3755,7 @@ Int64 CmpSeabaseDDL::getObjectInfo(
     strcpy(cfvd, " and valid_def = 'Y' ");
 
   char buf[4000];
-  str_sprintf(buf, "select object_uid, object_owner, schema_owner, flags, create_time from %s.\"%s\".%s where catalog_name = '%s' and schema_name = '%s' and object_name = '%s'  and object_type = '%s' %s ",
+  str_sprintf(buf, "select object_uid, object_owner, schema_owner, flags, create_time,redef_time from %s.\"%s\".%s where catalog_name = '%s' and schema_name = '%s' and object_name = '%s'  and object_type = '%s' %s ",
               getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_OBJECTS,
               catName, quotedSchName.data(), quotedObjName.data(),
               objectTypeLit, cfvd);
@@ -3805,6 +3806,11 @@ Int64 CmpSeabaseDDL::getObjectInfo(
   if (createTime)
     *createTime = *(Int64*)ptr;
   
+ // return create_time
+  cliInterface->getPtrAndLen(6, ptr, len);
+  if (redefTime)
+    *redefTime = *(Int64*)ptr;
+  
   cliInterface->fetchRowsEpilogue(NULL, TRUE);
 
   return objUID;
@@ -5167,10 +5173,12 @@ short CmpSeabaseDDL::updateSeabaseMDSPJ(
       cliInterface->retrieveSQLDiagnostics(CmpCommon::diags());
       return -1;
     }
-
-  str_sprintf(buf, "insert into %s.\"%s\".%s values (%ld, '%s', %d, 0)",
-              getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_LIBRARIES,
-              libObjUID, libPath, routineInfo->library_version);
+  
+     
+  str_sprintf(buf, "insert into %s.\"%s\".%s values (%ld, '%s', empty_blob(), %d, 0)",
+                   getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_LIBRARIES,
+              libObjUID, libPath,routineInfo->library_version);
+     
   
   cliRC = cliInterface->executeImmediate(buf);
   if (cliRC < 0)
@@ -7231,8 +7239,10 @@ short CmpSeabaseDDL::updateSeabaseAuths(
 
  New method is called  initTrafMD.
 
+
 */
 
+
 void CmpSeabaseDDL::createSeabaseMDviews()
 {
   if (!ComUser::isRootUserID())
@@ -7318,14 +7328,14 @@ void CmpSeabaseDDL::createSeabaseSchemaObjects()
 
 }
 
+
 short CmpSeabaseDDL::createDefaultSystemSchema(ExeCliInterface *cliInterface)
 {
   Lng32 cliRC = 0;
   char buf[4000];
   
   str_sprintf(buf,"create shared schema " TRAFODION_SYSCAT_LIT"." SEABASE_SYSTEM_SCHEMA" ");
-  
-  cliRC = cliInterface->executeImmediate(buf);
+   cliRC = cliInterface->executeImmediate(buf);
   if (cliRC < 0)
     {
       cliInterface->retrieveSQLDiagnostics(CmpCommon::diags());
@@ -7335,6 +7345,25 @@ short CmpSeabaseDDL::createDefaultSystemSchema(ExeCliInterface *cliInterface)
   return 0;
 }
 
+short CmpSeabaseDDL::createLibrariesObject(ExeCliInterface *cliInterface)
+{
+  Lng32 retcode = 0;
+  Lng32 cliRC = 0;
+  char buf[4000];
+ 
+  str_sprintf(buf,"create table %s.\"%s\".LIBRARIES (library_uid largeint not null not serialized,library_filename varchar(512) character set iso88591 not null not serialized,library_storage  blob, version int not null not serialized, flags largeint not null not serialized)  primary key (library_uid) attribute hbase format ; ", getSystemCatalog(),SEABASE_MD_SCHEMA );
+
+  cliRC = cliInterface->executeImmediate(buf);
+  if (cliRC < 0)
+    {
+      cliInterface->retrieveSQLDiagnostics(CmpCommon::diags());
+      return -1;
+    }
+
+  return retcode;
+
+}
+
 short CmpSeabaseDDL::createSchemaObjects(ExeCliInterface *cliInterface)
 
 {
@@ -8837,7 +8866,12 @@ short CmpSeabaseDDL::executeSeabaseDDL(DDLExpr * ddlExpr, ExprNode * ddlNode,
     }
   else if (ddlExpr->upgradeLibmgr())
     {
-      upgradeSeabaseLibmgr(&cliInterface);
+      if( (CmpCommon::getDefault(USE_LIB_BLOB_STORE) == DF_OFF))
+        upgradeSeabaseLibmgr(&cliInterface);
+      else
+        {
+          upgradeSeabaseLibmgr2(&cliInterface);         
+        }
     }
   else if (ddlExpr->updateVersion())
     {
@@ -9246,26 +9280,49 @@ short CmpSeabaseDDL::executeSeabaseDDL(DDLExpr * ddlExpr, ExprNode * ddlNode,
           // create seabase library
           StmtDDLCreateLibrary * createLibraryParseNode =
             ddlNode->castToStmtDDLNode()->castToStmtDDLCreateLibrary();
-          
-          createSeabaseLibrary(createLibraryParseNode, currCatName, 
+          if( (CmpCommon::getDefault(USE_LIB_BLOB_STORE) == DF_OFF))
+            createSeabaseLibrary(createLibraryParseNode, currCatName, 
                                currSchName);
+          else
+            {
+              if (isLibBlobStoreValid(&cliInterface)==0)
+                createSeabaseLibrary2(createLibraryParseNode, currCatName, 
+                                      currSchName);
+              else
+                *CmpCommon::diags() << DgSqlCode(-CAT_UNABLE_TO_CREATE_OBJECT);
+      
+            }
         }
       else if (ddlNode->getOperatorType() == DDL_DROP_LIBRARY)
         {
           // drop seabase library
           StmtDDLDropLibrary * dropLibraryParseNode =
             ddlNode->castToStmtDDLNode()->castToStmtDDLDropLibrary();
-          
-          dropSeabaseLibrary(dropLibraryParseNode, currCatName, currSchName);
+          if( (CmpCommon::getDefault(USE_LIB_BLOB_STORE) == DF_OFF))
+            dropSeabaseLibrary(dropLibraryParseNode, currCatName, currSchName);
+          else
+            {
+              if (isLibBlobStoreValid(&cliInterface)==0)
+                dropSeabaseLibrary2(dropLibraryParseNode, currCatName, currSchName);
+              else
+                 *CmpCommon::diags() << DgSqlCode(-CAT_UNABLE_TO_DROP_OBJECT);
+            }
         }
        else if (ddlNode->getOperatorType() == DDL_ALTER_LIBRARY)
          {
            // create seabase library
            StmtDDLAlterLibrary * alterLibraryParseNode =
              ddlNode->castToStmtDDLNode()->castToStmtDDLAlterLibrary();
-           
-           alterSeabaseLibrary(alterLibraryParseNode, currCatName, 
-                               currSchName);
+           if( (CmpCommon::getDefault(USE_LIB_BLOB_STORE) == DF_OFF))
+             alterSeabaseLibrary(alterLibraryParseNode, currCatName, 
+                                 currSchName);
+           else
+             {
+               if (isLibBlobStoreValid(&cliInterface)==0)
+                alterSeabaseLibrary2(alterLibraryParseNode, currCatName, currSchName);
+              else
+                *CmpCommon::diags() << DgSqlCode(CAT_CANNOT_ALTER_WRONG_TYPE);
+             }
          }
       else if (ddlNode->getOperatorType() == DDL_CREATE_ROUTINE)
         {

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/sqlcomp/CmpSeabaseDDLincludes.h
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLincludes.h b/core/sql/sqlcomp/CmpSeabaseDDLincludes.h
index 9cbae54..e2713e3 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLincludes.h
+++ b/core/sql/sqlcomp/CmpSeabaseDDLincludes.h
@@ -105,7 +105,7 @@ enum {
   METADATA_MAJOR_VERSION = 2,
   METADATA_OLD_MAJOR_VERSION = 1,
   METADATA_MINOR_VERSION = 1,
-  METADATA_UPDATE_VERSION = 0,
+  METADATA_UPDATE_VERSION = 1,
   METADATA_OLD_MINOR_VERSION = 1,
   METADATA_OLD_UPDATE_VERSION = 0,
   DATAFORMAT_MAJOR_VERSION = 1,

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/sqlcomp/CmpSeabaseDDLinitraf.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLinitraf.cpp b/core/sql/sqlcomp/CmpSeabaseDDLinitraf.cpp
index e5491aa..ca24b2a 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLinitraf.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLinitraf.cpp
@@ -49,6 +49,7 @@ enum InitTrafSteps {
   IT_CREATE_SCHEMA_OBJECTS,
   IT_CREATE_MD_VIEWS,
   IT_CREATE_REPOS,
+  IT_CREATE_LIBRARIES,
   IT_CREATE_PRIVMGR_REPOS,
   IT_CREATE_LIBMGR,
   IT_STEP_FAILED,
@@ -692,7 +693,42 @@ short CmpSeabaseDDL::initTrafMD(CmpDDLwithStatusInfo *dws)
               } // switch
           }
           break;
+        case IT_CREATE_LIBRARIES:
+          {
+            switch (dws->subStep())
+              {
+              case 0:
+                {
+                  setValuesInDWS(dws, IT_NO_CHANGE,
+                                 "Create Libraries Tables: Started", 1, FALSE,
+                                 TRUE, FALSE, FALSE);
+
+                  return 0;
+                }
+                break;
+
+              case 1:
+                {
+                  ExeCliInterface cliInterface(STMTHEAP, 0, NULL, 
+                                               CmpCommon::context()->sqlSession()->getParentQid());
+
+                  if (createLibrariesObject(&cliInterface))
+                    {
+                      setValuesInDWS(dws, IT_STEP_FAILED,
+                                     "Create Libraries Tables: Failed", 0, TRUE,
+                                     FALSE, TRUE, TRUE);
+                      return 0;
+                    }
 
+                  setValuesInDWS(dws, IT_CREATE_PRIVMGR_REPOS,
+                                 "Create Libraries Tables: Completed", 0, TRUE,
+                                 FALSE, TRUE, TRUE);
+
+                  return 0;
+                } // case 1
+              } // switch
+          }
+          break;
         case IT_CREATE_PRIVMGR_REPOS:
           {
             switch (dws->subStep())

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/sqlcomp/CmpSeabaseDDLmd.h
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLmd.h b/core/sql/sqlcomp/CmpSeabaseDDLmd.h
index fefc29e..98ace75 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLmd.h
+++ b/core/sql/sqlcomp/CmpSeabaseDDLmd.h
@@ -190,7 +190,8 @@ static const QString seabaseLibrariesDDL[] =
   {" primary key (library_uid) "},
   {" attribute hbase format "},
   {" ; "}
-};
+  };
+
 
 static const QString seabaseLibrariesUsageDDL[] =
 {
@@ -497,7 +498,7 @@ static const QString seabaseViewsUsageDDL[] =
 
 static const ComTdbVirtTableRoutineInfo seabaseMDValidateRoutineInfo =
   {
-    "VALIDATEROUTINE", COM_PROCEDURE_TYPE_LIT,  COM_LANGUAGE_JAVA_LIT, 1, COM_NO_SQL_LIT, 0, 0, COM_STYLE_JAVA_CALL_LIT, COM_NO_TRANSACTION_REQUIRED_LIT, 0, 0, "org.trafodion.sql.udr.LmUtility.validateMethod", COM_ROUTINE_NO_PARALLELISM_LIT, " ", COM_ROUTINE_EXTERNAL_SECURITY_INVOKER_LIT, COM_ROUTINE_SAFE_EXECUTION_LIT, " ", 1, "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;III[Ljava/lang/String;[I[Ljava/lang/String;)V", " "
+    "VALIDATEROUTINE", COM_PROCEDURE_TYPE_LIT,  COM_LANGUAGE_JAVA_LIT, 1, COM_NO_SQL_LIT, 0, 0, COM_STYLE_JAVA_CALL_LIT, COM_NO_TRANSACTION_REQUIRED_LIT, 0, 0, "org.trafodion.sql.udr.LmUtility.validateMethod", COM_ROUTINE_NO_PARALLELISM_LIT, " ", COM_ROUTINE_EXTERNAL_SECURITY_INVOKER_LIT, COM_ROUTINE_SAFE_EXECUTION_LIT, " ", 1, "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;III[Ljava/lang/String;[I[Ljava/lang/String;)V", " ",0
   };
 
 static const ComTdbVirtTableColumnInfo seabaseMDValidateRoutineColInfo[] =
@@ -633,9 +634,9 @@ static const MDTableInfo allMDtablesInfo[] = {
    seabaseKeysDDL, sizeof(seabaseKeysDDL),
    NULL, 0, FALSE},
 
-  {SEABASE_LIBRARIES, 
+  /* {SEABASE_LIBRARIES, 
    seabaseLibrariesDDL, sizeof(seabaseLibrariesDDL),
-   NULL, 0, FALSE},
+   NULL, 0, FALSE},*/
 
   {SEABASE_LIBRARIES_USAGE, 
    seabaseLibrariesUsageDDL, sizeof(seabaseLibrariesUsageDDL),
@@ -746,6 +747,7 @@ static const MDTableInfo allMDHistInfo[] = {
 #define SEABASE_SEQ_GEN_OLD_MD          SEABASE_SEQ_GEN"_OLD_MD"
 #define SEABASE_TABLES_OLD_MD              SEABASE_TABLES"_OLD_MD"
 #define SEABASE_TABLE_CONSTRAINTS_OLD_MD SEABASE_TABLE_CONSTRAINTS"_OLD_MD"
+#define SEABASE_TABLE_CONSTRAINTS_IDX_OLD_MD SEABASE_TABLE_CONSTRAINTS_IDX"_OLD_MD" 
 #define SEABASE_TEXT_OLD_MD                 SEABASE_TEXT"_OLD_MD"
 #define SEABASE_UNIQUE_REF_CONSTR_USAGE_OLD_MD SEABASE_UNIQUE_REF_CONSTR_USAGE"_OLD_MD"
 #define SEABASE_VIEWS_OLD_MD                SEABASE_VIEWS"_OLD_MD"
@@ -1117,7 +1119,7 @@ static const QString seabaseOldTrafMDv11ViewsUsageDDL[] =
 
 static const ComTdbVirtTableRoutineInfo seabaseOldTrafMDv11MDValidateRoutineInfo =
   {
-    "VALIDATEROUTINE", COM_PROCEDURE_TYPE_LIT,  COM_LANGUAGE_JAVA_LIT, 1, COM_NO_SQL_LIT, 0, 0, COM_STYLE_JAVA_CALL_LIT, COM_NO_TRANSACTION_REQUIRED_LIT, 0, 0, "org.trafodion.sql.udr.LmUtility.validateMethod", COM_ROUTINE_NO_PARALLELISM_LIT, " ", COM_ROUTINE_EXTERNAL_SECURITY_INVOKER_LIT, COM_ROUTINE_SAFE_EXECUTION_LIT, " ", 1, "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;III[Ljava/lang/String;[I[Ljava/lang/String;)V", " "
+    "VALIDATEROUTINE", COM_PROCEDURE_TYPE_LIT,  COM_LANGUAGE_JAVA_LIT, 1, COM_NO_SQL_LIT, 0, 0, COM_STYLE_JAVA_CALL_LIT, COM_NO_TRANSACTION_REQUIRED_LIT, 0, 0, "org.trafodion.sql.udr.LmUtility.validateMethod", COM_ROUTINE_NO_PARALLELISM_LIT, " ", COM_ROUTINE_EXTERNAL_SECURITY_INVOKER_LIT, COM_ROUTINE_SAFE_EXECUTION_LIT, " ", 1, "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;III[Ljava/lang/String;[I[Ljava/lang/String;)V", " ",0
   };
 
 static const ComTdbVirtTableColumnInfo seabaseOldTrafMDv11MDValidateRoutineColInfo[] =

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/sqlcomp/CmpSeabaseDDLrepos.h
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLrepos.h b/core/sql/sqlcomp/CmpSeabaseDDLrepos.h
index 7a672d4..92ac39e 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLrepos.h
+++ b/core/sql/sqlcomp/CmpSeabaseDDLrepos.h
@@ -30,7 +30,7 @@
 
 #ifndef _CMP_SEABASE_REPOS_H_
 #define _CMP_SEABASE_REPOS_H_
-
+#include "CmpSeabaseDDLupgrade.h"
 #define TRAF_METRIC_QUERY_VIEW "METRIC_QUERY_VIEW"
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -894,8 +894,33 @@ static const QString createOldv23ReposMetricQueryAggrTable[] =
  {" primary key ( aggregation_start_utc_ts, session_id ) salt using 8 partitions "},
  {" ; "}
 };
-
 static const MDUpgradeInfo allReposUpgradeInfo[] = {
+ { REPOS_METRIC_QUERY_TABLE,  TRAF_METRIC_QUERY_TABLE_OLD_REPOS,
+   createMetricQueryTable,  sizeof(createMetricQueryTable),
+   NULL,0,
+   NULL, 0,
+   FALSE, NULL, NULL, NULL, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE},
+ // REPOS_METRIC_SESSION_TABLE
+  { REPOS_METRIC_SESSION_TABLE,  TRAF_METRIC_SESSION_TABLE_OLD_REPOS,
+    createMetricSessionTable,  sizeof(createMetricSessionTable),
+    NULL,0,
+    NULL, 0,
+    FALSE, NULL, NULL, NULL, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE},
+  // REPOS_METRIC_QUERY_AGGR_TABLE
+  { REPOS_METRIC_QUERY_AGGR_TABLE,  TRAF_METRIC_QUERY_AGGR_TABLE_OLD_REPOS,
+    createMetricQueryAggrTable,  sizeof(createMetricQueryAggrTable),
+    NULL,0,
+    NULL, 0,
+    FALSE, NULL, NULL, NULL, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE},
+  // REPOS_METRIC_TEXT_TABLE  
+  { REPOS_METRIC_TEXT_TABLE,  NULL,
+    createMetricTextTable,  sizeof(createMetricTextTable),
+    NULL, 0,
+    NULL, 0,
+    FALSE, NULL, NULL, NULL, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE}
+  
+};
+static const MDUpgradeInfo allReposv110Tov210UpgradeInfo[] = {
 
   // TRAF_METRIC_QUERY_TABLE
   { REPOS_METRIC_QUERY_TABLE,  TRAF_METRIC_QUERY_TABLE_OLD_REPOS,


[6/8] trafodion git commit: Fix issue with init sql ordering

Posted by sa...@apache.org.
Fix issue with init sql ordering


Project: http://git-wip-us.apache.org/repos/asf/trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafodion/commit/fab3c416
Tree: http://git-wip-us.apache.org/repos/asf/trafodion/tree/fab3c416
Diff: http://git-wip-us.apache.org/repos/asf/trafodion/diff/fab3c416

Branch: refs/heads/master
Commit: fab3c4164a0a3f8a8acd48afe07b4f10eaee8de1
Parents: 9528f8c
Author: Sandhya Sundaresan <sa...@apache.org>
Authored: Sat Sep 29 01:36:37 2018 +0000
Committer: Sandhya Sundaresan <sa...@apache.org>
Committed: Sat Sep 29 01:36:37 2018 +0000

----------------------------------------------------------------------
 core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp  | 17 ++++-------
 core/sql/sqlcomp/CmpSeabaseDDLinitraf.cpp | 42 ++++++++++++++------------
 2 files changed, 28 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafodion/blob/fab3c416/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
index 8b78f5f..8945254 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
@@ -9285,11 +9285,10 @@ short CmpSeabaseDDL::executeSeabaseDDL(DDLExpr * ddlExpr, ExprNode * ddlNode,
                                currSchName);
           else
             {
-              if (isLibBlobStoreValid(&cliInterface)==0)
+             
                 createSeabaseLibrary2(createLibraryParseNode, currCatName, 
                                       currSchName);
-              else
-                *CmpCommon::diags() << DgSqlCode(-CAT_UNABLE_TO_CREATE_OBJECT);
+              
       
             }
         }
@@ -9301,11 +9300,8 @@ short CmpSeabaseDDL::executeSeabaseDDL(DDLExpr * ddlExpr, ExprNode * ddlNode,
           if( (CmpCommon::getDefault(USE_LIB_BLOB_STORE) == DF_OFF))
             dropSeabaseLibrary(dropLibraryParseNode, currCatName, currSchName);
           else
-            {
-              if (isLibBlobStoreValid(&cliInterface)==0)
-                dropSeabaseLibrary2(dropLibraryParseNode, currCatName, currSchName);
-              else
-                 *CmpCommon::diags() << DgSqlCode(-CAT_UNABLE_TO_DROP_OBJECT);
+            {          
+              dropSeabaseLibrary2(dropLibraryParseNode, currCatName, currSchName);
             }
         }
        else if (ddlNode->getOperatorType() == DDL_ALTER_LIBRARY)
@@ -9318,10 +9314,9 @@ short CmpSeabaseDDL::executeSeabaseDDL(DDLExpr * ddlExpr, ExprNode * ddlNode,
                                  currSchName);
            else
              {
-               if (isLibBlobStoreValid(&cliInterface)==0)
+               
                 alterSeabaseLibrary2(alterLibraryParseNode, currCatName, currSchName);
-              else
-                *CmpCommon::diags() << DgSqlCode(CAT_CANNOT_ALTER_WRONG_TYPE);
+             
              }
          }
       else if (ddlNode->getOperatorType() == DDL_CREATE_ROUTINE)

http://git-wip-us.apache.org/repos/asf/trafodion/blob/fab3c416/core/sql/sqlcomp/CmpSeabaseDDLinitraf.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLinitraf.cpp b/core/sql/sqlcomp/CmpSeabaseDDLinitraf.cpp
index ca24b2a..5c6773c 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLinitraf.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLinitraf.cpp
@@ -529,25 +529,7 @@ short CmpSeabaseDDL::initTrafMD(CmpDDLwithStatusInfo *dws)
                         }
                     } // for
                   
-                  // update SPJ info
-                  // Note that this is not an existing jar file, the class
-                  // loader will attempt to load the class from the CLASSPATH if
-                  // it can't find this jar
-                  NAString installJar(getenv("TRAF_HOME"));
-                  installJar += "/export/lib/trafodion-sql-currversion.jar";
-                  if (updateSeabaseMDSPJ(&cliInterface, sysCat, SEABASE_MD_SCHEMA, 
-                                         SEABASE_VALIDATE_LIBRARY,
-                                         installJar.data(),SUPER_USER,SUPER_USER,
-                                         &seabaseMDValidateRoutineInfo,
-                                         sizeof(seabaseMDValidateRoutineColInfo) / sizeof(ComTdbVirtTableColumnInfo),
-                                         seabaseMDValidateRoutineColInfo))
-                    {
-                      setValuesInDWS(dws, IT_STEP_FAILED,
-                                     "Update Metadata Tables: Failed", 0, TRUE,
-                                     FALSE, TRUE, TRUE);                      
-
-                      return 0;
-                    }
+                  
                   
                   updateSeabaseVersions(&cliInterface, sysCat);
                   updateSeabaseAuths(&cliInterface, sysCat);
@@ -684,7 +666,7 @@ short CmpSeabaseDDL::initTrafMD(CmpDDLwithStatusInfo *dws)
                       return 0;
                     }
 
-                  setValuesInDWS(dws, IT_CREATE_PRIVMGR_REPOS,
+                  setValuesInDWS(dws, IT_CREATE_LIBRARIES,
                                  "Create Repository Tables: Completed", 0, TRUE,
                                  FALSE, TRUE, TRUE);
 
@@ -719,7 +701,27 @@ short CmpSeabaseDDL::initTrafMD(CmpDDLwithStatusInfo *dws)
                                      FALSE, TRUE, TRUE);
                       return 0;
                     }
+                  // update SPJ info
+                  // Note that this is not an existing jar file, the class
+                  // loader will attempt to load the class from the CLASSPATH if
+                  // it can't find this jar
+                  NAString installJar(getenv("TRAF_HOME"));
+                  installJar += "/export/lib/trafodion-sql-currversion.jar";
+                  const char* sysCat = 
+                    ActiveSchemaDB()->getDefaults().getValue(SEABASE_CATALOG);
+                  if (updateSeabaseMDSPJ(&cliInterface, sysCat, SEABASE_MD_SCHEMA, 
+                                         SEABASE_VALIDATE_LIBRARY,
+                                         installJar.data(),SUPER_USER,SUPER_USER,
+                                         &seabaseMDValidateRoutineInfo,
+                                         sizeof(seabaseMDValidateRoutineColInfo) / sizeof(ComTdbVirtTableColumnInfo),
+                                         seabaseMDValidateRoutineColInfo))
+                    {
+                      setValuesInDWS(dws, IT_STEP_FAILED,
+                                     "Update MDSPJ : Failed", 0, TRUE,
+                                     FALSE, TRUE, TRUE);                      
 
+                      return 0;
+                    }
                   setValuesInDWS(dws, IT_CREATE_PRIVMGR_REPOS,
                                  "Create Libraries Tables: Completed", 0, TRUE,
                                  FALSE, TRUE, TRUE);


[2/8] trafodion git commit: Fixees to support stroring Udr libraries s Blobs.

Posted by sa...@apache.org.
http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/sqlcomp/CmpSeabaseDDLroutine.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLroutine.cpp b/core/sql/sqlcomp/CmpSeabaseDDLroutine.cpp
index 29ef68e..f6bd227 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLroutine.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLroutine.cpp
@@ -57,7 +57,6 @@
 #include "CmpSeabaseDDL.h"
 
 #include "ExpHbaseInterface.h"
-
 #include "ExExeUtilCli.h"
 #include "Generator.h"
 #include "ComSmallDefs.h"
@@ -73,7 +72,7 @@
 
 #include "ComCextdecs.h"
 #include <sys/stat.h>
-
+short ExExeUtilLobExtractLibrary(ExeCliInterface *cliInterface,char *libHandle, char *cachedLibName,ComDiagsArea *toDiags);
 
 // *****************************************************************************
 // *                                                                           *
@@ -389,12 +388,245 @@ void CmpSeabaseDDL::createSeabaseLibrary(
     }
  
   char * query = new(STMTHEAP) char[1000];
-  str_sprintf(query, "insert into %s.\"%s\".%s values (%ld, '%s', %d, 0)",
-	      getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_LIBRARIES,
-	      objUID,
+  
+  //We come here only if CQD says use the old style without blobs . 
+  //So insert a NULL into the blob column.
+  str_sprintf(query, "insert into %s.\"%s\".%s values (%ld, '%s',NULL, %d, 0)",
+              getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_LIBRARIES,
+              objUID,
               libFileName.data(),
               createLibraryNode->getVersion());
+    
+ 
+  Lng32 cliRC = cliInterface.executeImmediate(query);
+
+  NADELETEBASIC(query, STMTHEAP);
+  if (cliRC < 0)
+    {
+      cliInterface.retrieveSQLDiagnostics(CmpCommon::diags());
+      processReturn();
+      return;
+    }
+    
+ 
+
+  // hope to remove this call soon by setting thevalid flag to Y sooner
+  if (updateObjectValidDef(&cliInterface, 
+			   catalogNamePart, schemaNamePart, objectNamePart,
+			   COM_LIBRARY_OBJECT_LIT,
+			   "Y"))
+    {
+      deallocEHI(ehi); 
+      processReturn();
+      return;
+    }
+
+  processReturn();
+
+  return;
+}
+short CmpSeabaseDDL::isLibBlobStoreValid(ExeCliInterface *cliInterface)
+{
+  Int32 cliRC=0;
+  char buf[4000];
+  char * query = new(STMTHEAP) char[1000];
+  str_sprintf(query, "select [first 1] library_storage from %s.\"%s\".%s ",
+	      getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_LIBRARIES
+	     );
+  
+  // set pointer in diags area
+  int32_t diagsMark = CmpCommon::diags()->mark();
+  cliRC = cliInterface->fetchRowsPrologue(query, TRUE/*no exec*/);
+  if (cliRC < 0)
+    {
+      cliInterface->retrieveSQLDiagnostics(CmpCommon::diags());
+      CmpCommon::diags()->rewind(diagsMark);
+      NADELETEBASIC(query, STMTHEAP);
+      return -1;
+    }
+
+  cliRC = cliInterface->clearExecFetchClose(NULL, 0);
+  if (cliRC < 0)
+    {
+      cliInterface->retrieveSQLDiagnostics(CmpCommon::diags());
+      CmpCommon::diags()->rewind(diagsMark);
+      NADELETEBASIC(query, STMTHEAP);
+      return -1;
+    }
+
+  if (cliRC >=0)
+    {
+      //found the new column.
+      NADELETEBASIC(query, STMTHEAP);
+      CmpCommon::diags()->rewind(diagsMark);
+      return 0;
+    }
+  
+  return 0;
+  NADELETEBASIC(query, STMTHEAP);
+ 
+}
+
+void CmpSeabaseDDL::createSeabaseLibrary2(
+				      StmtDDLCreateLibrary * createLibraryNode,
+				      NAString &currCatName, 
+                                      NAString &currSchName)
+{
+  Lng32 retcode = 0;
+ 
+  ComObjectName libraryName(createLibraryNode->getLibraryName());
+  ComAnsiNamePart currCatAnsiName(currCatName);
+  ComAnsiNamePart currSchAnsiName(currSchName);
+  libraryName.applyDefaults(currCatAnsiName, currSchAnsiName);
+  const NAString catalogNamePart = 
+    libraryName.getCatalogNamePartAsAnsiString();
+  const NAString schemaNamePart = 
+    libraryName.getSchemaNamePartAsAnsiString(TRUE);
+  const NAString objectNamePart = 
+    libraryName.getObjectNamePartAsAnsiString(TRUE);
+  const NAString extLibraryName = libraryName.getExternalName(TRUE);
+  const NAString extNameForHbase = catalogNamePart + "." + schemaNamePart + 
+    "." + objectNamePart;
+  
+  // Verify that the requester has MANAGE_LIBRARY privilege.
+  if (isAuthorizationEnabled() && !ComUser::isRootUserID())
+    {
+      NAString privMgrMDLoc;
+      CONCAT_CATSCH(privMgrMDLoc, getSystemCatalog(), SEABASE_PRIVMGR_SCHEMA);
+
+      PrivMgrComponentPrivileges componentPrivileges(std::string(privMgrMDLoc.data()),CmpCommon::diags());
+
+      if (!componentPrivileges.hasSQLPriv
+            (ComUser::getCurrentUser(),SQLOperation::MANAGE_LIBRARY,true))
+      {
+         *CmpCommon::diags() << DgSqlCode(-CAT_NOT_AUTHORIZED);
+         processReturn ();
+         return;
+      }
+    }
+
+  // Check to see if user has the authority to create the library
+  ExeCliInterface cliInterface(STMTHEAP, 0, NULL,
+    CmpCommon::context()->sqlSession()->getParentQid());
+  Int32 objectOwnerID = SUPER_USER;
+  Int32 schemaOwnerID = SUPER_USER;
+  ComSchemaClass schemaClass;
+
+  retcode = verifyDDLCreateOperationAuthorized(&cliInterface,
+                                               SQLOperation::CREATE_LIBRARY,
+                                               catalogNamePart,
+                                               schemaNamePart,
+                                               schemaClass,
+                                               objectOwnerID,
+                                               schemaOwnerID);
+  if (retcode != 0)
+  {
+     handleDDLCreateAuthorizationError(retcode,catalogNamePart,schemaNamePart);
+     return;
+  }
+     
+  ExpHbaseInterface * ehi = NULL;
+
+  ehi = allocEHI();
+  if (ehi == NULL)
+    {
+      processReturn();
+      return;
+    }
+
+  retcode = existsInSeabaseMDTable(&cliInterface, 
+				   catalogNamePart, schemaNamePart, 
+                                   objectNamePart, COM_LIBRARY_OBJECT, 
+                                   TRUE, FALSE);
+  if (retcode < 0)
+    {
+      deallocEHI(ehi); 
+      processReturn();
+      return;
+    }
+
+  if (retcode == 1) // already exists
+    {
+      *CmpCommon::diags() << DgSqlCode(-1390)
+			  << DgString0(extLibraryName);
+      deallocEHI(ehi); 
+      processReturn();
+      return;
+    }
+
+  NAString libFileName = createLibraryNode->getFilename() ;
+  // strip blank spaces
+  libFileName = libFileName.strip(NAString::both, ' ');
+
+  //Source file needs to exist on local node for LOB function 
+  //filetolob to succeed
+   if (validateLibraryFileExists(libFileName, FALSE))
+     {
+      deallocEHI(ehi); 
+      processReturn();
+      return;
+    }
+  size_t lastSlash = libFileName.last('/');
+  NAString libNameNoPath;
+  if (lastSlash != NA_NPOS)
+    libNameNoPath = libFileName(lastSlash+1, libFileName.length()-lastSlash-1);
+  else
+    {
+      *CmpCommon::diags() << DgSqlCode(-1382)
+                        << DgString0(libFileName);
+      deallocEHI(ehi); 
+      processReturn();
+      return;
+      
+    }
+  ComTdbVirtTableTableInfo * tableInfo = new(STMTHEAP) ComTdbVirtTableTableInfo[1];
+  tableInfo->tableName = NULL,
+  tableInfo->createTime = 0;
+  tableInfo->redefTime = 0;
+  tableInfo->objUID = 0;
+  tableInfo->objOwnerID = objectOwnerID;
+  tableInfo->schemaOwnerID = schemaOwnerID;
+  tableInfo->isAudited = 1;
+  tableInfo->validDef = 1;
+  tableInfo->hbaseCreateOptions = NULL;
+  tableInfo->numSaltPartns = 0;
+  tableInfo->rowFormat = COM_UNKNOWN_FORMAT_TYPE;
+  tableInfo->objectFlags = 0;
   
+  Int64 objUID = -1;
+  if (updateSeabaseMDTable(&cliInterface, 
+			   catalogNamePart, schemaNamePart, objectNamePart,
+			   COM_LIBRARY_OBJECT,
+			   "N",
+			   tableInfo,
+			   0,
+			   NULL,
+			   0,			       
+			   NULL,
+			   0, NULL,
+                           objUID))
+    {
+      deallocEHI(ehi); 
+      processReturn();
+      return;
+    }
+
+  if (objUID == -1)
+    {
+      deallocEHI(ehi); 
+      processReturn();
+      return;
+    }
+ 
+  char * query = new(STMTHEAP) char[1000];
+ 
+  str_sprintf(query, "insert into %s.\"%s\".%s values (%ld, '%s',filetolob('%s'), %d, 0)",
+                  getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_LIBRARIES,
+                  objUID,
+              libNameNoPath.data(),
+              libFileName.data(),
+                  createLibraryNode->getVersion());
+    
   Lng32 cliRC = cliInterface.executeImmediate(query);
 
   NADELETEBASIC(query, STMTHEAP);
@@ -421,7 +653,7 @@ void CmpSeabaseDDL::createSeabaseLibrary(
   return;
 }
 
-void CmpSeabaseDDL::dropSeabaseLibrary(StmtDDLDropLibrary * dropLibraryNode,
+void CmpSeabaseDDL::dropSeabaseLibrary2(StmtDDLDropLibrary * dropLibraryNode,
                                        NAString &currCatName, 
                                        NAString &currSchName)
 {
@@ -563,32 +795,332 @@ void CmpSeabaseDDL::dropSeabaseLibrary(StmtDDLDropLibrary * dropLibraryNode,
   processReturn();
   return;
 }
-
-void  CmpSeabaseDDL::alterSeabaseLibrary(StmtDDLAlterLibrary  *alterLibraryNode,
-					 NAString &currCatName, 
-					 NAString &currSchName)
+void CmpSeabaseDDL::dropSeabaseLibrary(StmtDDLDropLibrary * dropLibraryNode,
+                                       NAString &currCatName, 
+                                       NAString &currSchName)
 {
-  Lng32 cliRC;
-  Lng32 retcode;
-  
-  NAString libraryName = alterLibraryNode->getLibraryName();
-  NAString libFileName = alterLibraryNode->getFilename();
-  
-  ComObjectName libName(libraryName, COM_TABLE_NAME);
+  Lng32 cliRC = 0;
+  Lng32 retcode = 0;
+
+  BindWA bindWA(ActiveSchemaDB(), CmpCommon::context(), FALSE/*inDDL*/);
+  NARoutineDB *pRoutineDBCache  = ActiveSchemaDB()->getNARoutineDB();
+  const NAString &objName = dropLibraryNode->getLibraryName();
+
+  ComObjectName libraryName(objName);
   ComAnsiNamePart currCatAnsiName(currCatName);
   ComAnsiNamePart currSchAnsiName(currSchName);
-  libName.applyDefaults(currCatAnsiName, currSchAnsiName);
-  
-  NAString catalogNamePart = libName.getCatalogNamePartAsAnsiString();
-  NAString schemaNamePart = libName.getSchemaNamePartAsAnsiString(TRUE);
-  NAString libNamePart = libName.getObjectNamePartAsAnsiString(TRUE);
-  const NAString extLibName = libName.getExternalName(TRUE);
-  
-  ExeCliInterface cliInterface(STMTHEAP, 0, NULL,
-			       CmpCommon::context()->sqlSession()->getParentQid());
-  
+  libraryName.applyDefaults(currCatAnsiName, currSchAnsiName);
+
+  const NAString catalogNamePart = libraryName.
+    getCatalogNamePartAsAnsiString();
+  const NAString schemaNamePart = libraryName.
+    getSchemaNamePartAsAnsiString(TRUE);
+  const NAString objectNamePart = libraryName.
+    getObjectNamePartAsAnsiString(TRUE);
+  const NAString extLibraryName = libraryName.getExternalName(TRUE);
+
+  ExeCliInterface cliInterface(STMTHEAP, 0, NULL, 
+    CmpCommon::context()->sqlSession()->getParentQid());
+
+  ExpHbaseInterface * ehi = allocEHI();
+  if (ehi == NULL)
+    return;
+
   retcode = existsInSeabaseMDTable(&cliInterface, 
-				   catalogNamePart, schemaNamePart, libNamePart,
+				   catalogNamePart, schemaNamePart, 
+                                   objectNamePart,
+				   COM_LIBRARY_OBJECT, TRUE, FALSE);
+  if (retcode < 0)
+    {
+      deallocEHI(ehi); 
+      processReturn();
+      return;
+    }
+
+  if (retcode == 0) // does not exist
+    {
+      *CmpCommon::diags() << DgSqlCode(-1389)
+			  << DgString0(extLibraryName);
+      deallocEHI(ehi); 
+      processReturn();
+      return;
+    }
+
+  Int32 objectOwnerID = 0;
+  Int32 schemaOwnerID = 0;
+  Int64 objectFlags = 0;
+  Int64 objUID = getObjectInfo(&cliInterface,
+			      catalogNamePart.data(), schemaNamePart.data(), 
+			      objectNamePart.data(), COM_LIBRARY_OBJECT,
+                              objectOwnerID,schemaOwnerID,objectFlags);
+  if (objUID < 0 || objectOwnerID == 0 || schemaOwnerID == 0)
+    {
+      deallocEHI(ehi); 
+      processReturn();
+      return;
+    }
+
+  if (!isDDLOperationAuthorized(SQLOperation::DROP_LIBRARY,
+                                objectOwnerID,
+                                schemaOwnerID))
+  {
+     *CmpCommon::diags() << DgSqlCode(-CAT_NOT_AUTHORIZED);
+     processReturn ();
+     return;
+  }
+  
+  Queue * usingRoutinesQueue = NULL;
+  cliRC = getUsingRoutines(&cliInterface, objUID, usingRoutinesQueue);
+  if (cliRC < 0)
+    {
+      deallocEHI(ehi); 
+      processReturn();
+      return;
+    }
+  // If RESTRICT and the library is being used, return an error
+  if (cliRC != 100 && dropLibraryNode->getDropBehavior() == COM_RESTRICT_DROP_BEHAVIOR) 
+    {
+      *CmpCommon::diags() << DgSqlCode(-CAT_DEPENDENT_ROUTINES_EXIST);
+
+      deallocEHI(ehi); 
+      processReturn();
+      return;
+    }
+    
+  usingRoutinesQueue->position();
+  for (size_t i = 0; i < usingRoutinesQueue->numEntries(); i++)
+  { 
+     OutputInfo * rou = (OutputInfo*)usingRoutinesQueue->getNext(); 
+     
+     char * routineName = rou->get(0);
+     ComObjectType objectType = PrivMgr::ObjectLitToEnum(rou->get(1));
+
+     if (dropSeabaseObject(ehi, routineName,
+                           currCatName, currSchName, objectType,
+                           dropLibraryNode->ddlXns(),
+                           TRUE, FALSE))
+     {
+       deallocEHI(ehi); 
+       processReturn();
+       return;
+     }
+
+     // Remove routine from DBRoutinCache
+     ComObjectName objectName(routineName);
+     QualifiedName qualRoutineName(objectName, STMTHEAP);
+     NARoutineDBKey key(qualRoutineName, STMTHEAP);
+     NARoutine *cachedNARoutine = pRoutineDBCache->get(&bindWA, &key);
+
+     if (cachedNARoutine)
+     {
+       Int64 routineUID = *(Int64*)rou->get(2);
+       pRoutineDBCache->removeNARoutine(qualRoutineName,
+                                        ComQiScope::REMOVE_FROM_ALL_USERS,
+                                        routineUID,
+                                        dropLibraryNode->ddlXns(), FALSE);
+     }
+
+   }
+ 
+  // can get a slight perf. gain if we pass in objUID
+  if (dropSeabaseObject(ehi, objName,
+                        currCatName, currSchName, COM_LIBRARY_OBJECT,
+                        dropLibraryNode->ddlXns(),
+                        TRUE, FALSE))
+    {
+      deallocEHI(ehi); 
+      processReturn();
+      return;
+    }
+
+  deallocEHI(ehi);      
+  processReturn();
+  return;
+}
+
+void  CmpSeabaseDDL::alterSeabaseLibrary2(StmtDDLAlterLibrary  *alterLibraryNode,
+					 NAString &currCatName, 
+					 NAString &currSchName)
+{
+  Lng32 cliRC;
+  Lng32 retcode;
+  
+  NAString libraryName = alterLibraryNode->getLibraryName();
+  NAString libFileName = alterLibraryNode->getFilename();
+  
+  ComObjectName libName(libraryName, COM_TABLE_NAME);
+  ComAnsiNamePart currCatAnsiName(currCatName);
+  ComAnsiNamePart currSchAnsiName(currSchName);
+  libName.applyDefaults(currCatAnsiName, currSchAnsiName);
+  
+  NAString catalogNamePart = libName.getCatalogNamePartAsAnsiString();
+  NAString schemaNamePart = libName.getSchemaNamePartAsAnsiString(TRUE);
+  NAString libNamePart = libName.getObjectNamePartAsAnsiString(TRUE);
+  const NAString extLibName = libName.getExternalName(TRUE);
+  
+  ExeCliInterface cliInterface(STMTHEAP, 0, NULL,
+			       CmpCommon::context()->sqlSession()->getParentQid());
+  
+  retcode = existsInSeabaseMDTable(&cliInterface, 
+				   catalogNamePart, schemaNamePart, libNamePart,
+				   COM_LIBRARY_OBJECT, TRUE, FALSE);
+  if (retcode < 0)
+    {
+      processReturn();
+      return;
+    }
+  
+  if (retcode == 0) // does not exist
+    {
+      CmpCommon::diags()->clear();
+      *CmpCommon::diags() << DgSqlCode(-1389)
+			  << DgString0(extLibName);
+      processReturn();
+      return;
+    }
+  
+  // strip blank spaces
+  libFileName = libFileName.strip(NAString::both, ' ');
+  if (validateLibraryFileExists(libFileName, FALSE))
+    {
+      processReturn();
+      return;
+    }
+  
+  Int32 objectOwnerID = 0;
+  Int32 schemaOwnerID = 0;
+  Int64 objectFlags = 0;
+  Int64 libUID = getObjectInfo(&cliInterface,
+			       catalogNamePart.data(), schemaNamePart.data(),
+			       libNamePart.data(), COM_LIBRARY_OBJECT,
+			       objectOwnerID,schemaOwnerID,objectFlags);
+  
+  // Check for error getting metadata information
+  if (libUID == -1 || objectOwnerID == 0)
+    {
+      if (CmpCommon::diags()->getNumber(DgSqlCode::ERROR_) == 0)
+	SEABASEDDL_INTERNAL_ERROR("getting object UID and owner for alter library");
+      processReturn();
+      return;
+    }
+  
+  // Verify that the current user has authority to perform operation
+  if (!isDDLOperationAuthorized(SQLOperation::ALTER_LIBRARY,
+				objectOwnerID,schemaOwnerID))
+    {
+      *CmpCommon::diags() << DgSqlCode(-CAT_NOT_AUTHORIZED);
+      processReturn();
+      return;
+    }
+  
+  Int64 redefTime = NA_JulianTimestamp();
+    size_t lastSlash = libFileName.last('/');
+  NAString libNameNoPath;
+  if (lastSlash != NA_NPOS)
+    libNameNoPath = libFileName(lastSlash+1, libFileName.length()-lastSlash-1);
+  else
+    {
+      *CmpCommon::diags() << DgSqlCode(-1382)
+                        << DgString0(libFileName);
+      processReturn();
+      return;
+      
+    }
+  char buf[2048]; // filename max length is 512. Additional bytes for long
+  // library names.
+  str_sprintf(buf, "update %s.\"%s\".%s set library_filename = '%s' , library_storage = filetolob('%s') where library_uid = %ld",
+	      getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_LIBRARIES,
+              libNameNoPath.data(),
+	      libFileName.data(),
+	      libUID);
+  
+  cliRC = cliInterface.executeImmediate(buf);
+  if (cliRC < 0)
+    {
+      cliInterface.retrieveSQLDiagnostics(CmpCommon::diags());
+      return;
+    }
+  
+  if (updateObjectRedefTime(&cliInterface,
+			    catalogNamePart, schemaNamePart, libNamePart,
+			    COM_LIBRARY_OBJECT_LIT,
+			    redefTime))
+    {
+      processReturn();
+      return;
+   }
+  SQL_QIKEY qiKey;
+
+  
+  qiKey.ddlObjectUID = libUID;
+  qiKey.operation[0] = 'O';
+  qiKey.operation[1] = 'R';
+
+  cliRC = SQL_EXEC_SetSecInvalidKeys(1, &qiKey);
+  if (cliRC < 0)
+    {
+      processReturn();
+      return;
+    }
+  BindWA bindWA(ActiveSchemaDB(), CmpCommon::context(), FALSE/*inDDL*/);
+  NARoutineDB *pRoutineDBCache  = ActiveSchemaDB()->getNARoutineDB();
+  Queue * usingRoutinesQueue = NULL;
+  cliRC = getUsingRoutines(&cliInterface, libUID, usingRoutinesQueue);
+  if (cliRC < 0)
+    {
+      processReturn();
+      return;
+    }
+  usingRoutinesQueue->position();
+  for (size_t i = 0; i < usingRoutinesQueue->numEntries(); i++)
+    { 
+      OutputInfo * rou = (OutputInfo*)usingRoutinesQueue->getNext();    
+      char * routineName = rou->get(0);
+      ComObjectType objectType = PrivMgr::ObjectLitToEnum(rou->get(1));
+      // Remove routine from DBRoutinCache
+      ComObjectName objectName(routineName);
+      QualifiedName qualRoutineName(objectName, STMTHEAP);
+      NARoutineDBKey key(qualRoutineName, STMTHEAP);
+      NARoutine *cachedNARoutine = pRoutineDBCache->get(&bindWA, &key);
+      if (cachedNARoutine)
+	{
+	  Int64 routineUID = *(Int64*)rou->get(2);
+	  pRoutineDBCache->removeNARoutine(qualRoutineName,
+					   ComQiScope::REMOVE_FROM_ALL_USERS,
+					   routineUID,
+					   alterLibraryNode->ddlXns(), FALSE);
+	}
+    }
+  
+  return;
+}
+
+
+void  CmpSeabaseDDL::alterSeabaseLibrary(StmtDDLAlterLibrary  *alterLibraryNode,
+					 NAString &currCatName, 
+					 NAString &currSchName)
+{
+  Lng32 cliRC;
+  Lng32 retcode;
+  
+  NAString libraryName = alterLibraryNode->getLibraryName();
+  NAString libFileName = alterLibraryNode->getFilename();
+  
+  ComObjectName libName(libraryName, COM_TABLE_NAME);
+  ComAnsiNamePart currCatAnsiName(currCatName);
+  ComAnsiNamePart currSchAnsiName(currSchName);
+  libName.applyDefaults(currCatAnsiName, currSchAnsiName);
+  
+  NAString catalogNamePart = libName.getCatalogNamePartAsAnsiString();
+  NAString schemaNamePart = libName.getSchemaNamePartAsAnsiString(TRUE);
+  NAString libNamePart = libName.getObjectNamePartAsAnsiString(TRUE);
+  const NAString extLibName = libName.getExternalName(TRUE);
+  
+  ExeCliInterface cliInterface(STMTHEAP, 0, NULL,
+			       CmpCommon::context()->sqlSession()->getParentQid());
+  
+  retcode = existsInSeabaseMDTable(&cliInterface, 
+				   catalogNamePart, schemaNamePart, libNamePart,
 				   COM_LIBRARY_OBJECT, TRUE, FALSE);
   if (retcode < 0)
     {
@@ -697,6 +1229,26 @@ void  CmpSeabaseDDL::alterSeabaseLibrary(StmtDDLAlterLibrary  *alterLibraryNode,
   return;
 }
 
+short CmpSeabaseDDL::extractLibrary(ExeCliInterface *cliInterface,  char *libHandle, char *cachedLibName)
+{
+  struct stat statbuf;
+  Int64 libUID = 0;
+  short retcode = 0;
+      if (stat(cachedLibName, &statbuf) != 0)
+        {
+          retcode =  ExExeUtilLobExtractLibrary(cliInterface, libHandle, cachedLibName, 
+                                                CmpCommon::diags());
+          if (retcode < 0)
+            {
+              *CmpCommon::diags() <<  DgSqlCode(-4316)
+                                  << DgString0(cachedLibName);
+              processReturn();
+            }
+        }
+      
+  return retcode;
+}
+
 void CmpSeabaseDDL::createSeabaseRoutine(
 				      StmtDDLCreateRoutine * createRoutineNode,
 				      NAString &currCatName, 
@@ -727,7 +1279,7 @@ void CmpSeabaseDDL::createSeabaseRoutine(
   Int32 objectOwnerID = SUPER_USER;
   Int32 schemaOwnerID = SUPER_USER;
   ComSchemaClass schemaClass;
-
+  NAString libSuffix, libPrefix;
   retcode = verifyDDLCreateOperationAuthorized(&cliInterface,
                                                SQLOperation::CREATE_ROUTINE,
                                                catalogNamePart,
@@ -780,14 +1332,20 @@ void CmpSeabaseDDL::createSeabaseRoutine(
   NAString libObjNamePart = libName.getObjectNamePartAsAnsiString(TRUE);
   const NAString extLibraryName = libName.getExternalName(TRUE);
   char externalPath[512] ;
+  char libBlobHandle[LOB_HANDLE_LEN];
   Lng32 cliRC = 0;
-	
+  Int64 redefTime =0;	
   // this call needs to change
-  Int64 libUID = getObjectUID(&cliInterface, 
-                              libCatNamePart, 
-                              libSchNamePart, 
-                              libObjNamePart,
-                              COM_LIBRARY_OBJECT_LIT);
+  Int64 libUID = 0;
+  
+  Int32 dummy32;
+  Int64 dummy64;
+       
+  libUID = getObjectInfo(&cliInterface,
+                         libCatNamePart, libSchNamePart, 
+                         libObjNamePart, COM_LIBRARY_OBJECT,
+                         dummy32,dummy32,dummy64,FALSE,FALSE, &dummy64, &redefTime);
+     
 
   if (libUID < 0)
     {
@@ -804,13 +1362,15 @@ void CmpSeabaseDDL::createSeabaseRoutine(
       return;
     }
 
-  // read the library path name from the LIBRARIES metadata table
-
+  
+  // read the library  name from the LIBRARIES metadata table
   char * buf = new(STMTHEAP) char[200];
-  str_sprintf(buf, "select library_filename from %s.\"%s\".%s"
+ 
+  str_sprintf(buf, "select library_filename, library_storage from %s.\"%s\".%s"
               " where library_uid = %ld for read uncommitted access",
               getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_LIBRARIES, libUID);
-
+    
+   
   cliRC = cliInterface.fetchRowsPrologue(buf, TRUE/*no exec*/);
   if (cliRC < 0)
     {
@@ -839,21 +1399,27 @@ void CmpSeabaseDDL::createSeabaseRoutine(
 
   char * ptr = NULL;
   Lng32 len = 0;
+  
   cliInterface.getPtrAndLen(1, ptr, len);
   str_cpy_all(externalPath, ptr, len);
   externalPath[len] = '\0'; 
-
+  
+  cliInterface.getPtrAndLen(2, ptr, len);
+  str_cpy_all(libBlobHandle, ptr, len);
+  libBlobHandle[len] = '\0'; 
+    
+  
+  NAString extPath(externalPath);
+  size_t lastDot = extPath.last('.');
+     
+  
+  if (lastDot != NA_NPOS)  
+    libSuffix = extPath(lastDot,extPath.length()-lastDot);
+       
   // determine language and parameter styles based on the library
   // type, unless already specified
   if (!createRoutineNode->isLanguageTypeSpecified())
-    {
-      NAString extPath(externalPath);
-      size_t lastDot = extPath.last('.');
-      NAString libSuffix;
-
-      if (lastDot != NA_NPOS)
-        libSuffix = extPath(lastDot,extPath.length()-lastDot);
-
+    {   
       libSuffix.toUpper();
 
       if (libSuffix == ".JAR")
@@ -995,180 +1561,293 @@ void CmpSeabaseDDL::createSeabaseRoutine(
   sigBuf[0] = '\0';
 
   if (style == COM_STYLE_JAVA_CALL) 
-  {
-     // validate routine for Java call based on signature
-     Lng32 numJavaParam = 0;
-     ComFSDataType *paramType = new ComFSDataType[numParams];
-     ComUInt32     *subType   = new ComUInt32    [numParams];
-     ComColumnDirection *direction = new ComColumnDirection[numParams];
-     NAType *genericType;
+    {
+      // validate routine for Java call based on signature
+      Lng32 numJavaParam = 0;
+      ComFSDataType *paramType = new ComFSDataType[numParams];
+      ComUInt32     *subType   = new ComUInt32    [numParams];
+      ComColumnDirection *direction = new ComColumnDirection[numParams];
+      NAType *genericType;
 
-     // Gather the param attributes for LM from the paramDefArray previously
-     // populated and from the routineparamList generated from paramDefArray.
+      // Gather the param attributes for LM from the paramDefArray previously
+      // populated and from the routineparamList generated from paramDefArray.
 
-     for (CollIndex i = 0; (Int32)i < numParams; i++)
-     {
-       paramType[i] = (ComFSDataType)routineParamArray[i]->getParamDataType()->getFSDatatype();
-       subType[i] = 0;  // default
-       // Set subType for special cases detected by LM
-       switch ( paramType[i] )
-       {
-         case COM_SIGNED_BIN8_FSDT :
-         case COM_UNSIGNED_BIN8_FSDT :
-         case COM_SIGNED_BIN16_FSDT :
-         case COM_SIGNED_BIN32_FSDT :
-         case COM_SIGNED_BIN64_FSDT :
-         case COM_UNSIGNED_BIN16_FSDT :
-         case COM_UNSIGNED_BIN32_FSDT :
-         case COM_UNSIGNED_BPINT_FSDT :
-         {
-           genericType = routineParamArray[i]->getParamDataType() ;
-           if (genericType->getTypeName() == LiteralNumeric)
-             subType[i] = genericType->getPrecision();
-           else
-             subType[i] = 0 ;
-
-           break;
-         }
-
-         case COM_DATETIME_FSDT :
-         {
-           genericType = routineParamArray[i]->getParamDataType() ;
-           DatetimeType & datetimeType = (DatetimeType &) *genericType;
-            if (datetimeType.getSimpleTypeName() EQU "DATE")
-              subType[i] = 1 ;
-            else if (datetimeType.getSimpleTypeName() EQU "TIME")
-              subType[i] = 2;
-            else if (datetimeType.getSimpleTypeName() EQU "TIMESTAMP")
-              subType[i] = 3;
-         }
-       } // end switch paramType[i]
-
-       direction[i] = (ComColumnDirection) routineParamArray[i]->getParamDirection();
-     }
+      for (CollIndex i = 0; (Int32)i < numParams; i++)
+        {
+          paramType[i] = (ComFSDataType)routineParamArray[i]->getParamDataType()->getFSDatatype();
+          subType[i] = 0;  // default
+          // Set subType for special cases detected by LM
+          switch ( paramType[i] )
+            {
+            case COM_SIGNED_BIN8_FSDT :
+            case COM_UNSIGNED_BIN8_FSDT :
+            case COM_SIGNED_BIN16_FSDT :
+            case COM_SIGNED_BIN32_FSDT :
+            case COM_SIGNED_BIN64_FSDT :
+            case COM_UNSIGNED_BIN16_FSDT :
+            case COM_UNSIGNED_BIN32_FSDT :
+            case COM_UNSIGNED_BPINT_FSDT :
+              {
+                genericType = routineParamArray[i]->getParamDataType() ;
+                if (genericType->getTypeName() == LiteralNumeric)
+                  subType[i] = genericType->getPrecision();
+                else
+                  subType[i] = 0 ;
+
+                break;
+              }
+
+            case COM_DATETIME_FSDT :
+              {
+                genericType = routineParamArray[i]->getParamDataType() ;
+                DatetimeType & datetimeType = (DatetimeType &) *genericType;
+                if (datetimeType.getSimpleTypeName() EQU "DATE")
+                  subType[i] = 1 ;
+                else if (datetimeType.getSimpleTypeName() EQU "TIME")
+                  subType[i] = 2;
+                else if (datetimeType.getSimpleTypeName() EQU "TIMESTAMP")
+                  subType[i] = 3;
+              }
+            } // end switch paramType[i]
+
+          direction[i] = (ComColumnDirection) routineParamArray[i]->getParamDirection();
+        }
     
-     // If the syntax specified a signature, pass that to LanguageManager.
-     NAString specifiedSig( createRoutineNode->getJavaSignature() );
-     char* optionalSig;
-     if ( specifiedSig.length() == 0 )
-       optionalSig = NULL;
-     else
-       optionalSig = (char *)specifiedSig.data();
+      // If the syntax specified a signature, pass that to LanguageManager.
+      NAString specifiedSig( createRoutineNode->getJavaSignature() );
+      char* optionalSig;
+      if ( specifiedSig.length() == 0 )
+        optionalSig = NULL;
+      else
+        optionalSig = (char *)specifiedSig.data();
      
-     ComBoolean isJavaMain =
-       ((str_cmp_ne(createRoutineNode->getJavaMethodName(), "main") == 0) ? TRUE : FALSE);
-
-     LmResult createSigResult;
-     LmJavaSignature *lmSignature =  new (STMTHEAP) LmJavaSignature(NULL,
-                                                                    STMTHEAP);
-     createSigResult = lmSignature->createSig(paramType, subType, direction,
-                                              numParams, COM_UNKNOWN_FSDT, 0,
-                                              createRoutineNode->getMaxResults(), optionalSig, isJavaMain, sigBuf,
-                                              MAX_SIGNATURE_LENGTH,
-                                              CmpCommon::diags());
-     NADELETE(lmSignature, LmJavaSignature, STMTHEAP);
-     delete [] paramType;
-     delete [] subType;
-     delete [] direction;
-
-     // Lm returned error. Lm fills diags area, so no need to worry about diags.
-     if (createSigResult == LM_ERR)
-     {
-       *CmpCommon::diags() << DgSqlCode(-1231)
-			  << DgString0(extRoutineName);
-       deallocEHI(ehi); 
-       processReturn();
-       return;
-     }
+      ComBoolean isJavaMain =
+        ((str_cmp_ne(createRoutineNode->getJavaMethodName(), "main") == 0) ? TRUE : FALSE);
+
+      LmResult createSigResult;
+      LmJavaSignature *lmSignature =  new (STMTHEAP) LmJavaSignature(NULL,
+                                                                     STMTHEAP);
+      createSigResult = lmSignature->createSig(paramType, subType, direction,
+                                               numParams, COM_UNKNOWN_FSDT, 0,
+                                               createRoutineNode->getMaxResults(), optionalSig, isJavaMain, sigBuf,
+                                               MAX_SIGNATURE_LENGTH,
+                                               CmpCommon::diags());
+      NADELETE(lmSignature, LmJavaSignature, STMTHEAP);
+      delete [] paramType;
+      delete [] subType;
+      delete [] direction;
+
+      // Lm returned error. Lm fills diags area, so no need to worry about diags.
+      if (createSigResult == LM_ERR)
+        {
+          *CmpCommon::diags() << DgSqlCode(-1231)
+                              << DgString0(extRoutineName);
+          deallocEHI(ehi); 
+          processReturn();
+          return;
+        }
 
-     numJavaParam = (isJavaMain ? 1 : numParams);
+      numJavaParam = (isJavaMain ? 1 : numParams);
+
+      if( libBlobHandle[0] != '\0' )
+        {
+          NAString dummyUser;
+          NAString cachedLibName, cachedLibPath;
+          
+          if(ComGenerateUdrCachedLibName(extPath,redefTime,libSchNamePart,dummyUser, cachedLibName, cachedLibPath))
+            {
+              *CmpCommon::diags() << DgSqlCode(-1231)
+                                  << DgString0(extRoutineName);
+              deallocEHI(ehi); 
+              processReturn();
+              return;
+            }
+         
+          NAString cachedFullName = cachedLibPath+"/"+cachedLibName;
+          
+          if (extractLibrary(&cliInterface,libBlobHandle, (char *)cachedFullName.data()))
+            {
+              *CmpCommon::diags() << DgSqlCode(-1231)
+                                  << DgString0(extRoutineName);
+              deallocEHI(ehi); 
+              processReturn();
+              return;
+            }
+                       
+          if (validateRoutine(&cliInterface, 
+                              createRoutineNode->getJavaClassName(),
+                              createRoutineNode->getJavaMethodName(),
+                              cachedFullName,
+                              sigBuf,
+                              numJavaParam,
+                              createRoutineNode->getMaxResults(),
+                              optionalSig))
+            {
+              *CmpCommon::diags() << DgSqlCode(-1231)
+                                  << DgString0(extRoutineName);
+              deallocEHI(ehi); 
+              processReturn();
+              return;
+            }
+        }
+    
+      else
+        {                      
+          if (validateRoutine(&cliInterface, 
+                          createRoutineNode->getJavaClassName(),
+                          createRoutineNode->getJavaMethodName(),
+                          externalPath,
+                          sigBuf,
+                          numJavaParam,
+                          createRoutineNode->getMaxResults(),
+                          optionalSig))
+           
+            {
+              *CmpCommon::diags() << DgSqlCode(-1231)
+                              << DgString0(extRoutineName);
+              deallocEHI(ehi); 
+              processReturn();
+              return;
+            }
+        }
+    }
+          
 
-     if (validateRoutine(&cliInterface, 
-                         createRoutineNode->getJavaClassName(),
-                         createRoutineNode->getJavaMethodName(),
-                         externalPath,
-                         sigBuf,
-                         numJavaParam,
-                         createRoutineNode->getMaxResults(),
-                         optionalSig))
-     {
-       *CmpCommon::diags() << DgSqlCode(-1231)
-                           << DgString0(extRoutineName);
-       deallocEHI(ehi); 
-       processReturn();
-       return;
-     }
-  }
   else if (style == COM_STYLE_JAVA_OBJ ||
            style == COM_STYLE_CPP_OBJ)
-  {
-    // validate existence of the C++ or Java class in the library
-    Int32 routineHandle = NullCliRoutineHandle;
-    NAString externalPrefix(externalPath);
-    NAString externalNameForValidation(externalName);
-    NAString containerName;
+    {
+      // validate existence of the C++ or Java class in the library
+      Int32 routineHandle = NullCliRoutineHandle;
+      NAString externalPrefix(externalPath);
+      NAString externalNameForValidation(externalName);
+      NAString containerName;
 
-    if (language == COM_LANGUAGE_C || language == COM_LANGUAGE_CPP)
-      {
-        // separate the actual DLL name from the prefix
-        char separator = '/';
-        size_t separatorPos = externalPrefix.last(separator);
+      if (language == COM_LANGUAGE_C || language == COM_LANGUAGE_CPP)
+        {
+          if( libBlobHandle[0] != '\0' )
+            {
+              NAString dummyUser;
+              NAString cachedLibName, cachedLibPath;
+              
+              if (ComGenerateUdrCachedLibName(externalPrefix,redefTime,libSchNamePart,dummyUser, cachedLibName, cachedLibPath))
+                {
+                  *CmpCommon::diags() << DgSqlCode(-1231)
+                                      << DgString0(extRoutineName);
+                  deallocEHI(ehi); 
+                  processReturn();
+                  return;
+                }
+         
+              NAString cachedFullName = cachedLibPath+"/"+cachedLibName;
+          
+              if (extractLibrary(&cliInterface,libBlobHandle, (char *)cachedFullName.data()))
+                {
+                  *CmpCommon::diags() << DgSqlCode(-1231)
+                                      << DgString0(extRoutineName);
+                  deallocEHI(ehi); 
+                  processReturn();
+                  return;
+                }
+              externalPrefix = cachedLibPath;
+              containerName = cachedLibName;
+              
+            }
+          else
+            {
+              // separate the actual DLL name from the prefix
+              char separator = '/';
+              size_t separatorPos = externalPrefix.last(separator);
+
+              if (separatorPos != NA_NPOS)
+                {
+                  containerName = externalPrefix(separatorPos+1,
+                                                 externalPrefix.length()-separatorPos-1);
+                  externalPrefix.remove(separatorPos,
+                                        externalPrefix.length()-separatorPos);
+                }
+              else
+                {
+                  // assume the entire string is a local name
+                  containerName = externalPrefix;
+                  externalPrefix = ".";
+                }
+            }
+        }
+      else
+        {
+          // For Java, the way the language manager works is that the
+          // external path is the fully qualified name of the jar and
+          // the container is the class name (external name).  We load
+          // the container (the class) by searching in the path (the
+          // jar). The external name is the method name, which in this
+          // case is the constructor of the class, <init>.
 
-        if (separatorPos != NA_NPOS)
-          {
-            containerName = externalPrefix(separatorPos+1,
-                                           externalPrefix.length()-separatorPos-1);
-            externalPrefix.remove(separatorPos,
-                                  externalPrefix.length()-separatorPos);
-          }
-        else
-          {
-            // assume the entire string is a local name
-            containerName = externalPrefix;
-            externalPrefix = ".";
-          }
-      }
-    else
-      {
-        // For Java, the way the language manager works is that the
-        // external path is the fully qualified name of the jar and
-        // the container is the class name (external name).  We load
-        // the container (the class) by searching in the path (the
-        // jar). The external name is the method name, which in this
-        // case is the constructor of the class, <init>.
-
-        // leave externalPrevix unchanged, fully qualified jar file
-        containerName = externalName;
-        externalNameForValidation = "<init>";
-      }
+          // leave externalPrevix unchanged, fully qualified jar file
 
-    // use a CLI call to validate that the library contains the routine
-    if (cliInterface.getRoutine(
-             NULL, // No InvocationInfo specified in this step
-             0,
-             NULL,
-             0,
-             (Int32) language,
-             (Int32) style,
-             externalNameForValidation.data(),
-             containerName.data(),
-             externalPrefix.data(),
-             extLibraryName.data(),
-             &routineHandle,
-             CmpCommon::diags()) != LME_ROUTINE_VALIDATED)
-      {
-        if (routineHandle != NullCliRoutineHandle)
-          cliInterface.putRoutine(routineHandle,
-                                  CmpCommon::diags());
 
-        CMPASSERT(CmpCommon::diags()->mainSQLCODE() < 0);
-        processReturn();
-        return;
-      }
 
-    cliInterface.putRoutine(routineHandle,
-                            CmpCommon::diags());
-  }
+          if( libBlobHandle[0] != '\0' )
+            {
+              NAString dummyUser;
+              NAString cachedLibName, cachedLibPath;
+              NAString libSchema(libSchNamePart);
+              if(ComGenerateUdrCachedLibName(extPath,redefTime,libSchNamePart,dummyUser, cachedLibName, cachedLibPath))
+                {
+                  *CmpCommon::diags() << DgSqlCode(-1231)
+                                      << DgString0(extRoutineName);
+                  deallocEHI(ehi); 
+                  processReturn();
+                  return;
+                }
+         
+              NAString cachedFullName = cachedLibPath+"/"+cachedLibName;
+          
+              if (extractLibrary(&cliInterface,libBlobHandle, (char *)cachedFullName.data()))
+                {
+                  *CmpCommon::diags() << DgSqlCode(-1231)
+                                      << DgString0(extRoutineName);
+                  deallocEHI(ehi); 
+                  processReturn();
+                  return;
+                }
+              externalPrefix = cachedFullName;
+              containerName = externalName;
+              externalNameForValidation="<init>";
+            }
+          else
+            {
+              containerName = externalName;
+              externalNameForValidation = "<init>";
+            }
+        }
+
+      // use a CLI call to validate that the library contains the routine
+      if (cliInterface.getRoutine(
+               NULL, // No InvocationInfo specified in this step
+               0,
+               NULL,
+               0,
+               (Int32) language,
+               (Int32) style,
+               externalNameForValidation.data(),
+               containerName.data(),
+               externalPrefix.data(),
+               extLibraryName.data(),
+               &routineHandle,
+               CmpCommon::diags()) != LME_ROUTINE_VALIDATED)
+        {
+          if (routineHandle != NullCliRoutineHandle)
+            cliInterface.putRoutine(routineHandle,
+                                    CmpCommon::diags());
+
+          CMPASSERT(CmpCommon::diags()->mainSQLCODE() < 0);
+          processReturn();
+          return;
+        }
+
+      cliInterface.putRoutine(routineHandle,
+                              CmpCommon::diags());
+    }
 
   ComTdbVirtTableColumnInfo * colInfoArray = (ComTdbVirtTableColumnInfo*)
     new(STMTHEAP) ComTdbVirtTableColumnInfo[numParams];
@@ -1502,6 +2181,7 @@ short CmpSeabaseDDL::validateRoutine(ExeCliInterface *cliInterface,
               numSqlParam, maxResultSets, optionalSig ? 1 : 0); 
              
   Lng32 cliRC = cliInterface->fetchRowsPrologue(query, TRUE/*no exec*/);
+  
   if (cliRC < 0)
   {
      cliInterface->retrieveSQLDiagnostics(CmpCommon::diags());
@@ -1602,9 +2282,11 @@ short CmpSeabaseDDL::createSeabaseLibmgr(ExeCliInterface * cliInterface)
       *CmpCommon::diags() << DgSqlCode(-TRAF_NOT_INITIALIZED);
       return -1;
     }
-
+  
   NAString jarLocation(getenv("TRAF_HOME"));
   jarLocation += "/export/lib/lib_mgmt.jar";
+   
+   
   char queryBuf[strlen(getSystemCatalog()) + strlen(SEABASE_LIBMGR_SCHEMA) +
                 strlen(SEABASE_LIBMGR_LIBRARY) + strlen(DB__LIBMGRROLE) + 
                 jarLocation.length() + 100];
@@ -1749,7 +2431,124 @@ short CmpSeabaseDDL::grantLibmgrPrivs(ExeCliInterface *cliInterface)
   return 0;
 }
 
-short CmpSeabaseDDL::upgradeSeabaseLibmgr(ExeCliInterface * cliInterface)
+short CmpSeabaseDDL::upgradeSeabaseLibmgr(ExeCliInterface * cliInterface)
+{
+  if (!ComUser::isRootUserID())
+    {
+      *CmpCommon::diags() << DgSqlCode(-CAT_NOT_AUTHORIZED);
+      return -1;
+    }
+
+  Lng32 cliRC = 0;
+
+  cliRC = existsInSeabaseMDTable(cliInterface,
+                                 getSystemCatalog(), SEABASE_LIBMGR_SCHEMA,
+                                 SEABASE_LIBMGR_LIBRARY,
+                                 COM_LIBRARY_OBJECT, TRUE, FALSE);
+  if (cliRC < 0)
+    return -1;
+
+  if (cliRC == 0) // does not exist
+    {
+      // give an error if the Java library does not exist, since that is
+      // an indication that we never ran
+      // INITIALIZE TRAFODION, CREATE LIBRARY MANAGEMENT
+      NAString libraryName(getSystemCatalog());
+      libraryName + ".\"" + SEABASE_LIBMGR_SCHEMA + "\"" + SEABASE_LIBMGR_LIBRARY;
+      *CmpCommon::diags() << DgSqlCode(-1389)
+                          << DgString0(libraryName.data());
+      return -1;
+    }
+
+  // Update the jar locations for system procedures and functions.  This should 
+  // be done before adding any new jar's since we use a system procedure to add
+  // procedures.
+  NAString jarLocation(getenv("TRAF_HOME"));
+  jarLocation += "/export/lib";
+
+  char queryBuf[1000];
+
+  // trafodion-sql_currversion.jar 
+  Int32 stmtSize = snprintf(queryBuf, sizeof(queryBuf), "update %s.\"%s\".%s  "
+           "set library_filename = '%s/trafodion-sql-currversion.jar' "
+           "where library_uid = "
+           "(select object_uid from %s.\"%s\".%s "
+           " where object_name = '%s'  and object_type = 'LB')",
+           getSystemCatalog(),SEABASE_MD_SCHEMA, SEABASE_LIBRARIES, jarLocation.data(),
+           getSystemCatalog(),SEABASE_MD_SCHEMA, SEABASE_OBJECTS, SEABASE_VALIDATE_LIBRARY);
+  CMPASSERT(stmtSize < sizeof(queryBuf));
+
+  cliRC = cliInterface->executeImmediate(queryBuf);
+  if (cliRC < 0)
+    {
+      cliInterface->retrieveSQLDiagnostics(CmpCommon::diags());
+      return -1;
+    }
+
+  // lib_mgmt.jar
+  stmtSize = snprintf(queryBuf, sizeof(queryBuf), "update %s.\"%s\".%s  "
+           "set library_filename = '%s/lib_mgmt.jar' "
+           "where library_uid = "
+           "(select object_uid from %s.\"%s\".%s "
+           " where object_name = '%s'  and object_type = 'LB')",
+           getSystemCatalog(),SEABASE_MD_SCHEMA, SEABASE_LIBRARIES, jarLocation.data(),
+           getSystemCatalog(),SEABASE_MD_SCHEMA, SEABASE_OBJECTS, SEABASE_LIBMGR_LIBRARY);
+  CMPASSERT(stmtSize < sizeof(queryBuf));
+
+  cliRC = cliInterface->executeImmediate(queryBuf);
+  if (cliRC < 0)
+    {
+      cliInterface->retrieveSQLDiagnostics(CmpCommon::diags());
+      return -1;
+    }
+
+  // libudr_predef.so
+  NAString dllLocation(getenv("TRAF_HOME"));
+  dllLocation += "/export/lib64";
+  if (strcmp(getenv("SQ_MBTYPE"), "64d") == 0)
+    dllLocation += "d";
+
+  stmtSize = snprintf(queryBuf, sizeof(queryBuf), "update %s.\"%s\".%s  "
+           "set library_filename = '%s/libudr_predef.so' "
+           "where library_uid = "
+           "(select object_uid from %s.\"%s\".%s "
+           " where object_name = '%s'  and object_type = 'LB')",
+           getSystemCatalog(),SEABASE_MD_SCHEMA, SEABASE_LIBRARIES, dllLocation.data(),
+           getSystemCatalog(),SEABASE_MD_SCHEMA, SEABASE_OBJECTS, SEABASE_LIBMGR_LIBRARY_CPP);
+  CMPASSERT(stmtSize < sizeof(queryBuf));
+
+  cliRC = cliInterface->executeImmediate(queryBuf);
+  if (cliRC < 0)
+    {
+      cliInterface->retrieveSQLDiagnostics(CmpCommon::diags());
+      return -1;
+    }
+
+
+  // now check for the C++ library, which was added in Trafodion 2.3
+  cliRC = existsInSeabaseMDTable(cliInterface,
+                                 getSystemCatalog(), SEABASE_LIBMGR_SCHEMA,
+                                 SEABASE_LIBMGR_LIBRARY_CPP,
+                                 COM_LIBRARY_OBJECT, TRUE, FALSE);
+  if (cliRC < 0)
+    return -1;
+
+  if (cliRC == 0)
+    {
+      // The Java library exists, but the C++ library does not yet
+      // exist. This means that we last created or upgraded the
+      // library management subsystem in Trafodion 2.2 or earlier.
+      // Create the C++ library, as it is needed for Trafodion 2.3
+      // and higher.
+      if (createSeabaseLibmgrCPPLib(cliInterface) < 0)
+        return -1;
+    }
+
+  return (createLibmgrProcs(cliInterface));
+}
+
+
+short CmpSeabaseDDL::upgradeSeabaseLibmgr2(ExeCliInterface * cliInterface)
 {
   if (!ComUser::isRootUserID())
     {
@@ -1778,6 +2577,8 @@ short CmpSeabaseDDL::upgradeSeabaseLibmgr(ExeCliInterface * cliInterface)
       return -1;
     }
 
+  
+  
   // Update the jar locations for system procedures and functions.  This should 
   // be done before adding any new jar's since we use a system procedure to add
   // procedures.
@@ -1788,11 +2589,12 @@ short CmpSeabaseDDL::upgradeSeabaseLibmgr(ExeCliInterface * cliInterface)
 
   // trafodion-sql_currversion.jar 
   Int32 stmtSize = snprintf(queryBuf, sizeof(queryBuf), "update %s.\"%s\".%s  "
-           "set library_filename = '%s/trafodion-sql-currversion.jar' "
+           "set library_filename = 'trafodion-sql-currversion.jar', "
+           "library_storage =   empty_blob() "              
            "where library_uid = "
            "(select object_uid from %s.\"%s\".%s "
            " where object_name = '%s'  and object_type = 'LB')",
-           getSystemCatalog(),SEABASE_MD_SCHEMA, SEABASE_LIBRARIES, jarLocation.data(),
+           getSystemCatalog(),SEABASE_MD_SCHEMA, SEABASE_LIBRARIES,
            getSystemCatalog(),SEABASE_MD_SCHEMA, SEABASE_OBJECTS, SEABASE_VALIDATE_LIBRARY);
   CMPASSERT(stmtSize < sizeof(queryBuf));
 
@@ -1805,7 +2607,8 @@ short CmpSeabaseDDL::upgradeSeabaseLibmgr(ExeCliInterface * cliInterface)
 
   // lib_mgmt.jar
   stmtSize = snprintf(queryBuf, sizeof(queryBuf), "update %s.\"%s\".%s  "
-           "set library_filename = '%s/lib_mgmt.jar' "
+           "set library_filename = 'lib_mgmt.jar', "
+           "library_storage = filetolob('%s/lib_mgmt.jar') "
            "where library_uid = "
            "(select object_uid from %s.\"%s\".%s "
            " where object_name = '%s'  and object_type = 'LB')",
@@ -1827,7 +2630,8 @@ short CmpSeabaseDDL::upgradeSeabaseLibmgr(ExeCliInterface * cliInterface)
     dllLocation += "d";
 
   stmtSize = snprintf(queryBuf, sizeof(queryBuf), "update %s.\"%s\".%s  "
-           "set library_filename = '%s/libudr_predef.so' "
+           "set library_filename = 'libudr_predef.so', "
+           "library_storage = filetolob('%s/libudr_predef.so') "
            "where library_uid = "
            "(select object_uid from %s.\"%s\".%s "
            " where object_name = '%s'  and object_type = 'LB')",
@@ -1865,6 +2669,7 @@ short CmpSeabaseDDL::upgradeSeabaseLibmgr(ExeCliInterface * cliInterface)
   return (createLibmgrProcs(cliInterface));
 }
 
+
 short CmpSeabaseDDL::dropSeabaseLibmgr(ExeCliInterface *cliInterface)
 {
     if (!ComUser::isRootUserID())
@@ -1925,3 +2730,568 @@ short CmpSeabaseDDL::createSeabaseLibmgrCPPLib(ExeCliInterface * cliInterface)
     }
   return 0;
 }
+
+short CmpSeabaseDDL::upgradeLibraries(ExeCliInterface * cliInterface,
+                                  CmpDDLwithStatusInfo *mdui)
+{
+Lng32 cliRC = 0;
+
+  while (1) // exit via return stmt in switch
+    {
+      switch (mdui->subStep())
+        {
+        case 0:
+          {
+            mdui->setMsg("Upgrade Libraries: Started");
+            mdui->subStep()++;
+            mdui->setEndStep(FALSE);
+        
+            return 0;
+          }
+          break;
+      
+        case 1:
+          {
+            mdui->setMsg("  Start: Drop Old Libraries");
+            mdui->subStep()++;
+            mdui->setEndStep(FALSE);
+        
+            return 0;
+          }
+          break;
+
+        case 2:
+          {
+            // drop old libraries
+            if (dropLibraries(cliInterface, TRUE/*old */))
+              return -3;  // error, but no recovery needed 
+        
+            mdui->setMsg("  End:   Drop Old Libraries");
+            mdui->subStep()++;
+            mdui->setEndStep(FALSE);
+        
+            return 0;
+          }
+          break;
+
+        case 3:
+          {
+            mdui->setMsg("  Start: Rename Current Libraries");
+            mdui->subStep()++;
+            mdui->setEndStep(FALSE);
+        
+            return 0;
+          }
+          break;
+        
+        case 4:
+          {
+            // rename current libraries tables to *_OLD_LIBRARIES
+            if (alterRenameLibraries(cliInterface, TRUE))
+              return -2;  // error, need to undo the rename only
+
+            mdui->setMsg("  End:   Rename Current Libraries");
+            mdui->subStep()++;
+            mdui->setEndStep(FALSE);
+        
+            return 0;
+          }
+          break;
+
+        case 5:
+          {
+            mdui->setMsg("  Start: Create New Libraries");
+            mdui->subStep()++;
+            mdui->setEndStep(FALSE);
+        
+            return 0;
+          }
+          break;
+         
+        case 6:
+          {
+            // create new libraries
+            if (createLibraries(cliInterface))
+              return -1;  // error, need to drop new libraies then undo rename
+        
+            mdui->setMsg("  End:   Create New Libraries");
+            mdui->subStep()++;
+            mdui->setEndStep(FALSE);
+  
+            return 0;
+          }
+          break;
+
+        case 7:
+          {
+            mdui->setMsg("  Start: Copy Old Libraries Contents ");
+            mdui->subStep()++;
+            mdui->setEndStep(FALSE);
+        
+            return 0;
+          }
+          break;
+
+        case 8:
+          {
+            // copy old contents into new 
+           
+            if (copyOldLibrariesToNew(cliInterface))
+              {
+                mdui->setMsg(" Copy Old Libraries failed ! Drop  and recreate the following :   ");
+                //return -1;  // error, need to drop new libraries then undo rename
+              }
+        
+            mdui->setMsg("  End:   Copy Old Libraries Contents ");
+            mdui->subStep()++;
+            mdui->setEndStep(FALSE);
+         
+            return 0;
+          }
+          break;
+
+        case 9:
+          {
+            mdui->setMsg("Upgrade Libraries: Done except for cleaning up");
+            mdui->setSubstep(0);
+            mdui->setEndStep(TRUE);
+        
+            return 0;
+          }
+          break;
+
+        default:
+          return -1;
+        }
+    } // while
+
+  return 0;
+}
+
+short CmpSeabaseDDL::upgradeLibrariesComplete(ExeCliInterface * cliInterface,
+                                              CmpDDLwithStatusInfo *mdui)
+{
+  switch (mdui->subStep())
+    {
+    case 0:
+      {
+        mdui->setMsg("Upgrade Libraries: Drop old libraries");
+        mdui->subStep()++;
+        mdui->setEndStep(FALSE);
+        
+        return 0;
+      }
+      break;
+    case 1:
+      {
+        // drop old libraries; ignore errors
+        dropLibraries(cliInterface, TRUE/*old repos*/, FALSE/*no schema drop*/);
+        
+        mdui->setMsg("Upgrade Libraries: Drop Old Libraries done");
+        mdui->setEndStep(TRUE);
+        mdui->setSubstep(0);
+         
+        return 0;
+      }
+      break;
+
+    default:
+      return -1;
+    }
+
+return 0;
+}
+
+
+short CmpSeabaseDDL::upgradeLibrariesUndo(ExeCliInterface * cliInterface,
+                                  CmpDDLwithStatusInfo *mdui)
+{
+  Lng32 cliRC = 0;
+
+  while (1) // exit via return stmt in switch
+    {
+      switch (mdui->subStep())
+        {
+        // error return codes from upgradeLibraries can be mapped to
+        // the right recovery substep by this formula: substep = -(retcode + 1)
+        case 0: // corresponds to -1 return code from upgradeRepos (or
+                // to full recovery after some error after upgradeRepos)
+        case 1: // corresponds to -2 return code from upgradeRepos
+        case 2: // corresponds to -3 return code from upgradeRepos
+          {
+            mdui->setMsg("Upgrade Libraries: Restoring Old Libraries");
+            mdui->setSubstep(2*mdui->subStep()+3); // go to appropriate case
+            mdui->setEndStep(FALSE);
+        
+            return 0;
+          }
+          break;
+
+        case 3:
+          {
+            mdui->setMsg(" Start: Drop New Libraries");
+            mdui->subStep()++;
+            mdui->setEndStep(FALSE);
+        
+            return 0;
+          }
+          break;
+
+        case 4:
+          {
+            // drop new Libraries; ignore errors
+            dropLibraries(cliInterface, FALSE/*new repos*/, 
+                          TRUE /* don't drop new tables that haven't been upgraded */);
+            cliInterface->clearGlobalDiags();
+            mdui->setMsg(" End: Drop New Libraries");
+            mdui->subStep()++;
+            mdui->setEndStep(FALSE);
+        
+            return 0;
+          }
+          break;
+
+        case 5:
+          {
+            mdui->setMsg(" Start: Rename Old Libraries back to New");
+            mdui->subStep()++;
+            mdui->setEndStep(FALSE);
+        
+            return 0;
+          }
+          break;
+ 
+        case 6:
+          {
+            // rename old Libraries to current; ignore errors
+            alterRenameLibraries(cliInterface, FALSE);
+            cliInterface->clearGlobalDiags();
+            mdui->setMsg(" End: Rename Old Libraries back to New");
+            mdui->subStep()++;
+            mdui->setEndStep(FALSE);
+        
+            return 0;
+          }
+          break;
+
+        case 7:
+          {
+            mdui->setMsg("Upgrade Libraries: Restore done");
+            mdui->setSubstep(0);
+            mdui->setEndStep(TRUE);
+        
+            return 0;
+          }
+          break;
+
+        default:
+          return -1;
+        }
+    } // while
+
+  return 0;
+
+}
+
+short CmpSeabaseDDL::createLibraries(ExeCliInterface * cliInterface)
+{
+ Lng32 cliRC = 0;
+
+  char queryBuf[20000];
+
+  NABoolean xnWasStartedHere = FALSE;
+
+
+  for (Int32 i = 0; i < sizeof(allLibrariesUpgradeInfo)/sizeof(MDUpgradeInfo); i++)
+    {
+      const MDUpgradeInfo &lti = allLibrariesUpgradeInfo[i];
+
+      if (! lti.newName)
+        continue;
+
+      for (Int32 j = 0; j < NUM_MAX_PARAMS; j++)
+	{
+	  param_[j] = NULL;
+	}
+
+      const QString * qs = NULL;
+      Int32 sizeOfqs = 0;
+
+      qs = lti.newDDL;
+      sizeOfqs = lti.sizeOfnewDDL; 
+
+      Int32 qryArraySize = sizeOfqs / sizeof(QString);
+      char * gluedQuery;
+      Lng32 gluedQuerySize;
+      glueQueryFragments(qryArraySize,  qs,
+			 gluedQuery, gluedQuerySize);
+
+ 
+      param_[0] = getSystemCatalog();
+      param_[1] = SEABASE_MD_SCHEMA;
+
+      str_sprintf(queryBuf, gluedQuery, param_[0], param_[1]);
+      NADELETEBASICARRAY(gluedQuery, STMTHEAP);
+
+      if (beginXnIfNotInProgress(cliInterface, xnWasStartedHere))
+        goto label_error;
+      
+      cliRC = cliInterface->executeImmediate(queryBuf);
+      if (cliRC == -1390)  // table already exists
+	{
+	  // ignore error.
+          cliRC = 0;
+	}
+      else if (cliRC < 0)
+	{
+	  cliInterface->retrieveSQLDiagnostics(CmpCommon::diags());
+	}
+
+      if (endXnIfStartedHere(cliInterface, xnWasStartedHere, cliRC) < 0)
+        goto label_error;
+      
+    } // for
+  
+  
+  return 0;
+
+  label_error:
+   
+   return -1;
+}
+
+short CmpSeabaseDDL::dropLibraries(ExeCliInterface * cliInterface,
+                               NABoolean oldLibrary,
+                               NABoolean inRecovery)
+{
+ Lng32 cliRC = 0;
+  NABoolean xnWasStartedHere = FALSE;
+  char queryBuf[1000];
+
+  for (Int32 i = 0; i < sizeof(allLibrariesUpgradeInfo)/sizeof(MDUpgradeInfo); i++)
+    {
+      const MDUpgradeInfo &lti = allLibrariesUpgradeInfo[i];
+
+      // If we are dropping the new repository as part of a recovery action,
+      // and there is no "old" table (because the table didn't change in this
+      // upgrade), then don't drop the new table. (If we did, we would be 
+      // dropping the existing data.)
+      if (!oldLibrary && inRecovery && !lti.oldName)
+        continue;
+
+      if ((oldLibrary  && !lti.oldName) || (NOT oldLibrary && ! lti.newName))
+        continue;
+
+      str_sprintf(queryBuf, "drop table %s.\"%s\".%s cascade; ",
+                  getSystemCatalog(), SEABASE_MD_SCHEMA,
+                  (oldLibrary ? lti.oldName : lti.newName));
+    
+      if (beginXnIfNotInProgress(cliInterface, xnWasStartedHere))
+        {
+          cliInterface->retrieveSQLDiagnostics(CmpCommon::diags());
+          return -1;
+        }    
+
+      cliRC = cliInterface->executeImmediate(queryBuf);
+      if (cliRC == -1389)  // table doesn't exist
+	{
+	  // ignore the error.
+          cliRC = 0;
+	}
+      else if (cliRC < 0)
+        {
+          cliInterface->retrieveSQLDiagnostics(CmpCommon::diags());
+        }
+ 
+      if (endXnIfStartedHere(cliInterface, xnWasStartedHere, cliRC) < 0)
+        {
+          cliInterface->retrieveSQLDiagnostics(CmpCommon::diags());
+          return -1;
+        }
+ 
+      if (cliRC < 0)
+        {
+          return -1;  
+        }
+
+    }
+
+
+  return 0;
+}
+
+short CmpSeabaseMDupgrade::dropLibrariesTables(ExpHbaseInterface *ehi,
+                                           NABoolean oldLibraries)
+{
+  Lng32 retcode = 0;
+  Lng32 errcode = 0;
+
+  for (Int32 i = 0; i < sizeof(allLibrariesUpgradeInfo)/sizeof(MDUpgradeInfo); i++)
+    {
+      const MDUpgradeInfo &lti = allLibrariesUpgradeInfo[i];
+
+      if ((NOT oldLibraries) && (!lti.newName))
+	continue;
+
+      HbaseStr hbaseTable;
+      NAString extNameForHbase = TRAFODION_SYSCAT_LIT;
+      extNameForHbase += ".";
+      extNameForHbase += SEABASE_MD_SCHEMA;
+      extNameForHbase +=  ".";
+
+      if (oldLibraries)
+	{
+          if (!lti.oldName)
+            continue;
+          
+          extNameForHbase += lti.oldName;
+	}
+      else
+	extNameForHbase += lti.newName;
+      
+      hbaseTable.val = (char*)extNameForHbase.data();
+      hbaseTable.len = extNameForHbase.length();
+      
+      retcode = dropHbaseTable(ehi, &hbaseTable, FALSE, FALSE);
+      if (retcode < 0)
+	{
+	  errcode = -1;
+	}
+      
+    } // for
+  
+  return errcode;
+}
+
+
+short CmpSeabaseDDL::alterRenameLibraries(ExeCliInterface * cliInterface,
+                                          NABoolean newToOld)
+{
+ Lng32 cliRC = 0;
+
+  char queryBuf[10000];
+
+  NABoolean xnWasStartedHere = FALSE;
+
+  // alter table rename cannot run inside of a transaction.
+  // return an error if a xn is in progress
+  if (xnInProgress(cliInterface))
+    {
+      *CmpCommon::diags() << DgSqlCode(-20123);
+      return -1;
+    }
+
+  for (Int32 i = 0; i < sizeof(allLibrariesUpgradeInfo)/sizeof(MDUpgradeInfo); i++)
+    {
+      const MDUpgradeInfo &lti = allLibrariesUpgradeInfo[i];
+
+      if ((! lti.newName) || (! lti.oldName) || (NOT lti.upgradeNeeded))
+        continue;
+
+      if (newToOld)
+        str_sprintf(queryBuf, "alter table %s.\"%s\".%s rename to %s ; ",
+                    getSystemCatalog(), SEABASE_MD_SCHEMA, lti.newName, lti.oldName);
+      else
+        str_sprintf(queryBuf, "alter table %s.\"%s\".%s rename to %s ; ",
+                    getSystemCatalog(), SEABASE_MD_SCHEMA, lti.oldName, lti.newName);
+        
+      cliRC = cliInterface->executeImmediate(queryBuf);
+      if (cliRC == -1389 || cliRC == -1390)
+        {
+          // ignore.
+          cliRC = 0;
+        }
+      else if (cliRC < 0)
+	{
+	  cliInterface->retrieveSQLDiagnostics(CmpCommon::diags());
+	}
+    }
+
+  return 0;
+}
+
+short CmpSeabaseDDL::copyOldLibrariesToNew(ExeCliInterface * cliInterface)
+{
+  Lng32 cliRC = 0;
+  NAString failedLibraries;
+
+  char queryBuf[10000];
+  for (Int32 i = 0; i < sizeof(allLibrariesUpgradeInfo)/sizeof(MDUpgradeInfo); i++)
+    {
+      const MDUpgradeInfo lti = allLibrariesUpgradeInfo[i];
+
+      if ((! lti.newName) || (! lti.oldName) || (NOT lti.upgradeNeeded))
+        continue;
+      // Update all existing libraries  so the blob contains the library
+      char * sbuf = new(STMTHEAP) char[200];
+      char * ubuf = new(STMTHEAP) char[500];
+      NABoolean libsToUpgrade = TRUE;
+      Queue *userLibsQ = NULL;
+      str_sprintf(sbuf, "select library_filename,library_uid from %s.\"%s\".%s"
+                  " for read uncommitted access",
+                  getSystemCatalog(), SEABASE_MD_SCHEMA, lti.oldName); 
+      cliRC = cliInterface->fetchAllRows(userLibsQ,sbuf, 0, FALSE,FALSE,TRUE/*no exec*/);
+      if (cliRC < 0)
+        {
+          cliInterface->retrieveSQLDiagnostics(CmpCommon::diags());
+          return -1;
+        }
+
+    
+     
+      str_sprintf(queryBuf, "upsert using load into %s.\"%s\".%s %s%s%s select %s from %s.\"%s\".%s SRC %s;",
+                  TRAFODION_SYSCAT_LIT,
+                  SEABASE_MD_SCHEMA,
+                  lti.newName, 
+                  (lti.insertedCols ? "(" : ""),
+                  (lti.insertedCols ? lti.selectedCols : ""), // insert only the original column values
+                  (lti.insertedCols ? ")" : ""),
+                  (lti.selectedCols ? lti.selectedCols : "*"),
+                  TRAFODION_SYSCAT_LIT,
+                  SEABASE_MD_SCHEMA,
+                  lti.oldName,
+                  (lti.wherePred ? lti.wherePred : ""));
+
+      cliRC = cliInterface->executeImmediate(queryBuf);
+      if (cliRC < 0)
+        {
+          cliInterface->retrieveSQLDiagnostics(CmpCommon::diags());
+          return -1;
+        }
+
+      //update contents into  the new library table so the libname doesn't contain the path and the 
+      //lib contents get loaded into the blob column.
+      userLibsQ->position();
+      for (size_t i = 0; i < userLibsQ->numEntries(); i++)
+        {
+          OutputInfo *userLibRow = (OutputInfo *)userLibsQ->getNext();
+          char *libName = userLibRow->get(0);
+          NAString libFileName(libName);
+          Int64 libuid = *(Int64 *)userLibRow->get(1);
+
+          size_t lastSlash = libFileName.last('/');
+          NAString libNameNoPath;
+          if (lastSlash != NA_NPOS)
+            libNameNoPath = libFileName(lastSlash+1, libFileName.length()-lastSlash-1);
+          str_sprintf(ubuf," update %s.\"%s\".%s set library_filename = '%s', library_storage = filetolob('%s') where library_uid = %ld",
+                      getSystemCatalog(),SEABASE_MD_SCHEMA, lti.newName,
+                      libNameNoPath.data(),libName,libuid
+                      );
+          cliRC = cliInterface->executeImmediate(ubuf);
+          if (cliRC < 0)
+            {
+              if (failedLibraries.length() ==0)
+                failedLibraries += "Libraries Upgrade failed for :";
+              failedLibraries += libFileName;
+              failedLibraries += ";";
+              //cliInterface->retrieveSQLDiagnostics(CmpCommon::diags());
+              //return -1;
+            }
+        } //end for 
+    
+    }//end for
+
+  if (failedLibraries.length())
+    SQLMXLoggingArea::logSQLMXPredefinedEvent(failedLibraries, LL_WARN);
+  return 0;
+}

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/sqlcomp/CmpSeabaseDDLroutine.h
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLroutine.h b/core/sql/sqlcomp/CmpSeabaseDDLroutine.h
index 92adf18..e98c80b 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLroutine.h
+++ b/core/sql/sqlcomp/CmpSeabaseDDLroutine.h
@@ -23,6 +23,7 @@
 #define _CMP_SEABASE_PROCEDURES_H_
 
 #include "CmpSeabaseDDL.h"
+#include "CmpSeabaseDDLupgrade.h"
 
 // To add a new procedure:
 //   update export/lib/lib_mgmt.jar to include code for the new procedure 
@@ -407,4 +408,80 @@ static const LibmgrRoutineInfo allLibmgrRoutineInfo[] = {
 
 };
 
+/////////////////////////////////////////////////////////////////////
+//
+// Information about changed old metadata tables from which upgrade
+// is being done to the current version.
+// These definitions have changed in the current version of code.
+// 
+// Old definitions have the form (for ex for METRIC_QUERY_TABLE table):
+//            createOldTrafv??MetricQueryTable[]
+// v?? is the old version.
+//
+// When definitions change, make new entries between
+// START_OLD_MD_v?? and END_OLD_MD_v??.
+// Do not remove older entries. We want to keep them around for
+// historical purpose.
+//
+// Change entries in allReposUpgradeInfo[] struct in this file
+// to reflect the 'old' repository tables.
+//
+//////////////////////////////////////////////////////////////////////
+//----------------------------------------------------------------
+//-- LIBRARIES
+//----------------------------------------------------------------
+static const QString createLibrariesTable[] =
+  {
+    {" create table %s.\"%s\"." SEABASE_LIBRARIES" "},
+    {" ( "},
+    {"  library_uid largeint not null not serialized, "},
+    {"  library_filename varchar(512) character set iso88591 not null not serialized, "},
+    {"  library_storage  blob,"},
+    {"  version int not null not serialized, "},
+    {"  flags largeint not null not serialized "},
+    {" ) "},
+    {" primary key (library_uid) "},
+    {" attribute hbase format "},
+    {" ; "}
+  };
+
+#define SEABASE_LIBRARIES_OLD SEABASE_LIBRARIES"_OLD"
+static const QString createOldTrafv210LibrariesTable[] =
+{
+{" create table %s.\"%s\"." SEABASE_LIBRARIES" "},
+    {" ( "},
+    {"  library_uid largeint not null not serialized, "},
+    {"  library_filename varchar(512) character set iso88591 not null not serialized, "},
+    {"  version int not null not serialized, "},
+    {"  flags largeint not null not serialized "},
+    {" ) "},
+    {" primary key (library_uid) "},
+    {" attribute hbase format "},
+    {" ; "}
+  };
+
+static const MDUpgradeInfo allLibrariesUpgradeInfo[] = {
+  // LIBRARIES
+  {
+    SEABASE_LIBRARIES,  SEABASE_LIBRARIES_OLD,
+    createLibrariesTable,  sizeof(createLibrariesTable),
+    createOldTrafv210LibrariesTable,  sizeof(createOldTrafv210LibrariesTable),
+    NULL, 0,
+    TRUE,
+    //new table columns
+    "library_uid,"
+    "library_filename,"
+    "library_storage,"
+    "version,"
+    "flags",
+    //old table columns
+    "library_uid,"
+    "library_filename,"
+    "version,"
+    "flags",
+    NULL, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE}
+};
+
+
+  
 #endif

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9528f8c0/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp b/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
index a620624..3569b90 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
@@ -5475,7 +5475,7 @@ void CmpSeabaseDDL::alterSeabaseTableAddColumn(
       if (pColDef->getDefaultClauseStatus() != ElemDDLColDef::DEFAULT_CLAUSE_SPEC)
         {
           *CmpCommon::diags() << DgSqlCode(-CAT_DEFAULT_REQUIRED);
-
+          deallocEHI(ehi);
           processReturn();
 
           return;
@@ -5492,7 +5492,7 @@ void CmpSeabaseDDL::alterSeabaseTableAddColumn(
           if (pDefVal->isNull()) 
             {
               *CmpCommon::diags() << DgSqlCode(-CAT_CANNOT_BE_DEFAULT_NULL_AND_NOT_NULL);
-
+              deallocEHI(ehi);
               processReturn();
 
               return;
@@ -5504,7 +5504,7 @@ void CmpSeabaseDDL::alterSeabaseTableAddColumn(
   if (pColDef->getDefaultClauseStatus() == ElemDDLColDef::NO_DEFAULT_CLAUSE_SPEC)
     {
       *CmpCommon::diags() << DgSqlCode(-CAT_DEFAULT_REQUIRED);
-
+      deallocEHI(ehi);
       processReturn();
 
       return;
@@ -5513,7 +5513,7 @@ void CmpSeabaseDDL::alterSeabaseTableAddColumn(
   if (pColDef->getSGOptions())
     {
       *CmpCommon::diags() << DgSqlCode(-1514);
-
+      deallocEHI(ehi);
       processReturn();
 
       return;
@@ -5606,11 +5606,12 @@ void CmpSeabaseDDL::alterSeabaseTableAddColumn(
           *CmpCommon::diags() << DgSqlCode(-CAT_DUPLICATE_COLUMNS)
                               << DgColumnName(colName);
         }
-      
+      deallocEHI(ehi);
       processReturn();
 
       return;
     }
+  /*
   // If column is a LOB column , error
    if ((datatype == REC_BLOB) || (datatype == REC_CLOB))
      {
@@ -5619,8 +5620,80 @@ void CmpSeabaseDDL::alterSeabaseTableAddColumn(
       processReturn();
       return;
      }
-  char * col_name = new(STMTHEAP) char[colName.length() + 1];
+  */
+  char *col_name = new(STMTHEAP) char[colName.length() + 1];
   strcpy(col_name, (char*)colName.data());
+ if ((datatype == REC_BLOB) ||
+          (datatype == REC_CLOB))
+   {
+ 
+     short *lobNumList = new (STMTHEAP) short;
+     short *lobTypList = new (STMTHEAP) short;
+     char  **lobLocList = new (STMTHEAP) char*[1];
+     char **lobColNameList = new (STMTHEAP) char*[1];
+    
+     Int64 lobMaxSize =  CmpCommon::getDefaultNumeric(LOB_MAX_SIZE)*1024*1024;
+    
+    
+
+     lobNumList[0] = nacolArr.entries();
+     lobTypList[0] = (short)(pColDef->getLobStorage());
+     char * loc = new (STMTHEAP) char[1024];
+	  
+     const char* f = ActiveSchemaDB()->getDefaults().
+       getValue(LOB_STORAGE_FILE_DIR);
+	  
+     strcpy(loc, f);
+	  
+     lobLocList[0] = loc;
+     lobColNameList[0] = col_name;
+     char  lobHdfsServer[256] ; // max length determined by dfs.namenode.fs-limits.max-component-length(255)
+     memset(lobHdfsServer,0,256);
+     strncpy(lobHdfsServer,CmpCommon::getDefaultString(LOB_HDFS_SERVER),sizeof(lobHdfsServer)-1);
+     Int32 lobHdfsPort = (Lng32)CmpCommon::getDefaultNumeric(LOB_HDFS_PORT);
+      Int32 rc = sendAllControls(FALSE, FALSE, TRUE);
+      
+      Int64 objUID = getObjectUID(&cliInterface,
+                                  catalogNamePart.data(), schemaNamePart.data(), 
+                                  objectNamePart.data(),
+                                  COM_BASE_TABLE_OBJECT_LIT);
+      
+      ComString newSchName = "\"";
+      newSchName += catalogNamePart;
+      newSchName.append("\".\"");
+      newSchName.append(schemaNamePart);
+      newSchName += "\"";
+      NABoolean lobTrace=FALSE;
+      if (getenv("TRACE_LOB_ACTIONS"))
+        lobTrace=TRUE;
+      Int32 numLobs = 1;
+      
+      rc = SQL_EXEC_LOBddlInterface((char*)newSchName.data(),
+                                          newSchName.length(),
+                                          objUID,
+                                          numLobs,
+                                          LOB_CLI_CREATE,
+                                          lobNumList,
+                                          lobTypList,
+                                          lobLocList,
+                                          lobColNameList,
+                                          lobHdfsServer,
+                                          lobHdfsPort,
+                                          lobMaxSize,
+                                          lobTrace);
+      if (rc < 0)
+        {
+          // retrieve the cli diags here.
+          CmpCommon::diags()->mergeAfter(*(GetCliGlobals()->currContext()->getDiagsArea()));
+         
+          deallocEHI(ehi); 	   
+          processReturn();
+	   
+          return ;
+        }
+   }
+
+
 
   ULng32 maxColQual = nacolArr.getMaxTrafHbaseColQualifier();
 
@@ -13758,7 +13831,8 @@ TrafDesc *CmpSeabaseDDL::getSeabaseRoutineDesc(const NAString &catName,
                                       const NAString &objName)
 {
    TrafDesc *result = NULL;
-
+   NABoolean useLibBlobStore = FALSE;
+   
    if (switchCompiler(CmpContextInfo::CMPCONTEXT_TYPE_META))
      return NULL;
 
@@ -13771,12 +13845,13 @@ TrafDesc *CmpSeabaseDDL::getSeabaseRoutineDesc(const NAString &catName,
 
 
 TrafDesc *CmpSeabaseDDL::getSeabaseRoutineDescInternal(const NAString &catName,
-                                      const NAString &schName,
-                                      const NAString &objName)
+                                                       const NAString &schName,
+                                                       const NAString &objName
+                                                       )
 {
   Lng32 retcode = 0;
   Lng32 cliRC = 0;
-
+  
   TrafDesc *result;
   char query[4000];
   char buf[4000];
@@ -13803,20 +13878,23 @@ TrafDesc *CmpSeabaseDDL::getSeabaseRoutineDescInternal(const NAString &catName,
       return NULL;
     }
 
+ 
+    
+    
   str_sprintf(buf, "select udr_type, language_type, deterministic_bool,"
-  " sql_access, call_on_null, isolate_bool, param_style,"
-  " transaction_attributes, max_results, state_area_size, external_name,"
-  " parallelism, user_version, external_security, execution_mode,"
-  " library_filename, version, signature,  catalog_name, schema_name,"
-  " object_name"
-  " from %s.\"%s\".%s r, %s.\"%s\".%s l, %s.\"%s\".%s o "
-  " where r.udr_uid = %ld and r.library_uid = l.library_uid "
-  " and l.library_uid = o.object_uid for read committed access",
-       getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_ROUTINES,
-       getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_LIBRARIES,
-       getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_OBJECTS,
-       objectUID);
-
+                  " sql_access, call_on_null, isolate_bool, param_style,"
+                  " transaction_attributes, max_results, state_area_size, external_name,"
+                  " parallelism, user_version, external_security, execution_mode,"
+                  " library_filename, version, signature,  catalog_name, schema_name,"
+                  " object_name, redef_time,library_storage, l.library_uid"
+                  " from %s.\"%s\".%s r, %s.\"%s\".%s l, %s.\"%s\".%s o "
+                  " where r.udr_uid = %ld and r.library_uid = l.library_uid "
+                  " and l.library_uid = o.object_uid for read committed access",
+                  getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_ROUTINES,
+                  getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_LIBRARIES,
+                  getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_OBJECTS,
+                  objectUID);
+    
 
   cliRC = cliInterface.fetchRowsPrologue(buf, TRUE/*no exec*/);
   if (cliRC < 0)
@@ -13912,6 +13990,8 @@ TrafDesc *CmpSeabaseDDL::getSeabaseRoutineDescInternal(const NAString &catName,
   cliInterface.getPtrAndLen(20, ptr, len);
   char *libSch = new (STMTHEAP) char[len+1];    
   str_cpy_and_null(libSch, ptr, len, '\0', ' ', TRUE);
+  routineInfo->lib_sch_name = new (STMTHEAP) char[len+1];
+  str_cpy_and_null(routineInfo->lib_sch_name, ptr, len, '\0', ' ', TRUE);
   cliInterface.getPtrAndLen(21, ptr, len);
   char *libObj = new (STMTHEAP) char[len+1];    
   str_cpy_and_null(libObj, ptr, len, '\0', ' ', TRUE);
@@ -13925,6 +14005,29 @@ TrafDesc *CmpSeabaseDDL::getSeabaseRoutineDescInternal(const NAString &catName,
                    libSQLExtName.data(),
                    libSQLExtName.length(),
                    '\0', ' ', TRUE);
+  NAString naLibSch(libSch);
+ 
+  
+  
+  cliInterface.getPtrAndLen(22,ptr,len);
+  routineInfo->lib_redef_time = *(Int64 *)ptr;
+
+
+  cliInterface.getPtrAndLen(23, ptr, len);
+  routineInfo->lib_blob_handle = new (STMTHEAP) char[len+1];    
+  str_cpy_and_null(routineInfo->lib_blob_handle, ptr, len, '\0', ' ', TRUE);
+
+  cliInterface.getPtrAndLen(24,ptr,len);
+  routineInfo->lib_obj_uid= *(Int64 *)ptr;
+  
+  
+    
+  if ((routineInfo->lib_blob_handle[0] == '\0')|| (naLibSch  == NAString(SEABASE_MD_SCHEMA)))
+    {
+      routineInfo->lib_redef_time = -1;
+      routineInfo->lib_blob_handle=NULL;
+      routineInfo->lib_obj_uid = 0;
+    }  
   
   ComTdbVirtTableColumnInfo *paramsArray;
   Lng32 numParams;