Exemplo n.º 1
0
//Get the position block on predicaiton
MultiPosFilterBlock* DataSource::getPosOnPred(){
/*
	 * This method should be rewritten in children class
	 * For the reason of different value types.
	 * The default here is string.
*/
	matchedPredPos = new MultiPosFilterBlock ();
	if(pred==NULL)matchedPredPos->setCompleteSet(true);
	else{
		predChanged=false;//Reset predChanged

		ValPos* rhsvp = pred->getRHS();
		char* rhsval = (char*)rhsvp->value;
		ValPos* tempVP = rhsvp->clone();
		int valsize = pred->getRHS()->getSize();
		unsigned char* temp;
		if (pred->getRHS()->type == ValPos::STRINGTYPE){
			temp = StringUtil::getSmallestLargerValue(rhsval,valsize);
			tempVP->set(temp);
		}else{//Default is string type column.
			return NULL;
		}

		if (valSorted) {					
			getPosOnPredValueSorted(rhsvp, tempVP);
		}else {// The column is not value sorted
			getPosOnPredValueUnsorted((ROSAM*)am, rhsvp, tempVP);
		}	
	}
	return matchedPredPos;
}
void PipelinedAggregator::aggregateOneValuedBlocks() {
  // this condition should have been caught in generateBlocks
  assert(m_groupBlockIn != NULL);

  m_aggData->reset();

  // extent of group is entire block b/c of one value property
  int groupStart, groupEnd;
  ValPos *vp = m_groupBlockIn->getNext();
  do {
    //assume int type for now ... fix later
    //assert(vp->type == ValPos::INTTYPE);
    //groupVal = *(int*)vp->value;
    groupStart = vp->position;
    groupEnd = m_groupBlockIn->getPairAtLoc(m_groupBlockIn->getSize()-1)->position;

    // debugging
    //cout << " Mcurr " << m_currGroup << " val " << pair->value << " Position " << pair->position << " (not that end, eln is " << groupEnd << endl;
    if (m_currGroup && *m_currGroup > vp) {
      throw new UnexpectedException("input to PipelinedAggregator is not sorted");
    }

    delete m_currGroup;
    m_currGroup = vp->clone();
    
    // must read in only one block?
    processAggBlock(m_aggData, vp, groupStart, groupEnd);
    m_groupBlockIn = m_group->getNextValBlock(m_groupColIndex);
    if (m_aggType == GROUP_BY_SELF) {
      m_aggBlockIn = m_groupBlockIn;
    }
  } while (m_groupBlockIn != NULL && (vp = m_groupBlockIn->getNext()) && (*vp == m_currGroup));
  // keep reading in group blocks while the value hasn't changed
  if (m_groupBlockIn && vp)
    m_groupBlockIn->resetBlock();
  
  // write out the next value
  double aggValue = m_aggData->evaluate();
  //logOutputBlock(groupVal, aggValue);
  m_currGroup->position=m_currOutputPosition;
  m_groupBlockOut->setValue(m_currGroup);
  DoubleValPos lvp;
  lvp.set(m_currOutputPosition, (byte*)&aggValue);
  m_aggBlockOut->setValue(&lvp);
  m_currOutputPosition++;
}
Exemplo n.º 3
0
//Get the position block on predicaiton
MultiPosFilterBlock* RLEDataSource::getPosOnPred(){
	if (m_pPred == NULL){
		matchedPredPos = new MultiPosFilterBlock();
		matchedPredPos->setCompleteSet(true);
	}
	else{
		predChanged = false;//Reset predChanged

		ValPos* rhsvp = m_pPred->getRHS();
		char* rhsval = (char*)rhsvp->value;
		ValPos* tempVP = rhsvp->clone();
		int valsize = m_pPred->getRHS()->getSize();
		unsigned char* temp;
		temp = StringUtil::getSmallestLargerValue(rhsval, valsize);
		tempVP->set(temp);
		// The column is for sure not value sorted
		if (!getPosOnPredValueUnsorted((ROSAM*)am, rhsvp, tempVP))
			//If nothing find, matched predication position is a NULL set.
			matchedPredPos = new MultiPosFilterBlock();
	}
	return matchedPredPos;
}
void PipelinedAggregator::aggregateMultiValuedBlocks() {
  // update to next group block if current block has no more groups
  if (!m_groupBlockIn->hasNext()) {
    m_groupBlockIn = m_group->getNextValBlock(m_groupColIndex);
    //    if (m_groupBlockIn)
    //groupStart=m_groupBlockIn->peekNext()->position;
    //else
    if (!m_groupBlockIn) {
      m_groupBlockOut = NULL;
      m_aggBlockOut = NULL;
      return;
    }
    if (m_aggType == GROUP_BY_SELF) {
      m_aggBlockIn = m_groupBlockIn;
    }
  }
  ValPos* vp = m_groupBlockIn->getNext();
  //assume int type for now ... fix later
  //assert(vp->type == ValPos::INTTYPE);
  
  //int groupVal = *(int*)vp->value;
  int groupStart = vp->position;

  // debugging
  if (m_currGroup && *m_currGroup > vp) {
    throw new UnexpectedException("input to PipelinedAggregator is not sorted");
  }

  delete m_currGroup;
  m_currGroup = vp->clone();
  
  m_aggData->reset();
 
  // calculate extent of group, reading in blocks as necessary  
  //if (m_groupBlockIn) {
    
  while (m_groupBlockIn->hasNext() && *m_groupBlockIn->peekNext() == vp) {
    while (m_groupBlockIn->hasNext() && *m_groupBlockIn->peekNext() == vp) {
      vp = m_groupBlockIn->getNext();
      //assume int type for now ... fix later
      //assert(vp->type == ValPos::INTTYPE);
    }
    if (!m_groupBlockIn->hasNext()) {
      m_groupBlockIn = m_group->getNextValBlock(m_groupColIndex);
      if (!m_groupBlockIn) {
	break;
      }
      if (m_aggType == GROUP_BY_SELF) {
	m_aggBlockIn = m_groupBlockIn;
      }
    }
  }

    int groupEnd = vp->position;
    // processAggBlock pulls up new blocks if necessary
    processAggBlock(m_aggData, vp, groupStart, groupEnd);
    
    //}

  // write out the next value
  double aggValue = m_aggData->evaluate();
  //logOutputBlock(groupVal, aggValue);
  //m_groupBlockOut->setValue(groupVal, m_currOutputPosition);
  m_currGroup->position=m_currOutputPosition;
  m_groupBlockOut->setValue(m_currGroup);

  DoubleValPos lvp;
  lvp.set(m_currOutputPosition, (byte*)&aggValue);
  m_aggBlockOut->setValue(&lvp);
  m_currOutputPosition++;

}