Esempio n. 1
0
void Sphere::sub(int n, Point3 p1, Point3 p2, Point3 p3) {
    Vector3 pv1(p1.x,p1.y,p1.z);
    Vector3 pv2(p2.x,p2.y,p2.z);
    Vector3 pv3(p3.x,p3.y,p3.z);
    if (n == 1) {
        pv1.normalize();
        pv2.normalize();
        pv3.normalize();
		pv1 *= 0.5;
		pv2 *= 0.5;
		pv3 *= 0.5;
        p1.x = pv1.x; p1.y = pv1.y; p1.z = pv1.z;
        p2.x = pv2.x; p2.y = pv2.y; p2.z = pv2.z;
        p3.x = pv3.x; p3.y = pv3.y; p3.z = pv3.z;
        addTriangle(p1,p2,p3);
    } else {
        Vector3 av = pv1+pv2; 
        Vector3 bv = pv2+pv3; 
        Vector3 cv = pv3+pv1; 
    
        av.normalize();
        bv.normalize();
        cv.normalize();

        Point3 v12(av.x,av.y,av.z); 
        Point3 v23(bv.x,bv.y,bv.z); 
        Point3 v31(cv.x,cv.y,cv.z);

        sub(n-1,p1,v12,v31);
        sub(n-1,p2,v23,v12);
        sub(n-1,p3,v31,v23);
        sub(n-1,v12,v23,v31);
    }
}
Esempio n. 2
0
void MirrorMod::DrawGizmo(float size,PolyLineProc& lp)
	{
	Point3 v0(0,0,0), pv0(0,0,0), v1(0,0,0), pv1(0,0,0);
	int ct=0;
	int axis;
	pblock->GetValue(PB_AXIS,0,axis,FOREVER);

	switch (axis) {
		case 0:
		case 1:
		case 2:
			v0[axis]        = -1.0f;
			pv0[(axis+1)%3]	= 1.0f;
			pv0[(axis+2)%3]	= 1.0f;
			ct=1;
			break;
		
		case 3:
		case 4:
		case 5:
			v0[(axis)%3]    = -1.0f;
			pv0[(axis+1)%3]	= 1.0f;
			pv0[(axis+2)%3]	= 1.0f;
			v1[(axis+1)%3]  = -1.0f;
			pv1[(axis+2)%3]	= 1.0f;
			pv1[(axis+3)%3]	= 1.0f;
			ct=2;
			break;
		}
	
	Point3 pts[20];
	SetupAxisPoints(v0, pv0, size, pts);
	lp.proc(pts,5);
	lp.proc(pts+5,2);
	lp.proc(pts+7,3);
	lp.proc(pts+10,3);
	lp.proc(pts+13,3);
	lp.proc(pts+16,3);

	if (ct==2) {
		SetupAxisPoints(v1, pv1, size, pts);
		lp.proc(pts,5);
		lp.proc(pts+5,2);
		lp.proc(pts+7,3);
		lp.proc(pts+10,3);
		lp.proc(pts+13,3);
		lp.proc(pts+16,3);
		}
	}
