forked from dase/CLAIMS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TablePartition.cpp
executable file
·108 lines (92 loc) · 2.02 KB
/
TablePartition.cpp
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
/*
* PartitoiinedTable.cpp
*
* Created on: May 8, 2013
* Author: wangli
*/
#include "TablePartition.h"
TablePartition::TablePartition(unsigned table_id)
:table_id(table_id)
{
// TODO Auto-generated constructor stub
}
TablePartition::~TablePartition() {
// TODO Auto-generated destructor stub
}
bool TablePartition::createTablePartition(vector<data_type> dt_list)
{
for(unsigned i=0;i<dt_list.size();i++)
{
switch(dt_list[i])
{
case t_int:
{
HeapColumn<int>* tmp=new HeapColumn<int>(table_id,i);
if(!tmp->create_empty())
return false;
column_list.push_back(tmp);
break;
}
case t_float:
{
HeapColumn<float>* tmp=new HeapColumn<float>(table_id,i);
if(!tmp->create_empty())
return false;
column_list.push_back(tmp);
break;
}
default:
printf("the %d-th type is unknown!",i);
}
}
return true;
}
TablePartition::Appender::Appender(TablePartition * table_partition)
:table_partition(table_partition)
{
//initialize the offset_list
for(int i=0;i<table_partition->column_list.size();i++)
{
if(i==0)
{
offset_list.push_back(0);
}
else
{
offset_list.push_back(table_partition->column_list[i]->get_type_length()+offset_list[i-1]);
}
column_appender_list.push_back(table_partition->column_list[i]->create_appender());
}
// for(int i=0;i<table_partition->column_list.size();i++)
// {
// printf("offset[%d]=%d\n",i,offset_list[i]);
// }
}
bool TablePartition::Appender::open()
{
for(int i=0;i<table_partition->column_list.size();i++)
{
column_appender_list[i]->open();
}
return false;
}
bool TablePartition::Appender::close()
{
for(int i=0;i<table_partition->column_list.size();i++)
{
column_appender_list[i]->close();
}
return false;
}
bool TablePartition::Appender::append(void* src, oid_t oid)
{
for(int i=0;i<table_partition->column_list.size();i++)
{
column_appender_list[i]->append((char*)src+offset_list[i],oid);
}
table_partition->record_count++;
}
unsigned TablePartition::get_column_number()
{
return column_list.size();
}