コード例 #1
0
/////////////////////////////////////////////////////////////////////
//
// Contents:
//    
//   RelStoredProc::codeGen()
//
//////////////////////////////////////////////////////////////////////
short generateSPIOExpr(RelInternalSP * sp,
		       Generator * generator,
		       ExSPInputOutput * &inputExpr,
		       ExSPInputOutput * &outputExpr)
{
  ExpGenerator * expGen = generator->getExpGenerator();
  Space * genSpace = generator->getSpace();

  // Generate input(extract) expr
  FragmentDir * compFragDir = generator->getFragmentDir();

  // create the fragment (independent code space) for this expression
  CollIndex myFragmentId = compFragDir->pushFragment(FragmentDir::MASTER);
  Space * space = generator->getSpace();

  // Start generation by creating the ExSPInputOutput class.
  //It will be initialized later.
  ExSPInputOutput * lInputExpr = new(space) ExSPInputOutput();

  ULng32 recordLen;
  ExpTupleDesc * tupleDesc = NULL;

  if (expGen->processValIdList(sp->procTypes(),
			       ExpTupleDesc::SQLARK_EXPLODED_FORMAT,
			       recordLen,
			       0, 1,
			       &tupleDesc, 
			       ExpTupleDesc::LONG_FORMAT) == -1)
    return -1;

  ConvInstruction * cia = 
    (ConvInstruction *)space->allocateMemory(sp->procTypes().entries() * 
					    sizeof(ConvInstruction));

  ULng32 totalLen = space->getAllocatedSpaceSize();
 
  lInputExpr->initialize(tupleDesc, totalLen, cia);

  ExSPInputOutputPtr(lInputExpr).pack(space);

  // the generated expr is generated in chunks internally by
  // the space class. Make it contiguous by allocating and
  // moving it to a contiguous area.
  char * expr = new(generator->wHeap()) char[totalLen];
  space->makeContiguous((char *)expr, totalLen);
  inputExpr =
    (ExSPInputOutput *)(genSpace->allocateAndCopyToAlignedSpace((char *)expr, totalLen, 0));

  compFragDir->removeFragment();

  // Delete expr
  NADELETEBASIC(expr, generator->wHeap());
  expr = NULL;

  // Now generate the move to output row expr
  myFragmentId = compFragDir->pushFragment(FragmentDir::MASTER);
  space = generator->getSpace();

  ExSPInputOutput * lOutputExpr = new(space) ExSPInputOutput();

  if (expGen->processValIdList(sp->getTableDesc()->getColumnList(),
			       ExpTupleDesc::SQLARK_EXPLODED_FORMAT,
			       recordLen,
			       0, 1,
			       &tupleDesc, 
			       ExpTupleDesc::LONG_FORMAT) == -1)
    return -1;

  cia = 
    (ConvInstruction *)space->allocateMemory(sp->getTableDesc()->getColumnList().entries() * 
					    sizeof(ConvInstruction));

  for (short i = 0; i < (short) tupleDesc->numAttrs(); i++)
    {
      ex_conv_clause tempClause;

      cia[i] = tempClause.findInstruction(REC_BYTE_V_ASCII, 
					  -1, // no op 
					  tupleDesc->getAttr(i)->getDatatype(), 
					  tupleDesc->getAttr(i)->getLength(),
					  0);
      
    }

  totalLen = space->getAllocatedSpaceSize();
 
  lOutputExpr->initialize(tupleDesc, totalLen, cia);

  ExSPInputOutputPtr(lOutputExpr).pack(space);

  expr = new(generator->wHeap()) char[totalLen];
  space->makeContiguous((char *)expr, totalLen);
  outputExpr =
    (ExSPInputOutput *)(genSpace->allocateAndCopyToAlignedSpace((char *)expr, totalLen, 0));

  compFragDir->removeFragment();

  // Delete expr
  NADELETEBASIC(expr, generator->wHeap());
  expr = NULL;
  
  return 0;
}
コード例 #2
0
ファイル: ComTdbHbaseAccess.cpp プロジェクト: hadr4ros/core
void ComTdbHbaseAccess::displayRowId(Space * space, char * inputRowIdBuf)
{
  char buf[100];
  char keyVal[41];
  Lng32 keyValLen = 0;
  
  ExpTupleDesc * asciiSourceTD =
    workCriDesc_->getTupleDescriptor(rowIdAsciiTuppIndex_);
  
  Lng32 currPos = 0;
  if (asciiSourceTD)
    {
      for (CollIndex i = 0; i < asciiSourceTD->numAttrs(); i++)
	{
	  Attributes * attr = asciiSourceTD->getAttr(i);
	  
	  short inputRowIdValLen = *(short*)&inputRowIdBuf[currPos];
	  currPos += sizeof(short);
	  
	  if (inputRowIdValLen > 0)
	    {
	      NABoolean nullVal = FALSE;
	      if (attr->getNullFlag())
		{
		  if (*(short*)&inputRowIdBuf[currPos] != 0) // null val
		    {
		      nullVal = TRUE;
		      strcpy(keyVal, "NULL");
		      keyValLen = strlen("NULL");
		    }
		  else
		    keyValLen = inputRowIdValLen - sizeof(short);
		  
		  currPos += sizeof(short);
		}
	      else
		keyValLen = inputRowIdValLen;
	  
	      if (NOT nullVal)
		{
		  const char * inputRowIdVal = &inputRowIdBuf[currPos];
		  // print max 20 bytes from the key value
		  Int32 fieldWidth = (MINOF(keyValLen, 20) + 1) / 2;
		  for (Int32 idx = 0; idx < fieldWidth; idx++)
		    {
		      // print each byte in 2-digit hex value
		      sprintf(keyVal + 2*idx, "%02x", *(inputRowIdVal + idx));
		    }
		  keyVal[fieldWidth*2] = 0;  // null terminate
		}
	    }
	  else
	    {
	      keyValLen = 0;
	      strcpy(keyVal, "<missing>");
	    }

	  keyValLen = MINOF(keyValLen, 40);
	  keyVal[keyValLen] = 0;
	  str_sprintf(buf, "        %d:%s", keyValLen, keyVal);
	  space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sizeof(short));
	  
	  currPos += inputRowIdValLen;
	}
    }
}