Example #1
0
    void arithmeticExpression_2()
    {
        cout << "\nbuild arithmetic column by using accessing methods:" << endl;
        erydbSelectExecutionPlan::Parser parser;
        std::vector<Token> tokens;
        Token t;
        
        ArithmeticColumn b;
        cout << b;
        
        ConstantColumn *c1 = new ConstantColumn();
        c1->constval("'ASIA'");
        c1->type(ConstantColumn::LITERAL);
        //CPPUNIT_ASSERT (c1->data() == "'ASIA'(l)");
        
        t.value = c1;
        tokens.push_back(t);
        
        t.value = new Operator ("/");
        tokens.push_back(t);        
        
        ConstantColumn *c2 = new ConstantColumn(5);        
        CPPUNIT_ASSERT (c2->type() == ConstantColumn::NUM);
        t.value = c2;
        tokens.push_back(t);
        
        ParseTree* tree = parser.parse(tokens.begin(), tokens.end());
        b.expression (tree);

        cout << b;
        cout << " --- end of test 7 ---" << endl;                 
    }
Example #2
0
	ArithmeticColumn* makeArithmeticColumn()
	{
		ArithmeticColumn *ret;
		ParseTree *t;
		
		t = makeParseTree();
		ret = new ArithmeticColumn();
		ret->expression(t);
		ret->alias("ArithmeticColumn");
		ret->data("AD");
		return ret;
	}
