Merge remote branch 'origin/pr/1721/head' into merge_1721
diff --git a/core/sqf/sqenvcom.sh b/core/sqf/sqenvcom.sh
index 6bbd089..987d519 100644
--- a/core/sqf/sqenvcom.sh
+++ b/core/sqf/sqenvcom.sh
@@ -61,6 +61,13 @@
 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
 
@@ -106,10 +113,10 @@
 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
 
@@ -201,6 +208,7 @@
 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 UDR_CACHE_LIBDIR=cached_libs
 
 
 if [[ "$HBASE_DISTRO" == "HDP" ]]; then
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 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
diff --git a/core/sqf/sql/scripts/genms b/core/sqf/sql/scripts/genms
index a06f360..53c23b0 100755
--- a/core/sqf/sql/scripts/genms
+++ b/core/sqf/sql/scripts/genms
@@ -168,21 +168,23 @@
 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 "UDR_CACHE_LIBDIR=cached_libs"
+
 echo ""
 echo "#creating sqllogs folder for capturing osim data"
 sqllogdir=$HOME/sqllogs
diff --git a/core/sqf/sql/scripts/install_local_hadoop b/core/sqf/sql/scripts/install_local_hadoop
index e035a1e..9a2376b 100755
--- a/core/sqf/sql/scripts/install_local_hadoop
+++ b/core/sqf/sql/scripts/install_local_hadoop
@@ -1375,6 +1375,11 @@
 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
diff --git a/core/sql/bin/SqlciErrors.txt b/core/sql/bin/SqlciErrors.txt
index 2cdf4a4..a5ce81c 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.
@@ -1328,7 +1328,7 @@
 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.
diff --git a/core/sql/cli/Cli.cpp b/core/sql/cli/Cli.cpp
index cef45b8..e6008e4 100644
--- a/core/sql/cli/Cli.cpp
+++ b/core/sql/cli/Cli.cpp
@@ -2203,6 +2203,14 @@
                 } 
             }
         }
+
+      // 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;
@@ -9548,7 +9556,7 @@
         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    , 
