MCPcopy Create free account
hub / github.com/1345414527/MIT6.830 / validateJoin

Method validateJoin

test/simpledb/systemtest/JoinTest.java:23–65  ·  view source on GitHub ↗
(int table1ColumnValue, int table1Rows, int table2ColumnValue,
            int table2Rows)

Source from the content-addressed store, hash-verified

21public class JoinTest extends SimpleDbTestBase {
22 private static final int COLUMNS = 2;
23 public void validateJoin(int table1ColumnValue, int table1Rows, int table2ColumnValue,
24 int table2Rows)
25 throws IOException, DbException, TransactionAbortedException {
26 // Create the two tables
27 Map<Integer, Integer> columnSpecification = new HashMap<>();
28 columnSpecification.put(0, table1ColumnValue);
29 List<List<Integer>> t1Tuples = new ArrayList<>();
30 HeapFile table1 = SystemTestUtil.createRandomHeapFile(
31 COLUMNS, table1Rows, columnSpecification, t1Tuples);
32 assert t1Tuples.size() == table1Rows;
33
34 columnSpecification.put(0, table2ColumnValue);
35 List<List<Integer>> t2Tuples = new ArrayList<>();
36 HeapFile table2 = SystemTestUtil.createRandomHeapFile(
37 COLUMNS, table2Rows, columnSpecification, t2Tuples);
38 assert t2Tuples.size() == table2Rows;
39
40 // Generate the expected results
41 List<List<Integer>> expectedResults = new ArrayList<>();
42 for (List<Integer> t1 : t1Tuples) {
43 for (List<Integer> t2 : t2Tuples) {
44 // If the columns match, join the tuples
45 if (t1.get(0).equals(t2.get(0))) {
46 List<Integer> out = new ArrayList<>(t1);
47 out.addAll(t2);
48 expectedResults.add(out);
49 }
50 }
51 }
52
53 // Begin the join
54 TransactionId tid = new TransactionId();
55 SeqScan ss1 = new SeqScan(tid, table1.getId(), "");
56 SeqScan ss2 = new SeqScan(tid, table2.getId(), "");
57 JoinPredicate p = new JoinPredicate(0, Predicate.Op.EQUALS, 0);
58 Join joinOp = new Join(p, ss1, ss2);
59
60 // test the join results
61 SystemTestUtil.matchTuples(joinOp, expectedResults);
62
63 joinOp.close();
64 Database.getBufferPool().transactionComplete(tid);
65 }
66
67 @Test public void testSingleMatch()
68 throws IOException, DbException, TransactionAbortedException {

Callers 3

testSingleMatchMethod · 0.95
testNoMatchMethod · 0.95
testMultipleMatchMethod · 0.95

Calls 9

createRandomHeapFileMethod · 0.95
getIdMethod · 0.95
matchTuplesMethod · 0.95
closeMethod · 0.95
getBufferPoolMethod · 0.95
putMethod · 0.80
getMethod · 0.80
equalsMethod · 0.65
transactionCompleteMethod · 0.45

Tested by

no test coverage detected