Example #3
0
void VirtualTable::addColumn(const SRCP& column)
{
	// As of bug3695, make sure varbinary is not used in subquery.
	if (column->resultType().colDataType == CalpontSystemCatalog::VARBINARY && !fVarBinOK)
		throw runtime_error ("VARBINARY in subquery is not supported.");

	AggregateColumn*      agc = NULL;
	ArithmeticColumn*     arc = NULL;
	ConstantColumn*       cc  = NULL;
	FunctionColumn*       fc  = NULL;
	SimpleColumn*         sc  = NULL;
	WindowFunctionColumn* wc  = NULL;

	string columnName;
	ostringstream oss;
	UniqId colId;
	if ((sc = dynamic_cast<SimpleColumn*>(column.get())) != NULL)
	{
		columnName = sc->columnName();
		colId = UniqId(sc);
	}
	else if ((agc = dynamic_cast<AggregateColumn*>(column.get())) != NULL)
	{
//		oss << agc->functionName() << "_" << agc->expressionId();
//		oss << "Aggregate_" << agc->expressionId();
		columnName = agc->data();
		colId = UniqId(agc->expressionId(), "", "", "");
	}
	else if ((wc = dynamic_cast<WindowFunctionColumn*>(column.get())) != NULL)
	{
//		oss << wc->functionName() << "_" << wc->expressionId();
//		oss << "Window_" << wc->expressionId();
		columnName = wc->data();
		colId = UniqId(wc->expressionId(), "", "", "");
	}
	else if ((arc = dynamic_cast<ArithmeticColumn*>(column.get())) != NULL)
	{
//		oss << "Arithmetic_" << arc->expressionId();
		columnName = arc->data();
		colId = UniqId(arc->expressionId(), "", "", "");
	}
	else if ((fc = dynamic_cast<FunctionColumn*>(column.get())) != NULL)
	{
//		oss << fc->functionName() << "_" << fc->expressionId();
		columnName = fc->data();
		colId = UniqId(fc->expressionId(), "", "", "");
	}
	else if ((cc = dynamic_cast<ConstantColumn*>(column.get())) != NULL)
	{
//		oss << "Constant_" << cc->expressionId();
		columnName = cc->data();
		colId = UniqId(cc->expressionId(), cc->alias(), "", fView);
	}
	else // new column type has added, but this code is not updated.
	{
		oss << "not supported column type: " << typeid(*(column.get())).name();
		throw runtime_error(oss.str());
	}

	if (columnName.empty())
		columnName = column->alias();

	SimpleColumn* vc = new SimpleColumn();
	vc->tableName(fName);
	vc->tableAlias(fAlias);
	vc->columnName(columnName);
	vc->alias(column->alias());
	vc->viewName(fView);

	uint32_t index = fColumns.size();
	vc->colPosition(index);
	vc->oid(fTableOid+index+1);
	vc->resultType(column->resultType());

	SSC ssc(vc);
	fColumns.push_back(ssc);
	fColumnTypes.push_back(column->resultType());
	fColumnMap.insert(make_pair(colId, index));
}
Example #4
0
SimpleFilter::SimpleFilter(const SimpleFilter& rhs) :
	fOp(rhs.op()),
	fIndexFlag(rhs.indexFlag()),
	fJoinFlag(rhs.joinFlag())
{
	fLhs = rhs.lhs()->clone();
	fRhs = rhs.rhs()->clone();

	fSimpleColumnList.clear();
	fAggColumnList.clear();
	fWindowFunctionColumnList.clear();

	SimpleColumn *lsc = dynamic_cast<SimpleColumn*>(fLhs);
	FunctionColumn *lfc = dynamic_cast<FunctionColumn*>(fLhs);
	ArithmeticColumn *lac = dynamic_cast<ArithmeticColumn*>(fLhs);
	WindowFunctionColumn *laf = dynamic_cast<WindowFunctionColumn*>(fLhs);
	AggregateColumn *lagc = dynamic_cast<AggregateColumn*>(fLhs);
	SimpleColumn *rsc = dynamic_cast<SimpleColumn*>(fRhs);
	FunctionColumn *rfc = dynamic_cast<FunctionColumn*>(fRhs);
	ArithmeticColumn *rac = dynamic_cast<ArithmeticColumn*>(fRhs);
	AggregateColumn *ragc = dynamic_cast<AggregateColumn*>(fRhs);
	WindowFunctionColumn *raf = dynamic_cast<WindowFunctionColumn*>(fRhs);

	if (lsc)
	{
		fSimpleColumnList.push_back(lsc);
	}
	else if (lagc)
	{
		fAggColumnList.push_back(lagc);
	}
	else if (lfc)
	{
		fSimpleColumnList.insert(fSimpleColumnList.end(), lfc->simpleColumnList().begin(), lfc->simpleColumnList().end());
		fAggColumnList.insert(fAggColumnList.end(), lfc->aggColumnList().begin(), lfc->aggColumnList().end());
		fWindowFunctionColumnList.insert
		  (fWindowFunctionColumnList.end(), lfc->windowfunctionColumnList().begin(), lfc->windowfunctionColumnList().end());
	}
	else if (lac)
	{
		fSimpleColumnList.insert(fSimpleColumnList.end(), lac->simpleColumnList().begin(), lac->simpleColumnList().end());
		fAggColumnList.insert(fAggColumnList.end(), lac->aggColumnList().begin(), lac->aggColumnList().end());
		fWindowFunctionColumnList.insert
		  (fWindowFunctionColumnList.end(), lac->windowfunctionColumnList().begin(), lac->windowfunctionColumnList().end());
	}
	else if (laf)
	{
		fWindowFunctionColumnList.push_back(laf);
	}

	if (rsc)
	{
		fSimpleColumnList.push_back(rsc);
	}
	else if (ragc)
	{
		fAggColumnList.push_back(ragc);
	}
	else if (rfc)
	{
		fSimpleColumnList.insert
		  (fSimpleColumnList.end(), rfc->simpleColumnList().begin(), rfc->simpleColumnList().end());
		fAggColumnList.insert
		  (fAggColumnList.end(), rfc->aggColumnList().begin(), rfc->aggColumnList().end());
		fWindowFunctionColumnList.insert
		  (fWindowFunctionColumnList.end(), rfc->windowfunctionColumnList().begin(), rfc->windowfunctionColumnList().end());
	}
	else if (rac)
	{
		fSimpleColumnList.insert(fSimpleColumnList.end(), rac->simpleColumnList().begin(), rac->simpleColumnList().end());
		fAggColumnList.insert(fAggColumnList.end(), rac->aggColumnList().begin(), rac->aggColumnList().end());
		fWindowFunctionColumnList.insert
		  (fWindowFunctionColumnList.end(), rac->windowfunctionColumnList().begin(), rac->windowfunctionColumnList().end());
	}
	else if (raf)
	{
		fWindowFunctionColumnList.push_back(raf);
	}
}
Example #5
0
void SimpleFilter::unserialize(messageqcpp::ByteStream& b)
{
	ObjectReader::checkType(b, ObjectReader::SIMPLEFILTER);

	//delete fOp;
	delete fLhs;
	delete fRhs;
	Filter::unserialize(b);
	fOp.reset(dynamic_cast<Operator*>(ObjectReader::createTreeNode(b)));
	fLhs = dynamic_cast<ReturnedColumn*>(ObjectReader::createTreeNode(b));
	fRhs = dynamic_cast<ReturnedColumn*>(ObjectReader::createTreeNode(b));
	b >> reinterpret_cast<uint32_t&>(fIndexFlag);
	b >> reinterpret_cast<uint32_t&>(fJoinFlag);

	fSimpleColumnList.clear();
	fAggColumnList.clear();
	fWindowFunctionColumnList.clear();

	SimpleColumn *lsc = dynamic_cast<SimpleColumn*>(fLhs);
	FunctionColumn *lfc = dynamic_cast<FunctionColumn*>(fLhs);
	ArithmeticColumn *lac = dynamic_cast<ArithmeticColumn*>(fLhs);
	WindowFunctionColumn *laf = dynamic_cast<WindowFunctionColumn*>(fLhs);
	AggregateColumn *lagc = dynamic_cast<AggregateColumn*>(fLhs);
	SimpleColumn *rsc = dynamic_cast<SimpleColumn*>(fRhs);
	FunctionColumn *rfc = dynamic_cast<FunctionColumn*>(fRhs);
	ArithmeticColumn *rac = dynamic_cast<ArithmeticColumn*>(fRhs);
	AggregateColumn *ragc = dynamic_cast<AggregateColumn*>(fRhs);
	WindowFunctionColumn *raf = dynamic_cast<WindowFunctionColumn*>(fRhs);

	if (lsc)
	{
		fSimpleColumnList.push_back(lsc);
	}
	else if (lagc)
	{
		fAggColumnList.push_back(lagc);
	}
	else if (lfc)
	{
		fSimpleColumnList.insert(fSimpleColumnList.end(), lfc->simpleColumnList().begin(), lfc->simpleColumnList().end());
		fAggColumnList.insert(fAggColumnList.end(), lfc->aggColumnList().begin(), lfc->aggColumnList().end());
		fWindowFunctionColumnList.insert
		  (fWindowFunctionColumnList.end(), lfc->windowfunctionColumnList().begin(), lfc->windowfunctionColumnList().end());
	}
	else if (lac)
	{
		fSimpleColumnList.insert(fSimpleColumnList.end(), lac->simpleColumnList().begin(), lac->simpleColumnList().end());
		fAggColumnList.insert(fAggColumnList.end(), lac->aggColumnList().begin(), lac->aggColumnList().end());
		fWindowFunctionColumnList.insert
		  (fWindowFunctionColumnList.end(), lac->windowfunctionColumnList().begin(), lac->windowfunctionColumnList().end());
	}
	else if (laf)
	{
		fWindowFunctionColumnList.push_back(laf);
	}

	if (rsc)
	{
		fSimpleColumnList.push_back(rsc);
	}
	else if (ragc)
	{
		fAggColumnList.push_back(ragc);
	}
	else if (rfc)
	{
		fSimpleColumnList.insert
		  (fSimpleColumnList.end(), rfc->simpleColumnList().begin(), rfc->simpleColumnList().end());
		fAggColumnList.insert
		  (fAggColumnList.end(), rfc->aggColumnList().begin(), rfc->aggColumnList().end());
		fWindowFunctionColumnList.insert
		  (fWindowFunctionColumnList.end(), rfc->windowfunctionColumnList().begin(), rfc->windowfunctionColumnList().end());
	}
	else if (rac)
	{
		fSimpleColumnList.insert(fSimpleColumnList.end(), rac->simpleColumnList().begin(), rac->simpleColumnList().end());
		fAggColumnList.insert(fAggColumnList.end(), rac->aggColumnList().begin(), rac->aggColumnList().end());
		fWindowFunctionColumnList.insert
		  (fWindowFunctionColumnList.end(), rac->windowfunctionColumnList().begin(), rac->windowfunctionColumnList().end());
	}
	else if (raf)
	{
		fWindowFunctionColumnList.push_back(raf);
	}

	// construct regex constant for like operator
	if (fOp->op() == OP_LIKE || fOp->op() == OP_NOTLIKE)
	{
		ConstantColumn *rcc = dynamic_cast<ConstantColumn*>(fRhs);
		if (rcc)
			rcc->constructRegex();
		ConstantColumn *lcc = dynamic_cast<ConstantColumn*>(fLhs);
		if (lcc)
			lcc->constructRegex();
	}
}
Example #6
0
    void selectExecutionPlan_1() {
        cout << "SQL: select region.r_regionkey from region, nation where nation.n_regionkey = region.r_regionkey and nation.n_regionkey != 3;" << endl;

        erydbSelectExecutionPlan csep;
        CPPUNIT_ASSERT (csep.location() == erydbSelectExecutionPlan::MAIN);
        CPPUNIT_ASSERT (csep.dependent() == false);
        CPPUNIT_ASSERT (csep.subSelects().size() == 0);
        
        // returned columns
        erydbSelectExecutionPlan::ReturnedColumnList colList;        
        SimpleColumn *sc = new SimpleColumn("tpch.region.r_regionkey", 0);
        colList.push_back(sc);        
        ArithmeticColumn *ac = new ArithmeticColumn("a+sum(r_regionkey)", 0);
        colList.push_back(ac);
        csep.returnedCols (colList);   
        CPPUNIT_ASSERT(csep.returnedCols().size() == 2);     
               
        // filters
        erydbSelectExecutionPlan::FilterTokenList filterTokenList;
       
        SimpleFilter *sf = new SimpleFilter();
        SimpleColumn *lhs = new SimpleColumn();
        *lhs = *sc;       
        SimpleColumn *rhs = new SimpleColumn("tpch.nation.n_regionkey", 0);
        CPPUNIT_ASSERT (*lhs == *sc);
        CPPUNIT_ASSERT (*rhs != *lhs);
        Operator *op = new Operator("=");
        
        sf->op(op);
        sf->lhs(lhs);
        sf->rhs(rhs);
        filterTokenList.push_back (sf);
        
        filterTokenList.push_back( new Operator ("And") );   
        SimpleFilter *sf1 = new SimpleFilter (new Operator("="), sc->clone(), ac->clone());
        
        filterTokenList.push_back (sf1);
               
        csep.filterTokenList (filterTokenList);
        ParseTree *filterList = const_cast<ParseTree*> (csep.filters());
        
        // draw filterList tree
        filterList->drawTree("selectExecutionPlan_1.dot");                     
        csep.filters (filterList);

        // Group by
	    erydbSelectExecutionPlan::GroupByColumnList groupByList;
        groupByList.push_back(sc->clone());        
        csep.groupByCols (groupByList);
        CPPUNIT_ASSERT(csep.groupByCols().size() == 1);
        
        // Having
        erydbSelectExecutionPlan::FilterTokenList havingTokenList;
        SimpleFilter *having = new SimpleFilter( new Operator("="),
                                                 new ArithmeticColumn("sum(volumn)", 0),
                                                 new ConstantColumn(8));
        havingTokenList.push_back (having);
        csep.havingTokenList (havingTokenList);
        CPPUNIT_ASSERT (*sf1 != *having);
        CPPUNIT_ASSERT (csep.havingTokenList().size() == 1);                                                         
        
        // Order by                                                
	    erydbSelectExecutionPlan::OrderByColumnList orderByList;
	    ArithmeticColumn *o1 = new ArithmeticColumn(*ac);
	    o1->asc(false);
	    orderByList.push_back(o1);
        csep.orderByCols(orderByList);
        CPPUNIT_ASSERT(csep.orderByCols().size() == 1);        
        
        // another csep
        erydbSelectExecutionPlan *newcsep = new erydbSelectExecutionPlan(erydbSelectExecutionPlan::FROM);
        erydbSelectExecutionPlan::ReturnedColumnList ncolList;        
        SimpleColumn *newsc = new SimpleColumn("tpch.region.r_regionkey", 0);
        ncolList.push_back(newsc);        
        newcsep->returnedCols (ncolList);  
        erydbSelectExecutionPlan::FilterTokenList nfilterTokenList; 
        SimpleFilter *newsf = new SimpleFilter ( new Operator (">"),
                                    sc->clone(),
                                    newsc->clone());
        nfilterTokenList.push_back(newsf);
        newcsep->filterTokenList (nfilterTokenList);
        erydbSelectExecutionPlan::FilterTokenList nhavingTokenList;
        SimpleFilter *newhaving = new SimpleFilter ( new Operator (">"),
                                    sc->clone(),
                                    newsc->clone());  
        CPPUNIT_ASSERT (*newsf == *newhaving);                                    
        nhavingTokenList.push_back(newhaving);
        newcsep->havingTokenList (nhavingTokenList);
        CPPUNIT_ASSERT (*newcsep != csep); 
        CPPUNIT_ASSERT (*newcsep->filters() == *newcsep->having());
        ByteStream b;
        csep.serialize (b);
        newcsep->unserialize (b);
        CPPUNIT_ASSERT (csep == *newcsep);
        erydbSelectExecutionPlan::SelectList selectList;
        selectList.push_back(newcsep);
        csep.subSelects(selectList);        
        cout << "\nerydb Execution Plan:" << endl;
        cout << csep;
        cout << " --- end of test 1 ---" << endl;
    }