示例#1
0
	void serializeCSEP()
	{
	   /*
		* erydbSelectExecutionPlan
		* This is a large class; it makes more sense to write == operators
		* for everything than to write a giant equivalance test here.
		* For now this is mostly a regression test.
		*/

		erydbSelectExecutionPlan csep1, csep2;
		erydbSelectExecutionPlan::ReturnedColumnList colList;
		ParseTree* filterList;
		erydbExecutionPlan *cep;
		ByteStream b;
		
		cep = &csep2;
		
		CPPUNIT_ASSERT(csep1 == csep2);
		CPPUNIT_ASSERT(!(csep1 != csep2));
		CPPUNIT_ASSERT(csep1 == cep);
		CPPUNIT_ASSERT(!(csep1 != cep));
		
        // returned columns
		SimpleColumn *sc = new SimpleColumn("tpch.region.r_regionkey");
		colList.push_back(sc);
               
        // filters
		erydbSelectExecutionPlan::Parser parser;
		std::vector<Token> tokens;
		Token t;
        
		SimpleFilter *sf = new SimpleFilter();
		SimpleColumn *lhs = new SimpleColumn(*sc);       
		SimpleColumn *rhs = new SimpleColumn("tpch.nation.n_regionkey");
		Operator *op = new Operator("=");
        
		sf->op(op);
		sf->lhs(lhs);
		sf->rhs(rhs);
        
		t.value = sf;
		tokens.push_back(t);
        
		Operator *op1 = new Operator ("and");
		t.value = op1;
		tokens.push_back(t);
        
		SimpleFilter *sf1 = new SimpleFilter();
		SimpleColumn *lhs1 = new SimpleColumn (*rhs);       
		ConstantColumn *constCol = new ConstantColumn("3", ConstantColumn::NUM);        
		Operator *op2 = new Operator("!=");
        
		sf1->op(op2);
		sf1->lhs(lhs1);
		sf1->rhs(constCol);

		t.value = sf1;
		tokens.push_back(t);
        
		filterList = parser.parse(tokens.begin(), tokens.end());
        
        // draw filterList tree
		filterList->drawTree("selectExecutionPlan_1.dot");
                     
        // erydb execution plan        
		csep1.returnedCols (colList);
		csep1.filters (filterList);
		
		CPPUNIT_ASSERT(csep1 != csep2);
		CPPUNIT_ASSERT(!(csep1 == csep2));
		CPPUNIT_ASSERT(csep1 != cep);
		CPPUNIT_ASSERT(!(csep1 == cep));
		
		csep1.serialize(b);
		csep2.unserialize(b);
		CPPUNIT_ASSERT(b.length() == 0);
		
		CPPUNIT_ASSERT(csep1 == csep2);
		CPPUNIT_ASSERT(!(csep1 != csep2));
		CPPUNIT_ASSERT(csep1 == cep);
		CPPUNIT_ASSERT(!(csep1 != cep));
		
		erydbSelectExecutionPlan csep3, csep4;
        
        // subselect
		erydbSelectExecutionPlan *subselect = new erydbSelectExecutionPlan;
		subselect->location(erydbSelectExecutionPlan::WHERE);
		subselect->dependent (false);
		CPPUNIT_ASSERT (subselect->location() == erydbSelectExecutionPlan::WHERE);
		CPPUNIT_ASSERT (subselect->dependent() == false);
		erydbSelectExecutionPlan::SelectList selectList;
		selectList.push_back(subselect);
		csep3.subSelects(selectList);
        
        // exist filter
		erydbSelectExecutionPlan* cep1 = new erydbSelectExecutionPlan();
		ExistsFilter *filter = new ExistsFilter();
		delete filter;
		filter = new ExistsFilter(cep1);        
		filter->exists(cep1);
		//erydbSelectExecutionPlan* cep2 = const_cast<erydbSelectExecutionPlan*>(filter->exists());

		erydbSelectExecutionPlan::Parser parser1;
		std::vector<Token> tokens1;
		Token t1;
		t1.value = filter;
		tokens1.push_back(t1);
		csep3.filters(parser1.parse(tokens1.begin(), tokens1.end()));
		
		csep3.serialize(b);
		csep4.unserialize(b);
		
		CPPUNIT_ASSERT(csep3 == csep4);
		CPPUNIT_ASSERT(!(csep3 != csep4));
		
		
	}
示例#2
0
 void selectExecutionPlan_2()
 {
     erydbSelectExecutionPlan cep;
     
     // select filter
     erydbSelectExecutionPlan *subselect = new erydbSelectExecutionPlan;
     subselect->location(erydbSelectExecutionPlan::WHERE);
     subselect->dependent (false);
     CPPUNIT_ASSERT (subselect->location() == erydbSelectExecutionPlan::WHERE);
     CPPUNIT_ASSERT (subselect->dependent() == false);
     ByteStream selb;
     subselect->serialize(selb);
     erydbSelectExecutionPlan *subselect1 = new erydbSelectExecutionPlan;
     subselect->location(erydbSelectExecutionPlan::WHERE);
     subselect1->unserialize(selb);
     
     SelectFilter *sef = new SelectFilter ( new SimpleColumn ("tpch.region.r_regionkey", 0),
                                             new Operator (">="),
                                             subselect);
     cout << *sef;
     ByteStream b;
     sef->serialize(b);
     SelectFilter *newsef = new SelectFilter ( new SimpleColumn ("tpch.nation.n_regionke", 0),
                                             new Operator ("<="),
                                             subselect1);
     newsef->unserialize(b);
     CPPUNIT_ASSERT(*sef == *newsef);                                                
     delete sef;
     delete newsef;
     
     // simple filter
     Filter *sf = new SimpleFilter(new Operator("="), 
     															new SimpleColumn ("tpch.nation.n_regionke", 0),
     															new SimpleColumn ("tpch.region.r_regionkey", 0));
     cout << *sf;
     
     ByteStream sfb;
     SimpleFilter *sf2 = new SimpleFilter();
     sf2->serialize (sfb);
     sf->unserialize (sfb);
     CPPUNIT_ASSERT (*sf == *sf2);
     delete sf2;
     delete sf;
      
     // exist filter
     erydbSelectExecutionPlan *cep1 = new erydbSelectExecutionPlan();
     ExistsFilter *filter = new ExistsFilter();
     delete filter;
     filter = new ExistsFilter(cep1);        
     filter->exists(cep1);
     const erydbSelectExecutionPlan* cep2 = filter->exists();
     cout << *filter;
     CPPUNIT_ASSERT (*cep1 == *cep2);
     erydbSelectExecutionPlan::Parser parser;
     std::vector<Token> tokens;
     Token t;
     t.value = filter;
     tokens.push_back(t);
     cep.filters(parser.parse(tokens.begin(), tokens.end())); 
     cout << cep;
     
     cout << " --- end of test 2 ---" << endl;
 }