greenplumn CDistributionSpecTest 源码

  • 2022-08-18
  • 浏览 (65)

greenplumn CDistributionSpecTest 代码

文件路径:/src/backend/gporca/server/src/unittest/gpopt/base/CDistributionSpecTest.cpp

//---------------------------------------------------------------------------
//	Greenplum Database
//	Copyright (C) 2011 EMC Corp.
//
//	@filename:
//		CDistributionSpecTest.cpp
//
//	@doc:
//		Tests for distribution specification
//---------------------------------------------------------------------------

#include "unittest/gpopt/base/CDistributionSpecTest.h"

#include "gpos/error/CAutoTrace.h"

#include "gpopt/base/CColRefSet.h"
#include "gpopt/base/CColumnFactory.h"
#include "gpopt/base/CDistributionSpecAny.h"
#include "gpopt/base/CDistributionSpecHashed.h"
#include "gpopt/base/CDistributionSpecRandom.h"
#include "gpopt/base/CDistributionSpecReplicated.h"
#include "gpopt/base/CDistributionSpecSingleton.h"
#include "gpopt/base/CDistributionSpecUniversal.h"
#include "gpopt/eval/CConstExprEvaluatorDefault.h"
#include "gpopt/mdcache/CMDAccessor.h"
#include "gpopt/mdcache/CMDCache.h"
#include "gpopt/metadata/CName.h"
#include "gpopt/operators/CExpressionHandle.h"
#include "naucrates/md/CMDProviderMemory.h"
#include "naucrates/md/IMDTypeInt4.h"

#include "unittest/base.h"
#include "unittest/gpopt/CTestUtils.h"


const CHAR *szMDFileName = "../data/dxl/metadata/md.xml";

//---------------------------------------------------------------------------
//	@function:
//		CDistributionSpecTest::EresUnittest
//
//	@doc:
//		Unittest for distribution spec classes
//
//---------------------------------------------------------------------------
GPOS_RESULT
CDistributionSpecTest::EresUnittest()
{
	CUnittest rgut[] = {
		GPOS_UNITTEST_FUNC(CDistributionSpecTest::EresUnittest_Any),
		GPOS_UNITTEST_FUNC(CDistributionSpecTest::EresUnittest_Singleton),
		GPOS_UNITTEST_FUNC(CDistributionSpecTest::EresUnittest_Random),
		GPOS_UNITTEST_FUNC(CDistributionSpecTest::EresUnittest_Replicated),
		GPOS_UNITTEST_FUNC(CDistributionSpecTest::EresUnittest_Universal),
		GPOS_UNITTEST_FUNC(CDistributionSpecTest::EresUnittest_Hashed),
#ifdef GPOS_DEBUG
		GPOS_UNITTEST_FUNC_ASSERT(
			CDistributionSpecTest::EresUnittest_NegativeAny),
		GPOS_UNITTEST_FUNC_ASSERT(
			CDistributionSpecTest::EresUnittest_NegativeUniversal),
		GPOS_UNITTEST_FUNC_ASSERT(
			CDistributionSpecTest::EresUnittest_NegativeRandom),
#endif	// GPOS_DEBUG
	};

	return CUnittest::EresExecute(rgut, GPOS_ARRAY_SIZE(rgut));
}

//---------------------------------------------------------------------------
//	@function:
//		CDistributionSpecTest::EresUnittest_Any
//
//	@doc:
//		Test for "any" distribution spec
//
//---------------------------------------------------------------------------
GPOS_RESULT
CDistributionSpecTest::EresUnittest_Any()
{
	CAutoMemoryPool amp;
	CMemoryPool *mp = amp.Pmp();

	// any distribution
	CDistributionSpecAny *pdsany =
		GPOS_NEW(mp) CDistributionSpecAny(COperator::EopSentinel);

	GPOS_ASSERT(pdsany->FSatisfies(pdsany));
	GPOS_ASSERT(pdsany->Matches(pdsany));

	CAutoTrace at(mp);
	at.Os() << std::endl;
	at.Os() << *pdsany << std::endl;

	pdsany->Release();

	return GPOS_OK;
}

