You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafodion.apache.org by sa...@apache.org on 2017/05/02 17:24:13 UTC

[3/7] incubator-trafodion git commit: Support for insert-select for tables containing LOB columns.

Support for insert-select for tables containing LOB columns.


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

Branch: refs/heads/master
Commit: b8cfdc87ec95694765ad2cd3ca892f95d0a1b5b2
Parents: f8c57fd
Author: Sandhya Sundaresan <sa...@apache.org>
Authored: Tue Apr 25 21:07:47 2017 +0000
Committer: Sandhya Sundaresan <sa...@apache.org>
Committed: Tue Apr 25 21:07:47 2017 +0000

----------------------------------------------------------------------
 core/sql/bin/clitest.cpp              |   2 +-
 core/sql/clitest/blobtest.cpp         |   4 +-
 core/sql/executor/ExExeUtilLoad.cpp   |   2 +-
 core/sql/exp/ExpLOB.cpp               |  65 ++--
 core/sql/exp/ExpLOB.h                 |  12 +-
 core/sql/exp/ExpLOBaccess.cpp         | 213 +++++++++++--
 core/sql/exp/ExpLOBaccess.h           |   9 +-
 core/sql/exp/ExpLOBenums.h            |   5 +-
 core/sql/exp/ExpLOBinterface.cpp      |  75 +++--
 core/sql/exp/ExpLOBinterface.h        |  34 ++-
 core/sql/generator/GenItemFunc.cpp    |   7 +-
 core/sql/generator/GenPreCode.cpp     |  52 ++--
 core/sql/optimizer/ItemFunc.h         |   2 +-
 core/sql/regress/executor/EXPECTED130 | 469 ++++++++++++-----------------
 core/sql/regress/executor/TEST130     |  37 ++-
 core/sql/sqlcomp/nadefaults.cpp       |   2 +-
 licenses/lic-pyinstall-src            |   4 +-
 17 files changed, 571 insertions(+), 423 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/b8cfdc87/core/sql/bin/clitest.cpp
----------------------------------------------------------------------
diff --git a/core/sql/bin/clitest.cpp b/core/sql/bin/clitest.cpp
index 137943a..caff696 100644
--- a/core/sql/bin/clitest.cpp
+++ b/core/sql/bin/clitest.cpp
@@ -204,7 +204,7 @@ int main(int argc, const char * argv[])
 	}
       cout << "LOB data length :" << lengthOfLob << endl;
       //extract lob data to buffer
