//--------------------------------------------------------------------------- // @function: // CPredicateUtilsTest::EresUnittest_Disjunctions // // @doc: // Test extraction and construction of disjuncts // //--------------------------------------------------------------------------- GPOS_RESULT CPredicateUtilsTest::EresUnittest_Disjunctions() { 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); // install opt context in TLS CAutoOptCtxt aoc ( mp, &mda, NULL, /* pceeval */ CTestUtils::GetCostModel(mp) ); // build disjunction CExpressionArray *pdrgpexpr = GPOS_NEW(mp) CExpressionArray(mp); const ULONG ulDisjs = 3; for (ULONG ul = 0; ul < ulDisjs; ul++) { pdrgpexpr->Append(CUtils::PexprScalarConstBool(mp, false /*fValue*/)); } CExpression *pexprDisjunction = CUtils::PexprScalarBoolOp(mp, CScalarBoolOp::EboolopOr, pdrgpexpr); // break into disjuncts CExpressionArray *pdrgpexprExtract = CPredicateUtils::PdrgpexprDisjuncts(mp, pexprDisjunction); GPOS_ASSERT(pdrgpexprExtract->Size() == ulDisjs); // collapse into single disjunct CExpression *pexpr = CPredicateUtils::PexprDisjunction(mp, pdrgpexprExtract); GPOS_ASSERT(NULL != pexpr); GPOS_ASSERT(CUtils::FScalarConstFalse(pexpr)); pexpr->Release(); // collapse empty input array to disjunct CExpression *pexprSingleton = CPredicateUtils::PexprDisjunction(mp, NULL /*pdrgpexpr*/); GPOS_ASSERT(NULL != pexprSingleton); pexprSingleton->Release(); pexprDisjunction->Release(); // disjunction on scalar comparisons CExpression *pexprGet = CTestUtils::PexprLogicalGet(mp); CColRefSet *pcrs = CDrvdPropRelational::GetRelationalProperties(pexprGet->PdpDerive())->PcrsOutput(); CColRefSetIter crsi(*pcrs); #ifdef GPOS_DEBUG BOOL fAdvance = #endif crsi.Advance(); GPOS_ASSERT(fAdvance); CColRef *pcr1 = crsi.Pcr(); #ifdef GPOS_DEBUG fAdvance = #endif crsi.Advance(); GPOS_ASSERT(fAdvance); CColRef *pcr2 = crsi.Pcr(); #ifdef GPOS_DEBUG fAdvance = #endif crsi.Advance(); GPOS_ASSERT(fAdvance); CColRef *pcr3 = crsi.Pcr(); CExpression *pexprCmp1 = CUtils::PexprScalarCmp(mp, pcr1, pcr2, IMDType::EcmptEq); CExpression *pexprCmp2 = CUtils::PexprScalarCmp(mp, pcr1, CUtils::PexprScalarConstInt4(mp, 1 /*val*/), IMDType::EcmptEq); { CExpression *pexprDisj = CPredicateUtils::PexprDisjunction(mp, pexprCmp1, pexprCmp2); pdrgpexprExtract = CPredicateUtils::PdrgpexprDisjuncts(mp, pexprDisj); GPOS_ASSERT(2 == pdrgpexprExtract->Size()); pdrgpexprExtract->Release(); pexprDisj->Release(); } { CExpressionArray *pdrgpexpr = GPOS_NEW(mp) CExpressionArray(mp); CExpression *pexprCmp3 = CUtils::PexprScalarCmp(mp, pcr2, pcr1, IMDType::EcmptG); CExpression *pexprCmp4 = CUtils::PexprScalarCmp(mp, CUtils::PexprScalarConstInt4(mp, 200 /*val*/), pcr3, IMDType::EcmptL); pexprCmp1->AddRef(); pexprCmp2->AddRef(); pdrgpexpr->Append(pexprCmp3); pdrgpexpr->Append(pexprCmp4); pdrgpexpr->Append(pexprCmp1); pdrgpexpr->Append(pexprCmp2); CExpression *pexprDisj = CPredicateUtils::PexprDisjunction(mp, pdrgpexpr); pdrgpexprExtract = CPredicateUtils::PdrgpexprDisjuncts(mp, pexprDisj); GPOS_ASSERT(4 == pdrgpexprExtract->Size()); pdrgpexprExtract->Release(); pexprDisj->Release(); } pexprCmp1->Release(); pexprCmp2->Release(); pexprGet->Release(); return GPOS_OK; }
//--------------------------------------------------------------------------- // @function: // CColRefSetIterTest::EresUnittest_Basics // // @doc: // Testing ctors/dtor; and pcr decoding; // Other functionality already tested in vanilla CBitSetIter; // //--------------------------------------------------------------------------- GPOS_RESULT CColRefSetIterTest::EresUnittest_Basics() { CAutoMemoryPool amp; IMemoryPool *pmp = amp.Pmp(); // Setup an MD cache with a file-based provider CMDProviderMemory *pmdp = CTestUtils::m_pmdpf; pmdp->AddRef(); CMDAccessor mda(pmp, CMDCache::Pcache()); mda.RegisterProvider(CTestUtils::m_sysidDefault, pmdp); // install opt context in TLS CAutoOptCtxt aoc ( pmp, &mda, NULL /* pceeval */, CTestUtils::Pcm(pmp) ); // get column factory from optimizer context object CColumnFactory *pcf = COptCtxt::PoctxtFromTLS()->Pcf(); CColRefSet *pcrs = GPOS_NEW(pmp) CColRefSet(pmp); CWStringConst strName(GPOS_WSZ_LIT("Test Column")); CName name(&strName); // create a int4 datum const IMDTypeInt4 *pmdtypeint4 = mda.PtMDType<IMDTypeInt4>(); ULONG ulCols = 10; for(ULONG i = 0; i < ulCols; i++) { CColRef *pcr = pcf->PcrCreate(pmdtypeint4, name); pcrs->Include(pcr); GPOS_ASSERT(pcrs->FMember(pcr)); } GPOS_ASSERT(pcrs->CElements() == ulCols); ULONG ulCount = 0; CColRefSetIter crsi(*pcrs); while(crsi.FAdvance()) { GPOS_ASSERT((BOOL)crsi); CColRef *pcr = crsi.Pcr(); GPOS_ASSERT(pcr->Name().FEquals(name)); // to avoid unused variable warnings (void) pcr->UlId(); ulCount++; } GPOS_ASSERT(ulCols == ulCount); GPOS_ASSERT(!((BOOL)crsi)); pcrs->Release(); return GPOS_OK; }