/*

Test 03: read tuple, change core attributes and resave to file." << endl;

 */
void SecondoTestFrame::Test03(const TupleAttributes *attributes, 
		SmiRecordFile *recFile, SmiRecordFile *lobFile) {
	Tuple* myTuple;	
	float realv;
	int intv;
	char boolv;
	bool bboolv;
	CcReal *real1;
	CcInt *int1;
	CcBool *bool1;
	SmiRecordId recId;
	
	
	cout << "\tID:";
	cin >> recId;
	cout << "\trecId = " << recId << endl;
						
	cout << "\treading tuple." << endl;
	myTuple = new Tuple(recFile, recId, lobFile, attributes, SmiFile::ReadOnly);

	cout << "\ttest tuple values" << endl;
	cout << "\t" << *myTuple << endl;
	cout << "\tSize: " << myTuple->GetSize() << endl;
	cout << "\tAttributes: " << myTuple->GetAttrNum() << endl;

	cout << "\ta new float value, please: "; cin >> realv;
	cout << "\ta new int value, please: "; cin >> intv;
	cout << "\tt = true, f = false" << endl;
	cout << "\ta new boolean value, please: "; cin >> boolv;
	bboolv = ((boolv == 't') ? true : false);
	real1 = new CcReal(true, realv);
    int1 = new CcInt(true, intv);
	bool1 = new CcBool(true, bboolv);
					
	myTuple->Put(0, int1);
	myTuple->Put(1, bool1);
	myTuple->Put(2, real1);
						
	cout << "\ttest tuple values" << endl;
	cout << "\t" << *myTuple << endl;
	cout << "\tSize: " << myTuple->GetSize() << endl;
	cout << "\tAttributes: " << myTuple->GetAttrNum() << endl;
	myTuple->Save();
					
	delete bool1;
	delete int1;
	delete real1;
	delete(myTuple);
}
/*

Test 02: read tuple from file

*/
void SecondoTestFrame::Test02(const TupleAttributes *attributes, 
		SmiRecordFile *recFile, SmiRecordFile *lobFile) {
	Tuple* myTuple;	
	SmiRecordId recId;

	cout << "\tID:";
	cin >> recId;
	cout << "\trecId = " << recId << endl;
	cout << "\treading tuple." << endl;
						
	myTuple = new Tuple(recFile, recId, lobFile, attributes, SmiFile::ReadOnly);
	
	if (myTuple->error == false) {												
		cout << "\ttest tuple values" << endl;
		cout << "\t" << *myTuple << endl;

		cout << "\t\tint-Attribute:\t\t" << *myTuple->Get(0) << endl;
		cout << "\t\tbool-Attribute:\t\t" << *myTuple->Get(1) << endl;
		cout << "\t\treal-Attribute:\t\t" << *myTuple->Get(2) << endl;
		cout << "\t\tPolygon-Attribute:\t" << *myTuple->Get(3) << endl;

		cout << "\tSize: " << myTuple->GetSize() << endl;
		cout << "\tAttributes: " << myTuple->GetAttrNum() << endl;
	}
	else {
		cout << "Tuple could not be read from SmiFile." << endl;
	}
						
	delete(myTuple);
}
Exemple #3
0
/*
7 Implementation of class ~SortAlgorithm~

*/
SortAlgorithm::SortAlgorithm( Word stream,
                              const SortOrderSpecification& spec,
                              SortProgressLocalInfo* p,
                              Supplier s,
                              size_t maxFanIn,
                              size_t maxMemSize,
                              size_t ioBufferSize)