//---------------------------------------------------------------------------
//	@function:
//		CDistributionSpecTest::EresUnittest_Random
//
//	@doc:
//		Test for forced random distribution spec
//
//---------------------------------------------------------------------------
GPOS_RESULT
CDistributionSpecTest::EresUnittest_Random()
{
	CAutoMemoryPool amp;
	CMemoryPool *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, nullptr /*pceeval*/,
					 CTestUtils::GetCostModel(mp));
	COptCtxt *poptctxt = COptCtxt::PoctxtFromTLS();

	// basic tests with random distribution
	poptctxt->MarkDMLQuery(true /*fDMLQuery*/);
	CDistributionSpecRandom *pdsRandomDuplicateSensitive =
		GPOS_NEW(mp) CDistributionSpecRandom();

	poptctxt->MarkDMLQuery(false /*fDMLQuery*/);
	CDistributionSpecRandom *pdsRandomNonDuplicateSensitive =
		GPOS_NEW(mp) CDistributionSpecRandom();

	GPOS_ASSERT(
		pdsRandomDuplicateSensitive->FSatisfies(pdsRandomDuplicateSensitive));
	GPOS_ASSERT(
		pdsRandomDuplicateSensitive->Matches(pdsRandomDuplicateSensitive));
	GPOS_ASSERT(pdsRandomDuplicateSensitive->FSatisfies(
		pdsRandomNonDuplicateSensitive));
	GPOS_ASSERT(!pdsRandomNonDuplicateSensitive->FSatisfies(
		pdsRandomDuplicateSensitive));

	// random and universal
	CDistributionSpecUniversal *pdsUniversal =
		GPOS_NEW(mp) CDistributionSpecUniversal();
	GPOS_ASSERT(pdsUniversal->FSatisfies(pdsRandomNonDuplicateSensitive));
	GPOS_ASSERT(!pdsUniversal->FSatisfies(pdsRandomDuplicateSensitive));

	// random and any
	CDistributionSpecAny *pdsany =
		GPOS_NEW(mp) CDistributionSpecAny(COperator::EopSentinel);

	GPOS_ASSERT(!pdsany->FSatisfies(pdsRandomDuplicateSensitive));
	GPOS_ASSERT(pdsRandomDuplicateSensitive->FSatisfies(pdsany));

	CAutoTrace at(mp);
	at.Os() << std::endl;
	at.Os() << *pdsRandomDuplicateSensitive << std::endl;

	pdsRandomDuplicateSensitive->Release();
	pdsRandomNonDuplicateSensitive->Release();
	pdsUniversal->Release();
	pdsany->Release();

	return GPOS_OK;
}

//---------------------------------------------------------------------------
//	@function:
//		CDistributionSpecTest::EresUnittest_Replicated
//
//	@doc:
//		Test for replicated distribution spec
//
//---------------------------------------------------------------------------
GPOS_RESULT
CDistributionSpecTest::EresUnittest_Replicated()
{
	CAutoMemoryPool amp;
	CMemoryPool *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, nullptr /*pceeval*/,
					 CTestUtils::GetCostModel(mp));

	// basic tests with replicated distributions
	CDistributionSpecReplicated *pdsreplicated = GPOS_NEW(mp)
		CDistributionSpecReplicated(CDistributionSpec::EdtStrictReplicated);

	GPOS_ASSERT(pdsreplicated->FSatisfies(pdsreplicated));
	GPOS_ASSERT(pdsreplicated->Matches(pdsreplicated));

	// replicated and random
	CDistributionSpecRandom *pdsrandom = GPOS_NEW(mp) CDistributionSpecRandom();

	GPOS_ASSERT(!pdsrandom->FSatisfies(pdsreplicated));
	GPOS_ASSERT(pdsreplicated->FSatisfies(pdsrandom));

	// replicated and any
	CDistributionSpecAny *pdsany =
		GPOS_NEW(mp) CDistributionSpecAny(COperator::EopSentinel);

	GPOS_ASSERT(!pdsany->FSatisfies(pdsreplicated));
	GPOS_ASSERT(pdsreplicated->FSatisfies(pdsany));

	CAutoTrace at(mp);
	at.Os() << std::endl;
	at.Os() << *pdsreplicated << std::endl;

	pdsreplicated->Release();
	pdsrandom->Release();
	pdsany->Release();

	return GPOS_OK;
}

