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 2016/01/08 20:11:27 UTC

[02/13] incubator-trafodion git commit: Recommitting the last commit. Some files did notget added. Context/changes are the same as earlier commit.

Recommitting the last commit. Some files did notget added. Context/changes are the same as earlier commit.


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

Branch: refs/heads/master
Commit: 5cfc9fa4e70eaeb041a03499fb2e7dd2fae7d28e
Parents: dd73284
Author: Sandhya Sundaresan <sa...@apache.org>
Authored: Wed Dec 9 22:39:20 2015 +0000
Committer: Sandhya Sundaresan <sa...@apache.org>
Committed: Wed Dec 9 22:39:20 2015 +0000

----------------------------------------------------------------------
 core/sql/bin/clitest.cpp                 |  91 +++++++++++++++++---
 core/sql/cli/Cli.cpp                     |  31 +++++--
 core/sql/cli/sqlcli.h                    |   5 +-
 core/sql/clitest/blobtest.cpp            |  86 +++++++++++++++----
 core/sql/clitest/blobtest.h              |   7 +-
 core/sql/comexe/ComTdbExeUtil.cpp        |  18 ++--
 core/sql/comexe/ComTdbExeUtil.h          |  27 ++++--
 core/sql/comexe/ComTdbRoot.h             |  14 ++-
 core/sql/executor/ExExeUtil.h            |   2 +-
 core/sql/executor/ExExeUtilCli.cpp       |  74 +++++++++++++++-
 core/sql/executor/ExExeUtilCli.h         |   6 +-
 core/sql/executor/ExExeUtilLoad.cpp      | 117 +++++++++++++++++---------
 core/sql/executor/ExHdfsScan.cpp         |   8 +-
 core/sql/exp/ExpLOBaccess.cpp            |   2 +-
 core/sql/exp/ExpLOBenums.h               |   1 +
 core/sql/exp/ExpLOBinterface.cpp         |   9 +-
 core/sql/exp/ExpLOBinterface.h           |   1 +
 core/sql/generator/GenRelExeUtil.cpp     |  11 ++-
 core/sql/generator/GenRelMisc.cpp        |   4 +
 core/sql/nskgmake/Makerules.linux        |   4 +-
 core/sql/nskgmake/clitest/Makefile       |   3 +-
 core/sql/nskgmake/clitestdriver/Makefile |   2 +-
 core/sql/optimizer/RelExeUtil.cpp        |   4 +-
 core/sql/optimizer/RelExeUtil.h          |  12 +--
 core/sql/parser/sqlparser.y              |  21 ++---
 25 files changed, 426 insertions(+), 134 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5cfc9fa4/core/sql/bin/clitest.cpp
----------------------------------------------------------------------
diff --git a/core/sql/bin/clitest.cpp b/core/sql/bin/clitest.cpp
index 78d347a..e88ee9d 100644
--- a/core/sql/bin/clitest.cpp
+++ b/core/sql/bin/clitest.cpp
@@ -66,25 +66,92 @@
 #include "Context.h"
 #include "blobtest.h"
 
