-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathJoinTest.java
115 lines (102 loc) · 3.15 KB
/
JoinTest.java
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
package simpledb;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import junit.framework.JUnit4TestAdapter;
import org.junit.Before;
import org.junit.Test;
import simpledb.systemtest.SimpleDbTestBase;
public class JoinTest extends SimpleDbTestBase {
int width1 = 2;
int width2 = 3;
DbIterator scan1;
DbIterator scan2;
DbIterator eqJoin;
DbIterator gtJoin;
/**
* Initialize each unit test
*/
@Before public void createTupleLists() throws Exception {
this.scan1 = TestUtil.createTupleList(width1,
new int[] { 1, 2,
3, 4,
5, 6,
7, 8 });
this.scan2 = TestUtil.createTupleList(width2,
new int[] { 1, 2, 3,
2, 3, 4,
3, 4, 5,
4, 5, 6,
5, 6, 7 });
this.eqJoin = TestUtil.createTupleList(width1 + width2,
new int[] { 1, 2, 1, 2, 3,
3, 4, 3, 4, 5,
5, 6, 5, 6, 7 });
this.gtJoin = TestUtil.createTupleList(width1 + width2,
new int[] {
3, 4, 1, 2, 3, // 1, 2 < 3
3, 4, 2, 3, 4,
5, 6, 1, 2, 3, // 1, 2, 3, 4 < 5
5, 6, 2, 3, 4,
5, 6, 3, 4, 5,
5, 6, 4, 5, 6,
7, 8, 1, 2, 3, // 1, 2, 3, 4, 5 < 7
7, 8, 2, 3, 4,
7, 8, 3, 4, 5,
7, 8, 4, 5, 6,
7, 8, 5, 6, 7 });
}
/**
* Unit test for Join.getTupleDesc()
*/
@Test public void getTupleDesc() {
JoinPredicate pred = new JoinPredicate(0, Predicate.Op.EQUALS, 0);
Join op = new Join(pred, scan1, scan2);
TupleDesc expected = Utility.getTupleDesc(width1 + width2);
TupleDesc actual = op.getTupleDesc();
assertEquals(expected, actual);
}
/**
* Unit test for Join.rewind()
*/
@Test public void rewind() throws Exception {
JoinPredicate pred = new JoinPredicate(0, Predicate.Op.EQUALS, 0);
Join op = new Join(pred, scan1, scan2);
op.open();
while (op.hasNext()) {
assertNotNull(op.next());
}
assertTrue(TestUtil.checkExhausted(op));
op.rewind();
eqJoin.open();
Tuple expected = eqJoin.next();
Tuple actual = op.next();
assertTrue(TestUtil.compareTuples(expected, actual));
}
/**
* Unit test for Join.getNext() using a > predicate
*/
@Test public void gtJoin() throws Exception {
JoinPredicate pred = new JoinPredicate(0, Predicate.Op.GREATER_THAN, 0);
Join op = new Join(pred, scan1, scan2);
op.open();
gtJoin.open();
TestUtil.matchAllTuples(gtJoin, op);
}
/**
* Unit test for Join.getNext() using an = predicate
*/
@Test public void eqJoin() throws Exception {
JoinPredicate pred = new JoinPredicate(0, Predicate.Op.EQUALS, 0);
Join op = new Join(pred, scan1, scan2);
op.open();
eqJoin.open();
TestUtil.matchAllTuples(eqJoin, op);
}
/**
* JUnit suite target
*/
public static junit.framework.Test suite() {
return new JUnit4TestAdapter(JoinTest.class);
}
}