//---------------------------------------------------------------------------
//	@function:
//		CDistributionSpecTest::EresUnittest_Singleton
//
//	@doc:
//		Test for singleton distribution spec
//
//---------------------------------------------------------------------------
GPOS_RESULT
CDistributionSpecTest::EresUnittest_Singleton()
{
	CAutoMemoryPool amp;
	CMemoryPool *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, nullptr /*pceeval*/,
					 CTestUtils::GetCostModel(mp));

	// basic tests with singleton distributions
	CDistributionSpecSingleton *pdssSegment = GPOS_NEW(mp)
		CDistributionSpecSingleton(CDistributionSpecSingleton::EstSegment);
	CDistributionSpecSingleton *pdssMaster = GPOS_NEW(mp)
		CDistributionSpecSingleton(CDistributionSpecSingleton::EstMaster);

	GPOS_ASSERT(pdssMaster->FSatisfies(pdssMaster));
	GPOS_ASSERT(pdssMaster->Matches(pdssMaster));

	GPOS_ASSERT(pdssSegment->FSatisfies(pdssSegment));
	GPOS_ASSERT(pdssSegment->Matches(pdssSegment));

	GPOS_ASSERT(!pdssMaster->FSatisfies(pdssSegment) &&
				!pdssSegment->FSatisfies(pdssMaster));

	// singleton and replicated
	CDistributionSpecReplicated *pdsreplicated = GPOS_NEW(mp)
		CDistributionSpecReplicated(CDistributionSpec::EdtStrictReplicated);

	GPOS_ASSERT(pdsreplicated->FSatisfies(pdssSegment));
	GPOS_ASSERT(!pdsreplicated->FSatisfies(pdssMaster));

	GPOS_ASSERT(!pdssSegment->FSatisfies(pdsreplicated));

	// singleton and random
	CDistributionSpecRandom *pdsrandom = GPOS_NEW(mp) CDistributionSpecRandom();

	GPOS_ASSERT(!pdsrandom->FSatisfies(pdssSegment));
	GPOS_ASSERT(!pdsrandom->FSatisfies(pdssMaster));
	GPOS_ASSERT(!pdssSegment->FSatisfies(pdsrandom));
	GPOS_ASSERT(!pdssMaster->FSatisfies(pdsrandom));

	// singleton and any
	CDistributionSpecAny *pdsany =
		GPOS_NEW(mp) CDistributionSpecAny(COperator::EopSentinel);

	GPOS_ASSERT(!pdsany->FSatisfies(pdssSegment));
	GPOS_ASSERT(pdssSegment->FSatisfies(pdsany));

	CAutoTrace at(mp);
	at.Os() << std::endl;
	at.Os() << *pdssMaster << std::endl;
	at.Os() << *pdssSegment << std::endl;

	pdssMaster->Release();
	pdssSegment->Release();
	pdsreplicated->Release();
	pdsrandom->Release();
	pdsany->Release();

	return GPOS_OK;
}

//---------------------------------------------------------------------------
//	@function:
//		CDistributionSpecTest::EresUnittest_Universal
//
//	@doc:
//		Test for universal distribution spec
//
//---------------------------------------------------------------------------
GPOS_RESULT
CDistributionSpecTest::EresUnittest_Universal()
{
	CAutoMemoryPool amp;
	CMemoryPool *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, nullptr /*pceeval*/,
					 CTestUtils::GetCostModel(mp));

	// basic tests with universal distributions
	CDistributionSpecUniversal *pdsuniversal =
		GPOS_NEW(mp) CDistributionSpecUniversal();

	GPOS_ASSERT(pdsuniversal->FSatisfies(pdsuniversal));
	GPOS_ASSERT(pdsuniversal->Matches(pdsuniversal));

	// universal and singleton
	CDistributionSpecSingleton *pdssSegment = GPOS_NEW(mp)
		CDistributionSpecSingleton(CDistributionSpecSingleton::EstSegment);

	GPOS_ASSERT(pdsuniversal->FSatisfies(pdssSegment));

	// universal and replicated
	CDistributionSpecReplicated *pdsreplicated = GPOS_NEW(mp)
		CDistributionSpecReplicated(CDistributionSpec::EdtStrictReplicated);

	GPOS_ASSERT(pdsuniversal->FSatisfies(pdsreplicated));

	// universal and random
	CDistributionSpecRandom *pdsrandom = GPOS_NEW(mp) CDistributionSpecRandom();

	GPOS_ASSERT(pdsuniversal->FSatisfies(pdsrandom));

	// universal and any
	CDistributionSpecAny *pdsany =
		GPOS_NEW(mp) CDistributionSpecAny(COperator::EopSentinel);

	GPOS_ASSERT(pdsuniversal->FSatisfies(pdsany));

	CAutoTrace at(mp);
	at.Os() << std::endl;
	at.Os() << *pdsuniversal << std::endl;

	pdsuniversal->Release();
	pdssSegment->Release();
	pdsreplicated->Release();
	pdsrandom->Release();
	pdsany->Release();

	return GPOS_OK;
}

