CDXLTranslateContext.h 3.6 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
//---------------------------------------------------------------------------
//	Greenplum Database
//	Copyright (C) 2010 Greenplum, Inc.
//
//	@filename:
//		CDXLTranslateContext.h
//
//	@doc:
//		Class providing access to translation context, such as mappings between
//		table names, operator names, etc. and oids
//
//	@test:
//
//
//---------------------------------------------------------------------------

#ifndef GPDXL_CDXLTranslateContext_H
#define GPDXL_CDXLTranslateContext_H

#include "gpopt/translate/CMappingElementColIdParamId.h"

#include "gpos/base.h"
#include "gpos/common/CHashMap.h"
#include "gpos/common/CHashMapIter.h"


// fwd decl
struct TargetEntry;

namespace gpdxl
{
J
Jesse Zhang 已提交
32
using namespace gpos;
33

J
Jesse Zhang 已提交
34 35 36 37
// hash maps mapping ULONG -> TargetEntry
typedef CHashMap<ULONG, TargetEntry, gpos::HashValue<ULONG>,
				 gpos::Equals<ULONG>, CleanupDelete<ULONG>, CleanupNULL>
	ULongToTargetEntryMap;
38

J
Jesse Zhang 已提交
39 40 41 42 43
// hash maps mapping ULONG -> CMappingElementColIdParamId
typedef CHashMap<ULONG, CMappingElementColIdParamId, gpos::HashValue<ULONG>,
				 gpos::Equals<ULONG>, CleanupDelete<ULONG>,
				 CleanupRelease<CMappingElementColIdParamId> >
	ULongToColParamMap;
44

J
Jesse Zhang 已提交
45 46 47 48
typedef CHashMapIter<ULONG, CMappingElementColIdParamId, gpos::HashValue<ULONG>,
					 gpos::Equals<ULONG>, CleanupDelete<ULONG>,
					 CleanupRelease<CMappingElementColIdParamId> >
	ULongToColParamMapIter;
49 50


J
Jesse Zhang 已提交
51 52 53 54 55 56 57 58 59 60 61 62 63
//---------------------------------------------------------------------------
//	@class:
//		CDXLTranslateContext
//
//	@doc:
//		Class providing access to translation context, such as mappings between
//		ColIds and target entries
//
//---------------------------------------------------------------------------
class CDXLTranslateContext
{
private:
	CMemoryPool *m_mp;
64

J
Jesse Zhang 已提交
65 66
	// private copy ctor
	CDXLTranslateContext(const CDXLTranslateContext &);
67

J
Jesse Zhang 已提交
68 69
	// mappings ColId->TargetEntry used for intermediate DXL nodes
	ULongToTargetEntryMap *m_colid_to_target_entry_map;
70

J
Jesse Zhang 已提交
71 72
	// mappings ColId->ParamId used for outer refs in subplans
	ULongToColParamMap *m_colid_to_paramid_map;
73

J
Jesse Zhang 已提交
74 75 76 77 78 79
	// is the node for which this context is built a child of an aggregate node
	// This is used to assign 0 instead of OUTER for the varno value of columns
	// in an Agg node, as expected in GPDB
	// TODO: antovl - Jan 26, 2011; remove this when Agg node in GPDB is fixed
	// to use OUTER instead of 0 for Var::varno in Agg target lists (MPP-12034)
	BOOL m_is_child_agg_node;
80

J
Jesse Zhang 已提交
81 82
	// copy the params hashmap
	void CopyParamHashmap(ULongToColParamMap *original);
83

J
Jesse Zhang 已提交
84 85 86
public:
	// ctor/dtor
	CDXLTranslateContext(CMemoryPool *mp, BOOL is_child_agg_node);
87

J
Jesse Zhang 已提交
88 89
	CDXLTranslateContext(CMemoryPool *mp, BOOL is_child_agg_node,
						 ULongToColParamMap *original);
90

J
Jesse Zhang 已提交
91
	~CDXLTranslateContext();
92

J
Jesse Zhang 已提交
93 94
	// is parent an aggregate node
	BOOL IsParentAggNode() const;
95

J
Jesse Zhang 已提交
96 97 98 99 100 101
	// return the params hashmap
	ULongToColParamMap *
	GetColIdToParamIdMap()
	{
		return m_colid_to_paramid_map;
	}
102

J
Jesse Zhang 已提交
103 104
	// return the target entry corresponding to the given ColId
	const TargetEntry *GetTargetEntry(ULONG colid) const;
105

J
Jesse Zhang 已提交
106 107 108
	// return the param id corresponding to the given ColId
	const CMappingElementColIdParamId *GetParamIdMappingElement(
		ULONG colid) const;
109

J
Jesse Zhang 已提交
110 111
	// store the mapping of the given column id and target entry
	void InsertMapping(ULONG colid, TargetEntry *target_entry);
112

J
Jesse Zhang 已提交
113 114 115 116
	// store the mapping of the given column id and param id
	BOOL FInsertParamMapping(ULONG colid,
							 CMappingElementColIdParamId *pmecolidparamid);
};
117 118


J
Jesse Zhang 已提交
119 120 121 122
// array of dxl translation context
typedef CDynamicPtrArray<const CDXLTranslateContext, CleanupNULL>
	CDXLTranslationContextArray;
}  // namespace gpdxl
123

J
Jesse Zhang 已提交
124
#endif	// !GPDXL_CDXLTranslateContext_H
125 126

// EOF