-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTupleStreamWriter.cpp
More file actions
executable file
·73 lines (61 loc) · 1.58 KB
/
TupleStreamWriter.cpp
File metadata and controls
executable file
·73 lines (61 loc) · 1.58 KB
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
#include <stdio.h>
#include <string.h>
#include "TupleStreamWriter.h"
TupleStreamWriter::TupleStreamWriter(MemoryBlock & block, size_t record_size) : m_block(block)
{
m_pos = 0;
m_layout = NULL;
m_nRecs = 0;
m_record_size = record_size;
}
TupleStreamWriter::~TupleStreamWriter()
{
//delete m_layout;
}
void TupleStreamWriter::layout(const MaterializationLayout * layout)
{
m_layout = layout;
}
void TupleStreamWriter::discard()
{
m_nRecs = 0;
m_pos = 0;
m_block.clear();
}
bool TupleStreamWriter::isStreamFull()
{
return ((m_block.capacity() - m_pos) < m_record_size);
}
void TupleStreamWriter::write(Tuple & t)
{
if (m_layout != NULL)
{
int tuple_offset = 0;
for (int i = 0; i < 2 /* m_layout->npartitions() */; i++)
{
const Partition * p = m_layout->partition(i);
int offset = p->start() + p->bytes() * m_nRecs;
/* If we cascaded the interesting fields down, we could optimize
the writes as below. However, testing has shown this will not
improve performance beyond that of a n-ary layout. Therefore no
more development on this optimization
m_block.put(t.m_data + tuple_offset, offset, p->bytes());
tuple_offset += p->bytes();
*/
for (int j = 0; j < p->nitems(); j++)
{
const Attribute * a = p->attribute(j);
m_block.put(t.m_data + t.schema()->offset(a), offset, a->size());
offset += a->size();
}
}
}
else
{
int offset = t.schema()->rsize()*m_nRecs;
m_block.put((byte*)t.m_data, offset, t.schema()->rsize());
}
m_pos += m_record_size;
m_nRecs++;
m_block.setSize(m_nRecs);
}