You are viewing a plain text version of this content. The canonical link for it is here.
Posted to codereview@trafodion.apache.org by sandhyasun <gi...@git.apache.org> on 2016/04/16 00:10:44 UTC

[GitHub] incubator-trafodion pull request: Support for [TRAFODION-1891] and...

GitHub user sandhyasun opened a pull request:

    https://github.com/apache/incubator-trafodion/pull/438

    Support for [TRAFODION-1891] and [TRAFODION-1937]

    Support for get statements to retrieve lob related info.
    Support for  tracing/debug iformtion for LOB operations. 
    Added a new test case to executor/TEST130 to cover the new "get" command.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/sandhyasun/incubator-trafodion lob_get_trace

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-trafodion/pull/438.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #438
    
----
commit bbe87c923d6fcfedf5ddbccc2d05f5aa07dc87df
Author: Sandhya Sundaresan <sa...@apache.org>
Date:   2016-04-15T07:32:38Z

    support for get command for LOB tables. Support for tracing LOB operations.

commit 8b39808010d4558534d48e1d760766e67b8fc07f
Author: Sandhya Sundaresan <sa...@apache.org>
Date:   2016-04-15T07:33:36Z

    Merge remote branch 'origin/master' into lob_get_trace

commit fcab6578681517dc83340b0d39f9566c3d2bd9e5
Author: Sandhya Sundaresan <sa...@apache.org>
Date:   2016-04-15T21:45:39Z

    Merge issue with 8606,73.

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-trafodion pull request: Support for [TRAFODION-1891] and...