//---------------------------------------------------------------------------
//	@function:
//		CDistributionSpecTest::EresUnittest_Hashed
//
//	@doc:
//		Test for hashed distribution spec
//
//---------------------------------------------------------------------------
GPOS_RESULT
CDistributionSpecTest::EresUnittest_Hashed()
{
	CAutoMemoryPool amp;
	CMemoryPool *mp = amp.Pmp();

	CMDProviderMemory *pmdp = CTestUtils::m_pmdpf;
	pmdp->AddRef();
	CMDAccessor mda(mp, CMDCache::Pcache(), CTestUtils::m_sysidDefault, pmdp);

	// install opt context
	CAutoOptCtxt aoc(mp, &mda, nullptr, /* pceeval */
					 CTestUtils::GetCostModel(mp));

	// get column factory from optimizer context object
	COptCtxt *poptctxt = COptCtxt::PoctxtFromTLS();
	CColumnFactory *col_factory = poptctxt->Pcf();

	CWStringConst strA(GPOS_WSZ_LIT("A"));
	CWStringConst strB(GPOS_WSZ_LIT("B"));

	CName nameA(&strA);
	CName nameB(&strB);

	const IMDTypeInt4 *pmdtypeint4 =
		mda.PtMDType<IMDTypeInt4>(CTestUtils::m_sysidDefault);

	CColRef *pcrA =
		col_factory->PcrCreate(pmdtypeint4, default_type_modifier, nameA);
	CColRef *pcrB =
		col_factory->PcrCreate(pmdtypeint4, default_type_modifier, nameB);

	CExpression *pexprScalarA = CUtils::PexprScalarIdent(mp, pcrA);
	CExpression *pexprScalarB = CUtils::PexprScalarIdent(mp, pcrB);

	CExpressionArray *prgpexpr1 = GPOS_NEW(mp) CExpressionArray(mp);
	prgpexpr1->Append(pexprScalarA);
	prgpexpr1->Append(pexprScalarB);

	CExpressionArray *prgpexpr2 = GPOS_NEW(mp) CExpressionArray(mp);
	pexprScalarA->AddRef();
	prgpexpr2->Append(pexprScalarA);

	CExpressionArray *prgpexpr3 = GPOS_NEW(mp) CExpressionArray(mp);
	pexprScalarB->AddRef();
	prgpexpr3->Append(pexprScalarB);

	// basic hash distribution tests

	// HD{A,B}, nulls colocated, duplicate insensitive
	poptctxt->MarkDMLQuery(false /*fDMLQuery*/);
	CDistributionSpecHashed *pdshashed1 = GPOS_NEW(mp)
		CDistributionSpecHashed(prgpexpr1, true /* fNullsCollocated */);
	GPOS_ASSERT(pdshashed1->FSatisfies(pdshashed1));
	GPOS_ASSERT(pdshashed1->Matches(pdshashed1));

	// HD{A}, nulls colocated, duplicate sensitive
	poptctxt->MarkDMLQuery(true /*fDMLQuery*/);
	CDistributionSpecHashed *pdshashed2 = GPOS_NEW(mp)
		CDistributionSpecHashed(prgpexpr2, true /* fNullsCollocated */);
	GPOS_ASSERT(pdshashed2->FSatisfies(pdshashed2));
	GPOS_ASSERT(pdshashed2->Matches(pdshashed2));

	// HD{A}, nulls not colocated, duplicate sensitive
	prgpexpr2->AddRef();
	CDistributionSpecHashed *pdshashed3 = GPOS_NEW(mp)
		CDistributionSpecHashed(prgpexpr2, false /* fNullsCollocated */);
	GPOS_ASSERT(pdshashed3->FSatisfies(pdshashed3));
	GPOS_ASSERT(pdshashed3->Matches(pdshashed3));

	// ({A,B}, true, true) does not satisfy ({A}, true, false)
	GPOS_ASSERT(!pdshashed1->FMatchSubset(pdshashed2));
	GPOS_ASSERT(!pdshashed1->FSatisfies(pdshashed2));

	// ({A}, true) satisfies ({A, B}, true)
	GPOS_ASSERT(pdshashed2->FMatchSubset(pdshashed1));
	GPOS_ASSERT(pdshashed2->FSatisfies(pdshashed1));

	// ({A}, true) satisfies ({A}, false)
	GPOS_ASSERT(pdshashed2->FMatchSubset(pdshashed3));
	GPOS_ASSERT(pdshashed2->FSatisfies(pdshashed3));

	// ({A}, false) does not satisfy ({A}, true)
	GPOS_ASSERT(!pdshashed1->FMatchSubset(pdshashed3));
	GPOS_ASSERT(!pdshashed1->FSatisfies(pdshashed3));

	// HD{B}, nulls colocated, duplicate sensitive
	poptctxt->MarkDMLQuery(true /*fDMLQuery*/);
	CDistributionSpecHashed *pdshashed4 = GPOS_NEW(mp)
		CDistributionSpecHashed(prgpexpr3, true /* fNullsCollocated */);

	// HD{B}, nulls not colocated, duplicate sensitive
	prgpexpr3->AddRef();
	CDistributionSpecHashed *pdshashed5 = GPOS_NEW(mp)
		CDistributionSpecHashed(prgpexpr3, false /* fNullsCollocated */);

	// Combine {A} true, {B} false
	CDistributionSpecHashed *pdshashed6 = pdshashed2->Combine(mp, pdshashed5);

	GPOS_ASSERT(true == pdshashed6->FNullsColocated());
	GPOS_ASSERT(false == pdshashed6->PdshashedEquiv()->FNullsColocated());

	// Combine {B} true, {A} false
	CDistributionSpecHashed *pdshashed7 = pdshashed4->Combine(mp, pdshashed3);

	GPOS_ASSERT(true == pdshashed7->FNullsColocated());
	GPOS_ASSERT(false == pdshashed7->PdshashedEquiv()->FNullsColocated());

	// Copy {A} true, {B} false
	CDistributionSpecHashed *pdshashed8 = pdshashed7->Copy(mp);

	GPOS_ASSERT(true == pdshashed8->FNullsColocated());
	GPOS_ASSERT(false == pdshashed8->PdshashedEquiv()->FNullsColocated());

	// Copy {A} true, {B} true
	CDistributionSpecHashed *pdshashed9 = pdshashed6->Copy(mp, true);

	GPOS_ASSERT(true == pdshashed9->FNullsColocated());
	GPOS_ASSERT(true == pdshashed9->PdshashedEquiv()->FNullsColocated());

	// Copy {B} false, {A} false
	CDistributionSpecHashed *pdshashed10 = pdshashed7->Copy(mp, false);

	GPOS_ASSERT(false == pdshashed10->FNullsColocated());
	GPOS_ASSERT(false == pdshashed10->PdshashedEquiv()->FNullsColocated());

	// hashed and universal
	CDistributionSpecUniversal *pdsuniversal =
		GPOS_NEW(mp) CDistributionSpecUniversal();

	GPOS_ASSERT(pdsuniversal->FSatisfies(pdshashed1));

	// hashed and singleton
	CDistributionSpecSingleton *pdssSegment = GPOS_NEW(mp)
		CDistributionSpecSingleton(CDistributionSpecSingleton::EstSegment);

	GPOS_ASSERT(!pdshashed1->FSatisfies(pdssSegment));
	GPOS_ASSERT(!pdssSegment->Matches(pdshashed1));

	// hashed and replicated
	CDistributionSpecReplicated *pdsreplicated = GPOS_NEW(mp)
		CDistributionSpecReplicated(CDistributionSpec::EdtStrictReplicated);

	GPOS_ASSERT(pdsreplicated->FSatisfies(pdshashed1));
	GPOS_ASSERT(!pdshashed1->FSatisfies(pdsreplicated));

	// hashed and random
	CDistributionSpecRandom *pdsrandom = GPOS_NEW(mp) CDistributionSpecRandom();

	GPOS_ASSERT(!pdsrandom->FSatisfies(pdshashed1));
	GPOS_ASSERT(!pdshashed1->FSatisfies(pdsrandom));

	// hashed and any
	CDistributionSpecAny *pdsany =
		GPOS_NEW(mp) CDistributionSpecAny(COperator::EopSentinel);

	GPOS_ASSERT(!pdsany->FSatisfies(pdshashed1));
	GPOS_ASSERT(pdshashed1->FSatisfies(pdsany));

	CAutoTrace at(mp);
	at.Os() << std::endl;
	at.Os() << *pdshashed1 << std::endl;
	at.Os() << *pdshashed2 << std::endl;
	at.Os() << *pdshashed3 << std::endl;
	at.Os() << *pdshashed4 << std::endl;
	at.Os() << *pdshashed5 << std::endl;
	at.Os() << *pdshashed6 << std::endl;
	at.Os() << *pdshashed7 << std::endl;
	at.Os() << *pdshashed8 << std::endl;
	at.Os() << *pdshashed9 << std::endl;
	at.Os() << *pdshashed10 << std::endl;

	pdshashed1->Release();
	pdshashed2->Release();
	pdshashed3->Release();
	pdshashed4->Release();
	pdshashed5->Release();
	pdshashed6->Release();
	pdshashed7->Release();
	pdshashed8->Release();
	pdshashed9->Release();
	pdshashed10->Release();

	pdssSegment->Release();
	pdsreplicated->Release();
	pdsrandom->Release();
	pdsany->Release();
	pdsuniversal->Release();

	return GPOS_OK;
}

