[ 
https://issues.apache.org/jira/browse/TRAFODION-2408?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15795860#comment-15795860
 ] 

ASF GitHub Bot commented on TRAFODION-2408:
-------------------------------------------

Github user sandhyasun commented on a diff in the pull request:

    https://github.com/apache/incubator-trafodion/pull/889#discussion_r94461709
  
    --- Diff: core/sql/exp/ExpLOBaccess.cpp ---
    @@ -1502,7 +1507,50 @@ Ex_Lob_Error ExLob::allocateDesc(ULng32 size, Int64 
&descNum, Int64 &dataOffset,
         char logBuf[4096];
         lobDebugInfo("In ExLob::allocateDesc",0,__LINE__,lobTrace_);
         Int32 openFlags = O_RDONLY ;   
    -    
    +    if (size == 0) //we are trying to empty this lob.
    +      {
    +        //rename lob datafile
    +        char * saveLobDataFile = new(getLobGlobalHeap()) 
char[MAX_LOB_FILE_NAME_LEN+6];
    +        str_sprintf(saveLobDataFile, "%s_save",lobDataFile_);
    +        Int32 rc2 = hdfsRename(fs_,lobDataFile_,saveLobDataFile);
    +        if (rc2 == -1)
    +          {
    +            lobDebugInfo("Problem renaming datafile to save data 
file",0,__LINE__,lobTrace_);
    +            NADELETEBASIC(saveLobDataFile,getLobGlobalHeap());
    +            return LOB_DATA_FILE_WRITE_ERROR;
    +          }
    +        //create a new file of the same name.
    +        hdfsFile fdNew = hdfsOpenFile(fs_, 
lobDataFile_,O_WRONLY|O_CREAT,0,0,0);
    +        if (!fdNew) 
    +          {
    +            str_sprintf(logBuf,"Could not create/open 
file:%s",lobDataFile_);
    +            lobDebugInfo(logBuf,0,__LINE__,lobTrace_);
    +            
    +            //restore previous version
    +            Int32 rc2 = hdfsRename(fs_,saveLobDataFile,lobDataFile_);
    +              if (rc2 == -1)
    +                {
    +                  lobDebugInfo("Problem restoring datafile . Will need to 
retry the update",0,__LINE__,lobTrace_);
    +                  NADELETEBASIC(saveLobDataFile,getLobGlobalHeap());
    +                  return LOB_DATA_FILE_WRITE_ERROR;
    +                }
    +            return LOB_DATA_FILE_OPEN_ERROR;
    --- End diff --
    
    its deleted below in the "else" part 
     else
              {
                //A new empty data file has been created.
                // delete the saved data file
                Int32 rc2 = hdfsDelete(fs_,saveLobDataFile,FALSE);//ok to 
ignore error.nt32            
                if (rc2 == -1)
                  {
                    lobDebugInfo("Problem deleting saved datafile . Will need 
to manually cleanup saved datafile",0,__LINE__,lobTrace_);
                  }
                NADELETEBASIC(saveLobDataFile,getLobGlobalHeap());
                hdfsCloseFile(fs_,fdNew);
                fdNew = NULL;    
              }


> Support for empty_blob() and update syntax using lobhandle
> ----------------------------------------------------------
>
>                 Key: TRAFODION-2408
>                 URL: https://issues.apache.org/jira/browse/TRAFODION-2408
>             Project: Apache Trafodion
>          Issue Type: Sub-task
>          Components: sql-exe
>            Reporter: Sandhya Sundaresan
>            Assignee: Sandhya Sundaresan
>
> This subtask in SQL is to help JDBC implementation for LOBs. They require the 
> eimplementation of 2 interfaces
> .EMPTY_BLOB() , EMPTY_CLOB()
> update done directly to a lobhandle . This update syntax is different form 
> the regular updates to lob columns using position.
> Assume a lob table of type :
>  Create table tlob(c1 int , c2 blob, primary key (c1));
>   Insert :
>     Insert into tlob  values (1, empty_blob());
>  Insert into tlob values (1,empty_clob());
>  
>  
> This will create a lob handle . It will also create an empty descriptor 
> handle entry and 1 chunk in the descriptor chunks table that is of size 0. 
>  
> The “type” of the lob handle will be the same as the underlying lob type of 
> the column.
>  
>   Eg if we had created the table to hold external lobs 
>      Create table tlob(c1 int , c2 blob storage ‘external’ , primary key 
> (c1));
>     Insert into tlob  values (1, empty_blob());
>  
> The lob handle for this tlobext will contain the type ‘8’ instead of ‘2’ (as 
> is the case for tlob.)
>  
> But looking at the lob handle you will not be able to say if it’s empty or 
> not. But if lob data is selected out it will be empty. 
>  
>   Update:
>          Assume tlob has some lob data in it.
>  
>          Update tlob set c2=empty_blob();
>              This will replace all lob data in the table with the empty lob. 
> The lob handle remains the same as before. 
>  
>         Update tlob set c2 = stringtolob(‘xxxx’);
>                             This will replace the empty lob entry inth 
> descriptor handle and descriptor chunks table with a new entry.
>       OR
>                       Update tlob set c2 – stringtolob(‘xxxx’, append);
>                          This will append the new data to the empty lob. So 
> it will leave 2 entries in the descriptor handle and descriptor chunks table. 
>  
>      But the result when you select the data will be the same in both cases 
> above.
>  
>  
>  Update directly  using a lobhandle using a buffer programmatically :
>       New syntax has been introduced to allow updating a lob entry using lob 
> handle directory. This is not positional syntax. 
>  
>    The syntax is as follows :
>  
>        update lob (LOB ‘<lob handle>’, LOCATION < int64 address>, SIZE < 
> int64 size>);
>        This will take a lob handle as input (it could be an empty lob or have 
> existing data). It will replace the contents with the data specified  in 
> LOCATION. 
>         
>         update lob (LOB ‘<lob handle>’, LOCATION < int64 address>, SIZE < 
> int64  size>, APPEND);
>       This will take a lob handle as input (it could be an empty lob or have 
> existing data). It will append the contents with the data specified  in 
> LOCATION.
>  
>                    update lob (LOB ‘<lob handle>’,  TRUNCATE);
>     This will truncate the existing data and initialize the lob to empty_lob 
> for the  provided lob handle. 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to