Posted by DaveBirdsall <gi...@git.apache.org>.
Github user DaveBirdsall commented on a diff in the pull request:

    https://github.com/apache/incubator-trafodion/pull/438#discussion_r60326304
  
    --- Diff: core/sql/executor/ExExeUtilGet.cpp ---
    @@ -6116,4 +6116,588 @@ short ExExeUtilRegionStatsFormatTcb::work()
       return WORK_OK;
     }
     
    +
    +///////////////////////////////////////////////////////////////////
    +ex_tcb * ExExeUtilLobInfoTdb::build(ex_globals * glob)
    +{
    +
    +  if (isTableFormat())
    +    {
    +      ExExeUtilLobInfoTableTcb *exe_util_tcb = new(glob->getSpace()) ExExeUtilLobInfoTableTcb(*this,glob);
    +      exe_util_tcb->registerSubtasks();
    +
    +      return (exe_util_tcb);
    +    }
    +  else
    +    {
    +
    +
    +    ExExeUtilLobInfoTcb *exe_util_tcb = new(glob->getSpace()) ExExeUtilLobInfoTcb(*this, glob);
    +    exe_util_tcb->registerSubtasks();
    +
    +    return (exe_util_tcb);
    +    }
    + 
    +}
    +
    +////////////////////////////////////////////////////////////////
    +// Constructor for class ExExeUtilLobInfoTcb
    +///////////////////////////////////////////////////////////////
    +ExExeUtilLobInfoTcb::ExExeUtilLobInfoTcb(
    +     const ComTdbExeUtilLobInfo & exe_util_tdb,
    +     ex_globals * glob)
    +     : ExExeUtilTcb( exe_util_tdb, NULL, glob)
    +{
    +  
    +
    +  inputNameBuf_ = NULL;
    +  if (exe_util_tdb.inputExpr_)
    +    {
    +      inputNameBuf_ = new(glob->getDefaultHeap()) char[exe_util_tdb.inputRowlen_];
    +    }
    +
    +  tableName_ = new(glob->getDefaultHeap()) char[2000];
    +  currLobNum_ = 1;
    +  step_ = INITIAL_;
    +}
    +
    +ExExeUtilLobInfoTcb::~ExExeUtilLobInfoTcb()
    +{
    +  if (tableName_)
    +    NADELETEBASIC(tableName_, getGlobals()->getDefaultHeap());
    +  if(inputNameBuf_) 
    +     NADELETEBASIC(inputNameBuf_, getGlobals()->getDefaultHeap());
    + 
    +  tableName_ = NULL;
    +  inputNameBuf_ = NULL;
    +}
    +
    +short ExExeUtilLobInfoTcb::collectAndReturnLobInfo(char * tableName,Int32 currLobNum, ContextCli *currContext)
    +{
    +  char *catName = NULL;
    +  char *schName = NULL;
    +  char *objName = NULL;
    +  Int32 offset = 0;
    +  char columnName[LOBINFO_MAX_FILE_LEN]= {'\0'};
    +  char lobLocation[LOBINFO_MAX_FILE_LEN]={'\0'};
    +  char lobDataFilePath[LOBINFO_MAX_FILE_LEN]={'\0'};
    +  Int64 lobEOD=0;
    +
    +  char buf[1000];
    --- End diff --
    
    Looks like this buffer is plenty long enough. Though I did have to hunt for LOBINFO_MAX_FILE_LEN to be sure (it is 256). Something to consider in the future is to use an expression here involving LOBINFO_MAX_FILE_LEN + some constant to make it easier for a reader to judge correctness. (It also has the benefit that if you change the value of LOBINFO_MAX_FILE_LEN later, say to 1024, this code doesn't break.)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-trafodion pull request: Support for [TRAFODION-1891] and...

Posted by sandhyasun <gi...@git.apache.org>.
Github user sandhyasun commented on a diff in the pull request:

    https://github.com/apache/incubator-trafodion/pull/438#discussion_r60339767
  
    --- Diff: core/sql/cli/Cli.cpp ---
    @@ -10495,13 +10528,18 @@ Lng32 SQLCLI_LOB_GC_Interface
     
           // Restore original data file.
           Int32 rc2=ExpLOBoper::restoreLobDataFile(lobGlobals,tgtLobName, (void *)currContext.exHeap(),hdfsServer,hdfsPort,lobLocation);
    +      if (rc2)
    +        {
    +          lobDebugInfo("restoreLobDataFile Failed",0,__LINE__,lobTrace);
    --- End diff --
    
    Yes it returns -1 on error.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-trafodion pull request: Support for [TRAFODION-1891] and...

Posted by DaveBirdsall <gi...@git.apache.org>.
Github user DaveBirdsall commented on a diff in the pull request:

    https://github.com/apache/incubator-trafodion/pull/438#discussion_r60326500
  
    --- Diff: core/sql/executor/ExExeUtilGet.cpp ---
    @@ -6116,4 +6116,588 @@ short ExExeUtilRegionStatsFormatTcb::work()
       return WORK_OK;
     }
     
    +
    +///////////////////////////////////////////////////////////////////
    +ex_tcb * ExExeUtilLobInfoTdb::build(ex_globals * glob)
    +{
    +
    +  if (isTableFormat())
    +    {
    +      ExExeUtilLobInfoTableTcb *exe_util_tcb = new(glob->getSpace()) ExExeUtilLobInfoTableTcb(*this,glob);
    +      exe_util_tcb->registerSubtasks();
    +
    +      return (exe_util_tcb);
    +    }
    +  else
    +    {
    +
    +
    +    ExExeUtilLobInfoTcb *exe_util_tcb = new(glob->getSpace()) ExExeUtilLobInfoTcb(*this, glob);
    +    exe_util_tcb->registerSubtasks();
    +
    +    return (exe_util_tcb);
    +    }
    + 
    +}
    +
    +////////////////////////////////////////////////////////////////
    +// Constructor for class ExExeUtilLobInfoTcb
    +///////////////////////////////////////////////////////////////
    +ExExeUtilLobInfoTcb::ExExeUtilLobInfoTcb(
    +     const ComTdbExeUtilLobInfo & exe_util_tdb,
    +     ex_globals * glob)
    +     : ExExeUtilTcb( exe_util_tdb, NULL, glob)
    +{
    +  
    +
    +  inputNameBuf_ = NULL;
    +  if (exe_util_tdb.inputExpr_)
    +    {
    +      inputNameBuf_ = new(glob->getDefaultHeap()) char[exe_util_tdb.inputRowlen_];
    +    }
    +
    +  tableName_ = new(glob->getDefaultHeap()) char[2000];
    +  currLobNum_ = 1;
    +  step_ = INITIAL_;
    +}
    +
    +ExExeUtilLobInfoTcb::~ExExeUtilLobInfoTcb()
    +{
    +  if (tableName_)
    +    NADELETEBASIC(tableName_, getGlobals()->getDefaultHeap());
    +  if(inputNameBuf_) 
    +     NADELETEBASIC(inputNameBuf_, getGlobals()->getDefaultHeap());
    + 
    +  tableName_ = NULL;
    +  inputNameBuf_ = NULL;
    +}
    +
    +short ExExeUtilLobInfoTcb::collectAndReturnLobInfo(char * tableName,Int32 currLobNum, ContextCli *currContext)
    +{
    +  char *catName = NULL;
    +  char *schName = NULL;
    +  char *objName = NULL;
    +  Int32 offset = 0;
    +  char columnName[LOBINFO_MAX_FILE_LEN]= {'\0'};
    +  char lobLocation[LOBINFO_MAX_FILE_LEN]={'\0'};
    +  char lobDataFilePath[LOBINFO_MAX_FILE_LEN]={'\0'};
    +  Int64 lobEOD=0;
    +
    +  char buf[1000];
    +  short rc = 0;
    +  if (isUpQueueFull(5))
    +    {
    +      return WORK_CALL_AGAIN; // come back later
    +    }
    +  
    +
    +  // populate catName, schName, objName.
    +  if (extractParts(tableName,
    +                   &catName, &schName, &objName))
    +    {
    +      return -1;
    +    }
    +  str_pad(buf,1000,' ');
    +  //column name
    +  offset = (currLobNum-1)*LOBINFO_MAX_FILE_LEN; 
    +  strcpy(columnName, &((getLItdb().getLobColList())[offset]));
    +  removeTrailingBlanks(columnName, LOBINFO_MAX_FILE_LEN);
    +  str_sprintf(buf, "  ColumnName :  %s", columnName);
    +  if (moveRowToUpQueue(buf, strlen(buf), &rc))
    +    return rc;
    +
    +  //lob location  
    +  strcpy(lobLocation, &((getLItdb().getLobLocList())[offset]));
    +  removeTrailingBlanks(lobLocation, LOBINFO_MAX_FILE_LEN);
    +  str_sprintf(buf, "  Lob Location :  %s", lobLocation);
    +  if (moveRowToUpQueue(buf, strlen(buf), &rc))
    +    return rc;      
    +                 
    +  // lobDataFile
    +  char tgtLobNameBuf[256];
    +  char *lobDataFile = 
    +    ExpLOBoper::ExpGetLOBname
    +    (getLItdb().objectUID_, currLobNum, 
    +     tgtLobNameBuf, 256);
    + 
    +  removeTrailingBlanks(lobDataFile, LOBINFO_MAX_FILE_LEN);
    +  str_sprintf(buf, "  LOB Data File:  %s", lobDataFile);
    +  if (moveRowToUpQueue(buf, strlen(buf), &rc))
    +    return rc;  
    +                
    +  //EOD of LOB data file
    +  hdfsFS fs = hdfsConnect((char*)getLItdb().getHdfsServer(),getLItdb().getHdfsPort());
    +  if (fs == NULL)
    +    return LOB_DATA_FILE_OPEN_ERROR;
    +
    +  snprintf(lobDataFilePath, LOBINFO_MAX_FILE_LEN, "%s/%s", lobLocation, lobDataFile);
    +  hdfsFile fdData = hdfsOpenFile(fs, lobDataFilePath,O_RDONLY,0,0,0);
    +  if (!fdData) 
    +    {
    +      hdfsCloseFile(fs,fdData);
    +      fdData = NULL;
    +      return LOB_DATA_FILE_OPEN_ERROR;
    +    }
    +  hdfsFileInfo *fInfo = hdfsGetPathInfo(fs, lobDataFilePath);
    +  if (fInfo)
    +    lobEOD = fInfo->mSize;
    + 
    +  
    +  str_sprintf(buf, "  LOB EOD :  %Ld", lobEOD);
    +  if (moveRowToUpQueue(buf, strlen(buf), &rc))
    +    return rc;
    +
    +  // Sum of all the lobDescChunks for used space
    +
    +  char lobDescChunkFileBuf[512];
    +  //Get the descriptor chunks table name
    +  char *lobDescChunksFile =
    +    ExpLOBoper::ExpGetLOBDescChunksName(strlen(schName),schName,
    +                                        getLItdb().objectUID_, currLobNum, 
    +                                        lobDescChunkFileBuf, 512);
    + 
    +  char *query = new(getGlobals()->getDefaultHeap()) char[4096];
    +  str_sprintf (query,  "select sum(chunklen) from  %s ", lobDescChunksFile);
    +
    +  // set parserflags to allow ghost table
    +  currContext->setSqlParserFlags(0x1);
    +	
    +
    +  Int64 outlen = 0;Lng32 len = 0;
    +  Int32 cliRC = cliInterface()->executeImmediate(query,(char *)&outlen, &len, FALSE);
    +  NADELETEBASIC(query, getGlobals()->getDefaultHeap());
    +  currContext->resetSqlParserFlags(0x1);
    +  if (cliRC <0 )
    +    {
    +      return cliRC;
    +    }
    +
    +  str_sprintf(buf, "  LOB Used Len :  %Ld", outlen);
    +  if (moveRowToUpQueue(buf, strlen(buf), &rc))
    +    return rc;
    +  return 0;
    +}
    +short ExExeUtilLobInfoTcb::work()
    +{
    +  short retcode = 0;
    +  Lng32 cliRC = 0;
    +   const char *parentQid = NULL;
    +  char buf[1000];
    +     short rc = 0;
    +  // if no parent request, return
    +  if (qparent_.down->isEmpty())
    +    return WORK_OK;
    +  
    +  // if no room in up queue, won't be able to return data/status.
    +  // Come back later.
    +  if (qparent_.up->isFull())
    +    return WORK_OK;
    +  
    +  ex_queue_entry * pentry_down = qparent_.down->getHeadEntry();
    +  ExExeUtilPrivateState & pstate =
    +    *((ExExeUtilPrivateState*) pentry_down->pstate);
    +
    +  // Get the globals stucture of the master executor.
    +  ExExeStmtGlobals *exeGlob = getGlobals()->castToExExeStmtGlobals();
    +  ExMasterStmtGlobals *masterGlob = exeGlob->castToExMasterStmtGlobals();
    +  ContextCli * currContext = masterGlob->getCliGlobals()->currContext();
    +   ExExeStmtGlobals *stmtGlobals = getGlobals()->castToExExeStmtGlobals();
    +  while (1)
    +    {
    +      switch (step_)
    +	{
    +	case INITIAL_:
    +	  {
    +            if (isUpQueueFull(3))
    +	      {
    +		return WORK_CALL_AGAIN; // come back later
    +	      }
    +           
    +             
    +            if (getLItdb().inputExpr())
    +              {
    +                step_ = EVAL_INPUT_;
    +                break;
    +              }
    +
    +            strcpy(tableName_, getLItdb().getTableName());
    +            str_pad(buf,1000,'\0');
    +            str_sprintf(buf, " ");
    +	    if (moveRowToUpQueue(buf, strlen(buf), &rc))
    +              return rc;
    +            removeTrailingBlanks(tableName_, LOBINFO_MAX_FILE_LEN);
    +            str_pad(buf,1000,'\0');
    +            str_sprintf(buf, "Lob Information for table: %s", tableName_);
    +            if (moveRowToUpQueue(buf, strlen(buf), &rc))
    +              return rc;
    +            str_pad(buf,1000,'\0');
    +             str_sprintf(buf, "=========================");
    +            if (moveRowToUpQueue(buf, strlen(buf), &rc))
    +              return rc;
    +            str_pad(buf,1000,'\0');
    +            str_sprintf(buf, " ");
    +	    if (moveRowToUpQueue(buf, strlen(buf), &rc))
    +	      return rc;
    +            
    +	    step_ = COLLECT_LOBINFO_;
    +           
    +	  }
    +	break;
    +
    +        case EVAL_INPUT_:
    +          {
    +	    workAtp_->getTupp(getLItdb().workAtpIndex())
    +	      .setDataPointer(inputNameBuf_);
    +
    +	    ex_expr::exp_return_type exprRetCode =
    +	      getLItdb().inputExpr()->eval(pentry_down->getAtp(), workAtp_);
    +	    if (exprRetCode == ex_expr::EXPR_ERROR)
    +	      {
    +		step_ = HANDLE_ERROR_;
    +		break;
    +	      }
    +
    +            short len = *(short*)inputNameBuf_;
    +            str_cpy_all(tableName_, &inputNameBuf_[2], len);
    +            tableName_[len] = 0;
    +
    +           
    +            step_ = COLLECT_LOBINFO_;
    +          }
    +          break;
    +
    +        case COLLECT_LOBINFO_:
    +          {
    +            if (getLItdb().getNumLobs() == 0)
    +              {
    +                str_sprintf(buf, "  Num Lob Columns = 0", tableName_);
    +                if (moveRowToUpQueue(buf, strlen(buf), &rc))
    +                  return rc;
    +                step_ = DONE_;
    +                break;
    +              }
    +            if (currLobNum_ == getLItdb().getNumLobs()+1)
    +              {
    +                step_ = DONE_;
    +                break;
    +              }
    +            if (collectAndReturnLobInfo(tableName_,currLobNum_, currContext))
    +              {
    +                step_ = HANDLE_ERROR_;
    +                break;
    +              }
    +            currLobNum_++;
    +            
    +          }
    +          break;
    +
    +
    +
    +	case HANDLE_ERROR_:
    +	  {
    +	    retcode = handleError();
    +	    if (retcode == 1)
    +	      return WORK_OK;
    +	    
    +	    step_ = DONE_;
    +	  }
    +	break;
    +	
    +	case DONE_:
    +	  {
    +           
    +	    retcode = handleDone();
    +	    if (retcode == 1)
    +	      return WORK_OK;
    +	    
    +	    step_ = INITIAL_;
    +	    
    +	    return WORK_OK;
    +	  }
    +	break;
    +
    +
    +	} // switch
    +
    +    } // while
    +
    +  return WORK_OK;
    +}
    +//LCOV_EXCL_STOP
    +
    +
    +
    +////////////////////////////////////////////////////////////////
    +// Constructor for class ExExeUtilLobInfoTableTcb
    +///////////////////////////////////////////////////////////////
    +ExExeUtilLobInfoTableTcb::ExExeUtilLobInfoTableTcb(
    +     const ComTdbExeUtilLobInfo & exe_util_tdb,
    +     ex_globals * glob)
    +     : ExExeUtilTcb( exe_util_tdb, NULL, glob)
    +{
    +  lobInfoBuf_ = new(glob->getDefaultHeap()) char[sizeof(ComTdbLobInfoVirtTableColumnStruct)];
    +  lobInfoBufLen_ = sizeof(ComTdbLobInfoVirtTableColumnStruct);
    +
    +  lobInfo_ = (ComTdbLobInfoVirtTableColumnStruct*)lobInfoBuf_;
    +
    +  inputNameBuf_ = NULL;
    +  if (exe_util_tdb.inputExpr_)
    +    {
    +      inputNameBuf_ = new(glob->getDefaultHeap()) char[exe_util_tdb.inputRowlen_];
    +    }
    +
    +  
    +  tableName_ = new(glob->getDefaultHeap()) char[2000];
    +  currLobNum_ = 1;
    +  step_ = INITIAL_;
    +}
    +
    +ExExeUtilLobInfoTableTcb::~ExExeUtilLobInfoTableTcb()
    +{
    +  if (lobInfoBuf_)
    +    NADELETEBASIC(lobInfoBuf_, getGlobals()->getDefaultHeap());
    +  if (tableName_)
    +    NADELETEBASIC(tableName_, getGlobals()->getDefaultHeap());
    +  if(inputNameBuf_) 
    +     NADELETEBASIC(inputNameBuf_, getGlobals()->getDefaultHeap());
    +
    +  tableName_ = NULL;
    +  inputNameBuf_ = NULL;
    +
    +  lobInfoBuf_ = NULL;
    +}
    +short ExExeUtilLobInfoTableTcb:: populateLobInfo(Int32 currIndex, NABoolean nullTerminate )
    +{
    +  return 0;
    +}
    +short ExExeUtilLobInfoTableTcb::collectLobInfo(char * tableName,Int32 currLobNum, ContextCli *currContext)
    +{
    +  char *catName = NULL;
    +  char *schName = NULL;
    +  char *objName = NULL;
    +  Int32 offset = 0;
    +  char columnName[LOBINFO_MAX_FILE_LEN]= {'\0'};
    +  char lobDataFilePath[LOBINFO_MAX_FILE_LEN]={'\0'};
    +  Int64 lobEOD=0;
    +
    +  // populate catName, schName, objName.
    +  if (extractParts(tableName,
    +                   &catName, &schName, &objName))
    +    {
    +      return -1;
    +    }
    +  str_pad((char *)lobInfo_,sizeof(ComTdbLobInfoVirtTableColumnStruct),' ');
    +  
    +  str_cpy_all(lobInfo_->catalogName,catName,strlen(catName));
    +  str_cpy_all(lobInfo_->schemaName,schName,strlen(schName));
    +  str_cpy_all(lobInfo_->objectName,objName,strlen(objName));
    +
    +  //column name
    +  offset = (currLobNum-1)*LOBINFO_MAX_FILE_LEN; 
    +  str_cpy_all(lobInfo_->columnName, &((getLItdb().getLobColList())[offset]),
    +              strlen(&((getLItdb().getLobColList())[offset])));
    +  
    +  //lob location  
    +  char *lobLocation = &((getLItdb().getLobLocList())[offset]);
    +  str_cpy_all(lobInfo_->lobLocation, lobLocation, strlen(lobLocation));
    +                          
    +  // lobDataFile
    +  char tgtLobNameBuf[256];
    --- End diff --
    
    Should this be LOBINFO_MAX_FILE_LEN?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-trafodion pull request: Support for [TRAFODION-1891] and...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/incubator-trafodion/pull/438


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-trafodion pull request: Support for [TRAFODION-1891] and...

Posted by DaveBirdsall <gi...@git.apache.org>.
Github user DaveBirdsall commented on a diff in the pull request:

    https://github.com/apache/incubator-trafodion/pull/438#discussion_r60325040
  
    --- Diff: core/sql/cli/Cli.cpp ---
    @@ -10495,13 +10528,18 @@ Lng32 SQLCLI_LOB_GC_Interface
     
           // Restore original data file.
           Int32 rc2=ExpLOBoper::restoreLobDataFile(lobGlobals,tgtLobName, (void *)currContext.exHeap(),hdfsServer,hdfsPort,lobLocation);
    +      if (rc2)
    +        {
    +          lobDebugInfo("restoreLobDataFile Failed",0,__LINE__,lobTrace);
    --- End diff --
    
    Is the value of rc2 interesting here? (Or is it always -1 on an error and therefore uninteresting?)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-trafodion pull request: Support for [TRAFODION-1891] and...

Posted by sandhyasun <gi...@git.apache.org>.
Github user sandhyasun commented on a diff in the pull request:

    https://github.com/apache/incubator-trafodion/pull/438#discussion_r60339842
  
    --- Diff: core/sql/executor/ExExeUtilGet.cpp ---
    @@ -6116,4 +6116,588 @@ short ExExeUtilRegionStatsFormatTcb::work()
       return WORK_OK;
     }
     
    +
    +///////////////////////////////////////////////////////////////////
    +ex_tcb * ExExeUtilLobInfoTdb::build(ex_globals * glob)
    +{
    +
    +  if (isTableFormat())
    +    {
    +      ExExeUtilLobInfoTableTcb *exe_util_tcb = new(glob->getSpace()) ExExeUtilLobInfoTableTcb(*this,glob);
    +      exe_util_tcb->registerSubtasks();
    +
    +      return (exe_util_tcb);
    +    }
    +  else
    +    {
    +
    +
    +    ExExeUtilLobInfoTcb *exe_util_tcb = new(glob->getSpace()) ExExeUtilLobInfoTcb(*this, glob);
    +    exe_util_tcb->registerSubtasks();
    +
    +    return (exe_util_tcb);
    +    }
    + 
    +}
    +
    +////////////////////////////////////////////////////////////////
    +// Constructor for class ExExeUtilLobInfoTcb
    +///////////////////////////////////////////////////////////////
    +ExExeUtilLobInfoTcb::ExExeUtilLobInfoTcb(
    +     const ComTdbExeUtilLobInfo & exe_util_tdb,
    +     ex_globals * glob)
    +     : ExExeUtilTcb( exe_util_tdb, NULL, glob)
    +{
    +  
    +
    +  inputNameBuf_ = NULL;
    +  if (exe_util_tdb.inputExpr_)
    +    {
    +      inputNameBuf_ = new(glob->getDefaultHeap()) char[exe_util_tdb.inputRowlen_];
    +    }
    +
    +  tableName_ = new(glob->getDefaultHeap()) char[2000];
    +  currLobNum_ = 1;
    +  step_ = INITIAL_;
    +}
    +
    +ExExeUtilLobInfoTcb::~ExExeUtilLobInfoTcb()
    +{
    +  if (tableName_)
    +    NADELETEBASIC(tableName_, getGlobals()->getDefaultHeap());
    +  if(inputNameBuf_) 
    +     NADELETEBASIC(inputNameBuf_, getGlobals()->getDefaultHeap());
    + 
    +  tableName_ = NULL;
    +  inputNameBuf_ = NULL;
    +}
    +
    +short ExExeUtilLobInfoTcb::collectAndReturnLobInfo(char * tableName,Int32 currLobNum, ContextCli *currContext)
    +{
    +  char *catName = NULL;
    +  char *schName = NULL;
    +  char *objName = NULL;
    +  Int32 offset = 0;
    +  char columnName[LOBINFO_MAX_FILE_LEN]= {'\0'};
    +  char lobLocation[LOBINFO_MAX_FILE_LEN]={'\0'};
    +  char lobDataFilePath[LOBINFO_MAX_FILE_LEN]={'\0'};
    +  Int64 lobEOD=0;
    +
    +  char buf[1000];
    --- End diff --
    
    Will consider making this a constant too. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-trafodion pull request: Support for [TRAFODION-1891] and...

Posted by sandhyasun <gi...@git.apache.org>.
Github user sandhyasun commented on a diff in the pull request:

    https://github.com/apache/incubator-trafodion/pull/438#discussion_r60339892
  
    --- Diff: core/sql/executor/ExExeUtilGet.cpp ---
    @@ -6116,4 +6116,588 @@ short ExExeUtilRegionStatsFormatTcb::work()
       return WORK_OK;
     }
     
    +
    +///////////////////////////////////////////////////////////////////
    +ex_tcb * ExExeUtilLobInfoTdb::build(ex_globals * glob)
    +{
    +
    +  if (isTableFormat())
    +    {
    +      ExExeUtilLobInfoTableTcb *exe_util_tcb = new(glob->getSpace()) ExExeUtilLobInfoTableTcb(*this,glob);
    +      exe_util_tcb->registerSubtasks();
    +
    +      return (exe_util_tcb);
    +    }
    +  else
    +    {
    +
    +
    +    ExExeUtilLobInfoTcb *exe_util_tcb = new(glob->getSpace()) ExExeUtilLobInfoTcb(*this, glob);
    +    exe_util_tcb->registerSubtasks();
    +
    +    return (exe_util_tcb);
    +    }
    + 
    +}
    +
    +////////////////////////////////////////////////////////////////
    +// Constructor for class ExExeUtilLobInfoTcb
    +///////////////////////////////////////////////////////////////
    +ExExeUtilLobInfoTcb::ExExeUtilLobInfoTcb(
    +     const ComTdbExeUtilLobInfo & exe_util_tdb,
    +     ex_globals * glob)
    +     : ExExeUtilTcb( exe_util_tdb, NULL, glob)
    +{
    +  
    +
    +  inputNameBuf_ = NULL;
    +  if (exe_util_tdb.inputExpr_)
    +    {
    +      inputNameBuf_ = new(glob->getDefaultHeap()) char[exe_util_tdb.inputRowlen_];
    +    }
    +
    +  tableName_ = new(glob->getDefaultHeap()) char[2000];
    +  currLobNum_ = 1;
    +  step_ = INITIAL_;
    +}
    +
    +ExExeUtilLobInfoTcb::~ExExeUtilLobInfoTcb()
    +{
    +  if (tableName_)
    +    NADELETEBASIC(tableName_, getGlobals()->getDefaultHeap());
    +  if(inputNameBuf_) 
    +     NADELETEBASIC(inputNameBuf_, getGlobals()->getDefaultHeap());
    + 
    +  tableName_ = NULL;
    +  inputNameBuf_ = NULL;
    +}
    +
    +short ExExeUtilLobInfoTcb::collectAndReturnLobInfo(char * tableName,Int32 currLobNum, ContextCli *currContext)
    +{
    +  char *catName = NULL;
    +  char *schName = NULL;
    +  char *objName = NULL;
    +  Int32 offset = 0;
    +  char columnName[LOBINFO_MAX_FILE_LEN]= {'\0'};
    +  char lobLocation[LOBINFO_MAX_FILE_LEN]={'\0'};
    +  char lobDataFilePath[LOBINFO_MAX_FILE_LEN]={'\0'};
    +  Int64 lobEOD=0;
    +
    +  char buf[1000];
    +  short rc = 0;
    +  if (isUpQueueFull(5))
    +    {
    +      return WORK_CALL_AGAIN; // come back later
    +    }
    +  
    +
    +  // populate catName, schName, objName.
    +  if (extractParts(tableName,
    +                   &catName, &schName, &objName))
    +    {
    +      return -1;
    +    }
    +  str_pad(buf,1000,' ');
    +  //column name
    +  offset = (currLobNum-1)*LOBINFO_MAX_FILE_LEN; 
    +  strcpy(columnName, &((getLItdb().getLobColList())[offset]));
    +  removeTrailingBlanks(columnName, LOBINFO_MAX_FILE_LEN);
    +  str_sprintf(buf, "  ColumnName :  %s", columnName);
    +  if (moveRowToUpQueue(buf, strlen(buf), &rc))
    +    return rc;
    +
    +  //lob location  
    +  strcpy(lobLocation, &((getLItdb().getLobLocList())[offset]));
    +  removeTrailingBlanks(lobLocation, LOBINFO_MAX_FILE_LEN);
    +  str_sprintf(buf, "  Lob Location :  %s", lobLocation);
    +  if (moveRowToUpQueue(buf, strlen(buf), &rc))
    +    return rc;      
    +                 
    +  // lobDataFile
    +  char tgtLobNameBuf[256];
    +  char *lobDataFile = 
    +    ExpLOBoper::ExpGetLOBname
    +    (getLItdb().objectUID_, currLobNum, 
    +     tgtLobNameBuf, 256);
    + 
    +  removeTrailingBlanks(lobDataFile, LOBINFO_MAX_FILE_LEN);
    +  str_sprintf(buf, "  LOB Data File:  %s", lobDataFile);
    +  if (moveRowToUpQueue(buf, strlen(buf), &rc))
    +    return rc;  
    +                
    +  //EOD of LOB data file
    +  hdfsFS fs = hdfsConnect((char*)getLItdb().getHdfsServer(),getLItdb().getHdfsPort());
    +  if (fs == NULL)
    +    return LOB_DATA_FILE_OPEN_ERROR;
    +
    +  snprintf(lobDataFilePath, LOBINFO_MAX_FILE_LEN, "%s/%s", lobLocation, lobDataFile);
    +  hdfsFile fdData = hdfsOpenFile(fs, lobDataFilePath,O_RDONLY,0,0,0);
    +  if (!fdData) 
    +    {
    +      hdfsCloseFile(fs,fdData);
    +      fdData = NULL;
    +      return LOB_DATA_FILE_OPEN_ERROR;
    +    }
    +  hdfsFileInfo *fInfo = hdfsGetPathInfo(fs, lobDataFilePath);
    +  if (fInfo)
    +    lobEOD = fInfo->mSize;
    + 
    +  
    +  str_sprintf(buf, "  LOB EOD :  %Ld", lobEOD);
    +  if (moveRowToUpQueue(buf, strlen(buf), &rc))
    +    return rc;
    +
    +  // Sum of all the lobDescChunks for used space
    +
    +  char lobDescChunkFileBuf[512];
    +  //Get the descriptor chunks table name
    +  char *lobDescChunksFile =
    +    ExpLOBoper::ExpGetLOBDescChunksName(strlen(schName),schName,
    +                                        getLItdb().objectUID_, currLobNum, 
    +                                        lobDescChunkFileBuf, 512);
    + 
    +  char *query = new(getGlobals()->getDefaultHeap()) char[4096];
    +  str_sprintf (query,  "select sum(chunklen) from  %s ", lobDescChunksFile);
    +
    +  // set parserflags to allow ghost table
    +  currContext->setSqlParserFlags(0x1);
    +	
    +
    +  Int64 outlen = 0;Lng32 len = 0;
    +  Int32 cliRC = cliInterface()->executeImmediate(query,(char *)&outlen, &len, FALSE);
    +  NADELETEBASIC(query, getGlobals()->getDefaultHeap());
    +  currContext->resetSqlParserFlags(0x1);
    +  if (cliRC <0 )
    +    {
    +      return cliRC;
    +    }
    +
    +  str_sprintf(buf, "  LOB Used Len :  %Ld", outlen);
    +  if (moveRowToUpQueue(buf, strlen(buf), &rc))
    +    return rc;
    +  return 0;
    +}
    +short ExExeUtilLobInfoTcb::work()
    +{
    +  short retcode = 0;
    +  Lng32 cliRC = 0;
    +   const char *parentQid = NULL;
    +  char buf[1000];
    +     short rc = 0;
    +  // if no parent request, return
    +  if (qparent_.down->isEmpty())
    +    return WORK_OK;
    +  
    +  // if no room in up queue, won't be able to return data/status.
    +  // Come back later.
    +  if (qparent_.up->isFull())
    +    return WORK_OK;
    +  
    +  ex_queue_entry * pentry_down = qparent_.down->getHeadEntry();
    +  ExExeUtilPrivateState & pstate =
    +    *((ExExeUtilPrivateState*) pentry_down->pstate);
    +
    +  // Get the globals stucture of the master executor.
    +  ExExeStmtGlobals *exeGlob = getGlobals()->castToExExeStmtGlobals();
    +  ExMasterStmtGlobals *masterGlob = exeGlob->castToExMasterStmtGlobals();
    +  ContextCli * currContext = masterGlob->getCliGlobals()->currContext();
    +   ExExeStmtGlobals *stmtGlobals = getGlobals()->castToExExeStmtGlobals();
    +  while (1)
    +    {
    +      switch (step_)
    +	{
    +	case INITIAL_:
    +	  {
    +            if (isUpQueueFull(3))
    +	      {
    +		return WORK_CALL_AGAIN; // come back later
    +	      }
    +           
    +             
    +            if (getLItdb().inputExpr())
    +              {
    +                step_ = EVAL_INPUT_;
    +                break;
    +              }
    +
    +            strcpy(tableName_, getLItdb().getTableName());
    +            str_pad(buf,1000,'\0');
    +            str_sprintf(buf, " ");
    +	    if (moveRowToUpQueue(buf, strlen(buf), &rc))
    +              return rc;
    +            removeTrailingBlanks(tableName_, LOBINFO_MAX_FILE_LEN);
    +            str_pad(buf,1000,'\0');
    +            str_sprintf(buf, "Lob Information for table: %s", tableName_);
    +            if (moveRowToUpQueue(buf, strlen(buf), &rc))
    +              return rc;
    +            str_pad(buf,1000,'\0');
    +             str_sprintf(buf, "=========================");
    +            if (moveRowToUpQueue(buf, strlen(buf), &rc))
    +              return rc;
    +            str_pad(buf,1000,'\0');
    +            str_sprintf(buf, " ");
    +	    if (moveRowToUpQueue(buf, strlen(buf), &rc))
    +	      return rc;
    +            
    +	    step_ = COLLECT_LOBINFO_;
    +           
    +	  }
    +	break;
    +
    +        case EVAL_INPUT_:
    +          {
    +	    workAtp_->getTupp(getLItdb().workAtpIndex())
    +	      .setDataPointer(inputNameBuf_);
    +
    +	    ex_expr::exp_return_type exprRetCode =
    +	      getLItdb().inputExpr()->eval(pentry_down->getAtp(), workAtp_);
    +	    if (exprRetCode == ex_expr::EXPR_ERROR)
    +	      {
    +		step_ = HANDLE_ERROR_;
    +		break;
    +	      }
    +
    +            short len = *(short*)inputNameBuf_;
    +            str_cpy_all(tableName_, &inputNameBuf_[2], len);
    +            tableName_[len] = 0;
    +
    +           
    +            step_ = COLLECT_LOBINFO_;
    +          }
    +          break;
    +
    +        case COLLECT_LOBINFO_:
    +          {
    +            if (getLItdb().getNumLobs() == 0)
    +              {
    +                str_sprintf(buf, "  Num Lob Columns = 0", tableName_);
    +                if (moveRowToUpQueue(buf, strlen(buf), &rc))
    +                  return rc;
    +                step_ = DONE_;
    +                break;
    +              }
    +            if (currLobNum_ == getLItdb().getNumLobs()+1)
    +              {
    +                step_ = DONE_;
    +                break;
    +              }
    +            if (collectAndReturnLobInfo(tableName_,currLobNum_, currContext))
    +              {
    +                step_ = HANDLE_ERROR_;
    +                break;
    +              }
    +            currLobNum_++;
    +            
    +          }
    +          break;
    +
    +
    +
    +	case HANDLE_ERROR_:
    +	  {
    +	    retcode = handleError();
    +	    if (retcode == 1)
    +	      return WORK_OK;
    +	    
    +	    step_ = DONE_;
    +	  }
    +	break;
    +	
    +	case DONE_:
    +	  {
    +           
    +	    retcode = handleDone();
    +	    if (retcode == 1)
    +	      return WORK_OK;
    +	    
    +	    step_ = INITIAL_;
    +	    
    +	    return WORK_OK;
    +	  }
    +	break;
    +
    +
    +	} // switch
    +
    +    } // while
    +
    +  return WORK_OK;
    +}
    +//LCOV_EXCL_STOP
    +
    +
    +
    +////////////////////////////////////////////////////////////////
    +// Constructor for class ExExeUtilLobInfoTableTcb
    +///////////////////////////////////////////////////////////////
    +ExExeUtilLobInfoTableTcb::ExExeUtilLobInfoTableTcb(
    +     const ComTdbExeUtilLobInfo & exe_util_tdb,
    +     ex_globals * glob)
    +     : ExExeUtilTcb( exe_util_tdb, NULL, glob)
    +{
    +  lobInfoBuf_ = new(glob->getDefaultHeap()) char[sizeof(ComTdbLobInfoVirtTableColumnStruct)];
    +  lobInfoBufLen_ = sizeof(ComTdbLobInfoVirtTableColumnStruct);
    +
    +  lobInfo_ = (ComTdbLobInfoVirtTableColumnStruct*)lobInfoBuf_;
    +
    +  inputNameBuf_ = NULL;
    +  if (exe_util_tdb.inputExpr_)
    +    {
    +      inputNameBuf_ = new(glob->getDefaultHeap()) char[exe_util_tdb.inputRowlen_];
    +    }
    +
    +  
    +  tableName_ = new(glob->getDefaultHeap()) char[2000];
    +  currLobNum_ = 1;
    +  step_ = INITIAL_;
    +}
    +
    +ExExeUtilLobInfoTableTcb::~ExExeUtilLobInfoTableTcb()
    +{
    +  if (lobInfoBuf_)
    +    NADELETEBASIC(lobInfoBuf_, getGlobals()->getDefaultHeap());
    +  if (tableName_)
    +    NADELETEBASIC(tableName_, getGlobals()->getDefaultHeap());
    +  if(inputNameBuf_) 
    +     NADELETEBASIC(inputNameBuf_, getGlobals()->getDefaultHeap());
    +
    +  tableName_ = NULL;
    +  inputNameBuf_ = NULL;
    +
    +  lobInfoBuf_ = NULL;
    +}
    +short ExExeUtilLobInfoTableTcb:: populateLobInfo(Int32 currIndex, NABoolean nullTerminate )
    +{
    +  return 0;
    +}
    +short ExExeUtilLobInfoTableTcb::collectLobInfo(char * tableName,Int32 currLobNum, ContextCli *currContext)
    +{
    +  char *catName = NULL;
    +  char *schName = NULL;
    +  char *objName = NULL;
    +  Int32 offset = 0;
    +  char columnName[LOBINFO_MAX_FILE_LEN]= {'\0'};
    +  char lobDataFilePath[LOBINFO_MAX_FILE_LEN]={'\0'};
    +  Int64 lobEOD=0;
    +
    +  // populate catName, schName, objName.
    +  if (extractParts(tableName,
    +                   &catName, &schName, &objName))
    +    {
    +      return -1;
    +    }
    +  str_pad((char *)lobInfo_,sizeof(ComTdbLobInfoVirtTableColumnStruct),' ');
    +  
    +  str_cpy_all(lobInfo_->catalogName,catName,strlen(catName));
    +  str_cpy_all(lobInfo_->schemaName,schName,strlen(schName));
    +  str_cpy_all(lobInfo_->objectName,objName,strlen(objName));
    +
    +  //column name
    +  offset = (currLobNum-1)*LOBINFO_MAX_FILE_LEN; 
    +  str_cpy_all(lobInfo_->columnName, &((getLItdb().getLobColList())[offset]),
    +              strlen(&((getLItdb().getLobColList())[offset])));
    +  
    +  //lob location  
    +  char *lobLocation = &((getLItdb().getLobLocList())[offset]);
    +  str_cpy_all(lobInfo_->lobLocation, lobLocation, strlen(lobLocation));
    +                          
    +  // lobDataFile
    +  char tgtLobNameBuf[256];
    --- End diff --
    
    Yes - that would be better. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-trafodion pull request: Support for [TRAFODION-1891] and...

Posted by DaveBirdsall <gi...@git.apache.org>.
Github user DaveBirdsall commented on a diff in the pull request:

    https://github.com/apache/incubator-trafodion/pull/438#discussion_r60326346
  
    --- Diff: core/sql/executor/ExExeUtilGet.cpp ---
    @@ -6116,4 +6116,588 @@ short ExExeUtilRegionStatsFormatTcb::work()
       return WORK_OK;
     }
     
    +
    +///////////////////////////////////////////////////////////////////
    +ex_tcb * ExExeUtilLobInfoTdb::build(ex_globals * glob)
    +{
    +
    +  if (isTableFormat())
    +    {
    +      ExExeUtilLobInfoTableTcb *exe_util_tcb = new(glob->getSpace()) ExExeUtilLobInfoTableTcb(*this,glob);
    +      exe_util_tcb->registerSubtasks();
    +
    +      return (exe_util_tcb);
    +    }
    +  else
    +    {
    +
    +
    +    ExExeUtilLobInfoTcb *exe_util_tcb = new(glob->getSpace()) ExExeUtilLobInfoTcb(*this, glob);
    +    exe_util_tcb->registerSubtasks();
    +
    +    return (exe_util_tcb);
    +    }
    + 
    +}
    +
    +////////////////////////////////////////////////////////////////
    +// Constructor for class ExExeUtilLobInfoTcb
    +///////////////////////////////////////////////////////////////
    +ExExeUtilLobInfoTcb::ExExeUtilLobInfoTcb(
    +     const ComTdbExeUtilLobInfo & exe_util_tdb,
    +     ex_globals * glob)
    +     : ExExeUtilTcb( exe_util_tdb, NULL, glob)
    +{
    +  
    +
    +  inputNameBuf_ = NULL;
    +  if (exe_util_tdb.inputExpr_)
    +    {
    +      inputNameBuf_ = new(glob->getDefaultHeap()) char[exe_util_tdb.inputRowlen_];
    +    }
    +
    +  tableName_ = new(glob->getDefaultHeap()) char[2000];
    +  currLobNum_ = 1;
    +  step_ = INITIAL_;
    +}
    +
    +ExExeUtilLobInfoTcb::~ExExeUtilLobInfoTcb()
    +{
    +  if (tableName_)
    +    NADELETEBASIC(tableName_, getGlobals()->getDefaultHeap());
    +  if(inputNameBuf_) 
    +     NADELETEBASIC(inputNameBuf_, getGlobals()->getDefaultHeap());
    + 
    +  tableName_ = NULL;
    +  inputNameBuf_ = NULL;
    +}
    +
    +short ExExeUtilLobInfoTcb::collectAndReturnLobInfo(char * tableName,Int32 currLobNum, ContextCli *currContext)
    +{
    +  char *catName = NULL;
    +  char *schName = NULL;
    +  char *objName = NULL;
    +  Int32 offset = 0;
    +  char columnName[LOBINFO_MAX_FILE_LEN]= {'\0'};
    +  char lobLocation[LOBINFO_MAX_FILE_LEN]={'\0'};
    +  char lobDataFilePath[LOBINFO_MAX_FILE_LEN]={'\0'};
    +  Int64 lobEOD=0;
    +
    +  char buf[1000];
    +  short rc = 0;
    +  if (isUpQueueFull(5))
    +    {
    +      return WORK_CALL_AGAIN; // come back later
    +    }
    +  
    +
    +  // populate catName, schName, objName.
    +  if (extractParts(tableName,
    +                   &catName, &schName, &objName))
    +    {
    +      return -1;
    +    }
    +  str_pad(buf,1000,' ');
    --- End diff --
    
    Use sizeof(buf) instead of 1000 to be more robust


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---