-
Notifications
You must be signed in to change notification settings - Fork 0
/
TupleStreamReader.cpp
executable file
·76 lines (63 loc) · 1.32 KB
/
TupleStreamReader.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
#include <stdio.h>
#include <string.h>
#include "TupleStreamReader.h"
TupleStreamReader::TupleStreamReader(MemoryBlock & block) : m_block(block)
{
m_nRecs = 0;
m_layout = NULL;
}
TupleStreamReader::~TupleStreamReader()
{
//delete m_layout;
}
void TupleStreamReader::layout(const MaterializationLayout * layout)
{
m_layout = layout;
}
void TupleStreamReader::peek(Tuple & t)
{
read(t);
m_nRecs--;
}
void TupleStreamReader::read(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);
// all or none
if ((t.schema()->m_partitions & (i+1)) == 0)
continue;
int partition_offset = p->start() + p->bytes() * m_nRecs;
m_block.get(t.m_data + tuple_offset, partition_offset, p->bytes());
tuple_offset += p->bytes();
}
}
else
{
const Schema * atts = t.schema();
int totalNumBytes = atts->rsize();
int offset = totalNumBytes*m_nRecs;
m_block.get(t.m_data,offset,totalNumBytes);
}
m_nRecs++;
}
bool TupleStreamReader::isEndOfStream()
{
bool ret = (m_nRecs == m_block.getSize());
return ret;
}
void TupleStreamReader::rewind(int nback)
{
m_nRecs -= nback;
if (m_nRecs < 0)
{
m_nRecs = 0;
}
}
void TupleStreamReader::reset()
{
m_nRecs = 0;
}