-// DEFINE_DOVERS(clitest)
-
-int main()
+//DEFINE_DOVERS(clitestdriver)
+// 
+int main(int argc, const char * argv[])
 {
+
+  if ((argc < 2) || (argc > 2))
+    {
+      cout << "Error -  provide an option: " << endl;
+      cout << "Usage : clitestdriver <option number>" << endl;
+      cout << "TEST            : OPTION        "<<endl;
+      cout << "--------------------------------"<<endl;
+      cout << "Blob test          1 "<< endl;
+      return 0;
+    }
+  Int32 retcode = 0;
   SQLCTX_HANDLE defContext = 0;
   Lng32 retCode = SQL_EXEC_CreateContext(&defContext, NULL, 0);
+ 
+  int option = atoi(argv[1]);
 
-  if(retCode == 0){
-    cerr << "success -- new handle:" << defContext << endl;
-  }
-  else{
-    cerr << "error -- " << endl;
+  if(retcode != 0 )
+    cout << "Error creating a CLI context error " << endl;
    
-  }
+  
   CliGlobals * cliGlob = GetCliGlobals();
-  //extract length of blob column from a table with 1 lob column.
-  Int64 lengthOfLob= 0;
-  retCode = extractLengthOfBlobColumn(cliGlob, lengthOfLob,(char *)"c2",(char *)"tlob1");
+  char tablename[50] = {'\0'};
+  char columnname[50] = {'\0'};
  
+  switch (option) 
+    {
+    case 1:
+      {
+	cout <<"***********"  <<endl;
+	cout << "Blob test " << endl;
+	cout <<"***********"  <<endl;
+	cout << " Extract from a lob column in a lob table" << endl << endl;
+	cout << " Input lob table name :" << endl;
+	cin.getline(tablename,40);
+	cout << " Table name : " << tablename << endl;
+	cout << "Input lob column name to extract from :" << endl;
+	cin.getline(columnname,40); 
+	cout << "Column Name : " << columnname << endl;
+
+      //extract lob handle
+      
+      char *lobHandle = new char[1024];
+      str_cpy_all(lobHandle," ",1024);
+      cout << "Extracting  lob handle for column " << columnname << "..." << endl;
+      retcode = extractLobHandle(cliGlob, lobHandle, (char *)"c2",(char *)"tlob1");
+      if (retcode)
+	{
+	  cout << "extractLobHandle returned " << retcode <<endl;
+	
+	  delete lobHandle;
+	  return retcode;
+	}
+      cout << "LOB handle for "<< columnname << ": " << lobHandle << endl;
+      //extract length of lob column from a table with 1 lob column.
+
+      cout << "Extracting LOB data length for the above handle..." << endl;
+      Int64 lengthOfLob= 0;
+      retCode = extractLengthOfLobColumn(cliGlob, lobHandle, lengthOfLob,(char *)"c2",(char *)"tlob1");
+      if (retcode)
+	{
+	  cout << "extractLengthOfLobColumn returned " << retcode <<endl;
+	 
+	  delete lobHandle;
+	  return retcode;
+	}
+      cout << "LOB data length :" << lengthOfLob << endl;
+      //extract lob data to buffer
+      cout << "Extracting lob data into user buffer in a loop ..." << endl;
+      retCode = extractLobToBuffer(cliGlob,lobHandle, lengthOfLob,(char *)"c2",(char *)"tlob1");
+      if (retcode)
+	{
+	  cout << "extractLobToBuffer returned " << retcode <<endl;
+
+	  delete lobHandle;
+	  return retcode;
+	}
+      delete lobHandle;
+      return retcode;
+      }
+     
+      break;
+    }
   
   
   return 0;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5cfc9fa4/core/sql/cli/Cli.cpp
----------------------------------------------------------------------
diff --git a/core/sql/cli/Cli.cpp b/core/sql/cli/Cli.cpp
index ba733d1..58a77ba 100644
--- a/core/sql/cli/Cli.cpp
+++ b/core/sql/cli/Cli.cpp
@@ -7532,8 +7532,13 @@ Lng32 SQLCLI_Xact(/*IN*/ CliGlobals * cliGlobals,
         if ((currContext.getTransaction()->xnInProgress()) &&
             (currContext.getTransaction()->exeStartedXn()) &&
             (currContext.getTransaction()->autoCommit()))
-          {
-            currContext.getTransaction()->rollbackTransactionWaited();
+          {            
+	    retcode = currContext.getTransaction()->rollbackTransactionWaited();
+	    if (retcode)
+	      {
+		diags.mergeAfter(*(currContext.getTransaction()->getDiagsArea()));
+		return -1;
+	      }
           }
       }
       //LCOV_EXCL_STOP
@@ -7546,8 +7551,14 @@ Lng32 SQLCLI_Xact(/*IN*/ CliGlobals * cliGlobals,
 	    (currContext.getTransaction()->exeStartedXn()))
 	  {
 	    retcode = currContext.getTransaction()->commitTransaction();
+
             if (retcode)
-              return -1;
+	      {
+                diags.mergeAfter(*(currContext.getTransaction()->getDiagsArea()));
+                return -1;
+	      }
+              
+	  
 	  }
       }
       //LCOV_EXCL_STOP
@@ -7559,7 +7570,12 @@ Lng32 SQLCLI_Xact(/*IN*/ CliGlobals * cliGlobals,
 	if ((currContext.getTransaction()->xnInProgress()) &&
 	    (currContext.getTransaction()->exeStartedXn()))
 	  {
-	    currContext.getTransaction()->rollbackTransaction();
+	    retcode= currContext.getTransaction()->rollbackTransaction();
+            if (retcode)
+	      {
+                diags.mergeAfter(*(currContext.getTransaction()->getDiagsArea()));
+                return -1;
+              }
 	  }
       }
       //LCOV_EXCL_STOP
@@ -7570,7 +7586,12 @@ Lng32 SQLCLI_Xact(/*IN*/ CliGlobals * cliGlobals,
       {
 	if (! (currContext.getTransaction()->xnInProgress()))
 	  {
-	    currContext.getTransaction()->beginTransaction();
+	    retcode = currContext.getTransaction()->beginTransaction();
+            if (retcode)
+	      {
+		diags.mergeAfter(*(currContext.getTransaction()->getDiagsArea()));
+		return -1;
+	      }
 	  }
       }
       //LCOV_EXCL_STOP

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5cfc9fa4/core/sql/cli/sqlcli.h
----------------------------------------------------------------------
diff --git a/core/sql/cli/sqlcli.h b/core/sql/cli/sqlcli.h
index 8b9fba3..07338db 100644
--- a/core/sql/cli/sqlcli.h
+++ b/core/sql/cli/sqlcli.h
@@ -825,6 +825,7 @@ enum SQLATTRQUERY_TYPE {
      approach to extract data from SQL tables into extrenal files */
   SQL_SELECT_UNLOAD = 19
   
+  
 
 };
 
@@ -837,7 +838,9 @@ enum SQLATTR_SUBQUERY_TYPE
   SQL_DESCRIBE_QUERY = 4,
   SQL_DISPLAY_EXPLAIN = 5,
   SQL_STMT_HBASE_LOAD = 6,
-  SQL_STMT_HBASE_UNLOAD = 7
+  SQL_STMT_HBASE_UNLOAD = 7,
+  /* Used to denote lob access */
+  SQL_LOB_EXTRACT = 8
 };
 
 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5cfc9fa4/core/sql/clitest/blobtest.cpp
----------------------------------------------------------------------
diff --git a/core/sql/clitest/blobtest.cpp b/core/sql/clitest/blobtest.cpp
index 3955e2d..d7d700d 100644
--- a/core/sql/clitest/blobtest.cpp
+++ b/core/sql/clitest/blobtest.cpp
@@ -1,13 +1,30 @@
 #include "blobtest.h"
 
-Int32 extractLengthOfBlobColumn(CliGlobals *cliglob, Int64 &lengthOfLob, 
-				char *lobColumnName, char *tableName)
+Int32 extractLengthOfLobColumn(CliGlobals *cliglob, char *lobHandle, 
+			       Int64 &lengthOfLob, 
+			       char *lobColumnName, char *tableName)
+{
+  Int32 retcode = 0;
+  char * query = new char[4096];
+  ExeCliInterface cliInterface((cliglob->currContext())->exHeap(), (Int32)SQLCHARSETCODE_UTF8, cliglob->currContext(),NULL);
+  //Use lob handle to retrieve the lob length.
+  char lobLengthResult[200];
+  str_cpy_all(lobLengthResult," ",200);
+  Int32 lobLengthResultLen = 0;
+  str_sprintf(query,"extract loblength (lob '%s') LOCATION %Ld ",lobHandle, &lengthOfLob);
+  retcode = cliInterface.executeImmediate(query,lobLengthResult,&lobLengthResultLen,FALSE);
+
+  delete query;
+  return retcode;
+ 
+}
+
+Int32 extractLobHandle(CliGlobals *cliglob, char *& lobHandle, 
+		       char *lobColumnName, char *tableName)
 {
   Int32 retcode = 0;
   ExeCliInterface cliInterface((cliglob->currContext())->exHeap(), (Int32)SQLCHARSETCODE_UTF8, cliglob->currContext(),NULL);
   char * query = new char[4096];
-  char *lobHandle = new char[1024];
-  str_cpy_all(lobHandle," ",1024);
   Int32 lobHandleLen = 0;
   str_sprintf(query,"select %s from %s",lobColumnName,tableName);
   
@@ -16,23 +33,56 @@ Int32 extractLengthOfBlobColumn(CliGlobals *cliglob, Int64 &lengthOfLob,
   if (retcode)
     return retcode;
   lobHandle[lobHandleLen]='\0';
+  delete query;
+  
+  return retcode;
+ 
+}
 
-  //Use lob handle to retrieve the lob length.
-  char lobLengthResult[200];
-  str_cpy_all(lobLengthResult," ",200);
-  Int32 lobLengthResultLen = 0;
-  str_sprintf(query,"extract loblength (lob '%s')",lobHandle);
-  retcode = cliInterface.executeImmediate(query,lobLengthResult,&lobLengthResultLen,FALSE);
-
+Int32 extractLobToBuffer(CliGlobals *cliglob, char * lobHandle, Int64 &lengthOfLob, 
+				char *lobColumnName, char *tableName)
+{
+  Int32 retcode = 0;
+  ExeCliInterface cliInterface((cliglob->currContext())->exHeap(), (Int32)SQLCHARSETCODE_UTF8, cliglob->currContext(),NULL);
   // Extract lob data into a buffer.
-  char lobBuf[200];
-  str_cpy_all(lobBuf," ",200);
-  char lobBufStatus[200];
-  str_cpy_all(lobBufStatus," ",200);
-  Int32 lobBufStatusLen = 0;
+  char * query = new char [500];
+  
+  char *lobFinalBuf = new char[lengthOfLob];
+  char statusBuf[200] = {'\0'};
+  Int32 statusBufLen = 0;
+  Int64 lobExtractLen = 10;
+  char *lobDataBuf = new char[lobExtractLen];
+  
+  str_sprintf(query,"extract lobtobuffer(lob '%s', LOCATION %Ld, SIZE %Ld) ", lobHandle, (Int64)lobDataBuf, lobExtractLen);
+ 
+ 
+  retcode = cliInterface.executeImmediatePrepare(query);
+  short i = 0;
+  while ((retcode != 100) && !(retcode<0))
+    {    
+      retcode = cliInterface.clearExecFetchClose(NULL,NULL,statusBuf, &statusBufLen);
+      if (!retcode)
+	{
+	memcpy((char*)&(lobFinalBuf[i]),(char *)lobDataBuf,lobExtractLen);
+	i += lobExtractLen;
+	}
+    }
+  if (retcode ==100 || retcode ==0)
+    {
+      FILE * lobFileId = fopen("lob_output_file","w");
+  
+      int byteCount=fwrite(lobFinalBuf,sizeof(char),lengthOfLob, lobFileId);
+      cout << "Wrote " << byteCount << " bytes to file lob_output_file" << endl;
 
-  str_sprintf(query,"extract lobtobuffer(lob '%s', LOCATION (Int64)lobBuf, SIZE 4 ", lobHandle);
-  retcode = cliInterface.executeImmediate(query,lobBufStatus,&lobBufStatusLen,FALSE);
+      fclose(lobFileId);
+    }
+  delete  lobFinalBuf;
+  delete query;
+  delete lobDataBuf;
+    
 
   return retcode;
+
 }
+
+

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5cfc9fa4/core/sql/clitest/blobtest.h
----------------------------------------------------------------------
diff --git a/core/sql/clitest/blobtest.h b/core/sql/clitest/blobtest.h
index e5a9dc3..4ec96dc 100644
--- a/core/sql/clitest/blobtest.h
+++ b/core/sql/clitest/blobtest.h
@@ -28,5 +28,10 @@
 #include "ExExeUtil.h"
 #include "Globals.h"
 #include "Context.h"
+Int32 extractLobHandle(CliGlobals *cliglob, char *& lobHandle, 
+		       char *lobColumnName, char *tableName);
 
-Int32 extractLengthOfBlobColumn(CliGlobals *cliglob, Int64 &lengthOfLob,char *lobColumnName, char *tableName);
+Int32 extractLengthOfLobColumn(CliGlobals *cliglob, char * lobHandle, Int64 &lengthOfLob,char *lobColumnName, char *tableName);
+
+Int32 extractLobToBuffer(CliGlobals *cliglob, char * lobHandle, Int64 &lengthOfLob, 
+			 char *lobColumnName, char *tableName);

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5cfc9fa4/core/sql/comexe/ComTdbExeUtil.cpp
----------------------------------------------------------------------
diff --git a/core/sql/comexe/ComTdbExeUtil.cpp b/core/sql/comexe/ComTdbExeUtil.cpp
index 1463a07..773df33 100644
--- a/core/sql/comexe/ComTdbExeUtil.cpp
+++ b/core/sql/comexe/ComTdbExeUtil.cpp
@@ -2200,6 +2200,8 @@ ComTdbExeUtilLobExtract::ComTdbExeUtilLobExtract
  char * handle,
  Lng32 handleLen,
  ExtractToType toType,
+ Int64 bufAddr,
+ Int64 extractSize,
  Int64 intParam1,
  Int64 intParam2,
  Lng32 lobStorageType,
@@ -2231,28 +2233,32 @@ ComTdbExeUtilLobExtract::ComTdbExeUtilLobExtract
     handle_(handle),
     handleLen_(handleLen),
     toType_((short)toType),
+    bufAddr_(bufAddr),
+    extractSize_(extractSize),
     lobStorageType_(lobStorageType),
     stringParam1_(stringParam1),
     stringParam2_(stringParam2),
     stringParam3_(stringParam3),
     lobHdfsServer_(lobHdfsServer),
     lobHdfsPort_(lobHdfsPort),
-    rowSize_(0),
-    bufSize_(0),
+    totalBufSize_(0),
     flags_(0)
 {
   setNodeType(ComTdb::ex_LOB_EXTRACT);
   if ((toType_ == ExtractToType::TO_BUFFER_) || (toType_ == ExtractToType::TO_STRING_))
     {
-      // intparam1 contains the rowsize passed in via syntax
+      /*// intparam1 contains the rowsize passed in via syntax
       // intparam2 constains the total buf size user has allocated
       rowSize_ = intParam1;
-      bufSize_ = intParam2;
+      bufSize_ = intParam2; */
+      
     }
     else if (toType_ == ExtractToType::TO_FILE_)
       {
-	// rowSize_ is irrelevant since the whole lob will be read into the output file
-	// bufSize_ is not passed in by user. It is a CQD value LOB_OUTPUT_SIZE
+	// extractSize_ is irrelevant since the whole lob will be read into the output file
+	// bufAddr_ is not passed in by user. It is a CQD value LOB_OUTPUT_SIZE
+	extractSize_ = 0;
+	bufAddr_ = 0;
 	
       }
 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5cfc9fa4/core/sql/comexe/ComTdbExeUtil.h
----------------------------------------------------------------------
diff --git a/core/sql/comexe/ComTdbExeUtil.h b/core/sql/comexe/ComTdbExeUtil.h
index 8389bcc..afe1a69 100644
--- a/core/sql/comexe/ComTdbExeUtil.h
+++ b/core/sql/comexe/ComTdbExeUtil.h
@@ -2655,7 +2655,7 @@ public:
   enum ExtractToType
   {
     TO_FILE_, TO_STRING_, TO_BUFFER_, TO_EXTERNAL_FROM_STRING_,
-    TO_EXTERNAL_FROM_FILE_,  NOOP_
+    TO_EXTERNAL_FROM_FILE_, RETRIEVE_LENGTH_,NOOP_
   };
   
 
@@ -2668,8 +2668,10 @@ public:
      char * handle,
      Lng32 handleLen,
      ExtractToType toType,
-     Int64 size,
-     Int64 size2,
+     Int64 bufAddr,
+     Int64 extractSize,
+     Int64 intParam1,
+     Int64 intParam2,
      Int32 lobStorageType,
      char * stringParam1,
      char * stringParam2,
@@ -2702,7 +2704,7 @@ public:
   Lng32 getLobHdfsPort() { return lobHdfsPort_; }
 
   ExtractToType getToType() { return (ExtractToType)toType_; }
-
+ 
   // ---------------------------------------------------------------------
   // Redefine virtual functions required for Versioning.
   //----------------------------------------------------------------------
@@ -2751,9 +2753,13 @@ public:
   {(v ? flags_ |= APPEND_OR_CREATE : flags_ &= ~APPEND_OR_CREATE); };
   NABoolean appendOrCreate() { return (flags_ & APPEND_OR_CREATE) != 0; };
 
-  void setRowSize(Int64 rowSize) { rowSize_ = rowSize; };
-  void setBufSize(Int64 bufSize) { bufSize_ = bufSize;};
-  
+  void setExtractSize(Int64 extractSize) { extractSize_ = extractSize; };
+  Int64 getExtractSize() { return extractSize_;}
+  void setTotalBufSize(Int64 bufSize) { totalBufSize_ = bufSize;};
+  Int64 getTotalBufSize() { return totalBufSize_;};
+  void setBufAddr(Int64 bufAddr) {bufAddr_ = bufAddr;};
+  Int64 getBufAddr() { return bufAddr_;};
+
 private:
   enum
   {
@@ -2773,8 +2779,11 @@ private:
   short toType_;                                           // 08-09
   Int32 flags_;    
   Lng32 handleLen_;
-  Int64 rowSize_; // row size
-  Int64 bufSize_; // buf size
+  Int64 extractSize_; // as passed in via syntax size
+  Int64 totalBufSize_; // buf size
+  Int64 bufAddr_ ; //buffer addressed as passed in by user via syntax
+  Int64 intParam1_;
+  Int64 intParam2_;
   Lng32 lobStorageType_ ; // valid when  extract is from a file.
   Lng32 lobHdfsPort_;
   NABasicPtr lobHdfsServer_;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5cfc9fa4/core/sql/comexe/ComTdbRoot.h
----------------------------------------------------------------------
diff --git a/core/sql/comexe/ComTdbRoot.h b/core/sql/comexe/ComTdbRoot.h
index e6d4d78..f7662fe 100644
--- a/core/sql/comexe/ComTdbRoot.h
+++ b/core/sql/comexe/ComTdbRoot.h
@@ -362,7 +362,8 @@ class ComTdbRoot : public ComTdb
     HDFS_ACCESS                 = 0x00000008,
     EXE_UTIL_RWRS              = 0x00000010,
     EMBEDDED_COMPILER          = 0x00000020,
-    HIVE_ACCESS                = 0x00000040
+    HIVE_ACCESS                = 0x00000040,
+    EXE_LOB_ACCESS             = 0x00000080
   };
 
   // Use these values in 16-bit rtFlags3_
@@ -628,7 +629,8 @@ public:
     SQL_DESCRIBE_QUERY = 4,
     SQL_DISPLAY_EXPLAIN = 5,
     SQL_STMT_HBASE_LOAD = 6,
-    SQL_STMT_HBASE_UNLOAD = 7
+    SQL_STMT_HBASE_UNLOAD = 7,
+    SQL_STMT_LOB_EXTRACT = 8
    };
   
   ComTdbRoot();
@@ -843,7 +845,9 @@ public:
 
    NABoolean isEmbeddedCompiler() const
     {return ((rtFlags2_ & EMBEDDED_COMPILER) != 0);};
- 
+    NABoolean isLobExtract() const
+    {return ((rtFlags2_ & EXE_LOB_ACCESS) != 0);};
+
   char * getSnapshotScanTempLocation () { return snapshotscanTempLocation_; }
   Queue * getListOfSnapshotScanTables() { return listOfSnapshotScanTables_; }
 
@@ -997,6 +1001,10 @@ public:
     { 
       (v ? rtFlags2_ |= EMBEDDED_COMPILER : rtFlags2_ &= ~EMBEDDED_COMPILER); 
     }
+  void setLobAccess(NABoolean v)
+    { 
+      (v ? rtFlags2_ |= EXE_LOB_ACCESS : rtFlags2_ &= ~EXE_LOB_ACCESS); 
+    }
   NABoolean hdfsAccess() const
     {return ((rtFlags2_ & HDFS_ACCESS) != 0);};
  

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5cfc9fa4/core/sql/executor/ExExeUtil.h
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtil.h b/core/sql/executor/ExExeUtil.h
index 61fd4b9..42e04bc 100755
--- a/core/sql/executor/ExExeUtil.h
+++ b/core/sql/executor/ExExeUtil.h
@@ -2947,7 +2947,7 @@ public:
   Lng32 lobType_;
   char * lobData_;
   char * lobData2_;
-  Int64 lobDataExtractLen_;
+  Int64 lobDataSpecifiedExtractLen_;
   Int64 lobDataLen_;
   Lng32 remainingBytes_;
   Lng32 currPos_;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5cfc9fa4/core/sql/executor/ExExeUtilCli.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtilCli.cpp b/core/sql/executor/ExExeUtilCli.cpp
index 13cfdb1..89d462e 100644
--- a/core/sql/executor/ExExeUtilCli.cpp
+++ b/core/sql/executor/ExExeUtilCli.cpp
@@ -759,7 +759,8 @@ Lng32 ExeCliInterface::getPtrAndLen(short entry, char* &ptr, Lng32 &len, short**
   if (datatype == REC_BYTE_V_ASCII ||
       datatype == REC_BYTE_V_ASCII_LONG ||
       datatype == REC_BYTE_V_DOUBLE ||
-      datatype == SQLTYPECODE_VARCHAR_WITH_LENGTH)
+      datatype == SQLTYPECODE_VARCHAR_WITH_LENGTH ||
+      datatype == SQLTYPECODE_VARCHAR_LONG)
     {
 
       // Depending on value of len, first 2 or 4 bytes of data indicate
@@ -1048,6 +1049,77 @@ Lng32 ExeCliInterface::executeImmediateExec(const char * stmtStr,
   return ((cliRetcode != -1) ? cliRetcode : retcode);
 }
 
+
+Lng32 ExeCliInterface::executeImmediateExecNoDealloc(const char * stmtStr,
+					   char * outputBuf,
+					   Lng32 * outputBufLen,
+					   NABoolean nullTerminate,
+					   Int64 * rowsAffected 
+					   )
+{
+  Lng32 retcode = 0;
+
+  retcode = exec();
+  if (retcode < 0)
+    {
+      deallocStuff(module_, stmt_, sql_src_, input_desc_, output_desc_);
+      return retcode;
+    }
+
+  retcode = fetch();
+  if (retcode < 0)
+    {
+      deallocStuff(module_, stmt_, sql_src_, input_desc_, output_desc_);
+      return retcode;
+    }
+
+  if ((outputBuf) &&
+      (outputBufLen))
+    {
+      *outputBufLen = 0;
+      if (retcode != 100)
+	{
+	  char * ptr;
+	  Lng32 len;
+	  getPtrAndLen(1, ptr, len);
+
+	  str_cpy_all(outputBuf, ptr, len);
+	  
+	  if (nullTerminate)
+	    outputBuf[len] = 0;
+	  *outputBufLen = len;
+	}
+    }
+
+  Lng32 cliRetcode = -1;
+  if (retcode >= 0)
+  {
+    cliRetcode = retcode;
+    if (rowsAffected)
+    {
+      Int64 tmpRowsAffected = 0;
+      retcode = SQL_EXEC_GetDiagnosticsStmtInfo2(NULL, SQLDIAG_ROW_COUNT,
+        &tmpRowsAffected, NULL,
+        0, NULL);
+
+      if(retcode == EXE_NUMERIC_OVERFLOW) 
+      {
+        GetRowsAffected(rowsAffected);
+      }
+      else
+        *rowsAffected = tmpRowsAffected;
+    }
+  }
+
+  clearGlobalDiags();
+
+  retcode = close();
+
+  /*deallocStuff(module_, stmt_, sql_src_, input_desc_, output_desc_);
+
+  clearGlobalDiags();*/
+  return ((cliRetcode != -1) ? cliRetcode : retcode);
+}
 Lng32 ExeCliInterface::executeImmediate(const char * stmtStr,
 				       char * outputBuf,
 				       Lng32 * outputBufLen,

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5cfc9fa4/core/sql/executor/ExExeUtilCli.h
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtilCli.h b/core/sql/executor/ExExeUtilCli.h
index 73e3a1c..b94c61b 100644
--- a/core/sql/executor/ExExeUtilCli.h
+++ b/core/sql/executor/ExExeUtilCli.h
@@ -100,7 +100,11 @@ private:
                             Lng32 * outputBufLen = NULL,
                             NABoolean nullTerminate = TRUE,
                             Int64 * rowsAffected = NULL);
-
+  Lng32 executeImmediateExecNoDealloc(const char * stmt,
+                            char * outputBuf = NULL,
+                            Lng32 * outputBufLen = NULL,
+                            NABoolean nullTerminate = TRUE,
+                            Int64 * rowsAffected = NULL);
   Lng32 prepare(const char * stmtStr,
 		SQLMODULE_ID * module,
 		SQLSTMT_ID * stmt,

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5cfc9fa4/core/sql/executor/ExExeUtilLoad.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtilLoad.cpp b/core/sql/executor/ExExeUtilLoad.cpp
index 0d36135..07d7902 100644
--- a/core/sql/executor/ExExeUtilLoad.cpp
+++ b/core/sql/executor/ExExeUtilLoad.cpp
@@ -2621,7 +2621,7 @@ ExExeUtilLobExtractTcb::ExExeUtilLobExtractTcb
   lobData_= NULL;
   lobData2_= NULL;
 
-  lobDataExtractLen_ = 0; // default. Actual value set from tdb below
+  lobDataSpecifiedExtractLen_ = 0; // default. Actual value set from tdb below
   lobDataLen_= 0;
   
   remainingBytes_= 0;
@@ -2639,9 +2639,9 @@ short ExExeUtilLobExtractTcb::work()
 {
   Lng32 cliRC = 0;
   Lng32 retcode = 0;
-  Int64 lobDataLen = 0;
-  Int64 outLobLen = 0;
+  Int64 lobDataOutputLen = 0;
   Int64 requestTag = -1;
+  LobsSubOper so;
   // if no parent request, return
   if (qparent_.down->isEmpty())
     return WORK_OK;
@@ -2890,7 +2890,12 @@ short ExExeUtilLobExtractTcb::work()
 
 	      }
 	    
-	    step_ = RETRIEVE_LOB_LENGTH_;	    
+	    if (lobTdb().getToType() == ComTdbExeUtilLobExtract::TO_BUFFER_)
+	      step_ = EXTRACT_LOB_DATA_;
+	    else
+	      if ((lobTdb().getToType() == ComTdbExeUtilLobExtract::RETRIEVE_LENGTH_) || (lobTdb().getToType() == ComTdbExeUtilLobExtract::TO_FILE_))
+	      step_ = RETRIEVE_LOB_LENGTH_;
+	    
 	    break;
 	  }
 	case RETRIEVE_LOB_LENGTH_ : 
@@ -2908,7 +2913,7 @@ short ExExeUtilLobExtractTcb::work()
 	   
 		//Retrieve the total length of this lob using the handle info and return to the caller
 		Int64 dummy = 0;
-		cliRC = SQL_EXEC_LOBcliInterface(lobHandle_, lobHandleLen_,NULL,NULL,NULL,NULL,LOB_CLI_SELECT_LOBLENGTH,LOB_CLI_ExecImmed, 0,&lobDataLen, &dummy, &dummy,0,0);
+		cliRC = SQL_EXEC_LOBcliInterface(lobHandle_, lobHandleLen_,NULL,NULL,NULL,NULL,LOB_CLI_SELECT_LOBLENGTH,LOB_CLI_ExecImmed, 0,&lobDataLen_, &dummy, &dummy,0,0);
 		if (cliRC < 0)
 		   {
 		     getDiagsArea()->mergeAfter(diags);
@@ -2918,7 +2923,8 @@ short ExExeUtilLobExtractTcb::work()
 		   }
 		if  (lobTdb().retrieveLength())
 		  {
-		    str_sprintf(statusString_," LOB Length : %d", lobDataLen);
+		    str_cpy_all((char *)lobTdb().getBufAddr(), (char *)&lobDataLen_,sizeof(Int64));
+		    str_sprintf(statusString_," LOB Length : %d", lobDataLen_);
 		    step_ = RETURN_STATUS_;
 		    break;	
 		  }
@@ -2934,13 +2940,14 @@ short ExExeUtilLobExtractTcb::work()
 	    Int64 uid, inDescSyskey, descPartnKey;
 	    short schNameLen;
 	    char schName[1024];
+	    
 	    ExpLOBoper::extractFromLOBhandle(&flags, &lobType_, &lobNum, &uid,  
 					     &inDescSyskey, &descPartnKey, 
 					     &schNameLen, (char *)schName,
 					     (char *)lobHandle_, (Lng32)lobHandleLen_);
 	    lobName_ = ExpLOBoper::ExpGetLOBname(uid, lobNum, lobNameBuf_, 1000);
 
-	    lobDataExtractLen_ = lobTdb().bufSize_; 
+	    lobDataSpecifiedExtractLen_ = lobTdb().totalBufSize_; 
 	    
 	    
 	   
@@ -2976,6 +2983,7 @@ short ExExeUtilLobExtractTcb::work()
 
 	    if (lobTdb().getToType() == ComTdbExeUtilLobExtract::TO_FILE_)
 	      {
+		so = Lob_File;
 		LobTgtFileFlags tgtFlags = Lob_Error_Or_Create;
 		if (lobTdb().errorIfNotExists() && !lobTdb().truncateExisting())
 		  tgtFlags = Lob_Append_Or_Error;
@@ -2994,12 +3002,12 @@ short ExExeUtilLobExtractTcb::work()
 						lobHandleLen_,
 						lobHandle_,
 						requestTag,
-						Lob_File,
+						so,
 						((LOBglobals *)lobGlobs)->xnId(),
 						0,0,					       					
-						0, lobDataLen, outLobLen, 
+						0, lobDataLen_, lobDataOutputLen, 
 						lobTdb().getFileName(),
-						lobDataExtractLen_,
+						lobDataSpecifiedExtractLen_,
 						(Int32)tgtFlags
 						);
 		if (retcode <0)
@@ -3014,9 +3022,15 @@ short ExExeUtilLobExtractTcb::work()
 		    step_ = HANDLE_ERROR_;
 		    break;
 		  }
-		str_sprintf(statusString_, "Success. Targetfile :%s  Length : %Ld", lobTdb().getFileName(), outLobLen);
+		str_sprintf(statusString_, "Success. Targetfile :%s  Length : %Ld", lobTdb().getFileName(), lobDataOutputLen);
 		step_ = RETURN_STATUS_;
 	      }
+	    else if (lobTdb().getToType() == ComTdbExeUtilLobExtract::TO_BUFFER_)
+	      {
+		so = Lob_Buffer;
+		lobData_ =  (char *)lobTdb().getBufAddr();
+		step_ = OPEN_CURSOR_;
+	      }
 	  }
 	  break;
 
