//--------------------------------------------------------------------------- // @function: // CTreeMapTest::EresUnittest_Count // // @doc: // Count and debug output of all counts at various nodes // //--------------------------------------------------------------------------- GPOS_RESULT CTreeMapTest::EresUnittest_Count() { CAutoMemoryPool amp; IMemoryPool *pmp = amp.Pmp(); TestMap *ptmap = PtmapLoad(pmp); // debug print CWStringDynamic str(pmp); COstreamString oss(&str); ULLONG ullCount = ptmap->UllCount(); oss << "total number of trees: " << ullCount << std::endl; #ifdef GPOS_DEBUG for (ULONG ul = 0; ul < ulElems; ul++) { oss << "node: " << ul << " count: " << ptmap->UllCount(&rgul[ul]) << std::endl; } (void) ptmap->OsPrint(oss); #endif // GPOS_DEBUG GPOS_TRACE(str.Wsz()); GPOS_DELETE(ptmap); return GPOS_OK; }
//--------------------------------------------------------------------------- // @function: // CTreeMapTest::EresUnittest_Unrank // // @doc: // Rehydrate all trees encoded in the map // //--------------------------------------------------------------------------- GPOS_RESULT CTreeMapTest::EresUnittest_Unrank() { CAutoMemoryPool amp; IMemoryPool *pmp = amp.Pmp(); TestMap *ptmap = PtmapLoad(pmp); // debug print CWStringDynamic str(pmp); COstreamString oss(&str); ULLONG ullCount = ptmap->UllCount(); for (ULONG ulRank = 0; ulRank < ullCount; ulRank++) { oss << "=== tree rank: " << ulRank << " ===" << std::endl; BOOL fFlag = true; CNode *pnd = ptmap->PrUnrank(pmp, &fFlag, ulRank); (void) pnd->OsPrint(oss); pnd->Release(); } GPOS_TRACE(str.Wsz()); GPOS_DELETE(ptmap); return GPOS_OK; }
//--------------------------------------------------------------------------- // @function: // CTreeMapTest::EresUnittest_Basic // // @doc: // Basic test // //--------------------------------------------------------------------------- GPOS_RESULT CTreeMapTest::EresUnittest_Basic() { CAutoMemoryPool amp; IMemoryPool *pmp = amp.Pmp(); TestMap *ptmap = NULL; // create blank map ptmap = GPOS_NEW(pmp) TestMap(pmp, &Pnd); GPOS_ASSERT(0 == ptmap->UllCount()); GPOS_DELETE(ptmap); // create map with test data ptmap = PtmapLoad(pmp); GPOS_DELETE(ptmap); return GPOS_OK; }
//--------------------------------------------------------------------------- // @function: // CSearchStrategyTest::EresUnittest_ParsingWithException // // @doc: // Test exception handling when parsing cost params // //--------------------------------------------------------------------------- GPOS_RESULT CCostTest::EresUnittest_ParsingWithException() { CAutoMemoryPool amp; IMemoryPool *mp = amp.Pmp(); CParseHandlerDXL *pphDXL = CDXLUtils::GetParseHandlerForDXLFile(mp,"../data/dxl/cost/wrong-cost.xml", NULL); GPOS_DELETE(pphDXL); return GPOS_OK; }
//--------------------------------------------------------------------------- // @function: // CParseHandlerTest::EresParseAndSerializeMetadata // // @doc: // Verifies that after parsing the given DXL file containing metadata into // a list of metadata objects, which should be serialized back to the same string. // //--------------------------------------------------------------------------- GPOS_RESULT CParseHandlerTest::EresParseAndSerializeMetadata ( IMemoryPool *pmp, const CHAR *szDXLFileName, BOOL fValidate ) { CWStringDynamic str(pmp); COstreamString oss(&str); // read DXL file CHAR *szDXL = CDXLUtils::SzRead(pmp, szDXLFileName); GPOS_CHECK_ABORT; // parse the metadata objects into a dynamic array const CHAR *szValidationPath = NULL; if (fValidate) { szValidationPath = CTestUtils::m_szXSDPath; } DrgPimdobj *pdrgpmdobj = CDXLUtils::PdrgpmdobjParseDXL(pmp, szDXL, szValidationPath); GPOS_ASSERT(NULL != pdrgpmdobj); GPOS_CHECK_ABORT; oss << "Serializing metadata objects" << std::endl; CWStringDynamic *pstr = CDXLUtils::PstrSerializeMetadata(pmp, pdrgpmdobj, true /*fSerializeHeaderFooter*/, true /*fIndent*/); GPOS_CHECK_ABORT; CWStringDynamic dstrExpected(pmp); dstrExpected.AppendFormat(GPOS_WSZ_LIT("%s"), szDXL); if (!dstrExpected.FEquals(pstr)) { GPOS_TRACE(pstr->Wsz()); GPOS_ASSERT(false); } pdrgpmdobj->Release(); GPOS_DELETE(pstr); GPOS_DELETE_ARRAY(szDXL); return GPOS_OK; }
//--------------------------------------------------------------------------- // @function: // CParseHandlerTest::EresParseAndSerializeQuery // // @doc: // Verifies that after parsing the given DXL file into a DXL tree // representing a query, it will be serialized back to the same string. // //--------------------------------------------------------------------------- GPOS_RESULT CParseHandlerTest::EresParseAndSerializeQuery ( IMemoryPool *pmp, const CHAR *szDXLFileName, BOOL fValidate ) { CWStringDynamic str(pmp); COstreamString oss(&str); // read DXL file CHAR *szDXL = CDXLUtils::SzRead(pmp, szDXLFileName); const CHAR *szValidationPath = NULL; if (fValidate) { szValidationPath = CTestUtils::m_szXSDPath; } // the root of the parsed DXL tree CQueryToDXLResult *pq2dxlresult = CDXLUtils::PdxlnParseDXLQuery(pmp, szDXL, szValidationPath); GPOS_ASSERT(NULL != pq2dxlresult); oss << "Serializing parsed tree" << std::endl; CDXLNode *pdxlnRoot = const_cast<CDXLNode *>(pq2dxlresult->Pdxln()); DrgPdxln* pdrgpdxln = const_cast<DrgPdxln* >(pq2dxlresult->PdrgpdxlnOutputCols()); DrgPdxln* pdrgpdxlnCTE = const_cast<DrgPdxln* >(pq2dxlresult->PdrgpdxlnCTE()); CWStringDynamic wstrQuery(pmp); COstreamString osQuery(&wstrQuery); CDXLUtils::SerializeQuery(pmp, osQuery, pdxlnRoot, pdrgpdxln, pdrgpdxlnCTE, true /*fSerializeHeaderFooter*/, true /*fIndent*/); CWStringDynamic dstrExpected(pmp); dstrExpected.AppendFormat(GPOS_WSZ_LIT("%s"), szDXL); if (!dstrExpected.FEquals(&wstrQuery)) { GPOS_TRACE(wstrQuery.Wsz()); } // cleanup GPOS_DELETE(pq2dxlresult); GPOS_DELETE_ARRAY(szDXL); return GPOS_OK; }
//--------------------------------------------------------------------------- // @function: // CParseHandlerTest::EresParseAndSerializeMetadata // // @doc: // Verifies that after parsing the given DXL file containing metadata into // a list of metadata objects, which should be serialized back to the same string. // //--------------------------------------------------------------------------- GPOS_RESULT CParseHandlerTest::EresParseAndSerializeMetadata ( IMemoryPool *mp, const CHAR *dxl_filename, BOOL fValidate ) { CWStringDynamic str(mp); COstreamString oss(&str); // read DXL file CHAR *dxl_string = CDXLUtils::Read(mp, dxl_filename); GPOS_CHECK_ABORT; // parse the metadata objects into a dynamic array const CHAR *szValidationPath = NULL; if (fValidate) { szValidationPath = CTestUtils::m_szXSDPath; } IMDCacheObjectArray *mdcache_obj_array = CDXLUtils::ParseDXLToIMDObjectArray(mp, dxl_string, szValidationPath); GPOS_ASSERT(NULL != mdcache_obj_array); GPOS_CHECK_ABORT; oss << "Serializing metadata objects" << std::endl; CWStringDynamic *metadata_str = CDXLUtils::SerializeMetadata(mp, mdcache_obj_array, true /*serialize_header_footer*/, true /*indentation*/); GPOS_CHECK_ABORT; CWStringDynamic dstrExpected(mp); dstrExpected.AppendFormat(GPOS_WSZ_LIT("%s"), dxl_string); if (!dstrExpected.Equals(metadata_str)) { GPOS_TRACE(metadata_str->GetBuffer()); GPOS_ASSERT(false); } mdcache_obj_array->Release(); GPOS_DELETE(metadata_str); GPOS_DELETE_ARRAY(dxl_string); return GPOS_OK; }
//--------------------------------------------------------------------------- // @function: // CParseHandlerTest::EresParseAndSerializeQuery // // @doc: // Verifies that after parsing the given DXL file into a DXL tree // representing a query, it will be serialized back to the same string. // //--------------------------------------------------------------------------- GPOS_RESULT CParseHandlerTest::EresParseAndSerializeQuery ( IMemoryPool *mp, const CHAR *dxl_filename, BOOL fValidate ) { CWStringDynamic str(mp); COstreamString oss(&str); // read DXL file CHAR *dxl_string = CDXLUtils::Read(mp, dxl_filename); const CHAR *szValidationPath = NULL; if (fValidate) { szValidationPath = CTestUtils::m_szXSDPath; } // the root of the parsed DXL tree CQueryToDXLResult *pq2dxlresult = CDXLUtils::ParseQueryToQueryDXLTree(mp, dxl_string, szValidationPath); GPOS_ASSERT(NULL != pq2dxlresult); oss << "Serializing parsed tree" << std::endl; CDXLNode *root_dxlnode = const_cast<CDXLNode *>(pq2dxlresult->CreateDXLNode()); CDXLNodeArray* dxl_array = const_cast<CDXLNodeArray* >(pq2dxlresult->GetOutputColumnsDXLArray()); CDXLNodeArray* cte_producers = const_cast<CDXLNodeArray* >(pq2dxlresult->GetCTEProducerDXLArray()); CWStringDynamic wstrQuery(mp); COstreamString osQuery(&wstrQuery); CDXLUtils::SerializeQuery(mp, osQuery, root_dxlnode, dxl_array, cte_producers, true /*serialize_header_footer*/, true /*indentation*/); CWStringDynamic dstrExpected(mp); dstrExpected.AppendFormat(GPOS_WSZ_LIT("%s"), dxl_string); if (!dstrExpected.Equals(&wstrQuery)) { GPOS_TRACE(wstrQuery.GetBuffer()); } // cleanup GPOS_DELETE(pq2dxlresult); GPOS_DELETE_ARRAY(dxl_string); return GPOS_OK; }
//--------------------------------------------------------------------------- // @function: // CParseHandlerTest::EresParseAndSerializeScalarExpr // // @doc: // Parses a ScalarExpr and verifies that the serialization is identical // to the original input. // //--------------------------------------------------------------------------- GPOS_RESULT CParseHandlerTest::EresParseAndSerializeScalarExpr ( IMemoryPool *pmp, const CHAR *szDXLFileName, BOOL fValidate ) { // read DXL file CHAR *szDXL = CDXLUtils::SzRead(pmp, szDXLFileName); GPOS_CHECK_ABORT; const CHAR *szValidationPath = NULL; if (fValidate) { szValidationPath = CTestUtils::m_szXSDPath; } // the root of the parsed DXL tree CDXLNode *pdxlnRoot = CDXLUtils::PdxlnParseScalarExpr(pmp, szDXL, szValidationPath); GPOS_CHECK_ABORT; CWStringDynamic str(pmp); COstreamString oss(&str); oss << "Serializing parsed tree" << std::endl; CWStringDynamic *pstr = CDXLUtils::PstrSerializeScalarExpr(pmp, pdxlnRoot, true /*fSerializeHeaderFooter*/, true /*fIndent*/); GPOS_CHECK_ABORT; CWStringDynamic dstrExpected(pmp); dstrExpected.AppendFormat(GPOS_WSZ_LIT("%s"), szDXL); GPOS_RESULT eres = GPOS_OK; if (!dstrExpected.FEquals(pstr)) { GPOS_TRACE(dstrExpected.Wsz()); GPOS_TRACE(pstr->Wsz()); GPOS_ASSERT(!"Not matching"); eres = GPOS_FAILED; } // cleanup pdxlnRoot->Release(); GPOS_DELETE(pstr); GPOS_DELETE_ARRAY(szDXL); return eres; }
//--------------------------------------------------------------------------- // @function: // CParseHandlerTest::EresParseAndSerializeScalarExpr // // @doc: // Parses a ScalarExpr and verifies that the serialization is identical // to the original input. // //--------------------------------------------------------------------------- GPOS_RESULT CParseHandlerTest::EresParseAndSerializeScalarExpr ( IMemoryPool *mp, const CHAR *dxl_filename, BOOL fValidate ) { // read DXL file CHAR *dxl_string = CDXLUtils::Read(mp, dxl_filename); GPOS_CHECK_ABORT; const CHAR *szValidationPath = NULL; if (fValidate) { szValidationPath = CTestUtils::m_szXSDPath; } // the root of the parsed DXL tree CDXLNode *root_dxl_node = CDXLUtils::ParseDXLToScalarExprDXLNode(mp, dxl_string, szValidationPath); GPOS_CHECK_ABORT; CWStringDynamic str(mp); COstreamString oss(&str); oss << "Serializing parsed tree" << std::endl; CWStringDynamic *scalar_expr_str = CDXLUtils::SerializeScalarExpr(mp, root_dxl_node, true /*serialize_header_footer*/, true /*indentation*/); GPOS_CHECK_ABORT; CWStringDynamic dstrExpected(mp); dstrExpected.AppendFormat(GPOS_WSZ_LIT("%s"), dxl_string); GPOS_RESULT eres = GPOS_OK; if (!dstrExpected.Equals(scalar_expr_str)) { GPOS_TRACE(dstrExpected.GetBuffer()); GPOS_TRACE(scalar_expr_str->GetBuffer()); GPOS_ASSERT(!"Not matching"); eres = GPOS_FAILED; } // cleanup root_dxl_node->Release(); GPOS_DELETE(scalar_expr_str); GPOS_DELETE_ARRAY(dxl_string); return eres; }
//--------------------------------------------------------------------------- // @function: // CCostTest::EresUnittest_Parsing // // @doc: // Test parsing cost params from external file // //--------------------------------------------------------------------------- GPOS_RESULT CCostTest::EresUnittest_Parsing() { CAutoMemoryPool amp; IMemoryPool *mp = amp.Pmp(); CParseHandlerDXL *pphDXL = CDXLUtils::GetParseHandlerForDXLFile(mp,"../data/dxl/cost/cost0.xml", NULL); ICostModelParams *pcp = pphDXL->GetCostModelParams(); { CAutoTrace at(mp); at.Os() << " Parsed cost params: " << std::endl; pcp->OsPrint(at.Os()); } GPOS_DELETE(pphDXL); return GPOS_OK; }
//--------------------------------------------------------------------------- // @function: // CCostTest::EresUnittest_SetParams // // @doc: // Test of setting cost model params // //--------------------------------------------------------------------------- GPOS_RESULT CCostTest::EresUnittest_SetParams() { CAutoMemoryPool amp; IMemoryPool *mp = amp.Pmp(); // setup a file-based provider CMDProviderMemory *pmdp = CTestUtils::m_pmdpf; pmdp->AddRef(); CMDAccessor mda(mp, CMDCache::Pcache(), CTestUtils::m_sysidDefault, pmdp); ICostModel *pcm = GPOS_NEW(mp) CCostModelGPDB(mp, GPOPT_TEST_SEGMENTS); // install opt context in TLS CAutoOptCtxt aoc(mp, &mda, NULL, /* pceeval */ pcm); // generate in-equality join expression CExpression *pexprOuter = CTestUtils::PexprLogicalGet(mp); const CColRef *pcrOuter = CDrvdPropRelational::GetRelationalProperties(pexprOuter->PdpDerive())->PcrsOutput()->PcrAny(); CExpression *pexprInner = CTestUtils::PexprLogicalGet(mp); const CColRef *pcrInner = CDrvdPropRelational::GetRelationalProperties(pexprInner->PdpDerive())->PcrsOutput()->PcrAny(); CExpression *pexprPred = CUtils::PexprScalarCmp(mp, pcrOuter, pcrInner, IMDType::EcmptNEq); CExpression *pexpr = CUtils::PexprLogicalJoin<CLogicalInnerJoin>(mp, pexprOuter, pexprInner, pexprPred); // optimize in-equality join based on default cost model params CExpression *pexprPlan1 = NULL; { CEngine eng(mp); // generate query context CQueryContext *pqc = CTestUtils::PqcGenerate(mp, pexpr); // Initialize engine eng.Init(pqc, NULL /*search_stage_array*/); // optimize query eng.Optimize(); // extract plan pexprPlan1 = eng.PexprExtractPlan(); GPOS_ASSERT(NULL != pexprPlan1); GPOS_DELETE(pqc); } // change NLJ cost factor ICostModelParams::SCostParam *pcp = pcm->GetCostModelParams()->PcpLookup(CCostModelParamsGPDB::EcpNLJFactor); CDouble dNLJFactor = CDouble(2.0); CDouble dVal = pcp->Get() * dNLJFactor; pcm->GetCostModelParams()->SetParam(pcp->Id(), dVal, dVal - 0.5, dVal + 0.5); // optimize again after updating NLJ cost factor CExpression *pexprPlan2 = NULL; { CEngine eng(mp); // generate query context CQueryContext *pqc = CTestUtils::PqcGenerate(mp, pexpr); // Initialize engine eng.Init(pqc, NULL /*search_stage_array*/); // optimize query eng.Optimize(); // extract plan pexprPlan2 = eng.PexprExtractPlan(); GPOS_ASSERT(NULL != pexprPlan2); GPOS_DELETE(pqc); } { CAutoTrace at(mp); at.Os() << "\nPLAN1: \n" << *pexprPlan1; at.Os() << "\nNLJ Cost1: " << (*pexprPlan1)[0]->Cost(); at.Os() << "\n\nPLAN2: \n" << *pexprPlan2; at.Os() << "\nNLJ Cost2: " << (*pexprPlan2)[0]->Cost(); } GPOS_ASSERT((*pexprPlan2)[0]->Cost() >= (*pexprPlan1)[0]->Cost() * dNLJFactor && "expected NLJ cost in PLAN2 to be larger than NLJ cost in PLAN1"); // clean up pexpr->Release(); pexprPlan1->Release(); pexprPlan2->Release(); return GPOS_OK; }
//--------------------------------------------------------------------------- // @function: // CParseHandlerTest::EresParseAndSerializeStatistics // // @doc: // Verifies that after parsing the given DXL file containing statistics // into a list of statistics objects, which should be serialized back // to the same string. // //--------------------------------------------------------------------------- GPOS_RESULT CParseHandlerTest::EresParseAndSerializeStatistics ( IMemoryPool *pmp, const CHAR *szDXLFileName, BOOL fValidate ) { // setup a file-based provider CMDProviderMemory *pmdp = CTestUtils::m_pmdpf; pmdp->AddRef(); CMDAccessor mda(pmp, CMDCache::Pcache(), CTestUtils::m_sysidDefault, pmdp); // install opt context in TLS CAutoOptCtxt aoc ( pmp, &mda, NULL /* pceeval */, CTestUtils::Pcm(pmp) ); CWStringDynamic str(pmp); COstreamString oss(&str); // read DXL file CHAR *szDXL = CDXLUtils::SzRead(pmp, szDXLFileName); GPOS_CHECK_ABORT; // parse the metadata objects into a dynamic array const CHAR *szValidationPath = NULL; if (fValidate) { szValidationPath = CTestUtils::m_szXSDPath; } // parse the statistics objects DrgPdxlstatsderrel *pdrgpdxlstatsderrel = CDXLUtils::PdrgpdxlstatsderrelParseDXL(pmp, szDXL, szValidationPath); DrgPstats *pdrgpstat = CDXLUtils::PdrgpstatsTranslateStats ( pmp, &mda, pdrgpdxlstatsderrel ); pdrgpdxlstatsderrel->Release(); GPOS_ASSERT(NULL != pdrgpstat); CStatistics *pstats = (* pdrgpstat)[0]; GPOS_ASSERT(pstats); pstats->DRows(); oss << "Statistics:" << std::endl; CStatisticsTest::Print(pmp, pstats); GPOS_CHECK_ABORT; oss << "Serializing Statistics Objects" << std::endl; CWStringDynamic *pstr = CDXLUtils::PstrSerializeStatistics ( pmp, &mda, pdrgpstat, true /*fSerializeHeaderFooter*/, true /*fIndent*/ ); CWStringDynamic dstrExpected(pmp); dstrExpected.AppendFormat(GPOS_WSZ_LIT("%s"), szDXL); GPOS_ASSERT(dstrExpected.FEquals(pstr)); pdrgpstat->Release(); GPOS_DELETE_ARRAY(szDXL); GPOS_DELETE(pstr); return GPOS_OK; }
//--------------------------------------------------------------------------- // @function: // CTreeMapTest::EresUnittest_Memo // // @doc: // Test loading map from actual memo // //--------------------------------------------------------------------------- GPOS_RESULT CTreeMapTest::EresUnittest_Memo() { GPOS_SET_TRACE(EtraceDisablePrintMemoryLeak); CAutoMemoryPool amp; IMemoryPool *pmp = amp.Pmp(); // setup a file-based provider CMDProviderMemory *pmdp = CTestUtils::m_pmdpf; pmdp->AddRef(); CMDAccessor mda(pmp, CMDCache::Pcache(), CTestUtils::m_sysidDefault, pmdp); CEngine *peng = NULL; CExpression *pexpr = NULL; CQueryContext *pqc = NULL; CExpression *pexprPlan = NULL; { // install opt context in TLS CAutoOptCtxt aoc ( pmp, &mda, NULL, /* pceeval */ CTestUtils::Pcm(pmp) ); CAutoTraceFlag atf(EopttraceEnumeratePlans, true); peng = GPOS_NEW(pmp) CEngine(pmp); // generate join expression pexpr = CTestUtils::PexprLogicalJoin<CLogicalInnerJoin>(pmp); // generate query context pqc = CTestUtils::PqcGenerate(pmp, pexpr); // Initialize engine peng->Init(pqc, NULL /*pdrgpss*/); // optimize query peng->Optimize(); // extract plan pexprPlan = peng->PexprExtractPlan(); GPOS_ASSERT(NULL != pexprPlan); peng->Trace(); { CAutoTrace at(pmp); ULLONG ullCount = peng->Pmemotmap()->UllCount(); #ifdef GPOS_DEBUG // test resetting map and re-creating it peng->ResetTreeMap(); ULLONG ullCount2 = peng->Pmemotmap()->UllCount(); GPOS_ASSERT(ullCount == ullCount2); #endif // GPOS_DEBUG for (ULONG ulRank = 0; ulRank < ullCount; ulRank++) { CDrvdPropCtxtPlan *pdpctxtplan = GPOS_NEW(pmp) CDrvdPropCtxtPlan(pmp, false /*fUpdateCTEMap*/); CExpression *pexprAlt = NULL; GPOS_TRY { pexprAlt = peng->Pmemotmap()->PrUnrank(pmp, pdpctxtplan, ulRank); at.Os() << std::endl << "ALTERNATIVE ["<< ulRank <<"]:" << std::endl << *pexprAlt << std::endl; } GPOS_CATCH_EX(ex) { if (!GPOS_MATCH_EX(ex, gpopt::ExmaGPOPT, gpopt::ExmiUnsatisfiedRequiredProperties)) { GPOS_RETHROW(ex); } IErrorContext *perrctxt = CTask::PtskSelf()->Perrctxt(); at.Os() << perrctxt->WszMsg() << std::endl; GPOS_RESET_EX; } GPOS_CATCH_END; CRefCount::SafeRelease(pexprAlt); CRefCount::SafeRelease(pdpctxtplan); } } } // clean up CRefCount::SafeRelease(pexprPlan); GPOS_DELETE(pqc); CRefCount::SafeRelease(pexpr); GPOS_DELETE(peng); return GPOS_OK; }
//--------------------------------------------------------------------------- // @function: // CParseHandlerTest::EresParseAndSerializeStatistics // // @doc: // Verifies that after parsing the given DXL file containing statistics // into a list of statistics objects, which should be serialized back // to the same string. // //--------------------------------------------------------------------------- GPOS_RESULT CParseHandlerTest::EresParseAndSerializeStatistics ( IMemoryPool *mp, const CHAR *dxl_filename, BOOL fValidate ) { // setup a file-based provider CMDProviderMemory *pmdp = CTestUtils::m_pmdpf; pmdp->AddRef(); CMDAccessor mda(mp, CMDCache::Pcache(), CTestUtils::m_sysidDefault, pmdp); // install opt context in TLS CAutoOptCtxt aoc ( mp, &mda, NULL /* pceeval */, CTestUtils::GetCostModel(mp) ); CWStringDynamic str(mp); COstreamString oss(&str); // read DXL file CHAR *dxl_string = CDXLUtils::Read(mp, dxl_filename); GPOS_CHECK_ABORT; // parse the metadata objects into a dynamic array const CHAR *szValidationPath = NULL; if (fValidate) { szValidationPath = CTestUtils::m_szXSDPath; } // parse the statistics objects CDXLStatsDerivedRelationArray *dxl_derived_rel_stats_array = CDXLUtils::ParseDXLToStatsDerivedRelArray(mp, dxl_string, szValidationPath); CStatisticsArray *statistics_array = CDXLUtils::ParseDXLToOptimizerStatisticObjArray ( mp, &mda, dxl_derived_rel_stats_array ); dxl_derived_rel_stats_array->Release(); GPOS_ASSERT(NULL != statistics_array); CStatistics *stats = (* statistics_array)[0]; GPOS_ASSERT(stats); stats->Rows(); oss << "Statistics:" << std::endl; CCardinalityTestUtils::PrintStats(mp, stats); GPOS_CHECK_ABORT; oss << "Serializing Statistics Objects" << std::endl; CWStringDynamic *statistics_str = CDXLUtils::SerializeStatistics ( mp, &mda, statistics_array, true /*serialize_header_footer*/, true /*indentation*/ ); CWStringDynamic dstrExpected(mp); dstrExpected.AppendFormat(GPOS_WSZ_LIT("%s"), dxl_string); GPOS_ASSERT(dstrExpected.Equals(statistics_str)); statistics_array->Release(); GPOS_DELETE_ARRAY(dxl_string); GPOS_DELETE(statistics_str); return GPOS_OK; }