forked from ad-freiburg/qlever
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MultiColumnJoinTest.cpp
78 lines (62 loc) · 2.5 KB
/
MultiColumnJoinTest.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
// Copyright 2018, University of Freiburg,
// Chair of Algorithms and Data Structures.
// Author: Florian Kramer ([email protected])
#include <gtest/gtest.h>
#include <array>
#include <vector>
#include "engine/MultiColumnJoin.h"
#include "util/AllocatorTestHelpers.h"
#include "util/IdTableHelpers.h"
#include "util/IdTestHelpers.h"
#include "util/IndexTestHelpers.h"
using ad_utility::testing::makeAllocator;
namespace {
auto V = ad_utility::testing::VocabId;
}
TEST(EngineTest, multiColumnJoinTest) {
using std::array;
using std::vector;
IdTable a = makeIdTableFromVector(
{{4, 1, 2}, {2, 1, 3}, {1, 1, 4}, {2, 2, 1}, {1, 3, 1}});
IdTable b =
makeIdTableFromVector({{3, 3, 1}, {1, 8, 1}, {4, 2, 2}, {1, 1, 3}});
IdTable res(4, makeAllocator());
vector<array<ColumnIndex, 2>> jcls;
jcls.push_back(array<ColumnIndex, 2>{{1, 2}});
jcls.push_back(array<ColumnIndex, 2>{{2, 1}});
auto* qec = ad_utility::testing::getQec();
// Join a and b on the column pairs 1,2 and 2,1 (entries from columns 1 of
// a have to equal those of column 2 of b and vice versa).
MultiColumnJoin{qec, idTableToExecutionTree(qec, a),
idTableToExecutionTree(qec, b)}
.computeMultiColumnJoin(a, b, jcls, &res);
auto expected = makeIdTableFromVector({{2, 1, 3, 3}, {1, 3, 1, 1}});
ASSERT_EQ(expected, res);
// Test the multi column join with variable sized data.
IdTable va(6, makeAllocator());
va.push_back({V(1), V(2), V(3), V(4), V(5), V(6)});
va.push_back({V(1), V(2), V(3), V(7), V(5), V(6)});
va.push_back({V(7), V(6), V(5), V(4), V(3), V(2)});
IdTable vb(3, makeAllocator());
vb.push_back({V(2), V(3), V(4)});
vb.push_back({V(2), V(3), V(5)});
vb.push_back({V(6), V(7), V(4)});
IdTable vres(7, makeAllocator());
jcls.clear();
jcls.push_back({1, 0});
jcls.push_back({2, 1});
MultiColumnJoin{qec, idTableToExecutionTree(qec, a),
idTableToExecutionTree(qec, b)}
.computeMultiColumnJoin(va, vb, jcls, &vres);
ASSERT_EQ(4u, vres.size());
ASSERT_EQ(7u, vres.numColumns());
IdTable wantedRes(7, makeAllocator());
wantedRes.push_back({V(1), V(2), V(3), V(4), V(5), V(6), V(4)});
wantedRes.push_back({V(1), V(2), V(3), V(4), V(5), V(6), V(5)});
wantedRes.push_back({V(1), V(2), V(3), V(7), V(5), V(6), V(4)});
wantedRes.push_back({V(1), V(2), V(3), V(7), V(5), V(6), V(5)});
ASSERT_EQ(wantedRes[0], vres[0]);
ASSERT_EQ(wantedRes[1], vres[1]);
ASSERT_EQ(wantedRes[2], vres[2]);
ASSERT_EQ(wantedRes[3], vres[3]);
}