//---------------------------------------------------------------------------
//	@function:
//		CParseHandlerTableDescr::EndElement
//
//	@doc:
//		Invoked by Xerces to process a closing tag
//
//---------------------------------------------------------------------------
void
CParseHandlerTableDescr::EndElement
	(
	const XMLCh* const, // xmlszUri,
	const XMLCh* const xmlszLocalname,
	const XMLCh* const // xmlszQname
	)
{
	if(0 != XMLString::compareString(CDXLTokens::XmlstrToken(EdxltokenTableDescr), xmlszLocalname))
	{
		CWStringDynamic *pstr = CDXLUtils::PstrFromXMLCh(m_pphm->Pmm(), xmlszLocalname);
		GPOS_RAISE(gpdxl::ExmaDXL, gpdxl::ExmiDXLUnexpectedTag, pstr->Wsz());
	}
	
	// construct node from the created child nodes
	
	GPOS_ASSERT(1 == this->UlLength());
	
	// assemble the properties container from the cost
	CParseHandlerColDescr *pphColDescr = dynamic_cast<CParseHandlerColDescr *>((*this)[0]);
	
	GPOS_ASSERT(NULL != pphColDescr->Pdrgpdxlcd());
	
	DrgPdxlcd *pdrgpdxlcd = pphColDescr->Pdrgpdxlcd();
	pdrgpdxlcd->AddRef();
	m_pdxltabdesc->SetColumnDescriptors(pdrgpdxlcd);
			
	// deactivate handler
	m_pphm->DeactivateHandler();
}
//---------------------------------------------------------------------------
//	@function:
//		CParseHandlerLogicalCTAS::EndElement
//
//	@doc:
//		Invoked by Xerces to process a closing tag
//
//---------------------------------------------------------------------------
void
CParseHandlerLogicalCTAS::EndElement
	(
	const XMLCh* const, // xmlszUri,
	const XMLCh* const xmlszLocalname,
	const XMLCh* const // xmlszQname
	)
{
	if (0 != XMLString::compareString(CDXLTokens::XmlstrToken(EdxltokenLogicalCTAS), xmlszLocalname))
	{
		CWStringDynamic *pstr = CDXLUtils::PstrFromXMLCh(m_pphm->Pmm(), xmlszLocalname);
		GPOS_RAISE(gpdxl::ExmaDXL, gpdxl::ExmiDXLUnexpectedTag, pstr->Wsz());
	}

	GPOS_ASSERT(3 == this->UlLength());

	CParseHandlerColDescr *pphColDescr = dynamic_cast<CParseHandlerColDescr *>((*this)[0]);
	CParseHandlerCtasStorageOptions *pphCTASOptions = dynamic_cast<CParseHandlerCtasStorageOptions *>((*this)[1]);
	CParseHandlerLogicalOp *pphChild = dynamic_cast<CParseHandlerLogicalOp*>((*this)[2]);

	GPOS_ASSERT(NULL != pphColDescr->Pdrgpdxlcd());
	GPOS_ASSERT(NULL != pphCTASOptions->Pdxlctasopt());
	GPOS_ASSERT(NULL != pphChild->Pdxln());
	
	DrgPdxlcd *pdrgpdxlcd = pphColDescr->Pdrgpdxlcd();
	pdrgpdxlcd->AddRef();
	
	CDXLCtasStorageOptions *pdxlctasopt = pphCTASOptions->Pdxlctasopt();
	pdxlctasopt->AddRef();
	
	m_pdxln = GPOS_NEW(m_pmp) CDXLNode
							(
							m_pmp,
							GPOS_NEW(m_pmp) CDXLLogicalCTAS
										(
										m_pmp, 
										m_pmdid, 
										m_pmdnameSchema, 
										m_pmdname, 
										pdrgpdxlcd, 
										pdxlctasopt, 
										m_ereldistrpolicy, 
										m_pdrgpulDistr, 
										m_fTemporary, 
										m_fHasOids, 
										m_erelstorage, 
										m_pdrgpulSource,
										m_pdrgpiVarTypeMod
										)
							);
	
	AddChildFromParseHandler(pphChild);

#ifdef GPOS_DEBUG
	m_pdxln->Pdxlop()->AssertValid(m_pdxln, false /* fValidateChildren */);
#endif // GPOS_DEBUG

	// deactivate handler
	m_pphm->DeactivateHandler();
}
//---------------------------------------------------------------------------
//	@function:
//		CParseHandlerLogicalConstTable::EndElement
//
//	@doc:
//		Invoked by Xerces to process a closing tag
//
//---------------------------------------------------------------------------
void
CParseHandlerLogicalConstTable::EndElement
	(
	const XMLCh* const, // xmlszUri,
	const XMLCh* const xmlszLocalname,
	const XMLCh* const // xmlszQname
	)
{
	if (0 == XMLString::compareString(CDXLTokens::XmlstrToken(EdxltokenLogicalConstTable), xmlszLocalname))
	{
		GPOS_ASSERT(1 == this->UlLength());

		CParseHandlerColDescr *pphColDescr = dynamic_cast<CParseHandlerColDescr *>((*this)[0]);
		GPOS_ASSERT(NULL != pphColDescr->Pdrgpdxlcd());

		DrgPdxlcd *pdrgpdxlcd = pphColDescr->Pdrgpdxlcd();
		pdrgpdxlcd->AddRef();

		CDXLLogicalConstTable *pdxlopConstTable = GPOS_NEW(m_pmp) CDXLLogicalConstTable(m_pmp, pdrgpdxlcd, m_pdrgpdrgpdxldatum);
		m_pdxln = GPOS_NEW(m_pmp) CDXLNode(m_pmp, pdxlopConstTable);

#ifdef GPOS_DEBUG
	pdxlopConstTable->AssertValid(m_pdxln, false /* fValidateChildren */);
#endif // GPOS_DEBUG

		// deactivate handler
	  	m_pphm->DeactivateHandler();
	}
	else if (0 == XMLString::compareString(CDXLTokens::XmlstrToken(EdxltokenConstTuple), xmlszLocalname))
	{
		GPOS_ASSERT(NULL != m_pdrgpdxldatum);
		m_pdrgpdrgpdxldatum->Append(m_pdrgpdxldatum);

		m_pdrgpdxldatum = NULL; // intialize for the parsing the next const tuple (if needed)
	}
	else if (0 != XMLString::compareString(CDXLTokens::XmlstrToken(EdxltokenDatum), xmlszLocalname))
	{
		CWStringDynamic *pstr = CDXLUtils::PstrFromXMLCh(m_pphm->Pmm(), xmlszLocalname);
		GPOS_RAISE(gpdxl::ExmaDXL, gpdxl::ExmiDXLUnexpectedTag, pstr->Wsz());
	}
}