@@ -3036,11 +3050,11 @@ short ExExeUtilLobExtractTcb::work()
                0, // cursor bytes 
                NULL, //cursor id
 	       requestTag_, 
+	       Lob_Buffer,
 	       0, // not check status
 	       1, // waited op
-
-	       0, lobDataExtractLen_, 
-	       lobDataLen_, lobData_, 
+	       0, lobDataSpecifiedExtractLen_, 
+	       lobDataOutputLen, lobData_, 
 	       1, // open
 	       2); // must open
 
@@ -3064,6 +3078,9 @@ short ExExeUtilLobExtractTcb::work()
 
 	case READ_CURSOR_:
 	  {
+	    if (lobTdb().getToType() == ComTdbExeUtilLobExtract::TO_BUFFER_)
+	      so = Lob_Buffer;
+	    lobDataSpecifiedExtractLen_ = lobTdb().getExtractSize();
 	    retcode = ExpLOBInterfaceSelectCursor
 	      (lobGlobs,
 	       lobName_, 
@@ -3071,16 +3088,18 @@ short ExExeUtilLobExtractTcb::work()
 	       lobType_,
 	       lobTdb().getLobHdfsServer(),
 	       lobTdb().getLobHdfsPort(),
-
 	       lobHandleLen_, lobHandle_,
                0 , //cursor bytes,
 	       NULL, //cursor id
 	       requestTag_, 
+	       so,
 	       0, // not check status
 	       1, // waited op
-
-	       0, lobDataExtractLen_, 
-	       lobDataLen_, lobData_, 
+	       0, 
+	       lobDataSpecifiedExtractLen_, 
+	       //lobDataLen_, lobData_, 
+	       lobDataOutputLen,
+	       lobData_,
 	       2, // read
 	       0); // open type not applicable
 
@@ -3098,19 +3117,22 @@ short ExExeUtilLobExtractTcb::work()
 		break;
 	      }
 
