//--------------------------------------------------------------------------- // @function: // CParseHandlerTest::EresParseAndSerializePlan // // @doc: // Verifies that after parsing the given DXL file into a DXL tree, // it will be serialized back to the same string. // //--------------------------------------------------------------------------- GPOS_RESULT CParseHandlerTest::EresParseAndSerializePlan ( 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; const CHAR *szValidationPath = NULL; if (fValidate) { szValidationPath = CTestUtils::m_szXSDPath; } // the root of the parsed DXL tree ULLONG ullPlanId = ULLONG_MAX; ULLONG ullPlanSpaceSize = ULLONG_MAX; CDXLNode *pdxlnRoot = CDXLUtils::PdxlnParsePlan(pmp, szDXL, szValidationPath, &ullPlanId, &ullPlanSpaceSize); GPOS_CHECK_ABORT; oss << "Serializing parsed tree" << std::endl; CWStringDynamic strPlan(pmp); COstreamString osPlan(&strPlan); CDXLUtils::SerializePlan(pmp, osPlan, pdxlnRoot, ullPlanId, ullPlanSpaceSize, true /*fSerializeHeaderFooter*/, true /*fIndent*/); GPOS_CHECK_ABORT; CWStringDynamic dstrExpected(pmp); dstrExpected.AppendFormat(GPOS_WSZ_LIT("%s"), szDXL); if (!dstrExpected.FEquals(&strPlan)) { GPOS_TRACE(dstrExpected.Wsz()); GPOS_TRACE(strPlan.Wsz()); GPOS_ASSERT(!"Not matching"); } // cleanup pdxlnRoot->Release(); GPOS_DELETE_ARRAY(szDXL); return GPOS_OK; }
//--------------------------------------------------------------------------- // @function: // CParseHandlerTest::EresParseAndSerializePlan // // @doc: // Verifies that after parsing the given DXL file into a DXL tree, // it will be serialized back to the same string. // //--------------------------------------------------------------------------- GPOS_RESULT CParseHandlerTest::EresParseAndSerializePlan ( 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; const CHAR *szValidationPath = NULL; if (fValidate) { szValidationPath = CTestUtils::m_szXSDPath; } // the root of the parsed DXL tree ULLONG plan_id = gpos::ullong_max; ULLONG plan_space_size = gpos::ullong_max; CDXLNode *root_dxl_node = CDXLUtils::GetPlanDXLNode(mp, dxl_string, szValidationPath, &plan_id, &plan_space_size); GPOS_CHECK_ABORT; oss << "Serializing parsed tree" << std::endl; CWStringDynamic strPlan(mp); COstreamString osPlan(&strPlan); CDXLUtils::SerializePlan(mp, osPlan, root_dxl_node, plan_id, plan_space_size, true /*serialize_header_footer*/, true /*indentation*/); GPOS_CHECK_ABORT; CWStringDynamic dstrExpected(mp); dstrExpected.AppendFormat(GPOS_WSZ_LIT("%s"), dxl_string); if (!dstrExpected.Equals(&strPlan)) { GPOS_TRACE(dstrExpected.GetBuffer()); GPOS_TRACE(strPlan.GetBuffer()); GPOS_ASSERT(!"Not matching"); } // cleanup root_dxl_node->Release(); GPOS_DELETE_ARRAY(dxl_string); 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: // 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: // 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; }