Пример #1
0
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;
	}
    }
}
void ExHdfsFastExtractTcb::convertSQRowToString(ULng32 nullLen,
                            ULng32 recSepLen,
                            ULng32 delimLen,
                            tupp_descriptor* dataDesc,
                            char* targetData,
                            NABoolean & convError) {
  char* childRow = dataDesc->getTupleAddress();
  ULng32 childRowLen = dataDesc->getAllocatedSize();
  UInt32 vcActualLen = 0;

  for (UInt32 i = 0; i < myTdb().getChildTuple()->numAttrs(); i++) {
    Attributes * attr = myTdb().getChildTableAttr(i);
    Attributes * attr2 = myTdb().getChildTableAttr2(i);
    char *childColData = NULL; //childRow + attr->getOffset();
    UInt32 childColLen = 0;
    UInt32 maxTargetColLen = attr2->getLength();

    //format is aligned format--
    //----------
    // field is varchar
    if (attr->getVCIndicatorLength() > 0) {
      childColData = childRow + *((UInt32*) (childRow + attr->getVoaOffset()));
      childColLen = attr->getLength(childColData);
      childColData += attr->getVCIndicatorLength();
    } else {              //source is fixed length
      childColData = childRow + attr->getOffset();
      childColLen = attr->getLength();
      if ((attr->getCharSet() == CharInfo::ISO88591
          || attr->getCharSet() == CharInfo::UTF8) && childColLen > 0) {
        // trim trailing blanks
        while (childColLen > 0 && childColData[childColLen - 1] == ' ') {
          childColLen--;
        }
      } else if (attr->getCharSet() == CharInfo::UCS2 && childColLen > 1) {
        ex_assert(childColLen % 2 == 0, "invalid ucs2");
        NAWchar* wChildColData = (NAWchar*) childColData;
        Int32 wChildColLen = childColLen / 2;
        while (wChildColLen > 0 && wChildColData[wChildColLen - 1] == L' ') {
          wChildColLen--;
        }
        childColLen = wChildColLen * 2;
      }
    }

    if (attr->getNullFlag()
        && ExpAlignedFormat::isNullValue(childRow + attr->getNullIndOffset(),
            attr->getNullBitIndex())) {
      // source is a null value.

      nullLen = 0;
      if (myTdb().getNullString()) {
        nullLen = strlen(myTdb().getNullString());
        memcpy(targetData, myTdb().getNullString(), nullLen); 
      } 

      targetData += nullLen;
      currBuffer_->bytesLeft_ -= nullLen;
    } else {
      switch ((conv_case_index) sourceFieldsConvIndex_[i]) {
      case CONV_ASCII_V_V:
      case CONV_ASCII_F_V:
      case CONV_UNICODE_V_V:
      case CONV_UNICODE_F_V: {
        if (childColLen > 0) {
          memcpy(targetData, childColData, childColLen);
          targetData += childColLen;
          currBuffer_->bytesLeft_ -= childColLen;
        }
      }
        break;

      default:
        ex_expr::exp_return_type err = convDoIt(childColData, childColLen,
            attr->getDatatype(), attr->getPrecision(), attr->getScale(),
            targetData, attr2->getLength(), attr2->getDatatype(),
            attr2->getPrecision(), attr2->getScale(), (char*) &vcActualLen,
            sizeof(vcActualLen), 0, 0,             // diags may need to be added
            (conv_case_index) sourceFieldsConvIndex_[i]);

        if (err == ex_expr::EXPR_ERROR) {
          convError = TRUE;
          // not exit loop -- we will log the errenous row later
          // do not cancel processing for this type of error???
        }
        targetData += vcActualLen;
        currBuffer_->bytesLeft_ -= vcActualLen;
        break;
      }                      //switch
    }

    if (i == myTdb().getChildTuple()->numAttrs() - 1) {
      strncpy(targetData, myTdb().getRecordSeparator(), recSepLen);
      targetData += recSepLen;
      currBuffer_->bytesLeft_ -= recSepLen;
    } else {
      strncpy(targetData, myTdb().getDelimiter(), delimLen);
      targetData += delimLen;
      currBuffer_->bytesLeft_ -= delimLen;
    }

  }
}