-	    if (lobDataLen_ == 0)
+	    if (lobDataOutputLen == 0)
 	      {
 		step_ = CLOSE_CURSOR_;
 		break;
 	      }
 
-	    remainingBytes_ = (Lng32)lobDataLen_;
+	    remainingBytes_ = (Lng32)lobDataOutputLen;
 	    currPos_ = 0;
 
-            if (lobTdb().getToType() == ComTdbExeUtilLobExtract::TO_FILE_)
-              step_ = INSERT_FROM_STRING_;
-            else
-              step_ = RETURN_STRING_;
+            /*if (lobTdb().getToType() == ComTdbExeUtilLobExtract::TO_FILE_)
+              step_ = INSERT_FROM_STRING_;*/
+            if (lobTdb().getToType() == ComTdbExeUtilLobExtract::TO_BUFFER_)
+	      {
+		str_sprintf(statusString_," Success: LOB data length returned : %d", lobDataOutputLen);
+		step_ = RETURN_STATUS_;
+	      }
 	  }
 	  break;
 
@@ -3128,10 +3150,11 @@ short ExExeUtilLobExtractTcb::work()
                0, //cursor bytes
                NULL, //cursor id
 	       requestTag_, 
+	       so,
 	       0, // not check status
 	       1, // waited op
 
