Пример #1
0
  void DDLIndexPopulator::makeCsep(erydbSelectExecutionPlan&  csep)
  {

    csep.sessionID(fSessionID);

    csep.txnID(fTxnID);
    csep.verID(fSessionManager->verID());

    erydbSelectExecutionPlan::ReturnedColumnList colList;
    erydbSelectExecutionPlan::ColumnMap colMap;
 	erydbSystemCatalog::TableColName tableColName;
 	erydbSystemCatalog::OID oid;
 	tableColName.schema = fTable.fSchema;
 	tableColName.table = fTable.fName;
 	boost::shared_ptr<erydbSystemCatalog> csc = erydbSystemCatalog::makeerydbSystemCatalog( fSessionID );
    string tableName(fTable.fSchema + "." + fTable.fName + ".");

    ColumnNameList::const_iterator cend = fColNames.end();
    for (ColumnNameList::const_iterator cname = fColNames.begin(); cname != cend; ++cname)
    {
	string fullColName(tableName + *cname);
        SRCP srcp(new SimpleColumn (fullColName, fSessionID));
	colList.push_back(srcp);
	tableColName.column = *cname; 
	oid = csc->lookupOID( tableColName );
	fOidList.push_back( oid );
	colMap.insert(erydbSelectExecutionPlan::ColumnMap::value_type(fullColName, srcp));
    }
    csep.columnMap (colMap);
    csep.returnedCols (colList);
  }
