예제 #1
0
//---------------------------------------------------------------------------
//	@function:
//		CDXLLogicalProject::AssertValid
//
//	@doc:
//		Checks whether operator node is well-structured
//
//---------------------------------------------------------------------------
void
CDXLLogicalProject::AssertValid
	(
	const CDXLNode *pdxln,
	BOOL fValidateChildren
	) const
{
	GPOS_ASSERT(2 == pdxln->UlArity());

	CDXLNode *pdxlnProjList = (*pdxln)[0];
	CDXLNode *pdxlnChild = (*pdxln)[1];

	GPOS_ASSERT(EdxlopScalarProjectList == pdxlnProjList->Pdxlop()->Edxlop());
	GPOS_ASSERT(EdxloptypeLogical == pdxlnChild->Pdxlop()->Edxloperatortype());
	
	if (fValidateChildren)
	{
		pdxlnProjList->Pdxlop()->AssertValid(pdxlnProjList, fValidateChildren);
		pdxlnChild->Pdxlop()->AssertValid(pdxlnChild, fValidateChildren);		
	}

	const ULONG ulArity = pdxlnProjList->UlArity();
	for (ULONG ul = 0; ul < ulArity; ++ul)
	{
		CDXLNode *pdxlnPrEl = (*pdxlnProjList)[ul];
		GPOS_ASSERT(EdxlopScalarIdent != pdxlnPrEl->Pdxlop()->Edxlop());
	}
}
예제 #2
0
//---------------------------------------------------------------------------
//	@function:
//		CDXLPhysicalSort::AssertValid
//
//	@doc:
//		Checks whether operator node is well-structured 
//
//---------------------------------------------------------------------------
void
CDXLPhysicalSort::AssertValid
	(
	const CDXLNode *pdxln,
	BOOL fValidateChildren
	) const
{
	// assert proj list and filter are valid
	CDXLPhysical::AssertValid(pdxln, fValidateChildren);
	
	GPOS_ASSERT(EdxlsortIndexSentinel == pdxln->UlArity());
	
	CDXLNode *pdxlnSortColList = (*pdxln)[EdxlsortIndexSortColList];
	CDXLNode *pdxlnChild = (*pdxln)[EdxlsortIndexChild];
	CDXLNode *pdxlnLimitCount = (*pdxln)[EdxlsortIndexLimitCount];
	CDXLNode *pdxlnLimitOffset = (*pdxln)[EdxlsortIndexLimitOffset];
	
	// assert children are of right type (physical/scalar)
	GPOS_ASSERT(EdxloptypeScalar == pdxlnSortColList->Pdxlop()->Edxloperatortype());
	GPOS_ASSERT(EdxloptypePhysical == pdxlnChild->Pdxlop()->Edxloperatortype());
	GPOS_ASSERT(EdxlopScalarLimitCount == pdxlnLimitCount->Pdxlop()->Edxlop());
	GPOS_ASSERT(EdxlopScalarLimitOffset == pdxlnLimitOffset->Pdxlop()->Edxlop());
	
	// there must be at least one sorting column
	GPOS_ASSERT(pdxlnSortColList->UlArity() > 0);
	
	if (fValidateChildren)
	{
		pdxlnSortColList->Pdxlop()->AssertValid(pdxlnSortColList, fValidateChildren);
		pdxlnChild->Pdxlop()->AssertValid(pdxlnChild, fValidateChildren);
	}
}
예제 #3
0
//---------------------------------------------------------------------------
//	@function:
//		CTranslatorDXLToQuery::TranslateProjList
//
//	@doc:
//		Translates a DXL projection list
//
//---------------------------------------------------------------------------
void
CTranslatorDXLToQuery::TranslateProjList
	(
	const CDXLNode *pdxlnPrL,
	CStateDXLToQuery *pstatedxltoquery,
	CMappingColIdVarQuery *pmapcidvarquery,
	ULONG ulTargetEntryIndex
	)
{
	if (NULL != pdxlnPrL)
	{
		// translate each DXL project element into a target entry
		const ULONG ulArity = pdxlnPrL->UlArity();
		for (ULONG ul = 0; ul < ulArity; ++ul)
		{
			CDXLNode *pdxlnPrEl = (*pdxlnPrL)[ul];
			CDXLScalarProjElem *pdxlopPrEl = CDXLScalarProjElem::PdxlopConvert(pdxlnPrEl->Pdxlop());

			GPOS_ASSERT(1 == pdxlnPrEl->UlArity());
			// translate proj element expression
			CDXLNode *pdxlnExpr = (*pdxlnPrEl)[0];

			Expr *pexpr = m_pdxlsctranslator->PexprFromDXLNodeScalar(pdxlnExpr, pmapcidvarquery);

			GPOS_ASSERT(NULL != pexpr);

			TargetEntry *pte = MakeNode(TargetEntry);
			pte->expr = pexpr;
			pte->resname = CTranslatorUtils::SzFromWsz(pdxlopPrEl->PmdnameAlias()->Pstr()->Wsz());
			pte->resno = (AttrNumber) (ulTargetEntryIndex + ul + 1);

			pstatedxltoquery->AddOutputColumnEntry(pte, pte->resname, pdxlopPrEl->UlId());
			//save mapping col id -> Var in the query translation context
			pmapcidvarquery->FInsertMapping(pdxlopPrEl->UlId(), pte);
		}
	}
}
예제 #4
0
//---------------------------------------------------------------------------
//	@function:
//		CTranslatorDXLToQuery::TranslateLimit
//
//	@doc:
//		Translate a logical limit operator
//
//---------------------------------------------------------------------------
void
CTranslatorDXLToQuery::TranslateLimit
	(
	const CDXLNode *pdxln,
	Query *pquery,
	CStateDXLToQuery *pstatedxltoquery,
	CMappingColIdVarQuery *pmapcidvarquery
	)
{
	List *plSortCl = NIL;

	GPOS_ASSERT(4 == pdxln->UlArity());

	// get children
	CDXLNode *pdxlnSortColList = (*pdxln)[0];
	CDXLNode *pdxlnLimitCount = (*pdxln)[1];
	CDXLNode *pdxlnLimitOffset = (*pdxln)[2];
	CDXLNode *pdxlnChild = (*pdxln)[3];

	// translate child node
	TranslateLogicalOp(pdxlnChild, pquery, pstatedxltoquery, pmapcidvarquery);

	// translate sorting column lists
	const ULONG ulNumSortCols = pdxlnSortColList->UlArity();
	if (0 < ulNumSortCols)
	{
		for (ULONG ul = 0; ul < ulNumSortCols; ul++)
		{
			CDXLNode *pdxlnSortCol = (*pdxlnSortColList)[ul];
			CDXLScalarSortCol *pdxlopSortCol = CDXLScalarSortCol::PdxlopConvert(pdxlnSortCol->Pdxlop());

			// get the target entry and the set the sortgroupref
			ULONG ulSortColId = pdxlopSortCol->UlColId();
			TargetEntry *pte = const_cast<TargetEntry *>(pmapcidvarquery->Pte(ulSortColId));
			GPOS_ASSERT(NULL != pte);

			// create the sort clause
			SortClause *psortcl = MakeNode(SortClause);
			psortcl->sortop = CMDIdGPDB::PmdidConvert(pdxlopSortCol->PmdidSortOp())->OidObjectId();
			plSortCl = gpdb::PlAppendElement(plSortCl, psortcl);

			// If ressortgroupref is not set then this column
			// was not used as a grouping column.
			if(0 == pte->ressortgroupref)
			{
				m_ulSortgrouprefCounter++;
				pte->ressortgroupref = m_ulSortgrouprefCounter;
			}

			psortcl->tleSortGroupRef = pte->ressortgroupref;

			if(!pstatedxltoquery->FTEFound(pte))
			{
				pstatedxltoquery->AddOutputColumnEntry(pte, pte->resname, ulSortColId);
			}
		}
	}

	GPOS_ASSERT(NULL != pdxlnLimitCount && NULL != pdxlnLimitOffset);

	// translate the limit count and offset;
	if(pdxlnLimitCount->UlArity() >0)
	{
		Expr *pexprCount = m_pdxlsctranslator->PexprFromDXLNodeScalar
												(
												(*pdxlnLimitCount)[0],
												pmapcidvarquery
												);

		pquery->limitCount = (Node *) pexprCount;
	}

	if(pdxlnLimitOffset->UlArity() >0)
	{
		Expr *pexprOffset = m_pdxlsctranslator->PexprFromDXLNodeScalar
												(
												(*pdxlnLimitOffset)[0],
												pmapcidvarquery
												);

		pquery->limitOffset = (Node *) pexprOffset;
	}

	pquery->sortClause = plSortCl;
}