@@ -9567,7 +9575,7 @@
 	    
 	    if (rc)
 	      {
-		cliRC = 0;
+		cliRC = -1;
 		ComDiagsArea * da = &diags;
 		ExRaiseSqlError(currContext.exHeap(), &da, 
 			    (ExeErrorCode)(8442), NULL, &cliRC    , 
@@ -9663,7 +9671,7 @@
         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    , 
@@ -9712,7 +9720,7 @@
         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    , 
diff --git a/core/sql/cli/sqlcli.h b/core/sql/cli/sqlcli.h
index 00ae7b2..8f8dd42 100644
--- a/core/sql/cli/sqlcli.h
+++ b/core/sql/cli/sqlcli.h
@@ -1,4 +1,4 @@
-/**********************************************************************
+/*********************************************************************
 // @@@ START COPYRIGHT @@@
 //
 // Licensed to the Apache Software Foundation (ASF) under one
diff --git a/core/sql/comexe/ComTdb.h b/core/sql/comexe/ComTdb.h
index 59db8a7..67f2b7b 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 @@
                              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 @@
   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
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 @@
                      char *containerName,
                      char *externalPath,
                      char *librarySqlName,
-                     
+                     Int64 libraryRedefTime,
+                     char *libraryBlobHandle,
+                     char *librarySchName,
+                     Int32 libraryVersion,
                      char *runtimeOptions,
                      char *runtimeOptionDelimiters,
 
@@ -111,7 +114,10 @@
   containerName_(containerName),
   externalPath_(externalPath),
   librarySqlName_(librarySqlName),
-
+  libraryRedefTime_(libraryRedefTime),
+  libraryBlobHandle_(libraryBlobHandle),
+  librarySchName_(librarySchName),
+  libraryVersion_(libraryVersion),
   runtimeOptions_(runtimeOptions),
   runtimeOptionDelimiters_(runtimeOptionDelimiters),
 
@@ -206,6 +212,8 @@
   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 @@
   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 @@
     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 @@
       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
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 @@
     char *containerName,
     char *externalPath,
     char *librarySqlName,
-
+    Int64 libraryRedefTime,
+    char *libraryBlobHandle,
+    char *librarySchName,
+    Int32 libraryVersion,
     char *javaOptions,
     char *javaOptionDelimiters,
 
@@ -322,8 +325,12 @@
 
   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
 };
 
 
diff --git a/core/sql/common/ComMisc.cpp b/core/sql/common/ComMisc.cpp
index 387b309..3ea50d5 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,122 @@
 
   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 we will pass an actual userid.
+  //By default we assume DB__ROOT.
+  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 errno;
+             }
+               
+         }
+      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 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 errno;
+             }
+               
+         }
+     
+      
+    }
+  else
+    {
+      cachedLibPath = getenv("TRAF_HOME") ;
+      cachedLibPath += "/udr";
+      if ( stat(cachedLibPath, &statbuf) != 0)
+         {
+           if (mkdir(cachedLibPath,S_IRWXU|S_IRWXG|S_IRWXO))
+             {
+               return errno;
+             }
+               
+         }
+      cachedLibPath +=  "/"+ NAString("DB__ROOT") ;
+      if (stat(cachedLibPath, &statbuf) != 0)
+        {
+          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 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 errno;
+             }
+               
+         }
+     
+    }
+      
+  
+  
+  cachedLibName += libPrefix + "_" ;
+  cachedLibName += redefTimeString;
+  cachedLibName += libSuffix ;
+
+  return 0;
+  
+}
+
+
diff --git a/core/sql/common/ComMisc.h b/core/sql/common/ComMisc.h
index 1581489..d13832e 100644
--- a/core/sql/common/ComMisc.h
+++ b/core/sql/common/ComMisc.h
@@ -112,4 +112,9 @@
 //                   with underscore(_)
 NABoolean ComTrafReservedColName(const NAString &colName);
 
+// Converts a library name like myfile.jar or myfile.so to this format
+// $TRAF_HOME/$UDR_CACHE_LIBDIR/<user>|myfile_<redeftime>.jar|so 
+Int32 ComGenerateUdrCachedLibName(NAString libname,Int64 redeftime,NAString schemaName, NAString user, NAString&cachedLibName, NAString &cachedPathName );
+
+
 #endif // COMMISC_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 @@
 protected:
 };
 
+short ExExeUtilLobExtractLibrary(ExeCliInterface *cliInterface,char *libHandle, char *cachedLibName,ComDiagsArea *toDiags);
 #endif
 
 
diff --git a/core/sql/executor/ExExeUtilLoad.cpp b/core/sql/executor/ExExeUtilLoad.cpp
index 7c051c4..436f2d2 100644
--- a/core/sql/executor/ExExeUtilLoad.cpp
+++ b/core/sql/executor/ExExeUtilLoad.cpp
@@ -3288,6 +3288,45 @@
   return 0;
 }
 
+
+short ExExeUtilLobExtractLibrary(ExeCliInterface *cliInterface,char *libHandle, char *cachedLibName,ComDiagsArea *toDiags)
+{
+  char buf[strlen(cachedLibName) + strlen(libHandle)+200];
+  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,
diff --git a/core/sql/executor/ExUdr.cpp b/core/sql/executor/ExUdr.cpp
index 230aa42..45f90cc 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 @@
 
   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,65 @@
                      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();
+          Int32 err = 0;
+          if(ComGenerateUdrCachedLibName(libOrJarName.data(),
+                                         myTdb().getLibraryRedefTime(),
+                                         myTdb().getLibrarySchName(),
+                                         dummyUser,
+                                         cachedLibName, cachedLibPath))
+            {
+              NAString cachedFullName = cachedLibPath+"/"+cachedLibName;
+               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.
+          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 +1876,7 @@
 // - 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 +1897,7 @@
   {
     transIdToSend = stmtTransId;
   }
-  
+ 
 #ifdef UDR_DEBUG
   {
     char stmtTx[256];
@@ -1848,7 +1908,8 @@
     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 +1943,38 @@
       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(),
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 @@
   {
     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 @@
   // 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
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 @@
   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 @@
 
     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 @@
     container,
     path,
     librarySqlName,
-    
+    libraryRedefTime,
+    libraryBlobHandle,
+    librarySchName,
+    libraryVersion,
     runtimeOptions,
     runtimeOptionDelimiters,
     
@@ -1567,7 +1579,10 @@
                            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 @@
                        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 @@
   }
 
   if (metadata.getRoutineID() > 0)
-    generator->objectUids().insert(metadata.getRoutineID());
+    {
+      generator->objectUids().insert(metadata.getRoutineID());
+      generator->objectUids().insert(metadata.getLibObjUID());
+    }
 
   return result;
 }
diff --git a/core/sql/generator/Generator.cpp b/core/sql/generator/Generator.cpp
index df98a66..7d45497 100644
--- a/core/sql/generator/Generator.cpp
+++ b/core/sql/generator/Generator.cpp
@@ -2368,6 +2368,14 @@
    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  = 
diff --git a/core/sql/optimizer/NARoutine.cpp b/core/sql/optimizer/NARoutine.cpp
index 49df34f..591de2a 100644
--- a/core/sql/optimizer/NARoutine.cpp
+++ b/core/sql/optimizer/NARoutine.cpp
@@ -114,6 +114,11 @@
     , dataSource_             ("", heap)
     , fileSuffix_             ("", heap)
     , schemaVersionOfRoutine_ (COM_VERS_UNKNOWN)
+    , libRedefTime_(0)
+    , libBlobHandle_("",heap)
+    , libSchName_("",heap)
+    , libVersion_(1)
+    , libObjUID_(0)
     , objectOwner_            (0)
     , schemaOwner_            (0)
     , privInfo_               (NULL)
@@ -144,6 +149,11 @@
     , 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)
@@ -277,6 +287,11 @@
     , 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_)
@@ -360,6 +375,9 @@
     , 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)
@@ -397,6 +415,14 @@
   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)
   {
diff --git a/core/sql/optimizer/NARoutine.h b/core/sql/optimizer/NARoutine.h
index 0ffc83b..304b11f 100644
--- a/core/sql/optimizer/NARoutine.h
+++ b/core/sql/optimizer/NARoutine.h
@@ -177,11 +177,20 @@
   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; }  
   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; }  
@@ -250,6 +259,11 @@
   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_;
diff --git a/core/sql/optimizer/UdfDllInteraction.cpp b/core/sql/optimizer/UdfDllInteraction.cpp
index 79df4ae..b7444cb 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,70 @@
       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();
+      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 *)errNAString.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 +212,8 @@
        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());
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           C2
 -----------  ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 
+
           1  LOBH0000000200010189730973312766405019189730973325743020118212400522666936189020"TRAFODION"."LOB130"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
           2  LOBH0000000200010189730973312766405019189730973325822915418212400522668231546020"TRAFODION"."LOB130"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
           3  LOBH0000000200010189730973312766405019189730973325854670118212400522668551834020"TRAFODION"."LOB130"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
 
+
 --- 3 row(s) selected.
 >>
 >>
@@ -668,7 +670,9 @@
 >>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 @@
 >>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 @@
 >>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 @@
 >>
 >>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 @@
 >>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 @@
 >>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 @@
 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 @@
 >>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 @@
 >>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 @@
 >>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 @@
 
   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 @@
 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 @@
 
   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 @@
 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 @@
 
   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 @@
 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 @@
 >>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 @@
 >>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 @@
 
   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 @@
 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 @@
 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 @@
 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 @@
 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 @@
 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 @@
 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 @@
 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 @@
 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
diff --git a/core/sql/regress/tools/rgrCleanup b/core/sql/regress/tools/rgrCleanup
new file mode 100755
index 0000000..c99de5b
--- /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/*/$UDR_CACHE_LIBDIR/* 2>$NULL"
+rm -rf $TRAF_HOME/udr/*/$UDR_CACHE_LIBDIR/* 2>$NULL
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 @@
   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 *****"
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 @@
 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 @@
 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 @@
 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.
 >>
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 @@
 >>-- 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 @@
 
 --- 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;
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.
 >>
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"
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"
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 @@
  ('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 @@
 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)
diff --git a/core/sql/sqlcat/TrafDDLdesc.cpp b/core/sql/sqlcat/TrafDDLdesc.cpp
index e1d4597..29788c7 100644
--- a/core/sql/sqlcat/TrafDDLdesc.cpp
+++ b/core/sql/sqlcat/TrafDDLdesc.cpp
@@ -590,7 +590,8 @@
   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);
+ libSchName = (libSchName ? (char*)(((Space*)space)->convertToOffset(libSchName)) : NULL);
   params.pack(space);
 
   return TrafDesc::pack(space);
@@ -603,7 +604,8 @@
   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);
+  libSchName = (libSchName ? (char*)((char*)base - (Long)libSchName) : NULL);
   if (params.unpack(base, reallocator)) return -1;
 
   return TrafDesc::unpack(base, reallocator);
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 @@
   DescStructPtr priv_desc;
 
   Int64 routineDescFlags; // my flags
-
+  Int64 libRedefTime; 
+  char *libBlobHandle;
+  char *libSchName;
+  Int32 libVersion;
+  Int64 libObjUID;
   char filler[24];
 };
 
diff --git a/core/sql/sqlcomp/CmpDDLCatErrorCodes.h b/core/sql/sqlcomp/CmpDDLCatErrorCodes.h
index 8ecf17e..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 @@
                   , CAT_CATALOG_ALREADY_EXISTS                    = 1035
                   , CAT_CIRCULAR_PRIVS                            = 1036
                   , CAT_DEPENDENT_PRIV_EXISTS                     = 1037
-                  // unused                                       = 1038
+                  //unused                         = 1038
                   , CAT_PRIVILEGE_NOT_REVOKED                     = 1039
                   , CAT_SMD_CANNOT_BE_ALTERED                     = 1040
                   , CAT_PRIMARY_KEY_ALREADY_DEFINED               = 1041
diff --git a/core/sql/sqlcomp/CmpSeabaseDDL.h b/core/sql/sqlcomp/CmpSeabaseDDL.h
index 22ee692..dc0d63b 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDL.h
+++ b/core/sql/sqlcomp/CmpSeabaseDDL.h
@@ -412,7 +412,8 @@
        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 @@
 		  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 @@
      
   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 @@
 
   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,12 @@
 
   void dropSeabaseLibrary(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 +1344,7 @@
 
   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 +1504,24 @@
                   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);
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
index 79ed311..6aaa084 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
@@ -3735,7 +3735,8 @@
                                    Int64 & objectFlags,
                                    bool reportErrorNow,
                                    NABoolean checkForValidDef,
-                                   Int64 *createTime)
+                                   Int64 *createTime,
+                                   Int64 *redefTime)
 {
   Lng32 retcode = 0;
   Lng32 cliRC = 0;
@@ -3754,7 +3755,7 @@
     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 @@
   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 @@
       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 @@
 
  New method is called  initTrafMD.
 
+
 */
 
+
 void CmpSeabaseDDL::createSeabaseMDviews()
 {
   if (!ComUser::isRootUserID())
@@ -7318,14 +7328,14 @@
 
 }
 
+
 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 @@
   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 @@
     }
   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,39 @@
           // 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
+            {
+             
+                createSeabaseLibrary2(createLibraryParseNode, currCatName, 
+                                      currSchName);
+              
+      
+            }
         }
       else if (ddlNode->getOperatorType() == DDL_DROP_LIBRARY)
         {
           // drop seabase library
           StmtDDLDropLibrary * dropLibraryParseNode =
             ddlNode->castToStmtDDLNode()->castToStmtDDLDropLibrary();
-          
-          dropSeabaseLibrary(dropLibraryParseNode, currCatName, currSchName);
+            dropSeabaseLibrary(dropLibraryParseNode, currCatName, currSchName);
         }
        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
