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;
}
Exemplo n.º 2
0
bool IntDecoder::skipToBlockOnValue(ValPos* rhs_) {
	reader.resetPos();
	int value;
	while (reader.readInt(value)) {
		ValPos* lhs = new IntValPos();
		lhs->set((byte*)&value);
		if (*lhs != rhs_) {
			currPos++;
			if (valSorted && *lhs>rhs_)return false;
		}
		else return true;
	}
	return false;
}
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;
}
Exemplo n.º 4
0
/**
 * This operator needs to return the next SBlock worth of tuples. Recall that
 * in CStore, for efficiency, iterators forward blocks of tuples, not single
 * tuples. colIndex_ is completely ignored by this function.
 */
SBlock* Filter::getNextSValBlockPredNotDumb(int colIndex_) {
  assert(colIndex_==0);
  int* values = new int[ninputs+1];
  bool atLeastOneResult=false;
  while (!atLeastOneResult) {
    updateInputBlocks();
    if (done)
      return NULL;
    sb1->resetBlock();
    sb1->setStartPosition(curpos);
    sb2->resetBlock();
    sb2->setStartPosition(curpos);
    ValPos* pair;
    //assume int type for now ... fix later ...
    ValPos* vp = new IntValPos();
    int* rhsints = new int[npreds];
    for (int i=0; i<npreds;i++) {
      assert(preds[i]->getRHS()->type == ValPos::INTTYPE);
      rhsints[i]=*(int*)(preds[i]->getRHS()->value);
      preds[i]->setLHS(vp);
    }
    
    int sbpos = 0;
    int* currarray;
    int currarraysize;
    int startpos;
    if (iterArray[predindexes[0]]->isOneValue()) {
      pair = iterArray[predindexes[0]]->getNext();
      preds[0]->setLHS(pair);
      if (preds[0]->evalPredicate(rhsints[0])) {
	unsigned int startpos = pair->position;
	unsigned int size = iterArray[predindexes[0]]->getSize();
	assert(pair->type == ValPos::INTTYPE);
	values[predindexes[0]+1]=*(int*)pair->value;
	for (unsigned int i = startpos; i < startpos + size; i++) {
	  values[0]=i;
	  //values[predindexes[0]+1]=pair->value;
	  sb1->setValueAtPos((char*)values, sbpos);
	  sbpos++;
	}
      }
      else {
	atLeastOneResult = false;
	continue;
      }
    }
    else {
      if (iterArray[predindexes[0]]->hasNext()) {
	currarray = (int*) iterArray[predindexes[0]]->asArray();
	currarraysize = iterArray[predindexes[0]]->getSize();
	pair = iterArray[predindexes[0]]->getNext();
	startpos=pair->position;
	for (int i = startpos; i < startpos+currarraysize; i++) {
	  //preds[0]->setLHS(currarray[i-startpos]);
	  vp->set((byte*)&currarray[i-startpos]);
	  if (preds[0]->evalPredicate(rhsints[0])) {
	    values[0]=i;
	    values[predindexes[0]+1]=currarray[i-startpos];
	    sb1->setValueAtPos((char*)values, sbpos);
	    sbpos++;
	  }
	}
      }
    }
    //int sbstartpos = sb1->getStartPosition();
    SPair* spair;
    SMultiBlock* tempsb;
    sbpos=0;
    for (int i = 1; i <npreds; i++) {
      tempsb = sb2;
      sb2=sb1;
      sb1=tempsb;
      pair = iterArray[predindexes[i]]->getStartPair();
      if (iterArray[predindexes[i]]->isOneValue()) {
	preds[i]->setLHS(pair);
	if (!preds[i]->evalPredicate(rhsints[i])) {
	  atLeastOneResult = false;
	  break;
	}
      }
      startpos = iterArray[predindexes[i]]->getStartPair()->position;
      currarray = (int*) iterArray[predindexes[i]]->asArray();
      currarraysize = iterArray[predindexes[i]]->getSize();
      while (sb2->hasNext()) {
	spair = sb2->getNext();
	memcpy((byte*)values, spair->value, (ninputs+1)*sizeof(int));
	assert((values[0]-startpos) < currarraysize);
	////pair = iterArray[predindexes[i]]->getPairAtLoc(values[0]-startpos);
	//preds[i]->setLHS(currarray[values[0]-startpos]); 
	vp->set((byte*)&currarray[values[0]-startpos]);
	if (preds[i]->evalPredicate(rhsints[i])) {
	  values[predindexes[i]+1]=currarray[values[0]-startpos];
	  sb1->setValueAtPos((char*)values, sbpos);
	  sbpos++;
	}
      }
    }
    if (sb1->getSize() > 0)
      atLeastOneResult = true;
  }

  /* ok, now would be the point where I fill in the rest of the tuple
     but for now since experiments have a predicate on every attribute, I
     don't need to worry about that for now ...
  */
    
  //sb->setRealStartPos(sb->peekNext()->position);
  delete[] values;

  return sb1;
}
Exemplo n.º 5
0
/**
 * This operator needs to return the next SBlock worth of tuples. Recall that
 * in CStore, for efficiency, iterators forward blocks of tuples, not single
 * tuples. colIndex_ is completely ignored by this function.
 */