: F0(0)
, W(0)
, nextRunNumber(1)
, checkProgressAfter(10)
, stream(stream)
, attributes(-1)
, spec(spec)
//, cmpObj(cmpObj)
, usedMemory(0)
, traceMode(RTFlag::isActive("ERA:TraceSort"))
, traceModeExtended(RTFlag::isActive("ERA:TraceSortExtended"))
, progress(p)
{
  SortedRun *curRun = 0, *nextRun = 0;

  Word wTuple(Address(0));

  // Check specified fan-in for a merge phase
  setMaxFanIn(maxFanIn);

  // Check specified main memory for this operation

  setMemory(maxMemSize, s);

  // Check I/O buffer size for this operation
  setIoBuffer(ioBufferSize);

  if ( traceMode )
  {
    info = new SortInfo(MAX_MEMORY, IO_BUFFER_SIZE);
    info->RunBuildPhase();
    info->MaxMergeFanIn = FMAX;
    TupleQueueCompare::ResetComparisonCounter();
  }

  // Request first tuple and consume the stream completely
  qp->Request(stream.addr, wTuple);

  while( qp->Received(stream.addr) )
  {
    Tuple *t = static_cast<Tuple*>( wTuple.addr );

    progress->read++;

    size_t memSize = t->GetMemSize();

    // Save number of attributes
    if ( attributes == -1 )
    {
      attributes = t->GetNoAttributes();
      curRun = new SortedRun(nextRunNumber++, attributes, spec, IO_BUFFER_SIZE);
      runs.push_back(curRun);
    }

    if ( traceMode )
    {
      info->UpdateStatistics(t->GetSize());
    }

    if( usedMemory <= MAX_MEMORY )
    {
      curRun->AppendToMemory(t);
      usedMemory += memSize;
    }
    else
    {
      if ( curRun->IsFirstTupleOnDisk() )
      {
        // memory is completely used, append to disk
        progress->state = 1;
        curRun->AppendToDisk(t);
      }
      else
      {
        if ( curRun->IsInSortOrder(t) )
        {
          // tuple is on sort order, append to disk
          curRun->AppendToDisk(t);
        }
        else
        {
          if ( traceMode )
          {
            curRun->Info()->TuplesPassedToNextRun++;
          }

          // create next run if necessary
          if ( nextRun == 0 )
          {
            nextRun = new SortedRun( nextRunNumber++, attributes,
                                     spec, IO_BUFFER_SIZE );
            runs.push_back(nextRun);
            updateIntermediateMergeCost();
          }

          // next tuple is smaller, save it for the next relation
          if ( !curRun->IsAtDisk() )
          {
            // push minimum tuple of current run to disk
            curRun->AppendToDisk();

            // append tuple to memory
            nextRun->AppendToMemory(t);
          }
          else
          {
            // finish current run
            curRun->RunFinished();

            // switch runs
            curRun = nextRun;
            nextRun = 0;

            curRun->AppendToDisk(t);
          }
        }
      }
    }

    qp->Request(stream.addr, wTuple);
  }

  if ( traceMode )
  {
    for (size_t i = 0; i < runs.size(); i++)
    {
      info->InitialRunInfo.push_back(runs[i]->InfoCopy());
      info->InitialRunsCount = runs.size();
    }
  }

  mergeInit();
}
/*

Test 08: create new tuple with lots of points and save to file

*/
void SecondoTestFrame::Test08(const TupleAttributes *attributes, 
		SmiRecordFile *recFile, SmiRecordFile *lobFile) {
	Tuple* myTuple;	
	float realv;
	int intv;
	char boolv;
	bool bboolv;
	int numberOfPoints;	
	int *X;
	int *Y;
	int i;
	CcReal *real1;
	CcInt *int1;
	CcBool *bool1;
	Polygon* polygon1;
	SmiRecordId recId;

	myTuple = new Tuple(attributes);
	cout << "\ta float value, please: "; cin >> realv;
	cout << "\tan int value, please: "; cin >> intv;
	cout << "\tt = true, f = false" << endl;
	cout << "\ta boolean value, please: "; cin >> boolv;
	bboolv = ((boolv == 't') ? true : false);
	cout << "\thow many points, please: "; cin >> numberOfPoints;
	X = new int[numberOfPoints];
	Y = new int[numberOfPoints];
						
	for (i = 0; i < numberOfPoints; i++) {
		X[i] = i;
		Y[i] = i * i;
	}
						
	real1 = new CcReal(true, realv);
    int1 = new CcInt(true, intv);
	bool1 = new CcBool(true, bboolv);
					
	polygon1 = new Polygon(lobFile, numberOfPoints, X, Y);
	myTuple->Put(0, int1);
	myTuple->Put(1, bool1);
	myTuple->Put(2, real1);
	myTuple->Put(3, polygon1);
					
	cout << "\ttest tuple values" << endl;
	cout << "\t" << *myTuple << endl;
	cout << "\tSize: " << myTuple->GetSize() << endl;
	cout << "\tAttributes: " << myTuple->GetAttrNum() << endl;
	cout << "\tSave tuple into recFile. Persistent id = ";

	myTuple->SaveTo(recFile, lobFile);
	recId = myTuple->GetPersistentId();
	cout << recId << endl;

        polygon1->Close();	
	delete polygon1;
	delete real1;
	delete int1;
	delete bool1;
	delete[] X;
	delete[] Y;
	delete myTuple;
}
/*

Test 07: create two new tuples with one shared float component, save both to file.

*/
void SecondoTestFrame::Test07(const TupleAttributes *attributes, 
		SmiRecordFile *recFile, SmiRecordFile *lobFile) {
	Tuple* myTuple;
	Tuple* myTuple2;
	float realv;
	int intv;
	int intv2;
	char boolv;
	char boolv2;
	bool bboolv;
	bool bboolv2;
	int numberOfPoints;	
	int *X;
	int *Y;
	int i;
	CcReal *real1;
	CcInt *int1;
	CcInt *int2;
	CcBool *bool1;
	CcBool *bool2;
	CcBool *bool2a;
	Polygon* polygon1;
	Polygon* polygon2;
	SmiRecordId recId;

	myTuple = new Tuple(attributes);
	myTuple2 = new Tuple(attributes);
	
	cout << "\ta float value for both tuples, please: "; cin >> realv;						
	cout << "\tan int value for the first tuple, please: "; cin >> intv;
	cout << "\tt = true, f = false" << endl;
	cout << "\ta boolean value for the first tuple, please: "; cin >> boolv;
						
	cout << "\tan int value for the second tuple, please: "; cin >> intv2;
	cout << "\tt = true, f = false" << endl;
	cout << "\ta boolean value for the second tuple, please: "; cin >> boolv2;
	bboolv = ((boolv == 't') ? true : false);
	bboolv2 = ((boolv2 == 't') ? true : false);
	
	cout << "\thow many points, please: "; cin >> numberOfPoints;
	X = new int[numberOfPoints];
	Y = new int[numberOfPoints];
						
	for (i = 0; i < numberOfPoints; i++) {
		cout << "\t" << (i+1) << ". Point:" << endl;
		cout << "\t\tX: "; cin >> X[i];
		cout << "\t\tY: "; cin >> Y[i];
	}

	real1 = new CcReal(true, realv);
    int1 = new CcInt(true, intv);
	bool1 = new CcBool(true, bboolv);
	int2 = new CcInt(true, intv2);
	bool2 = new CcBool(true, bboolv2);
	bool2a = new CcBool(true, bboolv2);
	
	polygon1 = new Polygon(lobFile, numberOfPoints, X, Y);
	polygon2 = new Polygon(lobFile, numberOfPoints, X, Y);
	
	myTuple->DelPut(0, int1);
	myTuple->DelPut(1, bool1);
	myTuple->DelPut(2, real1);
	myTuple->Put(3, polygon1);

	myTuple2->DelPut(0, int2);
	myTuple2->DelPut(1, bool2);
	myTuple2->AttrPut(1, myTuple, 1);
	myTuple2->AttrPut(2, myTuple, 2);
	myTuple2->Put(3, polygon2);
					
	cout << "\ttest tuple values" << endl;
	cout << "\t" << *myTuple << endl;
	cout << "\tSize: " << myTuple->GetSize() << endl;
	cout << "\tAttributes: " << myTuple->GetAttrNum() << endl;
	cout << endl;
	cout << "\ttest tuple values" << endl;
	cout << "\t" << *myTuple2 << endl;
	cout << "\tSize: " << myTuple2->GetSize() << endl;
	cout << "\tAttributes: " << myTuple2->GetAttrNum() << endl;

	cout << "\tSave tuple into recFile. Persistent id = ";

	myTuple->SaveTo(recFile, lobFile);
	recId = myTuple->GetPersistentId();
	cout << recId;
	
	myTuple2->SaveTo(recFile, lobFile);
	recId = myTuple2->GetPersistentId();
	cout << ", Persistent id = " << recId << endl;
	
	cout << "****************" << endl;
	delete myTuple2;
	cout << "(I)" << *myTuple << endl;
	delete myTuple;
	cout << "****************" << endl;
	
	
        polygon1->Close();	
	delete polygon1;
	delete polygon2;

	delete[] X;
	delete[] Y;
	
	//delete myTuple2;
	//delete myTuple;
}