+             {
+               
+                alterSeabaseLibrary2(alterLibraryParseNode, currCatName, currSchName);
+             
+             }
          }
       else if (ddlNode->getOperatorType() == DDL_CREATE_ROUTINE)
         {
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 @@
   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,
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLinitraf.cpp b/core/sql/sqlcomp/CmpSeabaseDDLinitraf.cpp
index e5491aa..5c6773c 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLinitraf.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLinitraf.cpp
@@ -49,6 +49,7 @@
   IT_CREATE_SCHEMA_OBJECTS,
   IT_CREATE_MD_VIEWS,
   IT_CREATE_REPOS,
+  IT_CREATE_LIBRARIES,
   IT_CREATE_PRIVMGR_REPOS,
   IT_CREATE_LIBMGR,
   IT_STEP_FAILED,
@@ -528,25 +529,7 @@
                         }
                     } // 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);
@@ -683,7 +666,7 @@
                       return 0;
                     }
 
-                  setValuesInDWS(dws, IT_CREATE_PRIVMGR_REPOS,
+                  setValuesInDWS(dws, IT_CREATE_LIBRARIES,
                                  "Create Repository Tables: Completed", 0, TRUE,
                                  FALSE, TRUE, TRUE);
 
@@ -692,7 +675,62 @@
               } // 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;