SBlock* Filter::getNextSValBlockParallel(int colIndex_) {
  assert(colIndex_==0);
  assert(ninputs==2);
  int* values = new int[ninputs+1];
  bool atLeastOneResult=false;
  while (!atLeastOneResult) {
    updateInputBlocks();
    if (done)
      return NULL;
    sb1->resetBlock();
    sb1->setStartPosition(curpos);
    //sb2->resetBlock();
    //sb2->setStartPosition(curpos);
    ValPos* pair;
    //assume int type for now ... fix later ...
    ValPos* vp = new IntValPos();
    int* rhsints = new int[npreds];
    for (int i=0; i<npreds;i++) {
      assert(preds[i]->getRHS()->type == ValPos::INTTYPE);
      rhsints[i]=*(int*)(preds[i]->getRHS()->value);
      preds[i]->setLHS(vp);
    }
    
    int sbpos = 0;
    int** currarray = new int*[ninputs];
    int* currarraysize = new int[ninputs];
    int* startposes = new int[ninputs];
    bool predsPassed;
    //int startpos;
    if (iterArray[0]->hasNext()) {
      for (int i = 0; i < ninputs; i++) {
	currarray[i] = (int*) iterArray[i]->asArray();
	currarraysize[i] = iterArray[i]->getSize();
	pair = iterArray[i]->getNext();
	startposes[i]=pair->position;
	if (i > 0) {
	  assert(startposes[i]==startposes[i-1]);
	  assert(currarraysize[i]==currarraysize[i-1]);
	}
      }
      for (int i = startposes[0]; i < startposes[0]+currarraysize[0]; i++) {
	values[0]=i;
	for (int j = 1; j <= ninputs; j++) {
	  values[j]=currarray[j-1][i-startposes[0]];
	}
	predsPassed = true;
	for (int i = 0; i <npreds; i++) {
	  //preds[i]->setLHS(values[predindexes[i]+1]);  
	  vp->set((byte*)&values[predindexes[i]+1]);  
	  if (!preds[i]->evalPredicate(rhsints[i])) {
	    predsPassed = false;
	  }
	}
	if (predsPassed) {
	  sb1->setValueAtPos((char*)values, sbpos);
	  sbpos++;
	  atLeastOneResult=true;
	}
      }
    }      
  }

  //sb->setRealStartPos(sb->peekNext()->position);
  delete[] values;

  return sb1;
}
Exemplo n.º 6
0
void Aggregator::processAggBlockGroupByOtherMultiValued(AggValue* aggValue_, int groupStart_, int groupEnd_) {
  int groupLength = groupEnd_ - groupStart_ + 1;
  int valuesProcessed = 0;
  //Pair* group;
  if (m_aggBlockIn->getStartPair()->type == ValPos::INTTYPE) {
    //ValPos* vp = m_aggBlockIn->getStartPair();
    while (valuesProcessed < groupLength) {
      if (!bi) {
	if (m_aggBlockIn->getBlock() == m_aggBlockIn) { // m_aggBlockIn is a normal block
	  bi = m_aggBlockIn->getIterator();
	} else {				  // m_aggBlockIn is an iterator
	  bi = static_cast<BlockIter*>(m_aggBlockIn);
	}
	iterarray = (int*) bi->asArray();
	itersize = bi->getSize();
	iterindex=0;
      }
      if ((itersize-iterindex)+valuesProcessed < groupLength) {
	valuesProcessed+=(itersize-iterindex);
	for (int i= iterindex; i< itersize; i++) { 
	  //group = m_aggBlockIn->getNext();
	  //update(aggValue_, group->value, 1);
	  //assert(group->value == iterarray[iterindex]);
	  //vp->set((byte*)(iterarray+iterindex));
	  update(aggValue_, iterarray[iterindex], 1);
	  iterindex++;
	}
	//assert(!m_aggBlockIn->hasNext());
	m_aggBlockIn = m_agg->getNextValBlock(m_aggColIndex);
	if (m_aggBlockIn) {
	  if (m_aggBlockIn->getBlock() == m_aggBlockIn) { // m_aggBlockIn is a normal block
	    bi = m_aggBlockIn->getIterator();
	  } else {				  // m_aggBlockIn is an iterator
	    bi = static_cast<BlockIter*>(m_aggBlockIn);
	  }
	  iterarray = (int*) bi->asArray();
	  itersize = bi->getSize();
	  iterindex=0;
	}
      }
      else {
	for (int i= 0; i< (groupLength-valuesProcessed); i++) {
	  //group = m_aggBlockIn->getNext();
	  //update(aggValue_, group->value, 1);
	  //assert(group->value == iterarray[iterindex]);
	  //vp->set((byte*)(iterarray+iterindex));
	  update(aggValue_, iterarray[iterindex], 1);
	  iterindex++;
	}
	valuesProcessed+=(groupLength-valuesProcessed);
      }
    }
    assert (valuesProcessed = groupLength);
    /*while (valuesProcessed < groupLength) {
      if (m_aggBlockIn->hasNext()) {
      group = m_aggBlockIn->getNext();
      update(aggValue_, group->value, 1);
      valuesProcessed++;
      } else {
      m_aggBlockIn = m_agg->getNextValBlock(m_aggColIndex);
      }
      }*/
  }
  else {
    byte* realArray = (byte*)iterarray;
    ValPos* vp = m_aggBlockIn->getStartPair()->clone();
    int valsize = vp->getSize();
    while (valuesProcessed < groupLength) {
      if (!bi) {
	if (m_aggBlockIn->getBlock() == m_aggBlockIn) { // m_aggBlockIn is a normal block
	  bi = m_aggBlockIn->getIterator();
	} else {				  // m_aggBlockIn is an iterator
	  bi = static_cast<BlockIter*>(m_aggBlockIn);
	}
	iterarray = (int*) bi->asArray();
	realArray = (byte*)iterarray;
	itersize = bi->getSize();
	iterindex=0;
      }
      if ((itersize-iterindex)+valuesProcessed < groupLength) {
	valuesProcessed+=(itersize-iterindex);
	for (int i= iterindex; i< itersize; i++) { 
	  //group = m_aggBlockIn->getNext();
	  //update(aggValue_, group->value, 1);
	  //assert(group->value == iterarray[iterindex]);
	  vp->set(realArray+(valsize*iterindex));
	  update(aggValue_, vp, 1);
	  iterindex++;
	}
	//assert(!m_aggBlockIn->hasNext());
	m_aggBlockIn = m_agg->getNextValBlock(m_aggColIndex);
	if (m_aggBlockIn) {
	  if (m_aggBlockIn->getBlock() == m_aggBlockIn) { // m_aggBlockIn is a normal block
	    bi = m_aggBlockIn->getIterator();
	  } else {				  // m_aggBlockIn is an iterator
	    bi = static_cast<BlockIter*>(m_aggBlockIn);
	  }
	  iterarray = (int*) bi->asArray();
	  realArray = (byte*)iterarray;
	  itersize = bi->getSize();
	  iterindex=0;
	}
      }
      else {
	for (int i= 0; i< (groupLength-valuesProcessed); i++) {
	  //group = m_aggBlockIn->getNext();
	  //update(aggValue_, group->value, 1);
	  //assert(group->value == iterarray[iterindex]);
	  vp->set(realArray+(valsize*iterindex));
	  update(aggValue_, vp, 1);
	  iterindex++;
	}
	valuesProcessed+=(groupLength-valuesProcessed);
      }
    }
    assert (valuesProcessed = groupLength);
    /*while (valuesProcessed < groupLength) {
      if (m_aggBlockIn->hasNext()) {
      group = m_aggBlockIn->getNext();
      update(aggValue_, group->value, 1);
      valuesProcessed++;
      } else {
      m_aggBlockIn = m_agg->getNextValBlock(m_aggColIndex);
      }
      }*/
    delete vp;
  }
}