Пример #2
0
bool Path::copy( const QString & src, const QString & dest )
{
	Path srcp( src ), destp( dest );
	if( !srcp.fileExists() || !destp.dir().dirExists() )
		return false;
#ifdef Q_OS_WIN
	bool s_unc = false, d_unc = false;
	
	QString srcw( srcp.path() );
	srcw = srcw.replace( "/", "\\" );
	QString destw( destp.path() );
	destw = destw.replace( "/", "\\" );
	
	if( srcw[0] == '\\' && srcw[1] == '\\' ) s_unc = true;
	if( destw[0] == '\\' && destw[1] == '\\' ) d_unc = true;
	srcw.replace( "\\\\", "\\" );
	if( s_unc ) srcw = "\\" + srcw;
	destw.replace( "\\\\", "\\" );
	if( d_unc ) destw = "\\" + destw;
	
	bool ret = CopyFileA( srcw.toLatin1(), destw.toLatin1(), false ) != 0;
	if( !ret ) {
		DWORD err = GetLastError();
		LOG_1( "Copy failed with error: " + QString::number(err) );
		LOG_1( "Src: " + srcw +  "Dest: " + destw );
	}
	return ret;
#else
	system( QString( "cp " + srcp.path() + " " + destp.path() ).toLatin1() );
	return true;
#endif
}
Пример #3
0
execplan::ReturnedColumn* buildPseudoColumn(Item* item,
                                            gp_walk_info& gwi,
                                            bool& nonSupport,
                                            uint32_t pseudoType)
{
	Item_func* ifp = (Item_func*)item;

	// idblocalpm is replaced by constant
	if (pseudoType == PSEUDO_LOCALPM)
	{
		int64_t localPm = idblocalpm();
		ConstantColumn* cc;
		if (localPm)
			cc = new ConstantColumn(localPm);
		else
			cc = new ConstantColumn("", ConstantColumn::NULLDATA);
		cc->alias(ifp->name? ifp->name : "");
		return cc;
	}

	// convert udf item to pseudocolumn item.
	// adjust result type
	// put arg col to column map
	string funcName = ifp->func_name();
	if (ifp->arg_count != 1 ||
	    !(ifp->arguments()) ||
	    !(ifp->arguments()[0]) ||
	    ifp->arguments()[0]->type() != Item::FIELD_ITEM)
		return nullOnError(gwi, funcName);

	Item_field* field = (Item_field*)(ifp->arguments()[0]);

	// @todo rule out derive table
	if (!field->field || !field->db_name || strlen(field->db_name) == 0)
		return nullOnError(gwi, funcName);

	SimpleColumn *sc = buildSimpleColumn(field, gwi);
	if (!sc)
		return nullOnError(gwi, funcName);

	if ((pseudoType == PSEUDO_EXTENTMIN || pseudoType == PSEUDO_EXTENTMAX) &&
	   (sc->colType().colDataType == CalpontSystemCatalog::VARBINARY ||
	   (sc->colType().colDataType == CalpontSystemCatalog::VARCHAR && sc->colType().colWidth > 7) ||
	   (sc->colType().colDataType == CalpontSystemCatalog::CHAR && sc->colType().colWidth > 8)))
		return nullOnError(gwi, funcName);

	// put arg col to column map
	if (gwi.clauseType == SELECT || gwi.clauseType == GROUP_BY) // select clause
	{
		SRCP srcp(sc);
		gwi.columnMap.insert(CalpontSelectExecutionPlan::ColumnMap::value_type(sc->columnName(), srcp));
		gwi.tableMap[make_aliastable(sc->schemaName(), sc->tableName(), sc->tableAlias(), sc->isInfiniDB())] =
		       make_pair(1, field->cached_table);
	}
	else if (!gwi.rcWorkStack.empty())
	{
		gwi.rcWorkStack.pop();
	}

	if (pseudoType == PSEUDO_PARTITION)
	{
		// parms: psueducolumn dbroot, segmentdir, segment
		SPTP sptp;
		FunctionColumn *fc = new FunctionColumn(funcName);
		funcexp::FunctionParm parms;
		PseudoColumn *dbroot = new PseudoColumn(*sc, PSEUDO_DBROOT);
		sptp.reset(new ParseTree(dbroot));
		parms.push_back(sptp);
		PseudoColumn *pp = new PseudoColumn(*sc, PSEUDO_SEGMENTDIR);
		sptp.reset(new ParseTree(pp));
		parms.push_back(sptp);
		PseudoColumn* seg = new PseudoColumn(*sc, PSEUDO_SEGMENT);
		sptp.reset(new ParseTree(seg));
		parms.push_back(sptp);
		fc->functionParms(parms);
		fc->expressionId(gwi.expressionId++);

		// string result type
		CalpontSystemCatalog::ColType ct;
		ct.colDataType = CalpontSystemCatalog::VARCHAR;
		ct.colWidth = 256;
		fc->resultType(ct);

		// operation type integer
		funcexp::Func_idbpartition* idbpartition = new funcexp::Func_idbpartition();
		fc->operationType(idbpartition->operationType(parms, fc->resultType()));
		fc->alias(ifp->name? ifp->name : "");
		return fc;
	}

	PseudoColumn *pc = new PseudoColumn(*sc, pseudoType);

	// @bug5892. set alias for derived table column matching.
	pc->alias(ifp->name? ifp->name : "");
	return pc;
}
Пример #4
0
ReturnedColumn* buildBoundExp(WF_Boundary& bound, SRCP& order, gp_walk_info& gwi)
{
	if (!(gwi.thd->infinidb_vtable.cal_conn_info))
		gwi.thd->infinidb_vtable.cal_conn_info = (void*)(new cal_connection_info());
	cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(gwi.thd->infinidb_vtable.cal_conn_info);

	bool addOp = true;
	ReturnedColumn* rc = NULL;
	if (bound.fFrame == execplan::WF_PRECEDING)
	{
		if (order->asc())
			addOp = false;
	}
	else if (!order->asc()) // must be WF_FOLLOWING
		addOp = false;

	funcexp::FunctionParm funcParms;
	SPTP sptp;
	IntervalColumn* intervalCol = dynamic_cast<IntervalColumn*>(bound.fVal.get());
	// @todo error out non constant. only support literal interval for now.
	if (!intervalCol && order->resultType().colDataType == CalpontSystemCatalog::DATE)
	{
		intervalCol = new IntervalColumn(bound.fVal, (int)IntervalColumn::INTERVAL_DAY);
		bound.fVal.reset(intervalCol);
	}

	if (intervalCol)
	{
		// date_add
		rc = new FunctionColumn();
		string funcName = "date_add_interval";
		
		// @bug6061 . YEAR, QUARTER, MONTH, WEEK, DAY type
		CalpontSystemCatalog::ColType ct;
		if (order->resultType().colDataType == CalpontSystemCatalog::DATE &&
		    intervalCol->intervalType() <= IntervalColumn::INTERVAL_DAY)
		{
			ct.colDataType = CalpontSystemCatalog::DATE;
			ct.colWidth = 4;
		}
		else
		{
			ct.colDataType = CalpontSystemCatalog::DATETIME;
			ct.colWidth = 8;
		}
		// put interval val column to bound
		(dynamic_cast<FunctionColumn*>(rc))->functionName(funcName);
		sptp.reset(new ParseTree(order->clone()));
		funcParms.push_back(sptp);
		sptp.reset(new ParseTree(intervalCol->val()->clone()));
		funcParms.push_back(sptp);
		funcParms.push_back(getIntervalType(intervalCol->intervalType()));
		SRCP srcp(intervalCol->val());
		bound.fVal = srcp;
		if (addOp)
		{
			sptp.reset(new ParseTree(new ConstantColumn("ADD")));
			funcParms.push_back(sptp);
		}
		else
		{
			sptp.reset(new ParseTree(new ConstantColumn("SUB")));
			funcParms.push_back(sptp);
		}
		(dynamic_cast<FunctionColumn*>(rc))->functionParms(funcParms);

		rc->resultType(ct);
		// @bug6061. Use result type as operation type for WF bound expression
		rc->operationType(ct);
		rc->expressionId(ci->expressionId++);
		return rc;
	}

	// arithmetic
	rc = new ArithmeticColumn();
	ArithmeticOperator* aop;
	if (addOp)
		aop = new ArithmeticOperator("+");
	else
		aop = new ArithmeticOperator("-");
	ParseTree *pt = new ParseTree(aop);
	ParseTree *lhs = 0, *rhs = 0;
	lhs = new ParseTree(order->clone());
	rhs = new ParseTree(bound.fVal->clone());
	pt->left(lhs);
	pt->right(rhs);
	aop->resultType(order->resultType());
	aop->operationType(aop->resultType());
	(dynamic_cast<ArithmeticColumn*>(rc))->expression(pt);
	rc->resultType(aop->resultType());
	rc->operationType(aop->operationType());
	rc->expressionId(ci->expressionId++);
	return rc;
}