+                    }
+                  // 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);
+
+                  return 0;
+                } // case 1
+              } // switch
+          }
+          break;
         case IT_CREATE_PRIVMGR_REPOS:
           {
             switch (dws->subStep())
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 @@
   {" primary key (library_uid) "},
   {" attribute hbase format "},
   {" ; "}
-};
+  };
+
 
 static const QString seabaseLibrariesUsageDDL[] =
 {
@@ -497,7 +498,7 @@
 
 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 @@
    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 @@
 #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 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[] =
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 @@
  {" 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,
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLroutine.cpp b/core/sql/sqlcomp/CmpSeabaseDDLroutine.cpp
index 29ef68e..1501661 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,246 @@
     }
  
   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)
+    {
+      deallocEHI(ehi); 
+      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,6 +654,7 @@
   return;
 }
 
+
 void CmpSeabaseDDL::dropSeabaseLibrary(StmtDDLDropLibrary * dropLibraryNode,
                                        NAString &currCatName, 
                                        NAString &currSchName)
@@ -564,6 +798,164 @@
   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)
@@ -697,6 +1089,26 @@
   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 +1139,7 @@
   Int32 objectOwnerID = SUPER_USER;
   Int32 schemaOwnerID = SUPER_USER;
   ComSchemaClass schemaClass;