-	       0, lobDataExtractLen_, 
+	       0, lobDataSpecifiedExtractLen_, 
 	       lobDataLen_, lobData_, 
 	       3, // close
                0); // open type not applicable
@@ -3149,7 +3172,6 @@ short ExExeUtilLobExtractTcb::work()
 		step_ = HANDLE_ERROR_;
 		break;
 	      }
-
 	    step_ = DONE_;
 	  }
 	  break;
@@ -3160,7 +3182,7 @@ short ExExeUtilLobExtractTcb::work()
 	    if (qparent_.up->isFull())
 	      return WORK_OK;
 
-	    Lng32 size = MINOF((Lng32)lobTdb().rowSize_, (Lng32)remainingBytes_);
+	    Lng32 size = MINOF((Lng32)lobTdb().extractSize_, (Lng32)remainingBytes_);
 
 	    moveRowToUpQueue(&lobData_[currPos_], size);
 
@@ -3168,7 +3190,10 @@ short ExExeUtilLobExtractTcb::work()
 	    currPos_ += size;
 
 	    if (remainingBytes_ <= 0)
-	      step_ = READ_CURSOR_;
+	      {
+		step_ = READ_CURSOR_;
+		qparent_.down->removeHead();
+	      }
 
 	    return WORK_RESCHEDULE_AND_RETURN;
 	  }
