This repository has been archived by the owner on Sep 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 623
/
Copy pathtuple_test.cpp
153 lines (121 loc) · 5.39 KB
/
tuple_test.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//===----------------------------------------------------------------------===//
//
// Peloton
//
// tuple_test.cpp
//
// Identification: test/storage/tuple_test.cpp
//
// Copyright (c) 2015-17, Carnegie Mellon University Database Group
//
//===----------------------------------------------------------------------===//
#include "common/harness.h"
#include <memory>
#include "common/harness.h"
#include "storage/tuple.h"
#include "type/value_factory.h"
namespace peloton {
namespace test {
//===--------------------------------------------------------------------===//
// Tuple Tests
//===--------------------------------------------------------------------===//
class TupleTests : public PelotonTest {};
TEST_F(TupleTests, BasicTest) {
std::vector<catalog::Column> columns;
catalog::Column column1(type::TypeId::INTEGER,
type::Type::GetTypeSize(type::TypeId::INTEGER), "A",
true);
catalog::Column column2(type::TypeId::INTEGER,
type::Type::GetTypeSize(type::TypeId::INTEGER), "B",
true);
catalog::Column column3(type::TypeId::TINYINT,
type::Type::GetTypeSize(type::TypeId::TINYINT), "C",
true);
columns.push_back(column1);
columns.push_back(column2);
columns.push_back(column3);
std::unique_ptr<catalog::Schema> schema(new catalog::Schema(columns));
std::unique_ptr<storage::Tuple> tuple(new storage::Tuple(schema.get(), true));
auto pool = TestingHarness::GetInstance().GetTestingPool();
tuple->SetValue(0, type::ValueFactory::GetIntegerValue(23), pool);
tuple->SetValue(1, type::ValueFactory::GetIntegerValue(45), pool);
tuple->SetValue(2, type::ValueFactory::GetTinyIntValue(1), pool);
type::Value val0 = (tuple->GetValue(0));
type::Value val1 = (tuple->GetValue(1));
type::Value val2 = (tuple->GetValue(2));
type::Value cmp = type::ValueFactory::GetBooleanValue(
(val0.CompareEquals(type::ValueFactory::GetIntegerValue(23))));
EXPECT_TRUE(cmp.IsTrue());
cmp = type::ValueFactory::GetBooleanValue(
(val1.CompareEquals(type::ValueFactory::GetIntegerValue(45))));
EXPECT_TRUE(cmp.IsTrue());
cmp = type::ValueFactory::GetBooleanValue(
(val2.CompareEquals(type::ValueFactory::GetIntegerValue(1))));
EXPECT_TRUE(cmp.IsTrue());
tuple->SetValue(2, type::ValueFactory::GetTinyIntValue(2), pool);
val2 = (tuple->GetValue(2));
cmp = type::ValueFactory::GetBooleanValue(
(val2.CompareEquals(type::ValueFactory::GetIntegerValue(2))));
EXPECT_TRUE(cmp.IsTrue());
// Make sure that our tuple tells us the right estimated size
// for uninlined attributes
EXPECT_EQ(0, tuple->GetUninlinedMemorySize());
LOG_TRACE("%s", tuple->GetInfo().c_str());
}
TEST_F(TupleTests, VarcharTest) {
std::vector<catalog::Column> columns;
catalog::Column column1(type::TypeId::INTEGER,
type::Type::GetTypeSize(type::TypeId::INTEGER), "A",
true);
catalog::Column column2(type::TypeId::INTEGER,
type::Type::GetTypeSize(type::TypeId::INTEGER), "B",
true);
catalog::Column column3(type::TypeId::TINYINT,
type::Type::GetTypeSize(type::TypeId::TINYINT), "C",
true);
catalog::Column column4(type::TypeId::VARCHAR, 25, "D", false);
columns.push_back(column1);
columns.push_back(column2);
columns.push_back(column3);
columns.push_back(column4);
std::unique_ptr<catalog::Schema> schema(new catalog::Schema(columns));
std::unique_ptr<storage::Tuple> tuple(new storage::Tuple(schema.get(), true));
auto pool = TestingHarness::GetInstance().GetTestingPool();
tuple->SetValue(0, type::ValueFactory::GetIntegerValue(23), pool);
tuple->SetValue(1, type::ValueFactory::GetIntegerValue(45), pool);
tuple->SetValue(2, type::ValueFactory::GetTinyIntValue(1), pool);
type::Value val = type::ValueFactory::GetVarcharValue(
(std::string) "hello hello world", pool);
tuple->SetValue(3, val, pool);
type::Value value3 = (tuple->GetValue(3));
type::Value cmp =
type::ValueFactory::GetBooleanValue((value3.CompareEquals(val)));
EXPECT_TRUE(cmp.IsTrue());
LOG_TRACE("%s", tuple->GetInfo().c_str());
auto val2 =
type::ValueFactory::GetVarcharValue((std::string) "hi joy !", pool);
tuple->SetValue(3, val2, pool);
value3 = (tuple->GetValue(3));
cmp = type::ValueFactory::GetBooleanValue((value3.CompareNotEquals(val)));
EXPECT_TRUE(cmp.IsTrue());
cmp = type::ValueFactory::GetBooleanValue((value3.CompareEquals(val2)));
EXPECT_TRUE(cmp.IsTrue());
LOG_TRACE("%s", tuple->GetInfo().c_str());
// test if VARCHAR length is enforced
auto val3 = type::ValueFactory::GetVarcharValue((std::string) "this is a very long string", pool);
try {
tuple->SetValue(3, val3, pool);
}
catch (peloton::ValueOutOfRangeException e) {}
value3 = (tuple->GetValue(3));
cmp = type::ValueFactory::GetBooleanValue((value3.CompareNotEquals(val3)));
EXPECT_TRUE(cmp.IsTrue());
cmp = type::ValueFactory::GetBooleanValue((value3.CompareEquals(val2)));
EXPECT_TRUE(cmp.IsTrue());
LOG_TRACE("%s", tuple->GetInfo().c_str());
// Make sure that our tuple tells us the right estimated size
size_t expected_size = sizeof(int32_t) + value3.GetLength();
EXPECT_EQ(expected_size, tuple->GetUninlinedMemorySize());
}
} // namespace test
} // namespace peloton