-
+  NAString libSuffix, libPrefix;
   retcode = verifyDDLCreateOperationAuthorized(&cliInterface,
                                                SQLOperation::CREATE_ROUTINE,
                                                catalogNamePart,
@@ -780,14 +1192,20 @@
   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 +1222,15 @@
       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 +1259,27 @@
 
   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 +1421,293 @@
   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 ;
+      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;
-         }
+                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]
+            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();
-     }
+          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);
+      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;
+      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;
-     }
+      // 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 (validateRoutine(&cliInterface, 
-                         createRoutineNode->getJavaClassName(),
-                         createRoutineNode->getJavaMethodName(),
-                         externalPath,
-                         sigBuf,
-                         numJavaParam,
-                         createRoutineNode->getMaxResults(),
-                         optionalSig))
-     {
-       *CmpCommon::diags() << DgSqlCode(-1231)
-                           << DgString0(extRoutineName);
-       deallocEHI(ehi); 
-       processReturn();
-       return;
-     }
-  }
+      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;
+            }
+        }
+    }
+          
+
   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 +2041,7 @@
               numSqlParam, maxResultSets, optionalSig ? 1 : 0); 
              
   Lng32 cliRC = cliInterface->fetchRowsPrologue(query, TRUE/*no exec*/);
+  
   if (cliRC < 0)
   {
      cliInterface->retrieveSQLDiagnostics(CmpCommon::diags());
@@ -1602,9 +2142,11 @@
       *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];