@@ -3182,7 +3207,15 @@ short ExExeUtilLobExtractTcb::work()
        
 	    short rc; 
 	    moveRowToUpQueue(statusString_, 200, &rc);
-	    step_ = DONE_ ;
+
+	    if ((so == Lob_Buffer) && (remainingBytes_ >= 0))
+	      {
+		step_ = READ_CURSOR_;
+		qparent_.down->removeHead();
+		return WORK_RESCHEDULE_AND_RETURN;
+	      }
+	    else
+	      step_ = DONE_ ;
 	  }
 	  break;
 	case HANDLE_ERROR_:
@@ -3295,12 +3328,12 @@ short ExExeUtilFileExtractTcb::work()
 
 	    lobType_ =  lobTdb().lobStorageType_; //(Lng32)Lob_External_HDFS_File;
 
-	    lobDataExtractLen_ = lobTdb().bufSize_; 
+	    lobDataSpecifiedExtractLen_ = lobTdb().totalBufSize_; 
 	   
 
 	    // allocate 2 buffers for double buffering.
-	    lobData_ = new(getHeap()) char[(UInt32)lobDataExtractLen_];
-	    lobData2_ = new(getHeap()) char[(UInt32)lobDataExtractLen_];
+	    lobData_ = new(getHeap()) char[(UInt32)lobDataSpecifiedExtractLen_];
+	    lobData2_ = new(getHeap()) char[(UInt32)lobDataSpecifiedExtractLen_];
 
 	    eodReturned_ = FALSE;
 
@@ -3323,10 +3356,11 @@ short ExExeUtilFileExtractTcb::work()
 	       0, NULL, // handleLen, handle
                0, NULL, //cursor bytes, cursor id
 	       requestTag_, 
+	       Lob_File,
 	       0, // not check status
 	       1, // waited op
 
-	       0, lobDataExtractLen_, 
+	       0, lobDataSpecifiedExtractLen_, 
 	       lobDataLen_, lobData_, 
 	       1, // open
 	       2); // must open
@@ -3369,10 +3403,11 @@ short ExExeUtilFileExtractTcb::work()
 	       0, NULL,
                0, NULL ,//cursor bytes, cursor id
 	       requestTag_, 
+	       Lob_File,
 	       0, // not check status
 	       1, // waited op
 
-	       0, lobDataExtractLen_, 
+	       0, lobDataSpecifiedExtractLen_, 
 	       lobDataLen_, lobData_, 
 	       2, // read
 	       0); // open type not applicable
@@ -3400,7 +3435,7 @@ short ExExeUtilFileExtractTcb::work()
 		break;
 	      }
 
-	    if (lobDataLen_ < lobDataExtractLen_)
+	    if (lobDataLen_ < lobDataSpecifiedExtractLen_)
 	      {
 		// EOD with data: return data and then close cursor
 		eodReturned_ = TRUE;
@@ -3426,10 +3461,10 @@ short ExExeUtilFileExtractTcb::work()
 	       0, NULL,
                0, NULL, //cursor bytes, cursor id
 	       requestTag_, 
+	       Lob_File,
 	       0, // not check status
 	       1, // waited op
-
-	       0, lobDataExtractLen_, 
+	       0, lobDataSpecifiedExtractLen_, 
 	       lobDataLen_, lobData_, 
 	       3, // close
                0); // open type not applicable
@@ -3457,7 +3492,7 @@ short ExExeUtilFileExtractTcb::work()
 	    if (qparent_.up->isFull())
 	      return WORK_OK;
 
-	    Lng32 size = MINOF((Lng32)lobTdb().rowSize_, (Lng32)remainingBytes_);
+	    Lng32 size = MINOF((Lng32)lobTdb().extractSize_, (Lng32)remainingBytes_);
 
 	    // eval expression to convert lob data to sql row.
 	    // TBD.
@@ -3576,10 +3611,10 @@ short ExExeUtilFileLoadTcb::work()
 
 	    lobType_ =  lobTdb().lobStorageType_; //(Lng32)Lob_HDFS_File;
 
-	    lobDataExtractLen_ = lobTdb().bufSize_; 
+	    lobDataSpecifiedExtractLen_ = lobTdb().totalBufSize_; 
 	    
 
-	    lobData_ = new(getHeap()) char[(UInt32)lobDataExtractLen_];
+	    lobData_ = new(getHeap()) char[(UInt32)lobDataSpecifiedExtractLen_];
 
 	    srcFileRemainingBytes_ = 0;
 
@@ -3667,7 +3702,7 @@ short ExExeUtilFileLoadTcb::work()
 		break;
 	      }
 	      
-	    Int64 length = MINOF(srcFileRemainingBytes_, lobDataExtractLen_);
+	    Int64 length = MINOF(srcFileRemainingBytes_, lobDataSpecifiedExtractLen_);
 
 	    indata_.read (lobData_, (std::streamsize)length);
 	      

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5cfc9fa4/core/sql/executor/ExHdfsScan.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExHdfsScan.cpp b/core/sql/executor/ExHdfsScan.cpp
index 71c0118..7904ce2 100644
--- a/core/sql/executor/ExHdfsScan.cpp
+++ b/core/sql/executor/ExHdfsScan.cpp
@@ -498,7 +498,7 @@ ExWorkProcRetcode ExHdfsScanTcb::work()
                    bytesLeft_, // max bytes
                    cursorId_, 
 		       
-                   requestTag_, 
+                   requestTag_, Lob_Memory,
                    0, // not check status
                    (NOT hdfsScanTdb().hdfsPrefetch()),  //1, // waited op
 		       
@@ -531,7 +531,7 @@ ExWorkProcRetcode ExHdfsScanTcb::work()
                        hdfo->getBytesToRead(), // max bytes
                        cursorId, 
                            
-                       requestTag_, 
+                       requestTag_, Lob_Memory,
                        0, // not check status
                        (NOT hdfsScanTdb().hdfsPrefetch()),  //1, // waited op
                            
@@ -637,7 +637,7 @@ ExWorkProcRetcode ExHdfsScanTcb::work()
                    0, NULL,		       
                    0, cursorId_,
 		       
-                   requestTag_, 
+                   requestTag_, Lob_Memory,
                    0, // not check status
                    (NOT hdfsScanTdb().hdfsPrefetch()),  //1, // waited op
 		       
@@ -1149,7 +1149,7 @@ ExWorkProcRetcode ExHdfsScanTcb::work()
                    0,NULL, //handle not relevant for non lob access
                    0, cursorId_,
 		       