-      cout << "Extracting lob data into file in chunks of 1000 ..." << endl;
+      cout << "Extracting lob data into file in chunks ..." << endl;
       retCode = extractLobToFileInChunks(cliGlob,lobHandle, filename, lengthOfLob,columnname,tablename);
       if (retcode)
 	{

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/b8cfdc87/core/sql/clitest/blobtest.cpp
----------------------------------------------------------------------
diff --git a/core/sql/clitest/blobtest.cpp b/core/sql/clitest/blobtest.cpp
index 843f05a..a9a457a 100644
--- a/core/sql/clitest/blobtest.cpp
+++ b/core/sql/clitest/blobtest.cpp
@@ -81,7 +81,7 @@ Int32 extractLobToBuffer(CliGlobals *cliglob, char * lobHandle, Int64 &lengthOfL
   char *lobFinalBuf = new char[lengthOfLob];
   char statusBuf[200] = {'\0'};
   Int32 statusBufLen = 0;
-  Int64 lobExtractLen = 1000;
+  Int64 lobExtractLen = 10000;
   char *lobDataBuf = new char[lobExtractLen];
   
   str_sprintf(query,"extract lobtobuffer(lob '%s', LOCATION %Ld, SIZE %Ld) ", lobHandle, (Int64)lobDataBuf, &lobExtractLen);
@@ -128,7 +128,7 @@ Int32 extractLobToFileInChunks(CliGlobals *cliglob,  char * lobHandle, char *fil
   
   char statusBuf[200] = {'\0'};
   Int32 statusBufLen = 0;
-  Int64 lobExtractLen = 1000;
+  Int64 lobExtractLen = 10000;
   char *lobDataBuf = new char[lobExtractLen];
   Int64 *inputOutputAddr = &lobExtractLen;
 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/b8cfdc87/core/sql/executor/ExExeUtilLoad.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtilLoad.cpp b/core/sql/executor/ExExeUtilLoad.cpp
index 6b8e6ac..c7129a9 100644
--- a/core/sql/executor/ExExeUtilLoad.cpp
+++ b/core/sql/executor/ExExeUtilLoad.cpp
@@ -3477,7 +3477,7 @@ short ExExeUtilLobUpdateTcb::work()
   if (lobTdb().getFromType() == ComTdbExeUtilLobUpdate::FROM_STRING_)
     so = Lob_Memory;
   else if (lobTdb().getFromType() == ComTdbExeUtilLobUpdate::FROM_EXTERNAL_)
-    so = Lob_External;
+    so = Lob_External_File;
   else if (lobTdb().getFromType() == ComTdbExeUtilLobUpdate::FROM_BUFFER_)  //Only this is supported
     so= Lob_Buffer;
   

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/b8cfdc87/core/sql/exp/ExpLOB.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/ExpLOB.cpp b/core/sql/exp/ExpLOB.cpp
index 447ce89..28cd1c1 100644
--- a/core/sql/exp/ExpLOB.cpp
+++ b/core/sql/exp/ExpLOB.cpp
@@ -743,18 +743,15 @@ ex_expr::exp_return_type ExpLOBiud::insertDesc(char *op_data[],
   else if (fromString() || fromLoad())
     so = Lob_Memory;
   else if (fromLob())
-    so = Lob_Foreign_Lob;
+    so = Lob_Lob;
+  else if (fromLobExternal())
+    so = Lob_External_Lob;
   else if (fromBuffer())
     so = Lob_Buffer;
   else if (fromExternal())
-    so = Lob_External;
+    so = Lob_External_File;
   else if (fromEmpty())
     {
-      /* str_cpy_all(result, lobHandle, handleLen);
-
-       getOperand(0)->setVarLength(handleLen, op_data[-MAX_OPERANDS]);
-      //we can return now - nothing to insert into the descriptors
-      return ex_expr::EXPR_OK; */
       so = Lob_Memory;
     }
 
@@ -784,7 +781,7 @@ ex_expr::exp_return_type ExpLOBiud::insertDesc(char *op_data[],
   // until SQL_EXEC_LOBcliInterface is changed to allow for unlimited
   // black box sizes, we have to prevent over-sized file names from
   // being stored
-  if ((so == Lob_External) && (lobLen > MAX_LOB_FILE_NAME_LEN))
+  if ((so == Lob_External_File) && (lobLen > MAX_LOB_FILE_NAME_LEN))
     {
       ExRaiseSqlError(h, diagsArea, 
 		      (ExeErrorCode)(8557));
@@ -803,7 +800,7 @@ ex_expr::exp_return_type ExpLOBiud::insertDesc(char *op_data[],
   char * lobData = NULL;
   lobData= new(h) char[lobLen];
   //send lobData only if it's a lob_file operation
-  if ((so == Lob_File) || (so == Lob_External))
+  if ((so == Lob_File) || (so == Lob_External_File) || (so == Lob_Lob) || (so == Lob_External_Lob))
     {
       str_cpy_and_null(lobData,op_data[1],lobLen,'\0',' ',TRUE);
       
@@ -828,6 +825,21 @@ ex_expr::exp_return_type ExpLOBiud::insertDesc(char *op_data[],
   else
     lobMaxSize = getLobMaxSize();
     
+  if ((so == Lob_Lob) || (so == Lob_External_Lob))
+    {
+      
+      rc = ExpLOBInterfaceInsertSelect
+        (getExeGlobals()->getExLobGlobal(), 
+         getLobHdfsServer(), getLobHdfsPort(),
+         tgtLobName, 
+         so,
+         lobStorageLocation(),lobStorageType(),
+         getExeGlobals()->lobGlobals()->xnId(),
+         handleLen, lobHandle,  &outHandleLen_, outLobHandle_,            
+         lobData, lobLen, blackBox_, blackBoxLen_,lobMaxSize, getLobMaxChunkMemSize(),getLobGCLimit()); 
+        
+    }
+else
   rc = ExpLOBInterfaceInsert
     (getExeGlobals()->getExLobGlobal(), 
      tgtLobName, 
@@ -931,9 +943,11 @@ ex_expr::exp_return_type ExpLOBiud::insertData(Lng32 handleLen,
         lobLen = getOperand(1)->getLength(op_data[1]- getOperand(1)->getVCIndicatorLength());  
     }
   char * lobData = NULL;
-  if (fromExternal())
+  if (fromExternal() || fromLob() || fromLobExternal())
     {
       //no need to insert any data. All data resides in the external file
+      // for external LOB and it has already been read/inserted during 
+      // ::insertDesc for insert from another  LOB
       return ex_expr::EXPR_OK;
     }
   if(fromFile())
@@ -965,11 +979,11 @@ ex_expr::exp_return_type ExpLOBiud::insertData(Lng32 handleLen,
   else if (fromString() || fromLoad())
     so = Lob_Memory;
   else if (fromLob())
-    so = Lob_Foreign_Lob;
+    so = Lob_Lob;
   else if(fromBuffer())
     so = Lob_Buffer;
   else if (fromExternal())
-    so = Lob_External;
+    so = Lob_External_File;
 
  
   Lng32 waitedOp = 0;
@@ -986,26 +1000,7 @@ ex_expr::exp_return_type ExpLOBiud::insertData(Lng32 handleLen,
 
   blackBoxLen_ = 0;
 
-  if (fromLob())
-    {
-      Int64 srcDescKey = -1;
-      Int64 srcDescTS = -1;
-      char srcLobNameBuf[100];
-      char * srcLobName = NULL;
-      short srcSchNameLen = 0;
-      char  srcSchName[500];
-      extractFromLOBhandle(NULL, &lobType, &lobNum, &uid,
-			   &srcDescKey, &srcDescTS, 
-			   &srcSchNameLen, srcSchName,
-			   op_data[1]);
-      
-      // get the lob name where data will be read from
-      srcLobName = ExpGetLOBname(uid, lobNum, srcLobNameBuf, 100);
-      if (srcLobName == NULL)
-	return ex_expr::EXPR_ERROR;
-    }
-  else
-    {
+  
       rc = ExpLOBInterfaceInsert(getExeGlobals()->getExLobGlobal(),
 				 tgtLobName, 
 				 lobStorageLocation(),
@@ -1029,7 +1024,7 @@ ex_expr::exp_return_type ExpLOBiud::insertData(Lng32 handleLen,
 				 lobLen,getLobMaxSize(),
                                  getLobMaxChunkMemSize(),
                                  getLobGCLimit());
-    }
+    
 
   if (rc == LOB_ACCESS_PREEMPT)
     {
@@ -1334,11 +1329,11 @@ ex_expr::exp_return_type ExpLOBupdate::eval(char *op_data[],
   else if (fromString())
     so = Lob_Memory;
   else if (fromLob())
-    so = Lob_Foreign_Lob;
+    so = Lob_Lob;
   else if (fromBuffer())
     so= Lob_Buffer;
   else if (fromExternal())
-    so = Lob_External;
+    so = Lob_External_File;
  
    
  

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/b8cfdc87/core/sql/exp/ExpLOB.h
----------------------------------------------------------------------
diff --git a/core/sql/exp/ExpLOB.h b/core/sql/exp/ExpLOB.h
index 296fe69..66f213c 100644
--- a/core/sql/exp/ExpLOB.h
+++ b/core/sql/exp/ExpLOB.h
@@ -488,6 +488,15 @@ class ExpLOBiud : public ExpLOBoper {
   {
     (v) ? liudFlags_ |= FROM_LOB: liudFlags_ &= ~FROM_LOB;
   };
+  NA_EIDPROC NABoolean fromLobExternal()
+  {
+    return ((liudFlags_ & FROM_LOB_EXTERNAL) != 0);
+  };
+
+  NA_EIDPROC inline void setFromLobExternal(NABoolean v)
+  {
+    (v) ? liudFlags_ |= FROM_LOB_EXTERNAL: liudFlags_ &= ~FROM_LOB_EXTERNAL;
+  };
 
   NA_EIDPROC NABoolean fromExternal()
   {
@@ -512,7 +521,8 @@ class ExpLOBiud : public ExpLOBoper {
     FROM_LOB           = 0x0010,
     FROM_EXTERNAL      = 0x0020,
     FROM_BUFFER        = 0x0040,
-    FROM_EMPTY         = 0x0080
+    FROM_EMPTY         = 0x0080,
+    FROM_LOB_EXTERNAL  = 0x0100
   };
 
   Lng32 liudFlags_;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/b8cfdc87/core/sql/exp/ExpLOBaccess.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/ExpLOBaccess.cpp b/core/sql/exp/ExpLOBaccess.cpp
index 27d5011..46b4c90 100644
--- a/core/sql/exp/ExpLOBaccess.cpp
+++ b/core/sql/exp/ExpLOBaccess.cpp
@@ -58,6 +58,7 @@
 #include "ExpLOBaccess.h"
 #include "ExpLOBinterface.h"
 #include "ExpLOBexternal.h"
+#include "ExpLOB.h"
 #include "NAVersionedObject.h"
 #include "ComQueue.h"
 #include "QRLogger.h"
@@ -803,7 +804,7 @@ Ex_Lob_Error ExLob::readExternalSourceFile(char *srcfile, char *&fileData, Int32
   return LOB_OPER_OK;
 }
 
-Ex_Lob_Error ExLob::writeDesc(Int64 &sourceLen, char *source, LobsSubOper subOper, Int64 &descNumOut, Int64 &operLen, Int64 lobMaxSize,Int64 lobMaxChunkMemSize,Int64 lobGCLimit, char * handleIn, Int32 handleInLen, char *blackBox, Int32 *blackBoxLen, char *handleOut, Int32 &handleOutLen, void *lobGlobals)
+Ex_Lob_Error ExLob::writeDesc(Int64 &sourceLen, char *source, LobsSubOper subOper, Int64 &descNumOut, Int64 &operLen, Int64 lobMaxSize,Int64 lobMaxChunkMemSize,Int64 lobGCLimit, char * handleIn, Int32 handleInLen, char *blackBox, Int32 *blackBoxLen, char *handleOut, Int32 &handleOutLen, Int64 xnId, void *lobGlobals)
 {
   Ex_Lob_Error err=LOB_OPER_OK; 
     Int64 dataOffset = 0;
@@ -813,8 +814,15 @@ Ex_Lob_Error ExLob::writeDesc(Int64 &sourceLen, char *source, LobsSubOper subOpe
     char logBuf[4096];
   
     lobDebugInfo("In ExLob::writeDesc",0,__LINE__,lobTrace_);
+    //if external lob input, make sure it resides in hdfs
+    if (subOper == Lob_External_File)
+      {
+       LobInputOutputFileType srcFileType = fileType(source);
+       if (srcFileType != HDFS_FILE)
+         return  LOB_SOURCE_FILE_READ_ERROR;
+      }
     // Calculate sourceLen for each subOper.
-    if ((subOper == Lob_File)||(subOper == Lob_External))
+    if ((subOper == Lob_File))
       {
 	err = statSourceFile(source, sourceLen); 
 	if (err != LOB_OPER_OK)
@@ -823,9 +831,9 @@ Ex_Lob_Error ExLob::writeDesc(Int64 &sourceLen, char *source, LobsSubOper subOpe
     if (sourceLen < 0 || sourceLen > lobMaxSize)
       {
 	return LOB_MAX_LIMIT_ERROR; //exceeded the size of the max lob size
-        //TBD trigger compaction
+        
       }
-    if (subOper != Lob_External) 
+    if (subOper != Lob_External_File) 
       {
         lobDebugInfo("Calling ExLob::allocateDesc",0,__LINE__,lobTrace_);
         err = allocateDesc((unsigned int)sourceLen, descNumOut, dataOffset, lobMaxSize, lobMaxChunkMemSize,handleIn, handleInLen, lobGCLimit,lobGlobals);
@@ -845,7 +853,7 @@ Ex_Lob_Error ExLob::writeDesc(Int64 &sourceLen, char *source, LobsSubOper subOpe
                                      &dataOffset, &sourceLen,
                                      &outDescPartnKey, &outDescSyskey, 
 				     0,
-				     0,lobTrace_);
+				     xnId,lobTrace_);
     if (clierr < 0 ) {
       str_sprintf(logBuf,"CLI LOB_CLI_INSERT returned error %d",clierr);
       lobDebugInfo(logBuf, 0,__LINE__,lobTrace_);
@@ -856,7 +864,7 @@ Ex_Lob_Error ExLob::writeDesc(Int64 &sourceLen, char *source, LobsSubOper subOpe
 }
 
 
-Ex_Lob_Error ExLob::insertDesc(Int64 offset, Int64 size,  char *handleIn, Int32 handleInLen,  char *handleOut, Int32 &handleOutLen, char *blackBox, Int32 blackBoxLen,void *lobGlobals) 
+Ex_Lob_Error ExLob::insertDesc(Int64 offset, Int64 size,  char *handleIn, Int32 handleInLen,  char *handleOut, Int32 &handleOutLen, char *blackBox, Int32 blackBoxLen,Int64 xnId, void *lobGlobals) 
 {
   
    Lng32 clierr;
@@ -880,7 +888,7 @@ Ex_Lob_Error ExLob::insertDesc(Int64 offset, Int64 size,  char *handleIn, Int32
                                      &offset, &size,
                                      &outDescPartnKey, &outDescSyskey, 
 				     0,
-				     0,lobTrace_);
+				     xnId,lobTrace_);
    str_sprintf(logBuf,"After LOB_CLI_INSERT: ChunkNum: OutSyskey:%Ld",
                chunkNum,outDescSyskey);
    lobDebugInfo(logBuf,0,__LINE__,lobTrace_);
@@ -903,7 +911,7 @@ Ex_Lob_Error ExLob::writeLobData(char *source, Int64 sourceLen, LobsSubOper subO
     Int32 allocMemSize = 0;
     Int64 inputSize = sourceLen;
     Int64 writeOffset = tgtOffset;
-    if (subOperation == Lob_External)
+    if (subOperation == Lob_External_File)
       return LOB_OPER_OK;
     while(inputSize > 0)
       {
@@ -973,7 +981,7 @@ Ex_Lob_Error ExLob::readToMem(char *memAddr, Int64 size,  Int64 &operLen,char *
        return err;
      }
    sizeToRead = MINOF(size,desc.getSize());
-   if (blackBox)
+   if (blackBox && blackBoxLen >0 )
      {
        
        // we have received the external data file name from the descriptor table
@@ -1082,7 +1090,103 @@ Ex_Lob_Error ExLob::readToFile(char *tgtFileName, Int64 tgtLength, Int64 &operLe
   return LOB_OPER_OK;
 }
 
-Ex_Lob_Error ExLob::append(char *data, Int64 size, LobsSubOper so, Int64 headDescNum, Int64 &operLen, Int64 lobMaxSize,Int64 lobMaxChunkMemSize, Int64 lobGCLimit, char *handleIn, Int32 handleInLen,  char * handleOut, Int32 &handleOutLen,void *lobGlobals)
+
+Ex_Lob_Error ExLob::insertSelect(ExLob *srcLobPtr,
+                                 char *handleIn,Int32 handleInLen,char *source,
+                                 Int64 sourceLen, Int64 &operLen,
+                                 Int64 lobMaxSize, Int64 lobMaxChunkMemLen,
+                                 Int64 lobGCLimit, char *blackBox, 
+                                 Int32 blackBoxLen,char *handleOut, 
+                                 Int32 &handleOutLen,LobsSubOper so, Int64 xnId,void *lobGlobals)
+{
+  Ex_Lob_Error err = LOB_OPER_OK;
+  Int32 cliRC;
+  Int16 flags;
+  Lng32  lobNum;
+  Int64 descNumOut,descNumIn,descSyskey = 0;
+  Int32 lobType = 0;
+  Int64 uid, inDescSyskey, descPartnKey;
+  short schNameLen;
+  char schName[1024];
+  Int64 inputLobDataLen = 0;
+  Int64 retOperLen = 0; 
+  Int64 dummy = 0;
+  char logBuf[4096];
+  char sourceHandle[LOB_HANDLE_LEN]  = {};
+ 
+  str_cpy_all(sourceHandle, source, sourceLen);
+
+  if (so == Lob_External_Lob)
+    {
+      ExLobDesc desc;
+      char extFileName[MAX_LOB_FILE_NAME_LEN+6];
+      Int64 extFileNameLen = 0;
+      // retrieve the external file name from the source log descriptor
+      err = getDesc(desc,sourceHandle,sourceLen,blackBox,&blackBoxLen,handleOut,handleOutLen,xnId);
+      if (err != LOB_OPER_OK)
+        return LOB_DESC_READ_ERROR;
+      // we have received the external data file name from the descriptor table
+      // replace the contents of the lobDataFile with this name      
+      str_cpy_all(extFileName, blackBox, blackBoxLen);
+      extFileNameLen = blackBoxLen;
+      // Now insert this into the target lob descriptor
+      
+      err = writeDesc(extFileNameLen, extFileName, Lob_External_File, descNumOut, 
+                      retOperLen, lobMaxSize, lobMaxChunkMemLen,lobGCLimit,
+                      handleIn,handleInLen,(char *)blackBox, &blackBoxLen,
+                      handleOut,handleOutLen,xnId,lobGlobals);
+ 
+      if (err != LOB_OPER_OK)
+        return err;
+      return err;
+    }
+  // First retrieve length of the lob pointed to by source (input handle) 
+  cliRC = SQL_EXEC_LOBcliInterface(sourceHandle, sourceLen,
+                                   NULL,NULL,NULL,NULL,
+                                   LOB_CLI_SELECT_LOBLENGTH,LOB_CLI_ExecImmed,
+                                   0,&inputLobDataLen, &dummy, &dummy,0,0,FALSE);
+  if (cliRC < 0)
+    {
+      str_sprintf(logBuf,"cli LOB_CLI_SElECT_LOBLENGTH returned :%d", cliRC);
+      lobDebugInfo(logBuf, 0,__LINE__,lobTrace_);   
+      return LOB_DESC_READ_ERROR;
+    }
+      		   
+  // Allocate memory to hold the lob data from the input lob handle
+  char *inputLobData = (char *)(getLobGlobalHeap()->allocateMemory(inputLobDataLen));
+  // retrieve the section/sections from the lob pointed to by the input handle
+  // into memory
+  err = srcLobPtr->readToMem(inputLobData, inputLobDataLen,retOperLen, 
+                             sourceHandle,sourceLen,
+                             blackBox, blackBoxLen,
+                             handleOut, handleOutLen,xnId);
+  if (err != LOB_OPER_OK)
+    return err;
+
+  
+  // write the lob data into the target lob 
+  
+
+  err = writeDesc(inputLobDataLen, inputLobData, Lob_Memory, descNumOut, retOperLen, lobMaxSize, lobMaxChunkMemLen,lobGCLimit,handleIn,handleInLen,(char *)blackBox, &blackBoxLen,handleOut,handleOutLen,xnId,lobGlobals);
+ 
+  if (err != LOB_OPER_OK)
+    return err;
+  if (handleOutLen > 0)
+    {
+      ExpLOBoper::extractFromLOBhandle(NULL, &lobType, NULL, NULL, &descSyskey,
+				       NULL, NULL, NULL, handleOut);
+      
+      ExpLOBoper::updLOBhandle(descSyskey, 0, handleIn); 
+    }
+
+  err =  insertData(inputLobData, inputLobDataLen, Lob_Memory, descNumIn, retOperLen, lobMaxSize,lobMaxChunkMemLen,handleIn,handleInLen,(char *)blackBox, blackBoxLen,handleOut,handleOutLen,lobGlobals);
+  
+  if (err != LOB_OPER_OK)
+    return err;
+  return LOB_OPER_OK;
+}
+
+Ex_Lob_Error ExLob::append(char *data, Int64 size, LobsSubOper so, Int64 headDescNum, Int64 &operLen, Int64 lobMaxSize,Int64 lobMaxChunkMemSize, Int64 lobGCLimit, char *handleIn, Int32 handleInLen,  char * handleOut, Int32 &handleOutLen,Int64 xnId,void *lobGlobals)
 {
     Ex_Lob_Error err = LOB_OPER_OK;
     Int64 dummyParam;
@@ -1095,7 +1199,7 @@ Ex_Lob_Error ExLob::append(char *data, Int64 size, LobsSubOper so, Int64 headDes
     char *blackBox = NULL;
     Int32 blackBoxLen = 0;
 
-    if (so ==Lob_External)
+    if (so ==Lob_External_File)
       {
         blackBox = data;
         blackBoxLen = (Int32)size;
@@ -1126,7 +1230,7 @@ Ex_Lob_Error ExLob::append(char *data, Int64 size, LobsSubOper so, Int64 headDes
                                       &dataOffset, &sourceLen,
                                       &outDescPartnKey, &outDescSyskey, 
 				      0,
-				      0,lobTrace_);
+				      xnId,lobTrace_);
     
     
     if (clierr < 0 || clierr == 100) { // some error or EOD.
@@ -1185,7 +1289,7 @@ Ex_Lob_Error ExLob::insertData(char *data, Int64 size, LobsSubOper so,Int64 head
     }
     return LOB_OPER_OK;
 }
-Ex_Lob_Error ExLob::update(char *data, Int64 size, LobsSubOper so,Int64 headDescNum, Int64 &operLen, Int64 lobMaxSize, Int64 lobMaxChunkMemSize, Int64 lobGCLimit, char *handleIn, Int32 handleInLen,  char *handleOut, Int32 &handleOutLen, void *lobGlobals)
+Ex_Lob_Error ExLob::update(char *data, Int64 size, LobsSubOper so,Int64 headDescNum, Int64 &operLen, Int64 lobMaxSize, Int64 lobMaxChunkMemSize, Int64 lobGCLimit, char *handleIn, Int32 handleInLen,  char *handleOut, Int32 &handleOutLen, Int64 xnId,void *lobGlobals)
 {
     Ex_Lob_Error err = LOB_OPER_OK;
     Int64 dummyParam;
@@ -1198,13 +1302,13 @@ Ex_Lob_Error ExLob::update(char *data, Int64 size, LobsSubOper so,Int64 headDesc
     char *blackBox = NULL;
     Int32 blackBoxLen = 0;
 
-    if (so == Lob_External)
+    if (so == Lob_External_File)
       {
         blackBox = data;
         blackBoxLen = (Int32)size;
       }
     lobDebugInfo("In ExLob::update",0,__LINE__,lobTrace_);
-    if ((so == Lob_File) || (so == Lob_External))
+    if ((so == Lob_File) || (so == Lob_External_File))
       {
         str_sprintf(logBuf,"Calling statSourceFile: source:%s, sourceLen: %Ld",
                data,sourceLen);
@@ -1213,7 +1317,7 @@ Ex_Lob_Error ExLob::update(char *data, Int64 size, LobsSubOper so,Int64 headDesc
 	if (err != LOB_OPER_OK)
 	  return err;
       }
-    if(so != Lob_External)
+    if(so != Lob_External_File)
       {
         if (sourceLen < 0 || sourceLen > lobMaxSize)
           {
@@ -1233,7 +1337,7 @@ Ex_Lob_Error ExLob::update(char *data, Int64 size, LobsSubOper so,Int64 headDesc
                                       &dataOffset, &sourceLen,
                                       &outDescPartnKey, &outDescSyskey, 
 				      0,
-				      0,lobTrace_);
+				      xnId,lobTrace_);
     
     if (clierr < 0 || clierr == 100) { // some error or EOD.
       
@@ -2435,11 +2539,13 @@ Ex_Lob_Error ExLobsOper (
       break;
 
     case Lob_InsertDesc:
-      err = lobPtr->writeDesc(sourceLen, source, subOperation, descNumOut, retOperLen, lobMaxSize, lobMaxChunkMemSize,lobGCLimit,handleIn,handleInLen,(char *)blackBox, &blackBoxLen,handleOut,handleOutLen,lobGlobals);
+      
+      err = lobPtr->writeDesc(sourceLen, source, subOperation, descNumOut, retOperLen, lobMaxSize, lobMaxChunkMemSize,lobGCLimit,handleIn,handleInLen,(char *)blackBox, &blackBoxLen,handleOut,handleOutLen,transId,lobGlobals);
       if (err != LOB_OPER_OK)
         {
           lobDebugInfo("writeDesc failed ",err,__LINE__,lobGlobals->lobTrace_);
         }
+        
       break;
 
     case Lob_InsertData:
@@ -2454,7 +2560,55 @@ Ex_Lob_Error ExLobsOper (
       err = lobPtr->writeDataSimple(source, sourceLen, subOperation, retOperLen,
 				    bufferSize , replication , blockSize);
       break;
+    case Lob_InsSel:
+      {
+        
+        ExLob *srcLobPtr;
+        Int16 flags;
+        Lng32  lobNum;
+        Int32 lobType;
+        Int64 uid, inDescSyskey, descPartnKey;
+        short schNameLen;
+        char schName[1024];
+        char sourceHandle[512]  = {};
+        str_cpy_all(sourceHandle, source, sourceLen);
+        ExpLOBoper::extractFromLOBhandle(&flags, &lobType, &lobNum, &uid,  
+                                   &inDescSyskey, &descPartnKey,
+                                   &schNameLen, schName,
+                                   sourceHandle); 
+        char srcLobNameBuf[100];
+        char * srcLobName = 
+          ExpLOBoper::ExpGetLOBname(uid, lobNum, srcLobNameBuf, 100);
+        lobMap_it it2;
+        it2 = lobMap->find(string(srcLobName));
+
+        if (it2 == lobMap->end())
+	{
+	  srcLobPtr = new (lobGlobals->getHeap())ExLob(lobGlobals->getHeap());
+	  if (srcLobPtr == NULL) 
+	    return LOB_ALLOC_ERROR;
+
+	  err = srcLobPtr->initialize(srcLobName, EX_LOB_RW, lobStorageLocation, storage, hdfsServer, hdfsPort, lobStorageLocation,bufferSize, replication, blockSize,lobMaxSize,lobGlobals);
+	  if (err != LOB_OPER_OK)
+            {
+              char buf[5000];
+              str_sprintf(buf,"Lob initialization failed;filename:%s;location:%s;hdfsserver:%s;hdfsPort:%d;lobMaxSize:%Ld",srcLobName,lobStorageLocation,hdfsServer,lobMaxSize);
+              lobDebugInfo(buf,err,__LINE__,lobGlobals->lobTrace_);
+              return err;
+            }
+
+	  lobMap->insert(pair<string, ExLob*>(string(srcLobName), srcLobPtr));
+	}
+      else	
+        srcLobPtr = it2->second;
 
+        err = lobPtr->insertSelect(srcLobPtr,handleIn, handleInLen, source, sourceLen, retOperLen, lobMaxSize, lobMaxChunkMemSize,lobGCLimit,(char *)blackBox, blackBoxLen,handleOut,handleOutLen,subOperation,transId, lobGlobals);
+        if (err != LOB_OPER_OK)
+          {
+            lobDebugInfo("insertSelect failed ",err,__LINE__,lobGlobals->lobTrace_);
+          }
+      }
+      break;
     case Lob_Read:
       if (storage == Lob_External_HDFS_File)   
         //Allocate storage to read the lob external file name from the 
@@ -2546,10 +2700,6 @@ Ex_Lob_Error ExLobsOper (
       if (lobPtr->hasNoOpenCursors()) {
 	lobGlobals->traceMessage("Lob_CloseFile",NULL,__LINE__);
 	err = lobPtr->closeFile();
-	it = lobMap->find(string(lobName));
-	lobMap->erase(it);
-	delete lobPtr;
-	lobPtr = NULL;
       }  
       break;
 
@@ -2572,9 +2722,9 @@ Ex_Lob_Error ExLobsOper (
       break;
 
     case Lob_Append:
-      if ((subOperation == Lob_Memory) ||(subOperation == Lob_Buffer) || (subOperation ==Lob_External))
+      if ((subOperation == Lob_Memory) ||(subOperation == Lob_Buffer) || (subOperation ==Lob_External_File))
         {
-          err = lobPtr->append(source, sourceLen, subOperation, descNumIn, retOperLen,lobMaxSize, lobMaxChunkMemSize,lobGCLimit,handleIn,handleInLen,handleOut,handleOutLen,lobGlobals);
+          err = lobPtr->append(source, sourceLen, subOperation, descNumIn, retOperLen,lobMaxSize, lobMaxChunkMemSize,lobGCLimit,handleIn,handleInLen,handleOut,handleOutLen,transId, lobGlobals);
           if (err != LOB_OPER_OK)
             {
               lobDebugInfo("append(Memory,Buffer) failed ",err,__LINE__,lobGlobals->lobTrace_);
@@ -2582,7 +2732,7 @@ Ex_Lob_Error ExLobsOper (
         }
       else if (subOperation == Lob_File)
         {
-          err = lobPtr->append(source, -1, subOperation, descNumIn, retOperLen,lobMaxSize, lobMaxChunkMemSize,lobGCLimit,handleIn,handleInLen,handleOut,handleOutLen,lobGlobals);
+          err = lobPtr->append(source, -1, subOperation, descNumIn, retOperLen,lobMaxSize, lobMaxChunkMemSize,lobGCLimit,handleIn,handleInLen,handleOut,handleOutLen,transId,lobGlobals);
           if (err != LOB_OPER_OK)
             {
               lobDebugInfo("append(File) failed ",err,__LINE__,lobGlobals->lobTrace_);
@@ -2593,9 +2743,9 @@ Ex_Lob_Error ExLobsOper (
       break;
 
     case Lob_Update:
-      if ((subOperation == Lob_Memory)||(subOperation == Lob_Buffer)||(subOperation ==Lob_External))
+      if ((subOperation == Lob_Memory)||(subOperation == Lob_Buffer)||(subOperation ==Lob_External_File))
         {
-          err = lobPtr->update(source, sourceLen, subOperation, descNumIn, retOperLen, lobMaxSize, lobMaxChunkMemSize,lobGCLimit,handleIn,handleInLen,handleOut,handleOutLen,lobGlobals);
+          err = lobPtr->update(source, sourceLen, subOperation, descNumIn, retOperLen, lobMaxSize, lobMaxChunkMemSize,lobGCLimit,handleIn,handleInLen,handleOut,handleOutLen,transId, lobGlobals);
           if (err != LOB_OPER_OK)
             {
               lobDebugInfo("update(Memory,Buffer) failed ",err,__LINE__,lobGlobals->lobTrace_);
@@ -2603,7 +2753,7 @@ Ex_Lob_Error ExLobsOper (
         }
       else if (subOperation == Lob_File)
         {
-          err = lobPtr->update(source, -1, subOperation,descNumIn, retOperLen,lobMaxSize, lobMaxChunkMemSize,lobGCLimit,handleIn,handleInLen,handleOut,handleOutLen,lobGlobals); 
+          err = lobPtr->update(source, -1, subOperation,descNumIn, retOperLen,lobMaxSize, lobMaxChunkMemSize,lobGCLimit,handleIn,handleInLen,handleOut,handleOutLen,transId,lobGlobals); 
           if (err != LOB_OPER_OK)
             {
               lobDebugInfo("update(Memory,Buffer) failed ",err,__LINE__,lobGlobals->lobTrace_);
@@ -3182,6 +3332,13 @@ ExLobGlobals::~ExLobGlobals()
            numWorkerThreads_--;
        }
     }
+
+    //Free the preOpenList AFTER the worker threads have left to avoid the 
+    //case where a slow worker thread is still processing a preOpen and 
+    //may access the preOpenList.
+    preOpenListLock_.lock();
+    preOpenList_.clear();
+    preOpenListLock_.unlock();
     // Free the post fetch bugf list AFTER the worker threads have left to 
     // avoid slow worker thread being stuck and master deallocating these 
     // buffers and not consuming the buffers which could cause a  lock.

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/b8cfdc87/core/sql/exp/ExpLOBaccess.h
----------------------------------------------------------------------
diff --git a/core/sql/exp/ExpLOBaccess.h b/core/sql/exp/ExpLOBaccess.h
index 3d981b4..7d97e19 100644
--- a/core/sql/exp/ExpLOBaccess.h
+++ b/core/sql/exp/ExpLOBaccess.h
@@ -413,7 +413,7 @@ class ExLob : public NABasicObject
                             int blocksize=0, Int64 lobMaxSize = 0, 
                             ExLobGlobals *lobGlobals = NULL);
 
-  Ex_Lob_Error writeDesc(Int64 &sourceLen, char *source, LobsSubOper subOperation, Int64 &descNumOut, Int64 &operLen, Int64 lobMaxSize, Int64 lobMaxChunkMemSize,Int64 lobGCLimit, char * handleIn, Int32 handleInLen, char *blackBox, Int32 *blackBoxLen, char * handleOut, Int32 &handleOutLen, void *lobGlobals);
+  Ex_Lob_Error writeDesc(Int64 &sourceLen, char *source, LobsSubOper subOperation, Int64 &descNumOut, Int64 &operLen, Int64 lobMaxSize, Int64 lobMaxChunkMemSize,Int64 lobGCLimit, char * handleIn, Int32 handleInLen, char *blackBox, Int32 *blackBoxLen, char * handleOut, Int32 &handleOutLen, Int64 xnId,void *lobGlobals);
     Ex_Lob_Error writeLobData(char *source, Int64 sourceLen, 
 			      LobsSubOper subOperation, 
 			      Int64 tgtOffset,Int64 &operLen, 
@@ -433,8 +433,9 @@ class ExLob : public NABasicObject
     Ex_Lob_Error deleteCursor(const char *cursorName, ExLobGlobals *lobGlobals);
   Ex_Lob_Error fetchCursor(char *handleIn, Int32 handleLenIn, Int64 &outOffset, Int64 &outSize,NABoolean &isEOD,Int64 transId);
   Ex_Lob_Error insertData(char *data, Int64 size, LobsSubOper so,Int64 headDescNum, Int64 &operLen, Int64 lobMaxSize, Int64 lobMaxChunkMemSize,char *handleIn,Int32 handleInLen, char *blackBox, Int32 blackBoxLen, char * handleOut, Int32 &handleOutLen, void *lobGlobals);
-  Ex_Lob_Error append(char *data, Int64 size, LobsSubOper so, Int64 headDescNum, Int64 &operLen, Int64 lobMaxSize, Int64 lobMaxChunkMemLen,Int64 lobGCLimit, char *handleIn,Int32 handleInLen, char * handleOut, Int32 &handleOutLen, void *lobGlobals);
-  Ex_Lob_Error update(char *data, Int64 size, LobsSubOper so,Int64 headDescNum, Int64 &operLen, Int64 lobMaxSize,Int64 lobMaxChunkMemLen,Int64 lobGCLimit,char *handleIn,Int32 handleInLen, char * handleOut, Int32 &handleOutLen, void *lobGlobals);
+  Ex_Lob_Error insertSelect(ExLob *srcLobPtr,char *handleIn,Int32 handleInLen, char *source, Int64 sourceLen, Int64 &operLen,Int64 lobMaxSize, Int64 lobMaxChunkMemLen,Int64 lobGCLimit, char *blackBox, Int32 blackBoxLen, char *handleOut, Int32 &handleOutLen,LobsSubOper so,Int64 xnId,void *lobGlobals);
+  Ex_Lob_Error append(char *data, Int64 size, LobsSubOper so, Int64 headDescNum, Int64 &operLen, Int64 lobMaxSize, Int64 lobMaxChunkMemLen,Int64 lobGCLimit, char *handleIn,Int32 handleInLen, char * handleOut, Int32 &handleOutLen, Int64 xnId,void *lobGlobals);
+  Ex_Lob_Error update(char *data, Int64 size, LobsSubOper so,Int64 headDescNum, Int64 &operLen, Int64 lobMaxSize,Int64 lobMaxChunkMemLen,Int64 lobGCLimit,char *handleIn,Int32 handleInLen, char * handleOut, Int32 &handleOutLen, Int64 xnId,void *lobGlobals);
   Ex_Lob_Error readSourceFile(char *srcfile, char *&fileData, Int32 &size, Int64 offset);
   Ex_Lob_Error readHdfsSourceFile(char *srcfile, char *&fileData, Int32 &size, Int64 offset);
   Ex_Lob_Error readLocalSourceFile(char *srcfile, char *&fileData, Int32 &size, Int64 offset);
@@ -454,7 +455,7 @@ class ExLob : public NABasicObject
   Ex_Lob_Error readStats(char *buffer);
   Ex_Lob_Error initStats();
   
-  Ex_Lob_Error insertDesc(Int64 offset, Int64 size,  char *handleIn, Int32 handleInLen,  char *handleOut, Int32 &handleOutLen, char *blackBox, Int32 blackBoxLen,void *lobGlobals) ;
+  Ex_Lob_Error insertDesc(Int64 offset, Int64 size,  char *handleIn, Int32 handleInLen,  char *handleOut, Int32 &handleOutLen, char *blackBox, Int32 blackBoxLen,Int64 xnId,void *lobGlobals) ;
   
   Ex_Lob_Error lockDesc();
   Ex_Lob_Error unlockDesc();

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/b8cfdc87/core/sql/exp/ExpLOBenums.h
----------------------------------------------------------------------
diff --git a/core/sql/exp/ExpLOBenums.h b/core/sql/exp/ExpLOBenums.h
index 3f46d37..d63a0e2 100644
--- a/core/sql/exp/ExpLOBenums.h
+++ b/core/sql/exp/ExpLOBenums.h
@@ -178,8 +178,9 @@ typedef enum {
    Lob_File,
    Lob_Memory,
    Lob_Buffer,
-   Lob_Foreign_Lob,
-   Lob_External
+   Lob_Lob, // tranfer from lob column of one table to another
+   Lob_External_Lob,//transfer from external lob of one table to another
+   Lob_External_File // link external hdfs file into traf lob column without an hdfs copy. 
 } LobsSubOper;
 
 typedef enum {

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/b8cfdc87/core/sql/exp/ExpLOBinterface.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/ExpLOBinterface.cpp b/core/sql/exp/ExpLOBinterface.cpp
index 4634eec..42a85c7 100644
--- a/core/sql/exp/ExpLOBinterface.cpp
+++ b/core/sql/exp/ExpLOBinterface.cpp
@@ -559,49 +559,66 @@ Lng32 ExpLOBInterfaceInsertSelect(void * exLobGlob,
 				  char * lobHdfsServer ,
 				  Lng32 lobHdfsPort ,
 				  char * tgtLobName,
+                                  LobsSubOper so,
 				  char * lobStorageLocation,
-				  
-				  Lng32 handleLen,
+                                  Int32 lobType,
+                                  Int64 xnId,
+				   Lng32 handleLen,
 				  char * lobHandle,
+                                  Int32 *outHandleLen,
+                                  char * outLobHandle,
+                                  char * lobData, 
+                                  Int64 lobLen,
+                                  char * blackBox,
+                                  Int64 blackBoxLen,
+                                  Int64 lobMaxSize,
+                                  Int64 lobMaxChunkMemSize ,
+                                  Int64 lobGCLimit ,
+                                  int    bufferSize ,
+                                  short  replication ,
+                                  int    blocksize
 				  
-				  Int64 &descSyskey,
-				  Int64 &lobLen,
-				  
-				  char * lobData, 
-				  
-				  char * srcLobName, 
-				  short srcDescSchNameLen,
-				  char * srcDescSchName,
-				  
-				  Int64 srcDescKey, 
-				  Int64 srcDescTS)
+				 )
 {
   Ex_Lob_Error err;
 
-  LobsSubOper lso = Lob_Foreign_Lob;
+  
   Ex_Lob_Error status;
   Int64 dummyParam=0;
   Int32 dummyParam2 = 0;
   Int64 cliError = -1;
-
+  LobsStorage ls = (LobsStorage)lobType;
+ 
   err = ExLobsOper(tgtLobName, 
 		   lobHandle, handleLen, 
-		   NULL, 0, // hdfs server/port
-                   NULL, dummyParam2, -1, descSyskey, lobLen,
-                   0, dummyParam, status, cliError, 
-		   lobStorageLocation, Lob_HDFS_File,
-		   lobData, lobLen, //strlen(srcLobData),
+		   lobHdfsServer, lobHdfsPort,
+                   outLobHandle, *outHandleLen,
+                   dummyParam, dummyParam,
+                   dummyParam,
+                   dummyParam, dummyParam,
+                   status,cliError,
+                   lobStorageLocation, ls, //Lob_HDFS_File,
+		   lobData, lobLen, 
 		   0,NULL,
-		   Lob_Insert,
-		   lso,
-                   1, 
+		   Lob_InsSel, 
+		   so,
+                   dummyParam,
 		   exLobGlob,
-		   0, NULL, 0
+		   xnId, 
+		   blackBox, blackBoxLen,
+		   lobMaxSize,
+		   lobMaxChunkMemSize,
+                   lobGCLimit,
+		   bufferSize,
+                   replication,
+                   blocksize
 		   );
-
-  if (err != LOB_OPER_OK)
+  if (err != LOB_OPER_OK) 
     return -err;
+    
 
+  
+  
   return 0;
 }
 
@@ -641,7 +658,7 @@ Lng32 ExpLOBInterfaceUpdateAppend(void * exLobGlob,
   Ex_Lob_Error status;
   Int64 cliError = -1;
   Int64 srcLen = 0;
-  if((so == Lob_Memory) || (so== Lob_External))
+  if((so == Lob_Memory) || (so== Lob_External_File))
     srcLen = strlen(srcLobData);
   else if (so == Lob_Buffer)
     srcLen = tgtLobLen;
@@ -711,7 +728,7 @@ Lng32 ExpLOBInterfaceUpdate(void * exLobGlob,
   Ex_Lob_Error status;
   Int64 cliError = -1;
   Int64 sourceLen = 0;
-  if((so == Lob_Memory) || (so == Lob_External))
+  if((so == Lob_Memory) || (so == Lob_External_File))
     sourceLen = strlen(srcLobData);
   else if (so == Lob_Buffer)
     sourceLen = tgtLobLen;
@@ -813,7 +830,7 @@ Lng32 ExpLOBInterfaceSelect(void * exLobGlob,
 			    Lng32 lobType,
 			    char * lobHdfsServer,
 			    Lng32 lobHdfsPort,
-
+                          
 			    Lng32 handleLen,
 			    char * lobHandle,
 			    Int64 &requestTag,

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/b8cfdc87/core/sql/exp/ExpLOBinterface.h
----------------------------------------------------------------------
diff --git a/core/sql/exp/ExpLOBinterface.h b/core/sql/exp/ExpLOBinterface.h
index 1d5dbaf..a8245c8 100644
--- a/core/sql/exp/ExpLOBinterface.h
+++ b/core/sql/exp/ExpLOBinterface.h
@@ -111,22 +111,30 @@ Lng32 ExpLOBinterfaceCloseFile(void * lobGlob,
 			       Lng32 lobType,
 			       char * lobHdfsServer ,
 			       Lng32 lobHdfsPort );
-Lng32 ExpLOBInterfaceInsertSelect(void * lobGlob, 
-				  char * lobHdfsServer,
+Lng32 ExpLOBInterfaceInsertSelect(void * exLobGlob, 
+				  char * lobHdfsServer ,
 				  Lng32 lobHdfsPort ,
 				  char * tgtLobName,
+                                  LobsSubOper so,
 				  char * lobStorageLocation,
-				  Lng32 handleLen,
+                                  Int32 lobType,
+                                  Int64 xnId,
+				   Lng32 handleLen,
 				  char * lobHandle,
-				  Int64 &descSyskey,
-				  Int64 &lobLen,
-				  char * lobData, 
-				  char * srcLobName, 
-				  short srcDescSchNameLen,
-				  char * srcDescSchName,
-				  
-				  Int64 srcDescKey, 
-				  Int64 srcDescTS);
+                                  Int32 * outHandleLen,
+                                  char * outLobHandle,
+                                  char * lobData,
+                                  Int64 lobDataLen,
+                                  char *blackBox,
+                                  Int64 blackBoxLen,
+                                  Int64 lobMaxSize,
+                                  Int64 lobMaxChunkMemSize ,
+                                  Int64 lobGCLimit ,
+                                  int    bufferSize = 0,
+                                  short  replication =0,
+                                  int    blocksize=0
+
+                                  );
 Lng32 ExpLOBInterfaceInsert(void * lobGlob, 
 			    char * tgtLobName,
 			    char * lobLocation,
@@ -243,7 +251,7 @@ Lng32 ExpLOBInterfaceSelect(void * lobGlob,
 			    Lng32  lobType,
 			    char * lobHdfsServer,
 			    Lng32 lobHdfsPort,
-
+                           
 			    Lng32 handleLen,
 			    char * lobHandle,
 			    Int64 &requestTag,

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/b8cfdc87/core/sql/generator/GenItemFunc.cpp
----------------------------------------------------------------------
diff --git a/core/sql/generator/GenItemFunc.cpp b/core/sql/generator/GenItemFunc.cpp
index 6e98065..c73ba9e 100644
--- a/core/sql/generator/GenItemFunc.cpp
+++ b/core/sql/generator/GenItemFunc.cpp
@@ -2874,7 +2874,12 @@ short LOBinsert::codeGen(Generator * generator)
   else if (obj_ == LOBoper::LOAD_)
     li->setFromLoad(TRUE);
   else if (obj_ == LOBoper::LOB_)
-    li->setFromLob(TRUE);
+    {
+      if (lobStorageType() != Lob_External_HDFS_File)
+        li->setFromLob(TRUE);
+      else
+        li->setFromLobExternal(TRUE);
+    }
   else if (obj_ == LOBoper::EXTERNAL_)
     li->setFromExternal(TRUE);
   else if (obj_ ==LOBoper::BUFFER_)

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/b8cfdc87/core/sql/generator/GenPreCode.cpp
----------------------------------------------------------------------
diff --git a/core/sql/generator/GenPreCode.cpp b/core/sql/generator/GenPreCode.cpp
index d96378d..cb0dbb6 100644
--- a/core/sql/generator/GenPreCode.cpp
+++ b/core/sql/generator/GenPreCode.cpp
@@ -5526,7 +5526,7 @@ RelExpr * HbaseInsert::preCodeGen(Generator * generator,
       setInsertType(Insert::SIMPLE_INSERT);
 
       NAColumnArray colArray;
-      NAColumn *col;
+      NAColumn *tgtCol, *srcCol;
 
       for (CollIndex ii = 0;
            ii < newRecExprArray().entries(); ii++)
@@ -5540,8 +5540,8 @@ RelExpr * HbaseInsert::preCodeGen(Generator * generator,
 	  ValueId srcValueId =
 	    assignExpr->child(1)->castToItemExpr()->getValueId();
 
-	  col = tgtValueId.getNAColumn( TRUE );
-	  
+	  tgtCol = tgtValueId.getNAColumn( TRUE );
+	  srcCol = srcValueId.getNAColumn( TRUE );
 	  ItemExpr * child1Expr = assignExpr->child(1);
 	  if (srcValueId.getType().isLob())
 	    {
@@ -5570,18 +5570,36 @@ RelExpr * HbaseInsert::preCodeGen(Generator * generator,
                   li->lobSize() = tgtValueId.getType().getPrecision();
 		  li->lobFsType() = tgtValueId.getType().getFSDatatype();
 
-		  li->lobNum() = col->lobNum();
+		  li->lobNum() = tgtCol->lobNum();
                   if ((child1Expr->getOperatorType() == ITM_CONSTANT) && 
                       !(((ConstValue *)child1Expr)->isNull()))
-                    if (li->lobStorageType() != col->lobStorageType())
+                    {
+                    if (srcCol->lobStorageType() != tgtCol->lobStorageType())
                       {
                         *CmpCommon::diags() << DgSqlCode(-1432)
-                                            << DgInt0((Int32)li->lobStorageType())
-                                            << DgInt1((Int32)col->lobStorageType())
-                                            << DgString0(col->getColName());
+                                            << DgInt0((Int32)srcCol->lobStorageType())
+                                            << DgInt1((Int32)tgtCol->lobStorageType())
+                                            << DgString0(tgtCol->getColName());
                         GenExit();
                       }
-		  li->lobStorageLocation() = col->lobStorageLocation();
+                    }
+                    else
+                      if ((child1Expr->getOperatorType() == ITM_BASECOLUMN)||
+                          (child1Expr->getOperatorType() == ITM_INDEXCOLUMN))
+                        {
+                          if (srcCol->lobStorageType() != tgtCol->lobStorageType())
+                            {
+                              *CmpCommon::diags() << DgSqlCode(-1432)
+                                                  << DgInt0((Int32)srcCol->lobStorageType())
+                                                  << DgInt1((Int32)tgtCol->lobStorageType())
+                                                  << DgString0(tgtCol->getColName());
+                              GenExit();
+                            }
+                          
+                        }
+                  li->lobStorageType() = tgtCol->lobStorageType();
+
+		  li->lobStorageLocation() = tgtCol->lobStorageLocation();
 
 		  li->bindNode(generator->getBindWA());
 
@@ -5606,22 +5624,22 @@ RelExpr * HbaseInsert::preCodeGen(Generator * generator,
 			   getTableName().getSchemaName());
 		  li->insertedTableSchemaName() += "\"";
 		  
-		  li->lobNum() = col->lobNum();
+		  li->lobNum() = tgtCol->lobNum();
                   //If we are initializing an empty_lob, assume the storage 
                   //type of the underlying column
                   if (li->lobStorageType() == Lob_Empty)
                     {
-                      li->lobStorageType() = col->lobStorageType();
+                      li->lobStorageType() = tgtCol->lobStorageType();
                     }
-                  if (li->lobStorageType() != col->lobStorageType())
+                  if (li->lobStorageType() != tgtCol->lobStorageType())
                     {
                       *CmpCommon::diags() << DgSqlCode(-1432)
                                           << DgInt0((Int32)li->lobStorageType())
-                                          << DgInt1((Int32)col->lobStorageType())
-                                          << DgString0(col->getColName());
+                                          << DgInt1((Int32)tgtCol->lobStorageType())
+                                          << DgString0(tgtCol->getColName());
                         GenExit();
                       }
-		  li->lobStorageLocation() = col->lobStorageLocation();
+		  li->lobStorageLocation() = tgtCol->lobStorageLocation();
 		  
 		  li->lobSize() = tgtValueId.getType().getPrecision();
 
@@ -5651,9 +5669,9 @@ RelExpr * HbaseInsert::preCodeGen(Generator * generator,
                       li->lobSize() = tgtValueId.getType().getPrecision();
 		      li->lobFsType() = tgtValueId.getType().getFSDatatype();
 
-		      li->lobNum() = col->lobNum();
+		      li->lobNum() = tgtCol->lobNum();
 		     
-		      li->lobStorageLocation() = col->lobStorageLocation();
+		      li->lobStorageLocation() = tgtCol->lobStorageLocation();
 		      
 		      li->bindNode(generator->getBindWA());
 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/b8cfdc87/core/sql/optimizer/ItemFunc.h
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/ItemFunc.h b/core/sql/optimizer/ItemFunc.h
index 388c81e..702d5b4 100644
--- a/core/sql/optimizer/ItemFunc.h
+++ b/core/sql/optimizer/ItemFunc.h
@@ -2875,7 +2875,7 @@ public:
      hdfsPort_((Lng32)CmpCommon::getDefaultNumeric(LOB_HDFS_PORT)),
      hdfsServer_( CmpCommon::getDefaultString(LOB_HDFS_SERVER))
    {
-     if ((obj == STRING_) || (obj == BUFFER_) || (obj == FILE_) )
+     if ((obj == STRING_) || (obj == BUFFER_) || (obj == FILE_) || (obj ==LOB_) )
        lobStorageType_ = Lob_HDFS_File;
      else if (obj == EXTERNAL_)
        lobStorageType_ = Lob_External_HDFS_File;