@@ -1865,6 +2407,129 @@
   return (createLibmgrProcs(cliInterface));
 }
 
+
+short CmpSeabaseDDL::upgradeSeabaseLibmgr2(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 = '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,
+           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 = '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')",
+           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 = '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')",
+           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::dropSeabaseLibmgr(ExeCliInterface *cliInterface)
 {
     if (!ComUser::isRootUserID())
@@ -1925,3 +2590,568 @@
     }
   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;
+}
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 @@
 
 };
 
+/////////////////////////////////////////////////////////////////////
+//
+// 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
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp b/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
index cd785f6..ffe995d 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
@@ -5475,7 +5475,7 @@
       if (pColDef->getDefaultClauseStatus() != ElemDDLColDef::DEFAULT_CLAUSE_SPEC)
         {
           *CmpCommon::diags() << DgSqlCode(-CAT_DEFAULT_REQUIRED);
-
+          deallocEHI(ehi);
           processReturn();
 
           return;
@@ -5492,7 +5492,7 @@
           if (pDefVal->isNull()) 
             {
               *CmpCommon::diags() << DgSqlCode(-CAT_CANNOT_BE_DEFAULT_NULL_AND_NOT_NULL);
-
+              deallocEHI(ehi);
               processReturn();
 
               return;
@@ -5504,7 +5504,7 @@
   if (pColDef->getDefaultClauseStatus() == ElemDDLColDef::NO_DEFAULT_CLAUSE_SPEC)
     {
       *CmpCommon::diags() << DgSqlCode(-CAT_DEFAULT_REQUIRED);
-
+      deallocEHI(ehi);
       processReturn();
 
       return;
@@ -5513,7 +5513,7 @@
   if (pColDef->getSGOptions())
     {
       *CmpCommon::diags() << DgSqlCode(-1514);
-
+      deallocEHI(ehi);
       processReturn();
 
       return;
@@ -5606,11 +5606,12 @@
           *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 @@
       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();
 
@@ -13755,7 +13828,8 @@
                                       const NAString &objName)
 {
    TrafDesc *result = NULL;
-
+   NABoolean useLibBlobStore = FALSE;
+   
    if (switchCompiler(CmpContextInfo::CMPCONTEXT_TYPE_META))
      return NULL;
 
@@ -13768,12 +13842,13 @@
 
 
 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];
@@ -13800,20 +13875,23 @@
       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)
@@ -13909,6 +13987,8 @@
   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);
@@ -13922,6 +14002,29 @@
                    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;
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLupgrade.cpp b/core/sql/sqlcomp/CmpSeabaseDDLupgrade.cpp
index b2cea77..3871b4b 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 @@
   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
 //
@@ -313,8 +325,9 @@
   // interfaces for upgrading subsystems; OK to create on stack for
   // now as they are stateless
   CmpSeabaseUpgradeRepository upgradeRepository;
+  CmpSeabaseUpgradeLibraries upgradeLibraries;
   CmpSeabaseUpgradePrivMgr upgradePrivMgr;
-
+  
   ExeCliInterface cliInterface(STMTHEAP, 0, NULL,
     CmpCommon::context()->sqlSession()->getParentQid());
   ExpHbaseInterface * ehi = NULL;
@@ -323,8 +336,8 @@
     {
       // 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 +662,11 @@
 
 		  Int64 mdCurrMajorVersion;
 		  Int64 mdCurrMinorVersion;
+                  Int64 mdCurrUpdateVersion;
 		  retcode = validateVersions(&ActiveSchemaDB()->getDefaults(), ehi,
 					     &mdCurrMajorVersion,
-					     &mdCurrMinorVersion);
+					     &mdCurrMinorVersion,
+                                             &mdCurrUpdateVersion);
 
 		  deallocEHI(ehi);
 
@@ -668,10 +683,13 @@
 		      
 		      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 +712,18 @@
                                 {
                                   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 +1627,7 @@
           {
             if (NOT isReposUpgradeNeeded())
               {
-                mdui->setStep(UPGRADE_PRIV_MGR);
+                mdui->setStep(UPGRADE_LIBRARIES);
                 mdui->setSubstep(0);
                 break;
               }
@@ -1637,6 +1661,43 @@
           }
           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_LIBRARIES);
+                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 +1718,7 @@
 		    {
 		      *CmpCommon::diags() << DgSqlCode(-20123);
 
-		      mdui->setStep(UPGRADE_FAILED_RESTORE_OLD_REPOS);
+		      mdui->setStep(UPGRADE_FAILED_RESTORE_OLD_LIBRARIES);
 		      mdui->setSubstep(0);
 
 		      break;
@@ -1668,7 +1729,7 @@
 		    {
 		      cliInterface.retrieveSQLDiagnostics(CmpCommon::diags());
 
-		      mdui->setStep(UPGRADE_FAILED_RESTORE_OLD_REPOS);
+		      mdui->setStep(UPGRADE_FAILED_RESTORE_OLD_LIBRARIES);
 		      mdui->setSubstep(0);
 
 		      break;
@@ -1677,7 +1738,7 @@
 		  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 +1752,7 @@
 		    {
 		      cliInterface.retrieveSQLDiagnostics(CmpCommon::diags());
 		    
-		      mdui->setStep(UPGRADE_FAILED_RESTORE_OLD_REPOS);
+		      mdui->setStep(UPGRADE_FAILED_RESTORE_OLD_LIBRARIES);
 		      mdui->setSubstep(0);
 
 		      break;
@@ -1703,7 +1764,7 @@
                       (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 +1800,31 @@
               }
 	  }
 	  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 +1986,50 @@
               }
           }
           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 +2630,35 @@
 }
 
 // ----------------------------------------------------------------------------
+// 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)
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 @@
 // 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 @@
 
   {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 @@
 
 };
 
+
+
+
 //////////////////////////////////////////////////////////////
 // This struct is set up for V23 to V30 upgrade.
 //////////////////////////////////////////////////////////////
@@ -431,11 +569,11 @@
    "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 @@
     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 @@
   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 @@
 
 };
 
+//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
diff --git a/core/sql/sqlcomp/DefaultConstants.h b/core/sql/sqlcomp/DefaultConstants.h
index b9f0fe3..09ac553 100644
--- a/core/sql/sqlcomp/DefaultConstants.h
+++ b/core/sql/sqlcomp/DefaultConstants.h
@@ -3354,6 +3354,8 @@
   // 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)!
diff --git a/core/sql/sqlcomp/nadefaults.cpp b/core/sql/sqlcomp/nadefaults.cpp
index bd7e334..7f33f4a 100644
--- a/core/sql/sqlcomp/nadefaults.cpp
+++ b/core/sql/sqlcomp/nadefaults.cpp
@@ -2874,13 +2874,13 @@
 
   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"),   
 
@@ -3061,8 +3061,11 @@
   // 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"),