CMappingVarColId.h 4.7 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
//---------------------------------------------------------------------------
//	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 "gpos/common/CHashMap.h"
#include "gpos/common/CHashMapIter.h"

29 30
#include "naucrates/dxl/operators/dxlops.h"
#include "naucrates/dxl/CIdGenerator.h"
31 32 33 34 35 36 37

//fwd decl
struct Var;
struct List;

namespace gpmd
{
J
Jesse Zhang 已提交
38
class IMDIndex;
39 40 41 42
}

namespace gpdxl
{
J
Jesse Zhang 已提交
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
// 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
	CMemoryPool *m_mp;

	// hash map structure to store gpdb att -> opt col information
	typedef CHashMap<CGPDBAttInfo, CGPDBAttOptCol, HashGPDBAttInfo,
					 EqualGPDBAttInfo, CleanupRelease, CleanupRelease>
		GPDBAttOptColHashMap;

	// iterator
	typedef CHashMapIter<CGPDBAttInfo, CGPDBAttOptCol, HashGPDBAttInfo,
						 EqualGPDBAttInfo, CleanupRelease, CleanupRelease>
		GPDBAttOptColHashMapIter;

	// map from gpdb att to optimizer col
	GPDBAttOptColHashMap *m_gpdb_att_opt_col_mapping;

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

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

	// helper function to access mapping
	const CGPDBAttOptCol *GetGPDBAttOptColMapping(
		ULONG current_query_level, const Var *var,
		EPlStmtPhysicalOpType plstmt_physical_op_type) const;

public:
	// ctor
	explicit CMappingVarColId(CMemoryPool *);

	// dtor
	virtual ~CMappingVarColId()
111
	{
J
Jesse Zhang 已提交
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
		m_gpdb_att_opt_col_mapping->Release();
	}

	// given a gpdb attribute, return a column name in optimizer world
	virtual const CWStringBase *GetOptColName(
		ULONG current_query_level, const Var *var,
		EPlStmtPhysicalOpType plstmt_physical_op_type) const;

	// given a gpdb attribute, return column id
	virtual ULONG GetColId(ULONG current_query_level, const Var *var,
						   EPlStmtPhysicalOpType plstmt_physical_op_type) const;

	// load up mapping information from an index
	void LoadIndexColumns(ULONG query_level, ULONG RTE_index,
						  const IMDIndex *index,
						  const CDXLTableDescr *table_descr);

	// load up mapping information from table descriptor
	void LoadTblColumns(ULONG query_level, ULONG RTE_index,
						const CDXLTableDescr *table_descr);

	// load up column id mapping information from the array of column descriptors
	void LoadColumns(ULONG query_level, ULONG RTE_index,
					 const CDXLColDescrArray *column_descrs);

	// load up mapping information from derived table columns
	void LoadDerivedTblColumns(ULONG query_level, ULONG RTE_index,
							   const CDXLNodeArray *derived_columns_dxl,
							   List *target_list);

	// load information from CTE columns
	void LoadCTEColumns(ULONG query_level, ULONG RTE_index,
						const ULongPtrArray *pdrgpulCTE, List *target_list);

	// load up mapping information from scalar projection list
	void LoadProjectElements(ULONG query_level, ULONG RTE_index,
							 const CDXLNode *project_list_dxlnode);

	// load up mapping information from list of column names
	void Load(ULONG query_level, ULONG RTE_index, CIdGenerator *id_generator,
			  List *col_names);

	// create a deep copy
	CMappingVarColId *CopyMapColId(CMemoryPool *mp) const;

	// create a deep copy
	CMappingVarColId *CopyMapColId(ULONG query_level) const;

	// create a copy of the mapping replacing old col ids with new ones
	CMappingVarColId *CopyRemapColId(CMemoryPool *mp, ULongPtrArray *old_colids,
									 ULongPtrArray *new_colids) const;
};
}  // namespace gpdxl
165

J
Jesse Zhang 已提交
166
#endif	//GPDXL_CMappingVarColId_H
167 168

// EOF