-                   requestTag_, 
+                   requestTag_, Lob_Memory,
                    0, // not check status
                    (NOT hdfsScanTdb().hdfsPrefetch()),  //1, // waited op
 		       

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5cfc9fa4/core/sql/exp/ExpLOBaccess.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/ExpLOBaccess.cpp b/core/sql/exp/ExpLOBaccess.cpp
index c1df357..b52f183 100644
--- a/core/sql/exp/ExpLOBaccess.cpp
+++ b/core/sql/exp/ExpLOBaccess.cpp
@@ -2769,7 +2769,7 @@ Ex_Lob_Error ExLobsOper (
       break;
 
     case Lob_ReadCursor:
-      if (subOperation == Lob_Memory)
+      if ((subOperation == Lob_Memory) || (subOperation == Lob_Buffer))
 	err = lobPtr->readCursor(source, sourceLen, handleIn, handleInLen, retOperLen);
       else if (subOperation == Lob_File)
 	err = lobPtr->readCursor(source, -1, handleIn, handleInLen, retOperLen);

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5cfc9fa4/core/sql/exp/ExpLOBenums.h
----------------------------------------------------------------------
diff --git a/core/sql/exp/ExpLOBenums.h b/core/sql/exp/ExpLOBenums.h
index dcdddb8..67f5f43 100644
--- a/core/sql/exp/ExpLOBenums.h
+++ b/core/sql/exp/ExpLOBenums.h
@@ -173,6 +173,7 @@ typedef enum {
    Lob_None,
    Lob_File,
    Lob_Memory,
+   Lob_Buffer,
    Lob_Foreign_Lob
 } LobsSubOper;
 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5cfc9fa4/core/sql/exp/ExpLOBinterface.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/ExpLOBinterface.cpp b/core/sql/exp/ExpLOBinterface.cpp
index fafeabb..1790a50 100644
--- a/core/sql/exp/ExpLOBinterface.cpp
+++ b/core/sql/exp/ExpLOBinterface.cpp
@@ -792,6 +792,7 @@ Lng32 ExpLOBInterfaceSelectCursor(void * lobGlob,
 				  char *cursorId,
 				  
 				  Int64 &requestTag,
+				  LobsSubOper so,
 				  Lng32 checkStatus,
 				  Lng32 waitedOp,
 
@@ -810,7 +811,7 @@ Lng32 ExpLOBInterfaceSelectCursor(void * lobGlob,
   
   LobsOper lo;
 
-  //if (lobHandle == NULL)
+  if (lobHandle == NULL)
     {
       if (oper == 1)
 	lo = Lob_OpenDataCursorSimple;
@@ -821,7 +822,7 @@ Lng32 ExpLOBInterfaceSelectCursor(void * lobGlob,
       else
 	return -1;
     }
-  /*else
+  else
     {
       if (oper == 1)
 	lo = Lob_OpenCursor;
@@ -832,7 +833,7 @@ Lng32 ExpLOBInterfaceSelectCursor(void * lobGlob,
       else
 	return -1;
     }
-*/
+
   if (checkStatus)
     lo = Lob_Check_Status;
   else
@@ -852,7 +853,7 @@ Lng32 ExpLOBInterfaceSelectCursor(void * lobGlob,
 		   lobData, inLen, 
 		   cursorBytes,cursorId,
 		   lo,
-		   Lob_Memory,
+		   so,
                    waitedOp,
 		   lobGlob,
 		   0,

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5cfc9fa4/core/sql/exp/ExpLOBinterface.h
----------------------------------------------------------------------
diff --git a/core/sql/exp/ExpLOBinterface.h b/core/sql/exp/ExpLOBinterface.h
index 2afe55e..646d846 100644
--- a/core/sql/exp/ExpLOBinterface.h
+++ b/core/sql/exp/ExpLOBinterface.h
@@ -265,6 +265,7 @@ Lng32 ExpLOBInterfaceSelectCursor(void * lobGlob,
 				  Int64 cusrorBytes,
 				  char *cursorId,
 				  Int64 &requestTag,
+				  LobsSubOper so,
 				  Lng32 checkStatus,
 				  Lng32 waitedOp,
 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5cfc9fa4/core/sql/generator/GenRelExeUtil.cpp
----------------------------------------------------------------------
diff --git a/core/sql/generator/GenRelExeUtil.cpp b/core/sql/generator/GenRelExeUtil.cpp
index ba307b2..d1b73e2 100644
--- a/core/sql/generator/GenRelExeUtil.cpp
+++ b/core/sql/generator/GenRelExeUtil.cpp
@@ -3680,11 +3680,14 @@ short ExeUtilLobExtract::codeGen(Generator * generator)
      handle,
      handleLen,
      (toType_ == TO_BUFFER_ ? ComTdbExeUtilLobExtract::TO_BUFFER_ :
-      (toType_ == TO_STRING_ ? ComTdbExeUtilLobExtract::TO_STRING_ :
-       (toType_ == TO_FILE_ ? ComTdbExeUtilLobExtract::TO_FILE_ :
+      (toType_ == RETRIEVE_LENGTH_ ? ComTdbExeUtilLobExtract::RETRIEVE_LENGTH_ :
+       (toType_ == TO_STRING_ ? ComTdbExeUtilLobExtract::TO_STRING_ :
+	(toType_ == TO_FILE_ ? ComTdbExeUtilLobExtract::TO_FILE_ :
 	(toType_ == TO_EXTERNAL_FROM_STRING_ ? ComTdbExeUtilLobExtract::TO_EXTERNAL_FROM_STRING_ :
 	 (toType_ == TO_EXTERNAL_FROM_FILE_ ? ComTdbExeUtilLobExtract::TO_EXTERNAL_FROM_FILE_ :
-	  ComTdbExeUtilLobExtract::NOOP_))))),
+	  ComTdbExeUtilLobExtract::NOOP_)))))),
+     bufAddr_,
+     extractSize_,
      intParam_,
      intParam2_,
      lst,
@@ -3741,7 +3744,7 @@ if (handleInStringFormat_)
     {
       exe_util_tdb->setRetrieveLength(TRUE);
     }
-  exe_util_tdb->setBufSize(CmpCommon::getDefaultNumeric(LOB_MAX_CHUNK_MEM_SIZE));
+  exe_util_tdb->setTotalBufSize(CmpCommon::getDefaultNumeric(LOB_MAX_CHUNK_MEM_SIZE));
 
   generator->setCriDesc(givenDesc, Generator::DOWN);
   generator->setCriDesc(returnedDesc, Generator::UP);

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5cfc9fa4/core/sql/generator/GenRelMisc.cpp
----------------------------------------------------------------------
diff --git a/core/sql/generator/GenRelMisc.cpp b/core/sql/generator/GenRelMisc.cpp
index d2879b2..2580eab 100644
--- a/core/sql/generator/GenRelMisc.cpp
+++ b/core/sql/generator/GenRelMisc.cpp
@@ -2519,6 +2519,10 @@ short RelRoot::codeGen(Generator * generator)
        {
          root_tdb->setSubqueryType(ComTdbRoot::SQL_STMT_HBASE_UNLOAD);
        }
+       else if (exeUtil->getExeUtilType() == ExeUtilExpr::LOB_EXTRACT_)
+	 {
+	   root_tdb->setSubqueryType(ComTdbRoot::SQL_STMT_LOB_EXTRACT);
+	 }
 
       else if (exeUtil->isExeUtilQueryType())
 	{

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5cfc9fa4/core/sql/nskgmake/Makerules.linux
----------------------------------------------------------------------
diff --git a/core/sql/nskgmake/Makerules.linux b/core/sql/nskgmake/Makerules.linux
index f56d9d1..2db10b1 100755
--- a/core/sql/nskgmake/Makerules.linux
+++ b/core/sql/nskgmake/Makerules.linux
@@ -139,7 +139,7 @@ GLOBAL_SYS_LIBS := -L $(LOC_JVMLIBS) $(LIBHDFS_LIB) $(THRIFT_LIB) $(LIBCURL_LIB)
 
 # EXECUTABLES defines the executables that are built for release and debug
 # builds.  Any flavor-specific targets can be added later in this makefile.
-EXECUTABLES= arkcmp sqlci arkesp tdm_udrserv mxlobsrvr sscp ssmp
+EXECUTABLES= arkcmp sqlci arkesp tdm_udrserv mxlobsrvr sscp ssmp clitestdriver
 	# mxCompileUserModule mxsqlcfe mxsqlcofe sqlfe
 
 # LIBS defines the libraries that are built for release and debug builds.
@@ -150,7 +150,7 @@ DLLS := comexe common executor sort sqlmsg \
 	tdm_sqlmxevents tdm_sqlshare tdm_sqlerrormsg \
 	eh lmcomp \
 	sqlcilib cli porting_layer tdm_sqlmxmsg_intl \
-	arkcmp_dll smdio udr_predef
+	arkcmp_dll smdio udr_predef clitest
 
 DLLS += sqlcomp ustat sqlcat parser optimizer generator \
 	tdm_sqllangman arkcmplib qmscommon

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5cfc9fa4/core/sql/nskgmake/clitest/Makefile
----------------------------------------------------------------------
diff --git a/core/sql/nskgmake/clitest/Makefile b/core/sql/nskgmake/clitest/Makefile
index ffde7d4..d129541 100755
--- a/core/sql/nskgmake/clitest/Makefile
+++ b/core/sql/nskgmake/clitest/Makefile
@@ -22,7 +22,8 @@
 #######################################################################
 
 CPPSRC := \
-        blobtest.cpp 
+        blobtest.cpp \
+	vers_libclitest.cpp
        
 CPPSRC += mpisetup.cpp 
 SRCPATH := clitest bin 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5cfc9fa4/core/sql/nskgmake/clitestdriver/Makefile
----------------------------------------------------------------------
diff --git a/core/sql/nskgmake/clitestdriver/Makefile b/core/sql/nskgmake/clitestdriver/Makefile
index c07a510..d2ffa3e 100755
--- a/core/sql/nskgmake/clitestdriver/Makefile
+++ b/core/sql/nskgmake/clitestdriver/Makefile
@@ -28,7 +28,7 @@ EARLY_DLLS:= -ljsig
 
 DEP_LIBS += tdm_sqlcli arkcmp_dll clitest
 
-CPPSRC += vprocsqlci.cpp
+CPPSRC += vprocclitestdriver.cpp
 
 
 SRCPATH := clitest bin

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5cfc9fa4/core/sql/optimizer/RelExeUtil.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/RelExeUtil.cpp b/core/sql/optimizer/RelExeUtil.cpp
index 55a5210..3690c6f 100644
--- a/core/sql/optimizer/RelExeUtil.cpp
+++ b/core/sql/optimizer/RelExeUtil.cpp
@@ -5204,8 +5204,8 @@ RelExpr * ExeUtilLobExtract::copyTopNode(RelExpr *derivedNode, CollHeap* outHeap
 
   result->handle_ = handle_;
   result->toType_ = toType_;
-  result->bufAddrExpr_ = bufAddrExpr_;
-  result->bufSizeExpr_ = bufSizeExpr_;
+  result->bufAddr_ = bufAddr_;
+  result->extractSize_ = extractSize_;
   result->intParam_ = intParam_;
   result->intParam2_ = intParam2_;
   result->stringParam_ = stringParam_;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5cfc9fa4/core/sql/optimizer/RelExeUtil.h
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/RelExeUtil.h b/core/sql/optimizer/RelExeUtil.h
index 7a3e976..28edeba 100644
--- a/core/sql/optimizer/RelExeUtil.h
+++ b/core/sql/optimizer/RelExeUtil.h
@@ -1870,8 +1870,8 @@ public:
   
  ExeUtilLobExtract(ItemExpr * handle, 
 		   ExtractToType toType,
-		   ItemExpr * bufaddr,
-		   ItemExpr * bufsize,
+		   Int64 bufaddr=0,
+		   Int64 extractSize=0,
 		   Int64 intParam = 0,
 		   Int64 intParam2 = 0,
 		   char * stringParam = NULL,
@@ -1884,8 +1884,8 @@ public:
 		 NULL, CharInfo::UnknownCharSet, oHeap),
     handle_(handle),
     toType_(toType),
-    bufAddrExpr_(bufaddr),
-    bufSizeExpr_(bufsize),
+    bufAddr_(bufaddr),
+    extractSize_(extractSize),
     intParam_(intParam),
     intParam2_(intParam2),
     handleInStringFormat_(TRUE),
@@ -1941,8 +1941,8 @@ public:
   ItemExpr * handle_;
   ExtractToType toType_;
   
-  ItemExpr * bufAddrExpr_;
-  ItemExpr * bufSizeExpr_;
+  Int64 bufAddr_;
+  Int64 extractSize_;
   
   Int64 intParam_;   // options for create or size limit
   Int64 intParam2_;// options for file behavior

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5cfc9fa4/core/sql/parser/sqlparser.y
----------------------------------------------------------------------
diff --git a/core/sql/parser/sqlparser.y b/core/sql/parser/sqlparser.y
index e7166cf..6c686b4 100755
--- a/core/sql/parser/sqlparser.y
+++ b/core/sql/parser/sqlparser.y
@@ -15583,15 +15583,15 @@ exe_util_populate_in_memory_statistics : TOK_GENERATE TOK_STATISTICS TOK_FOR TOK
 	       }
 
 /* type relx */
-exe_util_lob_extract : TOK_EXTRACT TOK_LOBLENGTH '(' TOK_LOB QUOTED_STRING  ')'
+exe_util_lob_extract : TOK_EXTRACT TOK_LOBLENGTH '(' TOK_LOB QUOTED_STRING  ')' TOK_LOCATION NUMERIC_LITERAL_EXACT_NO_SCALE
                {
 		 ConstValue * handle = new(PARSERHEAP()) ConstValue(*$5);
-
+		 Int64 returnLengthAddr = atoInt64($8->data());
 		 ExeUtilLobExtract * lle =
 		   new (PARSERHEAP ()) ExeUtilLobExtract
 		   (handle, 
 		    ExeUtilLobExtract::RETRIEVE_LENGTH_,
-		    NULL, NULL, 0, 0);
+		    returnLengthAddr, NULL, 0, 0);
 
 		 $$ = lle;
 	       }
@@ -15614,9 +15614,9 @@ exe_util_lob_extract : TOK_EXTRACT TOK_LOBLENGTH '(' TOK_LOB QUOTED_STRING  ')'
 		 */
 	       }
 
-              | TOK_EXTRACT TOK_LOBTOBUFFER '(' TOK_LOB QUOTED_STRING ',' TOK_LOCATION value_expression ',' TOK_SIZE value_expression ')'
+              | TOK_EXTRACT TOK_LOBTOBUFFER '(' TOK_LOB QUOTED_STRING ',' TOK_LOCATION NUMERIC_LITERAL_EXACT_NO_SCALE ',' TOK_SIZE NUMERIC_LITERAL_EXACT_NO_SCALE ')'
                {
-                 if (NOT (($8->getOperatorType() == ITM_DYN_PARAM) ||
+		 /* if (NOT (($8->getOperatorType() == ITM_DYN_PARAM) ||
                           ($8->getOperatorType() == ITM_CONSTANT)))
                    {
                      YYERROR;
@@ -15626,23 +15626,24 @@ exe_util_lob_extract : TOK_EXTRACT TOK_LOBLENGTH '(' TOK_LOB QUOTED_STRING  ')'
                           ($11->getOperatorType() == ITM_CONSTANT)))
                    {
                      YYERROR;
-                   }
-
-                 ItemExpr * bufaddr = $8;
+		     }*/
+		 Int64 bufAddr = atoInt64($8->data());
+		 Int64 bufSize = atoInt64($11->data());
+		 /* ItemExpr * bufaddr = $8;
 		 bufaddr = new (PARSERHEAP()) 
 		   Cast(bufaddr, new (PARSERHEAP()) SQLLargeInt(TRUE, FALSE));
 
 		 ItemExpr * bufsize = $11;
 		 bufsize = new (PARSERHEAP()) 
 		   Cast(bufsize, new (PARSERHEAP()) SQLLargeInt(TRUE, FALSE));
-
+		 */
 		 ConstValue * handle = new(PARSERHEAP()) ConstValue(*$5);
 
 		 ExeUtilLobExtract * lle =
 		   new (PARSERHEAP ()) ExeUtilLobExtract
 		   (handle, 
 		    ExeUtilLobExtract::TO_BUFFER_,
-		    bufaddr, bufsize, 0, 0);
+		    bufAddr, bufSize, 0, 0);
 
 		 $$ = lle;
 	       }