CMappingVarColId.h 4.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
//---------------------------------------------------------------------------
//	Greenplum Database
//	Copyright (C) 2011 Greenplum, Inc.
//
//	@filename:
//		CMappingVarColId.h
//
//	@doc:
//		Abstract base class of VAR to DXL mapping during scalar operator translation.
//		If we need a scalar translator during PlStmt->DXL or Query->DXL translation
//		we implement a variable mapping for PlStmt or Query respectively that
//		is derived from this interface.
//
//	@test:
//
//
//---------------------------------------------------------------------------

#ifndef GPDXL_CMappingVarColId_H
#define GPDXL_CMappingVarColId_H


#include "gpopt/translate/CGPDBAttInfo.h"
#include "gpopt/translate/CGPDBAttOptCol.h"


#include "dxl/operators/dxlops.h"
#include "gpos/common/CHashMap.h"
#include "gpos/common/CHashMapIter.h"
#include "dxl/operators/dxlops.h"

#include "dxl/CIdGenerator.h"

//fwd decl
struct Var;
struct List;

namespace gpmd
{
	class IMDIndex;
}

namespace gpdxl
{
	// physical operator types used in planned statements
	enum EPlStmtPhysicalOpType
	{
		EpspotTblScan,
		EpspotHashjoin,
		EpspotNLJoin,
		EpspotMergeJoin,
		EpspotMotion,
		EpspotLimit,
		EpspotAgg,
		EpspotWindow,
		EpspotSort,
		EpspotSubqueryScan,
		EpspotAppend,
		EpspotResult,
		EpspotMaterialize,
		EpspotSharedScan,
		EpspotIndexScan,
		EpspotIndexOnlyScan,
		EpspotNone
	};

	//---------------------------------------------------------------------------
	//	@class:
	//		CMappingVarColId
	//
	//	@doc:
	//		Class providing the interface for VAR to DXL mapping during scalar
	//		operator translation that are used to generate the CDXLNode from a
	//		variable reference in a PlStmt or Query
	//
	//---------------------------------------------------------------------------
	class CMappingVarColId
	{
		private:
			// memory pool
			IMemoryPool *m_pmp;

			// hash map structure to store gpdb att -> opt col information
			typedef CHashMap<CGPDBAttInfo, CGPDBAttOptCol, UlHashGPDBAttInfo, FEqualGPDBAttInfo,
							CleanupRelease, CleanupRelease > CMVCMap;

			// iterator
			typedef CHashMapIter<CGPDBAttInfo, CGPDBAttOptCol, UlHashGPDBAttInfo, FEqualGPDBAttInfo,
							CleanupRelease, CleanupRelease > CMVCMapIter;

			// map from gpdb att to optimizer col
			CMVCMap	*m_pmvcmap;

			// insert mapping entry
			void Insert(ULONG, ULONG, INT, ULONG, CWStringBase *pstr);

			// no copy constructor
			CMappingVarColId(const CMappingVarColId &);

			// helper function to access mapping
			const CGPDBAttOptCol *Pgpdbattoptcol
								(
								ULONG ulCurrentQueryLevel,
								const Var *pvar,
								EPlStmtPhysicalOpType eplsphoptype
								)
								const;

		public:

			// ctor
			explicit
			CMappingVarColId(IMemoryPool *);

			// dtor
			virtual
			~CMappingVarColId()
			{
				m_pmvcmap->Release();
			}

			// given a gpdb attribute, return a column name in optimizer world
			virtual
			const CWStringBase *PstrColName
											(
											ULONG ulCurrentQueryLevel,
											const Var *pvar,
											EPlStmtPhysicalOpType eplsphoptype
											)
											const;

			// given a gpdb attribute, return column id
			virtual
			ULONG UlColId
							(
							ULONG ulCurrentQueryLevel,
							const Var *pvar,
							EPlStmtPhysicalOpType eplsphoptype
							)
							const;

			// load up mapping information from an index
			void LoadIndexColumns(ULONG ulQueryLevel, ULONG ulRTEIndex, const IMDIndex *pmdindex, const CDXLTableDescr *pdxltabdesc);

			// load up mapping information from table descriptor
			void LoadTblColumns(ULONG ulQueryLevel, ULONG ulRTEIndex, const CDXLTableDescr *pdxltabdesc);

			// load up column id mapping information from the array of column descriptors
			void LoadColumns(ULONG ulQueryLevel, ULONG ulRTEIndex, const DrgPdxlcd *pdrgdxlcd);

			// load up mapping information from derived table columns
			void LoadDerivedTblColumns(ULONG ulQueryLevel, ULONG ulRTEIndex, const DrgPdxln *pdrgpdxlnDerivedColumns, List *plTargetList);

			// load information from CTE columns
			void LoadCTEColumns(ULONG ulQueryLevel, ULONG ulRTEIndex, const DrgPul *pdrgpulCTE, List *plTargetList);

			// load up mapping information from scalar projection list
			void LoadProjectElements(ULONG ulQueryLevel, ULONG ulRTEIndex, const CDXLNode *pdxlnPrL);

			// load up mapping information from list of column names
			void Load(ULONG ulQueryLevel, ULONG ulRTEIndex,	CIdGenerator *pidgtor, List *plColNames);

			// create a deep copy
			CMappingVarColId *PmapvarcolidCopy(IMemoryPool *pmp) const;

			// create a deep copy
			CMappingVarColId *PmapvarcolidCopy(ULONG ulQueryLevel) const;
			
			// create a copy of the mapping replacing old col ids with new ones
			CMappingVarColId *PmapvarcolidRemap
				(
				IMemoryPool *pmp,
				DrgPul *pdrgpulOld,
				DrgPul *pdrgpulNew
				)
				const;
	};
}

#endif //GPDXL_CMappingVarColId_H

// EOF