#ifdef GPOS_DEBUG
//---------------------------------------------------------------------------
//	@function:
//		CDistributionSpecTest::EresUnittest_NegativeAny
//
//	@doc:
//		Negative test for ANY distribution spec
//
//---------------------------------------------------------------------------
GPOS_RESULT
CDistributionSpecTest::EresUnittest_NegativeAny()
{
	CAutoMemoryPool amp;
	CMemoryPool *mp = amp.Pmp();

	// cannot add enforcers for ANY distribution
	CDistributionSpecAny *pdsany =
		GPOS_NEW(mp) CDistributionSpecAny(COperator::EopSentinel);
	CExpressionHandle *pexprhdl = GPOS_NEW(mp) CExpressionHandle(mp);
	pdsany->AppendEnforcers(nullptr /*mp*/, *pexprhdl, nullptr /*prpp*/,
							nullptr /*pdrgpexpr*/, nullptr /*pexpr*/);
	pdsany->Release();
	GPOS_DELETE(pexprhdl);

	return GPOS_FAILED;
}


//---------------------------------------------------------------------------
//	@function:
//		CDistributionSpecTest::EresUnittest_NegativeUniversal
//
//	@doc:
//		Negative test for universal distribution spec
//
//---------------------------------------------------------------------------
GPOS_RESULT
CDistributionSpecTest::EresUnittest_NegativeUniversal()
{
	CAutoMemoryPool amp;
	CMemoryPool *mp = amp.Pmp();

	// cannot add enforcers for Universal distribution
	CDistributionSpecUniversal *pdsuniversal =
		GPOS_NEW(mp) CDistributionSpecUniversal();
	CExpressionHandle *pexprhdl = GPOS_NEW(mp) CExpressionHandle(mp);

	pdsuniversal->AppendEnforcers(nullptr /*mp*/, *pexprhdl, nullptr /*prpp*/,
								  nullptr /*pdrgpexpr*/, nullptr /*pexpr*/);
	pdsuniversal->Release();
	GPOS_DELETE(pexprhdl);

	return GPOS_FAILED;
}