matrix2d<T> matrix2d<T>::appendCols(matrix2d<T> &m) {

  matrix2d<T> result(rows_, cols_ + m.cols_);

  std::size_t s1[] = {rows_,cols_}; // shape of left matrix
  std::size_t p1[] = {result.cols_,1}; // position of left matrix in result
  std::size_t s2[] = {m.rows_,m.cols_}; // shape of right matrix
  std::size_t p2[] = {result.cols_,1}; // position or right matrix in result

  std::valarray<std::size_t> sv1(s1, 2);
  std::valarray<std::size_t> pv1(p1, 2);
  std::valarray<std::size_t> sv2(s2, 2);
  std::valarray<std::size_t> pv2(p2, 2);

  result.data_[std::gslice(0, sv1, pv1)] = data_; // copy left matrix into place
  result.data_[std::gslice(cols_, sv2, pv2)] = m.data_; // repeat for m

  return result;
}
Esempio n. 4
0
NaGeCircle3d::NaGeCircle3d(const NaGePoint3D& P1, const NaGePoint3D& P2, const NaGePoint3D& P3)
{
    NaGePoint3D p1=P1, p2=P2, p3=P3;
    double x1, x2, x3, y1, y2, y3, z1, z2, z3;
    x1 = p1.GetX(); y1 = p1.GetY(); z1 = p1.GetZ();
    x2 = p2.GetX(); y2 = p2.GetY(); z2 = p2.GetZ();
    x3 = p3.GetX(); y3 = p3.GetY(); z3 = p3.GetZ();

    NaGeVector3D pv1(p1);
    NaGeVector3D pv2(p2);
    NaGeVector3D pv3(p3);

    NaGeVector3D n1(pv1, pv2); 
    NaGeVector3D n2(pv2, pv3);
    NaGeVector3D n3(pv3, pv1);

    double Row1[3]={n1.GetX(), n1.GetY(), n1.GetZ()};
    double Row2[3]={n2.GetX(), n2.GetY(), n2.GetZ()};
    double Row3[3]={n3.GetX(), n3.GetY(), n3.GetZ()};

    double b1, b2, b3;
    b1 = ((p1.Distance(p2))/2) + (x1*n1.GetX() + y1*n1.GetY() + z1*n1.GetZ());
    b2 = ((p2.Distance(p3))/2) + (x2*n2.GetX() + y2*n2.GetY() + z2*n2.GetZ());
    b3 = ((p3.Distance(p1))/2) + (x3*n3.GetX() + y3*n3.GetY() + z3*n3.GetZ());

    NaGeVector3D b(b1, b2, b3);
    NaGeMatrix33 M(Row1, Row2, Row3);

    M.Invert();

    NaGeVector3D cen = M*b;
    NaGeVector3D dir = n1.Crossed(n2);
    NaGeVector3D xdir = dir.Crossed(n1);

    NaGeAxisSystem ax(NaGePoint3D(cen.GetX(), cen.GetY(), cen.GetZ()), 
	    dir, xdir);
    itsLocation = ax;

    itsRadius = p1.Distance(cen.Point());

    cType = CIRCLE;
}
Esempio n. 5
0
int main(){
	chdir(QUERY_DATA_PATH);
	EnvDB *env = new EnvDB();
	env->open();
	
	BDBOpe db_r(env->getEnv(), "REGION20.row");
	BDBOpe db_n(env->getEnv(), "NATION20.row");
	BDBOpe db_c(env->getEnv(), "CUSTOMER20.row");
	BDBOpe db_o(env->getEnv(), "ORDERS20.row");
	BDBOpe db_l(env->getEnv(), "LINEITEM20.row");
	BDBOpe db_s(env->getEnv(), "SUPPLIER20.row");

	Operator *o1, *o2, *o3, *o4, *o5, *o6, *o7, *o8, *o9, *o10;
	Operator *o11, *o12, *o13, *o14, *o15, *o16, *o17, *o18, *o19, *o20;
	Operator *o21, *o22, *o23;
	
	db_r.open();
	db_n.open();
	db_c.open();
	db_o.open();
	db_l.open();
	db_s.open();


	TABLE_REC tableRec_r;
	TABLE_REC tableRec_n;
	TABLE_REC tableRec_c;
	TABLE_REC tableRec_o;
	TABLE_REC tableRec_l;
	TABLE_REC tableRec_s;

	
/* set table info */
	tableRec_r.tableID = 9;
	tableRec_r.attriNum = 3;
	
	tableRec_n.tableID = 10;
	tableRec_n.attriNum = 4;
	
	tableRec_c.tableID = 14;
	tableRec_c.attriNum = 8;

	tableRec_o.tableID = 15;
	tableRec_o.attriNum = 9;
	
	tableRec_l.tableID = 16;
	tableRec_l.attriNum = 16;
	
	tableRec_s.tableID = 11;
	tableRec_s.attriNum = 7;

/* aet attriRec */
	ATTRIBUTE_REC attriRec_r[tableRec_r.attriNum];
	ATTRIBUTE_REC attriRec_n[tableRec_n.attriNum];
	ATTRIBUTE_REC attriRec_c[tableRec_c.attriNum];
	ATTRIBUTE_REC attriRec_o[tableRec_o.attriNum];
	ATTRIBUTE_REC attriRec_l[tableRec_l.attriNum];
	ATTRIBUTE_REC attriRec_s[tableRec_s.attriNum];

	AttributeManager AM(env->getEnv());

	AM.getForTableID(tableRec_r, attriRec_r);
	AM.getForTableID(tableRec_n, attriRec_n);
	AM.getForTableID(tableRec_c, attriRec_c);
	AM.getForTableID(tableRec_o, attriRec_o);
	AM.getForTableID(tableRec_l, attriRec_l);
	AM.getForTableID(tableRec_s, attriRec_s);

/* selection1 */
	FixStrPosVal pv1(1,25);
	string str1("ASIA");
	pv1.setStr(str1);

	ValueNode vn1 = ValueNode(&pv1);
	ColumnRefNode cn1;
	cn1.tableID = 9;
	cn1.attriID = 2;
	AxprNode an1 = AxprNode(EQ, &cn1, &vn1);
	

/* selection2 */

	DatePosVal pv2(1,(unsigned char *)"1994-01-01");
	DatePosVal pv3(1,(unsigned char *)"1995-01-01");
	

	ValueNode vn2 = ValueNode(&pv2);
	ValueNode vn3 = ValueNode(&pv3);
	ColumnRefNode cn2;
	cn2.tableID = 15;
	cn2.attriID = 5;
	AxprNode an2 = AxprNode(GE, &cn2, &vn2);
	AxprNode an3 = AxprNode(LT, &cn2, &vn3);
	AxprNode an4 = AxprNode(AND, &an2, &an3);
	
	
/* GROUP */
	IntPosVal pv5(1, 1);
	ValueNode vn5 = ValueNode(&pv5);
	ColumnRefNode cn4[2];
	cn4[0].tableID = 16;
	cn4[0].attriID = 6;
	cn4[1].tableID = 16;
	cn4[1].attriID = 7;
	ArithmeticNode arith1(SUB, &vn5, &cn4[1]);
	ArithmeticNode arith2(MUL, &cn4[0], &arith1);
	
	Aggregation *aggre[1];
	aggre[0] = new Sum(&arith2, 2);
	
	
	OPERATION_NODE group[1];
	group[0].tableID = 10;
	group[0].attributeID = 2;




/* Join1 */

	OPERATION_NODE pn1[2];
	pn1[0].tableID = 9;
	pn1[0].attributeID = 1;
	pn1[1].tableID = 10;
	pn1[1].attributeID = 3;
	

	JOIN_OPERATION_NODE jpn1[1];
	jpn1[0].rightNode = pn1[0];
	jpn1[0].leftNode = pn1[1];
	
	
/* Join2 */
	OPERATION_NODE pn2[2];
	pn2[0].tableID = 10;
	pn2[0].attributeID = 1;
	pn2[1].tableID = 11;
	pn2[1].attributeID = 4;

	
	JOIN_OPERATION_NODE jpn2[1];
	jpn2[0].rightNode = pn2[0];
	jpn2[0].leftNode = pn2[1];

/* Join3 */
	OPERATION_NODE pn3[2];
	pn3[0].tableID = 11;
	pn3[0].attributeID = 1;
	pn3[1].tableID = 16;
	pn3[1].attributeID = 3;

	
	JOIN_OPERATION_NODE jpn3[1];
	jpn3[0].rightNode = pn3[0];
	jpn3[0].leftNode = pn3[1];
	
/* Join4 */
	OPERATION_NODE pn4[2];
	pn4[0].tableID = 15;
	pn4[0].attributeID = 1;
	pn4[1].tableID = 16;
	pn4[1].attributeID = 1;

	
	JOIN_OPERATION_NODE jpn4[1];
	jpn4[0].rightNode = pn4[0];
	jpn4[0].leftNode = pn4[1];

/* Join5 */
	OPERATION_NODE pn5[4];
	pn5[0].tableID = 14;
	pn5[0].attributeID = 1;
	pn5[1].tableID = 14;
	pn5[1].attributeID = 4;
	pn5[2].tableID = 15;
	pn5[2].attributeID = 2;
	pn5[3].tableID = 11;
	pn5[3].attributeID = 4;

	
	JOIN_OPERATION_NODE jpn5[2];
	jpn5[0].rightNode = pn5[0];
	jpn5[0].leftNode = pn5[2];
	jpn5[1].rightNode = pn5[1];
	jpn5[1].leftNode = pn5[3];


/* Projection1 */

	OPERATION_NODE pro1[1];
	pro1[0].tableID = 9;
	pro1[0].attributeID = 1;

/* Projection2 */

	OPERATION_NODE pro2[2];
	pro2[0].tableID = 10;
	pro2[0].attributeID = 1;
	pro2[1].tableID = 10;
	pro2[1].attributeID = 2;

/* Projection3 */

	OPERATION_NODE pro3[3];
	pro3[0].tableID = 11;
	pro3[0].attributeID = 1;
	pro3[1].tableID = 11;
	pro3[1].attributeID = 4;
	pro3[2].tableID = 10;
	pro3[2].attributeID = 2;
	
/* Projection4 */

	OPERATION_NODE pro4[5];
	pro4[0].tableID = 16;
	pro4[0].attributeID = 1;
	pro4[1].tableID = 16;
	pro4[1].attributeID = 6;
	pro4[2].tableID = 16;
	pro4[2].attributeID = 7;
	pro4[3].tableID = 11;
	pro4[3].attributeID = 4;
	pro4[4].tableID = 10;
	pro4[4].attributeID = 2;

/* Projection5 */
	
	OPERATION_NODE pro5[2];
	pro5[0].tableID = 15;
	pro5[0].attributeID = 1;
	pro5[1].tableID = 15;
	pro5[1].attributeID = 2;

/* Projection6 */
	
	OPERATION_NODE pro6[2];
	pro6[0].tableID = 14;
	pro6[0].attributeID = 1;
	pro6[1].tableID = 14;
	pro6[1].attributeID = 4;

/* Projection7 */
	
	OPERATION_NODE pro7[3];
	pro7[0].tableID = 10;
	pro7[0].attributeID = 2;
	pro7[1].tableID = 16;
	pro7[1].attributeID = 6;
	pro7[2].tableID = 16;
	pro7[2].attributeID = 7;


/* Sort 1 */
	OPERATION_NODE so1[1];
	so1[0].tableID = 0;
	so1[0].attributeID = 0;
	so1[0].position = 1;
	so1[0].option = 1;


	o1 = new Scan(&db_r, attriRec_r, 3);
//	cout << "OK new o1" << endl;
	o2 = new Selection((Node *)&an1 ,(unsigned int)1);
//	cout << "OK new o2" << endl;
	o2->setPreOperator(o1);
	//r_regionkey
	o3 = new Projection(pro1, 1);
	o3->setPreOperator(o2);
//	cout << "OK new o3" << endl;
	
	o4 = new Scan(&db_n, attriRec_n, 4);
//	cout << "OK new o4" << endl;
	o5 = new OneSideHashJoin(o3, o4 , jpn1, 1);
//	cout << "OK new o5" << endl;
	//n_natonkey, n_name
	o6 = new Projection(pro2, 2);
	o6->setPreOperator(o5);
//	cout << "OK new o6" << endl;
	
	
	o7 = new Scan(&db_s, attriRec_s, 7);
//	cout << "OK new o7" << endl;
	o8 = new OneSideHashJoin(o6, o7 , jpn2, 1);
//	cout << "OK new o8" << endl;
	//s_suppkey, s_nationkey, n_name
	o9 = new Projection(pro3, 3);
	o9->setPreOperator(o8);
//	cout << "OK new o9" << endl;


	o10 = new Scan(&db_l, attriRec_l, 16);
//	cout << "OK new o10" << endl;
	
	o11 = new OneSideHashJoin(o9, o10 , jpn3, 1);
//	cout << "OK new o11" << endl;
	//l_orderkey, l_extendedprice, l_discount, s_nationkey, n_name
	o12 = new Projection(pro4, 5);
	o12->setPreOperator(o11);
//	cout << "OK new o12" << endl;

	o13 = new Scan(&db_o, attriRec_o, 9);
//	cout << "OK new o13" << endl;
	
	o14 = new Selection((Node *)&an4 ,(unsigned int)2);
//	cout << "OK new o14" << endl;
	o14->setPreOperator(o13);
	//o_orderkey, o_custkey
	o15 = new Projection(pro5, 2);
	o15->setPreOperator(o14);
//	cout << "OK new o15" << endl;
	
	o16 = new OneSideHashJoin(o15, o12 , jpn4, 1);
//	cout << "OK new o16" << endl;

	o17 = new Scan(&db_c, attriRec_c, 8);
//	cout << "OK new o17" << endl;
	//c_custkey, c_nationkey 
	o18 = new Projection(pro6, 2);
	o18->setPreOperator(o17);
//	cout << "OK new o18" << endl;
	
	o19 = new OneSideHashJoin(o18, o16 , jpn5, 2);
//	cout << "OK new o19" << endl;
	//n_name, l_extendedprice, l_discount
	o20 = new Projection(pro7, 3);
	o20->setPreOperator(o19);
//	cout << "OK new o20" << endl;

	o21 = new GroupBy(group, 1, aggre, 1);
	o21->setPreOperator(o20);
//	cout << "OK new o21" << endl;

	o22 = new Sort(so1, 1);
	o22->setPreOperator(o21);
//	cout << "OK new o22" << endl;


	o23 = new OutPut(STD_OUT);
//	cout << "OK new o23" << endl;

	o23->setPreOperator(o22);
	o23->init(env->getEnv());
	cout << "TEST START Q5 NSM20" << endl;
	
	cout << setprecision(2);
	cout << setiosflags(ios::fixed); 
	o23->exec();
}
Esempio n. 6
0
int main(){
	chdir(QUERY_DATA_PATH);
	EnvDB *env = new EnvDB();
	env->open();
	
	BDBOpe db_r_1(env->getEnv(), "1.1.DSM");
	BDBOpe db_r_2(env->getEnv(), "1.2.DSM");
	BDBOpe db_n_1(env->getEnv(), "2.1.DSM");
	BDBOpe db_n_2(env->getEnv(), "2.2.DSM");
	BDBOpe db_n_3(env->getEnv(), "2.3.DSM");
	BDBOpe db_s_1(env->getEnv(), "3.1.DSM");
	BDBOpe db_s_4(env->getEnv(), "3.4.DSM");
	BDBOpe db_c_1(env->getEnv(), "6.1.DSM");
	BDBOpe db_c_4(env->getEnv(), "6.4.DSM");
	BDBOpe db_o_1(env->getEnv(), "7.1.DSM");
	BDBOpe db_o_2(env->getEnv(), "7.2.DSM");
	BDBOpe db_o_5(env->getEnv(), "7.5.DSM");
	BDBOpe db_l_1(env->getEnv(), "8.1.DSM");
	BDBOpe db_l_3(env->getEnv(), "8.3.DSM");
	BDBOpe db_l_6(env->getEnv(), "8.6.DSM");
	BDBOpe db_l_7(env->getEnv(), "8.7.DSM");
	
	db_r_1.open();
	db_r_2.open();
	db_n_1.open();
	db_n_2.open();
	db_n_3.open();
	db_s_1.open();
	db_s_4.open();
	db_c_1.open();
	db_c_4.open();
	db_o_1.open();
	db_o_2.open();
	db_o_5.open();
	db_l_1.open();
	db_l_3.open();
	db_l_6.open();
	db_l_7.open();


	Operator *o1, *o2, *o3, *o4, *o5, *o6, *o7, *o8, *o9, *o10;
	Operator *o11, *o12, *o13, *o14, *o15, *o16, *o17, *o18, *o19, *o20;
	Operator *o21, *o22, *o23, *o24, *o25, *o26, *o27, *o28, *o29, *o30;
	Operator *o31, *o32, *o33, *o34, *o35, *o36, *o37, *o38, *o39;



	TABLE_REC tableRec_r;
	TABLE_REC tableRec_n;
	TABLE_REC tableRec_c;
	TABLE_REC tableRec_o;
	TABLE_REC tableRec_l;
	TABLE_REC tableRec_s;

	
/* set table info */
	tableRec_r.tableID = 1;
	tableRec_r.attriNum = 3;
	
	tableRec_n.tableID = 2;
	tableRec_n.attriNum = 4;
	
	tableRec_s.tableID = 3;
	tableRec_s.attriNum = 7;
	
	tableRec_c.tableID = 6;
	tableRec_c.attriNum = 8;

	tableRec_o.tableID = 7;
	tableRec_o.attriNum = 9;
	
	tableRec_l.tableID = 8;
	tableRec_l.attriNum = 16;
	


/* aet attriRec */
	ATTRIBUTE_REC attriRec_r[tableRec_r.attriNum];
	ATTRIBUTE_REC attriRec_n[tableRec_n.attriNum];
	ATTRIBUTE_REC attriRec_s[tableRec_s.attriNum];
	ATTRIBUTE_REC attriRec_c[tableRec_c.attriNum];
	ATTRIBUTE_REC attriRec_o[tableRec_o.attriNum];
	ATTRIBUTE_REC attriRec_l[tableRec_l.attriNum];
	

	AttributeManager AM(env->getEnv());
	

	AM.getForTableID(tableRec_r, attriRec_r);
	AM.getForTableID(tableRec_n, attriRec_n);
	AM.getForTableID(tableRec_c, attriRec_c);
	AM.getForTableID(tableRec_o, attriRec_o);
	AM.getForTableID(tableRec_l, attriRec_l);
	AM.getForTableID(tableRec_s, attriRec_s);

/* selection1 */
	FixStrPosVal pv1(1,25);
	string str1("ASIA");
	pv1.setStr(str1);

	ValueNode vn1 = ValueNode(&pv1);
	ColumnRefNode cn1;
	cn1.tableID = 1;
	cn1.attriID = 2;
	AxprNode an1 = AxprNode(EQ, &cn1, &vn1);
	

/* selection2 */

	DatePosVal pv2(1,(unsigned char *)"1994-01-01");
	DatePosVal pv3(1,(unsigned char *)"1995-01-01");
	

	ValueNode vn2 = ValueNode(&pv2);
	ValueNode vn3 = ValueNode(&pv3);
	ColumnRefNode cn2;
	cn2.tableID = 7;
	cn2.attriID = 5;
	AxprNode an2 = AxprNode(GE, &cn2, &vn2);
	AxprNode an3 = AxprNode(LT, &cn2, &vn3);
	AxprNode an4 = AxprNode(AND, &an2, &an3);
	
	
/* GROUP */
	IntPosVal pv5(1, 1);
	ValueNode vn5 = ValueNode(&pv5);
	ColumnRefNode cn4[2];
	cn4[0].tableID = 8;
	cn4[0].attriID = 6;
	cn4[1].tableID = 8;
	cn4[1].attriID = 7;
	ArithmeticNode arith1(SUB, &vn5, &cn4[1]);
	ArithmeticNode arith2(MUL, &cn4[0], &arith1);
	
	Aggregation *aggre[1];
	aggre[0] = new Sum(&arith2, 2);
	
	
	OPERATION_NODE group[1];
	group[0].tableID = 2;
	group[0].attributeID = 2;
	
/* Sort 1 */
	OPERATION_NODE so1[1];
	so1[0].tableID = 0;
	so1[0].attributeID = 0;
	so1[0].position = 1;
	so1[0].option = 1;

/* Projection1 */

	OPERATION_NODE pro1[2];
	pro1[0].tableID = 2;
	pro1[0].attributeID = 1;
	pro1[1].tableID = 2;
	pro1[1].attributeID = 2;
	
/* Projection2 */

	OPERATION_NODE pro2[3];
	pro2[0].tableID = 3;
	pro2[0].attributeID = 1;
	pro2[1].tableID = 3;
	pro2[1].attributeID = 4;
	pro2[2].tableID = 2;
	pro2[2].attributeID = 2;
	
/* Projection3 */

	OPERATION_NODE pro3[3];
	pro3[0].tableID = 2;
	pro3[0].attributeID = 2;
	pro3[1].tableID = 8;
	pro3[1].attributeID = 6;
	pro3[2].tableID = 8;
	pro3[2].attributeID = 7;
	
	
	OPERATION_NODE op1;
	op1.tableID = 2;
	op1.attributeID = 3;
	
	OPERATION_NODE op2;
	op2.tableID = 3;
	op2.attributeID = 4;
	
	OPERATION_NODE op3;
	op3.tableID = 8;
	op3.attributeID = 3;
	
	OPERATION_NODE op4;
	op4.tableID = 7;
	op4.attributeID = 2;
	
	OPERATION_NODE op5;
	op5.tableID = 6;
	op5.attributeID = 4;
	
	
/* Join1 */
	OPERATION_NODE pn1[4];
	pn1[0].tableID = 6;
	pn1[0].attributeID = 1;
	pn1[1].tableID = 6;
	pn1[1].attributeID = 4;
	pn1[2].tableID = 7;
	pn1[2].attributeID = 2;
	pn1[3].tableID = 3;
	pn1[3].attributeID = 4;

	
	JOIN_OPERATION_NODE jpn1[2];
	jpn1[0].rightNode = pn1[0];
	jpn1[0].leftNode = pn1[2];
	jpn1[1].rightNode = pn1[1];
	jpn1[1].leftNode = pn1[3];
	
/* exec */
	
	o1 = new ScanDSM(&db_r_2, &attriRec_r[1], 1);
//	cout << "OK new o1" << endl;
	
	o2 = new SelectBitOut((Node *)&an1 ,(unsigned int)1);
//	cout << "OK new o2" << endl;
	o2->setPreOperator(o1);
	
	o3 = new ScanDSM(&db_r_1, &attriRec_r[0], 1);
//	cout << "OK new o3" << endl;
	
	o4 = new BitFilter(o3, o2);
//	cout << "OK new o4" << endl;

	o5 = new ScanDSM(&db_n_3, &attriRec_n[2], 1);
//	cout << "OK new o5" << endl;
	
	o6 = new JoinIndex_OneHash(o4, o5); 
//	cout << "OK new o6" << endl;

	
	o7 = new ScanDSM(&db_n_1, &attriRec_n[0], 1);
//	cout << "OK new o7" << endl;
	
	o8 = new ScanFromJI(o7, o6, &op1);
//	cout << "OK new o8" << endl;
	
	o9 = new ScanDSM(&db_n_2, &attriRec_n[1], 1);
//	cout << "OK new o9" << endl;
	
	//n_name, n_natonkey, r_regionkey, n_nationkey
	o10 = new ScanFromJI(o9, o8, &op1);
//	cout << "OK new o10" << endl;
	
	//n_name, n_natonkey
	o11 = new Projection(pro1, 2);
	o11->setPreOperator(o10);
//	cout << "OK new o11" << endl;
	
	o12 = new ScanDSM(&db_s_4, &attriRec_s[3], 1);
//	cout << "OK new o12" << endl;
	
	o13 = new JoinIndex_OneHash(o11, o12); 
//	cout << "OK new o13" << endl;
	
	o14 = new ScanDSM(&db_s_1, &attriRec_s[0], 1);
//	cout << "OK new o14" << endl;
	
	o15 = new ScanFromJI(o14, o13, &op2);
//	cout << "OK new o15" << endl;
	
	//s_suppkey s_nationkey n_name
	o16 = new Projection(pro2, 3);
	o16->setPreOperator(o15);
//	cout << "OK new o16" << endl;
	
	o17 = new ScanDSM(&db_l_3, &attriRec_l[2], 1);
//	cout << "OK new o17" << endl;
	
	o18 = new JoinIndex_OneHash(o16, o17); 
//	cout << "OK new o18" << endl;
	
	o19 = new ScanDSM(&db_l_6, &attriRec_l[5], 1);
//	cout << "OK new o19" << endl;
	
	o20 = new ScanFromJI(o19, o18, &op3);
//	cout << "OK new o20" << endl;
	
	o21 = new ScanDSM(&db_l_7, &attriRec_l[6], 1);
//	cout << "OK new o21" << endl;
	
	o22 = new ScanFromJI(o21, o20, &op3);
//	cout << "OK new o22" << endl;
	
	o23 = new ScanDSM(&db_l_1, &attriRec_l[0], 1);
//	cout << "OK new o23" << endl;
	
	//l_orderkey, l_extendedprice, l_discount, s_suppkey, s_nationkey, n_name, l_suppkey
	o24 = new ScanFromJI(o23, o22, &op3);
//	cout << "OK new o24" << endl;
	
	
	
	o25 = new ScanDSM(&db_o_5, &attriRec_o[4], 1);
//	cout << "OK new o25" << endl;
	
	o26 = new SelectBitOut((Node *)&an4 ,(unsigned int)2);
//	cout << "OK new o26" << endl;
	o26->setPreOperator(o25);
	
	o27 = new ScanDSM(&db_o_2, &attriRec_o[1], 1);
//	cout << "OK new o27" << endl;
	
	o28 = new BitFilter(o27, o26);
//	cout << "OK new o28" << endl;
	
	o29 = new ScanDSM(&db_o_1, &attriRec_o[0], 1);
//	cout << "OK new o29" << endl;
	
	//o_order, o_custkey
	o30 = new ScanFromJI(o29, o28, &op4);
//	cout << "OK new o30" << endl;
	
	//o_custkey, o_orderkey, l_orderkey, l_extendedprice, l_discount, s_suppkey, s_nationkey, n_name, l_suppkey
	o31 = new JoinIndex_OneHash(o30, o24); 
//	cout << "OK new o31" << endl;

	o32 = new ScanDSM(&db_c_4, &attriRec_c[3], 1);
//	cout << "OK new o32" << endl;
	
	o33 = new ScanDSM(&db_c_1, &attriRec_c[0], 1);
//	cout << "OK new o33" << endl;
	
	o34 = new ScanFromJI(o33, o32, &op5);
//	cout << "OK new o34" << endl;
	
	o35 = new OneSideHashJoin(o34, o31 , jpn1, 2);
//	cout << "OK new o31" << endl;
	
	
	o36 = new Projection(pro3, 3);
	o36->setPreOperator(o35);
//	cout << "OK new o36" << endl;
	
	o37 = new GroupBy(group, 1, aggre, 1);
	o37->setPreOperator(o36);
//	cout << "OK new o37" << endl;

	o38 = new Sort(so1, 1);
	o38->setPreOperator(o37);
//	cout << "OK new o38" << endl;
	
	o39 = new OutPut(STD_OUT);
//	cout << "OK new o39" << endl;

	o39->setPreOperator(o38);
	o39->init(env->getEnv());
	cout << "TEST START" << endl;
	
	cout << setprecision(4);
	cout << setiosflags(ios::fixed); 
	o39->exec();
}
Esempio n. 7
0
int main(){
	chdir("../RunData");
	BDBOpe db_r("REGION.row");
	BDBOpe db_n1("NATION.row");
	BDBOpe db_c("CUSTOMER.row");
	BDBOpe db_o("ORDERS.row");
	BDBOpe db_l("LINEITEM.row");
	BDBOpe db_p("PART.row");
	BDBOpe db_s("SUPPLIER.row");
	BDBOpe db_n2("NATION.row");
	Operator *o1, *o2, *o3, *o4, *o5, *o6, *o7, *o8, *o9, *o10;
	Operator *o11, *o12, *o13, *o14, *o15, *o16, *o17, *o18, *o19, *o20;
	Operator *o21, *o22, *o23, *o24, *o25, *o26, *o27, *o28, *o29, *o30;
	
	db_r.open();
	db_n1.open();
	db_c.open();
	db_o.open();
	db_l.open();
	db_p.open();
	db_s.open();
	db_n2.open();

	TABLE_REC tableRec_r;
	TABLE_REC tableRec_n1;
	TABLE_REC tableRec_c;
	TABLE_REC tableRec_o;
	TABLE_REC tableRec_l;
	TABLE_REC tableRec_p;
	TABLE_REC tableRec_s;
	TABLE_REC tableRec_n2;
	
/* set table info */
	tableRec_r.tableID = 1;
	tableRec_r.attriNum = 3;
	
	tableRec_n1.tableID = 2;
	tableRec_n1.attriNum = 4;
	
	tableRec_c.tableID = 6;
	tableRec_c.attriNum = 8;

	tableRec_o.tableID = 7;
	tableRec_o.attriNum = 9;
	
	tableRec_l.tableID = 8;
	tableRec_l.attriNum = 16;

	tableRec_p.tableID = 4;
	tableRec_p.attriNum = 9;
	
	tableRec_s.tableID = 3;
	tableRec_s.attriNum = 7;
	
	tableRec_n2.tableID = 2;
	tableRec_n2.attriNum = 4;

/* aet attriRec */
	ATTRIBUTE_REC attriRec_r[tableRec_r.attriNum];
	ATTRIBUTE_REC attriRec_n1[tableRec_n1.attriNum];
	ATTRIBUTE_REC attriRec_c[tableRec_c.attriNum];
	ATTRIBUTE_REC attriRec_o[tableRec_o.attriNum];
	ATTRIBUTE_REC attriRec_l[tableRec_l.attriNum];
	ATTRIBUTE_REC attriRec_p[tableRec_p.attriNum];
	ATTRIBUTE_REC attriRec_s[tableRec_s.attriNum];
	ATTRIBUTE_REC attriRec_n2[tableRec_n2.attriNum];

	AttributeManager AM_r;
	AttributeManager AM_n1;
	AttributeManager AM_c;
	AttributeManager AM_o;
	AttributeManager AM_l;
	AttributeManager AM_p;
	AttributeManager AM_s;
	AttributeManager AM_n2;

	AM_r.getForTableID(tableRec_r, attriRec_r);
	for(int i=0 ; i < (int)tableRec_r.attriNum ; i++){
		cout << attriRec_r[i].attributeName << endl;
	}
	AM_n1.getForTableID(tableRec_n1, attriRec_n1);
	for(int i=0 ; i < (int)tableRec_n1.attriNum ; i++){
		cout << attriRec_n1[i].attributeName << endl;
	}
	AM_c.getForTableID(tableRec_c, attriRec_c);
	for(int i=0 ; i < (int)tableRec_c.attriNum ; i++){
		cout << attriRec_c[i].attributeName << endl;
	}
	AM_o.getForTableID(tableRec_o, attriRec_o);
	for(int i=0 ; i < (int)tableRec_o.attriNum ; i++){
		cout << attriRec_o[i].attributeName << endl;
	}
	AM_l.getForTableID(tableRec_l, attriRec_l);
	for(int i=0 ; i < (int)tableRec_l.attriNum ; i++){
		cout << attriRec_l[i].attributeName << endl;
	}
	AM_p.getForTableID(tableRec_p, attriRec_p);
	for(int i=0 ; i < (int)tableRec_p.attriNum ; i++){
		cout << attriRec_p[i].attributeName << endl;
	}
	AM_s.getForTableID(tableRec_s, attriRec_s);
	for(int i=0 ; i < (int)tableRec_s.attriNum ; i++){
		cout << attriRec_s[i].attributeName << endl;
	}
	AM_n2.getForTableID(tableRec_n2, attriRec_n2);
	for(int i=0 ; i < (int)tableRec_n2.attriNum ; i++){
		cout << attriRec_n2[i].attributeName << endl;
	}

/* selection1 */
	FixStrPosVal pv1(1,25);
	string str1("AMERICA");
	pv1.setStr(str1);

	ValueNode vn1 = ValueNode(&pv1);
	ColumnRefNode cn1;
	cn1.tableID = 1;
	cn1.attriID = 2;
	AxprNode an1 = AxprNode(EQ, &cn1, &vn1);
	

/* selection2 */

	DatePosVal pv2(1,(unsigned char *)"1995-01-01");
	DatePosVal pv3(1,(unsigned char *)"1996-12-31");
	

	ValueNode vn2 = ValueNode(&pv2);
	ValueNode vn3 = ValueNode(&pv3);
	ColumnRefNode cn2;
	cn2.tableID = 7;
	cn2.attriID = 5;
	AxprNode an2 = AxprNode(GE, &cn2, &vn2);
	AxprNode an3 = AxprNode(LE, &cn2, &vn3);
	AxprNode an4 = AxprNode(AND, &an2, &an3);

/* selection3 */
	VarStrPosVal pv4(1,25);
	string str2("ECONOMY ANODIZED STEEL");
	pv4.set((unsigned char*)str2.c_str());

	ValueNode vn4 = ValueNode(&pv4);
	ColumnRefNode cn3;
	cn3.tableID = 4;
	cn3.attriID = 5;
	AxprNode an5 = AxprNode(EQ, &cn3, &vn4);
	
	
/* GROUP */
	IntPosVal pv5(1, 1);
	ValueNode vn5 = ValueNode(&pv5);
	ColumnRefNode cn4[2];
	cn4[0].tableID = 8;
	cn4[0].attriID = 6;
	cn4[1].tableID = 8;
	cn4[1].attriID = 7;
	ArithmeticNode arith1(SUB, &vn5, &cn4[1]);
	ArithmeticNode arith2(MUL, &cn4[0], &arith1);
	
	Aggregation *aggre[1];
	aggre[0] = new Sum(&arith2, 2);
	
	
	OPERATION_NODE group[1];
	group[0].tableID = 7;
	group[0].attributeID = 5;




/* Join1 */

	OPERATION_NODE pn1[2];
	pn1[0].tableID = 1;
	pn1[0].attributeID = 1;
	pn1[1].tableID = 2;
	pn1[1].attributeID = 3;
	

	JOIN_OPERATION_NODE jpn1[1];
	jpn1[0].rightNode = pn1[0];
	jpn1[0].leftNode = pn1[1];
	
	
/* Join2 */
	OPERATION_NODE pn2[2];
	pn2[0].tableID = 2;
	pn2[0].attributeID = 1;
	pn2[1].tableID = 6;
	pn2[1].attributeID = 4;

	
	JOIN_OPERATION_NODE jpn2[1];
	jpn2[0].rightNode = pn2[0];
	jpn2[0].leftNode = pn2[1];

/* Join3 */
	OPERATION_NODE pn3[2];
	pn3[0].tableID = 6;
	pn3[0].attributeID = 1;
	pn3[1].tableID = 7;
	pn3[1].attributeID = 2;

	
	JOIN_OPERATION_NODE jpn3[1];
	jpn3[0].rightNode = pn3[0];
	jpn3[0].leftNode = pn3[1];
	
/* Join4 */
	OPERATION_NODE pn4[2];
	pn4[0].tableID = 7;
	pn4[0].attributeID = 1;
	pn4[1].tableID = 8;
	pn4[1].attributeID = 1;

	
	JOIN_OPERATION_NODE jpn4[1];
	jpn4[0].rightNode = pn4[0];
	jpn4[0].leftNode = pn4[1];

/* Join5 */
	OPERATION_NODE pn5[2];
	pn5[0].tableID = 4;
	pn5[0].attributeID = 1;
	pn5[1].tableID = 8;
	pn5[1].attributeID = 2;

	
	JOIN_OPERATION_NODE jpn5[1];
	jpn5[0].rightNode = pn5[0];
	jpn5[0].leftNode = pn5[1];
	
/* Join6 */
	OPERATION_NODE pn6[2];
	pn6[0].tableID = 3;
	pn6[0].attributeID = 1;
	pn6[1].tableID = 8;
	pn6[1].attributeID = 3;

	
	JOIN_OPERATION_NODE jpn6[1];
	jpn6[0].rightNode = pn6[0];
	jpn6[0].leftNode = pn6[1];

/* Join7 */
	OPERATION_NODE pn7[2];
	pn7[0].tableID = 2;
	pn7[0].attributeID = 1;
	pn7[1].tableID = 3;
	pn7[1].attributeID = 4;

	
	JOIN_OPERATION_NODE jpn7[1];
	jpn7[0].rightNode = pn7[0];
	jpn7[0].leftNode = pn7[1];



/* Projection1 */

	OPERATION_NODE pro1[1];
	pro1[0].tableID = 1;
	pro1[0].attributeID = 1;

/* Projection2 */

	OPERATION_NODE pro2[2];
	pro2[0].tableID = 2;
	pro2[0].attributeID = 1;
	pro2[1].tableID = 2;
	pro2[1].attributeID = 3;

/* Projection3 */

	OPERATION_NODE pro3[1];
	pro3[0].tableID = 6;
	pro3[0].attributeID = 1;
	
/* Projection4 */

	OPERATION_NODE pro4[2];
	pro4[0].tableID = 7;
	pro4[0].attributeID = 1;
	pro4[1].tableID = 7;
	pro4[1].attributeID = 5;

/* Projection5 */
	
	OPERATION_NODE pro5[1];
	pro5[0].tableID = 4;
	pro5[0].attributeID = 1;

/* Projection6 */
	
	OPERATION_NODE pro6[2];
	pro6[0].tableID = 3;
	pro6[0].attributeID = 1;
	pro6[1].tableID = 3;
	pro6[1].attributeID = 4;

/* Projection7 */
	
	OPERATION_NODE pro7[2];
	pro7[0].tableID = 2;
	pro7[0].attributeID = 1;
	pro7[1].tableID = 2;
	pro7[1].attributeID = 2;

/* Projection8 */
	
	OPERATION_NODE pro8[7];
	pro8[0].tableID = 7;
	pro8[0].attributeID = 5;
	pro8[1].tableID = 2;
	pro8[1].attributeID = 2;
	pro8[2].tableID = 8;
	pro8[2].attributeID = 6;
	pro8[3].tableID = 8;
	pro8[3].attributeID = 7;
	pro8[4].tableID = 8;
	pro8[4].attributeID = 1;
	pro8[5].tableID = 8;
	pro8[5].attributeID = 2;
	pro8[6].tableID = 8;
	pro8[6].attributeID = 3;
	
	
/* Extract */
	OPERATION_NODE ex[1];
	ex[0].tableID = 7;
	ex[0].attributeID = 5;

/* Sort 1 */
	OPERATION_NODE so1[1];
	so1[0].tableID = 7;
	so1[0].attributeID = 5;
	so1[0].option = 0;

	o1 = new Scan(&db_r, attriRec_r, 3);
	cout << "OK new o1" << endl;
	o2 = new Selection((Node *)&an1 ,(unsigned int)1);
	cout << "OK new o2" << endl;
	o2->setPreOperator(o1);
	o3 = new Projection(pro1, 1);
	o3->setPreOperator(o2);
	cout << "OK new o3" << endl;
	
	o4 = new Scan(&db_n1, attriRec_n1, 4);
	cout << "OK new o4" << endl;
	o5 = new OneSideHashJoin(o3, o4 , jpn1, 1);
	cout << "OK new o5" << endl;
	o6 = new Projection(pro2, 1);
	o6->setPreOperator(o5);
	cout << "OK new o6" << endl;
	
	
	o7 = new Scan(&db_c, attriRec_c, 8);
	cout << "OK new o7" << endl;
	o8 = new OneSideHashJoin(o6, o7 , jpn2, 1);
	cout << "OK new o8" << endl;
	o9 = new Projection(pro3, 1);
	o9->setPreOperator(o8);
	cout << "OK new o9" << endl;
	

	o10 = new Scan(&db_o, attriRec_o, 9);
	cout << "OK new o10" << endl;
	o11 = new Selection((Node *)&an4 ,(unsigned int)2);
	cout << "OK new o11" << endl;
	o11->setPreOperator(o10);
	
	o12 = new OneSideHashJoin(o9, o11 , jpn3, 1);
	cout << "OK new o12" << endl;


	o13 = new Projection(pro4, 2);
	o13->setPreOperator(o12);
	cout << "OK new o13" << endl;
	
	o14 = new Scan(&db_l, attriRec_l, 16);
	cout << "OK new o14" << endl;
	o15 = new OneSideHashJoin(o13, o14 , jpn4, 1);
	cout << "OK new o15" << endl;

	o16 = new Scan(&db_p, attriRec_p, 9);
	cout << "OK new o16" << endl;
	o17 = new Selection((Node *)&an5 ,(unsigned int)1);
	cout << "OK new o17" << endl;
	o17->setPreOperator(o16);
	o18 = new Projection(pro5, 1);
	o18->setPreOperator(o17);
	cout << "OK new o18" << endl;
	o19 = new OneSideHashJoin(o18, o15 , jpn5, 1);
	cout << "OK new o19" << endl;
	
	
	o20 = new Scan(&db_s, attriRec_s, 7);
	cout << "OK new o20" << endl;
	o21 = new Projection(pro6, 2);
	o21->setPreOperator(o20);
	cout << "OK new o21" << endl;
	o22 = new OneSideHashJoin(o21, o19 , jpn6, 1);
	cout << "OK new o22" << endl;
	
	o23 = new Scan(&db_n2, attriRec_n2, 4);
	cout << "OK new o23" << endl;
	o24 = new Projection(pro7, 2);
	o24->setPreOperator(o23);
	cout << "OK new o24" << endl;
	o25 = new OneSideHashJoin(o24, o22 , jpn7, 1);
	cout << "OK new o25" << endl;
	
	o26 = new Extract(ex, true, false, false);
	o26->setPreOperator(o25);
	cout << "OK new o26" << endl;
	
	o27 = new Projection(pro8, 7);
	o27->setPreOperator(o26);
	cout << "OK new o27" << endl;


	o28 = new GroupBy(group, 1, aggre, 1);
	o28->setPreOperator(o27);
	cout << "OK new o28" << endl;

	o29 = new Sort(so1, 1);
	o29->setPreOperator(o28);
	cout << "OK new o29" << endl;


	o30 = new OutPut(STD_OUT);
	cout << "OK new o30" << endl;

	o30->setPreOperator(o29);
	o30->init();
	cout << "TEST START" << endl;
	
	cout << setprecision(2);
	cout << setiosflags(ios::fixed); 
	o30->exec();
}
void
CoinShallowPackedVectorUnitTest()
{
  CoinRelFltEq eq;
  int i;
  // Test default constructor
  {
    CoinShallowPackedVector r;
    assert( r.indices_==NULL );
    assert( r.elements_==NULL );
    assert( r.nElements_==0 );
  }

  // Test set and get methods
  const int ne = 4;
  int inx[ne] = { 1, 3, 4, 7 };
  double el[ne] = { 1.2, 3.4, 5.6, 7.8 };
  {
    CoinShallowPackedVector r;    
    assert( r.getNumElements()==0 );
    
    // Test setting/getting elements with int* & double* vectors
    r.setVector( ne, inx, el );
    assert( r.getNumElements()==ne );
    for ( i=0; i<ne; i++ ) {
      assert( r.getIndices()[i]  == inx[i] );
      assert( r.getElements()[i] == el[i]  );
    }
    assert ( r.getMaxIndex()==7 );
    assert ( r.getMinIndex()==1 );

    // try to clear it
    r.clear();
    assert( r.indices_==NULL );
    assert( r.elements_==NULL );
    assert( r.nElements_==0 );

    // Test setting/getting elements with indices out of order  
    const int ne2 = 5;
    int inx2[ne2] = { 2, 4, 8, 14, 3 };
    double el2[ne2] = { 2.2, 4.4, 6.6, 8.8, 3.3 };
 
    r.setVector(ne2,inx2,el2);
    
    assert( r.getNumElements()==ne2 );    
    for (i = 0; i < ne2; ++i) {
       assert( r.getIndices()[i]==inx2[i] );
       assert( r.getElements()[i]==el2[i] );
    }
    
    assert ( r.getMaxIndex()==14 );
    assert ( r.getMinIndex()==2 );
    // try to call it once more
    assert ( r.getMaxIndex()==14 );
    assert ( r.getMinIndex()==2 );

    CoinShallowPackedVector r1(ne2,inx2,el2);
    assert( r == r1 );

    // assignment operator
    r1.clear();
    r1 = r;
    assert( r == r1 );

    // assignment from packed vector
    CoinPackedVector pv1(ne2,inx2,el2);
    r1 = pv1;
    assert( r == r1 );

    // construction
    CoinShallowPackedVector r2(r1);
    assert( r2 == r );
    
    // construction from packed vector
    CoinShallowPackedVector r3(pv1);
    assert( r3 == r );

    // test duplicate indices
    {
      const int ne3 = 4;
      int inx3[ne3] = { 2, 4, 2, 3 };
      double el3[ne3] = { 2.2, 4.4, 8.8, 6.6 };
      r.setVector(ne3,inx3,el3, false);
      assert(r.testForDuplicateIndex() == false);
      bool errorThrown = false;
      try {
        r.setTestForDuplicateIndex(true);
      }
      catch (CoinError& e) {
        errorThrown = true;
      }
      assert( errorThrown );

      r.clear();
      errorThrown = false;
      try {
	 r.setVector(ne3,inx3,el3);
      }
      catch (CoinError& e) {
        errorThrown = true;
      }
      assert( errorThrown );
	 
      errorThrown = false;
      try {
	 CoinShallowPackedVector r1(ne3,inx3,el3);
      }
      catch (CoinError& e) {
	 errorThrown = true;
      }
      assert( errorThrown );
    } 
    
  } 

  // Test copy constructor and assignment operator
  {
    CoinShallowPackedVector rhs;
    {
      CoinShallowPackedVector r;
      {
        CoinShallowPackedVector rC1(r);      
        assert( 0==r.getNumElements() );
        assert( 0==rC1.getNumElements() );
        
        r.setVector( ne, inx, el ); 
        
        assert( ne==r.getNumElements() );
        assert( 0==rC1.getNumElements() ); 
      }
      
      CoinShallowPackedVector rC2(r);   
      
      assert( ne==r.getNumElements() );
      assert( ne==rC2.getNumElements() );
      
      for ( i=0; i<ne; i++ ) {
        assert( r.getIndices()[i] == rC2.getIndices()[i] );
        assert( r.getElements()[i] == rC2.getElements()[i] );
      }

      rhs=rC2;
    }
    // Test that rhs has correct values even though lhs has gone out of scope
    assert( rhs.getNumElements()==ne );
    
    for ( i=0; i<ne; i++ ) {
      assert( inx[i] == rhs.getIndices()[i] );
      assert(  el[i] == rhs.getElements()[i] );
    } 
  }

  // Test operator==
  {
    CoinShallowPackedVector v1,v2;
    assert( v1==v2 );
    assert( v2==v1 );
    assert( v1==v1 );
    assert( !(v1!=v2) );
    
    v1.setVector( ne, inx, el );
    assert ( !(v1==v2) );
    assert ( v1!=v2 );

    CoinShallowPackedVector v3(v1);
    assert( v3==v1 );
    assert( v3!=v2 );

    CoinShallowPackedVector v4(v2);
    assert( v4!=v1 );
    assert( v4==v2 );
  }

 

  {
    // Test operator[] and isExistingIndex()
    const int ne = 4;
    int inx[ne] =   {  1,   4,  0,   2 };
    double el[ne] = { 10., 40., 1., 50. };
    CoinShallowPackedVector r;
    assert( r[1]==0. );

    r.setVector(ne,inx,el);

    assert( r[-1]==0. );
    assert( r[ 0]==1. );
    assert( r[ 1]==10.);
    assert( r[ 2]==50.);
    assert( r[ 3]==0. );
    assert( r[ 4]==40.);
    assert( r[ 5]==0. );
    assert(  r.isExistingIndex(2) );
    assert( !r.isExistingIndex(3) );

    assert( !r.isExistingIndex(-1) );
    assert(  r.isExistingIndex(0) );
    assert( !r.isExistingIndex(3) );
    assert(  r.isExistingIndex(4) );
    assert( !r.isExistingIndex(5) );
    
    assert ( r.getMaxIndex()==4 );
    assert ( r.getMinIndex()==0 );
  }
  
  // Test that attemping to get min/max index of a 0,
  // length vector 
  {
    CoinShallowPackedVector nullVec;
    assert( nullVec.getMaxIndex() == -COIN_INT_MAX/*0*/ );
    assert( nullVec.getMinIndex() == COIN_INT_MAX/*0*/ );
  } 

  {
     // test dense vector
     const int ne = 4;
     int inx[ne] =   {  1,   4,  0,   2 };
     double el[ne] = { 10., 40., 1., 50. };
     CoinShallowPackedVector r;
     r.setVector(ne,inx,el);
     double * dense = r.denseVector(6);
     assert(dense[0] == 1.);
     assert(dense[1] == 10.);
     assert(dense[2] == 50.);
     assert(dense[3] == 0.);
     assert(dense[4] == 40.);
     assert(dense[5] == 0.);
     delete[] dense;

     // try once more
     dense = r.denseVector(7);
     assert(dense[0] == 1.);
     assert(dense[1] == 10.);
     assert(dense[2] == 50.);
     assert(dense[3] == 0.);
     assert(dense[4] == 40.);
     assert(dense[5] == 0.);
     assert(dense[6] == 0.);
     delete[] dense;
     
  }
     
     

  
#if 0
  // what happens when someone sets 
  // the number of elements to be a negative number
  {    
    const int ne = 4;
    int inx1[ne] = { 1, 3, 4, 7 };
    double el1[ne] = { 1.2, 3.4, 5.6, 7.8 };
    CoinShallowPackedVector v1;
    v1.setVector(-ne,inx1,el1);
  }
#endif

  
  // Test adding vectors
  {    
    const int ne1 = 5;
    int inx1[ne1]   = { 1,  3,  4,  7,  5  };
    double el1[ne1] = { 1., 5., 6., 2., 9. };
    const int ne2 = 4;
    int inx2[ne2] =   { 7,  4,  2,  1  };
    double el2[ne2] = { 7., 4., 2., 1. };
    CoinShallowPackedVector v1;
    v1.setVector(ne1,inx1,el1);
    CoinShallowPackedVector v2;
    v2.setVector(ne2,inx2,el2);
    CoinPackedVector r = v1 + v2;

    const int ner = 6;
    int inxr[ner] =   {    1,     2,     3,     4,     5,     7  };
    double elr[ner] = { 1.+1., 0.+2., 5.+0., 6.+4., 9.+0., 2.+7. };
    CoinPackedVector rV;
    rV.setVector(ner,inxr,elr);
    assert( rV != r );
    assert( r.isEquivalent(rV) );
    
    CoinPackedVector p1=v1+3.1415;
    for ( i=0; i<p1.getNumElements(); i++ )
      assert( eq( p1.getElements()[i], v1.getElements()[i]+3.1415) );

    CoinPackedVector p2=(-3.1415) + p1;
    assert( p2.isEquivalent(v1) );
  } 
  
  // Test subtracting vectors
  {    
    const int ne1 = 5;
    int inx1[ne1]   = { 1,  3,  4,  7,  5  };
    double el1[ne1] = { 1., 5., 6., 2., 9. };
    const int ne2 = 4;
    int inx2[ne2] =   { 7,  4,  2,  1  };
    double el2[ne2] = { 7., 4., 2., 1. };
    CoinShallowPackedVector v1;
    v1.setVector(ne1,inx1,el1);
    CoinShallowPackedVector v2;
    v2.setVector(ne2,inx2,el2);
    CoinPackedVector r = v1 - v2;

    const int ner = 6;
    int inxr[ner] =   {    1,     2,     3,     4,     5,     7  };
    double elr[ner] = { 1.-1., 0.-2., 5.-0., 6.-4., 9.-0., 2.-7. };
    CoinPackedVector rV;
    rV.setVector(ner,inxr,elr);
    assert( r.isEquivalent(rV) );  
    
    CoinPackedVector p1=v1-3.1415;
    for ( i=0; i<p1.getNumElements(); i++ )
      assert( eq( p1.getElements()[i], v1.getElements()[i]-3.1415) );
  } 
  
  // Test multiplying vectors
  {    
    const int ne1 = 5;
    int inx1[ne1]   = { 1,  3,  4,  7,  5  };
    double el1[ne1] = { 1., 5., 6., 2., 9. };
    const int ne2 = 4;
    int inx2[ne2] =   { 7,  4,  2,  1  };
    double el2[ne2] = { 7., 4., 2., 1. };
    CoinShallowPackedVector v1;
    v1.setVector(ne1,inx1,el1);
    CoinShallowPackedVector v2;
    v2.setVector(ne2,inx2,el2);
    CoinPackedVector r = v1 * v2;

    const int ner = 6;
    int inxr[ner] =   {    1,     2,     3,     4,     5,     7  };
    double elr[ner] = { 1.*1., 0.*2., 5.*0., 6.*4., 9.*0., 2.*7. };
    CoinPackedVector rV;
    rV.setVector(ner,inxr,elr);
    assert( r.isEquivalent(rV) );

    CoinPackedVector p1=v1*3.3;
    for ( i=0; i<p1.getNumElements(); i++ )
      assert( eq( p1.getElements()[i], v1.getElements()[i]*3.3) );
    
    CoinPackedVector p2=(1./3.3) * p1;
    assert( p2.isEquivalent(v1) );
  } 
  
  // Test dividing vectors
  {    
    const int ne1 = 3;
    int inx1[ne1]   = { 1,  4,  7  };
    double el1[ne1] = { 1., 6., 2. };
    const int ne2 = 4;
    int inx2[ne2] =   { 7,  4,  2,  1  };
    double el2[ne2] = { 7., 4., 2., 1. };
    CoinShallowPackedVector v1;
    v1.setVector(ne1,inx1,el1);
    CoinShallowPackedVector v2;
    v2.setVector(ne2,inx2,el2);
    CoinPackedVector r = v1 / v2;

    const int ner = 4;
    int inxr[ner] =   {    1,     2,      4,     7  };
    double elr[ner] = { 1./1., 0./2.,  6./4., 2./7. };
    CoinPackedVector rV;
    rV.setVector(ner,inxr,elr);
    assert( r.isEquivalent(rV) );
        
    CoinPackedVector p1=v1/3.1415;
    for ( i=0; i<p1.getNumElements(); i++ )
      assert( eq( p1.getElements()[i], v1.getElements()[i]/3.1415) );
  }
   
  // Test sum
  { 
    CoinShallowPackedVector s;
    assert( s.sum() == 0 );

    int inx = 25;
    double value = 45.;
    s.setVector(1, &inx, &value);
    assert(s.sum()==45.);

    const int ne1 = 5;
    int inx1[ne1]   = { 10,  3,  4,  7,  5  };
    double el1[ne1] = { 1., 5., 6., 2., 9. };
    s.setVector(ne1,inx1,el1);

    assert(s.sum()==1.+5.+6.+2.+9.);
  }
  
  // Just another interesting test
  {    
    // Create numerator vector
    const int ne1 = 2;
    int inx1[ne1]   = { 1,  4  };
    double el1[ne1] = { 1., 6. };
    CoinShallowPackedVector v1(ne1,inx1,el1);

    // create denominator vector
    const int ne2 = 3;
    int inx2[ne2] =   { 1,  2,  4 };
    double el2[ne2] = { 1., 7., 4.};
    CoinShallowPackedVector v2(ne2,inx2,el2);

    // Compute ratio
    CoinPackedVector ratio = v1 / v2;

    // Sort ratios
    ratio.sortIncrElement();

    // Test that the sort really worked
    assert( ratio.getElements()[0] == 0.0/7.0 );
    assert( ratio.getElements()[1] == 1.0/1.0 );
    assert( ratio.getElements()[2] == 6.0/4.0 );

    // Get numerator of of sorted ratio vector
    assert( v1[ ratio.getIndices()[0] ] == 0.0 );
    assert( v1[ ratio.getIndices()[1] ] == 1.0 );
    assert( v1[ ratio.getIndices()[2] ] == 6.0 );

    // Get denominator of of sorted ratio vector
    assert( v2[ ratio.getIndices()[0] ] == 7.0 );
    assert( v2[ ratio.getIndices()[1] ] == 1.0 );
    assert( v2[ ratio.getIndices()[2] ] == 4.0 );
  }

  {
    // Test that sample usage works

    const int ne = 4;
    int inx[ne] =   {  1,   4,  0,   2 };
    double el[ne] = { 10., 40., 1., 50. };
    CoinShallowPackedVector r(ne,inx,el);

    assert( r.getIndices()[0]== 1  );
    assert( r.getElements()[0]==10. );
    assert( r.getIndices()[1]== 4  );
    assert( r.getElements()[1]==40. );
    assert( r.getIndices()[2]== 0  );
    assert( r.getElements()[2]== 1. );
    assert( r.getIndices()[3]== 2  );
    assert( r.getElements()[3]==50. );

    assert( r[ 0]==1. );
    assert( r[ 1]==10.);
    assert( r[ 2]==50.);
    assert( r[ 3]==0. );
    assert( r[ 4]==40.);

    CoinShallowPackedVector r1;
    r1=r;
    assert( r==r1 );

    CoinPackedVector add = r + r1;
    assert( add[0] ==  1.+ 1. );
    assert( add[1] == 10.+10. );
    assert( add[2] == 50.+50. );
    assert( add[3] ==  0.+ 0. );
    assert( add[4] == 40.+40. );

    assert( r.sum() == 10.+40.+1.+50. );
  }
  
  {
    // Test findIndex
    const int ne = 4;
    int inx[ne] =   {  1,  -4,  0,   2 };
    double el[ne] = { 10., 40., 1., 50. };
    CoinShallowPackedVector r(ne,inx,el);

    assert( r.findIndex(2)  == 3 );
    assert( r.findIndex(0)  == 2 );
    assert( r.findIndex(-4) == 1 );
    assert( r.findIndex(1)  == 0 );
    assert( r.findIndex(3)  == -1 );
  }  
  {
    // Test construction with testing for duplicates as false
    const int ne = 4;
    int inx[ne] =   {  1,  -4,  0,   2 };
    double el[ne] = { 10., 40., 1., 50. };
    CoinShallowPackedVector r(ne,inx,el,false);

    assert( r.isExistingIndex(1) );
    assert( r.isExistingIndex(-4) );
    assert( r.isExistingIndex(0) );
    assert( r.isExistingIndex(2) );
    assert( !r.isExistingIndex(3) );
    assert( !r.isExistingIndex(-3) );
  }
}
Esempio n. 9
0
int main(){
	chdir(QUERY_DATA_PATH);
	EnvDB *env = new EnvDB();
	env->open();
	
	BDBOpe db_r_1(env->getEnv(), "1.1.DSM");
	BDBOpe db_r_2(env->getEnv(), "1.2.DSM");
	BDBOpe db_n_1(env->getEnv(), "2.1.DSM");
	BDBOpe db_n2_1(env->getEnv(), "2.1.DSM");
	BDBOpe db_n2_2(env->getEnv(), "2.2.DSM");
	BDBOpe db_n_3(env->getEnv(), "2.3.DSM");
	BDBOpe db_s_1(env->getEnv(), "3.1.DSM");
	BDBOpe db_s_4(env->getEnv(), "3.4.DSM");
	BDBOpe db_p_1(env->getEnv(), "4.1.DSM");
	BDBOpe db_p_5(env->getEnv(), "4.5.DSM");
	BDBOpe db_c_1(env->getEnv(), "6.1.DSM");
	BDBOpe db_c_4(env->getEnv(), "6.4.DSM");
	BDBOpe db_o_1(env->getEnv(), "7.1.DSM");
	BDBOpe db_o_2(env->getEnv(), "7.2.DSM");
	BDBOpe db_o_5(env->getEnv(), "7.5.DSM");
	BDBOpe db_l_1(env->getEnv(), "8.1.DSM");
	BDBOpe db_l_2(env->getEnv(), "8.2.DSM");
	BDBOpe db_l_3(env->getEnv(), "8.3.DSM");
	BDBOpe db_l_6(env->getEnv(), "8.6.DSM");
	BDBOpe db_l_7(env->getEnv(), "8.7.DSM");

	Operator *o1, *o2, *o3, *o4, *o5, *o6, *o7, *o8, *o9, *o10;
	Operator *o11, *o12, *o13, *o14, *o15, *o16, *o17, *o18, *o19, *o20;
	Operator *o21, *o22, *o23, *o24, *o25, *o26, *o27, *o28, *o29, *o30;
	Operator *o31, *o32, *o33, *o34, *o35, *o36, *o37, *o38, *o39, *o40;
	Operator *o41, *o42, *o43, *o44, *o45, *o46, *o47, *o48, *o49, *o50, *o51;
	db_r_1.open();
	db_r_2.open();
	db_n_1.open();
	db_n2_1.open();
	db_n2_2.open();
	db_n_3.open();
	db_s_1.open();
	db_s_4.open();
	db_p_1.open();
	db_p_5.open();
	db_c_1.open();
	db_c_4.open();
	db_o_1.open();
	db_o_2.open();
	db_o_5.open();
	
	db_l_1.open();
	db_l_2.open();
	db_l_3.open();
	db_l_6.open();
	db_l_7.open();
	
	TABLE_REC tableRec_r;
	TABLE_REC tableRec_n;
	TABLE_REC tableRec_s;
	TABLE_REC tableRec_p;
	TABLE_REC tableRec_c;
	TABLE_REC tableRec_o;
	TABLE_REC tableRec_l;

	tableRec_r.tableID = 1;
	tableRec_r.attriNum = 3;

	tableRec_n.tableID = 2;
	tableRec_n.attriNum = 4;
	
	tableRec_s.tableID = 3;
	tableRec_s.attriNum = 7;
	
	tableRec_p.tableID = 4;
	tableRec_p.attriNum = 9;
	
	tableRec_c.tableID = 6;
	tableRec_c.attriNum = 8;
	
	tableRec_o.tableID = 7;
	tableRec_o.attriNum = 9;
	
	tableRec_l.tableID = 8;
	tableRec_l.attriNum = 16;
	
	
	ATTRIBUTE_REC attriRec_r[tableRec_r.attriNum];
	ATTRIBUTE_REC attriRec_n[tableRec_n.attriNum];
	ATTRIBUTE_REC attriRec_s[tableRec_s.attriNum];
	ATTRIBUTE_REC attriRec_p[tableRec_p.attriNum];
	ATTRIBUTE_REC attriRec_c[tableRec_c.attriNum];
	ATTRIBUTE_REC attriRec_o[tableRec_o.attriNum];
	ATTRIBUTE_REC attriRec_l[tableRec_l.attriNum];

	AttributeManager AM(env->getEnv());
	
	AM.getForTableID(tableRec_r, attriRec_r);
/*	for(int i=0 ; i < (int)tableRec_r.attriNum ; i++){
		cout << attriRec_r[i].attributeName << endl;
	}
*/
	AM.getForTableID(tableRec_n, attriRec_n);
/*	for(int i=0 ; i < (int)tableRec_n.attriNum ; i++){
		cout << attriRec_n[i].attributeName << endl;
	}
*/
	AM.getForTableID(tableRec_s, attriRec_s);
/*	for(int i=0 ; i < (int)tableRec_s.attriNum ; i++){
		cout << attriRec_s[i].attributeName << endl;
	}
*/
	AM.getForTableID(tableRec_p, attriRec_p);
/*	for(int i=0 ; i < (int)tableRec_p.attriNum ; i++){
		cout << attriRec_p[i].attributeName << endl;
	}
*/
	AM.getForTableID(tableRec_c, attriRec_c);
/*	for(int i=0 ; i < (int)tableRec_c.attriNum ; i++){
		cout << attriRec_c[i].attributeName << endl;
	}
*/
	AM.getForTableID(tableRec_o, attriRec_o);
/*	for(int i=0 ; i < (int)tableRec_o.attriNum ; i++){
		cout << attriRec_o[i].attributeName << endl;
	}
*/
	AM.getForTableID(tableRec_l, attriRec_l);
/*	for(int i=0 ; i < (int)tableRec_l.attriNum ; i++){
		cout << attriRec_l[i].attributeName << endl;
	}
*/

/* selection1 */
	FixStrPosVal pv1(1,25);
	string str1("AMERICA");
	pv1.setStr(str1);

	ValueNode vn1 = ValueNode(&pv1);
	ColumnRefNode cn1;
	cn1.tableID = 1;
	cn1.attriID = 2;
	AxprNode an1 = AxprNode(EQ, &cn1, &vn1);
	

/* selection2 */

	DatePosVal pv2(1,(unsigned char *)"1995-01-01");
	DatePosVal pv3(1,(unsigned char *)"1996-12-31");
	

	ValueNode vn2 = ValueNode(&pv2);
	ValueNode vn3 = ValueNode(&pv3);
	ColumnRefNode cn2;
	cn2.tableID = 7;
	cn2.attriID = 5;
	AxprNode an2 = AxprNode(GE, &cn2, &vn2);
	AxprNode an3 = AxprNode(LE, &cn2, &vn3);
	AxprNode an4 = AxprNode(AND, &an2, &an3);

/* selection3 */
	VarStrPosVal pv4(1,25);
	string str2("ECONOMY ANODIZED STEEL");
	pv4.set((unsigned char*)str2.c_str());

	ValueNode vn4 = ValueNode(&pv4);
	ColumnRefNode cn3;
	cn3.tableID = 4;
	cn3.attriID = 5;
	AxprNode an5 = AxprNode(EQ, &cn3, &vn4);
	

	
/*Join1*/
	OPERATION_NODE jop1, jop2;
	jop1.tableID = 6;
	jop1.attributeID = 4;
	jop2.tableID = 6;
	jop2.attributeID = 1;
	
	JOIN_OPERATION_NODE jon1;
	jon1.rightNode = jop1;
	jon1.leftNode = jop2;

/*Join2*/
	OPERATION_NODE jop3, jop4;
	jop3.tableID = 7;
	jop3.attributeID = 2;
	jop4.tableID = 7;
	jop4.attributeID = 5;
	
	JOIN_OPERATION_NODE jon2;
	jon2.rightNode = jop3;
	jon2.leftNode = jop4;

/*Join3*/
	OPERATION_NODE jop5, jop6;
	jop5.tableID = 7;
	jop5.attributeID = 5;
	jop6.tableID = 7;
	jop6.attributeID = 1;
	
	JOIN_OPERATION_NODE jon3;
	jon3.rightNode = jop5;
	jon3.leftNode = jop6;

/*Join4*/
	OPERATION_NODE jop7, jop8;
	jop7.tableID = 7;
	jop7.attributeID = 1;
	jop8.tableID = 8;
	jop8.attributeID = 1;
	
	JOIN_OPERATION_NODE jon4;
	jon4.rightNode = jop7;
	jon4.leftNode = jop8;
	
/*Join5*/
	OPERATION_NODE jop9, jop10;
	jop9.tableID = 4;
	jop9.attributeID = 1;
	jop10.tableID = 8;
	jop10.attributeID = 2;
	
	JOIN_OPERATION_NODE jon5;
	jon5.rightNode = jop9;
	jon5.leftNode = jop10;

/*Join6*/
	OPERATION_NODE jop11, jop12;
	jop11.tableID = 6;
	jop11.attributeID = 1;
	jop12.tableID = 7;
	jop12.attributeID = 2;
	
	JOIN_OPERATION_NODE jon6;
	jon6.rightNode = jop11;
	jon6.leftNode = jop12;
	
/*Join7*/
	OPERATION_NODE jop13, jop14;
	jop13.tableID = 3;
	jop13.attributeID = 1;
	jop14.tableID = 8;
	jop14.attributeID = 3;
	
	JOIN_OPERATION_NODE jon7;
	jon7.rightNode = jop13;
	jon7.leftNode = jop14;
	
/*Join8*/
	OPERATION_NODE jop15, jop16;
	jop15.tableID = 2;
	jop15.attributeID = 1;
	jop16.tableID = 3;
	jop16.attributeID = 4;
	
	JOIN_OPERATION_NODE jon8;
	jon8.rightNode = jop15;
	jon8.leftNode = jop16;
	
/* Projection1 */

	OPERATION_NODE pro1[1];
	pro1[0].tableID = 6;
	pro1[0].attributeID = 1;
	
	
/* Projection2 */

	OPERATION_NODE pro2[2];
	pro2[0].tableID = 7;
	pro2[0].attributeID = 1;
	pro2[1].tableID = 7;
	pro2[1].attributeID = 5;
	
/* Projection3 */

	OPERATION_NODE pro3[1];
	pro3[0].tableID = 8;
	pro3[0].attributeID = 2;
	
/* Projection4 */

	OPERATION_NODE pro4[2];
	pro4[0].tableID = 8;
	pro4[0].attributeID = 3;
	pro4[1].tableID = 2;
	pro4[1].attributeID = 2;

/* Projection5 */

	OPERATION_NODE pro5[4];
	pro5[0].tableID = 7;
	pro5[0].attributeID = 5;
	pro5[1].tableID = 2;
	pro5[1].attributeID = 2;
	pro5[2].tableID = 8;
	pro5[2].attributeID = 6;
	pro5[3].tableID = 8;
	pro5[3].attributeID = 7;

/* Extract */
	OPERATION_NODE ex[1];
	ex[0].tableID = 7;
	ex[0].attributeID = 5;

/* GROUP */
	IntPosVal pv5(1, 1);
	ValueNode vn5 = ValueNode(&pv5);
	ColumnRefNode cn4[2];
	cn4[0].tableID = 8;
	cn4[0].attriID = 6;
	cn4[1].tableID = 8;
	cn4[1].attriID = 7;
	ArithmeticNode arith1(SUB, &vn5, &cn4[1]);
	ArithmeticNode arith2(MUL, &cn4[0], &arith1);
	
	Aggregation *aggre[1];
	aggre[0] = new Sum(&arith2, 2);
	
	
	OPERATION_NODE group[1];
	group[0].tableID = 7;
	group[0].attributeID = 5;

/* Sort 1 */
	OPERATION_NODE so1[1];
	so1[0].tableID = 7;
	so1[0].attributeID = 5;
	so1[0].option = 0;
	
	


	OPERATION_NODE op1;
	op1.tableID = 2;
	op1.attributeID = 3;
	
	OPERATION_NODE op2;
	op2.tableID = 6;
	op2.attributeID = 4;
	
	OPERATION_NODE op3;
	op3.tableID = 7;
	op3.attributeID = 5;
	
	OPERATION_NODE op4;
	op4.tableID = 8;
	op4.attributeID = 1;
	
	OPERATION_NODE op5;
	op5.tableID = 3;
	op5.attributeID = 4;
	
	OPERATION_NODE op6;
	op6.tableID = 2;
	op6.attributeID = 2;
	
	OPERATION_NODE op7;
	op7.tableID = 8;
	op7.attributeID = 2;


	o1 = new ScanDSM(&db_r_2, &attriRec_r[1], 1);
	
	o2 = new SelectBitOut((Node *)&an1 ,(unsigned int)1);
	o2->setPreOperator(o1);
	
	o3 = new ScanDSM(&db_r_1, &attriRec_r[0], 1); 
	
	o4 = new BitFilter(o3, o2);
	
	o5 = new ScanDSM(&db_n_3, &attriRec_n[2], 1);
	
	o6 = new JoinIndex_OneHash(o4, o5); 
	
	o7 = new ScanDSM(&db_n_1, &attriRec_n[0], 1);
	
	o8 = new ScanFromJI(o7, o6, &op1);

	o9 = new ScanDSM(&db_c_4, &attriRec_c[3], 1);

	o10 = new JoinIndex_OneHash(o8, o9); 
	
	o11 = new ScanDSM(&db_c_1, &attriRec_c[0], 1);
	
	o12 = new ScanFromJI(o11, o10, &op2);
	
	o13 = new Projection(pro1, 1);
	o13->setPreOperator(o12);
	
/*	
	
	o14 = new ScanDSM(&db_o_2, &attriRec_o[1], 1);
//	cout << "OK new o14" << endl;
	
	o15 = new JoinIndex_OneHash(o13, o14); 
//	cout << "OK new o15" << endl;
	
*/
	o14 = new ScanDSM(&db_o_5, &attriRec_o[4], 1);

	o15 = new Selection((Node *)&an4 ,(unsigned int)2);
	o15->setPreOperator(o14);
	
	o16 = new ScanDSM(&db_o_2, &attriRec_o[1], 1);
	
	o17 = new ScanFromJI(o16, o15, &op3);
	
	o18 = new ScanDSM(&db_o_1, &attriRec_o[0], 1);
	
	o19 = new ScanFromJI(o18, o17, &op3);
	
	
	
	o20 = new ScanDSM(&db_p_5, &attriRec_p[4], 1);

	o21 = new SelectBitOut((Node *)&an5 ,1);
	o21->setPreOperator(o20);
	
	o22 = new ScanDSM(&db_p_1, &attriRec_p[0], 1);

	o23 = new BitFilter(o22, o21);
	
	o24 = new ScanDSM(&db_l_2, &attriRec_l[1], 1);
	
	o25 = new JoinIndex_OneHash(o23, o24, &jon5); 



	o26 = new ScanDSM(&db_l_1, &attriRec_l[0], 1);
	o27 = new ScanFromJI(o26, o25, &op7);
	
	
	o28 = new JoinIndex_OneHash(o19, o27, &jon4);
	o29 = new JoinIndex_OneHash(o13, o28, &jon6);
	
	o30 = new ScanDSM(&db_s_4, &attriRec_s[3], 1);
	
	o31 = new ScanDSM(&db_s_1, &attriRec_s[0], 1);
	
	o32 = new ScanFromJI(o31, o30, &op5);
	
	
	
	o33 = new ScanDSM(&db_l_3, &attriRec_l[2], 1);
	o34 = new ScanFromJI(o33, o29, &op7);
	
	o35 = new JoinIndex_OneHash(o32, o34, &jon7);
	
	
	
	o36 = new ScanDSM(&db_n2_1, &attriRec_n[0], 1);
	o37 = new ScanDSM(&db_n2_2, &attriRec_n[1], 1);
	o38 = new ScanFromJI(o36, o37, &op6);
	
	o40 = new JoinIndex_OneHash(o38, o35, &jon8);
	
	
	
	o41 = new ScanDSM(&db_l_6, &attriRec_l[5], 1);
	o42 = new ScanFromJI(o41, o40, &op4);


	o43 = new ScanDSM(&db_l_7, &attriRec_l[6], 1);
	o44 = new ScanFromJI(o43, o42, &op4);

	o45 = new Projection(pro5, 4);
	o45->setPreOperator(o44);
	
	o46 = new Extract(ex, true, false, false);
	o46->setPreOperator(o45);
	
	o47 = new GroupBy(group, 1, aggre, 1);
	o47->setPreOperator(o46);
	
	o48 = new Sort(so1, 1);
	o48->setPreOperator(o47);


	o49 = new OutPut(TIME_OUT);
	o49->setPreOperator(o48);
	o49->init(env->getEnv());
	cout << "TEST START" << endl;
	
	cout << setprecision(2);
	cout << setiosflags(ios::fixed);
	o49->exec();
}
Esempio n. 10
0
void PrintVirutalFucAddr()
{
	B1 b1(1), b2(2); D1 d1(3), d2(4);
	B1 * pd1 = &d1, * pd2 = &d2;
	cout << "b1对象地址:" << &b1 << endl;
	cout << "b2对象地址:" << &b2 << endl;
	cout << "d1对象地址:" << &d1 << endl;
	cout << "d2对象地址:" << &d2 << endl;
	cout << "pd1对象地址:" << pd1 << endl;
	cout << "pd2对象地址:" << pd2 << endl;
	cout << "b1虚函数表地址:" << (int*)*(int*)(&b1) << endl;
	cout << "b2虚函数表地址:" << (int*)*(int*)(&b2) << endl;
	cout << "d1虚函数表地址:" << (int*)*(int*)(&d1) << endl;
	cout << "d2虚函数表地址:" << (int*)*(int*)(&d2) << endl;
	cout << "pd1虚函数表地址:" << (int*)*(int*)(pd1) << endl;
	cout << "pd2虚函数表地址:" << (int*)*(int*)(pd2) << endl;
	cout << "b1虚函数表  — 第一个函数地址:" << (int*)*((int*)*(int*)(&b1) + 0) << endl;
	cout << "b2虚函数表  — 第一个函数地址:" << (int*)*((int*)*(int*)(&b2) + 0) << endl;
	cout << "d1虚函数表  — 第一个函数地址:" << (int*)*((int*)*(int*)(&d1) + 0) << endl;
	cout << "d2虚函数表  — 第一个函数地址:" << (int*)*((int*)*(int*)(&d2) + 0) << endl;
	cout << "pd1虚函数表 — 第一个函数地址:" << (int*)*((int*)*(int*)(pd1) + 0) << endl;
	cout << "pd2虚函数表 — 第一个函数地址:" << (int*)*((int*)*(int*)(pd2) + 0) << endl;
	cout << "b1虚函数表  — 第二个函数地址:" << (int*)*((int*)*(int*)(&b1) + 1) << endl;
	cout << "b2虚函数表  — 第二个函数地址:" << (int*)*((int*)*(int*)(&b2) + 1) << endl;
	cout << "d1虚函数表  — 第二个函数地址:" << (int*)*((int*)*(int*)(&d1) + 1) << endl;
	cout << "d2虚函数表  — 第二个函数地址:" << (int*)*((int*)*(int*)(&d2) + 1) << endl;
	cout << "pd1虚函数表 — 第二个函数地址:" << (int*)*((int*)*(int*)(pd1) + 1) << endl;
	cout << "pd2虚函数表 — 第二个函数地址:" << (int*)*((int*)*(int*)(pd2) + 1) << endl;

	
	typedef void (*VFUN)(void);

	cout << "b1 与 d1 执行第一个函数地址" << endl;
	VFUN pv1 = (VFUN)*((int*)*(int*)(&b1));
	VFUN pv2 = (VFUN)*((int*)*(int*)(&d1));
	pv1();
	pv2();
	cout << "b1 与 d1 执行第二个函数地址" << endl;
	pv1 = (VFUN)*((int*)*(int*)(&b1) + 1);
	pv2 = (VFUN)*((int*)*(int*)(&d1) + 1);
	pv1();
	pv2();
	cout << "b1 与 d1 执行第四个函数地址" << endl;
	pv1 = (VFUN)*((int*)*(int*)(&b1) + 3);
	pv2 = (VFUN)*((int*)*(int*)(&d1) + 3);
	//pv1(); error
	//pv2(); error
	typedef void (*VFUN2)(B1*);
	VFUN2 pv3 = (VFUN2)*((int*)*(int*)(&b1) + 3);
	VFUN2 pv4 = (VFUN2)*((int*)*(int*)(&d1) + 3);
	pv3(&b1);
	pv4(&d1);
	
	
	cout << "sizeof(int*): " << sizeof(int*) << endl;
	cout << "sizeof(double): " << sizeof(double) << endl;
	cout << "sizeof(float): " << sizeof(float) << endl;
	cout << "sizeof(unsigned long): " << sizeof(unsigned long) << endl;
	cout << "sizeof(long): " << sizeof(long) << endl;
	cout << "sizeof(unsigned int): " << sizeof(unsigned int) << endl;
	cout << "sizeof(int): " << sizeof(int) << endl;
	cout << "sizeof(unsigned short): " << sizeof(unsigned short) << endl;
	cout << "sizeof(short): " << sizeof(short) << endl;
}
Esempio n. 11
0
int main(){
	chdir("../RunData");
	BDBOpe db_r_1("1.1.DSM");
	BDBOpe db_r_2("1.2.DSM");
	BDBOpe db_n_1("2.1.DSM");
	BDBOpe db_n_2("2.2.DSM");
	BDBOpe db_n_3("2.3.DSM");
	BDBOpe db_c_1("6.1.DSM");
	BDBOpe db_c_4("6.4.DSM");
	BDBOpe db_o_1("7.1.DSM");
	BDBOpe db_o_2("7.2.DSM");
	BDBOpe db_o_5("7.5.DSM");
	Operator *o1, *o2, *o3, *o4, *o5, *o6, *o7, *o8, *o9, *o10;
	Operator *o11, *o12, *o13, *o14, *o15, *o16, *o17, *o18, *o19, *o20;
	Operator *o21, *o22, *o23, *o24, *o25, *o26, *o27, *o28, *o29, *o30;
	db_r_1.open();
	db_r_2.open();
	db_n_1.open();
	db_n_2.open();
	db_n_3.open();
	db_c_1.open();
	db_c_4.open();
	db_o_1.open();
	db_o_2.open();
	db_o_5.open();
	
	
	TABLE_REC tableRec_r;
	TABLE_REC tableRec_n;
	TABLE_REC tableRec_c;
	TABLE_REC tableRec_o;


	tableRec_r.tableID = 1;
	tableRec_r.attriNum = 3;

	tableRec_n.tableID = 2;
	tableRec_n.attriNum = 4;
	
	tableRec_c.tableID = 6;
	tableRec_c.attriNum = 8; 
	
	tableRec_o.tableID = 7;
	tableRec_o.attriNum = 9;
	
	ATTRIBUTE_REC attriRec_r[tableRec_r.attriNum];
	ATTRIBUTE_REC attriRec_n[tableRec_n.attriNum];
	ATTRIBUTE_REC attriRec_c[tableRec_c.attriNum];
	ATTRIBUTE_REC attriRec_o[tableRec_o.attriNum];

	AttributeManager AM_r;
	AttributeManager AM_n;
	AttributeManager AM_c;
	AttributeManager AM_o;
	
	AM_r.getForTableID(tableRec_r, attriRec_r);
	for(int i=0 ; i < (int)tableRec_r.attriNum ; i++){
		cout << attriRec_r[i].attributeName << endl;
	}
	AM_n.getForTableID(tableRec_n, attriRec_n);
	for(int i=0 ; i < (int)tableRec_n.attriNum ; i++){
		cout << attriRec_n[i].attributeName << endl;
	}
	AM_c.getForTableID(tableRec_c, attriRec_c);
	for(int i=0 ; i < (int)tableRec_c.attriNum ; i++){
		cout << attriRec_c[i].attributeName << endl;
	}
	AM_o.getForTableID(tableRec_o, attriRec_o);
	for(int i=0 ; i < (int)tableRec_o.attriNum ; i++){
		cout << attriRec_o[i].attributeName << endl;
	}

/* selection1 */
	FixStrPosVal pv1(1,25);
	string str1("AMERICA");
	pv1.setStr(str1);

	ValueNode vn1 = ValueNode(&pv1);
	ColumnRefNode cn1;
	cn1.tableID = 1;
	cn1.attriID = 2;
	AxprNode an1 = AxprNode(EQ, &cn1, &vn1);
	

/* selection2 */

	DatePosVal pv2(1,(unsigned char *)"1995-01-01");
	DatePosVal pv3(1,(unsigned char *)"1996-12-31");
	

	ValueNode vn2 = ValueNode(&pv2);
	ValueNode vn3 = ValueNode(&pv3);
	ColumnRefNode cn2;
	cn2.tableID = 7;
	cn2.attriID = 5;
	AxprNode an2 = AxprNode(GE, &cn2, &vn2);
	AxprNode an3 = AxprNode(LE, &cn2, &vn3);
	AxprNode an4 = AxprNode(AND, &an2, &an3);
	

	
/*Join1*/
	OPERATION_NODE jop1, jop2;
	jop1.tableID = 6;
	jop1.attributeID = 4;
	jop2.tableID = 6;
	jop2.attributeID = 1;
	
	JOIN_OPERATION_NODE jon1;
	jon1.rightNode = jop1;
	jon1.leftNode = jop2;

/*Join2*/
	OPERATION_NODE jop3, jop4;
	jop3.tableID = 7;
	jop3.attributeID = 2;
	jop4.tableID = 7;
	jop4.attributeID = 5;
	
	JOIN_OPERATION_NODE jon2;
	jon2.rightNode = jop3;
	jon2.leftNode = jop4;

/*Join3*/
	OPERATION_NODE jop5, jop6;
	jop5.tableID = 7;
	jop5.attributeID = 5;
	jop6.tableID = 7;
	jop6.attributeID = 1;
	
	JOIN_OPERATION_NODE jon3;
	jon3.rightNode = jop5;
	jon3.leftNode = jop6;
	
/* Projection */

	OPERATION_NODE pro1[1];
	pro1[0].tableID = 6;
	pro1[0].attributeID = 1;


	OPERATION_NODE op1;
	op1.tableID = 2;
	op1.attributeID = 3;
	
	OPERATION_NODE op2;
	op2.tableID = 6;
	op2.attributeID = 4;
	
	OPERATION_NODE op3;
	op3.tableID = 7;
	op3.attributeID = 2;
	


	o1 = new ScanDSM(&db_r_2, &attriRec_r[1], 1);
	cout << "OK new o1" << endl;
	
	o2 = new SelectBitOut((Node *)&an1 ,(unsigned int)1);
	cout << "OK new o2" << endl;
	o2->setPreOperator(o1);
	
	o3 = new ScanDSM(&db_r_1, attriRec_r, 1);
	cout << "OK new o3" << endl;
	
	o4 = new BitFilter(o3, o2);
	cout << "OK new o4" << endl;
	
	
	o5 = new ScanDSM(&db_n_3, &attriRec_n[2], 1);
	cout << "OK new o5" << endl;
	
	o6 = new JoinIndex_OneHash(o4, o5); 
	cout << "OK new o6" << endl;
	
	o7 = new ScanDSM(&db_n_1, &attriRec_n[0], 1);
	cout << "OK new o7" << endl;
	
	o8 = new ScanFromJI(o7, o6, &op1);
	cout << "OK new o8" << endl;

	o9 = new ScanDSM(&db_c_4, &attriRec_c[3], 1);
	cout << "OK new o9" << endl;

	o10 = new JoinIndex_OneHash(o8, o9); 
	cout << "OK new o10" << endl;
	
	o11 = new ScanDSM(&db_c_1, &attriRec_c[0], 1);
	cout << "OK new o11" << endl;
	
	o12 = new ScanFromJI(o11, o10, &op2);
	cout << "OK new o8" << endl;
	
	o13 = new Projection(pro1, 1);
	o13->setPreOperator(o12);
	
	
	
	o14 = new ScanDSM(&db_o_2, &attriRec_o[1], 1);
	cout << "OK new o14" << endl;
	
	o15 = new JoinIndex_OneHash(o13, o14); 
	cout << "OK new o15" << endl;
	

	o16 = new ScanDSM(&db_o_5, &attriRec_o[4], 1);
	cout << "OK new o16" << endl;

	o17 = new Selection((Node *)&an4 ,(unsigned int)2);
	cout << "OK new o17" << endl;
	o17->setPreOperator(o16);
	
	
	o18 = new ScanFromJI(o17, o15, &op3);
	cout << "OK new o18" << endl;
	
	o19 = new ScanDSM(&db_o_1, &attriRec_o[0], 1);
	cout << "OK new o19" << endl;
	
	o20 = new ScanFromJI(o19, o18, &op3);
	cout << "OK new o20" << endl;
	
/*
	o16 = new BitSort();
	o16->setPreOperator(o15);
	
	o16 = new ScanDSM(&db_o_1, &attriRec_o[0], 1);
	cout << "OK new o16" << endl;

	o17 = new BitFilter(o16, o15);
	cout << "OK new o17" << endl;
	o17->init();
	
	
	/*
	o2 = new ScanDSM(&db4, attriRec_n + 2, 1);
	cout << "OK new o2" << endl;
	
	JoinIndex_OneHash *JI = new JoinIndex_OneHash(o1, o2); 
	JI->init();
	
	
	o3 = new ScanDSM(&db2, attriRec_r + 1, 1);
	cout << "OK new o3" << endl;
	o4 = new ScanDSM(&db3, attriRec_n + 1, 1);
	cout << "OK new o4" << endl;
	*/
	/*
	JOIN_INDEX *J = JI->createJoinIndex();

	J->ScanNode->setkey(1);
	cout << J->ScanNode->getRow(NULL, 0) << endl;
	


	
	o5 = new JoinFromJoinIndex(o3, o4, JI->createJoinIndex(), &jon);
	cout << "OK new o5" << endl;
	*/
	o30 = new OutPut(STD_OUT);
	cout << "OK new o20" << endl;
	o30->setPreOperator(o20);
	o30->init();
	cout << "TEST START" << endl;
	o30->exec();
	
	/*
	o7 = new OutPut(STD_OUT);
	cout << "OK new o7" << endl;
	o7->setPreOperator(o2);
	o7->init();
	cout << "TEST START" << endl;
	o7->exec();
	*/
}
Esempio n. 12
0
int main(){
	chdir(QUERY_DATA_PATH);
	EnvDB *env = new EnvDB();
	env->open();
	
	BDBOpe db_r_1(env->getEnv(), "1.1.DSM");
	BDBOpe db_r_2(env->getEnv(), "1.2.DSM");
	BDBOpe db_n_1(env->getEnv(), "2.1.DSM");
	BDBOpe db_n_2(env->getEnv(), "2.2.DSM");
	BDBOpe db_n_3(env->getEnv(), "2.3.DSM");
	BDBOpe db_s_1(env->getEnv(), "3.1.DSM");
	BDBOpe db_s_4(env->getEnv(), "3.4.DSM");
	BDBOpe db_c_1(env->getEnv(), "6.1.DSM");
	BDBOpe db_c_4(env->getEnv(), "6.4.DSM");
	BDBOpe db_o(env->getEnv(), "ORDERS.row");
	BDBOpe db_l(env->getEnv(), "LINEITEM.row");
	
	SecondDB *sDB,*sDB_o;
	int (*pf)(Db *sdbp, const Dbt*pkey, const Dbt *pdata, Dbt *skey);
	pf = L_1_secondary;
	sDB = new SecondDB(env->getEnv(), "8.1.secondary");
	sDB->setNumCmp();
	
	int (*pf_o)(Db *sdbp, const Dbt*pkey, const Dbt *pdata, Dbt *skey);
	pf_o = O_2_secondary;
	sDB_o = new SecondDB(env->getEnv(), "7.2.secondary");
	sDB_o->setNumCmp();
	
	db_r_1.open();
	db_r_2.open();
	db_n_1.open();
	db_n_2.open();
	db_n_3.open();
	db_s_1.open();
	db_s_4.open();
	db_c_1.open();
	db_c_4.open();
	db_o.open();
	db_l.open();
	sDB->open(0);
	db_l.associate(sDB->getDb(), pf);
	sDB->openCursor();
	sDB_o->open(0);
	db_o.associate(sDB_o->getDb(), pf_o);
	sDB_o->openCursor();


	Operator *o1, *o2, *o3, *o4, *o5, *o6, *o7, *o8, *o9, *o10;
	Operator *o11, *o12, *o13, *o14, *o15, *o16, *o17, *o18, *o19, *o20;
	Operator *o21, *o22, *o23, *o24, *o25, *o26, *o27, *o28, *o29, *o30;
	Operator *o31, *o32, *o33, *o34, *o35, *o36, *o37, *o38, *o39, *o40;



	TABLE_REC tableRec_r;
	TABLE_REC tableRec_n;
	TABLE_REC tableRec_c;
	TABLE_REC tableRec_o;
	TABLE_REC tableRec_l;
	TABLE_REC tableRec_s;

	
/* set table info */
	tableRec_r.tableID = 1;
	tableRec_r.attriNum = 3;
	
	tableRec_n.tableID = 2;
	tableRec_n.attriNum = 4;
	
	tableRec_s.tableID = 3;
	tableRec_s.attriNum = 7;
	
	tableRec_c.tableID = 6;
	tableRec_c.attriNum = 8;

	tableRec_o.tableID = 7;
	tableRec_o.attriNum = 9;
	
	tableRec_l.tableID = 8;
	tableRec_l.attriNum = 16;
	


/* aet attriRec */
	ATTRIBUTE_REC attriRec_r[tableRec_r.attriNum];
	ATTRIBUTE_REC attriRec_n[tableRec_n.attriNum];
	ATTRIBUTE_REC attriRec_s[tableRec_s.attriNum];
	ATTRIBUTE_REC attriRec_c[tableRec_c.attriNum];
	ATTRIBUTE_REC attriRec_o[tableRec_o.attriNum];
	ATTRIBUTE_REC attriRec_l[tableRec_l.attriNum];
	

	AttributeManager AM(env->getEnv());
	

	AM.getForTableID(tableRec_r, attriRec_r);
	AM.getForTableID(tableRec_n, attriRec_n);
	AM.getForTableID(tableRec_c, attriRec_c);
	AM.getForTableID(tableRec_o, attriRec_o);
	AM.getForTableID(tableRec_l, attriRec_l);
	AM.getForTableID(tableRec_s, attriRec_s);

/* selection1 */
	FixStrPosVal pv1(1,25);
	string str1("ASIA");
	pv1.setStr(str1);

	ValueNode vn1 = ValueNode(&pv1);
	ColumnRefNode cn1;
	cn1.tableID = 1;
	cn1.attriID = 2;
	AxprNode an1 = AxprNode(EQ, &cn1, &vn1);
	

/* selection2 */

	DatePosVal pv2(1,(unsigned char *)"1994-01-01");
	DatePosVal pv3(1,(unsigned char *)"1995-01-01");
	

	ValueNode vn2 = ValueNode(&pv2);
	ValueNode vn3 = ValueNode(&pv3);
	ColumnRefNode cn2;
	cn2.tableID = 7;
	cn2.attriID = 5;
	AxprNode an2 = AxprNode(GE, &cn2, &vn2);
	AxprNode an3 = AxprNode(LT, &cn2, &vn3);
	AxprNode an4 = AxprNode(AND, &an2, &an3);
	
	
/* GROUP */
	IntPosVal pv5(1, 1);
	ValueNode vn5 = ValueNode(&pv5);
	ColumnRefNode cn4[2];
	cn4[0].tableID = 8;
	cn4[0].attriID = 6;
	cn4[1].tableID = 8;
	cn4[1].attriID = 7;
	ArithmeticNode arith1(SUB, &vn5, &cn4[1]);
	ArithmeticNode arith2(MUL, &cn4[0], &arith1);
	
	Aggregation *aggre[1];
	aggre[0] = new Sum(&arith2, 2);
	
	
	OPERATION_NODE group[1];
	group[0].tableID = 2;
	group[0].attributeID = 2;
	
/* Sort 1 */
	OPERATION_NODE so1[1];
	so1[0].tableID = 0;
	so1[0].attributeID = 0;
	so1[0].position = 1;
	so1[0].option = 1;

/* Projection1 */

	OPERATION_NODE pro1[2];
	pro1[0].tableID = 2;
	pro1[0].attributeID = 1;
	pro1[1].tableID = 2;
	pro1[1].attributeID = 2;
	
/* Projection2 */

	OPERATION_NODE pro2[3];
	pro2[0].tableID = 3;
	pro2[0].attributeID = 1;
	pro2[1].tableID = 3;
	pro2[1].attributeID = 4;
	pro2[2].tableID = 2;
	pro2[2].attributeID = 2;
	
/* Projection3 */

	OPERATION_NODE pro3[3];
	pro3[0].tableID = 2;
	pro3[0].attributeID = 2;
	pro3[1].tableID = 8;
	pro3[1].attributeID = 6;
	pro3[2].tableID = 8;
	pro3[2].attributeID = 7;

/* Projection4 */

	OPERATION_NODE pro4[3];
	pro4[0].tableID = 2;
	pro4[0].attributeID = 2;
	pro4[1].tableID = 6;
	pro4[1].attributeID = 1;
	pro4[2].tableID =6;
	pro4[2].attributeID = 4;

/* Projection5 */

	OPERATION_NODE pro5[3];
	pro5[0].tableID = 2;
	pro5[0].attributeID = 2;
	pro5[1].tableID = 6;
	pro5[1].attributeID = 4;
	pro5[2].tableID = 7;
	pro5[2].attributeID = 1;

/* Projection6 */

	OPERATION_NODE pro6[5];
	pro6[0].tableID = 2;
	pro6[0].attributeID = 2;
	pro6[1].tableID = 6;
	pro6[1].attributeID = 4;
	pro6[2].tableID = 8;
	pro6[2].attributeID = 3;
	pro6[3].tableID = 8;
	pro6[3].attributeID = 6;
	pro6[4].tableID = 8;
	pro6[4].attributeID = 7;

/* Projection11 */
	
	OPERATION_NODE pro11[4];
	pro11[0].tableID = 2;
	pro11[0].attributeID = 2;
	pro11[1].tableID = 6;
	pro11[1].attributeID = 4;
	pro11[2].tableID = 7;
	pro11[2].attributeID = 1;
	pro11[3].tableID = 7;
	pro11[3].attributeID = 5;
	
	
	OPERATION_NODE op1;
	op1.tableID = 2;
	op1.attributeID = 3;
	
	OPERATION_NODE op2;
	op2.tableID = 3;
	op2.attributeID = 4;
	
	OPERATION_NODE op3;
	op3.tableID = 8;
	op3.attributeID = 3;
	
	OPERATION_NODE op4;
	op4.tableID = 7;
	op4.attributeID = 2;
	
	OPERATION_NODE op5;
	op5.tableID = 6;
	op5.attributeID = 4;

/* index position */
	
	OPERATION_NODE pro10[1];
	pro10[0].tableID = 7;
	pro10[0].attributeID = 1;
	
	
/* Join1 */
	OPERATION_NODE pn1[2];
	pn1[0].tableID = 2;
	pn1[0].attributeID = 1;
	pn1[1].tableID = 6;
	pn1[1].attributeID = 4;

	
	JOIN_OPERATION_NODE jpn1[1];
	jpn1[0].rightNode = pn1[0];
	jpn1[0].leftNode = pn1[1];

/* Join2 */
	OPERATION_NODE pn2[2];
	pn2[0].tableID = 6;
	pn2[0].attributeID = 1;
	pn2[1].tableID = 7;
	pn2[1].attributeID = 2;

	
	JOIN_OPERATION_NODE jpn2[1];
	jpn2[0].rightNode = pn2[0];
	jpn2[0].leftNode = pn2[1];
	
/* Join3 */
	OPERATION_NODE pn3[2];
	pn3[0].tableID = 7;
	pn3[0].attributeID = 1;
	pn3[1].tableID = 8;
	pn3[1].attributeID = 1;

	
	JOIN_OPERATION_NODE jpn3[1];
	jpn3[0].rightNode = pn3[0];
	jpn3[0].leftNode = pn3[1];

/* Join4 */
	OPERATION_NODE pn4[4];
	pn4[0].tableID = 3;
	pn4[0].attributeID = 1;
	pn4[1].tableID = 3;
	pn4[1].attributeID = 4;
	pn4[2].tableID = 8;
	pn4[2].attributeID = 3;
	pn4[3].tableID = 6;
	pn4[3].attributeID = 4;

	
	JOIN_OPERATION_NODE jpn4[2];
	jpn4[0].rightNode = pn4[0];
	jpn4[0].leftNode = pn4[2];
	jpn4[1].rightNode = pn4[1];
	jpn4[1].leftNode = pn4[3];

	
/* exec */
	
	o1 = new ScanDSM(&db_r_2, &attriRec_r[1], 1);
	o2 = new SelectBitOut((Node *)&an1 ,(unsigned int)1);
	o2->setPreOperator(o1);
	o3 = new ScanDSM(&db_r_1, &attriRec_r[0], 1);
	o4 = new BitFilter(o3, o2);

	o5 = new ScanDSM(&db_n_3, &attriRec_n[2], 1);
	o6 = new JoinIndex_OneHash(o4, o5); 

	
	o7 = new ScanDSM(&db_n_1, &attriRec_n[0], 1);
	o8 = new ScanFromJI(o7, o6, &op1);
	o9 = new ScanDSM(&db_n_2, &attriRec_n[1], 1);
	//n_name, n_natonkey, r_regionkey, n_nationkey
	o10 = new ScanFromJI(o9, o8, &op1);
	
	//n_name, n_natonkey
	o11 = new Projection(pro1, 2);
	o11->setPreOperator(o10);

	o12 = new ScanDSM(&db_c_4, &attriRec_c[3], 1);
	o13 = new ScanDSM(&db_c_1, &attriRec_c[0], 1);
	o14 = new ScanFromJI(o13, o12, &op5);
	
	o15 = new OneSideHashJoin(o10, o14 , jpn1, 1);
	//n_name, c_custkey, c_nationkey
	o16 = new Projection(pro4, 3);
	o16->setPreOperator(o15);
	
	/* ======== Nested Loop Join with Index ============ */
	IndexScan *IS_o = new IndexScan((BDBOpe *)sDB_o, attriRec_o, 9);
	o17 = new NestedJoin_Index(IS_o, o16, pn2);
	o18 = new Projection(pro11, 4);
	o18->setPreOperator(o17);

	//o17 = new ScanDSM(&db_o_5, &attriRec_o[4], 1);
	o19 = new Selection((Node *)&an4 ,(unsigned int)2);
	o19->setPreOperator(o18);
	//o19 = new ScanDSM(&db_o_2, &attriRec_o[1], 1);
	//o20 = new BitFilter(o19, o18);
	
	/* ======================================================= */
	
	
	//o21 = new ScanDSM(&db_o_1, &attriRec_o[0], 1);
	//o_order, o_custkey
	//o22 = new ScanFromJI(o21, o20, &op4);
	
	//n_name, c_custkey, c_nationkey, o_order, o_custkey
	//o23 = new OneSideHashJoin(o16, o22 , jpn2, 1);
	
	//n_name, c_nationkey, o_order
	o24 = new Projection(pro5, 3);
	o24->setPreOperator(o19);

	/* ======== Nested Loop Join with Index ============ */

	IndexScan *IS = new IndexScan((BDBOpe *)sDB, attriRec_l, 16);
	o25 = new NestedJoin_Index(IS, o24, pro10);
	o26 = new Projection(pro6, 5);
	o26->setPreOperator(o25);
	
	/* ======================================================= */
	
	//l_orderkey, l_extendedprice, l_discount, l_suppkey

	o33 = new ScanDSM(&db_s_4, &attriRec_s[3], 1);
	o34 = new ScanDSM(&db_s_1, &attriRec_s[0], 1);
	o35 = new ScanFromJI(o34, o33, &op2);

	o36 = new OneSideHashJoin(o35, o26 , jpn4, 2);



	o37 = new Projection(pro3, 3);
	o37->setPreOperator(o36);
	
	o38 = new GroupBy(group, 1, aggre, 1);
	o38->setPreOperator(o37);

	o39 = new Sort(so1, 1);
	o39->setPreOperator(o38);
	
	o40 = new OutPut(TIME_OUT);

	o40->setPreOperator(o39);
	o40->init(env->getEnv());
	cout << "TEST START Q5" << endl;
	
	cout << setprecision(4);
	cout << setiosflags(ios::fixed); 
	o40->exec();
}
Esempio n. 13
0
int main(){
	chdir(QUERY_DATA_PATH);
	EnvDB *env = new EnvDB();
	env->open();
	
	BDBOpe db_r_1(env->getEnv(), "1.1.DSM");
	BDBOpe db_r_2(env->getEnv(), "1.2.DSM");
	BDBOpe db_n_1(env->getEnv(), "2.1.DSM");
	BDBOpe db_n2_1(env->getEnv(), "2.1.DSM");
	BDBOpe db_n2_2(env->getEnv(), "2.2.DSM");
	BDBOpe db_n_3(env->getEnv(), "2.3.DSM");
	BDBOpe db_s_1(env->getEnv(), "3.1.DSM");
	BDBOpe db_s_4(env->getEnv(), "3.4.DSM");
	BDBOpe db_p_1(env->getEnv(), "4.1.DSM");
	BDBOpe db_p_5(env->getEnv(), "4.5.DSM");
	BDBOpe db_c_1(env->getEnv(), "6.1.DSM");
	BDBOpe db_c_4(env->getEnv(), "6.4.DSM");
	BDBOpe db_o(env->getEnv(), "ORDERS.row");
	BDBOpe db_l(env->getEnv(), "LINEITEM.row");
	
	SecondDB *sDB1;
	int (*pf1)(Db *sdbp, const Dbt*pkey, const Dbt *pdata, Dbt *skey);
	pf1 = L_1_secondary;
	sDB1 = new SecondDB(env->getEnv(), "8.1.secondary");
	sDB1->setNumCmp();
	
	SecondDB *sDB2;
	int (*pf2)(Db *sdbp, const Dbt*pkey, const Dbt *pdata, Dbt *skey);
	pf2 = O_2_secondary;
	sDB2 = new SecondDB(env->getEnv(), "7.2.secondary");
	sDB2->setNumCmp();

	Operator *o1, *o2, *o3, *o4, *o5, *o6, *o7, *o8, *o9, *o10;
	Operator *o11, *o12, *o13, *o14, *o15, *o16, *o17, *o18, *o19, *o20;
	Operator *o21, *o22, *o23, *o24, *o25, *o26, *o27, *o28, *o29, *o30;
	Operator *o31, *o32, *o33, *o34, *o35, *o36, *o37, *o38, *o39, *o40;
	Operator *o41, *o42, *o43, *o44, *o45, *o46, *o47, *o48, *o49, *o50, *o51;
	db_r_1.open();
	db_r_2.open();
	db_n_1.open();
	db_n2_1.open();
	db_n2_2.open();
	db_n_3.open();
	db_s_1.open();
	db_s_4.open();
	db_p_1.open();
	db_p_5.open();
	db_c_1.open();
	db_c_4.open();
	
	
	db_o.open();
	sDB2->open(0);
	db_o.associate(sDB2->getDb(), pf2);
	sDB2->openCursor();
	
	db_l.open();
	sDB1->open(0);
	db_l.associate(sDB1->getDb(), pf1);
	sDB1->openCursor();

	TABLE_REC tableRec_r;
	TABLE_REC tableRec_n;
	TABLE_REC tableRec_s;
	TABLE_REC tableRec_p;
	TABLE_REC tableRec_c;
	TABLE_REC tableRec_o;
	TABLE_REC tableRec_l;

	tableRec_r.tableID = 1;
	tableRec_r.attriNum = 3;

	tableRec_n.tableID = 2;
	tableRec_n.attriNum = 4;
	
	tableRec_s.tableID = 3;
	tableRec_s.attriNum = 7;
	
	tableRec_p.tableID = 4;
	tableRec_p.attriNum = 9;
	
	tableRec_c.tableID = 6;
	tableRec_c.attriNum = 8;
	
	tableRec_o.tableID = 7;
	tableRec_o.attriNum = 9;
	
	tableRec_l.tableID = 8;
	tableRec_l.attriNum = 16;
	
	
	ATTRIBUTE_REC attriRec_r[tableRec_r.attriNum];
	ATTRIBUTE_REC attriRec_n[tableRec_n.attriNum];
	ATTRIBUTE_REC attriRec_s[tableRec_s.attriNum];
	ATTRIBUTE_REC attriRec_p[tableRec_p.attriNum];
	ATTRIBUTE_REC attriRec_c[tableRec_c.attriNum];
	ATTRIBUTE_REC attriRec_o[tableRec_o.attriNum];
	ATTRIBUTE_REC attriRec_l[tableRec_l.attriNum];

	AttributeManager AM(env->getEnv());
	
	AM.getForTableID(tableRec_r, attriRec_r);
	AM.getForTableID(tableRec_n, attriRec_n);
	AM.getForTableID(tableRec_s, attriRec_s);
	AM.getForTableID(tableRec_p, attriRec_p);
	AM.getForTableID(tableRec_c, attriRec_c);
	AM.getForTableID(tableRec_o, attriRec_o);
	AM.getForTableID(tableRec_l, attriRec_l);

/* selection1 */
	FixStrPosVal pv1(1,25);
	string str1("AMERICA");
	pv1.setStr(str1);

	ValueNode vn1 = ValueNode(&pv1);
	ColumnRefNode cn1;
	cn1.tableID = 1;
	cn1.attriID = 2;
	AxprNode an1 = AxprNode(EQ, &cn1, &vn1);
	

/* selection2 */

	DatePosVal pv2(1,(unsigned char *)"1995-01-01");
	DatePosVal pv3(1,(unsigned char *)"1996-12-31");
	

	ValueNode vn2 = ValueNode(&pv2);
	ValueNode vn3 = ValueNode(&pv3);
	ColumnRefNode cn2;
	cn2.tableID = 7;
	cn2.attriID = 5;
	AxprNode an2 = AxprNode(GE, &cn2, &vn2);
	AxprNode an3 = AxprNode(LE, &cn2, &vn3);
	AxprNode an4 = AxprNode(AND, &an2, &an3);

/* selection3 */
	VarStrPosVal pv4(1,25);
	string str2("ECONOMY ANODIZED STEEL");
	pv4.set((unsigned char*)str2.c_str());

	ValueNode vn4 = ValueNode(&pv4);
	ColumnRefNode cn3;
	cn3.tableID = 4;
	cn3.attriID = 5;
	AxprNode an5 = AxprNode(EQ, &cn3, &vn4);
	

	
/*Join1*/
	OPERATION_NODE jop1, jop2;
	jop1.tableID = 6;
	jop1.attributeID = 4;
	jop2.tableID = 6;
	jop2.attributeID = 1;
	
	JOIN_OPERATION_NODE jon1;
	jon1.rightNode = jop1;
	jon1.leftNode = jop2;

/*Join2*/
	OPERATION_NODE jop3, jop4;
	jop3.tableID = 7;
	jop3.attributeID = 2;
	jop4.tableID = 7;
	jop4.attributeID = 5;
	
	JOIN_OPERATION_NODE jon2;
	jon2.rightNode = jop3;
	jon2.leftNode = jop4;

/*Join3*/
	OPERATION_NODE jop5, jop6;
	jop5.tableID = 7;
	jop5.attributeID = 5;
	jop6.tableID = 7;
	jop6.attributeID = 1;
	
	JOIN_OPERATION_NODE jon3;
	jon3.rightNode = jop5;
	jon3.leftNode = jop6;

/*Join4*/
	OPERATION_NODE jop7, jop8;
	jop7.tableID = 7;
	jop7.attributeID = 1;
	jop8.tableID = 8;
	jop8.attributeID = 1;
	
	JOIN_OPERATION_NODE jon4;
	jon4.rightNode = jop7;
	jon4.leftNode = jop8;
	
/*Join5*/
	OPERATION_NODE jop9, jop10;
	jop9.tableID = 4;
	jop9.attributeID = 1;
	jop10.tableID = 8;
	jop10.attributeID = 2;
	
	JOIN_OPERATION_NODE jon5;
	jon5.rightNode = jop9;
	jon5.leftNode = jop10;

/*Join6*/
	OPERATION_NODE jop11, jop12;
	jop11.tableID = 3;
	jop11.attributeID = 1;
	jop12.tableID = 8;
	jop12.attributeID = 3;
	
	JOIN_OPERATION_NODE jon6;
	jon6.rightNode = jop11;
	jon6.leftNode = jop12;
	
/* Projection1 */

	OPERATION_NODE pro1[1];
	pro1[0].tableID = 6;
	pro1[0].attributeID = 1;
	
	
/* Projection2 */

	OPERATION_NODE pro2[2];
	pro2[0].tableID = 7;
	pro2[0].attributeID = 1;
	pro2[1].tableID = 7;
	pro2[1].attributeID = 5;
	
/* Projection3 */

	OPERATION_NODE pro3[1];
	pro3[0].tableID = 8;
	pro3[0].attributeID = 2;
	
/* Projection4 */

	OPERATION_NODE pro4[2];
	pro4[0].tableID = 8;
	pro4[0].attributeID = 3;
	pro4[1].tableID = 2;
	pro4[1].attributeID = 2;

/* Projection5 */

	OPERATION_NODE pro5[4];
	pro5[0].tableID = 7;
	pro5[0].attributeID = 5;
	pro5[1].tableID = 2;
	pro5[1].attributeID = 2;
	pro5[2].tableID = 8;
	pro5[2].attributeID = 6;
	pro5[3].tableID = 8;
	pro5[3].attributeID = 7;
	
/* Projection6 */

	OPERATION_NODE pro6[5];
	pro6[0].tableID = 7;
	pro6[0].attributeID = 5;
	pro6[1].tableID = 8;
	pro6[1].attributeID = 2;
	pro6[2].tableID = 8;
	pro6[2].attributeID = 3;
	pro6[3].tableID = 8;
	pro6[3].attributeID = 6;
	pro6[4].tableID = 8;
	pro6[4].attributeID = 7;

/* Projection7 */

	OPERATION_NODE pro7[4];
	pro7[0].tableID = 7;
	pro7[0].attributeID = 5;
	pro7[1].tableID = 8;
	pro7[1].attributeID = 3;
	pro7[2].tableID = 8;
	pro7[2].attributeID = 6;
	pro7[3].tableID = 8;
	pro7[3].attributeID = 7;

/* Projection8 */

	OPERATION_NODE pro8[2];
	pro8[0].tableID = 3;
	pro8[0].attributeID = 1;
	pro8[1].tableID = 2;
	pro8[1].attributeID = 2;

/* Projection9 */

	OPERATION_NODE pro9[4];
	pro9[0].tableID = 2;
	pro9[0].attributeID = 2;
	pro9[1].tableID = 7;
	pro9[1].attributeID = 5;
	pro9[2].tableID = 8;
	pro9[2].attributeID = 6;
	pro9[3].tableID = 8;
	pro9[3].attributeID = 7;

/* Extract */
	OPERATION_NODE ex[1];
	ex[0].tableID = 7;
	ex[0].attributeID = 5;

/* GROUP */
	IntPosVal pv5(1, 1);
	ValueNode vn5 = ValueNode(&pv5);
	ColumnRefNode cn4[2];
	cn4[0].tableID = 8;
	cn4[0].attriID = 6;
	cn4[1].tableID = 8;
	cn4[1].attriID = 7;
	ArithmeticNode arith1(SUB, &vn5, &cn4[1]);
	ArithmeticNode arith2(MUL, &cn4[0], &arith1);
	
	Aggregation *aggre[1];
	aggre[0] = new Sum(&arith2, 2);
	
	
	OPERATION_NODE group[1];
	group[0].tableID = 7;
	group[0].attributeID = 5;

/* Sort 1 */
	OPERATION_NODE so1[1];
	so1[0].tableID = 7;
	so1[0].attributeID = 5;
	so1[0].option = 0;
	
	


	OPERATION_NODE op1;
	op1.tableID = 2;
	op1.attributeID = 3;
	
	OPERATION_NODE op2;
	op2.tableID = 6;
	op2.attributeID = 4;
	
	OPERATION_NODE op3;
	op3.tableID = 7;
	op3.attributeID = 2;
	
	OPERATION_NODE op4;
	op4.tableID = 8;
	op4.attributeID = 1;
	
	OPERATION_NODE op5;
	op5.tableID = 3;
	op5.attributeID = 4;
	
	OPERATION_NODE op6;
	op6.tableID = 2;
	op6.attributeID = 2;
	
	
/* index position */
	
	OPERATION_NODE idx1[1];
	idx1[0].tableID = 7;
	idx1[0].attributeID = 1;
	
/* index position */
	
	OPERATION_NODE idx2[1];
	idx2[0].tableID = 6;
	idx2[0].attributeID = 1;

//===============================================================-


	o1 = new ScanDSM(&db_r_2, &attriRec_r[1], 1);
//	cout << "OK new o1" << endl;
	
	o2 = new SelectBitOut((Node *)&an1 ,(unsigned int)1);
//	cout << "OK new o2" << endl;
	o2->setPreOperator(o1);
	
	o3 = new ScanDSM(&db_r_1, attriRec_r, 1);
//	cout << "OK new o3" << endl;
	
	o4 = new BitFilter(o3, o2);
//	cout << "OK new o4" << endl;
	
	
	o5 = new ScanDSM(&db_n_3, &attriRec_n[2], 1);
//	cout << "OK new o5" << endl;
	
	o6 = new JoinIndex_OneHash(o4, o5); 
//	cout << "OK new o6" << endl;
	
	o7 = new ScanDSM(&db_n_1, &attriRec_n[0], 1);
//	cout << "OK new o7" << endl;
	
	o8 = new ScanFromJI(o7, o6, &op1);
//	cout << "OK new o8" << endl;

	o9 = new ScanDSM(&db_c_4, &attriRec_c[3], 1);
//	cout << "OK new o9" << endl;

	o10 = new JoinIndex_OneHash(o8, o9); 
//	cout << "OK new o10" << endl;
	
	o11 = new ScanDSM(&db_c_1, &attriRec_c[0], 1);
//	cout << "OK new o11" << endl;
	
	o12 = new ScanFromJI(o11, o10, &op2);
//	cout << "OK new o12" << endl;
	
	o13 = new Projection(pro1, 1);
	o13->setPreOperator(o12);
	

/* ======== Nested Loop Join with Index ============ */

	IndexScan *IS2 = new IndexScan((BDBOpe *)sDB2, attriRec_o, 9);
	o14 = new NestedJoin_Index(IS2, o13, idx2);
	//l_partkey, l_suppkey, l_extentdedprice, l_discount, o_orderdate
	//o15 = new Projection(pro6, 5);
	//o15->setPreOperator(o22);
	
/* ======================================================= */
	

	o17 = new Selection((Node *)&an4 ,(unsigned int)2);
//	cout << "OK new o17" << endl;
	o17->setPreOperator(o14);
	

	o21 = new Projection(pro2, 2);
	o21->setPreOperator(o17);
//	cout << "OK new o21" << endl;


/* ======== Nested Loop Join with Index ============ */

	IndexScan *IS1 = new IndexScan((BDBOpe *)sDB1, attriRec_l, 16);
	o22 = new NestedJoin_Index(IS1, o21, idx1);
	//l_partkey, l_suppkey, l_extentdedprice, l_discount, o_orderdate
	o23 = new Projection(pro6, 5);
	o23->setPreOperator(o22);
	
/* ======================================================= */
	
	
	

	o24 = new ScanDSM(&db_p_5, &attriRec_p[4], 1);
//	cout << "OK new o24" << endl;

	o25 = new SelectBitOut((Node *)&an5 ,1);
//	cout << "OK new o25" << endl;
	o25->setPreOperator(o24);
	
	o26 = new ScanDSM(&db_p_1, &attriRec_p[0], 1);
//	cout << "OK new o26" << endl;

	o27 = new BitFilter(o26, o25);
//	cout << "OK new o27" << endl;
	
	
	o29 = new OneSideHashJoin(o27, o23, &jon5, 1); 
//	cout << "OK new o29" << endl;
	
	o30 = new Projection(pro7, 4);
	o30->setPreOperator(o29);
//	cout << "OK new o30" << endl;
	
	
	
	
	o32 = new ScanDSM(&db_n2_1, &attriRec_n[0], 1);
//	cout << "OK new o32" << endl;
	/**/
	o33 = new ScanDSM(&db_n2_2, &attriRec_n[1], 1);
//	cout << "OK new o33" << endl;
	
	o34 = new ScanFromJI(o32, o33, &op6);
//	cout << "OK new o34" << endl;
	/*  */
	o35 = new ScanDSM(&db_s_4, &attriRec_s[3], 1);
//	cout << "OK new o35" << endl;
	
	o36 = new JoinIndex_OneHash(o34, o35); 
//	cout << "OK new o36" << endl;
	
	o37 = new ScanDSM(&db_s_1, &attriRec_s[0], 1);
//	cout << "OK new o37" << endl;
	
	o38 = new ScanFromJI(o37, o36, &op5);
//	cout << "OK new o38" << endl;

	o39 = new Projection(pro8, 2);
	o39->setPreOperator(o38);
	
	
	o40 = new OneSideHashJoin(o39, o30, &jon6,1); 
//	cout << "OK new o40" << endl;
	
	
	
	
	
	
	o41 = new Projection(pro9, 4);
	o41->setPreOperator(o40);
//	cout << "OK new o41" << endl;
	/*l_suppkey, n_name, l_partkey, o_orderdate,*/

	
	o48 = new Extract(ex, true, false, false);
	o48->setPreOperator(o41);
//	cout << "OK new o48" << endl;
	
	o49 = new GroupBy(group, 1, aggre, 1);
	o49->setPreOperator(o48);
//	cout << "OK new o49" << endl;
	
	o50 = new Sort(so1, 1);
	o50->setPreOperator(o49);
//	cout << "OK new o50" << endl;


	o51 = new OutPut(TIME_OUT);
//	cout << "OK new o51" << endl;
	o51->setPreOperator(o50);
	o51->init(env->getEnv());
	cout << "TEST START" << endl;
	
	cout << setprecision(2);
	cout << setiosflags(ios::fixed); 
	o51->exec();
	

}
Esempio n. 14
0
void isolate_root_with_cluster(double& low, double& hgh, Polynomial *p)
{
  dprint(low);
  dprint(hgh);
  // ensure starting conditions
  //
  PointVal pv_low(low,p);
  // double p_low = eval(low);
  if(pv_low.v() < 0.)
  {
    Polynomial p_minus = -(*p);
    p_minus.isolate_root(low,hgh);
    return;
  }

  // initialize algorithm
  //
  // initialize root bracket.
  //
  PointVal pv_hgh(hgh,p);
  RootBracketClusterState rb(pv_low,pv_hgh);
  dprint(rb.low().x());
  dprint(rb.low().v());
  dprint(rb.hgh().x());
  dprint(rb.hgh().v());
  //
  Polynomial Dp = p->get_derivative();

  // requirements of algorithm:
  // - second-order convergence in all cases
  // - high performance in generic cases
  // - handles repeated polynomial roots
  // - converges to a root between low and hgh
  // - residual of answer is less than machine precision

  // conditions maintained by algorithm:
  // * low < hgh
  // * p(low) > EPSILON
  // * p(hgh) < -EPSILON
  // using_hgh = fabs(p(hgh)) > fabs(p(low))

  // state of algorithm is specified by:
  // * low
  // * hgh
  // * using_hgh
  // * num_roots_in_cluster = assumed odd number of roots in cluster

  // iteration of algorithm:
  // use newton iteration on smaller side to look for root
  // - check that guess is between low and hgh
  //   and that new value has smaller residual
  //   else switch to secant method
  // - if newton does not change the sign
  //   increment num_roots_in_cluster until you leave interval,
  //   the sign changes, or the residual increases.
  //  - if the sign does change
  //    decrement num_roots_in_cluster until num_roots_in_cluster=1
  //    or the sign does not change (if residual does not shrink
  //    sufficiently modify num_roots_in_cluster).
  //  - do one iteration of bisection if residual did not
  //    shrink by factor of e.g. .5

  // assumed number of roots in root cluster we are converging towards
  goto start_newton_iteration;

 start_newton_iteration:
  // initialize newton iteration
  // choose smaller endpoint as starting value.
  goto newton_iteration;

 done:
   dprint(rb.num_evals());
   low = rb.low().x();
   hgh = rb.hgh().x();
   //return rb.x();
   return;

 // newton's method begins with a point which is one end of a root bracket.
 // it determines a displacement based on the value of the function
 // and its derivative at the point.  To handle root clusters
 // it assumes that the function is approximated by a shifted
 // and scaled monomial.
 newton_iteration:
  {
    if(rb.done()) goto done;
    dprintf("using newton: x0=%24.16e, p(x0)=%24.16e",rb.pv().x(),rb.pv().v());

    const PointVal start_pv0(rb.pv());
    //
    const double Dpx0 = Dp.eval(rb.pv().x());
    // bail if the derivative is too small
    if(fabs(Dpx0) < 1e-6)
    {
      dprintf("bad derivative: %f",Dpx0);
      goto newton_bailed;
    }
    double displacement = -rb.pv().v()/Dpx0;
   compute_x0:
    double x0 = rb.pv().x() + rb.num_roots_in_cluster()*displacement;
    // if Newton prediction is outside interval
    if(rb.not_in_interval(x0))
    {
      // reset num_roots_in_cluster and try again.
      if(rb.num_roots_in_cluster()!=1)
      {
        rb.reset_num_roots_in_cluster();
        goto compute_x0;
      }
      dprintf("Newton %24.16e outside interval [%24.16e,%24.16e]",
        x0, rb.low().x(), rb.hgh().x());
      dprintf("with values [%24.16e,%24.16e]", rb.low().v(), rb.hgh().v());
      goto newton_bailed;
    }
    // evaluate the polynomial at the new guess
    if(rb.eval(x0,p)) goto done;
    // bail if the new residual is not sufficiently smaller
    if(rb.pv().a() > .5*start_pv0.a()) // exp(-1) < .5 < 1
    {
      dprintf("apx0=%24.16e and start_apx0=%24.16e",rb.pv().a(),start_pv0.a());
      dprintf("so Newton didn't help enough, maybe because Dpx0=%24.16e.",Dpx0);
      goto newton_bailed;
    }
    // did the sign change?
    bool sign_changed = ((start_pv0.v() < 0. && rb.pv().v() > 0.)
                      || (start_pv0.v() > 0. && rb.pv().v() < 0.)) ? true : false;
    // does changing number of roots in root cluster help?
    const PointVal old_pv0 = rb.pv();
    if(sign_changed)
    {
      // keep decrementing presumed number
      // of roots in cluster as long as you can
      // until it does not help the residual
      if(rb.num_roots_in_cluster()>=3)
      {
        //double old_x0 = x0;
       decrement:
        double x0 = old_pv0.x() - 2*displacement;
        // displacement stayed in root bracket, so smaller one will too
        if(rb.eval(x0,p)) goto done;
        if(rb.pv().a() < old_pv0.a())
        {
            // accept decrement
            rb.decrement_num_roots_in_cluster();
            goto decrement;
        }
        else
        {
          // reject decrement
          rb.set_to_using_smaller();
          goto newton_iteration;
        }
      }
      // only one root so just iterate
      goto newton_iteration;
    }
    else // !sign_changed
    {
      // if the residual did not shrink by trigger_ratio then
      // we will try incrementing num_roots_in_cluster
      //
      // compute trigger_ratio
      //
      const double trigger_ratio
        = get_trigger_ratio_for_newton(rb.num_roots_in_cluster());
      // if residual shrunk by more than trigger_ratio we're fine
      if(rb.pv().a() < trigger_ratio*old_pv0.a())
      {
        // evidently not near a root cluster
        // with a wrong assumption about the number
        // of roots, so just iterate
        goto newton_iteration;
      }
      else
      {
        // keep incrementing presumed number of roots
        // in cluster until we are outside the interval
        // or until doing so does not improve
        // the residual by better than multiplying
        // it by a factor of .5
        // (can use any number between 1/e and 1).
        {
         increment:
          x0 += 2*displacement;
          if(rb.not_in_interval(x0))
          {
            // reject increment
            goto newton_iteration;
          }
          const PointVal curr_pv0(rb.pv());
          if(rb.eval(x0,p)) goto done;
          if(rb.pv().a() > .5*curr_pv0.a())
          {
            // reject increment
            //
            // the constraint that we always
            // tighten the root bracket whenever
            // we evaluate the polynomial means
            // we cannot completely reject the evaluation
            // although we can still refrain from
            // incrementing num_roots_in_cluster.
            rb.set_to_using_smaller();
            goto newton_iteration;
          }
          else
          {
            // accept increment
            rb.increment_num_roots_in_cluster();
            goto increment;
          }
        }
      }
      goto newton_iteration;
    }
  }

 newton_bailed:
  {
    // ideally we should try the secant method
    // before reverting to bisection
    //
    // the secant method should handle repeated roots better
    goto secant_bracket_iteration;
  }

 // the secant rule needs to maintain a list of two
 // points that we are "using".
 // the root bracket contains the most recently evaluated point.
 // The secant method is initialized with a root bracket.
 secant_bracket_iteration:
  {
    dprintf("using secant: low=%24.16e, hgh=%24.16e, p_low=%24.16e, p_hgh=%24.16e",
      rb.low().x(),rb.hgh().x(),rb.low().v(),rb.hgh().v());
    // rb.set_to_using_smaller();
    PointVal pv1(rb.pv_old());
    const double start_pva = fmax(pv1.a(),rb.pv().a());

   secant_iteration:
    // double accepted_num_roots_in_cluster = num_roots_in_cluster;
   compute_x0_secant: // for try_num_roots_in_cluster
    const double ratio = rb.pv().v()/pv1.v();
   compute_secant_rule:
      // problem: these numbers can be equal.
      //dprint(rb.pv().v());
      //dprint(pv1.v());
    double x0 = secant_rule(rb.pv().x(),pv1.x(),ratio,
      rb.num_roots_in_cluster());
    // make sure that x0 is in root bracket
    if(x0<rb.low().x() || x0>rb.hgh().x())
    {
      // different signs would force x0 in root bracket
      //assert_gt(ratio, 0.)
      // increasing num roots would only make it worse
      if(rb.num_roots_in_cluster()>1)
      {
        rb.decrement_num_roots_in_cluster();
        goto compute_secant_rule;
      }
      //else
      //{
      //  goto bisect;
      //}
    }
    // evaluate at the candidate
    dprint(x0);
    pv1 = rb.pv(); if(rb.eval(x0,p)) goto done;
    if(rb.pv().a() >= pv1.a())
    {
      dprintf("bisect");
      goto bisect;
    }

    // did residual change signs?

    bool sign_changed = ((pv1.v() < 0. && rb.pv().v() > 0.)
                      || (pv1.v() > 0. && rb.pv().v() < 0.)) ? true : false;
    // if residual changed signs then try decrementing num_roots_in_cluster
    // if residual did not change signs then try incrementing.
    if(!sign_changed)
    {
      // if the residual did not shrink by trigger_ratio then
      // we will try incrementing num_roots_in_cluster
      double secant_trigger = get_trigger_ratio_for_secant(
        rb.num_roots_in_cluster());
      if(pv1.a() > secant_trigger * rb.pv().a())
      {
        // try incrementing num_roots_in_cluster
        const double ratio = rb.pv().v()/pv1.v();
        const double x0 = secant_rule(rb.pv().x(),pv1.x(),ratio,
          rb.num_roots_in_cluster()+2);
        // make sure root is in interval
        if(x0<rb.low().x() || x0>rb.hgh().x())
        {
          dprintf("bisect");
          goto bisect;
        }
        pv1 = rb.pv(); if(rb.eval(x0,p)) goto done;
        if(rb.pv().a() < pv1.a())
        {
          rb.increment_num_roots_in_cluster();
          goto secant_iteration;
        }
      }
    }
    else
    {
      // try decrementing num_roots_in_cluster
      if(rb.num_roots_in_cluster()>=3)
      {
        const double ratio = rb.pv().v()/pv1.v();
        const double x0 = secant_rule(rb.pv().x(),pv1.x(),ratio,
          rb.num_roots_in_cluster()-2);
        // make sure root is in interval
        if(x0<rb.low().x() || x0>rb.hgh().x()) goto bisect;
        pv1 = rb.pv(); if(rb.eval(x0,p)) goto done;
        if(rb.pv().a() < pv1.a())
        {
          rb.decrement_num_roots_in_cluster();
          goto secant_iteration;
        }
      }
    }
   secant_iter_done:
    {
      if(rb.pv().a() > .5*start_pva)
      {
        dprintf("secant did not help enough: apx=%24.16e, old_apx=%24.16e",
          rb.pv().a(), start_pva);
        goto bisect;
      }
      goto secant_bracket_iteration;
    }
  }
  
 bisect:
  {
    dprintf("bisecting: x=%24.16e, px=%24.16e",rb.pv().x(),rb.pv().v());
    const double x0 = (rb.low().x() + rb.hgh().x())*.5;
    if(rb.eval(x0,p)) goto done;
    //goto newton_iteration;
    goto secant_bracket_iteration;
  }
  eprintf("should not get here");
  return;
}
Esempio n. 15
0
int main(){
	chdir("../RunData");
	BDBOpe db_r_1("1.1.DSM");
	BDBOpe db_r_2("1.2.DSM");
	BDBOpe db_n_1("2.1.DSM");
	BDBOpe db_n2_1("2.1.DSM");
	BDBOpe db_n2_2("2.2.DSM");
	BDBOpe db_n_3("2.3.DSM");
	BDBOpe db_s_1("3.1.DSM");
	BDBOpe db_s_4("3.4.DSM");
	BDBOpe db_p_1("4.1.DSM");
	BDBOpe db_p_5("4.5.DSM");
	BDBOpe db_c_1("6.1.DSM");
	BDBOpe db_c_4("6.4.DSM");
	BDBOpe db_o_1("7.1.DSM");
	BDBOpe db_o_2("7.2.DSM");
	BDBOpe db_o_5("7.5.DSM");
	BDBOpe db_l_1("8.1.DSM");
	BDBOpe db_l_2("8.2.DSM");
	BDBOpe db_l_3("8.3.DSM");
	BDBOpe db_l_6("8.6.DSM");
	BDBOpe db_l_7("8.7.DSM");

	Operator *o1, *o2, *o3, *o4, *o5, *o6, *o7, *o8, *o9, *o10;
	Operator *o11, *o12, *o13, *o14, *o15, *o16, *o17, *o18, *o19, *o20;
	Operator *o21, *o22, *o23, *o24, *o25, *o26, *o27, *o28, *o29, *o30;
	Operator *o31, *o32, *o33, *o34, *o35, *o36, *o37, *o38, *o39, *o40;
	Operator *o41, *o42, *o43, *o44, *o45, *o46, *o47, *o48, *o49, *o50, *o51;
	db_r_1.open();
	db_r_2.open();
	db_n_1.open();
	db_n2_1.open();
	db_n2_2.open();
	db_n_3.open();
	db_s_1.open();
	db_s_4.open();
	db_p_1.open();
	db_p_5.open();
	db_c_1.open();
	db_c_4.open();
	db_o_1.open();
	db_o_2.open();
	db_o_5.open();
	db_l_1.open();
	db_l_2.open();
	db_l_3.open();
	db_l_6.open();
	db_l_7.open();
	
	TABLE_REC tableRec_r;
	TABLE_REC tableRec_n;
	TABLE_REC tableRec_s;
	TABLE_REC tableRec_p;
	TABLE_REC tableRec_c;
	TABLE_REC tableRec_o;
	TABLE_REC tableRec_l;

	tableRec_r.tableID = 1;
	tableRec_r.attriNum = 3;

	tableRec_n.tableID = 2;
	tableRec_n.attriNum = 4;
	
	tableRec_s.tableID = 3;
	tableRec_s.attriNum = 7;
	
	tableRec_p.tableID = 4;
	tableRec_p.attriNum = 9;
	
	tableRec_c.tableID = 6;
	tableRec_c.attriNum = 8;
	
	tableRec_o.tableID = 7;
	tableRec_o.attriNum = 9;
	
	tableRec_l.tableID = 8;
	tableRec_l.attriNum = 16;
	
	
	ATTRIBUTE_REC attriRec_r[tableRec_r.attriNum];
	ATTRIBUTE_REC attriRec_n[tableRec_n.attriNum];
	ATTRIBUTE_REC attriRec_s[tableRec_s.attriNum];
	ATTRIBUTE_REC attriRec_p[tableRec_p.attriNum];
	ATTRIBUTE_REC attriRec_c[tableRec_c.attriNum];
	ATTRIBUTE_REC attriRec_o[tableRec_o.attriNum];
	ATTRIBUTE_REC attriRec_l[tableRec_l.attriNum];

	AttributeManager AM_r;
	AttributeManager AM_n;
	AttributeManager AM_s;
	AttributeManager AM_p;
	AttributeManager AM_c;
	AttributeManager AM_o;
	AttributeManager AM_l;
	
	AM_r.getForTableID(tableRec_r, attriRec_r);
	for(int i=0 ; i < (int)tableRec_r.attriNum ; i++){
		cout << attriRec_r[i].attributeName << endl;
	}
	AM_n.getForTableID(tableRec_n, attriRec_n);
	for(int i=0 ; i < (int)tableRec_n.attriNum ; i++){
		cout << attriRec_n[i].attributeName << endl;
	}
	AM_s.getForTableID(tableRec_s, attriRec_s);
	for(int i=0 ; i < (int)tableRec_s.attriNum ; i++){
		cout << attriRec_s[i].attributeName << endl;
	}
	AM_p.getForTableID(tableRec_p, attriRec_p);
	for(int i=0 ; i < (int)tableRec_p.attriNum ; i++){
		cout << attriRec_p[i].attributeName << endl;
	}
	AM_c.getForTableID(tableRec_c, attriRec_c);
	for(int i=0 ; i < (int)tableRec_c.attriNum ; i++){
		cout << attriRec_c[i].attributeName << endl;
	}
	AM_o.getForTableID(tableRec_o, attriRec_o);
	for(int i=0 ; i < (int)tableRec_o.attriNum ; i++){
		cout << attriRec_o[i].attributeName << endl;
	}
	AM_l.getForTableID(tableRec_l, attriRec_l);
	for(int i=0 ; i < (int)tableRec_l.attriNum ; i++){
		cout << attriRec_l[i].attributeName << endl;
	}

/* selection1 */
	FixStrPosVal pv1(1,25);
	string str1("AMERICA");
	pv1.setStr(str1);

	ValueNode vn1 = ValueNode(&pv1);
	ColumnRefNode cn1;
	cn1.tableID = 1;
	cn1.attriID = 2;
	AxprNode an1 = AxprNode(EQ, &cn1, &vn1);
	

/* selection2 */

	DatePosVal pv2(1,(unsigned char *)"1995-01-01");
	DatePosVal pv3(1,(unsigned char *)"1996-12-31");
	

	ValueNode vn2 = ValueNode(&pv2);
	ValueNode vn3 = ValueNode(&pv3);
	ColumnRefNode cn2;
	cn2.tableID = 7;
	cn2.attriID = 5;
	AxprNode an2 = AxprNode(GE, &cn2, &vn2);
	AxprNode an3 = AxprNode(LE, &cn2, &vn3);
	AxprNode an4 = AxprNode(AND, &an2, &an3);

/* selection3 */
	VarStrPosVal pv4(1,25);
	string str2("ECONOMY ANODIZED STEEL");
	pv4.set((unsigned char*)str2.c_str());

	ValueNode vn4 = ValueNode(&pv4);
	ColumnRefNode cn3;
	cn3.tableID = 4;
	cn3.attriID = 5;
	AxprNode an5 = AxprNode(EQ, &cn3, &vn4);
	

	
/*Join1*/
	OPERATION_NODE jop1, jop2;
	jop1.tableID = 6;
	jop1.attributeID = 4;
	jop2.tableID = 6;
	jop2.attributeID = 1;
	
	JOIN_OPERATION_NODE jon1;
	jon1.rightNode = jop1;
	jon1.leftNode = jop2;

/*Join2*/
	OPERATION_NODE jop3, jop4;
	jop3.tableID = 7;
	jop3.attributeID = 2;
	jop4.tableID = 7;
	jop4.attributeID = 5;
	
	JOIN_OPERATION_NODE jon2;
	jon2.rightNode = jop3;
	jon2.leftNode = jop4;

/*Join3*/
	OPERATION_NODE jop5, jop6;
	jop5.tableID = 7;
	jop5.attributeID = 5;
	jop6.tableID = 7;
	jop6.attributeID = 1;
	
	JOIN_OPERATION_NODE jon3;
	jon3.rightNode = jop5;
	jon3.leftNode = jop6;

/*Join4*/
	OPERATION_NODE jop7, jop8;
	jop7.tableID = 7;
	jop7.attributeID = 1;
	jop8.tableID = 8;
	jop8.attributeID = 1;
	
	JOIN_OPERATION_NODE jon4;
	jon4.rightNode = jop7;
	jon4.leftNode = jop8;
	
/*Join5*/
	OPERATION_NODE jop9, jop10;
	jop9.tableID = 4;
	jop9.attributeID = 1;
	jop10.tableID = 8;
	jop10.attributeID = 2;
	
	JOIN_OPERATION_NODE jon5;
	jon5.rightNode = jop9;
	jon5.leftNode = jop10;
	
/* Projection1 */

	OPERATION_NODE pro1[1];
	pro1[0].tableID = 6;
	pro1[0].attributeID = 1;
	
	
/* Projection2 */

	OPERATION_NODE pro2[2];
	pro2[0].tableID = 7;
	pro2[0].attributeID = 1;
	pro2[1].tableID = 7;
	pro2[1].attributeID = 5;
	
/* Projection3 */

	OPERATION_NODE pro3[1];
	pro3[0].tableID = 8;
	pro3[0].attributeID = 2;
	
/* Projection4 */

	OPERATION_NODE pro4[2];
	pro4[0].tableID = 8;
	pro4[0].attributeID = 3;
	pro4[1].tableID = 2;
	pro4[1].attributeID = 2;

/* Projection5 */

	OPERATION_NODE pro5[4];
	pro5[0].tableID = 7;
	pro5[0].attributeID = 5;
	pro5[1].tableID = 2;
	pro5[1].attributeID = 2;
	pro5[2].tableID = 8;
	pro5[2].attributeID = 6;
	pro5[3].tableID = 8;
	pro5[3].attributeID = 7;

/* Extract */
	OPERATION_NODE ex[1];
	ex[0].tableID = 7;
	ex[0].attributeID = 5;

/* GROUP */
	IntPosVal pv5(1, 1);
	ValueNode vn5 = ValueNode(&pv5);
	ColumnRefNode cn4[2];
	cn4[0].tableID = 8;
	cn4[0].attriID = 6;
	cn4[1].tableID = 8;
	cn4[1].attriID = 7;
	ArithmeticNode arith1(SUB, &vn5, &cn4[1]);
	ArithmeticNode arith2(MUL, &cn4[0], &arith1);
	
	Aggregation *aggre[1];
	aggre[0] = new Sum(&arith2, 2);
	
	
	OPERATION_NODE group[1];
	group[0].tableID = 7;
	group[0].attributeID = 5;

/* Sort 1 */
	OPERATION_NODE so1[1];
	so1[0].tableID = 7;
	so1[0].attributeID = 5;
	so1[0].option = 0;
	
	


	OPERATION_NODE op1;
	op1.tableID = 2;
	op1.attributeID = 3;
	
	OPERATION_NODE op2;
	op2.tableID = 6;
	op2.attributeID = 4;
	
	OPERATION_NODE op3;
	op3.tableID = 7;
	op3.attributeID = 2;
	
	OPERATION_NODE op4;
	op4.tableID = 8;
	op4.attributeID = 1;
	
	OPERATION_NODE op5;
	op5.tableID = 3;
	op5.attributeID = 4;
	
	OPERATION_NODE op6;
	op6.tableID = 2;
	op6.attributeID = 2;
	
	


	o1 = new ScanDSM(&db_r_2, &attriRec_r[1], 1);
	cout << "OK new o1" << endl;
	
	o2 = new SelectBitOut((Node *)&an1 ,(unsigned int)1);
	cout << "OK new o2" << endl;
	o2->setPreOperator(o1);
	
	o3 = new ScanDSM(&db_r_1, attriRec_r, 1);
	cout << "OK new o3" << endl;
	
	o4 = new BitFilter(o3, o2);
	cout << "OK new o4" << endl;
	
	
	o5 = new ScanDSM(&db_n_3, &attriRec_n[2], 1);
	cout << "OK new o5" << endl;
	
	o6 = new JoinIndex_OneHash(o4, o5); 
	cout << "OK new o6" << endl;
	
	o7 = new ScanDSM(&db_n_1, &attriRec_n[0], 1);
	cout << "OK new o7" << endl;
	
	o8 = new ScanFromJI(o7, o6, &op1);
	cout << "OK new o8" << endl;

	o9 = new ScanDSM(&db_c_4, &attriRec_c[3], 1);
	cout << "OK new o9" << endl;

	o10 = new JoinIndex_OneHash(o8, o9); 
	cout << "OK new o10" << endl;
	
	o11 = new ScanDSM(&db_c_1, &attriRec_c[0], 1);
	cout << "OK new o11" << endl;
	
	o12 = new ScanFromJI(o11, o10, &op2);
	cout << "OK new o8" << endl;
	
	o13 = new Projection(pro1, 1);
	o13->setPreOperator(o12);
	
	
	
	o14 = new ScanDSM(&db_o_2, &attriRec_o[1], 1);
	cout << "OK new o14" << endl;
	
	o15 = new JoinIndex_OneHash(o13, o14); 
	cout << "OK new o15" << endl;
	

	o16 = new ScanDSM(&db_o_5, &attriRec_o[4], 1);
	cout << "OK new o16" << endl;

	o17 = new Selection((Node *)&an4 ,(unsigned int)2);
	cout << "OK new o17" << endl;
	o17->setPreOperator(o16);
	
	
	o18 = new ScanFromJI(o17, o15, &op3);
	cout << "OK new o18" << endl;
	
	o19 = new ScanDSM(&db_o_1, &attriRec_o[0], 1);
	cout << "OK new o19" << endl;
	
	o20 = new ScanFromJI(o19, o18, &op3);
	cout << "OK new o20" << endl;

	o21 = new Projection(pro2, 2);
	o21->setPreOperator(o20);
	cout << "OK new o21" << endl;
	
	o22 = new ScanDSM(&db_l_1, &attriRec_l[0], 1);
	cout << "OK new o22" << endl;
	/*o_orderkey, o_orderdate, l_orderkey*/
	o23 = new JoinIndex_OneHash(o21, o22, &jon4); 
	cout << "OK new o23" << endl;
	
	

	o24 = new ScanDSM(&db_p_5, &attriRec_p[4], 1);
	cout << "OK new o24" << endl;

	o25 = new SelectBitOut((Node *)&an5 ,1);
	cout << "OK new o25" << endl;
	o25->setPreOperator(o24);
	
	o26 = new ScanDSM(&db_p_1, &attriRec_p[0], 1);
	cout << "OK new o26" << endl;

	o27 = new BitFilter(o26, o25);
	cout << "OK new o27" << endl;
	
	o28 = new ScanDSM(&db_l_2, &attriRec_l[1], 1);
	cout << "OK new o28" << endl;
	
	o29 = new JoinIndex_OneHash(o27, o28, &jon5); 
	cout << "OK new o29" << endl;
	
	o30 = new Projection(pro3, 1);
	o30->setPreOperator(o29);
	cout << "OK new o30" << endl;
	/*l_partkey, o_orderkey, o_orderdate, l_orderkey*/
	o31 = new ScanFromJI(o30, o23, &op4);
	cout << "OK new o31" << endl;	
	
	
	
	
	o32 = new ScanDSM(&db_n2_1, &attriRec_n[0], 1);
	cout << "OK new o32" << endl;
	/**/
	o33 = new ScanDSM(&db_n2_2, &attriRec_n[1], 1);
	cout << "OK new o33" << endl;
	
	o34 = new ScanFromJI(o32, o33, &op6);
	cout << "OK new o34" << endl;
	/*  */
	o35 = new ScanDSM(&db_s_4, &attriRec_s[3], 1);
	cout << "OK new o35" << endl;
	
	o36 = new JoinIndex_OneHash(o34, o35); 
	cout << "OK new o36" << endl;
	
	o37 = new ScanDSM(&db_s_1, &attriRec_s[0], 1);
	cout << "OK new o37" << endl;
	
	o38 = new ScanFromJI(o37, o36, &op5);
	cout << "OK new o38" << endl;
	
	o39 = new ScanDSM(&db_l_3, &attriRec_l[2], 1);
	cout << "OK new o39" << endl;
	
	o40 = new JoinIndex_OneHash(o38, o39); 
	cout << "OK new o40" << endl;
	
	o41 = new Projection(pro4, 2);
	o41->setPreOperator(o40);
	cout << "OK new o41" << endl;
	/*l_suppkey, n_name, l_partkey, o_orderkey, o_orderdate, l_orderkey*/
	o42 = new ScanFromJI(o41, o31, &op4);
	cout << "OK new o42" << endl;
	
	
	o43 = new ScanDSM(&db_l_6, &attriRec_l[5], 1);
	cout << "OK new o43" << endl;
	/*l_extendedproce, l_suppkey, n_name, l_partkey, o_orderkey, o_orderdate, l_orderkey*/
	o44 = new ScanFromJI(o43, o42, &op4);
	cout << "OK new o44" << endl;


	o45 = new ScanDSM(&db_l_7, &attriRec_l[6], 1);
	cout << "OK new o45" << endl;
	/*l_discount, l_extendedproce, l_suppkey, n_name, l_partkey, o_orderkey, o_orderdate, l_orderkey*/
	o46 = new ScanFromJI(o45, o44, &op4);
	cout << "OK new o46" << endl;

	o47 = new Projection(pro5, 4);
	o47->setPreOperator(o46);
	
	o48 = new Extract(ex, true, false, false);
	o48->setPreOperator(o47);
	cout << "OK new o48" << endl;
	
	o49 = new GroupBy(group, 1, aggre, 1);
	o49->setPreOperator(o48);
	cout << "OK new o49" << endl;
	
	o50 = new Sort(so1, 1);
	o50->setPreOperator(o49);
	cout << "OK new o50" << endl;


	o51 = new OutPut(STD_OUT);
	cout << "OK new o51" << endl;
	o51->setPreOperator(o50);
	o51->init();
	cout << "TEST START" << endl;
	o51->exec();
	

}
Esempio n. 16
0
int main(){
	chdir(QUERY_DATA_PATH);
	EnvDB *env = new EnvDB();
	env->open();
	
	BDBOpe db_l_5(env->getEnv(), "8.5.DSM");
	BDBOpe db_l_6(env->getEnv(), "8.6.DSM");
	BDBOpe db_l_7(env->getEnv(), "8.7.DSM");
	BDBOpe db_l_11(env->getEnv(), "8.11.DSM");
	
	Operator *o1, *o2, *o3, *o4, *o5, *o6, *o7, *o8, *o9, *o10;
	Operator *o11, *o12;
	
	db_l_5.open();
	db_l_6.open();
	db_l_7.open();
	db_l_11.open();
	
	TABLE_REC tableRec_l;
	tableRec_l.tableID = 8;
	tableRec_l.attriNum = 16;
	ATTRIBUTE_REC attriRec_l[tableRec_l.attriNum];
	AttributeManager AM(env->getEnv());
	
	AM.getForTableID(tableRec_l, attriRec_l);
	
/* selection1 */

	DatePosVal pv1(1,(unsigned char *)"1994-01-01");

	ValueNode vn1 = ValueNode(&pv1);
	ColumnRefNode cn1;
	cn1.tableID = 8;
	cn1.attriID = 11;
	AxprNode an1 = AxprNode(GE, &cn1, &vn1);
	


	DatePosVal pv2(1,(unsigned char *)"1995-01-01");

	ValueNode vn2 = ValueNode(&pv2);
	ColumnRefNode cn2;
	cn2.tableID = 8;
	cn2.attriID = 11;
	AxprNode an2 = AxprNode(LT, &cn2, &vn2);
	
	AxprNode an7 = AxprNode(AND, &an1, &an2);
	
/* selection3 */

	FloatPosVal pv3(1, 0.06-0.01);
	FloatPosVal pv4(1, 0.06+0.01);
	

	ValueNode vn3 = ValueNode(&pv3);
	ValueNode vn4 = ValueNode(&pv4);
	ColumnRefNode cn3;
	cn3.tableID = 8;
	cn3.attriID = 7;
	AxprNode an3 = AxprNode(GE, &cn3, &vn3);
	AxprNode an4 = AxprNode(LE, &cn3, &vn4);
	AxprNode an5 = AxprNode(AND, &an3, &an4);
	
/* selection4 */

	FloatPosVal pv5(1, 24);

	ValueNode vn5 = ValueNode(&pv5);
	ColumnRefNode cn4;
	cn4.tableID = 8;
	cn4.attriID = 5;
	AxprNode an6 = AxprNode(LT, &cn4, &vn5);
	
	
/* AGGREGATION */
	ColumnRefNode cn5[2];
	cn5[0].tableID = 8;
	cn5[0].attriID = 6;
	cn5[1].tableID = 8;
	cn5[1].attriID = 7;
	ArithmeticNode arith1(MUL, &cn5[0], &cn5[1]);
	
	Aggregation *aggre[1];
	aggre[0] = new Sum(&arith1, 2);
	
	
	
	OPERATION_NODE op1;
	op1.tableID = 8;
	op1.attributeID = 7;
	
	
	
	o1 = new ScanDSM(&db_l_11, &attriRec_l[10], 1);
//	cout << "OK new o1" << endl;
	
	o2 = new SelectBitOut((Node *)&an7 ,(unsigned int)2);
//	cout << "OK new o2" << endl;
	o2->setPreOperator(o1);
	
	o3 = new ScanDSM(&db_l_5, &attriRec_l[4], 1);
//	cout << "OK new o3" << endl;
	
	o4 = new BitFilter(o3, o2);
//	cout << "OK new o4" << endl;
	
	o5 = new Selection((Node *)&an6 ,(unsigned int)1);
//	cout << "OK new o5" << endl;
	o5->setPreOperator(o4);
	
	o6 = new ScanDSM(&db_l_7, &attriRec_l[6], 1);
//	cout << "OK new o6" << endl;

	o7 = new Selection((Node *)&an5 ,(unsigned int)2);
//	cout << "OK new o7" << endl;
	o7->setPreOperator(o6);
	
	o8 = new ScanFromJI(o5, o7, &op1);
//	cout << "OK new o8" << endl;
	
	o9 = new ScanDSM(&db_l_6, &attriRec_l[5], 1);
//	cout << "OK new o9" << endl;
	
	o10 = new ScanFromJI(o9, o8, &op1);
//	cout << "OK new o10" << endl;
	
	o11 = new AggreOut(aggre, 1);
	o11->setPreOperator(o10);
//	cout << "OK new o11" << endl;
	
	o12 = new OutPut(STD_OUT);
//	cout << "OK new o12" << endl;
	o12->setPreOperator(o11);
	o12->init(env->getEnv());
	cout << "TEST START" << endl;
	
	cout << setprecision(6);
	cout << setiosflags(ios::fixed); 
	o12->exec();
}