CDXLTranslateContextBaseTable.cpp 4.0 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
//---------------------------------------------------------------------------
//	Greenplum Database
//	Copyright (C) 2010 Greenplum, Inc.
//
//	@filename:
//		CDXLTranslateContextBaseTable.cpp
//
//	@doc:
//		Implementation of the methods for accessing translation context for base tables.
//
//	@test:
//
//
//---------------------------------------------------------------------------

#include "postgres.h"
#include "gpopt/translate/CDXLTranslateContextBaseTable.h"

using namespace gpdxl;
using namespace gpos;

//---------------------------------------------------------------------------
//	@function:
//		CDXLTranslateContextBaseTable::CDXLTranslateContextBaseTable
//
//	@doc:
//		Constructor
//
//---------------------------------------------------------------------------
J
Jesse Zhang 已提交
30 31
CDXLTranslateContextBaseTable::CDXLTranslateContextBaseTable(CMemoryPool *mp)
	: m_mp(mp), m_oid(InvalidOid), m_rel_index(0)
32 33
{
	// initialize hash table
34
	m_colid_to_attno_map = GPOS_NEW(m_mp) UlongToIntMap(m_mp);
35 36 37 38 39 40 41 42 43 44 45 46
}

//---------------------------------------------------------------------------
//	@function:
//		CDXLTranslateContextBaseTable::~CDXLTranslateContextBaseTable
//
//	@doc:
//		Destructor
//
//---------------------------------------------------------------------------
CDXLTranslateContextBaseTable::~CDXLTranslateContextBaseTable()
{
47
	CRefCount::SafeRelease(m_colid_to_attno_map);
48 49 50 51 52 53 54 55 56 57 58 59
}


//---------------------------------------------------------------------------
//	@function:
//		CDXLTranslateContextBaseTable::SetOID
//
//	@doc:
//		Set the oid of the base relation
//
//---------------------------------------------------------------------------
void
J
Jesse Zhang 已提交
60
CDXLTranslateContextBaseTable::SetOID(OID oid)
61 62 63 64 65 66 67 68 69 70 71 72 73 74
{
	GPOS_ASSERT(oid != InvalidOid);
	m_oid = oid;
}

//---------------------------------------------------------------------------
//	@function:
//		CDXLTranslateContextBaseTable::SetIdx
//
//	@doc:
//		Set the index of the base relation in the range table
//
//---------------------------------------------------------------------------
void
J
Jesse Zhang 已提交
75
CDXLTranslateContextBaseTable::SetRelIndex(Index rel_index)
76
{
77 78
	GPOS_ASSERT(0 < rel_index);
	m_rel_index = rel_index;
79 80 81 82
}

//---------------------------------------------------------------------------
//	@function:
83
//		CDXLTranslateContextBaseTable::GetOid
84 85 86 87 88 89
//
//	@doc:
//		Returns the oid of the table
//
//---------------------------------------------------------------------------
OID
90
CDXLTranslateContextBaseTable::GetOid() const
91 92 93 94 95 96
{
	return m_oid;
}

//---------------------------------------------------------------------------
//	@function:
97
//		CDXLTranslateContextBaseTable::GetRelIndex
98 99 100 101 102 103
//
//	@doc:
//		Returns the index of the relation in the rable table
//
//---------------------------------------------------------------------------
Index
104
CDXLTranslateContextBaseTable::GetRelIndex() const
105
{
106 107
	GPOS_ASSERT(0 < m_rel_index);
	return m_rel_index;
108 109 110 111 112
}


//---------------------------------------------------------------------------
//	@function:
113
//		CDXLTranslateContextBaseTable::GetAttnoForColId
114 115 116 117 118 119
//
//	@doc:
//		Lookup the index of the attribute with the DXL col id in the underlying table schema
//
//---------------------------------------------------------------------------
INT
J
Jesse Zhang 已提交
120
CDXLTranslateContextBaseTable::GetAttnoForColId(ULONG colid) const
121
{
122
	const INT *pi = m_colid_to_attno_map->Find(&colid);
123 124 125 126 127 128 129 130 131 132 133
	if (NULL != pi)
	{
		return *pi;
	}

	// column not found
	return 0;
}

//---------------------------------------------------------------------------
//	@function:
134
//		CDXLTranslateContextBaseTable::InsertMapping
135 136 137 138 139 140 141
//
//	@doc:
//		Insert a mapping ColId->Idx, where ulDXLColId is a DXL introduced column id,
//		and ulIdx is the index of the column in the underlying table schema
//
//---------------------------------------------------------------------------
BOOL
J
Jesse Zhang 已提交
142
CDXLTranslateContextBaseTable::InsertMapping(ULONG dxl_colid, INT att_no)
143 144
{
	// copy key and value
145 146
	ULONG *key = GPOS_NEW(m_mp) ULONG(dxl_colid);
	INT *value = GPOS_NEW(m_mp) INT(att_no);
147 148 149

	// insert colid-idx mapping in the hash map

150
	BOOL res = m_colid_to_attno_map->Insert(key, value);
151

152
	GPOS_ASSERT(res);
153

154
	return res;
155 156 157
}

// EOF