//---------------------------------------------------------------------------
//	@function:
//		CDistributionSpecTest::EresUnittest_NegativeRandom
//
//	@doc:
//		Negative test for random distribution spec
//
//---------------------------------------------------------------------------
GPOS_RESULT
CDistributionSpecTest::EresUnittest_NegativeRandom()
{
	CAutoMemoryPool amp;
	CMemoryPool *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, nullptr /*pceeval*/,
					 CTestUtils::GetCostModel(mp));

	// cannot add enforcers for Random distribution
	CDistributionSpecRandom *pdsrandom = GPOS_NEW(mp) CDistributionSpecRandom();
	CExpressionHandle *pexprhdl = GPOS_NEW(mp) CExpressionHandle(mp);

	pdsrandom->AppendEnforcers(nullptr /*mp*/, *pexprhdl, nullptr /*prpp*/,
							   nullptr /*pdrgpexpr*/, nullptr /*pexpr*/);
	pdsrandom->Release();
	GPOS_DELETE(pexprhdl);

	return GPOS_FAILED;
}
#endif	// GPOS_DEBUG

// EOF

相关信息

greenplumn 源码目录

相关文章

greenplumn CColRefSetIterTest 源码

greenplumn CColRefSetTest 源码

greenplumn CColumnFactoryTest 源码

greenplumn CConstraintTest 源码

greenplumn CEquivalenceClassesTest 源码

greenplumn CFunctionalDependencyTest 源码

greenplumn CGroupTest 源码

greenplumn CKeyCollectionTest 源码

greenplumn CMaxCardTest 源码

greenplumn COrderSpecTest 源码

0  赞