Esempio n. 1
0
//---------------------------------------------------------------------------
//	@function:
//		CColumnFactory::PcrCopy
//
//	@doc:
//		Create a copy of the given colref
//
//---------------------------------------------------------------------------
CColRef *
CColumnFactory::PcrCopy
	(
	const CColRef* pcr
	)
{
	CName name(pcr->Name());
	if (CColRef::EcrtComputed == pcr->Ecrt())
	{
		return PcrCreate(pcr->Pmdtype(), name);
	}

	GPOS_ASSERT(CColRef::EcrtTable == pcr->Ecrt());
	ULONG ulId = m_aul.TIncr();
	CColRefTable *pcrTable = CColRefTable::PcrConvert(const_cast<CColRef*>(pcr));

	return PcrCreate
			(
			pcr->Pmdtype(),
			pcrTable->IAttno(),
			pcrTable->FNullable(),
			ulId,
			name,
			pcrTable->UlSourceOpId(),
			pcrTable->UlWidth()
			);
}
//---------------------------------------------------------------------------
//	@function:
//		CLogicalConstTableGet::PdrgpcoldescMapping
//
//	@doc:
//		Construct column descriptors from column references
//
//---------------------------------------------------------------------------
DrgPcoldesc *
CLogicalConstTableGet::PdrgpcoldescMapping
	(
	IMemoryPool *pmp,
	DrgPcr *pdrgpcr
	)
	const
{
	GPOS_ASSERT(NULL != pdrgpcr);
	DrgPcoldesc *pdrgpcoldesc = GPOS_NEW(pmp) DrgPcoldesc(pmp);

	const ULONG ulLen = pdrgpcr->UlLength();
	for (ULONG ul = 0; ul < ulLen; ul++)
	{
		CColRef *pcr = (*pdrgpcr)[ul];

		ULONG ulLength = ULONG_MAX;
		if (CColRef::EcrtTable == pcr->Ecrt())
		{
			CColRefTable *pcrTable = CColRefTable::PcrConvert(pcr);
			ulLength = pcrTable->UlWidth();
		}

		CColumnDescriptor *pcoldesc = GPOS_NEW(pmp) CColumnDescriptor
													(
													pmp,
													pcr->Pmdtype(),
													pcr->Name(),
													ul + 1, //iAttno
													true, // FNullable
													ulLength
													);
		pdrgpcoldesc->Append(pcoldesc);
	}

	return pdrgpcoldesc;
}